From b0e22ecf7d00a5fe5c5999c2d39b191ceed64d83 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Tue, 12 Apr 2016 10:51:29 -0400 Subject: Add scroll indicators to resolver list Also reformats resolver list XML. Bug: 27431395 Change-Id: I582448a01747b29fc6ac61dd80e27e6679507a81 --- .../internal/widget/ResolverDrawerLayout.java | 59 +++++++- core/res/res/layout/resolver_list.xml | 106 +++++++------ core/res/res/layout/resolver_list_with_default.xml | 165 +++++++++++---------- core/res/res/values/attrs.xml | 1 + 4 files changed, 202 insertions(+), 129 deletions(-) diff --git a/core/java/com/android/internal/widget/ResolverDrawerLayout.java b/core/java/com/android/internal/widget/ResolverDrawerLayout.java index c4347f832bd5..8b9d5034b0c2 100644 --- a/core/java/com/android/internal/widget/ResolverDrawerLayout.java +++ b/core/java/com/android/internal/widget/ResolverDrawerLayout.java @@ -17,9 +17,15 @@ package com.android.internal.widget; +import com.android.internal.R; + import android.content.Context; import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.Rect; +import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; @@ -38,7 +44,6 @@ import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; import android.view.animation.AnimationUtils; import android.widget.AbsListView; import android.widget.OverScroller; -import com.android.internal.R; public class ResolverDrawerLayout extends ViewGroup { private static final String TAG = "ResolverDrawerLayout"; @@ -86,6 +91,8 @@ public class ResolverDrawerLayout extends ViewGroup { private final OverScroller mScroller; private final VelocityTracker mVelocityTracker; + private Drawable mScrollIndicatorDrawable; + private OnDismissedListener mOnDismissedListener; private RunOnDismissedListener mRunOnDismissedListener; @@ -127,6 +134,8 @@ public class ResolverDrawerLayout extends ViewGroup { mMaxCollapsedHeight); a.recycle(); + mScrollIndicatorDrawable = mContext.getDrawable(R.drawable.scroll_indicator_material); + mScroller = new OverScroller(context, AnimationUtils.loadInterpolator(context, android.R.interpolator.decelerate_quint)); mVelocityTracker = VelocityTracker.obtain(); @@ -202,8 +211,7 @@ public class ResolverDrawerLayout extends ViewGroup { } final boolean isCollapsedNew = mCollapseOffset != 0; if (isCollapsedOld != isCollapsedNew) { - notifyViewAccessibilityStateChangedIfNeeded( - AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED); + onCollapsedChanged(isCollapsedNew); } } else { // Start out collapsed at first unless we restored state for otherwise @@ -442,8 +450,7 @@ public class ResolverDrawerLayout extends ViewGroup { mTopOffset += dy; final boolean isCollapsedNew = newPos != 0; if (isCollapsedOld != isCollapsedNew) { - notifyViewAccessibilityStateChangedIfNeeded( - AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED); + onCollapsedChanged(isCollapsedNew); } postInvalidateOnAnimation(); return dy; @@ -451,6 +458,15 @@ public class ResolverDrawerLayout extends ViewGroup { return 0; } + private void onCollapsedChanged(boolean isCollapsed) { + notifyViewAccessibilityStateChangedIfNeeded( + AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED); + + if (mScrollIndicatorDrawable != null) { + setWillNotDraw(!isCollapsed); + } + } + void dispatchOnDismissed() { if (mOnDismissedListener != null) { mOnDismissedListener.onDismissed(); @@ -708,6 +724,15 @@ public class ResolverDrawerLayout extends ViewGroup { return false; } + @Override + public void onDrawForeground(Canvas canvas) { + if (mScrollIndicatorDrawable != null) { + mScrollIndicatorDrawable.draw(canvas); + } + + super.onDrawForeground(canvas); + } + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int sourceWidth = MeasureSpec.getSize(widthMeasureSpec); @@ -794,6 +819,8 @@ public class ResolverDrawerLayout extends ViewGroup { protected void onLayout(boolean changed, int l, int t, int r, int b) { final int width = getWidth(); + View indicatorHost = null; + int ypos = mTopOffset; int leftEdge = getPaddingLeft(); int rightEdge = width - getPaddingRight(); @@ -802,6 +829,9 @@ public class ResolverDrawerLayout extends ViewGroup { for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); + if (lp.hasNestedScrollIndicator) { + indicatorHost = child; + } if (child.getVisibility() == GONE) { continue; @@ -822,6 +852,20 @@ public class ResolverDrawerLayout extends ViewGroup { ypos = bottom + lp.bottomMargin; } + + if (mScrollIndicatorDrawable != null) { + if (indicatorHost != null) { + final int left = indicatorHost.getLeft(); + final int right = indicatorHost.getRight(); + final int bottom = indicatorHost.getTop(); + final int top = bottom - mScrollIndicatorDrawable.getIntrinsicHeight(); + mScrollIndicatorDrawable.setBounds(left, top, right, bottom); + setWillNotDraw(!isCollapsed()); + } else { + mScrollIndicatorDrawable = null; + setWillNotDraw(true); + } + } } @Override @@ -861,6 +905,7 @@ public class ResolverDrawerLayout extends ViewGroup { public static class LayoutParams extends MarginLayoutParams { public boolean alwaysShow; public boolean ignoreOffset; + public boolean hasNestedScrollIndicator; public LayoutParams(Context c, AttributeSet attrs) { super(c, attrs); @@ -873,6 +918,9 @@ public class ResolverDrawerLayout extends ViewGroup { ignoreOffset = a.getBoolean( R.styleable.ResolverDrawerLayout_LayoutParams_layout_ignoreOffset, false); + hasNestedScrollIndicator = a.getBoolean( + R.styleable.ResolverDrawerLayout_LayoutParams_layout_hasNestedScrollIndicator, + false); a.recycle(); } @@ -884,6 +932,7 @@ public class ResolverDrawerLayout extends ViewGroup { super(source); this.alwaysShow = source.alwaysShow; this.ignoreOffset = source.ignoreOffset; + this.hasNestedScrollIndicator = source.hasNestedScrollIndicator; } public LayoutParams(MarginLayoutParams source) { diff --git a/core/res/res/layout/resolver_list.xml b/core/res/res/layout/resolver_list.xml index 5850e5090926..ae945031f11d 100644 --- a/core/res/res/layout/resolver_list.xml +++ b/core/res/res/layout/resolver_list.xml @@ -30,33 +30,37 @@ android:layout_height="wrap_content" android:layout_alwaysShow="true" android:elevation="8dp" - android:background="@color/white" > - - + android:background="@color/white"> + + + + -