summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorztenghui <ztenghui@google.com>2014-05-05 16:26:22 -0700
committerztenghui <ztenghui@google.com>2014-05-05 17:27:24 -0700
commit498213a265e05134b4a4fbf93dce69de1a47973c (patch)
treeb7e3ac490cefbc916c55dd84c60f37507c06b2bc
parent9f5957989ef8d1e2219b624d731acfbf61a366d2 (diff)
downloadframeworks_base-498213a265e05134b4a4fbf93dce69de1a47973c.zip
frameworks_base-498213a265e05134b4a4fbf93dce69de1a47973c.tar.gz
frameworks_base-498213a265e05134b4a4fbf93dce69de1a47973c.tar.bz2
First step on API cleaning on the VectorDrawable to disable animation support
Cleaning on the API level, and related tests. The animated icon will be only showing the initial state. TODO: Deep clean on the functionality part and attributes. Change-Id: I5723bc5b64f796c3a273d74bde02095751160a88
-rw-r--r--api/current.txt8
-rw-r--r--graphics/java/android/graphics/drawable/VectorDrawable.java152
-rw-r--r--tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawable01.java20
-rw-r--r--tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawablePerformance.java9
4 files changed, 2 insertions, 187 deletions
diff --git a/api/current.txt b/api/current.txt
index c1cac8a..9bfe43e 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -11126,19 +11126,11 @@ package android.graphics.drawable {
public class VectorDrawable extends android.graphics.drawable.Drawable {
ctor public VectorDrawable();
method public void draw(android.graphics.Canvas);
- method public float geAnimationFraction();
method public int getOpacity();
- method public int getRepeatCount();
method public void setAlpha(int);
- method public void setAnimationFraction(float);
method public void setColorFilter(android.graphics.ColorFilter);
- method public void setDuration(long);
method public void setPadding(android.graphics.Rect);
method public void setPadding(int, int, int, int);
- method public void setRepeatCount(int);
- method public void setRepeatMode(int);
- method public void start();
- method public void stop();
}
}
diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java
index 0992717..77712b6 100644
--- a/graphics/java/android/graphics/drawable/VectorDrawable.java
+++ b/graphics/java/android/graphics/drawable/VectorDrawable.java
@@ -182,28 +182,14 @@ public class VectorDrawable extends Drawable {
public VectorDrawable() {
mVectorState = new VectorDrawableState(null);
- mVectorState.mBasicAnimator = ObjectAnimator.ofFloat(this, "AnimationFraction", 0, 0);
-
- setDuration(DEFAULT_DURATION);
}
private VectorDrawable(VectorDrawableState state, Resources res, Theme theme) {
mVectorState = new VectorDrawableState(state);
- mVectorState.mBasicAnimator = ObjectAnimator.ofFloat(this, "AnimationFraction", 0, 0);
if (theme != null && canApplyTheme()) {
applyTheme(theme);
}
-
- long duration = mVectorState.mVAnimatedPath.getTotalAnimationDuration();
- if (duration == -1) {
- // If duration is infinite, set to 1 hour.
- // TODO: Define correct approach for infinite.
- duration = DEFAULT_INFINITE_DURATION;
- mVectorState.mBasicAnimator.setFloatValues(0, duration / 1000);
- mVectorState.mBasicAnimator.setInterpolator(new LinearInterpolator());
- }
- setDuration(duration);
}
@Override
@@ -212,118 +198,6 @@ public class VectorDrawable extends Drawable {
}
@Override
- public void jumpToCurrentState() {
- stop();
- }
-
- /**
- * Starts the animation.
- */
- public void start() {
- mVectorState.mBasicAnimator.start();
- }
-
- /**
- * Stops the animation and moves to the end state.
- */
- public void stop() {
- mVectorState.mBasicAnimator.end();
- }
-
- /**
- * Returns the current completion value for the animation.
- *
- * @return the current point on the animation, typically between 0 and 1
- */
- public float geAnimationFraction() {
- return mVectorState.mVAnimatedPath.getValue();
- }
-
- /**
- * Set the current completion value for the animation.
- *
- * @param value the point along the animation, typically between 0 and 1
- */
- public void setAnimationFraction(float value) {
- mVectorState.mVAnimatedPath.setAnimationFraction(value);
- invalidateSelf();
- }
-
- /**
- * set the amount of time the animation will take
- *
- * @param duration amount of time in milliseconds
- */
- public void setDuration(long duration) {
- mVectorState.mBasicAnimator.setDuration(duration);
- }
-
- /**
- * Defines what this animation should do when it reaches the end. This
- * setting is applied only when the repeat count is either greater than 0 or
- * {@link ValueAnimator#INFINITE}.
- *
- * @param mode the animation mode, either {@link ValueAnimator#RESTART} or
- * {@link ValueAnimator#REVERSE}
- */
- public void setRepeatMode(int mode) {
- mVectorState.mBasicAnimator.setRepeatMode(mode);
- }
-
- /**
- * Sets animation to repeat
- *
- * @param repeat True if this drawable repeats its animation
- */
- public void setRepeatCount(int repeat) {
- mVectorState.mBasicAnimator.setRepeatCount(repeat);
- }
-
- /**
- * @return the animation repeat count, either a value greater than 0 or
- * {@link ValueAnimator#INFINITE}
- */
- public int getRepeatCount() {
- return mVectorState.mBasicAnimator.getRepeatCount();
- }
-
- @Override
- public boolean isStateful() {
- return true;
- }
-
- @Override
- protected boolean onStateChange(int[] state) {
- super.onStateChange(state);
-
- mVectorState.mVAnimatedPath.setState(state);
-
- final int direction = mVectorState.mVAnimatedPath.getTrigger(state);
- if (direction > 0) {
- animateForward();
- } else if (direction < 0) {
- animateBackward();
- }
-
- invalidateSelf();
- return true;
- }
-
- private void animateForward() {
- if (!mVectorState.mBasicAnimator.isStarted()) {
- mVectorState.mBasicAnimator.setFloatValues(0, 1);
- start();
- }
- }
-
- private void animateBackward() {
- if (!mVectorState.mBasicAnimator.isStarted()) {
- mVectorState.mBasicAnimator.setFloatValues(1, 0);
- start();
- }
- }
-
- @Override
public void draw(Canvas canvas) {
final int saveCount = canvas.save();
final Rect bounds = getBounds();
@@ -432,7 +306,6 @@ public class VectorDrawable extends Drawable {
final VectorDrawable drawable = new VectorDrawable();
drawable.inflate(resources, xpp, attrs);
- drawable.setAnimationFraction(0);
return drawable;
} catch (XmlPullParserException e) {
@@ -536,35 +409,10 @@ public class VectorDrawable extends Drawable {
private void setAnimatedPath(VAnimatedPath animatedPath) {
mVectorState.mVAnimatedPath = animatedPath;
-
- long duration = mVectorState.mVAnimatedPath.getTotalAnimationDuration();
- if (duration == -1) { // if it set to infinite set to 1 hour
- duration = DEFAULT_INFINITE_DURATION; // TODO define correct
- // approach for infinite
- mVectorState.mBasicAnimator.setFloatValues(0, duration / 1000);
- mVectorState.mBasicAnimator.setInterpolator(new LinearInterpolator());
- }
-
- setDuration(duration);
- setAnimationFraction(0);
- }
-
- @Override
- public boolean setVisible(boolean visible, boolean restart) {
- boolean changed = super.setVisible(visible, restart);
- if (visible) {
- if (changed || restart) {
- setAnimationFraction(0);
- }
- } else {
- stop();
- }
- return changed;
}
private static class VectorDrawableState extends ConstantState {
int mChangingConfigurations;
- ValueAnimator mBasicAnimator;
VAnimatedPath mVAnimatedPath;
Rect mPadding;
diff --git a/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawable01.java b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawable01.java
index 88ae398..7ba01b1 100644
--- a/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawable01.java
+++ b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawable01.java
@@ -22,7 +22,7 @@ import android.widget.Button;
import android.widget.GridLayout;
@SuppressWarnings({"UnusedDeclaration"})
-public class VectorDrawable01 extends Activity implements View.OnClickListener {
+public class VectorDrawable01 extends Activity {
private static final String LOGCAT = "VectorDrawable1";
int[] icon = {
R.drawable.vector_drawable01,
@@ -61,28 +61,10 @@ public class VectorDrawable01 extends Activity implements View.OnClickListener {
button.setWidth(200);
button.setBackgroundResource(icon[i]);
container.addView(button);
- button.setOnClickListener(this);
}
- Button b = new Button(this);
- b.setText("Run All");
- b.setOnClickListener(new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- for (int i = 0; i < bArray.length; i++) {
- VectorDrawable d = (VectorDrawable) bArray[i].getBackground();
- d.start();
- }
- }});
- container.addView(b);
setContentView(container);
}
- @Override
- public void onClick(View v) {
- VectorDrawable d = (VectorDrawable) v.getBackground();
- d.start();
- }
-
}
diff --git a/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawablePerformance.java b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawablePerformance.java
index 3929298..b918cdd 100644
--- a/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawablePerformance.java
+++ b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawablePerformance.java
@@ -25,7 +25,7 @@ import android.widget.ScrollView;
import java.text.DecimalFormat;
@SuppressWarnings({"UnusedDeclaration"})
-public class VectorDrawablePerformance extends Activity implements View.OnClickListener {
+public class VectorDrawablePerformance extends Activity {
private static final String LOGCAT = "VectorDrawable1";
protected int[] icon = {
R.drawable.vector_drawable01,
@@ -76,7 +76,6 @@ public class VectorDrawablePerformance extends Activity implements View.OnClickL
button.setWidth(200);
button.setBackgroundResource(icon[i]);
container.addView(button);
- button.setOnClickListener(this);
}
setContentView(scrollView);
time = android.os.SystemClock.elapsedRealtimeNanos()-time;
@@ -85,10 +84,4 @@ public class VectorDrawablePerformance extends Activity implements View.OnClickL
t.setBackgroundColor(0xFF000000);
container.addView(t);
}
-
- @Override
- public void onClick(View v) {
- VectorDrawable d = (VectorDrawable) v.getBackground();
- d.start();
- }
}