Remove ShakeDetector
* It makes no sense to do that in app
This commit is contained in:
1 parent
c52c91e1c0
commit
4288bc790d
2 files changed
+1
-102
No files matched your search
@@ -32,7 +32,6 @@ import androidx.biometric.BiometricPrompt;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.hardware.ShakeDetector;
|
||||
import com.hippo.widget.lockpattern.LockPatternUtils;
|
||||
import com.hippo.widget.lockpattern.LockPatternView;
|
||||
import com.hippo.yorozuya.ObjectUtils;
|
||||
@@ -42,7 +41,7 @@ import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class SecurityScene extends SolidScene implements
|
||||
LockPatternView.OnPatternListener, ShakeDetector.OnShakeListener {
|
||||
LockPatternView.OnPatternListener{
|
||||
|
||||
private static final int MAX_RETRY_TIMES = 5;
|
||||
private static final String KEY_RETRY_TIMES = "retry_times";
|
||||
@@ -52,7 +51,6 @@ public class SecurityScene extends SolidScene implements
|
||||
|
||||
private SensorManager mSensorManager;
|
||||
private Sensor mAccelerometer;
|
||||
private ShakeDetector mShakeDetector;
|
||||
private BiometricPrompt.PromptInfo promptInfo;
|
||||
private BiometricPrompt biometricPrompt;
|
||||
private boolean canAuthenticate = false;
|
||||
@@ -72,10 +70,6 @@ public class SecurityScene extends SolidScene implements
|
||||
mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||
if (null != mSensorManager) {
|
||||
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
||||
if (null != mAccelerometer) {
|
||||
mShakeDetector = new ShakeDetector();
|
||||
mShakeDetector.setOnShakeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (null == savedInstanceState) {
|
||||
@@ -116,17 +110,12 @@ public class SecurityScene extends SolidScene implements
|
||||
|
||||
mSensorManager = null;
|
||||
mAccelerometer = null;
|
||||
mShakeDetector = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (null != mShakeDetector) {
|
||||
mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
|
||||
}
|
||||
|
||||
if (canAuthenticate) {
|
||||
startBiometricPrompt();
|
||||
}
|
||||
@@ -139,10 +128,6 @@ public class SecurityScene extends SolidScene implements
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
if (null != mShakeDetector) {
|
||||
mSensorManager.unregisterListener(mShakeDetector);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -205,17 +190,4 @@ public class SecurityScene extends SolidScene implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShake(int count) {
|
||||
if (count == 10) {
|
||||
MainActivity activity = getMainActivity();
|
||||
if (null == activity) {
|
||||
return;
|
||||
}
|
||||
Settings.putSecurity("");
|
||||
startSceneForCheckStep(CHECK_STEP_SECURITY, getArguments());
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package com.hippo.hardware;
|
||||
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
|
||||
// http://jasonmcreynolds.com/?p=388
|
||||
public class ShakeDetector implements SensorEventListener {
|
||||
|
||||
/*
|
||||
* The gForce that is necessary to register as shake.
|
||||
* Must be greater than 1G (one earth gravity unit).
|
||||
* You can install "G-Force", by Blake La Pierre
|
||||
* from the Google Play Store and run it to see how
|
||||
* many G's it takes to register a shake
|
||||
*/
|
||||
private static final float SHAKE_THRESHOLD_GRAVITY = 2.7F;
|
||||
private static final int SHAKE_SLOP_TIME_MS = 500;
|
||||
private static final int SHAKE_COUNT_RESET_TIME_MS = 3000;
|
||||
|
||||
private OnShakeListener mListener;
|
||||
private long mShakeTimestamp;
|
||||
private int mShakeCount;
|
||||
|
||||
public void setOnShakeListener(OnShakeListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
|
||||
if (mListener != null) {
|
||||
float x = event.values[0];
|
||||
float y = event.values[1];
|
||||
float z = event.values[2];
|
||||
|
||||
float gX = x / SensorManager.GRAVITY_EARTH;
|
||||
float gY = y / SensorManager.GRAVITY_EARTH;
|
||||
float gZ = z / SensorManager.GRAVITY_EARTH;
|
||||
|
||||
// gForce will be close to 1 when there is no movement.
|
||||
float gForce = (float) Math.sqrt(gX * gX + gY * gY + gZ * gZ);
|
||||
|
||||
if (gForce > SHAKE_THRESHOLD_GRAVITY) {
|
||||
final long now = System.currentTimeMillis();
|
||||
// ignore shake events too close to each other (500ms)
|
||||
if (mShakeTimestamp + SHAKE_SLOP_TIME_MS > now) {
|
||||
return;
|
||||
}
|
||||
|
||||
// reset the shake count after 3 seconds of no shakes
|
||||
if (mShakeTimestamp + SHAKE_COUNT_RESET_TIME_MS < now) {
|
||||
mShakeCount = 0;
|
||||
}
|
||||
|
||||
mShakeTimestamp = now;
|
||||
mShakeCount++;
|
||||
|
||||
mListener.onShake(mShakeCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnShakeListener {
|
||||
void onShake(int count);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user