Merge "Limit touch sampling rate for falsing." into qt-dev
This commit is contained in:
@@ -26,6 +26,9 @@ import java.util.ArrayList;
|
||||
* example, provide information on the current touch state.
|
||||
*/
|
||||
public class ClassifierData {
|
||||
private static final long MINIMUM_DT_NANOS = 16666666; // 60Hz
|
||||
private static final long MINIMUM_DT_SMEAR_NANOS = 2500000; // 2.5ms
|
||||
|
||||
private SparseArray<Stroke> mCurrentStrokes = new SparseArray<>();
|
||||
private ArrayList<Stroke> mEndingStrokes = new ArrayList<>();
|
||||
private final float mDpi;
|
||||
@@ -34,7 +37,18 @@ public class ClassifierData {
|
||||
mDpi = dpi;
|
||||
}
|
||||
|
||||
public void update(MotionEvent event) {
|
||||
/** Returns true if the event should be considered, false otherwise. */
|
||||
public boolean update(MotionEvent event) {
|
||||
// We limit to 60hz sampling. Drop anything happening faster than that.
|
||||
// Legacy code was created with an assumed sampling rate. As devices increase their
|
||||
// sampling rate, this creates potentialy false positives.
|
||||
if (event.getActionMasked() == MotionEvent.ACTION_MOVE
|
||||
&& mCurrentStrokes.size() != 0
|
||||
&& event.getEventTimeNano() - mCurrentStrokes.get(0).getLastEventTimeNano()
|
||||
< MINIMUM_DT_NANOS - MINIMUM_DT_SMEAR_NANOS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mEndingStrokes.clear();
|
||||
int action = event.getActionMasked();
|
||||
if (action == MotionEvent.ACTION_DOWN) {
|
||||
@@ -54,6 +68,8 @@ public class ClassifierData {
|
||||
mEndingStrokes.add(getStroke(id));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void cleanUp(MotionEvent event) {
|
||||
|
||||
@@ -151,7 +151,9 @@ public class HumanInteractionClassifier extends Classifier {
|
||||
}
|
||||
|
||||
private void addTouchEvent(MotionEvent event) {
|
||||
mClassifierData.update(event);
|
||||
if (!mClassifierData.update(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (StrokeClassifier c : mStrokeClassifiers) {
|
||||
c.onTouchEvent(event);
|
||||
|
||||
@@ -68,4 +68,12 @@ public class Stroke {
|
||||
public ArrayList<Point> getPoints() {
|
||||
return mPoints;
|
||||
}
|
||||
|
||||
public long getLastEventTimeNano() {
|
||||
if (mPoints.isEmpty()) {
|
||||
return mStartTimeNano;
|
||||
}
|
||||
|
||||
return mPoints.get(mPoints.size() - 1).timeOffsetNano;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user