summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yigit Boyar <yboyar@google.com> 2019-02-07 21:31:38 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-02-07 21:31:38 +0000
commit68d28e3fcb2e611b779cdfd7be84e91afe54e7ca (patch)
tree9dd70145174599d91f333b3ee2b4f66720c26151
parentb9218244e61995da9dd47e9bdf8f61dccc2d0eb2 (diff)
parentb621847ec67a0b6d354a7d1148ffc9b80c99ee69 (diff)
Merge "Add edge effect color APIs to AbsListView"
-rw-r--r--api/current.txt5
-rw-r--r--core/java/android/widget/AbsListView.java117
2 files changed, 97 insertions, 25 deletions
diff --git a/api/current.txt b/api/current.txt
index d6f0955dbca9..9366a9b45225 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -54849,6 +54849,7 @@ package android.widget {
method public void deferNotifyDataSetChanged();
method public void fling(int);
method public android.widget.AbsListView.LayoutParams generateLayoutParams(android.util.AttributeSet);
+ method @ColorInt public int getBottomEdgeEffectColor();
method @android.view.ViewDebug.ExportedProperty(category="drawing") @ColorInt public int getCacheColorHint();
method public int getCheckedItemCount();
method public long[] getCheckedItemIds();
@@ -54863,6 +54864,7 @@ package android.widget {
method @android.view.ViewDebug.ExportedProperty public android.view.View getSelectedView();
method public android.graphics.drawable.Drawable getSelector();
method public CharSequence getTextFilter();
+ method @ColorInt public int getTopEdgeEffectColor();
method public int getTranscriptMode();
method protected void handleDataChanged();
method public boolean hasTextFilter();
@@ -54890,9 +54892,11 @@ package android.widget {
method public void reclaimViews(java.util.List<android.view.View>);
method public void scrollListBy(int);
method public void setAdapter(android.widget.ListAdapter);
+ method public void setBottomEdgeEffectColor(@ColorInt int);
method public void setCacheColorHint(@ColorInt int);
method public void setChoiceMode(int);
method public void setDrawSelectorOnTop(boolean);
+ method public void setEdgeEffectColor(@ColorInt int);
method public void setFastScrollAlwaysVisible(boolean);
method public void setFastScrollEnabled(boolean);
method public void setFastScrollStyle(int);
@@ -54911,6 +54915,7 @@ package android.widget {
method public void setSmoothScrollbarEnabled(boolean);
method public void setStackFromBottom(boolean);
method public void setTextFilterEnabled(boolean);
+ method public void setTopEdgeEffectColor(@ColorInt int);
method public void setTranscriptMode(int);
method public void setVelocityScale(float);
method public void smoothScrollBy(int, int);
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index 542df4562908..1f8a9086ccb6 100644
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -708,15 +708,23 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
/**
* Tracks the state of the top edge glow.
+ *
+ * Even though this field is practically final, we cannot make it final because there are apps
+ * setting it via reflection and they need to keep working until they target Q.
*/
- @UnsupportedAppUsage
- private EdgeEffect mEdgeGlowTop;
+ @NonNull
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123769408)
+ private EdgeEffect mEdgeGlowTop = new EdgeEffect(mContext);
/**
* Tracks the state of the bottom edge glow.
+ *
+ * Even though this field is practically final, we cannot make it final because there are apps
+ * setting it via reflection and they need to keep working until they target Q.
*/
- @UnsupportedAppUsage
- private EdgeEffect mEdgeGlowBottom;
+ @NonNull
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768444)
+ private EdgeEffect mEdgeGlowBottom = new EdgeEffect(mContext);
/**
* An estimate of how many pixels are between the top of the list and
@@ -923,21 +931,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
mDensityScale = getContext().getResources().getDisplayMetrics().density;
}
- @Override
- public void setOverScrollMode(int mode) {
- if (mode != OVER_SCROLL_NEVER) {
- if (mEdgeGlowTop == null) {
- Context context = getContext();
- mEdgeGlowTop = new EdgeEffect(context);
- mEdgeGlowBottom = new EdgeEffect(context);
- }
- } else {
- mEdgeGlowTop = null;
- mEdgeGlowBottom = null;
- }
- super.setOverScrollMode(mode);
- }
-
/**
* {@inheritDoc}
*/
@@ -3772,7 +3765,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
}
private void invalidateTopGlow() {
- if (mEdgeGlowTop == null) {
+ if (!shouldDisplayEdgeEffects()) {
return;
}
final boolean clipToPadding = getClipToPadding();
@@ -3783,7 +3776,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
}
private void invalidateBottomGlow() {
- if (mEdgeGlowBottom == null) {
+ if (!shouldDisplayEdgeEffects()) {
return;
}
final boolean clipToPadding = getClipToPadding();
@@ -4208,7 +4201,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
setPressed(false);
- if (mEdgeGlowTop != null) {
+ if (shouldDisplayEdgeEffects()) {
mEdgeGlowTop.onRelease();
mEdgeGlowBottom.onRelease();
}
@@ -4233,6 +4226,10 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
}
}
+ private boolean shouldDisplayEdgeEffects() {
+ return getOverScrollMode() != OVER_SCROLL_NEVER;
+ }
+
private void onTouchCancel() {
switch (mTouchMode) {
case TOUCH_MODE_OVERSCROLL:
@@ -4258,7 +4255,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
recycleVelocityTracker();
}
- if (mEdgeGlowTop != null) {
+ if (shouldDisplayEdgeEffects()) {
mEdgeGlowTop.onRelease();
mEdgeGlowBottom.onRelease();
}
@@ -4379,7 +4376,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
- if (mEdgeGlowTop != null) {
+ if (shouldDisplayEdgeEffects()) {
final int scrollY = mScrollY;
final boolean clipToPadding = getClipToPadding();
final int width;
@@ -6371,7 +6368,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
}
private void finishGlows() {
- if (mEdgeGlowTop != null) {
+ if (shouldDisplayEdgeEffects()) {
mEdgeGlowTop.finish();
mEdgeGlowBottom.finish();
}
@@ -6478,6 +6475,76 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
}
/**
+ * Sets the edge effect color for both top and bottom edge effects.
+ *
+ * @param color The color for the edge effects.
+ * @see #setTopEdgeEffectColor(int)
+ * @see #setBottomEdgeEffectColor(int)
+ * @see #getTopEdgeEffectColor()
+ * @see #getBottomEdgeEffectColor()
+ */
+ public void setEdgeEffectColor(@ColorInt int color) {
+ setTopEdgeEffectColor(color);
+ setBottomEdgeEffectColor(color);
+ }
+
+ /**
+ * Sets the bottom edge effect color.
+ *
+ * @param color The color for the bottom edge effect.
+ * @see #setTopEdgeEffectColor(int)
+ * @see #setEdgeEffectColor(int)
+ * @see #getTopEdgeEffectColor()
+ * @see #getBottomEdgeEffectColor()
+ */
+ public void setBottomEdgeEffectColor(@ColorInt int color) {
+ mEdgeGlowBottom.setColor(color);
+ invalidateBottomGlow();
+ }
+
+ /**
+ * Sets the top edge effect color.
+ *
+ * @param color The color for the top edge effect.
+ * @see #setBottomEdgeEffectColor(int)
+ * @see #setEdgeEffectColor(int)
+ * @see #getTopEdgeEffectColor()
+ * @see #getBottomEdgeEffectColor()
+ */
+ public void setTopEdgeEffectColor(@ColorInt int color) {
+ mEdgeGlowTop.setColor(color);
+ invalidateTopGlow();
+ }
+
+ /**
+ * Returns the top edge effect color.
+ *
+ * @return The top edge effect color.
+ * @see #setEdgeEffectColor(int)
+ * @see #setTopEdgeEffectColor(int)
+ * @see #setBottomEdgeEffectColor(int)
+ * @see #getBottomEdgeEffectColor()
+ */
+ @ColorInt
+ public int getTopEdgeEffectColor() {
+ return mEdgeGlowTop.getColor();
+ }
+
+ /**
+ * Returns the bottom edge effect color.
+ *
+ * @return The bottom edge effect color.
+ * @see #setEdgeEffectColor(int)
+ * @see #setTopEdgeEffectColor(int)
+ * @see #setBottomEdgeEffectColor(int)
+ * @see #getTopEdgeEffectColor()
+ */
+ @ColorInt
+ public int getBottomEdgeEffectColor() {
+ return mEdgeGlowBottom.getColor();
+ }
+
+ /**
* Sets the recycler listener to be notified whenever a View is set aside in
* the recycler for later reuse. This listener can be used to free resources
* associated to the View.