diff options
| author | Alan Viverette <alanv@google.com> | 2016-04-14 01:45:33 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-04-14 01:45:35 +0000 |
| commit | 8bb7ad598560fda42ec256f02ba69cf54b433a85 (patch) | |
| tree | 3734f756f925b68f23d5858277468e8c01bdd96c /core/java | |
| parent | 6309cabcda6a6a3e2e397808f34ec6cc91b535aa (diff) | |
| parent | b0e22ecf7d00a5fe5c5999c2d39b191ceed64d83 (diff) | |
Merge "Add scroll indicators to resolver list" into nyc-dev
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/com/android/internal/widget/ResolverDrawerLayout.java | 59 |
1 files changed, 54 insertions, 5 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(); @@ -709,6 +725,15 @@ public class ResolverDrawerLayout extends ViewGroup { } @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); int widthSize = sourceWidth; @@ -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) { |
