Search in sources :

Example 6 with AnimationDrawable

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

the class ProgressBar method tileifyIndeterminate.

/**
     * Convert a AnimationDrawable for use as a barberpole animation.
     * Each frame of the animation is wrapped in a ClipDrawable and
     * given a tiling BitmapShader.
     */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());
        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
Also used : AnimationDrawable(android.graphics.drawable.AnimationDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 7 with AnimationDrawable

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

the class PointerIcon method loadResource.

private void loadResource(Context context, Resources resources, @XmlRes int resourceId) {
    final XmlResourceParser parser = resources.getXml(resourceId);
    final int bitmapRes;
    final float hotSpotX;
    final float hotSpotY;
    try {
        XmlUtils.beginDocument(parser, "pointer-icon");
        final TypedArray a = resources.obtainAttributes(parser, com.android.internal.R.styleable.PointerIcon);
        bitmapRes = a.getResourceId(com.android.internal.R.styleable.PointerIcon_bitmap, 0);
        hotSpotX = a.getDimension(com.android.internal.R.styleable.PointerIcon_hotSpotX, 0);
        hotSpotY = a.getDimension(com.android.internal.R.styleable.PointerIcon_hotSpotY, 0);
        a.recycle();
    } catch (Exception ex) {
        throw new IllegalArgumentException("Exception parsing pointer icon resource.", ex);
    } finally {
        parser.close();
    }
    if (bitmapRes == 0) {
        throw new IllegalArgumentException("<pointer-icon> is missing bitmap attribute.");
    }
    Drawable drawable;
    if (context == null) {
        drawable = resources.getDrawable(bitmapRes);
    } else {
        drawable = context.getDrawable(bitmapRes);
    }
    if (drawable instanceof AnimationDrawable) {
        // Extract animation frame bitmaps.
        final AnimationDrawable animationDrawable = (AnimationDrawable) drawable;
        final int frames = animationDrawable.getNumberOfFrames();
        drawable = animationDrawable.getFrame(0);
        if (frames == 1) {
            Log.w(TAG, "Animation icon with single frame -- simply treating the first " + "frame as a normal bitmap icon.");
        } else {
            // Assumes they have the exact duration.
            mDurationPerFrame = animationDrawable.getDuration(0);
            mBitmapFrames = new Bitmap[frames - 1];
            final int width = drawable.getIntrinsicWidth();
            final int height = drawable.getIntrinsicHeight();
            for (int i = 1; i < frames; ++i) {
                Drawable drawableFrame = animationDrawable.getFrame(i);
                if (!(drawableFrame instanceof BitmapDrawable)) {
                    throw new IllegalArgumentException("Frame of an animated pointer icon " + "must refer to a bitmap drawable.");
                }
                if (drawableFrame.getIntrinsicWidth() != width || drawableFrame.getIntrinsicHeight() != height) {
                    throw new IllegalArgumentException("The bitmap size of " + i + "-th frame " + "is different. All frames should have the exact same size and " + "share the same hotspot.");
                }
                mBitmapFrames[i - 1] = ((BitmapDrawable) drawableFrame).getBitmap();
            }
        }
    }
    if (!(drawable instanceof BitmapDrawable)) {
        throw new IllegalArgumentException("<pointer-icon> bitmap attribute must " + "refer to a bitmap drawable.");
    }
    // Set the properties now that we have successfully loaded the icon.
    mBitmap = ((BitmapDrawable) drawable).getBitmap();
    mHotSpotX = hotSpotX;
    mHotSpotY = hotSpotY;
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) AnimationDrawable(android.graphics.drawable.AnimationDrawable) TypedArray(android.content.res.TypedArray) BitmapDrawable(android.graphics.drawable.BitmapDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 8 with AnimationDrawable

use of android.graphics.drawable.AnimationDrawable in project android_frameworks_base by ParanoidAndroid.

the class ProgressBar method tileifyIndeterminate.

/**
     * Convert a AnimationDrawable for use as a barberpole animation.
     * Each frame of the animation is wrapped in a ClipDrawable and
     * given a tiling BitmapShader.
     */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());
        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
Also used : AnimationDrawable(android.graphics.drawable.AnimationDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 9 with AnimationDrawable

use of android.graphics.drawable.AnimationDrawable in project ADWLauncher2 by boombuler.

the class WidgetCellLayout method stopAllAnimationDrawables.

private void stopAllAnimationDrawables(ViewGroup vg) {
    View child;
    for (int i = vg.getChildCount() - 1; i >= 0; i--) {
        child = vg.getChildAt(i);
        if (child instanceof ImageView) {
            try {
                AnimationDrawable ad = (AnimationDrawable) ((ImageView) child).getDrawable();
                ad.stop();
            } catch (Exception e) {
            }
        } else if (child instanceof ViewGroup) {
            stopAllAnimationDrawables((ViewGroup) child);
        }
    }
}
Also used : AnimationDrawable(android.graphics.drawable.AnimationDrawable) ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) AppWidgetHostView(android.appwidget.AppWidgetHostView) ImageView(android.widget.ImageView) View(android.view.View)

Example 10 with AnimationDrawable

use of android.graphics.drawable.AnimationDrawable in project android-UniversalMusicPlayer by googlesamples.

the class MediaItemViewHolder method getDrawableByState.

public static Drawable getDrawableByState(Context context, int state) {
    if (sColorStateNotPlaying == null || sColorStatePlaying == null) {
        initializeColorStateLists(context);
    }
    switch(state) {
        case STATE_PLAYABLE:
            Drawable pauseDrawable = ContextCompat.getDrawable(context, R.drawable.ic_play_arrow_black_36dp);
            DrawableCompat.setTintList(pauseDrawable, sColorStateNotPlaying);
            return pauseDrawable;
        case STATE_PLAYING:
            AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(context, R.drawable.ic_equalizer_white_36dp);
            DrawableCompat.setTintList(animation, sColorStatePlaying);
            animation.start();
            return animation;
        case STATE_PAUSED:
            Drawable playDrawable = ContextCompat.getDrawable(context, R.drawable.ic_equalizer1_white_36dp);
            DrawableCompat.setTintList(playDrawable, sColorStatePlaying);
            return playDrawable;
        default:
            return null;
    }
}
Also used : AnimationDrawable(android.graphics.drawable.AnimationDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable)

Aggregations

AnimationDrawable (android.graphics.drawable.AnimationDrawable)70 BitmapDrawable (android.graphics.drawable.BitmapDrawable)32 Drawable (android.graphics.drawable.Drawable)31 ClipDrawable (android.graphics.drawable.ClipDrawable)19 LayerDrawable (android.graphics.drawable.LayerDrawable)19 ShapeDrawable (android.graphics.drawable.ShapeDrawable)14 View (android.view.View)11 StateListDrawable (android.graphics.drawable.StateListDrawable)9 ImageView (android.widget.ImageView)9 SuppressLint (android.annotation.SuppressLint)5 TypedArray (android.content.res.TypedArray)5 XmlResourceParser (android.content.res.XmlResourceParser)5 VectorDrawable (android.graphics.drawable.VectorDrawable)5 Button (android.widget.Button)5 TextView (android.widget.TextView)5 Intent (android.content.Intent)3 Paint (android.graphics.Paint)3 RecyclerView (android.support.v7.widget.RecyclerView)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 DividerItemDecoration (com.jakewharton.u2020.ui.misc.DividerItemDecoration)2