Search in sources :

Example 41 with AnimatedVectorDrawable

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

the class PageIndicator method playAnimation.

private void playAnimation(ImageView imageView, int res) {
    final AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getContext().getDrawable(res);
    imageView.setImageDrawable(avd);
    avd.forceAnimationOnUI();
    avd.start();
    // TODO: Figure out how to user an AVD animation callback instead, which doesn't
    // seem to be working right now...
    postDelayed(mAnimationDone, ANIMATION_DURATION);
}
Also used : AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Example 42 with AnimatedVectorDrawable

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

the class VolumeDialog method updateExpandButtonH.

private void updateExpandButtonH() {
    if (D.BUG)
        Log.d(TAG, "updateExpandButtonH");
    mExpandButton.setClickable(!mExpandButtonAnimationRunning);
    if (!(mExpandButtonAnimationRunning && isAttached())) {
        final int res = mExpanded ? R.drawable.ic_volume_collapse_animation : R.drawable.ic_volume_expand_animation;
        if (hasTouchFeature()) {
            mExpandButton.setImageResource(res);
        } else {
            // if there is no touch feature, show the volume ringer instead
            mExpandButton.setImageResource(R.drawable.ic_volume_ringer);
            // remove gray background emphasis
            mExpandButton.setBackgroundResource(0);
        }
        mExpandButton.setContentDescription(mContext.getString(mExpanded ? R.string.accessibility_volume_collapse : R.string.accessibility_volume_expand));
    }
    if (mExpandButtonAnimationRunning) {
        final Drawable d = mExpandButton.getDrawable();
        if (d instanceof AnimatedVectorDrawable) {
            // workaround to reset drawable
            final AnimatedVectorDrawable avd = (AnimatedVectorDrawable) d.getConstantState().newDrawable();
            mExpandButton.setImageDrawable(avd);
            avd.start();
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    mExpandButtonAnimationRunning = false;
                    updateExpandButtonH();
                    rescheduleTimeoutH();
                }
            }, mExpandButtonAnimationDuration);
        }
    }
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) SuppressLint(android.annotation.SuppressLint) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Example 43 with AnimatedVectorDrawable

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

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 44 with AnimatedVectorDrawable

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

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 45 with AnimatedVectorDrawable

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

the class BatteryMeterDrawable method checkBatteryMeterDrawableValid.

private void checkBatteryMeterDrawableValid(Resources res, int style) {
    final int resId = getBatteryDrawableResourceForStyle(style);
    final Drawable batteryDrawable;
    try {
        batteryDrawable = res.getDrawable(resId, null);
    } catch (Resources.NotFoundException e) {
        throw new BatteryMeterDrawableException(res.getResourceName(resId) + " is an " + "invalid drawable", e);
    }
    // Check that the drawable is a LayerDrawable
    if (!(batteryDrawable instanceof LayerDrawable)) {
        throw new BatteryMeterDrawableException("Expected a LayerDrawable but received a " + batteryDrawable.getClass().getSimpleName());
    }
    final LayerDrawable layerDrawable = (LayerDrawable) batteryDrawable;
    final Drawable frame = layerDrawable.findDrawableByLayerId(R.id.battery_frame);
    final Drawable level = layerDrawable.findDrawableByLayerId(R.id.battery_fill);
    final Drawable bolt = layerDrawable.findDrawableByLayerId(R.id.battery_charge_indicator);
    final Drawable plus = layerDrawable.findDrawableByLayerId(R.id.battery_powersave_indicator);
    // Now, check that the required layers exist and are of the correct type
    if (frame == null) {
        throw new BatteryMeterDrawableException("Missing battery_frame drawble");
    }
    if (bolt == null) {
        throw new BatteryMeterDrawableException("Missing battery_charge_indicator drawable");
    }
    if (plus == null) {
        throw new BatteryMeterDrawableException("Missing battery_powersave_indicator drawable");
    }
    if (level != null) {
        // Check that the level drawable is an AnimatedVectorDrawable
        if (!(level instanceof AnimatedVectorDrawable)) {
            throw new BatteryMeterDrawableException("Expected a AnimatedVectorDrawable " + "but received a " + level.getClass().getSimpleName());
        }
        // Make sure we can stop-motion animate the level drawable
        try {
            StopMotionVectorDrawable smvd = new StopMotionVectorDrawable(level);
            smvd.setCurrentFraction(0.5f);
        } catch (Exception e) {
            throw new BatteryMeterDrawableException("Unable to perform stop motion on " + "battery_fill drawable", e);
        }
    } else {
        throw new BatteryMeterDrawableException("Missing battery_fill drawable");
    }
}
Also used : StopMotionVectorDrawable(android.graphics.drawable.StopMotionVectorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) StopMotionVectorDrawable(android.graphics.drawable.StopMotionVectorDrawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Resources(android.content.res.Resources) Paint(android.graphics.Paint) 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