Search in sources :

Example 26 with AnimatedVectorDrawable

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

the class AnimatedVectorDrawableDupPerf method create.

/** @hide */
public static AnimatedVectorDrawable 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 AnimatedVectorDrawable drawable = new AnimatedVectorDrawable();
        drawable.inflate(resources, parser, attrs);
        return drawable;
    } catch (XmlPullParserException e) {
        Log.e(LOGTAG, "parser error", e);
    } catch (IOException e) {
        Log.e(LOGTAG, "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) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Example 27 with AnimatedVectorDrawable

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

the class AnimatedVectorDrawableTest method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    final int[] layerTypes = { View.LAYER_TYPE_SOFTWARE, View.LAYER_TYPE_HARDWARE };
    final boolean[] forceOnUi = { false, true };
    super.onCreate(savedInstanceState);
    ScrollView scrollView = new ScrollView(this);
    GridLayout container = new GridLayout(this);
    scrollView.addView(container);
    container.setColumnCount(layerTypes.length * forceOnUi.length);
    for (int j = 0; j < layerTypes.length; j++) {
        for (int k = 0; k < forceOnUi.length; k++) {
            TextView textView = new TextView(this);
            String category = "Layer:" + (layerTypes[j] == View.LAYER_TYPE_SOFTWARE ? "SW" : "HW") + (forceOnUi[k] == true ? ",forceUI" : "");
            textView.setText(category);
            container.addView(textView);
        }
    }
    for (int i = 0; i < icon.length; i++) {
        for (int j = 0; j < layerTypes.length; j++) {
            for (int k = 0; k < forceOnUi.length; k++) {
                Button button = new Button(this);
                button.setWidth(300);
                button.setHeight(300);
                button.setLayerType(layerTypes[j], null);
                button.setBackgroundResource(icon[i]);
                AnimatedVectorDrawable d = (AnimatedVectorDrawable) button.getBackground();
                if (forceOnUi[k] == true) {
                    d.forceAnimationOnUI();
                }
                d.registerAnimationCallback(new Animatable2.AnimationCallback() {

                    @Override
                    public void onAnimationStart(Drawable drawable) {
                        Log.v(LOGCAT, "Animator start");
                    }

                    @Override
                    public void onAnimationEnd(Drawable drawable) {
                        Log.v(LOGCAT, "Animator end");
                    }
                });
                container.addView(button);
                button.setOnClickListener(this);
            }
        }
    }
    setContentView(scrollView);
}
Also used : AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Drawable(android.graphics.drawable.Drawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Animatable2(android.graphics.drawable.Animatable2) GridLayout(android.widget.GridLayout) ScrollView(android.widget.ScrollView) Button(android.widget.Button) TextView(android.widget.TextView)

Example 28 with AnimatedVectorDrawable

use of android.graphics.drawable.AnimatedVectorDrawable in project android_frameworks_base by crdroidandroid.

the class ExpandableIndicator method setExpanded.

public void setExpanded(boolean expanded) {
    if (expanded == mExpanded)
        return;
    mExpanded = expanded;
    final int res = getDrawableResourceId(!mExpanded);
    // workaround to reset drawable
    final AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getContext().getDrawable(res).getConstantState().newDrawable();
    setImageDrawable(avd);
    avd.forceAnimationOnUI();
    avd.start();
    setContentDescription(getContentDescription(expanded));
}
Also used : AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Example 29 with AnimatedVectorDrawable

use of android.graphics.drawable.AnimatedVectorDrawable in project android_frameworks_base by crdroidandroid.

the class AnimatedVectorDrawableAttr method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_animated_vector_drawable_attr);
    ImageView avdIv = (ImageView) findViewById(R.id.avd);
    AnimatedVectorDrawable avd = (AnimatedVectorDrawable) avdIv.getDrawable();
    avd.start();
}
Also used : ImageView(android.widget.ImageView) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Example 30 with AnimatedVectorDrawable

use of android.graphics.drawable.AnimatedVectorDrawable in project android_frameworks_base by crdroidandroid.

the class AnimatedVectorDrawableDupPerf 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(5);
    Resources res = this.getResources();
    container.setBackgroundColor(0xFF888888);
    AnimatedVectorDrawable[] d = new AnimatedVectorDrawable[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) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Aggregations

AnimatedVectorDrawable (android.graphics.drawable.AnimatedVectorDrawable)56 Drawable (android.graphics.drawable.Drawable)18 TextView (android.widget.TextView)9 Resources (android.content.res.Resources)8 Button (android.widget.Button)8 GridLayout (android.widget.GridLayout)8 ScrollView (android.widget.ScrollView)8 SuppressLint (android.annotation.SuppressLint)5 ColorDrawable (android.graphics.drawable.ColorDrawable)5 InsetDrawable (android.graphics.drawable.InsetDrawable)5 ImageView (android.widget.ImageView)5 Paint (android.graphics.Paint)4 Animatable2 (android.graphics.drawable.Animatable2)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4 LayerDrawable (android.graphics.drawable.LayerDrawable)4 AttributeSet (android.util.AttributeSet)4 IOException (java.io.IOException)4 DecimalFormat (java.text.DecimalFormat)4 XmlPullParser (org.xmlpull.v1.XmlPullParser)4 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)4