ztenghui | e5e9260 | 2014-06-03 14:02:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | * in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 11 | * or implied. See the License for the specific language governing permissions and limitations under |
| 12 | * the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.test.dynamic; |
| 16 | |
| 17 | import android.app.Activity; |
ztenghui | 83a5203 | 2015-05-29 17:19:41 -0700 | [diff] [blame] | 18 | import android.graphics.drawable.Animatable2; |
ztenghui | e5e9260 | 2014-06-03 14:02:10 -0700 | [diff] [blame] | 19 | import android.graphics.drawable.AnimatedVectorDrawable; |
ztenghui | 83a5203 | 2015-05-29 17:19:41 -0700 | [diff] [blame] | 20 | import android.graphics.drawable.Drawable; |
ztenghui | e5e9260 | 2014-06-03 14:02:10 -0700 | [diff] [blame] | 21 | import android.os.Bundle; |
ztenghui | 1588f0f | 2015-03-24 14:11:37 -0700 | [diff] [blame] | 22 | import android.util.Log; |
ztenghui | e5e9260 | 2014-06-03 14:02:10 -0700 | [diff] [blame] | 23 | import android.view.View; |
| 24 | import android.widget.Button; |
ztenghui | 1c1cda0 | 2014-06-26 12:22:58 -0700 | [diff] [blame] | 25 | import android.widget.GridLayout; |
| 26 | import android.widget.ScrollView; |
Teng-Hui Zhu | 9ac5a33 | 2016-03-31 09:48:37 -0700 | [diff] [blame] | 27 | import android.widget.TextView; |
ztenghui | e5e9260 | 2014-06-03 14:02:10 -0700 | [diff] [blame] | 28 | |
ztenghui | 5eb5cde | 2014-08-04 13:07:51 -0700 | [diff] [blame] | 29 | public class AnimatedVectorDrawableTest extends Activity implements View.OnClickListener { |
ztenghui | 1c1cda0 | 2014-06-26 12:22:58 -0700 | [diff] [blame] | 30 | private static final String LOGCAT = "AnimatedVectorDrawableTest"; |
| 31 | |
| 32 | protected int[] icon = { |
Teng-Hui Zhu | 5339428 | 2016-03-28 16:34:53 -0700 | [diff] [blame] | 33 | R.drawable.btn_radio_on_to_off_bundle, |
ztenghui | 6eafdfc | 2014-09-23 17:00:55 -0700 | [diff] [blame] | 34 | R.drawable.ic_rotate_2_portrait_v2_animation, |
| 35 | R.drawable.ic_signal_airplane_v2_animation, |
| 36 | R.drawable.ic_hourglass_animation, |
ztenghui | 5eb5cde | 2014-08-04 13:07:51 -0700 | [diff] [blame] | 37 | R.drawable.animation_vector_linear_progress_bar, |
ztenghui | 1c1cda0 | 2014-06-26 12:22:58 -0700 | [diff] [blame] | 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, |
ztenghui | 8490354 | 2014-09-11 14:34:20 -0700 | [diff] [blame] | 42 | // Duplicate to test constant state. |
| 43 | R.drawable.animation_vector_drawable01, |
ztenghui | 1c1cda0 | 2014-06-26 12:22:58 -0700 | [diff] [blame] | 44 | }; |
ztenghui | e5e9260 | 2014-06-03 14:02:10 -0700 | [diff] [blame] | 45 | |
| 46 | @Override |
| 47 | protected void onCreate(Bundle savedInstanceState) { |
Teng-Hui Zhu | 06a353d | 2016-03-28 14:37:54 -0700 | [diff] [blame] | 48 | final int[] layerTypes = {View.LAYER_TYPE_SOFTWARE, View.LAYER_TYPE_HARDWARE}; |
Teng-Hui Zhu | 9ac5a33 | 2016-03-31 09:48:37 -0700 | [diff] [blame] | 49 | final boolean[] forceOnUi = {false, true}; |
ztenghui | e5e9260 | 2014-06-03 14:02:10 -0700 | [diff] [blame] | 50 | super.onCreate(savedInstanceState); |
| 51 | |
ztenghui | 1c1cda0 | 2014-06-26 12:22:58 -0700 | [diff] [blame] | 52 | ScrollView scrollView = new ScrollView(this); |
| 53 | GridLayout container = new GridLayout(this); |
| 54 | scrollView.addView(container); |
Teng-Hui Zhu | 9ac5a33 | 2016-03-31 09:48:37 -0700 | [diff] [blame] | 55 | container.setColumnCount(layerTypes.length * forceOnUi.length); |
ztenghui | e5e9260 | 2014-06-03 14:02:10 -0700 | [diff] [blame] | 56 | |
Teng-Hui Zhu | 9ac5a33 | 2016-03-31 09:48:37 -0700 | [diff] [blame] | 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 | } |
ztenghui | 1c1cda0 | 2014-06-26 12:22:58 -0700 | [diff] [blame] | 67 | for (int i = 0; i < icon.length; i++) { |
Teng-Hui Zhu | 06a353d | 2016-03-28 14:37:54 -0700 | [diff] [blame] | 68 | for (int j = 0; j < layerTypes.length; j++) { |
Teng-Hui Zhu | 9ac5a33 | 2016-03-31 09:48:37 -0700 | [diff] [blame] | 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(); |
Teng-Hui Zhu | 06a353d | 2016-03-28 14:37:54 -0700 | [diff] [blame] | 78 | } |
Teng-Hui Zhu | 9ac5a33 | 2016-03-31 09:48:37 -0700 | [diff] [blame] | 79 | d.registerAnimationCallback(new Animatable2.AnimationCallback() { |
| 80 | @Override |
| 81 | public void onAnimationStart(Drawable drawable) { |
| 82 | Log.v(LOGCAT, "Animator start"); |
| 83 | } |
ztenghui | 83a5203 | 2015-05-29 17:19:41 -0700 | [diff] [blame] | 84 | |
Teng-Hui Zhu | 9ac5a33 | 2016-03-31 09:48:37 -0700 | [diff] [blame] | 85 | @Override |
| 86 | public void onAnimationEnd(Drawable drawable) { |
| 87 | Log.v(LOGCAT, "Animator end"); |
| 88 | } |
| 89 | }); |
ztenghui | 1588f0f | 2015-03-24 14:11:37 -0700 | [diff] [blame] | 90 | |
Teng-Hui Zhu | 9ac5a33 | 2016-03-31 09:48:37 -0700 | [diff] [blame] | 91 | container.addView(button); |
| 92 | button.setOnClickListener(this); |
| 93 | } |
Teng-Hui Zhu | 06a353d | 2016-03-28 14:37:54 -0700 | [diff] [blame] | 94 | } |
ztenghui | 1c1cda0 | 2014-06-26 12:22:58 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | setContentView(scrollView); |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public void onClick(View v) { |
| 102 | AnimatedVectorDrawable d = (AnimatedVectorDrawable) v.getBackground(); |
| 103 | d.start(); |
ztenghui | e5e9260 | 2014-06-03 14:02:10 -0700 | [diff] [blame] | 104 | } |
| 105 | } |