123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- package com.example.zhpan.circleviewpager.imageloader;
- import android.content.Context;
- import android.support.annotation.DimenRes;
- import android.support.annotation.DrawableRes;
- import android.widget.ImageView;
- import com.zhpan.idea.utils.DensityUtils;
- /**
- * <pre>
- * Created by zhangpan on 2019-08-12.
- * Description:
- * </pre>
- */
- public class ImageLoaderOptions {
- private ImageView mImageView;
- private String url;
- private @DrawableRes
- int resource;
- private @DrawableRes
- int placeholder;
- private @DrawableRes
- int errorDrawable;
- private boolean asGif;
- private boolean isCrossFade;
- private boolean skipMemoryCache;
- private float roundCorner;
- private boolean blurImage;
- // 高斯模糊参数,越大越模糊
- private int blurValue;
- private ScaleType mScaleType;
- private ImageSize mImageSize;
- private ImageDiskCacheStrategy mDiskCacheStrategy;
- private ImageLoaderOptions(Builder builder) {
- this.mImageView = builder.mImageView;
- this.url = builder.url;
- this.resource = builder.resource;
- this.placeholder = builder.placeholder;
- this.errorDrawable = builder.errorDrawable;
- this.asGif = builder.asGif;
- this.isCrossFade = builder.isCrossFade;
- this.skipMemoryCache = builder.skipMemoryCache;
- this.mDiskCacheStrategy = builder.mDiskCacheStrategy;
- this.roundCorner = builder.roundCorner;
- this.blurImage = builder.blurImage;
- this.blurValue = builder.blurValue;
- this.mScaleType = builder.mScaleType;
- this.mImageSize = builder.mImageSize;
- }
- public ImageView getImageView() {
- return mImageView;
- }
- public String getUrl() {
- return url;
- }
- public int getResource() {
- return resource;
- }
- public int getPlaceholder() {
- return placeholder;
- }
- public int getErrorDrawable() {
- return errorDrawable;
- }
- public boolean isAsGif() {
- return asGif;
- }
- public boolean isCrossFade() {
- return isCrossFade;
- }
- public boolean isSkipMemoryCache() {
- return skipMemoryCache;
- }
- public float getRoundCorner() {
- return roundCorner;
- }
- public boolean isBlurImage() {
- return blurImage;
- }
- public int getBlurValue() {
- return blurValue;
- }
- public ScaleType getScaleType() {
- return mScaleType;
- }
- public ImageSize getImageSize() {
- return mImageSize;
- }
- public ImageDiskCacheStrategy getDiskCacheStrategy() {
- return mDiskCacheStrategy;
- }
- public static class Builder {
- private ImageView mImageView;
- private String url;
- private @DrawableRes
- int resource = -1;
- private @DrawableRes
- int placeholder = -1;
- private @DrawableRes
- int errorDrawable = -1;
- private boolean asGif;
- private boolean isCrossFade = true;
- private boolean skipMemoryCache;
- private float roundCorner;
- private boolean blurImage;
- private int blurValue; // 高斯模糊参数,越大越模糊
- private ScaleType mScaleType = ScaleType.DEFAULT;
- private ImageSize mImageSize;
- private ImageDiskCacheStrategy mDiskCacheStrategy = ImageDiskCacheStrategy.DEFAULT;
- public Builder into(ImageView imageView) {
- this.mImageView = imageView;
- return this;
- }
- public Builder load(String url) {
- this.url = url;
- return this;
- }
- public Builder load(@DrawableRes int resource) {
- this.resource = resource;
- return this;
- }
- public Builder placeHolder(@DrawableRes int placeholder) {
- this.placeholder = placeholder;
- return this;
- }
- public Builder isCrossFade(boolean isCrossFade) {
- this.isCrossFade = isCrossFade;
- return this;
- }
- public Builder isSkipMemoryCache(boolean skipMemoryCache) {
- this.skipMemoryCache = skipMemoryCache;
- return this;
- }
- public Builder asGif(boolean asGif) {
- this.asGif = asGif;
- return this;
- }
- public Builder error(@DrawableRes int errorDrawable) {
- this.errorDrawable = errorDrawable;
- return this;
- }
- public Builder diskCacheStrategy(ImageDiskCacheStrategy mDiskCacheStrategy) {
- this.mDiskCacheStrategy = mDiskCacheStrategy;
- return this;
- }
- public Builder setRoundCorner(Context context, float roundCornerDp) {
- this.roundCorner = DensityUtils.dp2px(context, roundCornerDp);
- return this;
- }
- public Builder setRoundCorner(Context context, @DimenRes int cornerRes) {
- this.roundCorner = context.getResources().getDimension(cornerRes);
- return this;
- }
- public Builder setBlurImage(int blurValue) {
- this.blurImage = true;
- this.blurValue = blurValue;
- return this;
- }
- public Builder setScaleType(ScaleType scaleType) {
- mScaleType = scaleType;
- return this;
- }
- public Builder override(int imageWidth, int imageHeight) {
- this.mImageSize = new ImageSize(imageWidth, imageHeight);
- return this;
- }
- public ImageLoaderOptions build() {
- return new ImageLoaderOptions(this);
- }
- }
- public static class ImageSize {
- private int imageWidth;
- private int imageHeight;
- public ImageSize(int imageWidth, int imageHeight) {
- this.imageWidth = imageWidth;
- this.imageHeight = imageHeight;
- }
- public int getImageWidth() {
- return imageWidth;
- }
- public int getImageHeight() {
- return imageHeight;
- }
- }
- // 对应磁盘缓存策略
- public enum ImageDiskCacheStrategy {
- All, NONE, SOURCE, RESULT, DEFAULT
- }
- }
|