alexandroid/decompiled/jadx/sources/com/facebook/react/common/ShakeDetector.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

136 lines
7.2 KiB
Java

package com.facebook.react.common;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import kotlin.Metadata;
import kotlin.jvm.JvmOverloads;
import kotlin.jvm.internal.DefaultConstructorMarker;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@Metadata(d1 = {"\u0000N\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0003\n\u0002\u0010\u0007\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0002\b\u0004\n\u0002\u0010\u000b\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0005\u0018\u00002\u00020\u0001:\u0001%B\u001b\b\u0007\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\b\b\u0002\u0010\u0004\u001a\u00020\u0005¢\u0006\u0004\b\u0006\u0010\u0007J\u000e\u0010\u0012\u001a\u00020\u00132\u0006\u0010\u0014\u001a\u00020\rJ\u0006\u0010\u0015\u001a\u00020\u0013J\b\u0010\u0016\u001a\u00020\u0013H\u0002J\u0010\u0010\u0017\u001a\u00020\u00182\u0006\u0010\u0019\u001a\u00020\tH\u0002J\u0010\u0010\u001a\u001a\u00020\u00132\u0006\u0010\u001b\u001a\u00020\u000fH\u0002J\u0010\u0010\u001c\u001a\u00020\u00132\u0006\u0010\u001d\u001a\u00020\u001eH\u0016J\u0018\u0010\u001f\u001a\u00020\u00132\u0006\u0010 \u001a\u00020!2\u0006\u0010\"\u001a\u00020\u0005H\u0016J\u0010\u0010#\u001a\u00020\u00132\u0006\u0010$\u001a\u00020\u000fH\u0002R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0004\u001a\u00020\u0005X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\tX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\n\u001a\u00020\tX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u000b\u001a\u00020\tX\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\f\u001a\u0004\u0018\u00010\rX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u000e\u001a\u00020\u000fX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0010\u001a\u00020\u0005X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0011\u001a\u00020\u000fX\u0082\u000e¢\u0006\u0002\n\u0000¨\u0006&"}, d2 = {"Lcom/facebook/react/common/ShakeDetector;", "Landroid/hardware/SensorEventListener;", "shakeListener", "Lcom/facebook/react/common/ShakeDetector$ShakeListener;", "minNumShakes", "", "<init>", "(Lcom/facebook/react/common/ShakeDetector$ShakeListener;I)V", "accelerationX", "", "accelerationY", "accelerationZ", "sensorManager", "Landroid/hardware/SensorManager;", "lastTimestamp", "", "numShakes", "lastShakeTimestamp", "start", "", "manager", "stop", "reset", "atLeastRequiredForce", "", "a", "recordShake", "timestamp", "onSensorChanged", "sensorEvent", "Landroid/hardware/SensorEvent;", "onAccuracyChanged", "sensor", "Landroid/hardware/Sensor;", "i", "maybeDispatchShake", "currentTimestamp", "ShakeListener", "ReactAndroid_release"}, k = 1, mv = {2, 1, 0}, xi = 48)
/* loaded from: classes6.dex */
public final class ShakeDetector implements SensorEventListener {
private float accelerationX;
private float accelerationY;
private float accelerationZ;
private long lastShakeTimestamp;
private long lastTimestamp;
private final int minNumShakes;
private int numShakes;
@Nullable
private SensorManager sensorManager;
@NotNull
private final ShakeListener shakeListener;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u0002\n\u0000\bæ\u0080\u0001\u0018\u00002\u00020\u0001J\b\u0010\u0002\u001a\u00020\u0003H&ø\u0001\u0000\u0082\u0002\u0006\n\u0004\b!0\u0001¨\u0006\u0004À\u0006\u0001"}, d2 = {"Lcom/facebook/react/common/ShakeDetector$ShakeListener;", "", "onShake", "", "ReactAndroid_release"}, k = 1, mv = {2, 1, 0}, xi = 48)
public interface ShakeListener {
void onShake();
}
@JvmOverloads
public ShakeDetector(@NotNull ShakeListener shakeListener, int i) {
shakeListener.getClass();
this.shakeListener = shakeListener;
this.minNumShakes = i;
}
private final boolean atLeastRequiredForce(float a2) {
return Math.abs(a2) > 13.042845f;
}
private final void maybeDispatchShake(long currentTimestamp) {
float f;
if (this.numShakes >= this.minNumShakes * 8) {
reset();
this.shakeListener.onShake();
}
float f2 = currentTimestamp - this.lastShakeTimestamp;
f = ShakeDetectorKt.SHAKING_WINDOW_NS;
if (f2 > f) {
reset();
}
}
private final void recordShake(long timestamp) {
this.lastShakeTimestamp = timestamp;
this.numShakes++;
}
private final void reset() {
this.numShakes = 0;
this.accelerationX = 0.0f;
this.accelerationY = 0.0f;
this.accelerationZ = 0.0f;
}
@Override // android.hardware.SensorEventListener
public void onAccuracyChanged(@NotNull Sensor sensor, int i) {
sensor.getClass();
}
@Override // android.hardware.SensorEventListener
public void onSensorChanged(@NotNull SensorEvent sensorEvent) {
long j;
sensorEvent.getClass();
long j2 = sensorEvent.timestamp - this.lastTimestamp;
j = ShakeDetectorKt.MIN_TIME_BETWEEN_SAMPLES_NS;
if (j2 < j) {
return;
}
float[] fArr = sensorEvent.values;
float f = fArr[0];
float f2 = fArr[1];
float f3 = fArr[2] - 9.80665f;
this.lastTimestamp = sensorEvent.timestamp;
if (atLeastRequiredForce(f) && this.accelerationX * f <= 0.0f) {
recordShake(sensorEvent.timestamp);
this.accelerationX = f;
} else if (atLeastRequiredForce(f2) && this.accelerationY * f2 <= 0.0f) {
recordShake(sensorEvent.timestamp);
this.accelerationY = f2;
} else if (atLeastRequiredForce(f3) && this.accelerationZ * f3 <= 0.0f) {
recordShake(sensorEvent.timestamp);
this.accelerationZ = f3;
}
maybeDispatchShake(sensorEvent.timestamp);
}
public final void start(@NotNull SensorManager manager) {
manager.getClass();
Sensor defaultSensor = manager.getDefaultSensor(1);
if (defaultSensor == null) {
return;
}
this.sensorManager = manager;
this.lastTimestamp = -1L;
manager.registerListener(this, defaultSensor, 2);
this.lastShakeTimestamp = 0L;
reset();
}
public final void stop() {
SensorManager sensorManager = this.sensorManager;
if (sensorManager != null) {
sensorManager.unregisterListener(this);
}
this.sensorManager = null;
}
/* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
@JvmOverloads
public ShakeDetector(@NotNull ShakeListener shakeListener) {
this(shakeListener, 0, 2, null);
shakeListener.getClass();
}
public /* synthetic */ ShakeDetector(ShakeListener shakeListener, int i, int i2, DefaultConstructorMarker defaultConstructorMarker) {
this(shakeListener, (i2 & 2) != 0 ? 1 : i);
}
}