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 */
14package com.android.test.dynamic;
15
16import android.app.Activity;
17import android.content.res.Resources;
18import android.graphics.drawable.BitmapDrawable;
19import android.os.Bundle;
20import android.widget.TextView;
21import android.widget.Button;
22import android.widget.GridLayout;
23import android.widget.ScrollView;
24
25import java.text.DecimalFormat;
26
27@SuppressWarnings({"UnusedDeclaration"})
28public class BitmapDrawableDupe extends Activity {
29    private static final String LOGCAT = "VectorDrawable1";
30    protected int[] icon = {
31            R.drawable.bitmap_drawable01,
32            R.drawable.bitmap_drawable01,
33            R.drawable.bitmap_drawable01,
34            R.drawable.bitmap_drawable01,
35            R.drawable.bitmap_drawable01,
36            R.drawable.bitmap_drawable01,
37            R.drawable.bitmap_drawable01,
38            R.drawable.bitmap_drawable01,
39            R.drawable.bitmap_drawable01,
40            R.drawable.bitmap_drawable01,
41            R.drawable.bitmap_drawable01,
42            R.drawable.bitmap_drawable01,
43            R.drawable.bitmap_drawable01,
44            R.drawable.bitmap_drawable01,
45            R.drawable.bitmap_drawable01,
46            R.drawable.bitmap_drawable01,
47            R.drawable.bitmap_drawable01,
48            R.drawable.bitmap_drawable01,
49            R.drawable.bitmap_drawable01,
50            R.drawable.bitmap_drawable01,
51            R.drawable.bitmap_drawable01,
52    };
53
54    @Override
55    protected void onCreate(Bundle savedInstanceState) {
56        super.onCreate(savedInstanceState);
57        ScrollView scrollView = new ScrollView(this);
58        GridLayout container = new GridLayout(this);
59        scrollView.addView(container);
60        container.setColumnCount(5);
61        container.setBackgroundColor(0xFF888888);
62
63        DecimalFormat df = new DecimalFormat("#.##");
64        long time =  android.os.SystemClock.elapsedRealtimeNanos();
65        for (int i = 0; i < icon.length; i++) {
66            Button button = new Button(this);
67            button.setWidth(200);
68            button.setBackgroundResource(icon[i]);
69            container.addView(button);
70        }
71
72        setContentView(scrollView);
73        time =  android.os.SystemClock.elapsedRealtimeNanos()-time;
74        TextView t = new TextView(this);
75        t.setText("avgS=" + df.format(time / (icon.length * 1000000.)) + " ms");
76        container.addView(t);
77    }
78}
79