Search in sources :

Example 51 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project MLib by DaoBillTang.

the class PhotoPagerAdapter method instantiateItem.

@Override
public Object instantiateItem(ViewGroup container, int position) {
    final Context context = container.getContext();
    View itemView = LayoutInflater.from(context).inflate(R.layout.__picker_picker_item_pager, container, false);
    final ImageView imageView = (ImageView) itemView.findViewById(R.id.iv_pager);
    final String path = paths.get(position);
    final Uri uri;
    if (path.startsWith("http")) {
        uri = Uri.parse(path);
    } else {
        uri = Uri.fromFile(new File(path));
    }
    boolean canLoadImage = AndroidLifecycleUtils.canLoadImage(context);
    if (canLoadImage) {
        final RequestOptions options = new RequestOptions();
        options.dontAnimate().dontTransform().override(800, 800).placeholder(R.drawable.__picker_ic_photo_black_48dp).error(R.drawable.__picker_ic_broken_image_black_48dp);
        mGlide.setDefaultRequestOptions(options).load(uri).thumbnail(0.1f).into(imageView);
    }
    imageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (context instanceof Activity) {
                if (!((Activity) context).isFinishing()) {
                    ((Activity) context).onBackPressed();
                }
            }
        }
    });
    container.addView(itemView);
    return itemView;
}
Also used : Context(android.content.Context) RequestOptions(com.bumptech.glide.request.RequestOptions) Activity(android.app.Activity) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) Uri(android.net.Uri) File(java.io.File)

Example 52 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project Rocket by mozilla-tw.

the class TabTrayAdapter method loadCachedFavicon.

private void loadCachedFavicon(final Tab tab, final ViewHolder holder) {
    RequestOptions options = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.RESOURCE).dontAnimate();
    Bitmap favicon = tab.getFavicon();
    FaviconModel model = new FaviconModel(tab.getUrl(), FavIconUtils.getFavIconType(holder.itemView.getResources(), favicon), favicon);
    requestManager.load(model).apply(options).listener(new RequestListener<Drawable>() {

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
            loadGeneratedFavicon(tab, holder);
            return true;
        }

        @Override
        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
            return false;
        }
    }).into(new SimpleTarget<Drawable>() {

        @Override
        public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
            updateFavicon(holder, resource);
        }
    });
}
Also used : RequestListener(com.bumptech.glide.request.RequestListener) RequestOptions(com.bumptech.glide.request.RequestOptions) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) DataSource(com.bumptech.glide.load.DataSource) Bitmap(android.graphics.Bitmap) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Target(com.bumptech.glide.request.target.Target) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(android.support.annotation.Nullable)

Example 53 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project KL2 by jweihao.

the class GridImageAdapter method onBindViewHolder.

/**
 * 设置值
 */
@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int position) {
    // 少于8张,显示继续添加的图标
    if (getItemViewType(position) == TYPE_CAMERA) {
        viewHolder.mImg.setImageResource(R.drawable.addimg_1x);
        viewHolder.mImg.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mOnAddPicClickListener.onAddPicClick();
            }
        });
        viewHolder.ll_del.setVisibility(View.INVISIBLE);
    } else {
        viewHolder.ll_del.setVisibility(View.VISIBLE);
        viewHolder.ll_del.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                int index = viewHolder.getAdapterPosition();
                // 通过源码分析应该是bindViewHolder()暂未绘制完成导致,知道原因的也可联系我~感谢
                if (index != RecyclerView.NO_POSITION) {
                    list.remove(index);
                    notifyItemRemoved(index);
                    notifyItemRangeChanged(index, list.size());
                }
            }
        });
        LocalMedia media = list.get(position);
        int mimeType = media.getMimeType();
        String path = "";
        if (media.isCut() && !media.isCompressed()) {
            // 裁剪过
            path = media.getCutPath();
        } else if (media.isCompressed() || (media.isCut() && media.isCompressed())) {
            // 压缩过,或者裁剪同时压缩过,以最终压缩过图片为准
            path = media.getCompressPath();
        } else {
            // 原图
            path = media.getPath();
        }
        // 图片
        if (media.isCompressed()) {
            Log.i("compress image result:", new File(media.getCompressPath()).length() / 1024 + "k");
            Log.i("压缩地址::", media.getCompressPath());
        }
        Log.i("原图地址::", media.getPath());
        int pictureType = PictureMimeType.isPictureType(media.getPictureType());
        if (media.isCut()) {
            Log.i("裁剪地址::", media.getCutPath());
        }
        long duration = media.getDuration();
        viewHolder.tv_duration.setVisibility(pictureType == PictureConfig.TYPE_VIDEO ? View.VISIBLE : View.GONE);
        if (mimeType == PictureMimeType.ofAudio()) {
            viewHolder.tv_duration.setVisibility(View.VISIBLE);
            Drawable drawable = ContextCompat.getDrawable(context, R.drawable.picture_audio);
            StringUtils.modifyTextViewDrawable(viewHolder.tv_duration, drawable, 0);
        } else {
            Drawable drawable = ContextCompat.getDrawable(context, R.drawable.video_icon);
            StringUtils.modifyTextViewDrawable(viewHolder.tv_duration, drawable, 0);
        }
        viewHolder.tv_duration.setText(DateUtils.timeParse(duration));
        if (mimeType == PictureMimeType.ofAudio()) {
            viewHolder.mImg.setImageResource(R.drawable.audio_placeholder);
        } else {
            RequestOptions options = new RequestOptions().centerCrop().placeholder(R.color.color_f6).diskCacheStrategy(DiskCacheStrategy.ALL);
            Glide.with(viewHolder.itemView.getContext()).load(path).apply(options).into(viewHolder.mImg);
        }
        // itemView 的点击事件
        if (mItemClickListener != null) {
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    int adapterPosition = viewHolder.getAdapterPosition();
                    mItemClickListener.onItemClick(adapterPosition, v);
                }
            });
        }
    }
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) Drawable(android.graphics.drawable.Drawable) LocalMedia(com.luck.picture.lib.entity.LocalMedia) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) File(java.io.File)

Example 54 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project LabDayApp by jakdor.

the class TimetableViewHolder method bind.

public void bind(Timetable timetable, Event event, int pos) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm", Locale.GERMAN);
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT+1"));
    Date start = new Date((long) timetable.getTimeStart() * 1000);
    Date end = new Date((long) timetable.getTimeEnd() * 1000);
    glide.load(event.getImg()).apply(new RequestOptions().placeholder(R.mipmap.ic_launcher_foreground).centerCrop()).transition(withCrossFade()).into(binding.timetableItemImage);
    binding.setIsNow(isNow(start, end));
    binding.setIsDarkColor(pos % 2 == 0);
    binding.setTimeStart(simpleDateFormat.format(start));
    binding.setTimeEnd(simpleDateFormat.format(end));
    binding.setTimetable(timetable);
    binding.setEvent(event);
    binding.executePendingBindings();
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 55 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project Camera-Roll-Android-App by kollerlukas.

the class AlbumHolder method loadImage.

void loadImage(final ImageView image) {
    if (album.getAlbumItems().size() == 0) {
        Glide.with(getContext()).load(R.drawable.error_placeholder).apply(new RequestOptions().skipMemoryCache(true)).into(image);
        return;
    }
    final AlbumItem coverImage = album.getAlbumItems().get(0);
    Glide.with(getContext()).asBitmap().load(coverImage.getPath()).listener(new RequestListener<Bitmap>() {

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
            coverImage.error = true;
            if (image instanceof ParallaxImageView) {
                ((ParallaxImageView) image).setParallaxTranslation();
            }
            return false;
        }

        @Override
        public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
            if (!coverImage.hasFadedIn) {
                coverImage.hasFadedIn = true;
                ColorFade.fadeSaturation(image);
            }
            if (image instanceof ParallaxImageView) {
                ((ParallaxImageView) image).setParallaxTranslation();
            }
            return false;
        }
    }).apply(coverImage.getGlideRequestOptions(getContext())).into(image);
}
Also used : Bitmap(android.graphics.Bitmap) RequestOptions(com.bumptech.glide.request.RequestOptions) ParallaxImageView(us.koller.cameraroll.ui.widget.ParallaxImageView) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) GlideException(com.bumptech.glide.load.engine.GlideException) DataSource(com.bumptech.glide.load.DataSource)

Aggregations

RequestOptions (com.bumptech.glide.request.RequestOptions)96 ImageView (android.widget.ImageView)23 View (android.view.View)18 Drawable (android.graphics.drawable.Drawable)16 TextView (android.widget.TextView)13 Bitmap (android.graphics.Bitmap)9 BitmapDrawable (android.graphics.drawable.BitmapDrawable)8 File (java.io.File)8 Uri (android.net.Uri)7 ColorDrawable (android.graphics.drawable.ColorDrawable)6 Context (android.content.Context)5 Intent (android.content.Intent)5 RecyclerView (android.support.v7.widget.RecyclerView)5 DataSource (com.bumptech.glide.load.DataSource)5 GlideException (com.bumptech.glide.load.engine.GlideException)5 FitCenter (com.bumptech.glide.load.resource.bitmap.FitCenter)5 RoundedCorners (com.bumptech.glide.load.resource.bitmap.RoundedCorners)5 Test (org.junit.Test)5 Activity (android.app.Activity)3 LayoutInflater (android.view.LayoutInflater)3