com.bumptech.glide.request.target.ViewTarget Java Examples

The following examples show how to use com.bumptech.glide.request.target.ViewTarget. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GlideImageLoader.java    From imsdk-android with MIT License 6 votes vote down vote up
@Override
    public void displaygGif(Activity activity, String path, ImageView imageView, int width, int height) {
        if(TextUtils.isEmpty(path)){
            com.orhanobut.logger.Logger.i("图片崩溃错误2");
            return;
        }
        Glide.with(activity)                             //配置上下文
                .load(path)
//                .load(new MyGlideUrl(path))      //设置图片路径(fix #8,文件名包含%符号 无法识别和显示)
                .asGif()
                .toBytes()
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)//缓存全尺寸
                .dontAnimate()
                .into(new ViewTarget<ImageView, byte[]>(imageView) {
                    @Override
                    public void onResourceReady(byte[] resource, GlideAnimation<? super byte[]> glideAnimation) {
//                            try {
                        FrameSequence fs = FrameSequence.decodeByteArray(resource);
                        FrameSequenceDrawable drawable = new FrameSequenceDrawable(fs);
                        view.setImageDrawable(drawable);
                    }
                });
    }
 
Example #2
Source File: App.java    From CrazyDaily with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    if (isMainProcess()) {
        sAppState = -1;
        getAppComponent();
        registerActivityLifecycleCallbacks(new CrazyDailyActivityLifecycleCallbacks());
        initScreenAdapter();
        ViewTarget.setTagId(R.id.glide_tag);
        LoggerUtil.init(BuildConfig.DEBUG);
        initWeex();
        initX5WebView();
        initSonic();
        initPgyer();
        initCrashHandler();
        initLeakCanary();
    }
}
 
Example #3
Source File: MyGlideModule.java    From Simpler with Apache License 2.0 6 votes vote down vote up
@Override
    public void applyOptions(Context context, GlideBuilder builder) {
        ViewTarget.setTagId(R.id.glide_tag_id);
        // Apply options to the builder here.
        // 默认内存和图片池大小
//        MemorySizeCalculator calculator = new MemorySizeCalculator(context);
//        int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); // 默认内存大小
//        int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); // 默认图片池大小
//        builder.setMemoryCache(new LruResourceCache(defaultMemoryCacheSize)); // 该两句无需设置,是默认的
//        builder.setBitmapPool(new LruBitmapPool(defaultBitmapPoolSize));
        //定义图片的本地磁盘缓存
//        File cacheDir = context.getExternalCacheDir();//指定的是数据的缓存地址
//        int diskCacheSize = 1024 * 1024 * 1024;//最多可以缓存多少字节的数据
        //设置磁盘缓存大小
//        builder.setDiskCache(new DiskLruCacheFactory(cacheDir.getPath(), "glide", diskCacheSize));
        // 定义缓存大小和位置
        if (BaseConfig.sSDCardExist) {
            builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, Constants.Dir.IMAGE_CACHE_DIR, extDiskSize)); //外部存储
        } else {
            builder.setDiskCache(new InternalCacheDiskCacheFactory(context, Constants.Dir.IMAGE_CACHE_DIR, intDiskSize));  //内部存储
        }
        // 自定义内存和图片池大小
//        builder.setMemoryCache(new LruResourceCache(memorySize));
//        builder.setBitmapPool(new LruBitmapPool(memorySize));
//        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    }
 
Example #4
Source File: LoggingListener.java    From StatusStories with Apache License 2.0 5 votes vote down vote up
private String getTargetDescription(Target<?> target) {
    String result;
    if (target instanceof WrappingTarget) {
        Target wrapped = ((WrappingTarget) target).getWrappedTarget();
        result = String.format(Locale.ROOT, "%s in %s", getTargetDescription(wrapped), target);
    } else if (target instanceof ViewTarget) {
        View v = ((ViewTarget) target).getView();
        LayoutParams p = v.getLayoutParams();
        result = String.format(Locale.ROOT,
                "%s(params=%dx%d->size=%dx%d)", target, p.width, p.height, v.getWidth(), v.getHeight());
    } else {
        result = String.valueOf(target);
    }
    return result;
}
 
Example #5
Source File: MyGlideModule.java    From ZoomPreviewPicture with Apache License 2.0 5 votes vote down vote up
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);
    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
     builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes));
    ViewTarget.setTagId(R.id.glide_tag_id);
}
 
Example #6
Source File: MyApplication.java    From XBanner with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    ViewTarget.setTagId(R.id.glide_tag);
    //Fresco初始化
    Fresco.initialize(this);
    OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .addInterceptor(new LoggerInterceptor("Xbanner"))
            .connectTimeout(10000L, TimeUnit.MILLISECONDS)
            .readTimeout(10000L, TimeUnit.MILLISECONDS)
            .build();
    OkHttpUtils.initClient(okHttpClient);
    Utils.init(this);
}
 
Example #7
Source File: VideoListGlideModule.java    From VideoListPlayer with MIT License 5 votes vote down vote up
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    ViewTarget.setTagId(R.id.glide_loader);
    builder.setDiskCache(new DiskLruCacheFactory(new DiskLruCacheFactory.CacheDirectoryGetter
            () {
        @Override
        public File getCacheDirectory() {
            return context.getExternalCacheDir();
        }
    }, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
}
 
Example #8
Source File: UsageExampleTargetsAndRemoteViews.java    From android-tutorials-glide with MIT License 5 votes vote down vote up
private void loadImageViewTarget() {
    viewTarget = new ViewTarget<FutureStudioView, GlideDrawable>( customView ) {
        @Override
        public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
            this.view.setImage( resource.getCurrent() );
        }
    };

    Glide
            .with( context.getApplicationContext() ) // safer!
            .load( eatFoodyImages[2] )
            .into( viewTarget );
}
 
Example #9
Source File: RobotNewQuestionListView.java    From imsdk-android with MIT License 4 votes vote down vote up
public LoadingImgView getLoadingImgView(final Context context, int w, int h, final String url, final int d) {
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(w, h);

        LoadingImgView mLoadingImgView = ViewPool.getView(LoadingImgView.class, context);
        mLoadingImgView.setLayoutParams(lp);

        if (Utils.isGifUrl(url)) {
            Glide.with(context)
                    .load(url.startsWith("http")?new MyGlideUrl(url):url)
                    .asGif()
                    .toBytes()
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)//缓存全尺寸
                    .dontAnimate()
                    .into(new ViewTarget<LoadingImgView, byte[]>(mLoadingImgView) {
                        @Override
                        public void onResourceReady(byte[] resource, GlideAnimation<? super byte[]> glideAnimation) {
                            WeakReference<Parcelable> cached = new WeakReference<>(MemoryCache.getMemoryCache(url));
                            if(cached.get() == null){
                                FrameSequence fs = FrameSequence.decodeByteArray(resource);
                                if(fs != null){
                                    FrameSequenceDrawable drawable = new FrameSequenceDrawable(fs);
                                    drawable.setByteCount(resource.length);
                                    view.setImageDrawable(drawable);
                                    MemoryCache.addObjToMemoryCache(url,drawable);
                                }
                            }else {
                                if(cached.get() instanceof FrameSequenceDrawable){
                                    FrameSequenceDrawable fsd = (FrameSequenceDrawable)cached.get();
                                    view.setImageDrawable(fsd);
                                }

                            }

                        }

                    });
        } else {
            //glide 3+
            Glide.with(context)                             //配置上下文
                    .load(url.startsWith("http")?new MyGlideUrl(url):url)      //设置图片路径(fix #8,文件名包含%符号 无法识别和显示)
                    .centerCrop()
                    .error(R.drawable.atom_ui_ic_default_image)           //设置错误图片
                    .placeholder(R.drawable.atom_ui_ic_default_image)     //设置占位图片
//                    .thumbnail(Glide.with(context).load(smallUrl))
                    .transform(new CenterCrop(context), new GlideRoundTransform(context))
                    .override(w, h)
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)//缓存全尺寸
                    .dontAnimate()
                    .into(mLoadingImgView);
        }
        return mLoadingImgView;
    }
 
Example #10
Source File: TextMessageProcessor.java    From imsdk-android with MIT License 4 votes vote down vote up
public LoadingImgView getLoadingImgView(final Context context, int w, int h, final String url, final int d) {
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(w, h);

        LoadingImgView mLoadingImgView = ViewPool.getView(LoadingImgView.class, context);
        mLoadingImgView.setLayoutParams(lp);

        if (Utils.isGifUrl(url)) {
            Glide.with(context)
                    .load(url.startsWith("http")?new MyGlideUrl(url):url)
                    .asGif()
                    .toBytes()
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)//缓存全尺寸
                    .dontAnimate()
                    .into(new ViewTarget<LoadingImgView, byte[]>(mLoadingImgView) {
                        @Override
                        public void onResourceReady(byte[] resource, GlideAnimation<? super byte[]> glideAnimation) {
                            WeakReference<Parcelable> cached = new WeakReference<>(MemoryCache.getMemoryCache(url));
                            if(cached.get() == null){
                                FrameSequence fs = FrameSequence.decodeByteArray(resource);
                                if(fs != null){
                                    FrameSequenceDrawable drawable = new FrameSequenceDrawable(fs);
                                    drawable.setByteCount(resource.length);
                                    view.setImageDrawable(drawable);
                                    MemoryCache.addObjToMemoryCache(url,drawable);
                                }
                            }else {
                                if(cached.get() instanceof FrameSequenceDrawable){
                                    FrameSequenceDrawable fsd = (FrameSequenceDrawable)cached.get();
                                    view.setImageDrawable(fsd);
                                }

                            }

                        }

                    });
        } else {
            //glide 3+
            Glide.with(context)                             //配置上下文
                    .load(url.startsWith("http")?new MyGlideUrl(url):url)      //设置图片路径(fix #8,文件名包含%符号 无法识别和显示)
                    .centerCrop()
                    .error(R.drawable.atom_ui_ic_default_image)           //设置错误图片
                    .placeholder(R.drawable.atom_ui_ic_default_image)     //设置占位图片
//                    .thumbnail(Glide.with(context).load(smallUrl))
                    .transform(new CenterCrop(context), new GlideRoundTransform(context))
                    .override(w, h)
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)//缓存全尺寸
                    .dontAnimate()
                    .into(mLoadingImgView);
        }
        return mLoadingImgView;
    }
 
Example #11
Source File: App.java    From glide-support with The Unlicense 4 votes vote down vote up
@Override public void onCreate() {
	super.onCreate();
	ViewTarget.setTagId(R.id._35096552_tag);
}
 
Example #12
Source File: NetworkFragment.java    From okulus with Apache License 2.0 4 votes vote down vote up
private void loadImage(final ImageView imageView, final int position) {

            final String imageurl = (String) getItem(position);
            switch (getItemViewType(position)) {

                //Volley - ImageRequest
                case 0: {
                    final ImageRequest request = new ImageRequest(
                            imageurl,
                            new Response.Listener<Bitmap>() {
                                @Override
                                public void onResponse(Bitmap response) {
                                    imageView.setImageBitmap(response);
                                }
                            },
                            dpToPx(128),
                            dpToPx(96),
                            null,
                            new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {

                                }
                            }
                    );

                    mRequestQueue.add(request);
                    break;
                }

                //Volley - NetworkImageView - In this case, NetworkImageView has been modified to extend OkulusImageView
                case 1: {

                    final NetworkImageView networkImageView = (NetworkImageView) imageView;
                    networkImageView.setImageUrl(imageurl, mImageLoader);
                    break;
                }

                //Picasso
                case 2: {

                    Picasso.with(imageView.getContext())
                            .load(imageurl)
                            .resize(dpToPx(128), dpToPx(96))
                            .centerCrop()
                            .into(new Target() {
                                @Override
                                public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                                    imageView.setImageBitmap(bitmap);
                                }

                                @Override
                                public void onBitmapFailed(Drawable errorDrawable) {

                                }

                                @Override
                                public void onPrepareLoad(Drawable placeHolderDrawable) {

                                }
                            });
                    break;
                }

                //Glide
                case 3: {

                    Glide.with(imageView.getContext())
                            .load(imageurl)
                            .asBitmap()
                            //.override(dpToPx(128), dpToPx(96))
                            .centerCrop()
                            .into(new ViewTarget<ImageView, Bitmap>(imageView) {
                                @Override
                                public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                                    imageView.setImageBitmap(resource);
                                }
                            });
                    break;
                }

                // Universal Image Loader
                case 4: {

                    ImageSize targetSize = new ImageSize(dpToPx(96), dpToPx(128));
                    mUniversalImageLoader.loadImage(imageurl, targetSize, new SimpleImageLoadingListener() {

                        @Override
                        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                            imageView.setImageBitmap(loadedImage);
                        }
                    });
                    break;
                }

            }
        }