diff options
Diffstat (limited to 'java/com/android/incallui/answer/impl/classifier')
13 files changed, 249 insertions, 251 deletions
diff --git a/java/com/android/incallui/answer/impl/classifier/AccelerationClassifier.java b/java/com/android/incallui/answer/impl/classifier/AccelerationClassifier.java index ac504444e..ae0d1c800 100644 --- a/java/com/android/incallui/answer/impl/classifier/AccelerationClassifier.java +++ b/java/com/android/incallui/answer/impl/classifier/AccelerationClassifier.java @@ -29,10 +29,10 @@ import java.util.Map; * the speed of a part. */ class AccelerationClassifier extends StrokeClassifier { - private final Map<Stroke, Data> mStrokeMap = new ArrayMap<>(); + private final Map<Stroke, Data> strokeMap = new ArrayMap<>(); public AccelerationClassifier(ClassifierData classifierData) { - mClassifierData = classifierData; + this.classifierData = classifierData; } @Override @@ -45,23 +45,23 @@ class AccelerationClassifier extends StrokeClassifier { int action = event.getActionMasked(); if (action == MotionEvent.ACTION_DOWN) { - mStrokeMap.clear(); + strokeMap.clear(); } for (int i = 0; i < event.getPointerCount(); i++) { - Stroke stroke = mClassifierData.getStroke(event.getPointerId(i)); + Stroke stroke = classifierData.getStroke(event.getPointerId(i)); Point point = stroke.getPoints().get(stroke.getPoints().size() - 1); - if (mStrokeMap.get(stroke) == null) { - mStrokeMap.put(stroke, new Data(point)); + if (strokeMap.get(stroke) == null) { + strokeMap.put(stroke, new Data(point)); } else { - mStrokeMap.get(stroke).addPoint(point); + strokeMap.get(stroke).addPoint(point); } } } @Override public float getFalseTouchEvaluation(Stroke stroke) { - Data data = mStrokeMap.get(stroke); + Data data = strokeMap.get(stroke); return 2 * SpeedRatioEvaluator.evaluate(data.maxSpeedRatio); } diff --git a/java/com/android/incallui/answer/impl/classifier/AnglesClassifier.java b/java/com/android/incallui/answer/impl/classifier/AnglesClassifier.java index dbfbcfc1c..24f04c438 100644 --- a/java/com/android/incallui/answer/impl/classifier/AnglesClassifier.java +++ b/java/com/android/incallui/answer/impl/classifier/AnglesClassifier.java @@ -47,10 +47,10 @@ import java.util.Map; * angels or right angles) */ class AnglesClassifier extends StrokeClassifier { - private Map<Stroke, Data> mStrokeMap = new ArrayMap<>(); + private Map<Stroke, Data> strokeMap = new ArrayMap<>(); public AnglesClassifier(ClassifierData classifierData) { - mClassifierData = classifierData; + this.classifierData = classifierData; } @Override @@ -63,22 +63,22 @@ class AnglesClassifier extends StrokeClassifier { int action = event.getActionMasked(); if (action == MotionEvent.ACTION_DOWN) { - mStrokeMap.clear(); + strokeMap.clear(); } for (int i = 0; i < event.getPointerCount(); i++) { - Stroke stroke = mClassifierData.getStroke(event.getPointerId(i)); + Stroke stroke = classifierData.getStroke(event.getPointerId(i)); - if (mStrokeMap.get(stroke) == null) { - mStrokeMap.put(stroke, new Data()); + if (strokeMap.get(stroke) == null) { + strokeMap.put(stroke, new Data()); } - mStrokeMap.get(stroke).addPoint(stroke.getPoints().get(stroke.getPoints().size() - 1)); + strokeMap.get(stroke).addPoint(stroke.getPoints().get(stroke.getPoints().size() - 1)); } } @Override public float getFalseTouchEvaluation(Stroke stroke) { - Data data = mStrokeMap.get(stroke); + Data data = strokeMap.get(stroke); return AnglesVarianceEvaluator.evaluate(data.getAnglesVariance()) + AnglesPercentageEvaluator.evaluate(data.getAnglesPercentage()); } @@ -87,82 +87,82 @@ class AnglesClassifier extends StrokeClassifier { private static final float ANGLE_DEVIATION = (float) Math.PI / 20.0f; private static final float MIN_MOVE_DIST_DP = .01f; - private List<Point> mLastThreePoints = new ArrayList<>(); - private float mFirstAngleVariance; - private float mPreviousAngle; - private float mBiggestAngle; - private float mSumSquares; - private float mSecondSumSquares; - private float mSum; - private float mSecondSum; - private float mCount; - private float mSecondCount; - private float mFirstLength; - private float mLength; - private float mAnglesCount; - private float mLeftAngles; - private float mRightAngles; - private float mStraightAngles; + private List<Point> lastThreePoints = new ArrayList<>(); + private float firstAngleVariance; + private float previousAngle; + private float biggestAngle; + private float sumSquares; + private float secondSumSquares; + private float sum; + private float secondSum; + private float count; + private float secondCount; + private float firstLength; + private float length; + private float anglesCount; + private float leftAngles; + private float rightAngles; + private float straightAngles; public Data() { - mFirstAngleVariance = 0.0f; - mPreviousAngle = (float) Math.PI; - mBiggestAngle = 0.0f; - mSumSquares = mSecondSumSquares = 0.0f; - mSum = mSecondSum = 0.0f; - mCount = mSecondCount = 1.0f; - mLength = mFirstLength = 0.0f; - mAnglesCount = mLeftAngles = mRightAngles = mStraightAngles = 0.0f; + firstAngleVariance = 0.0f; + previousAngle = (float) Math.PI; + biggestAngle = 0.0f; + sumSquares = secondSumSquares = 0.0f; + sum = secondSum = 0.0f; + count = secondCount = 1.0f; + length = firstLength = 0.0f; + anglesCount = leftAngles = rightAngles = straightAngles = 0.0f; } public void addPoint(Point point) { // Checking if the added point is different than the previously added point // Repetitions and short distances are being ignored so that proper angles are calculated. - if (mLastThreePoints.isEmpty() - || (!mLastThreePoints.get(mLastThreePoints.size() - 1).equals(point) - && (mLastThreePoints.get(mLastThreePoints.size() - 1).dist(point) + if (lastThreePoints.isEmpty() + || (!lastThreePoints.get(lastThreePoints.size() - 1).equals(point) + && (lastThreePoints.get(lastThreePoints.size() - 1).dist(point) > MIN_MOVE_DIST_DP))) { - if (!mLastThreePoints.isEmpty()) { - mLength += mLastThreePoints.get(mLastThreePoints.size() - 1).dist(point); + if (!lastThreePoints.isEmpty()) { + length += lastThreePoints.get(lastThreePoints.size() - 1).dist(point); } - mLastThreePoints.add(point); - if (mLastThreePoints.size() == 4) { - mLastThreePoints.remove(0); + lastThreePoints.add(point); + if (lastThreePoints.size() == 4) { + lastThreePoints.remove(0); float angle = - mLastThreePoints.get(1).getAngle(mLastThreePoints.get(0), mLastThreePoints.get(2)); + lastThreePoints.get(1).getAngle(lastThreePoints.get(0), lastThreePoints.get(2)); - mAnglesCount++; + anglesCount++; if (angle < Math.PI - ANGLE_DEVIATION) { - mLeftAngles++; + leftAngles++; } else if (angle <= Math.PI + ANGLE_DEVIATION) { - mStraightAngles++; + straightAngles++; } else { - mRightAngles++; + rightAngles++; } - float difference = angle - mPreviousAngle; + float difference = angle - previousAngle; // If this is the biggest angle of the stroke so then we save the value of // the angle variance so far and start to count the values for the angle // variance of the second part. - if (mBiggestAngle < angle) { - mBiggestAngle = angle; - mFirstLength = mLength; - mFirstAngleVariance = getAnglesVariance(mSumSquares, mSum, mCount); - mSecondSumSquares = 0.0f; - mSecondSum = 0.0f; - mSecondCount = 1.0f; + if (biggestAngle < angle) { + biggestAngle = angle; + firstLength = length; + firstAngleVariance = getAnglesVariance(sumSquares, sum, count); + secondSumSquares = 0.0f; + secondSum = 0.0f; + secondCount = 1.0f; } else { - mSecondSum += difference; - mSecondSumSquares += difference * difference; - mSecondCount += 1.0f; + secondSum += difference; + secondSumSquares += difference * difference; + secondCount += 1.0f; } - mSum += difference; - mSumSquares += difference * difference; - mCount += 1.0f; - mPreviousAngle = angle; + sum += difference; + sumSquares += difference * difference; + count += 1.0f; + previousAngle = angle; } } } @@ -172,22 +172,21 @@ class AnglesClassifier extends StrokeClassifier { } public float getAnglesVariance() { - float anglesVariance = getAnglesVariance(mSumSquares, mSum, mCount); - if (mFirstLength < mLength / 2f) { + float anglesVariance = getAnglesVariance(sumSquares, sum, count); + if (firstLength < length / 2f) { anglesVariance = Math.min( anglesVariance, - mFirstAngleVariance - + getAnglesVariance(mSecondSumSquares, mSecondSum, mSecondCount)); + firstAngleVariance + getAnglesVariance(secondSumSquares, secondSum, secondCount)); } return anglesVariance; } public float getAnglesPercentage() { - if (mAnglesCount == 0.0f) { + if (anglesCount == 0.0f) { return 1.0f; } - return (Math.max(mLeftAngles, mRightAngles) + mStraightAngles) / mAnglesCount; + return (Math.max(leftAngles, rightAngles) + straightAngles) / anglesCount; } } } diff --git a/java/com/android/incallui/answer/impl/classifier/Classifier.java b/java/com/android/incallui/answer/impl/classifier/Classifier.java index c6fbff327..1baa6b4f4 100644 --- a/java/com/android/incallui/answer/impl/classifier/Classifier.java +++ b/java/com/android/incallui/answer/impl/classifier/Classifier.java @@ -23,7 +23,7 @@ import android.view.MotionEvent; abstract class Classifier { /** Contains all the information about touch events from which the classifier can query */ - protected ClassifierData mClassifierData; + protected ClassifierData classifierData; /** Informs the classifier that a new touch event has occurred */ public void onTouchEvent(MotionEvent event) {} diff --git a/java/com/android/incallui/answer/impl/classifier/ClassifierData.java b/java/com/android/incallui/answer/impl/classifier/ClassifierData.java index ae07d27a0..fe3fbe0cf 100644 --- a/java/com/android/incallui/answer/impl/classifier/ClassifierData.java +++ b/java/com/android/incallui/answer/impl/classifier/ClassifierData.java @@ -26,31 +26,31 @@ import java.util.concurrent.TimeUnit; * example, provide information on the current touch state. */ class ClassifierData { - private SparseArray<Stroke> mCurrentStrokes = new SparseArray<>(); - private ArrayList<Stroke> mEndingStrokes = new ArrayList<>(); - private final float mDpi; - private final float mScreenHeight; + private SparseArray<Stroke> currentStrokes = new SparseArray<>(); + private ArrayList<Stroke> endingStrokes = new ArrayList<>(); + private final float dpi; + private final float screenHeight; public ClassifierData(float dpi, float screenHeight) { - mDpi = dpi; - mScreenHeight = screenHeight / dpi; + this.dpi = dpi; + this.screenHeight = screenHeight / dpi; } public void update(MotionEvent event) { - mEndingStrokes.clear(); + endingStrokes.clear(); int action = event.getActionMasked(); if (action == MotionEvent.ACTION_DOWN) { - mCurrentStrokes.clear(); + currentStrokes.clear(); } for (int i = 0; i < event.getPointerCount(); i++) { int id = event.getPointerId(i); - if (mCurrentStrokes.get(id) == null) { + if (currentStrokes.get(id) == null) { // TODO (keyboardr): See if there's a way to use event.getEventTimeNanos() instead - mCurrentStrokes.put( - id, new Stroke(TimeUnit.MILLISECONDS.toNanos(event.getEventTime()), mDpi)); + currentStrokes.put( + id, new Stroke(TimeUnit.MILLISECONDS.toNanos(event.getEventTime()), dpi)); } - mCurrentStrokes + currentStrokes .get(id) .addPoint( event.getX(i), event.getY(i), TimeUnit.MILLISECONDS.toNanos(event.getEventTime())); @@ -58,27 +58,27 @@ class ClassifierData { if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || (action == MotionEvent.ACTION_POINTER_UP && i == event.getActionIndex())) { - mEndingStrokes.add(getStroke(id)); + endingStrokes.add(getStroke(id)); } } } void cleanUp(MotionEvent event) { - mEndingStrokes.clear(); + endingStrokes.clear(); int action = event.getActionMasked(); for (int i = 0; i < event.getPointerCount(); i++) { int id = event.getPointerId(i); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || (action == MotionEvent.ACTION_POINTER_UP && i == event.getActionIndex())) { - mCurrentStrokes.remove(id); + currentStrokes.remove(id); } } } /** @return the list of Strokes which are ending in the recently added MotionEvent */ public ArrayList<Stroke> getEndingStrokes() { - return mEndingStrokes; + return endingStrokes; } /** @@ -86,11 +86,11 @@ class ClassifierData { * @return the Stroke assigned to the id */ public Stroke getStroke(int id) { - return mCurrentStrokes.get(id); + return currentStrokes.get(id); } /** @return the height of the screen in inches */ public float getScreenHeight() { - return mScreenHeight; + return screenHeight; } } diff --git a/java/com/android/incallui/answer/impl/classifier/EndPointLengthClassifier.java b/java/com/android/incallui/answer/impl/classifier/EndPointLengthClassifier.java index 95b317638..a111ccc70 100644 --- a/java/com/android/incallui/answer/impl/classifier/EndPointLengthClassifier.java +++ b/java/com/android/incallui/answer/impl/classifier/EndPointLengthClassifier.java @@ -21,7 +21,7 @@ package com.android.incallui.answer.impl.classifier; */ class EndPointLengthClassifier extends StrokeClassifier { public EndPointLengthClassifier(ClassifierData classifierData) { - mClassifierData = classifierData; + this.classifierData = classifierData; } @Override diff --git a/java/com/android/incallui/answer/impl/classifier/EndPointRatioClassifier.java b/java/com/android/incallui/answer/impl/classifier/EndPointRatioClassifier.java index 01a35c126..4336e00da 100644 --- a/java/com/android/incallui/answer/impl/classifier/EndPointRatioClassifier.java +++ b/java/com/android/incallui/answer/impl/classifier/EndPointRatioClassifier.java @@ -22,7 +22,7 @@ package com.android.incallui.answer.impl.classifier; */ class EndPointRatioClassifier extends StrokeClassifier { public EndPointRatioClassifier(ClassifierData classifierData) { - mClassifierData = classifierData; + this.classifierData = classifierData; } @Override diff --git a/java/com/android/incallui/answer/impl/classifier/FalsingManager.java b/java/com/android/incallui/answer/impl/classifier/FalsingManager.java index 9cdd888d1..3deff8852 100644 --- a/java/com/android/incallui/answer/impl/classifier/FalsingManager.java +++ b/java/com/android/incallui/answer/impl/classifier/FalsingManager.java @@ -36,23 +36,23 @@ public class FalsingManager implements SensorEventListener { Sensor.TYPE_PROXIMITY, }; - private final SensorManager mSensorManager; - private final HumanInteractionClassifier mHumanInteractionClassifier; - private final AccessibilityManager mAccessibilityManager; + private final SensorManager sensorManager; + private final HumanInteractionClassifier humanInteractionClassifier; + private final AccessibilityManager accessibilityManager; - private boolean mSessionActive = false; - private boolean mScreenOn; + private boolean sessionActive = false; + private boolean screenOn; public FalsingManager(Context context) { - mSensorManager = context.getSystemService(SensorManager.class); - mAccessibilityManager = context.getSystemService(AccessibilityManager.class); - mHumanInteractionClassifier = new HumanInteractionClassifier(context); - mScreenOn = context.getSystemService(PowerManager.class).isInteractive(); + sensorManager = context.getSystemService(SensorManager.class); + accessibilityManager = context.getSystemService(AccessibilityManager.class); + humanInteractionClassifier = new HumanInteractionClassifier(context); + screenOn = context.getSystemService(PowerManager.class).isInteractive(); } /** Returns {@code true} iff the FalsingManager is enabled and able to classify touches */ public boolean isEnabled() { - return mHumanInteractionClassifier.isEnabled(); + return humanInteractionClassifier.isEnabled(); } /** @@ -62,8 +62,8 @@ public class FalsingManager implements SensorEventListener { public boolean isFalseTouch() { // Touch exploration triggers false positives in the classifier and // already sufficiently prevents false unlocks. - return !mAccessibilityManager.isTouchExplorationEnabled() - && mHumanInteractionClassifier.isFalseTouch(); + return !accessibilityManager.isTouchExplorationEnabled() + && humanInteractionClassifier.isFalseTouch(); } /** @@ -71,7 +71,7 @@ public class FalsingManager implements SensorEventListener { * tracking changes if the manager is enabled. */ public void onScreenOn() { - mScreenOn = true; + screenOn = true; sessionEntrypoint(); } @@ -80,7 +80,7 @@ public class FalsingManager implements SensorEventListener { * will cause the manager to stop tracking changes. */ public void onScreenOff() { - mScreenOn = false; + screenOn = false; sessionExitpoint(); } @@ -90,25 +90,25 @@ public class FalsingManager implements SensorEventListener { * @param event MotionEvent to be classified as human or false. */ public void onTouchEvent(MotionEvent event) { - if (mSessionActive) { - mHumanInteractionClassifier.onTouchEvent(event); + if (sessionActive) { + humanInteractionClassifier.onTouchEvent(event); } } @Override public synchronized void onSensorChanged(SensorEvent event) { - mHumanInteractionClassifier.onSensorChanged(event); + humanInteractionClassifier.onSensorChanged(event); } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) {} private boolean shouldSessionBeActive() { - return isEnabled() && mScreenOn; + return isEnabled() && screenOn; } private boolean sessionEntrypoint() { - if (!mSessionActive && shouldSessionBeActive()) { + if (!sessionActive && shouldSessionBeActive()) { onSessionStart(); return true; } @@ -116,16 +116,16 @@ public class FalsingManager implements SensorEventListener { } private void sessionExitpoint() { - if (mSessionActive && !shouldSessionBeActive()) { - mSessionActive = false; - mSensorManager.unregisterListener(this); + if (sessionActive && !shouldSessionBeActive()) { + sessionActive = false; + sensorManager.unregisterListener(this); } } private void onSessionStart() { - mSessionActive = true; + sessionActive = true; - if (mHumanInteractionClassifier.isEnabled()) { + if (humanInteractionClassifier.isEnabled()) { registerSensors(CLASSIFIER_SENSORS); } } @@ -134,11 +134,11 @@ public class FalsingManager implements SensorEventListener { Trace.beginSection("FalsingManager.registerSensors"); for (int sensorType : sensors) { Trace.beginSection("get sensor " + sensorType); - Sensor s = mSensorManager.getDefaultSensor(sensorType); + Sensor s = sensorManager.getDefaultSensor(sensorType); Trace.endSection(); if (s != null) { Trace.beginSection("register"); - mSensorManager.registerListener(this, s, SensorManager.SENSOR_DELAY_GAME); + sensorManager.registerListener(this, s, SensorManager.SENSOR_DELAY_GAME); Trace.endSection(); } } diff --git a/java/com/android/incallui/answer/impl/classifier/HistoryEvaluator.java b/java/com/android/incallui/answer/impl/classifier/HistoryEvaluator.java index 3f302c65f..c0256a5d8 100644 --- a/java/com/android/incallui/answer/impl/classifier/HistoryEvaluator.java +++ b/java/com/android/incallui/answer/impl/classifier/HistoryEvaluator.java @@ -17,7 +17,6 @@ package com.android.incallui.answer.impl.classifier; import android.os.SystemClock; - import java.util.ArrayList; /** @@ -28,27 +27,27 @@ class HistoryEvaluator { private static final float HISTORY_FACTOR = 0.9f; private static final float EPSILON = 1e-5f; - private final ArrayList<Data> mStrokes = new ArrayList<>(); - private final ArrayList<Data> mGestureWeights = new ArrayList<>(); - private long mLastUpdate; + private final ArrayList<Data> strokes = new ArrayList<>(); + private final ArrayList<Data> gestureWeights = new ArrayList<>(); + private long lastUpdate; public HistoryEvaluator() { - mLastUpdate = SystemClock.elapsedRealtime(); + lastUpdate = SystemClock.elapsedRealtime(); } public void addStroke(float evaluation) { decayValue(); - mStrokes.add(new Data(evaluation)); + strokes.add(new Data(evaluation)); } public void addGesture(float evaluation) { decayValue(); - mGestureWeights.add(new Data(evaluation)); + gestureWeights.add(new Data(evaluation)); } /** Calculates the weighted average of strokes and adds to it the weighted average of gestures */ public float getEvaluation() { - return weightedAverage(mStrokes) + weightedAverage(mGestureWeights); + return weightedAverage(strokes) + weightedAverage(gestureWeights); } private float weightedAverage(ArrayList<Data> list) { @@ -71,16 +70,16 @@ class HistoryEvaluator { private void decayValue() { long time = SystemClock.elapsedRealtime(); - if (time <= mLastUpdate) { + if (time <= lastUpdate) { return; } // All weights are multiplied by HISTORY_FACTOR after each INTERVAL milliseconds. - float factor = (float) Math.pow(HISTORY_FACTOR, (time - mLastUpdate) / INTERVAL); + float factor = (float) Math.pow(HISTORY_FACTOR, (time - lastUpdate) / INTERVAL); - decayValue(mStrokes, factor); - decayValue(mGestureWeights, factor); - mLastUpdate = time; + decayValue(strokes, factor); + decayValue(gestureWeights, factor); + lastUpdate = time; } private void decayValue(ArrayList<Data> list, float factor) { diff --git a/java/com/android/incallui/answer/impl/classifier/HumanInteractionClassifier.java b/java/com/android/incallui/answer/impl/classifier/HumanInteractionClassifier.java index 5e83dfc78..b661579a3 100644 --- a/java/com/android/incallui/answer/impl/classifier/HumanInteractionClassifier.java +++ b/java/com/android/incallui/answer/impl/classifier/HumanInteractionClassifier.java @@ -28,10 +28,10 @@ class HumanInteractionClassifier extends Classifier { private static final String CONFIG_ANSWER_FALSE_TOUCH_DETECTION_ENABLED = "answer_false_touch_detection_enabled"; - private final StrokeClassifier[] mStrokeClassifiers; - private final GestureClassifier[] mGestureClassifiers; - private final HistoryEvaluator mHistoryEvaluator; - private final boolean mEnabled; + private final StrokeClassifier[] strokeClassifiers; + private final GestureClassifier[] gestureClassifiers; + private final HistoryEvaluator historyEvaluator; + private final boolean enabled; HumanInteractionClassifier(Context context) { DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); @@ -41,28 +41,28 @@ class HumanInteractionClassifier extends Classifier { // take the average. // Note that xdpi and ydpi are the physical pixels per inch and are not affected by scaling. float dpi = (displayMetrics.xdpi + displayMetrics.ydpi) / 2.0f; - mClassifierData = new ClassifierData(dpi, displayMetrics.heightPixels); - mHistoryEvaluator = new HistoryEvaluator(); - mEnabled = + classifierData = new ClassifierData(dpi, displayMetrics.heightPixels); + historyEvaluator = new HistoryEvaluator(); + enabled = ConfigProviderBindings.get(context) .getBoolean(CONFIG_ANSWER_FALSE_TOUCH_DETECTION_ENABLED, true); - mStrokeClassifiers = + strokeClassifiers = new StrokeClassifier[] { - new AnglesClassifier(mClassifierData), - new SpeedClassifier(mClassifierData), - new DurationCountClassifier(mClassifierData), - new EndPointRatioClassifier(mClassifierData), - new EndPointLengthClassifier(mClassifierData), - new AccelerationClassifier(mClassifierData), - new SpeedAnglesClassifier(mClassifierData), - new LengthCountClassifier(mClassifierData), - new DirectionClassifier(mClassifierData) + new AnglesClassifier(classifierData), + new SpeedClassifier(classifierData), + new DurationCountClassifier(classifierData), + new EndPointRatioClassifier(classifierData), + new EndPointLengthClassifier(classifierData), + new AccelerationClassifier(classifierData), + new SpeedAnglesClassifier(classifierData), + new LengthCountClassifier(classifierData), + new DirectionClassifier(classifierData) }; - mGestureClassifiers = + gestureClassifiers = new GestureClassifier[] { - new PointerCountClassifier(mClassifierData), new ProximityClassifier(mClassifierData) + new PointerCountClassifier(classifierData), new ProximityClassifier(classifierData) }; } @@ -80,59 +80,59 @@ class HumanInteractionClassifier extends Classifier { } private void addTouchEvent(MotionEvent event) { - mClassifierData.update(event); + classifierData.update(event); - for (StrokeClassifier c : mStrokeClassifiers) { + for (StrokeClassifier c : strokeClassifiers) { c.onTouchEvent(event); } - for (GestureClassifier c : mGestureClassifiers) { + for (GestureClassifier c : gestureClassifiers) { c.onTouchEvent(event); } - int size = mClassifierData.getEndingStrokes().size(); + int size = classifierData.getEndingStrokes().size(); for (int i = 0; i < size; i++) { - Stroke stroke = mClassifierData.getEndingStrokes().get(i); + Stroke stroke = classifierData.getEndingStrokes().get(i); float evaluation = 0.0f; - for (StrokeClassifier c : mStrokeClassifiers) { + for (StrokeClassifier c : strokeClassifiers) { float e = c.getFalseTouchEvaluation(stroke); evaluation += e; } - mHistoryEvaluator.addStroke(evaluation); + historyEvaluator.addStroke(evaluation); } int action = event.getActionMasked(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { float evaluation = 0.0f; - for (GestureClassifier c : mGestureClassifiers) { + for (GestureClassifier c : gestureClassifiers) { float e = c.getFalseTouchEvaluation(); evaluation += e; } - mHistoryEvaluator.addGesture(evaluation); + historyEvaluator.addGesture(evaluation); } - mClassifierData.cleanUp(event); + classifierData.cleanUp(event); } @Override public void onSensorChanged(SensorEvent event) { - for (Classifier c : mStrokeClassifiers) { + for (Classifier c : strokeClassifiers) { c.onSensorChanged(event); } - for (Classifier c : mGestureClassifiers) { + for (Classifier c : gestureClassifiers) { c.onSensorChanged(event); } } boolean isFalseTouch() { - float evaluation = mHistoryEvaluator.getEvaluation(); + float evaluation = historyEvaluator.getEvaluation(); return evaluation >= 5.0f; } public boolean isEnabled() { - return mEnabled; + return enabled; } @Override diff --git a/java/com/android/incallui/answer/impl/classifier/PointerCountClassifier.java b/java/com/android/incallui/answer/impl/classifier/PointerCountClassifier.java index 070de6c9b..b3ee84984 100644 --- a/java/com/android/incallui/answer/impl/classifier/PointerCountClassifier.java +++ b/java/com/android/incallui/answer/impl/classifier/PointerCountClassifier.java @@ -20,10 +20,10 @@ import android.view.MotionEvent; /** A classifier which looks at the total number of traces in the whole gesture. */ class PointerCountClassifier extends GestureClassifier { - private int mCount; + private int count; public PointerCountClassifier(ClassifierData classifierData) { - mCount = 0; + count = 0; } @Override @@ -36,16 +36,16 @@ class PointerCountClassifier extends GestureClassifier { int action = event.getActionMasked(); if (action == MotionEvent.ACTION_DOWN) { - mCount = 1; + count = 1; } if (action == MotionEvent.ACTION_POINTER_DOWN) { - ++mCount; + ++count; } } @Override public float getFalseTouchEvaluation() { - return PointerCountEvaluator.evaluate(mCount); + return PointerCountEvaluator.evaluate(count); } } diff --git a/java/com/android/incallui/answer/impl/classifier/ProximityClassifier.java b/java/com/android/incallui/answer/impl/classifier/ProximityClassifier.java index 28701ea6d..b63f15d53 100644 --- a/java/com/android/incallui/answer/impl/classifier/ProximityClassifier.java +++ b/java/com/android/incallui/answer/impl/classifier/ProximityClassifier.java @@ -26,11 +26,11 @@ import java.util.concurrent.TimeUnit; * the proximity sensor showing the near state during the whole gesture */ class ProximityClassifier extends GestureClassifier { - private long mGestureStartTimeNano; - private long mNearStartTimeNano; - private long mNearDuration; - private boolean mNear; - private float mAverageNear; + private long gestureStartTimeNano; + private long nearStartTimeNano; + private long nearDuration; + private boolean near; + private float averageNear; public ProximityClassifier(ClassifierData classifierData) {} @@ -51,19 +51,19 @@ class ProximityClassifier extends GestureClassifier { int action = event.getActionMasked(); if (action == MotionEvent.ACTION_DOWN) { - mGestureStartTimeNano = TimeUnit.MILLISECONDS.toNanos(event.getEventTime()); - mNearStartTimeNano = TimeUnit.MILLISECONDS.toNanos(event.getEventTime()); - mNearDuration = 0; + gestureStartTimeNano = TimeUnit.MILLISECONDS.toNanos(event.getEventTime()); + nearStartTimeNano = TimeUnit.MILLISECONDS.toNanos(event.getEventTime()); + nearDuration = 0; } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { - update(mNear, TimeUnit.MILLISECONDS.toNanos(event.getEventTime())); - long duration = TimeUnit.MILLISECONDS.toNanos(event.getEventTime()) - mGestureStartTimeNano; + update(near, TimeUnit.MILLISECONDS.toNanos(event.getEventTime())); + long duration = TimeUnit.MILLISECONDS.toNanos(event.getEventTime()) - gestureStartTimeNano; if (duration == 0) { - mAverageNear = mNear ? 1.0f : 0.0f; + averageNear = near ? 1.0f : 0.0f; } else { - mAverageNear = (float) mNearDuration / (float) duration; + averageNear = (float) nearDuration / (float) duration; } } } @@ -75,23 +75,23 @@ class ProximityClassifier extends GestureClassifier { private void update(boolean near, long timestampNano) { // This if is necessary because MotionEvents and SensorEvents do not come in // chronological order - if (timestampNano > mNearStartTimeNano) { + if (timestampNano > nearStartTimeNano) { // if the state before was near then add the difference of the current time and // mNearStartTimeNano to mNearDuration. - if (mNear) { - mNearDuration += timestampNano - mNearStartTimeNano; + if (this.near) { + nearDuration += timestampNano - nearStartTimeNano; } // if the new state is near, set mNearStartTimeNano equal to this moment. if (near) { - mNearStartTimeNano = timestampNano; + nearStartTimeNano = timestampNano; } } - mNear = near; + this.near = near; } @Override public float getFalseTouchEvaluation() { - return ProximityEvaluator.evaluate(mAverageNear); + return ProximityEvaluator.evaluate(averageNear); } } diff --git a/java/com/android/incallui/answer/impl/classifier/SpeedAnglesClassifier.java b/java/com/android/incallui/answer/impl/classifier/SpeedAnglesClassifier.java index 36ae3ad7c..034c4fea3 100644 --- a/java/com/android/incallui/answer/impl/classifier/SpeedAnglesClassifier.java +++ b/java/com/android/incallui/answer/impl/classifier/SpeedAnglesClassifier.java @@ -33,10 +33,10 @@ import java.util.Map; * a good stroke is most often increases, so most of these angels should be in this interval. */ class SpeedAnglesClassifier extends StrokeClassifier { - private Map<Stroke, Data> mStrokeMap = new ArrayMap<>(); + private Map<Stroke, Data> strokeMap = new ArrayMap<>(); public SpeedAnglesClassifier(ClassifierData classifierData) { - mClassifierData = classifierData; + this.classifierData = classifierData; } @Override @@ -49,27 +49,27 @@ class SpeedAnglesClassifier extends StrokeClassifier { int action = event.getActionMasked(); if (action == MotionEvent.ACTION_DOWN) { - mStrokeMap.clear(); + strokeMap.clear(); } for (int i = 0; i < event.getPointerCount(); i++) { - Stroke stroke = mClassifierData.getStroke(event.getPointerId(i)); + Stroke stroke = classifierData.getStroke(event.getPointerId(i)); - if (mStrokeMap.get(stroke) == null) { - mStrokeMap.put(stroke, new Data()); + if (strokeMap.get(stroke) == null) { + strokeMap.put(stroke, new Data()); } if (action != MotionEvent.ACTION_UP && action != MotionEvent.ACTION_CANCEL && !(action == MotionEvent.ACTION_POINTER_UP && i == event.getActionIndex())) { - mStrokeMap.get(stroke).addPoint(stroke.getPoints().get(stroke.getPoints().size() - 1)); + strokeMap.get(stroke).addPoint(stroke.getPoints().get(stroke.getPoints().size() - 1)); } } } @Override public float getFalseTouchEvaluation(Stroke stroke) { - Data data = mStrokeMap.get(stroke); + Data data = strokeMap.get(stroke); return SpeedVarianceEvaluator.evaluate(data.getAnglesVariance()) + SpeedAnglesPercentageEvaluator.evaluate(data.getAnglesPercentage()); } @@ -79,69 +79,69 @@ class SpeedAnglesClassifier extends StrokeClassifier { private static final float LENGTH_SCALE = 1.0f; private static final float ANGLE_DEVIATION = (float) Math.PI / 10.0f; - private List<Point> mLastThreePoints = new ArrayList<>(); - private Point mPreviousPoint; - private float mPreviousAngle; - private float mSumSquares; - private float mSum; - private float mCount; - private float mDist; - private float mAnglesCount; - private float mAcceleratingAngles; + private List<Point> lastThreePoints = new ArrayList<>(); + private Point previousPoint; + private float previousAngle; + private float sumSquares; + private float sum; + private float count; + private float dist; + private float anglesCount; + private float acceleratingAngles; public Data() { - mPreviousPoint = null; - mPreviousAngle = (float) Math.PI; - mSumSquares = 0.0f; - mSum = 0.0f; - mCount = 1.0f; - mDist = 0.0f; - mAnglesCount = mAcceleratingAngles = 0.0f; + previousPoint = null; + previousAngle = (float) Math.PI; + sumSquares = 0.0f; + sum = 0.0f; + count = 1.0f; + dist = 0.0f; + anglesCount = acceleratingAngles = 0.0f; } public void addPoint(Point point) { - if (mPreviousPoint != null) { - mDist += mPreviousPoint.dist(point); + if (previousPoint != null) { + dist += previousPoint.dist(point); } - mPreviousPoint = point; + previousPoint = point; Point speedPoint = - new Point((float) point.timeOffsetNano / DURATION_SCALE, mDist / LENGTH_SCALE); + new Point((float) point.timeOffsetNano / DURATION_SCALE, dist / LENGTH_SCALE); // Checking if the added point is different than the previously added point // Repetitions are being ignored so that proper angles are calculated. - if (mLastThreePoints.isEmpty() - || !mLastThreePoints.get(mLastThreePoints.size() - 1).equals(speedPoint)) { - mLastThreePoints.add(speedPoint); - if (mLastThreePoints.size() == 4) { - mLastThreePoints.remove(0); + if (lastThreePoints.isEmpty() + || !lastThreePoints.get(lastThreePoints.size() - 1).equals(speedPoint)) { + lastThreePoints.add(speedPoint); + if (lastThreePoints.size() == 4) { + lastThreePoints.remove(0); float angle = - mLastThreePoints.get(1).getAngle(mLastThreePoints.get(0), mLastThreePoints.get(2)); + lastThreePoints.get(1).getAngle(lastThreePoints.get(0), lastThreePoints.get(2)); - mAnglesCount++; + anglesCount++; if (angle >= (float) Math.PI - ANGLE_DEVIATION) { - mAcceleratingAngles++; + acceleratingAngles++; } - float difference = angle - mPreviousAngle; - mSum += difference; - mSumSquares += difference * difference; - mCount += 1.0f; - mPreviousAngle = angle; + float difference = angle - previousAngle; + sum += difference; + sumSquares += difference * difference; + count += 1.0f; + previousAngle = angle; } } } public float getAnglesVariance() { - return mSumSquares / mCount - (mSum / mCount) * (mSum / mCount); + return sumSquares / count - (sum / count) * (sum / count); } public float getAnglesPercentage() { - if (mAnglesCount == 0.0f) { + if (anglesCount == 0.0f) { return 1.0f; } - return (mAcceleratingAngles) / mAnglesCount; + return (acceleratingAngles) / anglesCount; } } } diff --git a/java/com/android/incallui/answer/impl/classifier/Stroke.java b/java/com/android/incallui/answer/impl/classifier/Stroke.java index c542d0f7c..a33424946 100644 --- a/java/com/android/incallui/answer/impl/classifier/Stroke.java +++ b/java/com/android/incallui/answer/impl/classifier/Stroke.java @@ -26,40 +26,40 @@ class Stroke { private static final float NANOS_TO_SECONDS = 1e9f; - private ArrayList<Point> mPoints = new ArrayList<>(); - private long mStartTimeNano; - private long mEndTimeNano; - private float mLength; - private final float mDpi; + private ArrayList<Point> points = new ArrayList<>(); + private long startTimeNano; + private long endTimeNano; + private float length; + private final float dpi; public Stroke(long eventTimeNano, float dpi) { - mDpi = dpi; - mStartTimeNano = mEndTimeNano = eventTimeNano; + this.dpi = dpi; + startTimeNano = endTimeNano = eventTimeNano; } public void addPoint(float x, float y, long eventTimeNano) { - mEndTimeNano = eventTimeNano; - Point point = new Point(x / mDpi, y / mDpi, eventTimeNano - mStartTimeNano); - if (!mPoints.isEmpty()) { - mLength += mPoints.get(mPoints.size() - 1).dist(point); + endTimeNano = eventTimeNano; + Point point = new Point(x / dpi, y / dpi, eventTimeNano - startTimeNano); + if (!points.isEmpty()) { + length += points.get(points.size() - 1).dist(point); } - mPoints.add(point); + points.add(point); } public int getCount() { - return mPoints.size(); + return points.size(); } public float getTotalLength() { - return mLength; + return length; } public float getEndPointLength() { - return mPoints.get(0).dist(mPoints.get(mPoints.size() - 1)); + return points.get(0).dist(points.get(points.size() - 1)); } public long getDurationNanos() { - return mEndTimeNano - mStartTimeNano; + return endTimeNano - startTimeNano; } public float getDurationSeconds() { @@ -67,6 +67,6 @@ class Stroke { } public ArrayList<Point> getPoints() { - return mPoints; + return points; } } |