VectorDrawablePerformance.java revision 8d0d24f7a2b1a59060aa18926984491691d3c667
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 }; 57 58 @Override 59 protected void onCreate(Bundle savedInstanceState) { 60 super.onCreate(savedInstanceState); 61 ScrollView scrollView = new ScrollView(this); 62 GridLayout container = new GridLayout(this); 63 scrollView.addView(container); 64 container.setColumnCount(5); 65 Resources res = this.getResources(); 66 container.setBackgroundColor(0xFF888888); 67 VectorDrawable []d = new VectorDrawable[icon.length]; 68 long time = android.os.SystemClock.elapsedRealtimeNanos(); 69 for (int i = 0; i < icon.length; i++) { 70 d[i] = VectorDrawable.create(res,icon[i]); 71 } 72 time = android.os.SystemClock.elapsedRealtimeNanos()-time; 73 TextView t = new TextView(this); 74 DecimalFormat df = new DecimalFormat("#.##"); 75 t.setText("avgL=" + df.format(time / (icon.length * 1000000.)) + " ms"); 76 container.addView(t); 77 time = android.os.SystemClock.elapsedRealtimeNanos(); 78 for (int i = 0; i < icon.length; i++) { 79 Button button = new Button(this); 80 button.setWidth(200); 81 button.setBackgroundResource(icon[i]); 82 container.addView(button); 83 } 84 setContentView(scrollView); 85 time = android.os.SystemClock.elapsedRealtimeNanos()-time; 86 t = new TextView(this); 87 t.setText("avgS=" + df.format(time / (icon.length * 1000000.)) + " ms"); 88 container.addView(t); 89 } 90} 91