FileDocCategorySizeDatePackage
VectorDrawablePerformance.javaAPI DocAndroid 5.1 API4954Thu Mar 12 22:22:44 GMT 2015com.android.test.dynamic

VectorDrawablePerformance

public class VectorDrawablePerformance extends android.app.Activity

Fields Summary
private static final String
LOGCAT
protected int[]
icon
Constructors Summary
Methods Summary
public static android.graphics.drawable.VectorDrawablecreate(android.content.res.Resources resources, int rid)


           
        try {
            final XmlPullParser parser = resources.getXml(rid);
            final AttributeSet attrs = Xml.asAttributeSet(parser);
            int type;
            while ((type=parser.next()) != XmlPullParser.START_TAG &&
                    type != XmlPullParser.END_DOCUMENT) {
                // Empty loop
            }
            if (type != XmlPullParser.START_TAG) {
                throw new XmlPullParserException("No start tag found");
            }

            final VectorDrawable drawable = new VectorDrawable();
            drawable.inflate(resources, parser, attrs);

            return drawable;
        } catch (XmlPullParserException e) {
            Log.e(LOGCAT, "parser error", e);
        } catch (IOException e) {
            Log.e(LOGCAT, "parser error", e);
        }
        return null;
    
protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);
        ScrollView scrollView = new ScrollView(this);
        GridLayout container = new GridLayout(this);
        scrollView.addView(container);
        container.setColumnCount(5);
        Resources res = this.getResources();
        container.setBackgroundColor(0xFF888888);
        VectorDrawable []d = new VectorDrawable[icon.length];
        long time =  android.os.SystemClock.elapsedRealtimeNanos();
        for (int i = 0; i < icon.length; i++) {
             d[i] = create(res,icon[i]);
        }
        time =  android.os.SystemClock.elapsedRealtimeNanos()-time;
        TextView t = new TextView(this);
        DecimalFormat df = new DecimalFormat("#.##");
        t.setText("avgL=" + df.format(time / (icon.length * 1000000.)) + " ms");
        container.addView(t);
        time =  android.os.SystemClock.elapsedRealtimeNanos();
        for (int i = 0; i < icon.length; i++) {
            Button button = new Button(this);
            button.setWidth(200);
            button.setBackgroundResource(icon[i]);
            container.addView(button);
        }
        setContentView(scrollView);
        time =  android.os.SystemClock.elapsedRealtimeNanos()-time;
        t = new TextView(this);
        t.setText("avgS=" + df.format(time / (icon.length * 1000000.)) + " ms");
        container.addView(t);