Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Update scrollbars to match Material spec
Browse files Browse the repository at this point in the history
Adds a minimum touch target size to the fast scroller so that we can
edge-align an 8dp thumb but still maintain a 48dp touch target.

BUG: 18467743
Change-Id: I31e9cf1948856f5fce7d75383b84a9359684ebe5
  • Loading branch information
alanv committed Nov 21, 2014
1 parent df84cb9 commit 7d5bcd7
Show file tree
Hide file tree
Showing 21 changed files with 48 additions and 13 deletions.
25 changes: 22 additions & 3 deletions core/java/android/widget/FastScroller.java
Expand Up @@ -106,6 +106,9 @@ class FastScroller {
*/
private final int[] mPreviewResId = new int[2];

/** The minimum touch target size in pixels. */
private final int mMinimumTouchTarget;

/**
* Padding in pixels around the preview text. Applied as layout margins to
* the preview text and padding to the preview image.
Expand Down Expand Up @@ -254,6 +257,9 @@ public FastScroller(AbsListView listView, int styleResId) {
mPrimaryText = createPreviewTextView(context);
mSecondaryText = createPreviewTextView(context);

mMinimumTouchTarget = listView.getResources().getDimensionPixelSize(
com.android.internal.R.dimen.fast_scroller_minimum_touch_target);

setStyle(styleResId);

final ViewGroupOverlay overlay = listView.getOverlay();
Expand Down Expand Up @@ -1474,18 +1480,31 @@ private boolean isPointInside(float x, float y) {
}

private boolean isPointInsideX(float x) {
final float offset = mThumbImage.getTranslationX();
final float left = mThumbImage.getLeft() + offset;
final float right = mThumbImage.getRight() + offset;

// Apply the minimum touch target size.
final float targetSizeDiff = mMinimumTouchTarget - (right - left);
final float adjust = targetSizeDiff > 0 ? targetSizeDiff : 0;

if (mLayoutFromRight) {
return x >= mThumbImage.getLeft();
return x >= mThumbImage.getLeft() - adjust;
} else {
return x <= mThumbImage.getRight();
return x <= mThumbImage.getRight() + adjust;
}
}

private boolean isPointInsideY(float y) {
final float offset = mThumbImage.getTranslationY();
final float top = mThumbImage.getTop() + offset;
final float bottom = mThumbImage.getBottom() + offset;
return y >= top && y <= bottom;

// Apply the minimum touch target size.
final float targetSizeDiff = mMinimumTouchTarget - (bottom - top);
final float adjust = targetSizeDiff > 0 ? targetSizeDiff / 2 : 0;

return y >= (top - adjust) && y <= (bottom + adjust);
}

/**
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
14 changes: 10 additions & 4 deletions core/res/res/drawable/fastscroll_thumb_material.xml
Expand Up @@ -16,11 +16,17 @@

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<bitmap android:src="@drawable/fastscroll_thumb_mtrl_alpha"
android:tint="?attr/colorControlActivated" />
<shape android:tint="?attr/colorControlActivated"
android:shape="rectangle">
<solid android:color="@color/white" />
<size android:width="8dp" android:height="48dp" />
</shape>
</item>
<item>
<bitmap android:src="@drawable/fastscroll_thumb_mtrl_alpha"
android:tint="?attr/colorControlNormal" />
<shape android:tint="?attr/colorControlNormal"
android:shape="rectangle">
<solid android:color="@color/white" />
<size android:width="8dp" android:height="48dp" />
</shape>
</item>
</selector>
9 changes: 6 additions & 3 deletions core/res/res/drawable/fastscroll_track_material.xml
Expand Up @@ -14,6 +14,9 @@
limitations under the License.
-->

<nine-patch xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/fastscroll_track_mtrl_alpha"
android:tint="?attr/colorControlNormal" />
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:tint="?attr/colorControlNormal"
android:shape="rectangle">
<solid android:color="#21ffffff" />
<size android:width="8dp" />
</shape>
9 changes: 6 additions & 3 deletions core/res/res/drawable/scrollbar_handle_material.xml
Expand Up @@ -14,6 +14,9 @@
limitations under the License.
-->

<nine-patch xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/scrollbar_handle_mtrl_alpha"
android:tint="?attr/colorControlNormal" />
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:tint="?attr/colorControlNormal"
android:shape="rectangle">
<solid android:color="#42ffffff" />
<size android:width="4dp" />
</shape>
3 changes: 3 additions & 0 deletions core/res/res/values/dimens.xml
Expand Up @@ -397,6 +397,9 @@
<dimen name="datepicker_header_height">30dp</dimen>
<dimen name="datepicker_header_text_size">14dp</dimen>

<!-- Minimum size of the fast scroller thumb's touch target. -->
<dimen name="fast_scroller_minimum_touch_target">48dp</dimen>

<!-- width of ImmersiveModeConfirmation (-1 for match_parent) -->
<dimen name="immersive_mode_cling_width">-1px</dimen>

Expand Down
1 change: 1 addition & 0 deletions core/res/res/values/symbols.xml
Expand Up @@ -2126,5 +2126,6 @@
<java-symbol type="string" name="android_system_label" />
<java-symbol type="string" name="system_error_wipe_data" />
<java-symbol type="string" name="system_error_manufacturer" />
<java-symbol type="dimen" name="fast_scroller_minimum_touch_target" />

</resources>

0 comments on commit 7d5bcd7

Please sign in to comment.