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

Commit e0251533 authored by Jens Doll's avatar Jens Doll
Browse files

Improving pie control's user interaction

User feedback showed that it is sometimes difficult to interact
with pie controls. This commit adds some tweaks to how pie
controls react on user touch events.

This changes:
* Pie trigger on LEFT and RIGHT are now more forgiving in the
  initial phase of a swipe. (This should reduce problems when
  trying to activate the pie with a thumb.)
* Pie items are now more sloppy when it comes to focus.

Patch Set #2:
* Removed sloppy focus.

Change-Id: Ib21556ed7f7ff9c6cdbcd1760e94a17c8534706a
parent 94ba14c9
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -68,12 +68,17 @@ public class PieItem extends PieLayout.PieDrawable {
    }
    private PieOnClickListener mOnClickListener = null;

    public PieItem(Context context, PieLayout parent, int width, Object tag, View view) {
    /**
     * The item is selected / has the focus from the gesture.
     */
    public final static int SELECTED = 0x100;

    public PieItem(Context context, PieLayout parent, int flags, int width, Object tag, View view) {
        mView = view;
        mPieLayout = parent;
        this.tag = tag;
        this.width = width;
        flags = PieDrawable.VISIBLE | PieDrawable.DISPLAY_ALL;
        this.flags = flags | PieDrawable.VISIBLE | PieDrawable.DISPLAY_ALL;

        final Resources res = context.getResources();

@@ -108,9 +113,9 @@ public class PieItem extends PieLayout.PieDrawable {
    public void setSelected(boolean selected) {
        mPieLayout.postInvalidate();
        if (selected) {
            flags |= PieLayout.PieDrawable.SELECTED;
            flags |= SELECTED;
        } else {
            flags &= ~PieLayout.PieDrawable.SELECTED;
            flags &= ~SELECTED;
        }
    }

@@ -158,9 +163,9 @@ public class PieItem extends PieLayout.PieDrawable {

    @Override
    public void draw(Canvas canvas, Position position) {
        canvas.drawPath(mPath, (flags & PieDrawable.SELECTED) != 0
        canvas.drawPath(mPath, (flags & SELECTED) != 0
                ? mSelectedPaint : mBackgroundPaint);
        canvas.drawPath(mPath, (flags & PieDrawable.SELECTED) != 0
        canvas.drawPath(mPath, (flags & SELECTED) != 0
                ? mSelectedPaint : mOutlinePaint);

        if (mView != null) {
@@ -193,6 +198,11 @@ public class PieItem extends PieLayout.PieDrawable {
        }
    }

    private boolean hit(float alpha, int radius) {
        return (alpha > mStart) && (alpha < mStart + mSweep)
                && (radius > mInner && radius < mOuter);
    }

    private Path getOutline(float scale) {
        RectF outerBB = new RectF(-mOuter * scale, -mOuter * scale, mOuter * scale, mOuter * scale);
        RectF innerBB = new RectF(-mInner * scale, -mInner * scale, mInner * scale, mInner * scale);
+1 −7
Original line number Diff line number Diff line
@@ -136,11 +136,6 @@ public class PieLayout extends FrameLayout implements View.OnTouchListener {
            mOuter = outer;
        }

        public boolean hit(float alpha, int radius) {
            return (alpha > mStart) && (alpha < mStart + mSweep)
                    && (radius > mInner) && (radius < mOuter);
        }

        // Display on all positions
        public final static int DISPLAY_ALL = Position.LEFT.FLAG
                | Position.BOTTOM.FLAG
@@ -152,8 +147,6 @@ public class PieLayout extends FrameLayout implements View.OnTouchListener {
                | Position.RIGHT.FLAG;
        // The PieDrawable is visible, note that slice visibility overrides item visibility
        public final static int VISIBLE = 0x10;
        // The item (?) is selected
        public final static int SELECTED = 0x20;

        public int flags;
    };
@@ -604,6 +597,7 @@ public class PieLayout extends FrameLayout implements View.OnTouchListener {
        if (mActiveItem != null) {
            mActiveItem.setSelected(false);
        }
        mActiveItem = null;

        mActive = false;
    }
+16 −1
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ public class PieController implements BaseStatusBar.NavigationBarCallback,
        public static float sDistance;
        private float initialX = 0;
        private float initialY = 0;
        private float gracePeriod = 0;

        private Tracker(Position position) {
            this.position = position;
@@ -153,6 +154,14 @@ public class PieController implements BaseStatusBar.NavigationBarCallback,
        public void start(MotionEvent event) {
            initialX = event.getX();
            initialY = event.getY();
            switch (position) {
                case LEFT:
                    gracePeriod = initialX + sDistance / 3.0f;
                    break;
                case RIGHT:
                    gracePeriod = initialX - sDistance / 3.0f;
                    break;
            }
            active = true;
        }

@@ -168,6 +177,9 @@ public class PieController implements BaseStatusBar.NavigationBarCallback,
            boolean loaded = false;
            switch (position) {
                case LEFT:
                    if (x < gracePeriod) {
                        initialY = y;
                    }
                    if (initialY - y < sDistance && y - initialY < sDistance) {
                        if (x - initialX <= sDistance) {
                            return false;
@@ -192,6 +204,9 @@ public class PieController implements BaseStatusBar.NavigationBarCallback,
                    }
                    break;
                case RIGHT:
                    if (x > gracePeriod) {
                        initialY = y;
                    }
                    if (initialY - y < sDistance && y - initialY < sDistance) {
                        if (initialX - x <= sDistance) {
                            return false;
@@ -392,7 +407,7 @@ public class PieController implements BaseStatusBar.NavigationBarCallback,
        view.setMinimumHeight(minimumImageSize);
        LayoutParams lp = new LayoutParams(minimumImageSize, minimumImageSize);
        view.setLayoutParams(lp);
        PieItem item = new PieItem(mContext, mPieContainer, width, type, view);
        PieItem item = new PieItem(mContext, mPieContainer, 0, width, type, view);
        item.setOnClickListener(this);
        return item;
    }