summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2021-01-27 22:29:05 +0000
committerGeorge Mount <mount@google.com>2021-02-10 15:48:02 +0000
commitba1c4c4e303af50175372b80778003fb2e945da2 (patch)
treeaae065f85b7f30130149f24ca06ffa3c34d357d2 /core/java/android
parentb4080f637b7bb846cdba516f6ac086f663a3b553 (diff)
Add edgeEffectType attribute and type property
Bug: 178807038 This adds the edgeEffectType property and type attribute. These will be used to enable stretchy edge effect for overscroll. Merged-In: I16f20b36d9a15c08e0a37f98572ef9c9f8fbc88f Test: new CTS test for setting/retrieving the effect type. Test: Ic363f71d241649d15faa86434516457e62b261f4 Change-Id: I16f20b36d9a15c08e0a37f98572ef9c9f8fbc88f
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/widget/EdgeEffect.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/core/java/android/widget/EdgeEffect.java b/core/java/android/widget/EdgeEffect.java
index c10ffbee686a..61ff36c09cb9 100644
--- a/core/java/android/widget/EdgeEffect.java
+++ b/core/java/android/widget/EdgeEffect.java
@@ -17,6 +17,7 @@
package android.widget;
import android.annotation.ColorInt;
+import android.annotation.IntDef;
import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
@@ -30,6 +31,9 @@ import android.view.animation.AnimationUtils;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
/**
* This class performs the graphical effect used at the edges of scrollable widgets
* when the user scrolls beyond the content bounds in 2D space.
@@ -55,6 +59,24 @@ public class EdgeEffect {
*/
public static final BlendMode DEFAULT_BLEND_MODE = BlendMode.SRC_ATOP;
+ /**
+ * Use a color edge glow for the edge effect. From XML, use
+ * <code>android:edgeEffectType="glow"</code>.
+ */
+ public static final int TYPE_GLOW = 0;
+
+ /**
+ * Use a stretch for the edge effect. From XML, use
+ * <code>android:edgeEffectType="stretch"</code>.
+ */
+ public static final int TYPE_STRETCH = 1;
+
+ /** @hide */
+ @IntDef({TYPE_GLOW, TYPE_STRETCH})
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface EdgeEffectType {
+ }
+
@SuppressWarnings("UnusedDeclaration")
private static final String TAG = "EdgeEffect";
@@ -121,6 +143,7 @@ public class EdgeEffect {
private float mBaseGlowScale;
private float mDisplacement = 0.5f;
private float mTargetDisplacement = 0.5f;
+ private @EdgeEffectType int mEdgeEffectType = TYPE_GLOW;
/**
* Construct a new EdgeEffect with a theme appropriate for the provided context.
@@ -132,6 +155,8 @@ public class EdgeEffect {
com.android.internal.R.styleable.EdgeEffect);
final int themeColor = a.getColor(
com.android.internal.R.styleable.EdgeEffect_colorEdgeEffect, 0xff666666);
+ mEdgeEffectType = a.getInt(
+ com.android.internal.R.styleable.EdgeEffect_edgeEffectType, TYPE_GLOW);
a.recycle();
mPaint.setColor((themeColor & 0xffffff) | 0x33000000);
mPaint.setStyle(Paint.Style.FILL);
@@ -309,6 +334,17 @@ public class EdgeEffect {
}
/**
+ * Sets the edge effect type to use. The default without a theme attribute set is
+ * {@link EdgeEffect#TYPE_GLOW}.
+ *
+ * @param type The edge effect type to use.
+ * @attr ref android.R.styleable#EdgeEffect_edgeEffectType
+ */
+ public void setType(@EdgeEffectType int type) {
+ mEdgeEffectType = type;
+ }
+
+ /**
* Set or clear the blend mode. A blend mode defines how source pixels
* (generated by a drawing command) are composited with the destination pixels
* (content of the render target).
@@ -333,6 +369,15 @@ public class EdgeEffect {
return mPaint.getColor();
}
+ /**
+ * Return the edge effect type to use.
+ *
+ * @return The edge effect type to use.
+ * @attr ref android.R.styleable#EdgeEffect_edgeEffectType
+ */
+ public @EdgeEffectType int getType() {
+ return mEdgeEffectType;
+ }
/**
* Returns the blend mode. A blend mode defines how source pixels