AnimatedVectorDrawableTest.java revision 86ec6088b5965919d156d50ed55b84a5043e3e56
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
15package com.android.test.dynamic;
16
17import android.app.Activity;
18import android.graphics.drawable.AnimatedVectorDrawable;
19import android.os.Bundle;
20import android.view.View;
21import android.widget.Button;
22import android.widget.GridLayout;
23import android.widget.ScrollView;
24
25public class AnimatedVectorDrawableTest extends Activity implements View.OnClickListener {
26    private static final String LOGCAT = "AnimatedVectorDrawableTest";
27
28    protected int[] icon = {
29            R.drawable.ic_rotate_2_portrait_v2_animation,
30            R.drawable.ic_signal_airplane_v2_animation,
31            R.drawable.ic_hourglass_animation,
32            R.drawable.ic_cast_v2_animation,
33            R.drawable.ic_bluethooth_v2_animation,
34            R.drawable.animation_vector_linear_progress_bar,
35            R.drawable.animation_vector_drawable_grouping_1,
36            R.drawable.animation_vector_progress_bar,
37            R.drawable.animation_vector_drawable_favorite,
38            R.drawable.animation_vector_drawable01,
39            // Duplicate to test constant state.
40            R.drawable.animation_vector_drawable01,
41    };
42
43    @Override
44    protected void onCreate(Bundle savedInstanceState) {
45        super.onCreate(savedInstanceState);
46
47        ScrollView scrollView = new ScrollView(this);
48        GridLayout container = new GridLayout(this);
49        scrollView.addView(container);
50        container.setColumnCount(1);
51
52        for (int i = 0; i < icon.length; i++) {
53            Button button = new Button(this);
54            button.setWidth(400);
55            button.setHeight(400);
56            button.setBackgroundResource(icon[i]);
57            container.addView(button);
58            button.setOnClickListener(this);
59        }
60
61        setContentView(scrollView);
62    }
63
64    @Override
65    public void onClick(View v) {
66        AnimatedVectorDrawable d = (AnimatedVectorDrawable) v.getBackground();
67        d.start();
68    }
69}
70