diff options
author | Hyunyoung Song <hyunyoungs@google.com> | 2016-06-15 12:51:30 -0700 |
---|---|---|
committer | Hyunyoung Song <hyunyoungs@google.com> | 2016-06-15 12:51:30 -0700 |
commit | 7d2fc8120e549eaa9542b0985aab67d172cbd682 (patch) | |
tree | 92335d428aa9379039c061bae93188c0b24135a8 /src/com/android/launcher3/pageindicators | |
parent | b25b2c41c2fa277e16d708ad827e283efcb86452 (diff) | |
download | android_packages_apps_Trebuchet-7d2fc8120e549eaa9542b0985aab67d172cbd682.tar.gz android_packages_apps_Trebuchet-7d2fc8120e549eaa9542b0985aab67d172cbd682.tar.bz2 android_packages_apps_Trebuchet-7d2fc8120e549eaa9542b0985aab67d172cbd682.zip |
Add caret shaped all app pull up handle to page indicator.
b/28917826
> PageIndicator is also added in landscape
> Touch delegate allows the active touch area to be 36dp
Change-Id: If00f45fc88a13cd5a6759d771313439eb58561e3
Diffstat (limited to 'src/com/android/launcher3/pageindicators')
-rw-r--r-- | src/com/android/launcher3/pageindicators/PageIndicator.java | 27 | ||||
-rw-r--r-- | src/com/android/launcher3/pageindicators/PageIndicatorCaretLandscape.java | 66 | ||||
-rw-r--r-- | src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java (renamed from src/com/android/launcher3/pageindicators/PageIndicatorLine.java) | 80 |
3 files changed, 152 insertions, 21 deletions
diff --git a/src/com/android/launcher3/pageindicators/PageIndicator.java b/src/com/android/launcher3/pageindicators/PageIndicator.java index 7c5949598..2209bb8ad 100644 --- a/src/com/android/launcher3/pageindicators/PageIndicator.java +++ b/src/com/android/launcher3/pageindicators/PageIndicator.java @@ -1,9 +1,26 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.android.launcher3.pageindicators; import android.content.Context; import android.util.AttributeSet; import android.view.View; +import com.android.launcher3.dynamicui.ExtractedColors; + /** * Base class for a page indicator. */ @@ -15,9 +32,9 @@ public abstract class PageIndicator extends View { super(context, attrs, defStyleAttr); } - public abstract void setScroll(int currentScroll, int totalScroll); + public void setScroll(int currentScroll, int totalScroll) {} - public abstract void setActiveMarker(int activePage); + public void setActiveMarker(int activePage) {} public void addMarker() { mNumPages++; @@ -33,5 +50,9 @@ public abstract class PageIndicator extends View { onPageCountChanged(); } - protected abstract void onPageCountChanged(); + protected void onPageCountChanged() { } + + public void setShouldAutoHide(boolean shouldAutoHide) {} + + public void updateColor(ExtractedColors extractedColors) {} } diff --git a/src/com/android/launcher3/pageindicators/PageIndicatorCaretLandscape.java b/src/com/android/launcher3/pageindicators/PageIndicatorCaretLandscape.java new file mode 100644 index 000000000..0f9145ddc --- /dev/null +++ b/src/com/android/launcher3/pageindicators/PageIndicatorCaretLandscape.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.pageindicators; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Canvas; +import android.graphics.drawable.Drawable; +import android.util.AttributeSet; + +import com.android.launcher3.Launcher; +import com.android.launcher3.R; +import com.android.launcher3.dynamicui.ExtractedColors; + +/** + * Simply draws the caret drawable in the center. Used for the landscape layout. + */ +public class PageIndicatorCaretLandscape extends PageIndicator { + // all apps pull up handle drawable. + private final Drawable caretDrawable; + + public PageIndicatorCaretLandscape(Context context) { + this(context, null); + } + + public PageIndicatorCaretLandscape(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public PageIndicatorCaretLandscape(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + + Resources res = context.getResources(); + caretDrawable = res.getDrawable(R.drawable.ic_allapps_caret); + Launcher l = (Launcher) context; + setOnTouchListener(l.getHapticFeedbackTouchListener()); + setOnClickListener(l); + setOnFocusChangeListener(l.mFocusHandler); + } + + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + int size = bottom - top; + int l = (right - left) / 2 - size / 2; + caretDrawable.setBounds(l, 0, l + size, size); + } + + @Override + protected void onDraw(Canvas canvas) { + caretDrawable.draw(canvas); + } +} diff --git a/src/com/android/launcher3/pageindicators/PageIndicatorLine.java b/src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java index aec708c1f..7394426a4 100644 --- a/src/com/android/launcher3/pageindicators/PageIndicatorLine.java +++ b/src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java @@ -5,17 +5,24 @@ import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.content.Context; +import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; import android.os.Handler; import android.os.Looper; import android.support.v4.graphics.ColorUtils; import android.util.AttributeSet; import android.util.Log; import android.util.Property; +import android.view.TouchDelegate; +import android.view.View; import android.view.ViewConfiguration; +import com.android.launcher3.Launcher; +import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.dynamicui.ExtractedColors; @@ -24,9 +31,11 @@ import com.android.launcher3.dynamicui.ExtractedColors; * * The fraction is 1 / number of pages and the position is based on the progress of the page scroll. */ -public class PageIndicatorLine extends PageIndicator { +public class PageIndicatorLineCaret extends PageIndicator { private static final String TAG = "PageIndicatorLine"; + private static final int[] sTempCoords = new int[2]; + private static final int LINE_ANIMATE_DURATION = ViewConfiguration.getScrollBarFadeDuration(); private static final int LINE_FADE_DELAY = ViewConfiguration.getScrollDefaultDelay(); public static final int WHITE_ALPHA = (int) (0.70f * 255); @@ -51,44 +60,50 @@ public class PageIndicatorLine extends PageIndicator { private int mCurrentScroll; private int mTotalScroll; private Paint mLinePaint; - - private static final Property<PageIndicatorLine, Integer> PAINT_ALPHA - = new Property<PageIndicatorLine, Integer>(Integer.class, "paint_alpha") { + private Launcher mLauncher; + // all apps pull up handle drawable. + private final Drawable caretDrawable; + private final int mLineHeight; + private final Rect mTouchHitRect = new Rect(); + private final int mTouchExtensionHeight; + + private static final Property<PageIndicatorLineCaret, Integer> PAINT_ALPHA + = new Property<PageIndicatorLineCaret, Integer>(Integer.class, "paint_alpha") { @Override - public Integer get(PageIndicatorLine obj) { + public Integer get(PageIndicatorLineCaret obj) { return obj.mLinePaint.getAlpha(); } @Override - public void set(PageIndicatorLine obj, Integer alpha) { + public void set(PageIndicatorLineCaret obj, Integer alpha) { obj.mLinePaint.setAlpha(alpha); obj.invalidate(); } }; - private static final Property<PageIndicatorLine, Float> NUM_PAGES - = new Property<PageIndicatorLine, Float>(Float.class, "num_pages") { + private static final Property<PageIndicatorLineCaret, Float> NUM_PAGES + = new Property<PageIndicatorLineCaret, Float>(Float.class, "num_pages") { @Override - public Float get(PageIndicatorLine obj) { + public Float get(PageIndicatorLineCaret obj) { return obj.mNumPagesFloat; } @Override - public void set(PageIndicatorLine obj, Float numPages) { + public void set(PageIndicatorLineCaret obj, Float numPages) { obj.mNumPagesFloat = numPages; obj.invalidate(); } }; - private static final Property<PageIndicatorLine, Integer> TOTAL_SCROLL - = new Property<PageIndicatorLine, Integer>(Integer.class, "total_scroll") { + private static final Property<PageIndicatorLineCaret, Integer> TOTAL_SCROLL + = new Property<PageIndicatorLineCaret, Integer>(Integer.class, "total_scroll") { @Override - public Integer get(PageIndicatorLine obj) { + public Integer get(PageIndicatorLineCaret obj) { return obj.mTotalScroll; } @Override - public void set(PageIndicatorLine obj, Integer totalScroll) { + public void set(PageIndicatorLineCaret obj, Integer totalScroll) { obj.mTotalScroll = totalScroll; obj.invalidate(); } @@ -101,22 +116,50 @@ public class PageIndicatorLine extends PageIndicator { } }; - public PageIndicatorLine(Context context) { + public PageIndicatorLineCaret(Context context) { this(context, null); } - public PageIndicatorLine(Context context, AttributeSet attrs) { + public PageIndicatorLineCaret(Context context, AttributeSet attrs) { this(context, attrs, 0); } - public PageIndicatorLine(Context context, AttributeSet attrs, int defStyle) { + public PageIndicatorLineCaret(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mLinePaint = new Paint(); mLinePaint.setAlpha(0); + + mLauncher = (Launcher) context; + setOnTouchListener(mLauncher.getHapticFeedbackTouchListener()); + setOnClickListener(mLauncher); + setOnFocusChangeListener(mLauncher.mFocusHandler); + Resources res = context.getResources(); + caretDrawable = res.getDrawable(R.drawable.ic_allapps_caret); + mLineHeight = res.getDimensionPixelSize(R.dimen.dynamic_grid_page_indicator_line_height); + mTouchExtensionHeight = res.getDimensionPixelSize( + R.dimen.dynamic_grid_page_indicator_extra_touch_height); + } + + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + int size = bottom - top; + int l = (right - left) / 2 - size / 2; + caretDrawable.setBounds(l, 0, l+ size, size); + + // 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.getDescendantCoordRelativeToParent(this, parent, sTempCoords, true); + mTouchHitRect.set(sTempCoords[0], sTempCoords[1], sTempCoords[0] + this.getWidth(), + sTempCoords[1] + getHeight() + mTouchExtensionHeight); + parent.setTouchDelegate(new TouchDelegate(mTouchHitRect, this)); } @Override protected void onDraw(Canvas canvas) { + caretDrawable.draw(canvas); if (mTotalScroll == 0 || mNumPagesFloat == 0) { return; } @@ -127,7 +170,8 @@ public class PageIndicatorLine extends PageIndicator { int lineWidth = (int) (availableWidth / mNumPagesFloat); int lineLeft = (int) (progress * (availableWidth - lineWidth)); int lineRight = lineLeft + lineWidth; - canvas.drawRect(lineLeft, 0, lineRight, canvas.getHeight(), mLinePaint); + canvas.drawRect(lineLeft, canvas.getHeight() + mLineHeight, lineRight, canvas.getHeight(), + mLinePaint); } @Override |