OSDN Git Service

Update scrollbars to match Material spec
authorAlan Viverette <alanv@google.com>
Fri, 21 Nov 2014 00:07:59 +0000 (16:07 -0800)
committerAlan Viverette <alanv@google.com>
Fri, 21 Nov 2014 00:07:59 +0000 (16:07 -0800)
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

21 files changed:
core/java/android/widget/FastScroller.java
core/res/res/drawable-hdpi/fastscroll_thumb_mtrl_alpha.png [deleted file]
core/res/res/drawable-hdpi/fastscroll_track_mtrl_alpha.9.png [deleted file]
core/res/res/drawable-hdpi/scrollbar_handle_mtrl_alpha.9.png [deleted file]
core/res/res/drawable-ldpi/fastscroll_thumb_mtrl_alpha.png [deleted file]
core/res/res/drawable-ldpi/fastscroll_track_mtrl_alpha.9.png [deleted file]
core/res/res/drawable-ldpi/scrollbar_handle_mtrl_alpha.9.png [deleted file]
core/res/res/drawable-mdpi/fastscroll_thumb_mtrl_alpha.png [deleted file]
core/res/res/drawable-mdpi/fastscroll_track_mtrl_alpha.9.png [deleted file]
core/res/res/drawable-mdpi/scrollbar_handle_mtrl_alpha.9.png [deleted file]
core/res/res/drawable-xhdpi/fastscroll_thumb_mtrl_alpha.png [deleted file]
core/res/res/drawable-xhdpi/fastscroll_track_mtrl_alpha.9.png [deleted file]
core/res/res/drawable-xhdpi/scrollbar_handle_mtrl_alpha.9.png [deleted file]
core/res/res/drawable-xxhdpi/fastscroll_thumb_mtrl_alpha.png [deleted file]
core/res/res/drawable-xxhdpi/fastscroll_track_mtrl_alpha.9.png [deleted file]
core/res/res/drawable-xxhdpi/scrollbar_handle_mtrl_alpha.9.png [deleted file]
core/res/res/drawable/fastscroll_thumb_material.xml
core/res/res/drawable/fastscroll_track_material.xml
core/res/res/drawable/scrollbar_handle_material.xml
core/res/res/values/dimens.xml
core/res/res/values/symbols.xml

index 06bb32c..fe143de 100644 (file)
@@ -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.
@@ -254,6 +257,9 @@ class FastScroller {
         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();
@@ -1474,10 +1480,18 @@ class FastScroller {
     }
 
     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;
         }
     }
 
@@ -1485,7 +1499,12 @@ class FastScroller {
         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);
     }
 
     /**
diff --git a/core/res/res/drawable-hdpi/fastscroll_thumb_mtrl_alpha.png b/core/res/res/drawable-hdpi/fastscroll_thumb_mtrl_alpha.png
deleted file mode 100644 (file)
index 2000422..0000000
Binary files a/core/res/res/drawable-hdpi/fastscroll_thumb_mtrl_alpha.png and /dev/null differ
diff --git a/core/res/res/drawable-hdpi/fastscroll_track_mtrl_alpha.9.png b/core/res/res/drawable-hdpi/fastscroll_track_mtrl_alpha.9.png
deleted file mode 100644 (file)
index 61ef6f6..0000000
Binary files a/core/res/res/drawable-hdpi/fastscroll_track_mtrl_alpha.9.png and /dev/null differ
diff --git a/core/res/res/drawable-hdpi/scrollbar_handle_mtrl_alpha.9.png b/core/res/res/drawable-hdpi/scrollbar_handle_mtrl_alpha.9.png
deleted file mode 100644 (file)
index a5166f2..0000000
Binary files a/core/res/res/drawable-hdpi/scrollbar_handle_mtrl_alpha.9.png and /dev/null differ
diff --git a/core/res/res/drawable-ldpi/fastscroll_thumb_mtrl_alpha.png b/core/res/res/drawable-ldpi/fastscroll_thumb_mtrl_alpha.png
deleted file mode 100644 (file)
index c901730..0000000
Binary files a/core/res/res/drawable-ldpi/fastscroll_thumb_mtrl_alpha.png and /dev/null differ
diff --git a/core/res/res/drawable-ldpi/fastscroll_track_mtrl_alpha.9.png b/core/res/res/drawable-ldpi/fastscroll_track_mtrl_alpha.9.png
deleted file mode 100644 (file)
index 833dac9..0000000
Binary files a/core/res/res/drawable-ldpi/fastscroll_track_mtrl_alpha.9.png and /dev/null differ
diff --git a/core/res/res/drawable-ldpi/scrollbar_handle_mtrl_alpha.9.png b/core/res/res/drawable-ldpi/scrollbar_handle_mtrl_alpha.9.png
deleted file mode 100644 (file)
index 3e301ef..0000000
Binary files a/core/res/res/drawable-ldpi/scrollbar_handle_mtrl_alpha.9.png and /dev/null differ
diff --git a/core/res/res/drawable-mdpi/fastscroll_thumb_mtrl_alpha.png b/core/res/res/drawable-mdpi/fastscroll_thumb_mtrl_alpha.png
deleted file mode 100644 (file)
index 4984f9c..0000000
Binary files a/core/res/res/drawable-mdpi/fastscroll_thumb_mtrl_alpha.png and /dev/null differ
diff --git a/core/res/res/drawable-mdpi/fastscroll_track_mtrl_alpha.9.png b/core/res/res/drawable-mdpi/fastscroll_track_mtrl_alpha.9.png
deleted file mode 100644 (file)
index 4041808..0000000
Binary files a/core/res/res/drawable-mdpi/fastscroll_track_mtrl_alpha.9.png and /dev/null differ
diff --git a/core/res/res/drawable-mdpi/scrollbar_handle_mtrl_alpha.9.png b/core/res/res/drawable-mdpi/scrollbar_handle_mtrl_alpha.9.png
deleted file mode 100644 (file)
index 1834b2e..0000000
Binary files a/core/res/res/drawable-mdpi/scrollbar_handle_mtrl_alpha.9.png and /dev/null differ
diff --git a/core/res/res/drawable-xhdpi/fastscroll_thumb_mtrl_alpha.png b/core/res/res/drawable-xhdpi/fastscroll_thumb_mtrl_alpha.png
deleted file mode 100644 (file)
index 9534f78..0000000
Binary files a/core/res/res/drawable-xhdpi/fastscroll_thumb_mtrl_alpha.png and /dev/null differ
diff --git a/core/res/res/drawable-xhdpi/fastscroll_track_mtrl_alpha.9.png b/core/res/res/drawable-xhdpi/fastscroll_track_mtrl_alpha.9.png
deleted file mode 100644 (file)
index 02f0174..0000000
Binary files a/core/res/res/drawable-xhdpi/fastscroll_track_mtrl_alpha.9.png and /dev/null differ
diff --git a/core/res/res/drawable-xhdpi/scrollbar_handle_mtrl_alpha.9.png b/core/res/res/drawable-xhdpi/scrollbar_handle_mtrl_alpha.9.png
deleted file mode 100644 (file)
index 3c816c7..0000000
Binary files a/core/res/res/drawable-xhdpi/scrollbar_handle_mtrl_alpha.9.png and /dev/null differ
diff --git a/core/res/res/drawable-xxhdpi/fastscroll_thumb_mtrl_alpha.png b/core/res/res/drawable-xxhdpi/fastscroll_thumb_mtrl_alpha.png
deleted file mode 100644 (file)
index 55a73e7..0000000
Binary files a/core/res/res/drawable-xxhdpi/fastscroll_thumb_mtrl_alpha.png and /dev/null differ
diff --git a/core/res/res/drawable-xxhdpi/fastscroll_track_mtrl_alpha.9.png b/core/res/res/drawable-xxhdpi/fastscroll_track_mtrl_alpha.9.png
deleted file mode 100644 (file)
index be64a94..0000000
Binary files a/core/res/res/drawable-xxhdpi/fastscroll_track_mtrl_alpha.9.png and /dev/null differ
diff --git a/core/res/res/drawable-xxhdpi/scrollbar_handle_mtrl_alpha.9.png b/core/res/res/drawable-xxhdpi/scrollbar_handle_mtrl_alpha.9.png
deleted file mode 100644 (file)
index c1c0622..0000000
Binary files a/core/res/res/drawable-xxhdpi/scrollbar_handle_mtrl_alpha.9.png and /dev/null differ
index 1288f0d..4e8ccc7 100644 (file)
 
 <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>
index 60f79b1..7882b05 100644 (file)
@@ -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>
index a241428..1b3bb9b 100644 (file)
@@ -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>
index b4e033c..3f840ab 100644 (file)
     <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>
 
index cbc379b..a91119f 100644 (file)
   <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>