From 016eaeea99e163f0b5385cf660297e6c21ff21e5 Mon Sep 17 00:00:00 2001 From: Hyunyoung Song Date: Wed, 7 Sep 2016 14:45:09 -0700 Subject: [PATCH] Change all apps caret target bounding box b/30400751 1) This also fixes the issue of apps drawer sliding up when page is swiped horizontally immediately above the hotseat area. 2) Disclaimer: this should be cp'ed to calgary. Hence, I tried to keep the diff small. Ideally, CaretDrawable animation handling should move to AllAppsHandleImageView via refactoring in follow up CL. Change-Id: I4d808ee2eeca53b40c0b4e4e0e364fef056e26c3 --- res/layout-port/launcher.xml | 6 +-- res/layout-sw720dp/launcher.xml | 6 +-- res/layout/page_indicator.xml | 27 ++++++++++ res/values/dimens.xml | 5 +- src/com/android/launcher3/DeviceProfile.java | 1 - .../pageindicators/CaretDrawable.java | 13 +++++ .../pageindicators/PageIndicator.java | 5 +- .../PageIndicatorLineCaret.java | 50 +++++-------------- 8 files changed, 61 insertions(+), 52 deletions(-) create mode 100644 res/layout/page_indicator.xml diff --git a/res/layout-port/launcher.xml b/res/layout-port/launcher.xml index 49bac3bcc8..a2e2f9bbab 100644 --- a/res/layout-port/launcher.xml +++ b/res/layout-port/launcher.xml @@ -56,10 +56,8 @@ - + - + + + + + + diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 87ef78b2e5..1ae4685574 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -4,9 +4,9 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 - + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,7 +19,6 @@ 8dp 28dp 1dp - 12dp 38dp 48dp 8dp diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index e6802bd27e..c9fd85a16d 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -533,7 +533,6 @@ public class DeviceProfile { } else { // Put the page indicators above the hotseat lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; - lp.width = LayoutParams.WRAP_CONTENT; lp.height = pageIndicatorHeightPx; lp.bottomMargin = hotseatBarHeightPx + mInsets.bottom; } diff --git a/src/com/android/launcher3/pageindicators/CaretDrawable.java b/src/com/android/launcher3/pageindicators/CaretDrawable.java index 1451773aff..4789f69f54 100644 --- a/src/com/android/launcher3/pageindicators/CaretDrawable.java +++ b/src/com/android/launcher3/pageindicators/CaretDrawable.java @@ -37,6 +37,7 @@ public class CaretDrawable extends Drawable { private Paint mShadowPaint = new Paint(); private Paint mCaretPaint = new Paint(); private Path mPath = new Path(); + private final int mCaretSizePx; public CaretDrawable(Context context) { final Resources res = context.getResources(); @@ -57,6 +58,18 @@ public class CaretDrawable extends Drawable { mShadowPaint.setStyle(Paint.Style.STROKE); mShadowPaint.setStrokeCap(Paint.Cap.ROUND); mShadowPaint.setStrokeJoin(Paint.Join.ROUND); + + mCaretSizePx = res.getDimensionPixelSize(R.dimen.all_apps_caret_size); + } + + @Override + public int getIntrinsicHeight() { + return mCaretSizePx; + } + + @Override + public int getIntrinsicWidth() { + return mCaretSizePx; } @Override diff --git a/src/com/android/launcher3/pageindicators/PageIndicator.java b/src/com/android/launcher3/pageindicators/PageIndicator.java index b53715d981..47c2ffb381 100644 --- a/src/com/android/launcher3/pageindicators/PageIndicator.java +++ b/src/com/android/launcher3/pageindicators/PageIndicator.java @@ -18,20 +18,21 @@ package com.android.launcher3.pageindicators; import android.content.Context; import android.graphics.drawable.Drawable; import android.util.AttributeSet; -import android.view.View; +import android.widget.FrameLayout; import com.android.launcher3.dynamicui.ExtractedColors; /** * Base class for a page indicator. */ -public abstract class PageIndicator extends View { +public abstract class PageIndicator extends FrameLayout { private CaretDrawable mCaretDrawable; protected int mNumPages = 1; public PageIndicator(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); + setWillNotDraw(false); } public void setScroll(int currentScroll, int totalScroll) {} diff --git a/src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java b/src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java index 0d771adb7e..ca3a2dd09e 100644 --- a/src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java +++ b/src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java @@ -15,14 +15,13 @@ import android.support.v4.graphics.ColorUtils; import android.util.AttributeSet; import android.util.Log; import android.util.Property; -import android.view.View; import android.view.ViewConfiguration; +import android.widget.ImageView; import com.android.launcher3.Launcher; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.dynamicui.ExtractedColors; -import com.android.launcher3.util.TransformingTouchDelegate; /** * A PageIndicator that briefly shows a fraction of a line when moving between pages. @@ -60,10 +59,7 @@ public class PageIndicatorLineCaret extends PageIndicator { private Paint mLinePaint; private Launcher mLauncher; private final int mLineHeight; - private final TransformingTouchDelegate mTouchDelegate; - private final int mTouchExtensionHeight; - private final int mCaretSizePx; - private final int mCaretWorkspaceOffsetPx; + private ImageView mAllAppsHandle; private static final Property PAINT_ALPHA = new Property(Integer.class, "paint_alpha") { @@ -128,48 +124,26 @@ public class PageIndicatorLineCaret extends PageIndicator { Resources res = context.getResources(); mLinePaint = new Paint(); mLinePaint.setAlpha(0); - mCaretSizePx = res.getDimensionPixelSize(R.dimen.all_apps_caret_size); - mCaretWorkspaceOffsetPx = res.getDimensionPixelSize( - R.dimen.all_apps_caret_workspace_offset); mLauncher = (Launcher) context; - setOnTouchListener(mLauncher.getHapticFeedbackTouchListener()); - setOnClickListener(mLauncher); - setOnLongClickListener(mLauncher); - setOnFocusChangeListener(mLauncher.mFocusHandler); - setCaretDrawable(new CaretDrawable(context)); mLineHeight = res.getDimensionPixelSize(R.dimen.dynamic_grid_page_indicator_line_height); - mTouchExtensionHeight = res.getDimensionPixelSize( - R.dimen.dynamic_grid_page_indicator_extra_touch_height); - mTouchDelegate = new TransformingTouchDelegate(this); + setCaretDrawable(new CaretDrawable(context)); } @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - mLauncher.getDragLayer().setTouchDelegate(mTouchDelegate); - } - - @Override - protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - super.onLayout(changed, left, top, right, bottom); - // Top/center align the caret in the page indicator space - int l = (right - left) / 2 - mCaretSizePx / 2; - getCaretDrawable().setBounds(l, mCaretWorkspaceOffsetPx, l + mCaretSizePx, - mCaretWorkspaceOffsetPx + mCaretSizePx); - - // The touch area is expanded below this view by #mTouchExtensionHeight - // which extends to the top of the hotseat. - View parent = mLauncher.getDragLayer(); - sTempCoords[0] = sTempCoords[1] = 0; - Utilities.getDescendantCoordRelativeToAncestor(this, parent, sTempCoords, true); - mTouchDelegate.setBounds(sTempCoords[0], sTempCoords[1], sTempCoords[0] + this.getWidth(), - sTempCoords[1] + getHeight() + mTouchExtensionHeight); + protected void onFinishInflate() { + super.onFinishInflate(); + mAllAppsHandle = (ImageView) findViewById(R.id.all_apps_handle); + mAllAppsHandle.setImageDrawable(getCaretDrawable()); + mAllAppsHandle.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener()); + mAllAppsHandle.setOnClickListener(mLauncher); + mAllAppsHandle.setOnLongClickListener(mLauncher); + mAllAppsHandle.setOnFocusChangeListener(mLauncher.mFocusHandler); + mLauncher.setAllAppsButton(mAllAppsHandle); } @Override protected void onDraw(Canvas canvas) { - getCaretDrawable().draw(canvas); if (mTotalScroll == 0 || mNumPagesFloat == 0) { return; }