diff options
Diffstat (limited to 'src/com/android/launcher3/BaseContainerView.java')
-rw-r--r-- | src/com/android/launcher3/BaseContainerView.java | 90 |
1 files changed, 83 insertions, 7 deletions
diff --git a/src/com/android/launcher3/BaseContainerView.java b/src/com/android/launcher3/BaseContainerView.java index 96942ee6f..b7321d94f 100644 --- a/src/com/android/launcher3/BaseContainerView.java +++ b/src/com/android/launcher3/BaseContainerView.java @@ -16,17 +16,24 @@ package com.android.launcher3; +import android.annotation.SuppressLint; import android.content.Context; import android.content.res.TypedArray; +import android.graphics.Point; +import android.graphics.PointF; +import android.graphics.Rect; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.InsetDrawable; import android.util.AttributeSet; +import android.view.MotionEvent; import android.view.View; +import android.view.ViewConfiguration; import android.widget.FrameLayout; import com.android.launcher3.allapps.AllAppsContainerView; import com.android.launcher3.config.FeatureFlags; +import com.android.launcher3.util.TransformingTouchDelegate; /** * A base container view, which supports resizing. @@ -39,12 +46,16 @@ public abstract class BaseContainerView extends FrameLayout protected int mContainerPaddingTop; protected int mContainerPaddingBottom; - private InsetDrawable mRevealDrawable; protected final Drawable mBaseDrawable; + private final Rect mBgPaddingRect = new Rect(); private View mRevealView; private View mContent; + private TransformingTouchDelegate mTouchDelegate; + + private final PointF mLastTouchDownPosPx = new PointF(-1.0f, -1.0f); + public BaseContainerView(Context context) { this(context, null); } @@ -72,6 +83,12 @@ public abstract class BaseContainerView extends FrameLayout DeviceProfile grid = Launcher.getLauncher(getContext()).getDeviceProfile(); grid.addLauncherLayoutChangedListener(this); + + View touchDelegateTargetView = getTouchDelegateTargetView(); + if (touchDelegateTargetView != null) { + mTouchDelegate = new TransformingTouchDelegate(touchDelegateTargetView); + ((View) touchDelegateTargetView.getParent()).setTouchDelegate(mTouchDelegate); + } } @Override @@ -93,10 +110,36 @@ public abstract class BaseContainerView extends FrameLayout } @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + getRevealView().getBackground().getPadding(mBgPaddingRect); + + View touchDelegateTargetView = getTouchDelegateTargetView(); + if (touchDelegateTargetView != null) { + mTouchDelegate.setBounds( + touchDelegateTargetView.getLeft() - mBgPaddingRect.left, + touchDelegateTargetView.getTop() - mBgPaddingRect.top, + touchDelegateTargetView.getRight() + mBgPaddingRect.right, + touchDelegateTargetView.getBottom() + mBgPaddingRect.bottom); + } + } + + @Override public void onLauncherLayoutChanged() { updatePaddings(); } + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + return handleTouchEvent(ev); + } + + @SuppressLint("ClickableViewAccessibility") + @Override + public boolean onTouchEvent(MotionEvent ev) { + return handleTouchEvent(ev); + } + public void setRevealDrawableColor(int color) { ((ColorDrawable) mBaseDrawable).setColor(color); } @@ -130,14 +173,47 @@ public abstract class BaseContainerView extends FrameLayout } } - mRevealDrawable = new InsetDrawable(mBaseDrawable, + InsetDrawable revealDrawable = new InsetDrawable(mBaseDrawable, mContainerPaddingLeft, mContainerPaddingTop, mContainerPaddingRight, mContainerPaddingBottom); - mRevealView.setBackground(mRevealDrawable); - if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && this instanceof AllAppsContainerView) { - // Skip updating the content background - } else { - mContent.setBackground(mRevealDrawable); + mRevealView.setBackground(revealDrawable); + mContent.setBackground(revealDrawable); + } + + /** + * Handles the touch events that shows the workspace when clicking outside the bounds of the + * touch delegate target view. + */ + private boolean handleTouchEvent(MotionEvent ev) { + switch (ev.getAction()) { + case MotionEvent.ACTION_DOWN: + // Check if the touch is outside touch delegate target view + View touchDelegateTargetView = getTouchDelegateTargetView(); + float leftBoundPx = touchDelegateTargetView.getLeft(); + if (ev.getX() < leftBoundPx || + ev.getX() > (touchDelegateTargetView.getWidth() + leftBoundPx)) { + mLastTouchDownPosPx.set((int) ev.getX(), (int) ev.getY()); + } + break; + case MotionEvent.ACTION_UP: + if (mLastTouchDownPosPx.x > -1) { + ViewConfiguration viewConfig = ViewConfiguration.get(getContext()); + float dx = ev.getX() - mLastTouchDownPosPx.x; + float dy = ev.getY() - mLastTouchDownPosPx.y; + float distance = PointF.length(dx, dy); + if (distance < viewConfig.getScaledTouchSlop()) { + // The background was clicked, so just go home + Launcher.getLauncher(getContext()).showWorkspace(true); + return true; + } + } + // Fall through + case MotionEvent.ACTION_CANCEL: + mLastTouchDownPosPx.set(-1, -1); + break; } + return false; } + + public abstract View getTouchDelegateTargetView(); } |