android.widget.ImageView#getResources ( )源码实例Demo

下面列出了android.widget.ImageView#getResources ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@SuppressWarnings("deprecation")
static boolean setResource(ImageView view, boolean isSrc, int resId) {
    Resources res = view.getResources();
    if (res != null) {
        try {
            GifDrawable d = new GifDrawable(res, resId);
            if (isSrc) {
                view.setImageDrawable(d);
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                view.setBackground(d);
            } else {
                view.setBackgroundDrawable(d);
            }
            return true;
        } catch (IOException | Resources.NotFoundException ignored) {
            //ignored
        }
    }
    return false;
}
 
private void setImage(ImageView imageView, Bitmap bitmap) {
    if (animate) {
        Resources resources = imageView.getResources();
        BitmapDrawable drawable = new BitmapDrawable(resources, bitmap);
        Drawable currentDrawable = imageView.getDrawable();
        if (currentDrawable != null) {
            Drawable[] arrayDrawable = new Drawable[2];
            arrayDrawable[0] = currentDrawable;
            arrayDrawable[1] = drawable;
            final TransitionDrawable transitionDrawable = new TransitionDrawable(arrayDrawable);
            transitionDrawable.setCrossFadeEnabled(true);
            imageView.setImageDrawable(transitionDrawable);
            transitionDrawable.startTransition(150);
        } else {
            imageView.setImageDrawable(drawable);
        }
    } else {
        imageView.setImageBitmap(bitmap);
    }
}
 
源代码3 项目: sketch   文件: GifViewUtils.java
@SuppressWarnings("deprecation")
static boolean setResource(ImageView view, boolean isSrc, int resId) {
	Resources res = view.getResources();
	if (res != null) {
		try {
			final String resourceTypeName = res.getResourceTypeName(resId);
			if (!SUPPORTED_RESOURCE_TYPE_NAMES.contains(resourceTypeName)) {
				return false;
			}
			GifDrawable d = new GifDrawable(res, resId);
			if (isSrc) {
				view.setImageDrawable(d);
			} else {
				view.setBackground(d);
			}
			return true;
		} catch (IOException | Resources.NotFoundException ignored) {
			//ignored
		}
	}
	return false;
}
 
源代码4 项目: mobile-manager-tool   文件: ImageProvider.java
private void setLoadedBitmap(ImageView imageView, Bitmap bitmap, String tag) {
    if (!tag.equals(imageView.getTag()))
        return;

    final TransitionDrawable transition = new TransitionDrawable(new Drawable[]{
            new ColorDrawable(android.R.color.transparent),
            new BitmapDrawable(imageView.getResources(), bitmap)
    });

    imageView.setImageDrawable(transition);
    final int duration = imageView.getResources().getInteger(R.integer.image_fade_in_duration);
    transition.startTransition(duration);
}
 
源代码5 项目: BaseProject   文件: ViewUtil.java
public static void imageViewRounded(ImageView iv, int imageResId, int roundedRadius) {
    Resources res = iv.getResources();
    RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(res, BitmapFactory.decodeResource(res, imageResId));
    roundedBitmapDrawable.setCornerRadius(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, roundedRadius, res.getDisplayMetrics()));
    iv.setImageDrawable(roundedBitmapDrawable);
}
 
源代码6 项目: box-android-browse-sdk   文件: LoaderDrawable.java
public static LoaderDrawable create(BoxRequestsFile.DownloadRepresentation request, final BoxItem boxItem, ImageView imageView, Bitmap placeHolder, final ImageReadyListener imageReadyListener) {
    return new LoaderDrawable(ThumbnailTask.create(request, boxItem, imageView, imageReadyListener),imageView.getResources(), placeHolder);
}
 
源代码7 项目: CrossBow   文件: CrossbowImage.java
@VisibleForTesting
void setBitmap(Bitmap bitmap, boolean fromCache) {
    ImageView imageView = this.imageView.get();
    if (bitmap != null && imageView != null) {

        Resources resources = imageView.getResources();
        BitmapDrawable bitmapDrawable = new BitmapDrawable(resources, bitmap);
        ScaleTypeDrawable bitmapScale = new ScaleTypeDrawable(bitmapDrawable, this.scaleType, this.debug && fromCache);

        if (this.fade != DEFAULT && !fromCache) {

            //Do a fade with an animation drawable

            if (defaultDrawable != null) {
                ScaleTypeDrawable defaultScale = new ScaleTypeDrawable(defaultDrawable, this.preScaleType);

                Drawable[] layers = new Drawable[2];
                layers[0] = defaultScale;
                layers[1] = bitmapScale;

                TransitionDrawable animationDrawable = new TransitionDrawable(layers);
                imageView.setImageDrawable(animationDrawable);
                animationDrawable.setCrossFadeEnabled(true);
                animationDrawable.startTransition(this.fade);
            }
            else {
                AlphaAnimation alphaAnimation = new AlphaAnimation(0,1);
                alphaAnimation.setDuration(this.fade);
                imageView.setImageDrawable(bitmapScale);
                imageView.startAnimation(alphaAnimation);
            }
        }
        else {
            //just set the bitmap
            imageView.setImageDrawable(bitmapScale);
        }

        if (this.listener != null) {
            this.listener.onLoad(true, fromCache, bitmap, imageView);
        }
    }
}
 
源代码8 项目: box-android-browse-sdk   文件: LoaderDrawable.java
/**
 * Creates a LoaderDrawable that is responsible for loading a thumbnail into the provided image view
 *
 * @param request            the request
 * @param boxItem            the box item
 * @param imageView          the image view
 * @param placeHolder        the place holder
 * @param imageReadyListener the image ready listener
 * @return loader drawable
 */
public static LoaderDrawable create(BoxRequestsFile.DownloadThumbnail request, final BoxItem boxItem, ImageView imageView, Bitmap placeHolder, final ImageReadyListener imageReadyListener) {
    return new LoaderDrawable(ThumbnailTask.create(request, boxItem, imageView, imageReadyListener),imageView.getResources(), placeHolder);
}