diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2017-06-14 15:35:16 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2017-06-16 14:57:34 -0700 |
commit | 1a8f6fb736c36548a44db6c7018771e3a895dda0 (patch) | |
tree | 4ba5fa5fd04a426bbc2a6d32579a41db116bb14e | |
parent | 3f2418976d97770bc0cc9aa006e36d84a8e2d426 (diff) | |
download | packages_apps_Trebuchet-1a8f6fb736c36548a44db6c7018771e3a895dda0.tar.gz packages_apps_Trebuchet-1a8f6fb736c36548a44db6c7018771e3a895dda0.tar.bz2 packages_apps_Trebuchet-1a8f6fb736c36548a44db6c7018771e3a895dda0.zip |
Updating the fast scroll bar UI
Bug: 37015359
Change-Id: Iec0748f04ebe9a3eef13ff759da3cab6ff28c3a1
-rw-r--r-- | res/drawable-ldrtl/container_fastscroll_popup_bg.xml | 27 | ||||
-rw-r--r-- | res/drawable/container_fastscroll_popup_bg.xml | 27 | ||||
-rw-r--r-- | res/layout/all_apps.xml | 6 | ||||
-rw-r--r-- | res/layout/all_apps_discovery_item.xml | 4 | ||||
-rw-r--r-- | res/layout/all_apps_discovery_loading_divider.xml | 4 | ||||
-rw-r--r-- | res/layout/all_apps_divider.xml | 4 | ||||
-rw-r--r-- | res/layout/all_apps_search_divider.xml | 4 | ||||
-rw-r--r-- | res/layout/all_apps_search_market.xml | 4 | ||||
-rw-r--r-- | res/layout/widgets_view.xml | 2 | ||||
-rw-r--r-- | res/values-land/dimens.xml | 15 | ||||
-rw-r--r-- | res/values-sw720dp/dimens.xml | 8 | ||||
-rw-r--r-- | res/values/dimens.xml | 20 | ||||
-rw-r--r-- | res/values/styles.xml | 8 | ||||
-rw-r--r-- | src/com/android/launcher3/BaseRecyclerView.java | 7 | ||||
-rw-r--r-- | src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java | 52 | ||||
-rw-r--r-- | src/com/android/launcher3/allapps/AllAppsRecyclerView.java | 8 | ||||
-rw-r--r-- | src/com/android/launcher3/graphics/FastScrollThumbDrawable.java | 89 | ||||
-rw-r--r-- | src/com/android/launcher3/widget/WidgetsRecyclerView.java | 4 |
18 files changed, 161 insertions, 132 deletions
diff --git a/res/drawable-ldrtl/container_fastscroll_popup_bg.xml b/res/drawable-ldrtl/container_fastscroll_popup_bg.xml deleted file mode 100644 index 2bbf5cd72..000000000 --- a/res/drawable-ldrtl/container_fastscroll_popup_bg.xml +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - Copyright (C) 2015 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. ---> -<shape xmlns:android="http://schemas.android.com/apk/res/android" - android:shape="rectangle"> - <solid android:color="?android:attr/colorAccent" /> - <size - android:width="64dp" - android:height="64dp" /> - <corners - android:topLeftRadius="64dp" - android:topRightRadius="64dp" - android:bottomRightRadius="64dp" /> -</shape>
\ No newline at end of file diff --git a/res/drawable/container_fastscroll_popup_bg.xml b/res/drawable/container_fastscroll_popup_bg.xml deleted file mode 100644 index 3dc76800b..000000000 --- a/res/drawable/container_fastscroll_popup_bg.xml +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - Copyright (C) 2015 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. ---> -<shape xmlns:android="http://schemas.android.com/apk/res/android" - android:shape="rectangle"> - <solid android:color="?android:attr/colorAccent" /> - <size - android:width="64dp" - android:height="64dp" /> - <corners - android:topLeftRadius="64dp" - android:topRightRadius="64dp" - android:bottomLeftRadius="64dp" /> -</shape>
\ No newline at end of file diff --git a/res/layout/all_apps.xml b/res/layout/all_apps.xml index 09b965544..ff605f4bb 100644 --- a/res/layout/all_apps.xml +++ b/res/layout/all_apps.xml @@ -54,8 +54,8 @@ android:overScrollMode="never" android:descendantFocusability="afterDescendants" android:focusable="true" - android:paddingStart="@dimen/container_fastscroll_thumb_max_width" - android:paddingEnd="@dimen/container_fastscroll_thumb_max_width" /> + android:paddingStart="@dimen/dynamic_grid_edge_margin" + android:paddingEnd="@dimen/dynamic_grid_edge_margin" /> <!-- Fast scroller popup --> <TextView @@ -63,7 +63,7 @@ android:layout_alignTop="@+id/apps_list_view" android:id="@+id/fast_scroller_popup" android:layout_alignParentEnd="true" - android:layout_marginEnd="@dimen/container_fastscroll_popup_margin" /> + android:layout_marginEnd="@dimen/fastscroll_popup_margin" /> <!-- Note: we are reusing/repurposing a system attribute for search layout, because of a platform bug, which prevents using custom attributes in <include> tag --> diff --git a/res/layout/all_apps_discovery_item.xml b/res/layout/all_apps_discovery_item.xml index fb1755c6b..728283fc1 100644 --- a/res/layout/all_apps_discovery_item.xml +++ b/res/layout/all_apps_discovery_item.xml @@ -94,8 +94,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" - android:paddingLeft="@dimen/container_fastscroll_thumb_max_width" - android:paddingRight="@dimen/container_fastscroll_thumb_max_width" + android:paddingLeft="@dimen/dynamic_grid_edge_margin" + android:paddingRight="@dimen/dynamic_grid_edge_margin" android:src="@drawable/all_apps_divider" android:scaleType="fitXY" android:focusable="false" /> diff --git a/res/layout/all_apps_discovery_loading_divider.xml b/res/layout/all_apps_discovery_loading_divider.xml index 1ad552142..005847c54 100644 --- a/res/layout/all_apps_discovery_loading_divider.xml +++ b/res/layout/all_apps_discovery_loading_divider.xml @@ -16,8 +16,8 @@ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="6dp" - android:paddingLeft="@dimen/container_fastscroll_thumb_max_width" - android:paddingRight="@dimen/container_fastscroll_thumb_max_width"> + android:paddingLeft="@dimen/dynamic_grid_edge_margin" + android:paddingRight="@dimen/dynamic_grid_edge_margin"> <ProgressBar android:id="@+id/loadingProgressBar" diff --git a/res/layout/all_apps_divider.xml b/res/layout/all_apps_divider.xml index 1eaf685c4..8a4f64664 100644 --- a/res/layout/all_apps_divider.xml +++ b/res/layout/all_apps_divider.xml @@ -19,8 +19,8 @@ android:layout_height="wrap_content" android:paddingTop="@dimen/all_apps_divider_margin_vertical" android:paddingBottom="@dimen/all_apps_divider_margin_vertical" - android:paddingLeft="@dimen/container_fastscroll_thumb_max_width" - android:paddingRight="@dimen/container_fastscroll_thumb_max_width" + android:paddingLeft="@dimen/dynamic_grid_edge_margin" + android:paddingRight="@dimen/dynamic_grid_edge_margin" android:src="@drawable/all_apps_divider" android:scaleType="fitXY" android:focusable="false" />
\ No newline at end of file diff --git a/res/layout/all_apps_search_divider.xml b/res/layout/all_apps_search_divider.xml index d2ef691ea..c052c6635 100644 --- a/res/layout/all_apps_search_divider.xml +++ b/res/layout/all_apps_search_divider.xml @@ -18,8 +18,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="@dimen/all_apps_divider_margin_vertical" - android:paddingLeft="@dimen/container_fastscroll_thumb_max_width" - android:paddingRight="@dimen/container_fastscroll_thumb_max_width" + android:paddingLeft="@dimen/dynamic_grid_edge_margin" + android:paddingRight="@dimen/dynamic_grid_edge_margin" android:src="@drawable/all_apps_search_divider" android:scaleType="fitXY" android:focusable="false" />
\ No newline at end of file diff --git a/res/layout/all_apps_search_market.xml b/res/layout/all_apps_search_market.xml index 3f19b2515..6f2dd3d21 100644 --- a/res/layout/all_apps_search_market.xml +++ b/res/layout/all_apps_search_market.xml @@ -19,8 +19,8 @@ android:layout_width="match_parent" android:layout_height="48dp" android:gravity="center" - android:paddingLeft="@dimen/container_fastscroll_thumb_max_width" - android:paddingRight="@dimen/container_fastscroll_thumb_max_width" + android:paddingLeft="@dimen/dynamic_grid_edge_margin" + android:paddingRight="@dimen/dynamic_grid_edge_margin" android:fontFamily="sans-serif-medium" android:textSize="14sp" android:textColor="?android:attr/colorAccent" diff --git a/res/layout/widgets_view.xml b/res/layout/widgets_view.xml index 476901d1e..47b068385 100644 --- a/res/layout/widgets_view.xml +++ b/res/layout/widgets_view.xml @@ -53,7 +53,7 @@ style="@style/FastScrollerPopup" android:id="@+id/fast_scroller_popup" android:layout_gravity="top|end" - android:layout_marginEnd="@dimen/container_fastscroll_popup_margin" /> + android:layout_marginEnd="@dimen/fastscroll_popup_margin" /> <ProgressBar android:layout_width="wrap_content" diff --git a/res/values-land/dimens.xml b/res/values-land/dimens.xml index 391575995..b40aa14ac 100644 --- a/res/values-land/dimens.xml +++ b/res/values-land/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. @@ -15,6 +15,13 @@ --> <resources> -<!-- Container --> - <item name="container_margin" format="fraction" type="fraction">12%</item> + <!-- Container --> + <item name="container_margin" format="fraction" type="fraction">12%</item> + + <!-- Fast scroll --> + <dimen name="fastscroll_popup_width">58dp</dimen> + <dimen name="fastscroll_popup_height">48dp</dimen> + <dimen name="fastscroll_popup_padding">10dp</dimen> + <dimen name="fastscroll_popup_text_size">24dp</dimen> + </resources> diff --git a/res/values-sw720dp/dimens.xml b/res/values-sw720dp/dimens.xml index 358d9b6a0..e836d7d78 100644 --- a/res/values-sw720dp/dimens.xml +++ b/res/values-sw720dp/dimens.xml @@ -15,10 +15,16 @@ --> <resources> -<!-- All Apps --> + <!-- All Apps --> <dimen name="all_apps_button_scale_down">8dp</dimen> <dimen name="all_apps_search_bar_height">54dp</dimen> <dimen name="all_apps_empty_search_message_top_offset">64dp</dimen> <dimen name="all_apps_empty_search_bg_top_offset">180dp</dimen> + <!-- Fast scroll --> + <dimen name="fastscroll_popup_width">75dp</dimen> + <dimen name="fastscroll_popup_height">62dp</dimen> + <dimen name="fastscroll_popup_padding">13dp</dimen> + <dimen name="fastscroll_popup_text_size">32dp</dimen> + </resources> diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 3a531b08d..57b4be4e2 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -47,14 +47,18 @@ <dimen name="widget_handle_margin">13dp</dimen> <dimen name="resize_frame_background_padding">24dp</dimen> -<!-- Container --> - <dimen name="container_fastscroll_thumb_min_width">5dp</dimen> - <dimen name="container_fastscroll_thumb_max_width">9dp</dimen> - <dimen name="container_fastscroll_popup_margin">18dp</dimen> - <dimen name="container_fastscroll_thumb_height">72dp</dimen> - <dimen name="container_fastscroll_thumb_touch_inset">-24dp</dimen> - <dimen name="container_fastscroll_popup_size">72dp</dimen> - <dimen name="container_fastscroll_popup_text_size">48dp</dimen> +<!-- Fast scroll --> + <dimen name="fastscroll_track_min_width">6dp</dimen> + <dimen name="fastscroll_track_max_width">8dp</dimen> + <dimen name="fastscroll_thumb_padding">1dp</dimen> + <dimen name="fastscroll_thumb_height">52dp</dimen> + <dimen name="fastscroll_thumb_touch_inset">-24dp</dimen> + + <dimen name="fastscroll_popup_width">75dp</dimen> + <dimen name="fastscroll_popup_height">62dp</dimen> + <dimen name="fastscroll_popup_padding">13dp</dimen> + <dimen name="fastscroll_popup_text_size">32dp</dimen> + <dimen name="fastscroll_popup_margin">19dp</dimen> <!-- All Apps --> <dimen name="all_apps_button_scale_down">0dp</dimen> diff --git a/res/values/styles.xml b/res/values/styles.xml index 8af6968a6..594c7dbde 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -86,11 +86,11 @@ </style> <style name="FastScrollerPopup" > - <item name="android:background">@drawable/container_fastscroll_popup_bg</item> <item name="android:layout_width">wrap_content</item> - <item name="android:minWidth">@dimen/container_fastscroll_popup_size</item> - <item name="android:layout_height">@dimen/container_fastscroll_popup_size</item> - <item name="android:textSize">@dimen/container_fastscroll_popup_text_size</item> + <item name="android:minWidth">@dimen/fastscroll_popup_width</item> + <item name="android:layout_height">@dimen/fastscroll_popup_height</item> + <item name="android:textSize">@dimen/fastscroll_popup_text_size</item> + <item name="android:paddingEnd">@dimen/fastscroll_popup_padding</item> <item name="android:gravity">center</item> <item name="android:alpha">0</item> <item name="android:elevation">3dp</item> diff --git a/src/com/android/launcher3/BaseRecyclerView.java b/src/com/android/launcher3/BaseRecyclerView.java index 514cc0751..84358ea37 100644 --- a/src/com/android/launcher3/BaseRecyclerView.java +++ b/src/com/android/launcher3/BaseRecyclerView.java @@ -185,13 +185,6 @@ public abstract class BaseRecyclerView extends RecyclerView } /** - * Returns the track color (ignoring alpha), can be overridden by each subclass. - */ - public int getFastScrollerTrackColor(int defaultTrackColor) { - return defaultTrackColor; - } - - /** * Returns the scrollbar for this recycler view. */ public BaseRecyclerViewFastScrollBar getScrollBar() { diff --git a/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java b/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java index 303974464..9e8d300ae 100644 --- a/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java +++ b/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java @@ -29,6 +29,7 @@ import android.view.ViewConfiguration; import android.widget.TextView; import com.android.launcher3.config.FeatureFlags; +import com.android.launcher3.graphics.FastScrollThumbDrawable; import com.android.launcher3.util.Themes; /** @@ -52,7 +53,7 @@ public class BaseRecyclerViewFastScrollBar { private final static int MAX_TRACK_ALPHA = 30; private final static int SCROLL_BAR_VIS_DURATION = 150; - private static final float FAST_SCROLL_OVERLAY_Y_OFFSET_FACTOR = 1.5f; + private static final float FAST_SCROLL_OVERLAY_Y_OFFSET_FACTOR = 0.75f; private final Rect mTmpRect = new Rect(); private final BaseRecyclerView mRv; @@ -64,12 +65,12 @@ public class BaseRecyclerViewFastScrollBar { private final int mMinWidth; private final int mMaxWidth; + private final int mThumbPadding; // Current width of the track private int mWidth; private ObjectAnimator mWidthAnimator; - private final Path mThumbPath = new Path(); private final Paint mThumbPaint; private final int mThumbHeight; @@ -94,7 +95,7 @@ public class BaseRecyclerViewFastScrollBar { public BaseRecyclerViewFastScrollBar(BaseRecyclerView rv, Resources res) { mRv = rv; mTrackPaint = new Paint(); - mTrackPaint.setColor(rv.getFastScrollerTrackColor(Color.BLACK)); + mTrackPaint.setColor(Themes.getAttrColor(rv.getContext(), android.R.attr.textColorPrimary)); mTrackPaint.setAlpha(MAX_TRACK_ALPHA); mThumbPaint = new Paint(); @@ -102,16 +103,19 @@ public class BaseRecyclerViewFastScrollBar { mThumbPaint.setColor(Themes.getColorAccent(rv.getContext())); mThumbPaint.setStyle(Paint.Style.FILL); - mWidth = mMinWidth = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_min_width); - mMaxWidth = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_max_width); - mThumbHeight = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_height); - mTouchInset = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_touch_inset); + mWidth = mMinWidth = res.getDimensionPixelSize(R.dimen.fastscroll_track_min_width); + mMaxWidth = res.getDimensionPixelSize(R.dimen.fastscroll_track_max_width); + + mThumbPadding = res.getDimensionPixelSize(R.dimen.fastscroll_thumb_padding); + mThumbHeight = res.getDimensionPixelSize(R.dimen.fastscroll_thumb_height); + + mTouchInset = res.getDimensionPixelSize(R.dimen.fastscroll_thumb_touch_inset); mIsRtl = Utilities.isRtl(res); - updateThumbPath(); } public void setPopupView(View popup) { mPopupView = (TextView) popup; + mPopupView.setBackground(new FastScrollThumbDrawable(mThumbPaint, mIsRtl)); } public void setDetachThumbOnFastScroll() { @@ -154,24 +158,6 @@ public class BaseRecyclerViewFastScrollBar { mRv.invalidate(left, top, left + mMaxWidth, top + mRv.getScrollbarTrackHeight()); mWidth = width; - updateThumbPath(); - } - - /** - * Updates the path for the thumb drawable. - */ - private void updateThumbPath() { - int smallWidth = mIsRtl ? mWidth : -mWidth; - int largeWidth = mIsRtl ? mMaxWidth : -mMaxWidth; - - mThumbPath.reset(); - mThumbPath.moveTo(0, 0); - mThumbPath.lineTo(0, mThumbHeight); // Left edge - mThumbPath.lineTo(smallWidth, mThumbHeight); // bottom edge - mThumbPath.cubicTo(smallWidth, mThumbHeight, // right edge - largeWidth, mThumbHeight / 2, - smallWidth, 0); - mThumbPath.close(); } public int getThumbHeight() { @@ -265,15 +251,16 @@ public class BaseRecyclerViewFastScrollBar { } int saveCount = canvas.save(Canvas.MATRIX_SAVE_FLAG); if (!mIsRtl) { - canvas.translate(mRv.getWidth(), 0); + canvas.translate(mRv.getWidth() - mWidth, 0); } canvas.translate(0, mRv.getPaddingTop()); // Draw the track - int thumbWidth = mIsRtl ? mWidth : -mWidth; - canvas.drawRect(0, 0, thumbWidth, mRv.getScrollbarTrackHeight(), mTrackPaint); + canvas.drawRoundRect(0, 0, mWidth, mRv.getScrollbarTrackHeight(), + mWidth, mWidth, mTrackPaint); - canvas.translate(0, mThumbOffsetY); - canvas.drawPath(mThumbPath, mThumbPaint); + canvas.translate(-mThumbPadding, mThumbOffsetY); + float r = mWidth + mThumbPadding + mThumbPadding; + canvas.drawRoundRect(0, 0, r, mThumbHeight, r, r, mThumbPaint); canvas.restoreToCount(saveCount); } @@ -320,7 +307,8 @@ public class BaseRecyclerViewFastScrollBar { private void updatePopupY(int lastTouchY) { int height = mPopupView.getHeight(); float top = lastTouchY - (FAST_SCROLL_OVERLAY_Y_OFFSET_FACTOR * height); - top = Math.max(mMaxWidth, Math.min(top, mRv.getScrollbarTrackHeight() - mMaxWidth - height)); + top = Utilities.boundToRange(top, + mMaxWidth, mRv.getScrollbarTrackHeight() - mMaxWidth - height); mPopupView.setTranslationY(top); } } diff --git a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java index b2a74ff15..0607a1e5d 100644 --- a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java +++ b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java @@ -376,7 +376,8 @@ public class AllAppsRecyclerView extends BaseRecyclerView { if (position == NO_POSITION) { return -1; } - return getCurrentScrollY(position, getLayoutManager().getDecoratedTop(child)); + return getPaddingTop() + + getCurrentScrollY(position, getLayoutManager().getDecoratedTop(child)); } public int getCurrentScrollY(int position, int offset) { @@ -406,8 +407,7 @@ public class AllAppsRecyclerView extends BaseRecyclerView { } mCachedScrollPositions.put(position, y); } - - return getPaddingTop() + y - offset; + return y - offset; } /** @@ -416,7 +416,7 @@ public class AllAppsRecyclerView extends BaseRecyclerView { */ @Override protected int getAvailableScrollHeight() { - return getCurrentScrollY(mApps.getAdapterItems().size(), 0) + return getPaddingTop() + getCurrentScrollY(mApps.getAdapterItems().size(), 0) - getHeight() + getPaddingBottom(); } diff --git a/src/com/android/launcher3/graphics/FastScrollThumbDrawable.java b/src/com/android/launcher3/graphics/FastScrollThumbDrawable.java new file mode 100644 index 000000000..6ebc74eeb --- /dev/null +++ b/src/com/android/launcher3/graphics/FastScrollThumbDrawable.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2017 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.graphics; + +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.Matrix; +import android.graphics.Outline; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.PixelFormat; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; + +public class FastScrollThumbDrawable extends Drawable { + + private static final Matrix sMatrix = new Matrix(); + + private final Path mPath = new Path(); + private final Paint mPaint; + private final boolean mIsRtl; + + public FastScrollThumbDrawable(Paint paint, boolean isRtl) { + mPaint = paint; + mIsRtl = isRtl; + } + + @Override + public void getOutline(Outline outline) { + if (mPath.isConvex()) { + outline.setConvexPath(mPath); + } + } + + @Override + protected void onBoundsChange(Rect bounds) { + mPath.reset(); + + float r = bounds.height() * 0.5f; + // The path represents a rotate tear-drop shape, with radius of one corner is 1/5th of the + // other 3 corners. + float diameter = 2 * r; + float r2 = r / 5; + mPath.addRoundRect(bounds.left, bounds.top, bounds.left + diameter, bounds.top + diameter, + new float[] {r, r, r, r, r2, r2, r, r}, + Path.Direction.CCW); + + sMatrix.setRotate(-45, bounds.left + r, bounds.top + r); + if (mIsRtl) { + sMatrix.postTranslate(bounds.width(), 0); + sMatrix.postScale(-1, 1, bounds.width(), 0); + } + mPath.transform(sMatrix); + } + + @Override + public void draw(Canvas canvas) { + canvas.drawPath(mPath, mPaint); + } + + @Override + public void setAlpha(int i) { + // Not supported + } + + @Override + public void setColorFilter(ColorFilter colorFilter) { + // Not supported + } + + @Override + public int getOpacity() { + return PixelFormat.TRANSLUCENT; + } +} diff --git a/src/com/android/launcher3/widget/WidgetsRecyclerView.java b/src/com/android/launcher3/widget/WidgetsRecyclerView.java index f47ca3eeb..9730a82aa 100644 --- a/src/com/android/launcher3/widget/WidgetsRecyclerView.java +++ b/src/com/android/launcher3/widget/WidgetsRecyclerView.java @@ -59,10 +59,6 @@ public class WidgetsRecyclerView extends BaseRecyclerView { setLayoutManager(new LinearLayoutManager(getContext())); } - public int getFastScrollerTrackColor(int defaultTrackColor) { - return Color.WHITE; - } - @Override public void setAdapter(Adapter adapter) { super.setAdapter(adapter); |