blob: 8f538aee78aa7481ad655f350c191d8943ed60da [file] [log] [blame]
ztenghuie5e92602014-06-03 14:02:10 -07001/*
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
15package com.android.test.dynamic;
16
17import android.app.Activity;
ztenghui83a52032015-05-29 17:19:41 -070018import android.graphics.drawable.Animatable2;
ztenghuie5e92602014-06-03 14:02:10 -070019import android.graphics.drawable.AnimatedVectorDrawable;
ztenghui83a52032015-05-29 17:19:41 -070020import android.graphics.drawable.Drawable;
ztenghuie5e92602014-06-03 14:02:10 -070021import android.os.Bundle;
ztenghui1588f0f2015-03-24 14:11:37 -070022import android.util.Log;
ztenghuie5e92602014-06-03 14:02:10 -070023import android.view.View;
24import android.widget.Button;
ztenghui1c1cda02014-06-26 12:22:58 -070025import android.widget.GridLayout;
26import android.widget.ScrollView;
Teng-Hui Zhu9ac5a332016-03-31 09:48:37 -070027import android.widget.TextView;
ztenghuie5e92602014-06-03 14:02:10 -070028
ztenghui5eb5cde2014-08-04 13:07:51 -070029public class AnimatedVectorDrawableTest extends Activity implements View.OnClickListener {
ztenghui1c1cda02014-06-26 12:22:58 -070030 private static final String LOGCAT = "AnimatedVectorDrawableTest";
31
32 protected int[] icon = {
Teng-Hui Zhu53394282016-03-28 16:34:53 -070033 R.drawable.btn_radio_on_to_off_bundle,
ztenghui6eafdfc2014-09-23 17:00:55 -070034 R.drawable.ic_rotate_2_portrait_v2_animation,
35 R.drawable.ic_signal_airplane_v2_animation,
36 R.drawable.ic_hourglass_animation,
ztenghui5eb5cde2014-08-04 13:07:51 -070037 R.drawable.animation_vector_linear_progress_bar,
ztenghui1c1cda02014-06-26 12:22:58 -070038 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,
ztenghui84903542014-09-11 14:34:20 -070042 // Duplicate to test constant state.
43 R.drawable.animation_vector_drawable01,
ztenghui1c1cda02014-06-26 12:22:58 -070044 };
ztenghuie5e92602014-06-03 14:02:10 -070045
46 @Override
47 protected void onCreate(Bundle savedInstanceState) {
Teng-Hui Zhu06a353d2016-03-28 14:37:54 -070048 final int[] layerTypes = {View.LAYER_TYPE_SOFTWARE, View.LAYER_TYPE_HARDWARE};
Teng-Hui Zhu9ac5a332016-03-31 09:48:37 -070049 final boolean[] forceOnUi = {false, true};
ztenghuie5e92602014-06-03 14:02:10 -070050 super.onCreate(savedInstanceState);
51
ztenghui1c1cda02014-06-26 12:22:58 -070052 ScrollView scrollView = new ScrollView(this);
53 GridLayout container = new GridLayout(this);
54 scrollView.addView(container);
Teng-Hui Zhu9ac5a332016-03-31 09:48:37 -070055 container.setColumnCount(layerTypes.length * forceOnUi.length);
ztenghuie5e92602014-06-03 14:02:10 -070056
Teng-Hui Zhu9ac5a332016-03-31 09:48:37 -070057 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 }
ztenghui1c1cda02014-06-26 12:22:58 -070067 for (int i = 0; i < icon.length; i++) {
Teng-Hui Zhu06a353d2016-03-28 14:37:54 -070068 for (int j = 0; j < layerTypes.length; j++) {
Teng-Hui Zhu9ac5a332016-03-31 09:48:37 -070069 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 Zhu06a353d2016-03-28 14:37:54 -070078 }
Teng-Hui Zhu9ac5a332016-03-31 09:48:37 -070079 d.registerAnimationCallback(new Animatable2.AnimationCallback() {
80 @Override
81 public void onAnimationStart(Drawable drawable) {
82 Log.v(LOGCAT, "Animator start");
83 }
ztenghui83a52032015-05-29 17:19:41 -070084
Teng-Hui Zhu9ac5a332016-03-31 09:48:37 -070085 @Override
86 public void onAnimationEnd(Drawable drawable) {
87 Log.v(LOGCAT, "Animator end");
88 }
89 });
ztenghui1588f0f2015-03-24 14:11:37 -070090
Teng-Hui Zhu9ac5a332016-03-31 09:48:37 -070091 container.addView(button);
92 button.setOnClickListener(this);
93 }
Teng-Hui Zhu06a353d2016-03-28 14:37:54 -070094 }
ztenghui1c1cda02014-06-26 12:22:58 -070095 }
96
97 setContentView(scrollView);
98 }
99
100 @Override
101 public void onClick(View v) {
102 AnimatedVectorDrawable d = (AnimatedVectorDrawable) v.getBackground();
103 d.start();
ztenghuie5e92602014-06-03 14:02:10 -0700104 }
105}