use of android.graphics.drawable.AnimationDrawable in project JamsMusicPlayer by psaravan.
the class PicassoDrawable method setBitmap.
/**
* Create or update the drawable on the target {@link ImageView} to display the supplied bitmap
* image.
*/
static void setBitmap(ImageView target, Context context, Bitmap bitmap, Picasso.LoadedFrom loadedFrom, boolean noFade, boolean debugging) {
Drawable placeholder = target.getDrawable();
if (placeholder instanceof AnimationDrawable) {
((AnimationDrawable) placeholder).stop();
}
PicassoDrawable drawable = new PicassoDrawable(context, bitmap, placeholder, loadedFrom, noFade, debugging);
target.setImageDrawable(drawable);
}
use of android.graphics.drawable.AnimationDrawable in project android_frameworks_base by crdroidandroid.
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;
}
use of android.graphics.drawable.AnimationDrawable in project android_frameworks_base by crdroidandroid.
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;
}
use of android.graphics.drawable.AnimationDrawable in project android_frameworks_base by crdroidandroid.
the class VectorDrawableAnimation method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Button button = new Button(this);
button.setBackgroundResource(R.drawable.animation_drawable_vector);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AnimationDrawable frameAnimation = (AnimationDrawable) v.getBackground();
// Start the animation (looped playback by default).
frameAnimation.start();
}
});
setContentView(button);
}
use of android.graphics.drawable.AnimationDrawable in project android_frameworks_base by AOSPA.
the class NotificationColorUtil method isGrayscaleIcon.
/**
* Checks whether a Drawable is a small grayscale icon.
* Grayscale here means "very close to a perfect gray"; icon means "no larger than 64dp".
*
* @param d The drawable to test.
* @return True if the bitmap is grayscale; false if it is color or too large to examine.
*/
public boolean isGrayscaleIcon(Drawable d) {
if (d == null) {
return false;
} else if (d instanceof BitmapDrawable) {
BitmapDrawable bd = (BitmapDrawable) d;
return bd.getBitmap() != null && isGrayscaleIcon(bd.getBitmap());
} else if (d instanceof AnimationDrawable) {
AnimationDrawable ad = (AnimationDrawable) d;
int count = ad.getNumberOfFrames();
return count > 0 && isGrayscaleIcon(ad.getFrame(0));
} else if (d instanceof VectorDrawable) {
// We just assume you're doing the right thing if using vectors
return true;
} else {
return false;
}
}
Aggregations