summaryrefslogtreecommitdiff
path: root/core/java/android/widget/SmartSelectSprite.java
diff options
context:
space:
mode:
authorPetar Šegina <psegina@google.com>2017-09-05 20:48:42 +0100
committerPetar Šegina <psegina@google.com>2017-09-06 14:26:28 +0100
commit5ab7bb242e8b24c1952cba16cc629b7174344937 (patch)
treea9f5a02705c83587af3ba01f8f52df5c36e6160d /core/java/android/widget/SmartSelectSprite.java
parentcc78299968e7f8815dba58ae975f93d1c14992e9 (diff)
Draw SmartSelectSprite in TextView
Instead of the SmartSelectSprite drawing its contents into a View's ViewOverlay, the SmartSelectSprite can now be drawn on any Canvas. In order to perform the smart select animation, it is now the TextView that performs the actual drawing. Since the TextView can adjust the canvas for its padding and offset, there is no more need to manually transform the selection rectangles, so that part can be removed. Test: manual - verify smart select animation still works Change-Id: Ibaccf59fd44d5701e6f37d6b4fa97f2b05fd77cc
Diffstat (limited to 'core/java/android/widget/SmartSelectSprite.java')
-rw-r--r--core/java/android/widget/SmartSelectSprite.java32
1 files changed, 19 insertions, 13 deletions
diff --git a/core/java/android/widget/SmartSelectSprite.java b/core/java/android/widget/SmartSelectSprite.java
index 8d06f5fdfaf2..27b93bc74969 100644
--- a/core/java/android/widget/SmartSelectSprite.java
+++ b/core/java/android/widget/SmartSelectSprite.java
@@ -36,11 +36,11 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.Shape;
import android.util.TypedValue;
-import android.view.View;
-import android.view.ViewOverlay;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
+import com.android.internal.util.Preconditions;
+
import java.lang.annotation.Retention;
import java.util.Collections;
import java.util.Comparator;
@@ -50,7 +50,6 @@ import java.util.List;
/**
* A utility class for creating and animating the Smart Select animation.
*/
-// TODO Do not rely on ViewOverlays for drawing the Smart Select sprite
final class SmartSelectSprite {
private static final int EXPAND_DURATION = 300;
@@ -65,8 +64,8 @@ final class SmartSelectSprite {
private final Interpolator mCornerInterpolator;
private final float mStrokeWidth;
- private final View mView;
private Animator mActiveAnimator = null;
+ private final Runnable mInvalidator;
@ColorInt
private final int mStrokeColor;
@@ -331,8 +330,12 @@ final class SmartSelectSprite {
}
- SmartSelectSprite(final View view) {
- final Context context = view.getContext();
+ /**
+ * @param context The {@link Context} in which the animation will run
+ * @param invalidator A {@link Runnable} which will be called every time the animation updates,
+ * indicating that the view drawing the animation should invalidate itself
+ */
+ SmartSelectSprite(final Context context, final Runnable invalidator) {
mExpandInterpolator = AnimationUtils.loadInterpolator(
context,
android.R.interpolator.fast_out_slow_in);
@@ -341,7 +344,7 @@ final class SmartSelectSprite {
android.R.interpolator.fast_out_linear_in);
mStrokeWidth = dpToPixel(context, STROKE_WIDTH_DP);
mStrokeColor = getStrokeColor(context);
- mView = view;
+ mInvalidator = Preconditions.checkNotNull(invalidator);
}
/**
@@ -366,7 +369,7 @@ final class SmartSelectSprite {
cancelAnimation();
final ValueAnimator.AnimatorUpdateListener updateListener =
- valueAnimator -> mView.invalidate();
+ valueAnimator -> mInvalidator.run();
final List<RoundedRectangleShape> shapes = new LinkedList<>();
final List<Animator> cornerAnimators = new LinkedList<>();
@@ -421,7 +424,6 @@ final class SmartSelectSprite {
mExistingRectangleList = rectangleList;
mExistingDrawable = shapeDrawable;
- mView.getOverlay().add(shapeDrawable);
mActiveAnimator = createAnimator(rectangleList, startingOffsetLeft, startingOffsetRight,
cornerAnimators, updateListener,
@@ -480,7 +482,7 @@ final class SmartSelectSprite {
@Override
public void onAnimationEnd(Animator animator) {
mExistingRectangleList.setDisplayType(RectangleList.DisplayType.POLYGON);
- mExistingDrawable.invalidateSelf();
+ mInvalidator.run();
onAnimationEnd.run();
}
@@ -581,11 +583,9 @@ final class SmartSelectSprite {
}
private void removeExistingDrawables() {
- final ViewOverlay overlay = mView.getOverlay();
- overlay.remove(mExistingDrawable);
-
mExistingDrawable = null;
mExistingRectangleList = null;
+ mInvalidator.run();
}
/**
@@ -599,4 +599,10 @@ final class SmartSelectSprite {
}
}
+ public void draw(Canvas canvas) {
+ if (mExistingDrawable != null) {
+ mExistingDrawable.draw(canvas);
+ }
+ }
+
}