Example usage for android.widget ImageView getDrawable

List of usage examples for android.widget ImageView getDrawable

Introduction

In this page you can find the example usage for android.widget ImageView getDrawable.

Prototype

public Drawable getDrawable() 

Source Link

Document

Gets the current Drawable, or null if no Drawable has been assigned.

Usage

From source file:edu.purdue.safewalk.bitmaps.BitmapHelper.java

public static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
    if (imageView != null) {
        Drawable drawable = imageView.getDrawable();
        if (drawable instanceof AsyncDrawable) {
            AsyncDrawable downloadedDrawable = (AsyncDrawable) drawable;
            return downloadedDrawable.getBitmapWorkerTask();
        }/*from   w ww.  ja  va 2s  . co  m*/
    }
    return null;
}

From source file:com.zion.adapter.CachedImageCursorAdapter.java

private static CachedImageCursorAdapter.BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
    if (null != imageView) {
        final Drawable drawable = imageView.getDrawable();
        if (drawable instanceof CachedImageCursorAdapter.AsyncDrawable) {
            final CachedImageCursorAdapter.AsyncDrawable asyncDrawable = (CachedImageCursorAdapter.AsyncDrawable) drawable;
            return asyncDrawable.getBitmapWorkerTask();
        }/*from  w  ww  .  j  a  v a  2s  .  c  om*/
    }
    return null;
}

From source file:Main.java

public static void startFrameAnimation(ImageView targetImageView, int animationDrawableId) {
    if (targetImageView == null || animationDrawableId <= 0) {
        return;//w w  w  . j ava  2s .c om
    }
    targetImageView.setImageResource(animationDrawableId);
    AnimationDrawable animationDrawable = (AnimationDrawable) targetImageView.getDrawable();
    animationDrawable.start();
}

From source file:Main.java

public static void traverseAndRecolor(View root, int color, boolean withStates,
        boolean setClickableItemBackgrounds) {
    Context context = root.getContext();

    if (setClickableItemBackgrounds && root.isClickable()) {
        StateListDrawable selectableItemBackground = new StateListDrawable();
        selectableItemBackground.addState(new int[] { android.R.attr.state_pressed },
                new ColorDrawable((color & 0xffffff) | 0x33000000));
        selectableItemBackground.addState(new int[] { android.R.attr.state_focused },
                new ColorDrawable((color & 0xffffff) | 0x44000000));
        selectableItemBackground.addState(new int[] {}, null);
        root.setBackground(selectableItemBackground);
    }//ww w.  j a  v  a2 s. c o m

    if (root instanceof ViewGroup) {
        ViewGroup parent = (ViewGroup) root;
        for (int i = 0; i < parent.getChildCount(); i++) {
            traverseAndRecolor(parent.getChildAt(i), color, withStates, setClickableItemBackgrounds);
        }

    } else if (root instanceof ImageView) {
        ImageView imageView = (ImageView) root;
        Drawable sourceDrawable = imageView.getDrawable();
        if (withStates && sourceDrawable != null && sourceDrawable instanceof BitmapDrawable) {
            imageView.setImageDrawable(
                    makeRecoloredDrawable(context, (BitmapDrawable) sourceDrawable, color, true));
        } else {
            imageView.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        }

    } else if (root instanceof TextView) {
        TextView textView = (TextView) root;
        if (withStates) {
            int sourceColor = textView.getCurrentTextColor();
            ColorStateList colorStateList = new ColorStateList(
                    new int[][] { new int[] { android.R.attr.state_pressed },
                            new int[] { android.R.attr.state_focused }, new int[] {} },
                    new int[] { sourceColor, sourceColor, color });
            textView.setTextColor(colorStateList);
        } else {
            textView.setTextColor(color);
        }

    } else if (root instanceof AnalogClock) {
        AnalogClock analogClock = (AnalogClock) root;
        try {
            Field hourHandField = AnalogClock.class.getDeclaredField("mHourHand");
            hourHandField.setAccessible(true);
            Field minuteHandField = AnalogClock.class.getDeclaredField("mMinuteHand");
            minuteHandField.setAccessible(true);
            Field dialField = AnalogClock.class.getDeclaredField("mDial");
            dialField.setAccessible(true);
            BitmapDrawable hourHand = (BitmapDrawable) hourHandField.get(analogClock);
            if (hourHand != null) {
                Drawable d = makeRecoloredDrawable(context, hourHand, color, withStates);
                d.setCallback(analogClock);
                hourHandField.set(analogClock, d);
            }
            BitmapDrawable minuteHand = (BitmapDrawable) minuteHandField.get(analogClock);
            if (minuteHand != null) {
                Drawable d = makeRecoloredDrawable(context, minuteHand, color, withStates);
                d.setCallback(analogClock);
                minuteHandField.set(analogClock, d);
            }
            BitmapDrawable dial = (BitmapDrawable) dialField.get(analogClock);
            if (dial != null) {
                Drawable d = makeRecoloredDrawable(context, dial, color, withStates);
                d.setCallback(analogClock);
                dialField.set(analogClock, d);
            }
        } catch (NoSuchFieldException ignored) {
        } catch (IllegalAccessException ignored) {
        } catch (ClassCastException ignored) {
        } // TODO: catch all exceptions?
    }
}

From source file:com.blogspot.codigogoogle.listloadingsamples.ImageLoaderListAdapter.java

private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
    if (imageView != null) {
        final Drawable drawable = imageView.getDrawable();
        if (drawable instanceof AsyncDrawable) {
            final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
            return asyncDrawable.getBitmapWorkerTask();
        }/*  w ww . j av  a  2  s  . c om*/
    }
    return null;
}

From source file:jahirfiquitiva.iconshowcase.utilities.color.ToolbarColorizer.java

private static void tintImageView(Object target, Field field, int tintColor) throws Exception {
    field.setAccessible(true);//from  w  w  w .  j  av a 2 s.c o m
    final ImageView imageView = (ImageView) field.get(target);
    if (imageView == null)
        return;
    if (imageView.getDrawable() != null)
        imageView.setImageDrawable(ColorUtils.getTintedIcon(imageView.getDrawable(), tintColor));
}

From source file:com.android.clear.reminder.AnimatorUtils.java

public static void startDrawableAnimation(ImageView view) {
    final Drawable d = view.getDrawable();
    if (d instanceof Animatable) {
        ((Animatable) d).start();//from ww  w  . ja va 2s .  c o m
    }
}

From source file:Main.java

public static void unbindImageView(ImageView imageView) {
    if (imageView == null) {
        return;//from w w  w .  ja va2s .  co m
    }

    if (imageView.getBackground() != null) {
        imageView.getBackground().setCallback(null);
    }

    if (imageView.getDrawable() == null)
        return;
    if (!(imageView.getDrawable() instanceof BitmapDrawable))
        return;
    if (((BitmapDrawable) imageView.getDrawable()).getBitmap() == null)
        return;

    BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
    try {
        if (drawable != null && imageView.getTag() != null && !drawable.getBitmap().isRecycled()) {
            if (!imageView.getTag().toString().equalsIgnoreCase("resource") && !usingMemoryCache) {
                drawable.getBitmap().recycle();
            }
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
    }
    drawable.setCallback(null);
    imageView.setImageBitmap(null);
    imageView.setImageDrawable(null);
}

From source file:com.witheyjr.listviewanimator.StableWrapperArrayAdapter.java

private static ImageLoaderTask getImageLoaderTask(ImageView imageView) {
    if (imageView != null) {
        Drawable drawable = imageView.getDrawable();
        if (drawable instanceof LoadedDrawable) {
            LoadedDrawable downloadedDrawable = (LoadedDrawable) drawable;
            return downloadedDrawable.getImageLoaderTask();
        }/*  w  ww  .  j  av a  2s . c  o  m*/
    }
    return null;
}

From source file:com.philliphsu.bottomsheetpickers.Utils.java

public static void applyTint(ImageView view, @ColorInt int color) {
    Drawable drawable = view.getDrawable();
    setTint(drawable, color);//from w w w .j  av a  2  s .  c  o m
    view.setImageDrawable(drawable);
}