FileDocCategorySizeDatePackage
NavigationBarViewTaskSwitchHelper.javaAPI DocAndroid 5.1 API4229Thu Mar 12 22:22:42 GMT 2015com.android.systemui.statusbar.phone

NavigationBarViewTaskSwitchHelper

public class NavigationBarViewTaskSwitchHelper extends GestureDetector.SimpleOnGestureListener

Fields Summary
private com.android.systemui.statusbar.BaseStatusBar
mBar
private boolean
mIsVertical
private boolean
mIsRTL
private final android.view.GestureDetector
mTaskSwitcherDetector
private final int
mScrollTouchSlop
private final int
mMinFlingVelocity
private int
mTouchDownX
private int
mTouchDownY
Constructors Summary
public NavigationBarViewTaskSwitchHelper(android.content.Context context)

        ViewConfiguration configuration = ViewConfiguration.get(context);
        Resources r = context.getResources();
        mScrollTouchSlop = r.getDimensionPixelSize(R.dimen.navigation_bar_min_swipe_distance);
        mMinFlingVelocity = configuration.getScaledMinimumFlingVelocity();
        mTaskSwitcherDetector = new GestureDetector(context, this);
    
Methods Summary
public booleanonFling(android.view.MotionEvent e1, android.view.MotionEvent e2, float velocityX, float velocityY)

        float absVelX = Math.abs(velocityX);
        float absVelY = Math.abs(velocityY);
        boolean isValidFling = absVelX > mMinFlingVelocity &&
                mIsVertical ? (absVelY > absVelX) : (absVelX > absVelY);
        if (isValidFling) {
            boolean showNext;
            if (!mIsRTL) {
                showNext = mIsVertical ? (velocityY < 0) : (velocityX < 0);
            } else {
                // In RTL, vertical is still the same, but horizontal is flipped
                showNext = mIsVertical ? (velocityY < 0) : (velocityX > 0);
            }
            if (showNext) {
                mBar.showNextAffiliatedTask();
            } else {
                mBar.showPreviousAffiliatedTask();
            }
        }
        return true;
    
public booleanonInterceptTouchEvent(android.view.MotionEvent event)

        // If we move more than a fixed amount, then start capturing for the
        // task switcher detector
        mTaskSwitcherDetector.onTouchEvent(event);
        int action = event.getAction();
        boolean intercepted = false;
        switch (action & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN: {
                mTouchDownX = (int) event.getX();
                mTouchDownY = (int) event.getY();
                break;
            }
            case MotionEvent.ACTION_MOVE: {
                int x = (int) event.getX();
                int y = (int) event.getY();
                int xDiff = Math.abs(x - mTouchDownX);
                int yDiff = Math.abs(y - mTouchDownY);
                boolean exceededTouchSlop = !mIsVertical
                        ? xDiff > mScrollTouchSlop && xDiff > yDiff
                        : yDiff > mScrollTouchSlop && yDiff > xDiff;
                if (exceededTouchSlop) {
                    return true;
                }
                break;
            }
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                break;
        }
        return intercepted;
    
public booleanonTouchEvent(android.view.MotionEvent event)

        return mTaskSwitcherDetector.onTouchEvent(event);
    
public voidsetBar(com.android.systemui.statusbar.BaseStatusBar phoneStatusBar)

        mBar = phoneStatusBar;
    
public voidsetBarState(boolean isVertical, boolean isRTL)

        mIsVertical = isVertical;
        mIsRTL = isRTL;