Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 91be2f88 authored by Blazej Magnowski's avatar Blazej Magnowski
Browse files

notification drag down fix

Change-Id: I17ddf28a5096782fd42ab011f0dac002b152db0f
parent 6dc59b48
Loading
Loading
Loading
Loading
+4 −6
Original line number Original line Diff line number Diff line
@@ -28,12 +28,10 @@ import java.util.ArrayList;
public class ClassifierData {
public class ClassifierData {
    private SparseArray<Stroke> mCurrentStrokes = new SparseArray<>();
    private SparseArray<Stroke> mCurrentStrokes = new SparseArray<>();
    private ArrayList<Stroke> mEndingStrokes = new ArrayList<>();
    private ArrayList<Stroke> mEndingStrokes = new ArrayList<>();
    private float mXdpi;
    private final float mDpi;
    private float mYdpi;


    public ClassifierData(float xdpi, float ydpi) {
    public ClassifierData(float dpi) {
        mXdpi = xdpi;
        mDpi = dpi;
        mYdpi = ydpi;
    }
    }


    public void update(MotionEvent event) {
    public void update(MotionEvent event) {
@@ -46,7 +44,7 @@ public class ClassifierData {
        for (int i = 0; i < event.getPointerCount(); i++) {
        for (int i = 0; i < event.getPointerCount(); i++) {
            int id = event.getPointerId(i);
            int id = event.getPointerId(i);
            if (mCurrentStrokes.get(id) == null) {
            if (mCurrentStrokes.get(id) == null) {
                mCurrentStrokes.put(id, new Stroke(event.getEventTimeNano(), mXdpi, mYdpi));
                mCurrentStrokes.put(id, new Stroke(event.getEventTimeNano(), mDpi));
            }
            }
            mCurrentStrokes.get(id).addPoint(event.getX(i), event.getY(i),
            mCurrentStrokes.get(id).addPoint(event.getX(i), event.getY(i),
                    event.getEventTimeNano());
                    event.getEventTimeNano());
+69 −28
Original line number Original line Diff line number Diff line
@@ -23,8 +23,10 @@ import android.os.Build;
import android.os.Handler;
import android.os.Handler;
import android.os.UserHandle;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.MotionEvent;


import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.ArrayList;


/**
/**
@@ -32,6 +34,7 @@ import java.util.ArrayList;
 */
 */
public class HumanInteractionClassifier extends Classifier {
public class HumanInteractionClassifier extends Classifier {
    private static final String HIC_ENABLE = "HIC_enable";
    private static final String HIC_ENABLE = "HIC_enable";
    private static final float FINGER_DISTANCE = 0.1f;
    private static HumanInteractionClassifier sInstance = null;
    private static HumanInteractionClassifier sInstance = null;


    private final Handler mHandler = new Handler();
    private final Handler mHandler = new Handler();
@@ -39,11 +42,13 @@ public class HumanInteractionClassifier extends Classifier {


    private ArrayList<StrokeClassifier> mStrokeClassifiers = new ArrayList<>();
    private ArrayList<StrokeClassifier> mStrokeClassifiers = new ArrayList<>();
    private ArrayList<GestureClassifier> mGestureClassifiers = new ArrayList<>();
    private ArrayList<GestureClassifier> mGestureClassifiers = new ArrayList<>();
    private ArrayDeque<MotionEvent> mBufferedEvents = new ArrayDeque<>();
    private final int mStrokeClassifiersSize;
    private final int mStrokeClassifiersSize;
    private final int mGestureClassifiersSize;
    private final int mGestureClassifiersSize;
    private final float mDpi;


    private HistoryEvaluator mHistoryEvaluator;
    private HistoryEvaluator mHistoryEvaluator;
    private boolean mEnableClassifier = false;
    private boolean mEnableClassifier = true;
    private int mCurrentType = Classifier.GENERIC;
    private int mCurrentType = Classifier.GENERIC;


    protected final ContentObserver mSettingsObserver = new ContentObserver(mHandler) {
    protected final ContentObserver mSettingsObserver = new ContentObserver(mHandler) {
@@ -55,8 +60,13 @@ public class HumanInteractionClassifier extends Classifier {


    private HumanInteractionClassifier(Context context) {
    private HumanInteractionClassifier(Context context) {
        mContext = context;
        mContext = context;
        mClassifierData = new ClassifierData(mContext.getResources().getDisplayMetrics().xdpi,
        DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
                mContext.getResources().getDisplayMetrics().ydpi);

        // If the phone is rotated to landscape, the calculations would be wrong if xdpi and ydpi
        // were to be used separately. Due negligible differences in xdpi and ydpi we can just
        // take the average.
        mDpi = (displayMetrics.xdpi + displayMetrics.ydpi) / 2.0f;
        mClassifierData = new ClassifierData(mDpi);
        mHistoryEvaluator = new HistoryEvaluator();
        mHistoryEvaluator = new HistoryEvaluator();


        mStrokeClassifiers.add(new AnglesVarianceClassifier(mClassifierData));
        mStrokeClassifiers.add(new AnglesVarianceClassifier(mClassifierData));
@@ -101,7 +111,39 @@ public class HumanInteractionClassifier extends Classifier {


    @Override
    @Override
    public void onTouchEvent(MotionEvent event) {
    public void onTouchEvent(MotionEvent event) {
        if (mEnableClassifier) {
        if (!mEnableClassifier) {
            return;
        }

        // If the user is dragging down the notification, he might want to drag it down
        // enough to see the content, read it for a while and then lift the finger to open
        // the notification. This kind of motion scores very bad in the Classifier so the
        // MotionEvents which are close to the current position of the finger are not
        // sent to the classifiers until the finger moves far enough. When the finger if lifted
        // up, the last MotionEvent which was far enough from the finger is set as the final
        // MotionEvent and sent to the Classifiers.
        if (mCurrentType == Classifier.NOTIFICATION_DRAG_DOWN) {
            mBufferedEvents.add(MotionEvent.obtain(event));
            Point pointEnd = new Point(event.getX() / mDpi, event.getY() / mDpi);

            while (pointEnd.dist(new Point(mBufferedEvents.getFirst().getX() / mDpi,
                    mBufferedEvents.getFirst().getY() / mDpi)) > FINGER_DISTANCE) {
                addTouchEvent(mBufferedEvents.getFirst());
                mBufferedEvents.remove();
            }

            int action = event.getActionMasked();
            if (action == MotionEvent.ACTION_UP) {
                mBufferedEvents.getFirst().setAction(MotionEvent.ACTION_UP);
                addTouchEvent(mBufferedEvents.getFirst());
                mBufferedEvents.clear();
            }
        } else {
            addTouchEvent(event);
        }
    }

    private void addTouchEvent(MotionEvent event) {
        mClassifierData.update(event);
        mClassifierData.update(event);


        for (int i = 0; i < mStrokeClassifiersSize; i++) {
        for (int i = 0; i < mStrokeClassifiersSize; i++) {
@@ -135,7 +177,6 @@ public class HumanInteractionClassifier extends Classifier {


        mClassifierData.cleanUp(event);
        mClassifierData.cleanUp(event);
    }
    }
    }


    @Override
    @Override
    public void onSensorChanged(SensorEvent event) {
    public void onSensorChanged(SensorEvent event) {
+4 −6
Original line number Original line Diff line number Diff line
@@ -29,18 +29,16 @@ public class Stroke {
    private long mStartTimeNano;
    private long mStartTimeNano;
    private long mEndTimeNano;
    private long mEndTimeNano;
    private float mLength;
    private float mLength;
    private float mXdpi;
    private final float mDpi;
    private float mYdpi;


    public Stroke(long eventTimeNano, float xdpi, float ydpi) {
    public Stroke(long eventTimeNano, float dpi) {
        mXdpi = xdpi;
        mDpi = dpi;
        mYdpi = ydpi;
        mStartTimeNano = mEndTimeNano = eventTimeNano;
        mStartTimeNano = mEndTimeNano = eventTimeNano;
    }
    }


    public void addPoint(float x, float y, long eventTimeNano) {
    public void addPoint(float x, float y, long eventTimeNano) {
        mEndTimeNano = eventTimeNano;
        mEndTimeNano = eventTimeNano;
        Point point = new Point(x / mXdpi, y / mYdpi, eventTimeNano - mStartTimeNano);
        Point point = new Point(x / mDpi, y / mDpi, eventTimeNano - mStartTimeNano);
        if (!mPoints.isEmpty()) {
        if (!mPoints.isEmpty()) {
            mLength += mPoints.get(mPoints.size() - 1).dist(point);
            mLength += mPoints.get(mPoints.size() - 1).dist(point);
        }
        }