FileDocCategorySizeDatePackage
DelegateViewHelper.javaAPI DocAndroid 5.1 API5240Thu Mar 12 22:22:42 GMT 2015com.android.systemui.statusbar

DelegateViewHelper

public class DelegateViewHelper extends Object

Fields Summary
private android.view.View
mDelegateView
private android.view.View
mSourceView
private BaseStatusBar
mBar
private int[]
mTempPoint
private float[]
mDownPoint
private float
mTriggerThreshhold
private boolean
mPanelShowing
android.graphics.RectF
mInitialTouch
private boolean
mStarted
private boolean
mSwapXY
private boolean
mDisabled
Constructors Summary
public DelegateViewHelper(android.view.View sourceView)


       
        setSourceView(sourceView);
    
Methods Summary
public booleanonInterceptTouchEvent(android.view.MotionEvent event)

        if (mSourceView == null || mDelegateView == null || mBar.shouldDisableNavbarGestures()) {
            return false;
        }

        mSourceView.getLocationOnScreen(mTempPoint);
        final float sourceX = mTempPoint[0];
        final float sourceY = mTempPoint[1];

        final int action = event.getAction();
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                mPanelShowing = mDelegateView.getVisibility() == View.VISIBLE;
                mDownPoint[0] = event.getX();
                mDownPoint[1] = event.getY();
                mStarted = mInitialTouch.contains(mDownPoint[0] + sourceX, mDownPoint[1] + sourceY);
                break;
        }

        if (!mStarted) {
            return false;
        }

        if (!mDisabled && !mPanelShowing && action == MotionEvent.ACTION_MOVE) {
            final int historySize = event.getHistorySize();
            for (int k = 0; k < historySize + 1; k++) {
                float x = k < historySize ? event.getHistoricalX(k) : event.getX();
                float y = k < historySize ? event.getHistoricalY(k) : event.getY();
                final float distance = mSwapXY ? (mDownPoint[0] - x) : (mDownPoint[1] - y);
                if (distance > mTriggerThreshhold) {
                    mBar.showSearchPanel();
                    mPanelShowing = true;
                    break;
                }
            }
        }

        if (action == MotionEvent.ACTION_DOWN) {
            mBar.setInteracting(StatusBarManager.WINDOW_NAVIGATION_BAR, true);
        } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
            mBar.setInteracting(StatusBarManager.WINDOW_NAVIGATION_BAR, false);
        }

        mDelegateView.getLocationOnScreen(mTempPoint);
        final float delegateX = mTempPoint[0];
        final float delegateY = mTempPoint[1];

        float deltaX = sourceX - delegateX;
        float deltaY = sourceY - delegateY;
        event.offsetLocation(deltaX, deltaY);
        mDelegateView.dispatchTouchEvent(event);
        event.offsetLocation(-deltaX, -deltaY);
        return mPanelShowing;
    
public voidsetBar(BaseStatusBar phoneStatusBar)

        mBar = phoneStatusBar;
    
public voidsetDelegateView(android.view.View view)

        mDelegateView = view;
    
public voidsetDisabled(boolean disabled)

        mDisabled = disabled;
    
public voidsetInitialTouchRegion(android.view.View views)
Selects the initial touch region based on a list of views. This is meant to be called by a container widget on children over which the initial touch should be detected. Note this will compute a minimum bound that contains all specified views.

param
views

        RectF bounds = new RectF();
        int p[] = new int[2];
        for (int i = 0; i < views.length; i++) {
            View view = views[i];
            if (view == null) continue;
            view.getLocationOnScreen(p);
            if (i == 0) {
                bounds.set(p[0], p[1], p[0] + view.getWidth(), p[1] + view.getHeight());
            } else {
                bounds.union(p[0], p[1], p[0] + view.getWidth(), p[1] + view.getHeight());
            }
        }
        mInitialTouch.set(bounds);
    
public voidsetSourceView(android.view.View view)

        mSourceView = view;
        if (mSourceView != null) {
            Resources r = mSourceView.getContext().getResources();
            mTriggerThreshhold = r.getDimensionPixelSize(R.dimen.navigation_bar_min_swipe_distance);
        }
    
public voidsetSwapXY(boolean swap)
When rotation is set to NO_SENSOR, then this allows swapping x/y for gesture detection

param
swap

        mSwapXY = swap;