diff options
Diffstat (limited to 'src/com/android/launcher3/pageindicators')
3 files changed, 64 insertions, 36 deletions
diff --git a/src/com/android/launcher3/pageindicators/CaretDrawable.java b/src/com/android/launcher3/pageindicators/CaretDrawable.java index 3a7fc4264..fcf3d23a2 100644 --- a/src/com/android/launcher3/pageindicators/CaretDrawable.java +++ b/src/com/android/launcher3/pageindicators/CaretDrawable.java @@ -34,29 +34,43 @@ public class CaretDrawable extends Drawable { private float mCaretProgress; - private Paint mPaint = new Paint(); + private Paint mShadowPaint = new Paint(); + private Paint mCaretPaint = new Paint(); private Path mPath = new Path(); - private int mInset; public CaretDrawable(Context context) { final Resources res = context.getResources(); - mPaint.setColor(res.getColor(R.color.all_apps_caret_color)); - mPaint.setAntiAlias(true); - mPaint.setStrokeWidth(res.getDimensionPixelSize(R.dimen.all_apps_caret_stroke_width)); - mPaint.setStyle(Paint.Style.STROKE); - mPaint.setStrokeCap(Paint.Cap.SQUARE); - mPaint.setStrokeJoin(Paint.Join.MITER); - - mInset = res.getDimensionPixelSize(R.dimen.all_apps_caret_inset); + final int strokeWidth = res.getDimensionPixelSize(R.dimen.all_apps_caret_stroke_width); + final int shadowSpread = res.getDimensionPixelSize(R.dimen.all_apps_caret_shadow_spread); + + mCaretPaint.setColor(res.getColor(R.color.all_apps_caret_color)); + mCaretPaint.setAntiAlias(true); + mCaretPaint.setStrokeWidth(strokeWidth); + mCaretPaint.setStyle(Paint.Style.STROKE); + mCaretPaint.setStrokeCap(Paint.Cap.SQUARE); + mCaretPaint.setStrokeJoin(Paint.Join.MITER); + + mShadowPaint.setColor(res.getColor(R.color.all_apps_caret_shadow_color)); + mShadowPaint.setAntiAlias(true); + mShadowPaint.setStrokeWidth(strokeWidth + (shadowSpread * 2)); + mShadowPaint.setStyle(Paint.Style.STROKE); + mShadowPaint.setStrokeCap(Paint.Cap.ROUND); + mShadowPaint.setStrokeJoin(Paint.Join.ROUND); } @Override public void draw(Canvas canvas) { - final float width = getBounds().width(); - final float height = getBounds().height(); - final float left = getBounds().left; - final float top = getBounds().top; + // Assumes caret paint is more important than shadow paint + if (Float.compare(mCaretPaint.getAlpha(), 0f) == 0) { + return; + } + + // Assumes shadow stroke width is larger + final float width = getBounds().width() - mShadowPaint.getStrokeWidth(); + final float height = getBounds().height() - mShadowPaint.getStrokeWidth(); + final float left = getBounds().left + (mShadowPaint.getStrokeWidth() / 2); + final float top = getBounds().top + (mShadowPaint.getStrokeWidth() / 2); final float verticalInset = (height / 4); final float caretHeight = (height - (verticalInset * 2)); @@ -66,7 +80,8 @@ public class CaretDrawable extends Drawable { mPath.lineTo(left + (width / 2), top + caretHeight * mCaretProgress); mPath.lineTo(left + width, top + caretHeight * (1 - mCaretProgress)); - canvas.drawPath(mPath, mPaint); + canvas.drawPath(mPath, mShadowPaint); + canvas.drawPath(mPath, mCaretPaint); } @Override @@ -78,21 +93,18 @@ public class CaretDrawable extends Drawable { @Override public int getOpacity() { - return PixelFormat.OPAQUE; + return PixelFormat.TRANSLUCENT; } @Override public void setAlpha(int alpha) { - // no-op + mCaretPaint.setAlpha(alpha); + mShadowPaint.setAlpha(alpha); + invalidateSelf(); } @Override public void setColorFilter(ColorFilter cf) { // no-op } - - @Override - public void setBounds(int left, int top, int right, int bottom) { - super.setBounds(left + mInset, top + mInset, right - mInset, bottom - mInset); - } } diff --git a/src/com/android/launcher3/pageindicators/PageIndicatorCaretLandscape.java b/src/com/android/launcher3/pageindicators/PageIndicatorCaretLandscape.java index 807520183..fea47a98f 100644 --- a/src/com/android/launcher3/pageindicators/PageIndicatorCaretLandscape.java +++ b/src/com/android/launcher3/pageindicators/PageIndicatorCaretLandscape.java @@ -16,13 +16,19 @@ package com.android.launcher3.pageindicators; import android.content.Context; +import android.content.res.Resources; import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Rect; import android.util.AttributeSet; import com.android.launcher3.Launcher; +import com.android.launcher3.R; /** - * Simply draws the caret drawable in the center. Used for the landscape layout. + * Simply draws the caret drawable bottom-right aligned in the view. This ensures that we can have + * a view with as large an area as we want (for touching) while maintaining a caret of size + * all_apps_caret_size. Used only for the landscape layout. */ public class PageIndicatorCaretLandscape extends PageIndicator { // all apps pull up handle drawable. @@ -38,23 +44,25 @@ public class PageIndicatorCaretLandscape extends PageIndicator { public PageIndicatorCaretLandscape(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - setCaretDrawable(new CaretDrawable(context)); + int caretSize = context.getResources().getDimensionPixelSize(R.dimen.all_apps_caret_size); + CaretDrawable caretDrawable = new CaretDrawable(context); + caretDrawable.setBounds(0, 0, caretSize, caretSize); + setCaretDrawable(caretDrawable); + Launcher l = (Launcher) context; setOnTouchListener(l.getHapticFeedbackTouchListener()); setOnClickListener(l); + setOnLongClickListener(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; - getCaretDrawable().setBounds(l, 0, l + size, size); - } - - @Override protected void onDraw(Canvas canvas) { + Rect drawableBounds = getCaretDrawable().getBounds(); + int count = canvas.save(); + canvas.translate(getWidth() - drawableBounds.width(), + getHeight() - drawableBounds.height()); getCaretDrawable().draw(canvas); + canvas.restoreToCount(count); } } diff --git a/src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java b/src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java index 684eb2953..0d771adb7 100644 --- a/src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java +++ b/src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java @@ -62,6 +62,8 @@ public class PageIndicatorLineCaret extends PageIndicator { private final int mLineHeight; private final TransformingTouchDelegate mTouchDelegate; private final int mTouchExtensionHeight; + private final int mCaretSizePx; + private final int mCaretWorkspaceOffsetPx; private static final Property<PageIndicatorLineCaret, Integer> PAINT_ALPHA = new Property<PageIndicatorLineCaret, Integer>(Integer.class, "paint_alpha") { @@ -122,14 +124,19 @@ public class PageIndicatorLineCaret extends PageIndicator { public PageIndicatorLineCaret(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + + 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); - Resources res = context.getResources(); setCaretDrawable(new CaretDrawable(context)); mLineHeight = res.getDimensionPixelSize(R.dimen.dynamic_grid_page_indicator_line_height); mTouchExtensionHeight = res.getDimensionPixelSize( @@ -146,9 +153,10 @@ public class PageIndicatorLineCaret extends PageIndicator { @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; - getCaretDrawable().setBounds(l, 0, l + size, size); + // 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. |