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.VectorDrawable; 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 VectorDrawablePerformance extends Activity { 29 private static final String LOGCAT = "VectorDrawable1"; 30 protected int[] icon = { 31 R.drawable.vector_drawable01, 32 R.drawable.vector_drawable02, 33 R.drawable.vector_drawable03, 34 R.drawable.vector_drawable04, 35 R.drawable.vector_drawable05, 36 R.drawable.vector_drawable06, 37 R.drawable.vector_drawable07, 38 R.drawable.vector_drawable08, 39 R.drawable.vector_drawable09, 40 R.drawable.vector_drawable10, 41 R.drawable.vector_drawable11, 42 R.drawable.vector_drawable12, 43 R.drawable.vector_drawable13, 44 R.drawable.vector_drawable14, 45 R.drawable.vector_drawable15, 46 R.drawable.vector_drawable16, 47 R.drawable.vector_drawable17, 48 R.drawable.vector_drawable18, 49 R.drawable.vector_drawable19, 50 R.drawable.vector_drawable20, 51 R.drawable.vector_drawable21, 52 R.drawable.vector_drawable22, 53 R.drawable.vector_drawable23, 54 R.drawable.vector_drawable24, 55 R.drawable.vector_drawable25, 56 R.drawable.vector_drawable26, 57 R.drawable.vector_drawable27, 58 R.drawable.vector_drawable28, 59 }; 60 61 @Override 62 protected void onCreate(Bundle savedInstanceState) { 63 super.onCreate(savedInstanceState); 64 ScrollView scrollView = new ScrollView(this); 65 GridLayout container = new GridLayout(this); 66 scrollView.addView(container); 67 container.setColumnCount(5); 68 Resources res = this.getResources(); 69 container.setBackgroundColor(0xFF888888); 70 VectorDrawable []d = new VectorDrawable[icon.length]; 71 long time = android.os.SystemClock.elapsedRealtimeNanos(); 72 for (int i = 0; i < icon.length; i++) { 73 d[i] = VectorDrawable.create(res,icon[i]); 74 } 75 time = android.os.SystemClock.elapsedRealtimeNanos()-time; 76 TextView t = new TextView(this); 77 DecimalFormat df = new DecimalFormat("#.##"); 78 t.setText("avgL=" + df.format(time / (icon.length * 1000000.)) + " ms"); 79 container.addView(t); 80 time = android.os.SystemClock.elapsedRealtimeNanos(); 81 for (int i = 0; i < icon.length; i++) { 82 Button button = new Button(this); 83 button.setWidth(200); 84 button.setBackgroundResource(icon[i]); 85 container.addView(button); 86 } 87 setContentView(scrollView); 88 time = android.os.SystemClock.elapsedRealtimeNanos()-time; 89 t = new TextView(this); 90 t.setText("avgS=" + df.format(time / (icon.length * 1000000.)) + " ms"); 91 container.addView(t); 92 } 93} 94