Search in sources :

Example 1 with VectorDrawable

use of android.graphics.drawable.VectorDrawable in project android_frameworks_base by ResurrectionRemix.

the class VectorDrawable01 method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GridLayout container = new GridLayout(this);
    container.setColumnCount(5);
    container.setBackgroundColor(0xFF888888);
    final Button[] bArray = new Button[icon.length];
    CheckBox toggle = new CheckBox(this);
    toggle.setText("Toggle");
    toggle.setChecked(true);
    toggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            ViewGroup vg = (ViewGroup) buttonView.getParent();
            for (int i = 0, count = vg.getChildCount(); i < count; i++) {
                View child = vg.getChildAt(i);
                if (child != buttonView) {
                    child.setEnabled(isChecked);
                }
            }
        }
    });
    container.addView(toggle);
    for (int i = 0; i < icon.length; i++) {
        Button button = new Button(this);
        bArray[i] = button;
        button.setWidth(200);
        button.setBackgroundResource(icon[i]);
        container.addView(button);
        VectorDrawable vd = (VectorDrawable) button.getBackground();
        vd.setAlpha((i + 1) * (0xFF / (icon.length + 1)));
    }
    setContentView(container);
}
Also used : GridLayout(android.widget.GridLayout) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) CompoundButton(android.widget.CompoundButton) Button(android.widget.Button) CheckBox(android.widget.CheckBox) ViewGroup(android.view.ViewGroup) View(android.view.View) CompoundButton(android.widget.CompoundButton) VectorDrawable(android.graphics.drawable.VectorDrawable)

Example 2 with VectorDrawable

use of android.graphics.drawable.VectorDrawable in project android_frameworks_base by ResurrectionRemix.

the class VectorDrawablePerformance method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ScrollView scrollView = new ScrollView(this);
    GridLayout container = new GridLayout(this);
    scrollView.addView(container);
    container.setColumnCount(4);
    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);
}
Also used : GridLayout(android.widget.GridLayout) ScrollView(android.widget.ScrollView) Button(android.widget.Button) DecimalFormat(java.text.DecimalFormat) TextView(android.widget.TextView) Resources(android.content.res.Resources) VectorDrawable(android.graphics.drawable.VectorDrawable)

Example 3 with VectorDrawable

use of android.graphics.drawable.VectorDrawable in project android_frameworks_base by ResurrectionRemix.

the class VectorDrawablePerformance method create.

public static VectorDrawable create(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;
}
Also used : AttributeSet(android.util.AttributeSet) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) VectorDrawable(android.graphics.drawable.VectorDrawable)

Example 4 with VectorDrawable

use of android.graphics.drawable.VectorDrawable in project android_frameworks_base by DirtyUnicorns.

the class VectorDrawable01 method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GridLayout container = new GridLayout(this);
    container.setColumnCount(5);
    container.setBackgroundColor(0xFF888888);
    final Button[] bArray = new Button[icon.length];
    CheckBox toggle = new CheckBox(this);
    toggle.setText("Toggle");
    toggle.setChecked(true);
    toggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            ViewGroup vg = (ViewGroup) buttonView.getParent();
            for (int i = 0, count = vg.getChildCount(); i < count; i++) {
                View child = vg.getChildAt(i);
                if (child != buttonView) {
                    child.setEnabled(isChecked);
                }
            }
        }
    });
    container.addView(toggle);
    for (int i = 0; i < icon.length; i++) {
        Button button = new Button(this);
        bArray[i] = button;
        button.setWidth(200);
        button.setBackgroundResource(icon[i]);
        container.addView(button);
        VectorDrawable vd = (VectorDrawable) button.getBackground();
        vd.setAlpha((i + 1) * (0xFF / (icon.length + 1)));
    }
    setContentView(container);
}
Also used : GridLayout(android.widget.GridLayout) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) CompoundButton(android.widget.CompoundButton) Button(android.widget.Button) CheckBox(android.widget.CheckBox) ViewGroup(android.view.ViewGroup) View(android.view.View) CompoundButton(android.widget.CompoundButton) VectorDrawable(android.graphics.drawable.VectorDrawable)

Example 5 with VectorDrawable

use of android.graphics.drawable.VectorDrawable in project android_frameworks_base by DirtyUnicorns.

the class VectorDrawablePerformance method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ScrollView scrollView = new ScrollView(this);
    GridLayout container = new GridLayout(this);
    scrollView.addView(container);
    container.setColumnCount(4);
    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);
}
Also used : GridLayout(android.widget.GridLayout) ScrollView(android.widget.ScrollView) Button(android.widget.Button) DecimalFormat(java.text.DecimalFormat) TextView(android.widget.TextView) Resources(android.content.res.Resources) VectorDrawable(android.graphics.drawable.VectorDrawable)

Aggregations

VectorDrawable (android.graphics.drawable.VectorDrawable)33 BitmapDrawable (android.graphics.drawable.BitmapDrawable)19 Bitmap (android.graphics.Bitmap)13 Canvas (android.graphics.Canvas)13 Paint (android.graphics.Paint)9 Button (android.widget.Button)8 GridLayout (android.widget.GridLayout)8 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)6 AnimationDrawable (android.graphics.drawable.AnimationDrawable)5 Resources (android.content.res.Resources)4 Rect (android.graphics.Rect)4 VectorDrawableCompat (android.support.graphics.drawable.VectorDrawableCompat)4 AttributeSet (android.util.AttributeSet)4 View (android.view.View)4 ViewGroup (android.view.ViewGroup)4 CheckBox (android.widget.CheckBox)4 CompoundButton (android.widget.CompoundButton)4 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)4 ScrollView (android.widget.ScrollView)4 TextView (android.widget.TextView)4