Example usage for android.widget ImageView getContext

List of usage examples for android.widget ImageView getContext

Introduction

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

Prototype

@ViewDebug.CapturedViewProperty
public final Context getContext() 

Source Link

Document

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Usage

From source file:uk.co.bubblebearapps.motionaiclient.view.customsetters.ImageViewSetters.java

@BindingAdapter("circleImageUrl")
public static void setCircularImageUrl(final ImageView imageView, String url) {
    if (Strings.isNullOrEmpty(url)) {
        imageView.setImageBitmap(null);//from   w ww . j  a v a 2s  . c o  m
    } else {
        Glide.with(imageView.getContext()).load(url).asBitmap().centerCrop()
                .into(new BitmapImageViewTarget(imageView) {
                    @Override
                    protected void setResource(Bitmap resource) {
                        RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory
                                .create(imageView.getResources(), resource);
                        roundedBitmapDrawable.setCircular(true);
                        imageView.setImageDrawable(roundedBitmapDrawable);
                    }
                });
    }
}

From source file:Main.java

public static void startVDAnimation(ImageView imageView, @DrawableRes int inactiveResId,
        @DrawableRes int activeResId, int duration) {
    int drawableResId = imageView.isSelected() ? activeResId : inactiveResId;
    Drawable drawable = ContextCompat.getDrawable(imageView.getContext(), drawableResId);
    imageView.setImageDrawable(drawable);

    if (drawable instanceof Animatable) {
        Animatable animatable = (Animatable) drawable;
        if (animatable.isRunning()) {
            animatable.stop();//  ww w  . j a  v a 2s  .c  o  m
        }

        animatable.start();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            imageView.setSelected(!imageView.isSelected());
        } else {
            imageView.postDelayed(() -> {
                imageView.setSelected(!imageView.isSelected());
                int nextDrawableResId = imageView.isSelected() ? activeResId : inactiveResId;
                Drawable nextDrawable = ContextCompat.getDrawable(imageView.getContext(), nextDrawableResId);
                imageView.setImageDrawable(nextDrawable);
            }, duration);
        }
    }
}

From source file:uk.co.bubblebearapps.motionaiclient.view.customsetters.ImageViewSetters.java

@BindingAdapter(value = { "imageUrl", "cornerRadius" }, requireAll = false)
public static void setImageUrl(final ImageView imageView, String url, final float cornerRadius) {

    if (Strings.isNullOrEmpty(url)) {
        imageView.setImageBitmap(null);/*from www .  j  ava2 s.  c  o  m*/
    } else if (url.endsWith("gif")) {
        Glide.with(imageView.getContext()).load(url).diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .into(imageView);

    } else {
        if (cornerRadius > 0) {
            Glide.with(imageView.getContext()).load(url).asBitmap().into(new BitmapImageViewTarget(imageView) {
                @Override
                protected void setResource(Bitmap resource) {
                    RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory
                            .create(imageView.getContext().getResources(), resource);
                    circularBitmapDrawable.setCornerRadius(cornerRadius);
                    imageView.setImageDrawable(circularBitmapDrawable);
                }
            });

        } else {

            Glide.with(imageView.getContext()).load(url).into(imageView);
        }
    }
}

From source file:com.doctoror.fuckoffmusicplayer.presentation.util.BindingAdapters.java

@BindingAdapter({ "srcRes", "tintAttr" })
public static void setSrcResTintedFromAttr(@NonNull final ImageView imageView, @DrawableRes final int res,
        @AttrRes final int tintAttr) {
    Drawable src = ContextCompat.getDrawable(imageView.getContext(), res);
    setSrcTintedFromAttr(imageView, src, tintAttr);
}

From source file:Main.java

public static boolean setAssetImage(ImageView imageView, String path, String filename) {
    if (filename == null || "".equals(filename) || "NULL".equalsIgnoreCase(filename)) {
        return false;
    }/*from ww  w  .ja va 2s  .co  m*/
    String _path = (path == null) ? "" : path;

    InputStream is = null;
    try {
        is = imageView.getContext().getAssets().open(_path + filename);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    Bitmap bitmap = BitmapFactory.decodeStream(is);
    imageView.setImageBitmap(bitmap);

    return true;
}

From source file:com.ruesga.rview.misc.BindingAdapters.java

@BindingAdapter("bindResourceDrawable")
public static void bindResourceDrawable(ImageView v, Integer resource) {
    if (resource == null || resource == 0) {
        v.setImageDrawable(null);/*from   w w  w.  j  av  a  2  s  .co m*/
    } else {
        v.setImageDrawable(ContextCompat.getDrawable(v.getContext(), resource));
    }
}

From source file:com.doctoror.fuckoffmusicplayer.presentation.util.BindingAdapters.java

@BindingAdapter({ "src", "tintAttr" })
public static void setSrcTintedFromAttr(@NonNull final ImageView imageView, @Nullable Drawable src,
        @AttrRes final int tintAttr) {
    if (src != null) {
        src = DrawableUtils.getTintedDrawableFromAttrTint(imageView.getContext(), src, tintAttr);
    }//  www  . jav  a 2  s  .com
    imageView.setImageDrawable(src);
}

From source file:com.drextended.rvdbsample.util.Converters.java

@BindingAdapter(value = { "glidePath", "glidePlaceholder", "glideSignature", "glideCacheStrategy",
        "glideCrossFadeDisabled", "glideAnimation", "glideTransform" }, requireAll = false)
public static void setImageUri(ImageView imageView, String path, Drawable placeholder, String glideSignature,
        String glideCacheStrategy, boolean crossFadeDisabled, Integer animationResId, String glideTransform) {
    Context context = imageView.getContext();

    if (context instanceof Activity && ((Activity) context).isFinishing())
        return;//ww w .  j ava2s .co m
    if (context instanceof ContextWrapper) {
        final Context baseContext = ((ContextWrapper) context).getBaseContext();
        if (baseContext instanceof Activity && ((Activity) baseContext).isFinishing())
            return;
    }
    boolean isEmptyPath = TextUtils.isEmpty(path);
    if (isEmptyPath) {
        if (placeholder != null) {
            imageView.setImageDrawable(placeholder);
        }
        return;
    }
    try {
        RequestManager glide = Glide.with(context);
        DrawableRequestBuilder request = glide.load(path);

        if (placeholder != null) {
            if (!crossFadeDisabled && animationResId == null)
                request.crossFade();
            request.placeholder(placeholder);
        }
        if (animationResId != null) {
            request.animate(animationResId);
        }
        if (!TextUtils.isEmpty(glideSignature)) {
            request.signature(new StringSignature(glideSignature));
        }
        if (glideTransform != null) {
            switch (glideTransform) {
            case "CIRCLE":
                request.bitmapTransform(
                        new CircleBorderedTransform(Glide.get(context).getBitmapPool(), Color.WHITE));
                break;
            case "BLUR":
                break;
            }
        }

        if (!TextUtils.isEmpty(glideCacheStrategy)) {
            request.diskCacheStrategy(DiskCacheStrategy.valueOf(glideCacheStrategy));
        }

        request.into(imageView);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    }
}

From source file:cn.bingoogolapple.scaffolding.util.DrawableUtil.java

public static void tintPressedIndicator(ImageView imageView, @DrawableRes int normalResId,
        @DrawableRes int pressedResId, @ColorRes int colorResId) {
    Drawable normal = imageView.getResources().getDrawable(normalResId);
    Drawable pressed = imageView.getResources().getDrawable(pressedResId);
    pressed = tintDrawable(imageView.getContext(), pressed, colorResId);
    imageView.setImageDrawable(getPressedSelectorDrawable(normal, pressed));
}

From source file:com.fast.access.kam.widget.colorpicker.dashclockpicker.ColorPickerDialogDash.java

private static void setColorViewValue(View view, int color) {
    if (view instanceof ImageView) {
        ImageView imageView = (ImageView) view;
        Resources res = imageView.getContext().getResources();

        Drawable currentDrawable = imageView.getDrawable();
        GradientDrawable colorChoiceDrawable;
        if (currentDrawable != null && currentDrawable instanceof GradientDrawable) {
            // Reuse drawable
            colorChoiceDrawable = (GradientDrawable) currentDrawable;
        } else {/*www. j  av a 2 s.  c  om*/
            colorChoiceDrawable = new GradientDrawable();
            colorChoiceDrawable.setShape(GradientDrawable.OVAL);
        }

        // Set stroke to dark version of color
        int darkenedColor = Color.rgb(Color.red(color) * 192 / 256, Color.green(color) * 192 / 256,
                Color.blue(color) * 192 / 256);

        colorChoiceDrawable.setColor(color);
        colorChoiceDrawable.setStroke(
                (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, res.getDisplayMetrics()),
                darkenedColor);
        imageView.setImageDrawable(colorChoiceDrawable);

    } else if (view instanceof TextView) {
        ((TextView) view).setTextColor(color);
    }
}