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

Commit d53e3515 authored by David van Tonder's avatar David van Tonder Committed by Gerrit Code Review
Browse files

Merge "Improving pie control's user interaction" into cm-10.1

parents 289362e1 e0251533
Loading
Loading
Loading
Loading
+16 −6
Original line number Original line Diff line number Diff line
@@ -68,12 +68,17 @@ public class PieItem extends PieLayout.PieDrawable {
    }
    }
    private PieOnClickListener mOnClickListener = null;
    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;
        mView = view;
        mPieLayout = parent;
        mPieLayout = parent;
        this.tag = tag;
        this.tag = tag;
        this.width = width;
        this.width = width;
        flags = PieDrawable.VISIBLE | PieDrawable.DISPLAY_ALL;
        this.flags = flags | PieDrawable.VISIBLE | PieDrawable.DISPLAY_ALL;


        final Resources res = context.getResources();
        final Resources res = context.getResources();


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


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


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


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


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

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


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


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


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


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