| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package com.android.test.dynamic; |
| 16 |
|
| 17 |
import android.app.Activity; |
| 18 |
import android.graphics.drawable.Animatable2; |
| 19 |
import android.graphics.drawable.AnimatedVectorDrawable; |
| 20 |
import android.graphics.drawable.Drawable; |
| 21 |
import android.os.Bundle; |
| 22 |
import android.util.Log; |
| 23 |
import android.view.View; |
| 24 |
import android.widget.Button; |
| 25 |
import android.widget.GridLayout; |
| 26 |
import android.widget.ScrollView; |
| 27 |
import android.widget.TextView; |
| 28 |
|
| 29 |
public class AnimatedVectorDrawableTest extends Activity implements View.OnClickListener { |
| 30 |
private static final String LOGCAT = "AnimatedVectorDrawableTest"; |
| 31 |
|
| 32 |
protected int[] icon = { |
| 33 |
R.drawable.btn_radio_on_to_off_bundle, |
| 34 |
R.drawable.ic_rotate_2_portrait_v2_animation, |
| 35 |
R.drawable.ic_signal_airplane_v2_animation, |
| 36 |
R.drawable.ic_hourglass_animation, |
| 37 |
R.drawable.animation_vector_linear_progress_bar, |
| 38 |
R.drawable.animation_vector_drawable_grouping_1, |
| 39 |
R.drawable.animation_vector_progress_bar, |
| 40 |
R.drawable.animation_vector_drawable_favorite, |
| 41 |
R.drawable.animation_vector_drawable01, |
| 42 |
|
| 43 |
R.drawable.animation_vector_drawable01, |
| 44 |
}; |
| 45 |
|
| 46 |
@Override |
| 47 |
protected void onCreate(Bundle savedInstanceState) { |
| 48 |
final int[] layerTypes = {View.LAYER_TYPE_SOFTWARE, View.LAYER_TYPE_HARDWARE}; |
| 49 |
final boolean[] forceOnUi = {false, true}; |
| 50 |
super.onCreate(savedInstanceState); |
| 51 |
|
| 52 |
ScrollView scrollView = new ScrollView(this); |
| 53 |
GridLayout container = new GridLayout(this); |
| 54 |
scrollView.addView(container); |
| 55 |
container.setColumnCount(layerTypes.length * forceOnUi.length); |
| 56 |
|
| 57 |
for (int j = 0; j < layerTypes.length; j++) { |
| 58 |
for (int k = 0; k < forceOnUi.length; k++) { |
| 59 |
TextView textView = new TextView(this); |
| 60 |
String category = "Layer:" |
| 61 |
+ (layerTypes[j] == View.LAYER_TYPE_SOFTWARE ? "SW" : "HW") |
| 62 |
+ (forceOnUi[k] == true ? ",forceUI" : ""); |
| 63 |
textView.setText(category); |
| 64 |
container.addView(textView); |
| 65 |
} |
| 66 |
} |
| 67 |
for (int i = 0; i < icon.length; i++) { |
| 68 |
for (int j = 0; j < layerTypes.length; j++) { |
| 69 |
for (int k = 0; k < forceOnUi.length; k++) { |
| 70 |
Button button = new Button(this); |
| 71 |
button.setWidth(300); |
| 72 |
button.setHeight(300); |
| 73 |
button.setLayerType(layerTypes[j], null); |
| 74 |
button.setBackgroundResource(icon[i]); |
| 75 |
AnimatedVectorDrawable d = (AnimatedVectorDrawable) button.getBackground(); |
| 76 |
if (forceOnUi[k] == true) { |
| 77 |
d.forceAnimationOnUI(); |
| 78 |
} |
| 79 |
d.registerAnimationCallback(new Animatable2.AnimationCallback() { |
| 80 |
@Override |
| 81 |
public void onAnimationStart(Drawable drawable) { |
| 82 |
Log.v(LOGCAT, "Animator start"); |
| 83 |
} |
| 84 |
|
| 85 |
@Override |
| 86 |
public void onAnimationEnd(Drawable drawable) { |
| 87 |
Log.v(LOGCAT, "Animator end"); |
| 88 |
} |
| 89 |
}); |
| 90 |
|
| 91 |
container.addView(button); |
| 92 |
button.setOnClickListener(this); |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
setContentView(scrollView); |
| 98 |
} |
| 99 |
|
| 100 |
@Override |
| 101 |
public void onClick(View v) { |
| 102 |
AnimatedVectorDrawable d = (AnimatedVectorDrawable) v.getBackground(); |
| 103 |
d.start(); |
| 104 |
} |
| 105 |
} |