类com.bumptech.glide.request.target.BitmapImageViewTarget源码实例Demo

下面列出了怎么用com.bumptech.glide.request.target.BitmapImageViewTarget的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: YCAudioPlayer   文件: ImageUtil.java
/**
 * 加载带有圆角的矩形图片  用glide处理
 *
 * @param path   路径
 * @param round  圆角半径
 * @param resId  加载失败时的图片
 * @param target 控件
 */
public static void loadImgByPicassoWithRound(final Context activity, String path, final int round, int resId, final ImageView target) {
    if (path != null && path.length() > 0) {
        Glide.with(activity)
                .load(path)
                .asBitmap()
                .placeholder(resId)
                .error(resId)
                //设置缓存
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(new BitmapImageViewTarget(target) {
                    @Override
                    protected void setResource(Bitmap resource) {
                        super.setResource(resource);
                        RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(activity.getResources(), resource);
                        //设置圆角弧度
                        circularBitmapDrawable.setCornerRadius(round);
                        target.setImageDrawable(circularBitmapDrawable);
                    }
                });
    }
}
 
源代码2 项目: youqu_master   文件: BookReviewsAdapter.java
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof BookCommentHolder) {
        List<BookReviewBean> reviews = reviewsListResponse.getReviews();
        Glide.with(BaseApplication.getAppContext())
                .load(reviews.get(position).getAuthor().getAvatar())
                .asBitmap()
                .centerCrop()
                .into(new BitmapImageViewTarget(((BookCommentHolder) holder).iv_avatar) {
                    @Override
                    protected void setResource(Bitmap resource) {
                        RoundedBitmapDrawable circularBitmapDrawable =
                                RoundedBitmapDrawableFactory.create(BaseApplication.getAppContext().getResources(), resource);
                        circularBitmapDrawable.setCircular(true);
                        ((BookCommentHolder) holder).iv_avatar.setImageDrawable(circularBitmapDrawable);
                    }
                });
        ((BookCommentHolder) holder).tv_user_name.setText(reviews.get(position).getAuthor().getName());
        if (reviews.get(position).getRating() != null) {
            ((BookCommentHolder) holder).ratingBar_hots.setRating(Float.valueOf(reviews.get(position).getRating().getValue()));
        }
        ((BookCommentHolder) holder).tv_comment_content.setText(reviews.get(position).getSummary());
        ((BookCommentHolder) holder).tv_favorite_num.setText(reviews.get(position).getVotes() + "");
        ((BookCommentHolder) holder).tv_update_time.setText(reviews.get(position).getUpdated().split(" ")[0]);
    }
}
 
/**
 * 加载相册目录
 *
 * @param context   上下文
 * @param url       图片路径
 * @param imageView 承载图片ImageView
 */
@Override
public void loadFolderImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
    Glide.with(context)
            .asBitmap()
            .load(url)
            .override(180, 180)
            .centerCrop()
            .sizeMultiplier(0.5f)
            .apply(new RequestOptions().placeholder(R.drawable.picture_image_placeholder))
            .into(new BitmapImageViewTarget(imageView) {
                @Override
                protected void setResource(Bitmap resource) {
                    RoundedBitmapDrawable circularBitmapDrawable =
                            RoundedBitmapDrawableFactory.
                                    create(context.getResources(), resource);
                    circularBitmapDrawable.setCornerRadius(8);
                    imageView.setImageDrawable(circularBitmapDrawable);
                }
            });
}
 
源代码4 项目: PictureSelector   文件: GlideEngine.java
/**
 * 加载相册目录
 *
 * @param context   上下文
 * @param url       图片路径
 * @param imageView 承载图片ImageView
 */
@Override
public void loadFolderImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
    Glide.with(context)
            .asBitmap()
            .load(url)
            .override(180, 180)
            .centerCrop()
            .sizeMultiplier(0.5f)
            .apply(new RequestOptions().placeholder(R.drawable.picture_image_placeholder))
            .into(new BitmapImageViewTarget(imageView) {
                @Override
                protected void setResource(Bitmap resource) {
                    RoundedBitmapDrawable circularBitmapDrawable =
                            RoundedBitmapDrawableFactory.
                                    create(context.getResources(), resource);
                    circularBitmapDrawable.setCornerRadius(8);
                    imageView.setImageDrawable(circularBitmapDrawable);
                }
            });
}
 
源代码5 项目: YCVideoPlayer   文件: ImageUtil.java
/**
 * 加载带有圆角的矩形图片  用glide处理
 *
 * @param path   路径
 * @param round  圆角半径
 * @param resId  加载失败时的图片
 * @param target 控件
 */
public static void loadImgByPicassoWithRound(final Context activity, String path, final int round, int resId, final ImageView target) {
    if (path != null && path.length() > 0) {
        Glide.with(activity)
                .asBitmap()
                .load(path)
                .placeholder(resId)
                .error(resId)
                //设置缓存
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(new BitmapImageViewTarget(target) {
                    @Override
                    protected void setResource(Bitmap resource) {
                        super.setResource(resource);
                        RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(activity.getResources(), resource);
                        //设置圆角弧度
                        circularBitmapDrawable.setCornerRadius(round);
                        target.setImageDrawable(circularBitmapDrawable);
                    }
                });
    }
}
 
源代码6 项目: SendBird-Android   文件: ImageUtils.java
/**
 * Crops image into a circle that fits within the ImageView.
 */
public static void displayRoundImageFromUrl(final Context context, final String url, final ImageView imageView) {
    RequestOptions myOptions = new RequestOptions()
            .centerCrop()
            .dontAnimate();

    Glide.with(context)
            .asBitmap()
            .apply(myOptions)
            .load(url)
            .into(new BitmapImageViewTarget(imageView) {
                @Override
                protected void setResource(Bitmap resource) {
                    RoundedBitmapDrawable circularBitmapDrawable =
                            RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                    circularBitmapDrawable.setCircular(true);
                    imageView.setImageDrawable(circularBitmapDrawable);
                }
            });
}
 
源代码7 项目: SendBird-Android   文件: ImageUtils.java
/**
 * Crops image into a circle that fits within the ImageView.
 */
public static void displayRoundImageFromUrl(final Context context, final String url, final ImageView imageView) {
    RequestOptions myOptions = new RequestOptions()
            .centerCrop()
            .dontAnimate();

    Glide.with(context)
            .asBitmap()
            .apply(myOptions)
            .load(url)
            .into(new BitmapImageViewTarget(imageView) {
                @Override
                protected void setResource(Bitmap resource) {
                    RoundedBitmapDrawable circularBitmapDrawable =
                            RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                    circularBitmapDrawable.setCircular(true);
                    imageView.setImageDrawable(circularBitmapDrawable);
                }
            });
}
 
源代码8 项目: GankGirl   文件: GirlAdapter.java
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    GankBean gankBean = mData.get(position);
    BitmapRequestBuilder<String, Bitmap> requestBuilder = Glide.with(mContext)
            .load(gankBean.url)
            .asBitmap()
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .transform(new GlideRoundTransform(mContext, 4))
            .animate(R.anim.image_alpha_in)
            .error(R.color.accent);
    requestBuilder.into(new BitmapImageViewTarget(holder.ivGirlImg){
        @Override
        protected void setResource(Bitmap resource) {
            holder.ivGirlImg.setOriginalSize(resource.getWidth(), resource.getHeight());
            holder.ivGirlImg.setImageBitmap(resource);
        }
    });
}
 
private void setUserInfo() {

    Glide.with(this)
        .load(mUserInfo.avatarUrl)
        .asBitmap()
        .placeholder(R.drawable.ic_slide_menu_avatar_no_login)
        .into(new BitmapImageViewTarget(mUserInfoAvatar) {

          @Override
          protected void setResource(Bitmap resource) {

            mUserInfoAvatar.setImageDrawable(RoundedBitmapDrawableFactory
                .create(GitHubUserActivity.this.getResources(), resource));
          }
        });
    mUsername.setText(mUserInfo.name);
  }
 
源代码10 项目: MaterialHome   文件: EBookReviewsAdapter.java
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof BookCommentHolder) {
        List<HotReview.Reviews> reviews = mHotView.getReviews();
        Glide.with(UIUtils.getContext())
                .load(EBookUtils.getImageUrl(reviews.get(position).getAuthor().getAvatar()))
                .asBitmap()
                .centerCrop()
                .into(new BitmapImageViewTarget(((BookCommentHolder) holder).iv_avatar) {
                    @Override
                    protected void setResource(Bitmap resource) {
                        RoundedBitmapDrawable circularBitmapDrawable =
                                RoundedBitmapDrawableFactory.create(UIUtils.getContext().getResources(), resource);
                        circularBitmapDrawable.setCircular(true);
                        ((BookCommentHolder) holder).iv_avatar.setImageDrawable(circularBitmapDrawable);
                    }
                });
        ((BookCommentHolder) holder).tv_user_name.setText(reviews.get(position).getAuthor().getNickname());
        ((BookCommentHolder) holder).ratingBar_hots.setRating((float) reviews.get(position).getRating());
        ((BookCommentHolder) holder).tv_comment_content.setText(reviews.get(position).getContent());
        ((BookCommentHolder) holder).tv_favorite_num.setText(reviews.get(position).getLikeCount() + "");
        ((BookCommentHolder) holder).tv_update_time.setText(reviews.get(position).getUpdated().split("T")[0]);
    }
}
 
源代码11 项目: MaterialHome   文件: BookReviewsAdapter.java
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof BookCommentHolder) {
        List<BookReviewResponse> reviews = reviewsListResponse.getReviews();
        Glide.with(UIUtils.getContext())
                .load(reviews.get(position).getAuthor().getAvatar())
                .asBitmap()
                .centerCrop()
                .into(new BitmapImageViewTarget(((BookCommentHolder) holder).iv_avatar) {
                    @Override
                    protected void setResource(Bitmap resource) {
                        RoundedBitmapDrawable circularBitmapDrawable =
                                RoundedBitmapDrawableFactory.create(UIUtils.getContext().getResources(), resource);
                        circularBitmapDrawable.setCircular(true);
                        ((BookCommentHolder) holder).iv_avatar.setImageDrawable(circularBitmapDrawable);
                    }
                });
        ((BookCommentHolder) holder).tv_user_name.setText(reviews.get(position).getAuthor().getName());
        if (reviews.get(position).getRating() != null) {
            ((BookCommentHolder) holder).ratingBar_hots.setRating(Float.valueOf(reviews.get(position).getRating().getValue()));
        }
        ((BookCommentHolder) holder).tv_comment_content.setText(reviews.get(position).getSummary());
        ((BookCommentHolder) holder).tv_favorite_num.setText(reviews.get(position).getVotes() + "");
        ((BookCommentHolder) holder).tv_update_time.setText(reviews.get(position).getUpdated().split(" ")[0]);
    }
}
 
源代码12 项目: GankDaily   文件: MainListAdapter.java
@Override
void bindItem(Context context, final Gank gank, final int position) {
    mTvTime.setText(DateUtil.toDate(gank.publishedAt));

    Glide.with(context)
            .load(gank.url)
            .asBitmap()
            .into(new BitmapImageViewTarget(mImageView){
                @Override
                public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                    super.onResourceReady(resource, glideAnimation);
                    mBkTime.setVisibility(View.VISIBLE);
                }
            });

    mTvTime.setText(DateUtil.toDate(gank.publishedAt));
    mImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mIClickItem.onClickGankItemGirl(gank, mImageView, mTvTime);
        }
    });
}
 
@Override
public View getView(int position, View convertView, ViewGroup container) {
    if (convertView == null) {
        convertView = LayoutInflater.from(getActivity()).inflate(R.layout.list_item_article, container, false);
    }

    final DummyContent.DummyItem item = (DummyContent.DummyItem) getItem(position);
    ((TextView) convertView.findViewById(R.id.article_title)).setText(item.title);
    ((TextView) convertView.findViewById(R.id.article_subtitle)).setText(item.author);
    final ImageView img = (ImageView) convertView.findViewById(R.id.thumbnail);
    Glide.with(getActivity()).load(item.photoId).asBitmap().fitCenter().into(new BitmapImageViewTarget(img) {
        @Override
        protected void setResource(Bitmap resource) {
            RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getActivity().getResources(), resource);
            circularBitmapDrawable.setCircular(true);
            img.setImageDrawable(circularBitmapDrawable);
        }
    });

    return convertView;
}
 
源代码14 项目: MovieGuide   文件: MoviesListingAdapter.java
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    holder.itemView.setOnClickListener(holder);
    holder.movie = movies.get(position);
    holder.name.setText(holder.movie.getTitle());

    RequestOptions options = new RequestOptions()
            .centerCrop()
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
            .priority(Priority.HIGH);

    Glide.with(context)
            .asBitmap()
            .load(Api.getPosterPath(holder.movie.getPosterPath()))
            .apply(options)
            .into(new BitmapImageViewTarget(holder.poster) {
                @Override
                public void onResourceReady(Bitmap bitmap, @Nullable Transition<? super Bitmap> transition) {
                    super.onResourceReady(bitmap, transition);
                    Palette.from(bitmap).generate(palette -> setBackgroundColor(palette, holder));
                }
            });
}
 
源代码15 项目: Hillffair17   文件: LeaderBoardAdapter.java
@Override
public void onBindViewHolder(LeaderBoardViewHolder holder, int position) {
    LeaderBoardActivity.LeaderBoardUserModel user=users.get(position);

    holder.username.setText(user.getName().toString());
    holder.score.setText("Score: "+Integer.toString(user.getSets().getScore()));
    Glide.with(context).load(user.getPhoto()).into(holder.photo);

    final ImageView imageView=holder.photo;

    Glide.with(context).load(user.getPhoto()).asBitmap().centerCrop().into(new BitmapImageViewTarget(imageView) {
        @Override
        protected void setResource(Bitmap resource) {
            RoundedBitmapDrawable circularBitmapDrawable =
                    RoundedBitmapDrawableFactory.create(context.getResources(), resource);
            circularBitmapDrawable.setCircular(true);
            imageView.setImageDrawable(circularBitmapDrawable);
        }
    });

    Integer prsnlscore = user.getSets().getScore();
    if(prsnlscore>=800) holder.useraward.setImageResource(R.drawable.trophy_gold);
    else if(prsnlscore>=600) holder.useraward.setImageResource(R.drawable.trophy_silver);
    else if(prsnlscore>=450) holder.useraward.setImageResource(R.drawable.trophy_bronze);
    else if(prsnlscore>=300) holder.useraward.setImageResource(R.drawable.trophy_goldbadge);
    else if(prsnlscore>=150) holder.useraward.setImageResource(R.drawable.trophy_silverbadge);
    else if(prsnlscore>0) holder.useraward.setImageResource(R.drawable.trophy_bronzebadge);
    else if(prsnlscore==0) holder.useraward.setImageResource(R.drawable.trophy_participation);
    holder.sets.setText("Sets: "+Integer.toString(user.getSets().getSets()));
}
 
源代码16 项目: Nimbus   文件: LeaderBoardAdapter.java
@Override
public void onBindViewHolder(LeaderBoardViewHolder holder, int position) {
    LeaderBoardActivity.LeaderBoardUserModel user=users.get(position);

    holder.username.setText(user.getName().toString());
    holder.score.setText("Score: "+Integer.toString(user.getSets().getScore()));
    Glide.with(context).load(user.getPhoto()).into(holder.photo);

    final ImageView imageView=holder.photo;

    Glide.with(context).load(user.getPhoto()).asBitmap().centerCrop().into(new BitmapImageViewTarget(imageView) {
        @Override
        protected void setResource(Bitmap resource) {
            RoundedBitmapDrawable circularBitmapDrawable =
                    RoundedBitmapDrawableFactory.create(context.getResources(), resource);
            circularBitmapDrawable.setCircular(true);
            imageView.setImageDrawable(circularBitmapDrawable);
        }
    });

    Integer prsnlscore = user.getSets().getScore();
    if(prsnlscore>=800) holder.useraward.setImageResource(R.drawable.trophy_gold);
    else if(prsnlscore>=600) holder.useraward.setImageResource(R.drawable.trophy_silver);
    else if(prsnlscore>=450) holder.useraward.setImageResource(R.drawable.trophy_bronze);
    else if(prsnlscore>=300) holder.useraward.setImageResource(R.drawable.trophy_goldbadge);
    else if(prsnlscore>=150) holder.useraward.setImageResource(R.drawable.trophy_silverbadge);
    else if(prsnlscore>0) holder.useraward.setImageResource(R.drawable.trophy_bronzebadge);
    else if(prsnlscore==0) holder.useraward.setImageResource(R.drawable.trophy_participation);
    holder.sets.setText("Sets: "+Integer.toString(user.getSets().getSets()));
}
 
源代码17 项目: TouchNews   文件: ImageUtil.java
public static void displayCircularImage(final Context context, String url, final ImageView imageView) {
    Glide.with(context).load(url).asBitmap().centerCrop().into(new BitmapImageViewTarget(imageView) {
        @Override
        protected void setResource(Bitmap resource) {
            RoundedBitmapDrawable circularBitmapDrawable =
                RoundedBitmapDrawableFactory.create(context.getResources(), resource);
            circularBitmapDrawable.setCircular(true);
            imageView.setImageDrawable(circularBitmapDrawable);

        }
    });
}
 
源代码18 项目: TvAppRepo   文件: ApkPresenter.java
@Override
public void onBindViewHolder(ViewHolder viewHolder, Object item) {
    Apk application = (Apk) item;
    final ImageCardView cardView = (ImageCardView) viewHolder.view;

    Log.d(TAG, "onBindViewHolder");
    if (application.getBanner() != null) {
        cardView.setTitleText(application.getName());
        cardView.setContentText(mContext.getString(R.string.version_number, application.getVersionName()));
        cardView.setMainImageDimensions(CARD_WIDTH, CARD_HEIGHT);
        Glide.with(viewHolder.view.getContext())
                .load(!application.getBanner().isEmpty() ? application.getBanner() : application.getIcon())
                .asBitmap()
                .into(new BitmapImageViewTarget(cardView.getMainImageView()) {
                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                        super.onResourceReady(resource, glideAnimation);
                        Palette.generateAsync(resource, new Palette.PaletteAsyncListener() {
                            @Override
                            public void onGenerated(Palette palette) {
                                // Here's your generated palette
                                if (palette.getDarkVibrantSwatch() != null) {
                                    cardView.findViewById(R.id.info_field).setBackgroundColor(
                                            palette.getDarkVibrantSwatch().getRgb());
                                }
                            }
                        });
                    }
                });
    }
}
 
public void setUserInfo() {

    GitHubUserInfo mUserInfo = (GitHubUserInfo) ACache.get(MainActivity.this)
        .getAsObject(ConstantUtil.CACHE_USER_KEY);

    if (mUserInfo != null) {
      isLogin = true;
      Glide.with(MainActivity.this)
          .load(mUserInfo.avatarUrl)
          .asBitmap()
          .placeholder(R.drawable.ic_slide_menu_avatar_no_login)
          .into(new BitmapImageViewTarget(mUserAvatar) {

            @Override
            protected void setResource(Bitmap resource) {

              mUserAvatar.setImageDrawable(RoundedBitmapDrawableFactory.create
                  (MainActivity.this.getResources(), resource));
            }
          });

      mUserName.setText(mUserInfo.name);
      mUserBio.setText(mUserInfo.bio);
    } else {
      isLogin = false;
    }
  }
 
源代码20 项目: AlbumSelector   文件: MainActivity.java
/**
 * 得到选择的图片路径集合
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == ImageSelector.REQUEST_SELECT_IMAGE) {
        if (resultCode == RESULT_OK) {
            ArrayList<String> imagesPath = data.getStringArrayListExtra(ImageSelector.SELECTED_RESULT);
            if (isAvatorModel && imagesPath != null) {
                mRlAvator.setVisibility(View.VISIBLE);
                Glide.with(this)
                        .load(imagesPath.get(0))
                        .asBitmap()
                        .into(new BitmapImageViewTarget(mIvAvator) {
                            @Override
                            protected void setResource(Bitmap resource) {
                                RoundedBitmapDrawable circularBitmapDrawable =
                                        RoundedBitmapDrawableFactory.create(getResources(), resource);
                                circularBitmapDrawable.setCircular(true);
                                mIvAvator.setImageDrawable(circularBitmapDrawable);
                            }
                        });

            } else if (imagesPath != null) {
                mRlAvator.setVisibility(View.GONE);
                mAdapter.refreshData(imagesPath);
            }

        }
    }
}
 
源代码21 项目: Pasta-for-Spotify   文件: ArtistListData.java
@Override
public void bindView(final ViewHolder holder) {
    holder.name.setText(artistName);
    holder.extra.setText(String.valueOf(followers) + " followers");

    if (!PreferenceUtils.isThumbnails(holder.activity)) holder.image.setVisibility(View.GONE);
    else {
        Glide.with(holder.activity).load(artistImage).asBitmap().placeholder(ImageUtils.getVectorDrawable(holder.activity, R.drawable.preload)).thumbnail(0.2f).into(new BitmapImageViewTarget(holder.image) {
            @Override
            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                super.onResourceReady(resource, glideAnimation);

                if (holder.bg == null) return;
                Palette.from(resource).generate(new Palette.PaletteAsyncListener() {
                    @Override
                    public void onGenerated(Palette palette) {
                        ValueAnimator animator = ValueAnimator.ofObject(new ArgbEvaluator(), Color.DKGRAY, palette.getDarkVibrantColor(Color.DKGRAY));
                        animator.setDuration(250);
                        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                            @Override
                            public void onAnimationUpdate(ValueAnimator animation) {
                                int color = (int) animation.getAnimatedValue();
                                holder.bg.setBackgroundColor(color);
                            }
                        });
                        animator.start();
                    }
                });
            }
        });
    }
}
 
源代码22 项目: Pasta-for-Spotify   文件: PlaylistListData.java
@Override
public void bindView(final ViewHolder holder) {
    holder.name.setText(playlistName);
    holder.extra.setText(String.format("%d %s", tracks, tracks == 1 ? "track" : "tracks"));

    if (!PreferenceUtils.isThumbnails(holder.activity)) holder.image.setVisibility(View.GONE);
    else {
        Glide.with(holder.activity).load(playlistImage).asBitmap().placeholder(ImageUtils.getVectorDrawable(holder.activity, R.drawable.preload)).thumbnail(0.2f).into(new BitmapImageViewTarget(holder.image) {
            @Override
            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                super.onResourceReady(resource, glideAnimation);

                if (holder.bg == null) return;
                Palette.from(resource).generate(new Palette.PaletteAsyncListener() {
                    @Override
                    public void onGenerated(Palette palette) {
                        ValueAnimator animator = ValueAnimator.ofObject(new ArgbEvaluator(), Color.DKGRAY, palette.getDarkVibrantColor(Color.DKGRAY));
                        animator.setDuration(250);
                        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                            @Override
                            public void onAnimationUpdate(ValueAnimator animation) {
                                int color = (int) animation.getAnimatedValue();
                                holder.bg.setBackgroundColor(color);
                            }
                        });
                        animator.start();
                    }
                });
            }
        });
    }
}
 
源代码23 项目: Pasta-for-Spotify   文件: TrackListData.java
@Override
public void bindView(final ViewHolder holder) {
    holder.name.setText(trackName);
    if (artists.size() > 0)
        holder.extra.setText(artists.get(0).artistName);
    else holder.extra.setText("");

    if (!PreferenceUtils.isThumbnails(holder.activity)) holder.image.setVisibility(View.GONE);
    else {
        Glide.with(holder.activity).load(trackImage).asBitmap().placeholder(ImageUtils.getVectorDrawable(holder.activity, R.drawable.preload)).thumbnail(0.2f).into(new BitmapImageViewTarget(holder.image) {
            @Override
            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                super.onResourceReady(resource, glideAnimation);

                if (holder.bg == null) return;
                Palette.from(resource).generate(new Palette.PaletteAsyncListener() {
                    @Override
                    public void onGenerated(Palette palette) {
                        ValueAnimator animator = ValueAnimator.ofObject(new ArgbEvaluator(), Color.DKGRAY, palette.getDarkVibrantColor(Color.DKGRAY));
                        animator.setDuration(250);
                        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                            @Override
                            public void onAnimationUpdate(ValueAnimator animation) {
                                int color = (int) animation.getAnimatedValue();
                                holder.bg.setBackgroundColor(color);
                            }
                        });
                        animator.start();
                    }
                });
            }
        });
    }
}
 
源代码24 项目: RxZhihuDaily   文件: ChiefEditorAdapter.java
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.chief_editor_item, parent, false);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    final ViewHolder Hohholder = holder;
    if (Hohholder != null) {
        Glide
                .with(context)
                .load(editors.get(position).getAvatar())
                .asBitmap()
                .centerCrop()
                .into(new BitmapImageViewTarget(Hohholder.imgChiefEditorItem) {
                    @Override
                    protected void setResource(Bitmap resource) {
                        RoundedBitmapDrawable circularBitmapDrawable =
                                RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                        circularBitmapDrawable.setCircular(true);
                        Hohholder.imgChiefEditorItem.setImageDrawable(circularBitmapDrawable);
                    }
                });
    }
    return convertView;
}
 
源代码25 项目: android   文件: RepCallActivity.java
private void setupContactUi(int index, boolean expandLocalSection) {
    final Contact contact = mIssue.contacts.get(index);
    contactName.setText(contact.name);

    // Set the reason for contacting this rep, using default text if no reason is provided.
    final String contactReasonText = TextUtils.isEmpty(contact.reason)
            ? getResources().getString(R.string.contact_reason_default)
            : contact.reason;
    contactReason.setText(contactReasonText);

    if (!TextUtils.isEmpty(contact.photoURL)) {
        repImage.setVisibility(View.VISIBLE);
        Glide.with(getApplicationContext())
                .load(contact.photoURL)
                .asBitmap()
                .centerCrop()
                .into(new BitmapImageViewTarget(repImage) {
                    @Override
                    protected void setResource(Bitmap resource) {
                        RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(
                                repImage.getContext().getResources(), resource);
                        drawable.setCircular(true);
                        drawable.setGravity(Gravity.TOP);
                        repImage.setImageDrawable(drawable);
                    }
                });
    } else {
        repImage.setVisibility(View.GONE);
    }
    phoneNumber.setText(contact.phone);
    Linkify.addLinks(phoneNumber, Linkify.PHONE_NUMBERS);

    if (expandLocalSection) {
        localOfficeButton.setVisibility(View.INVISIBLE);
        expandLocalOfficeSection(contact);
    } else {
        localOfficeSection.setVisibility(View.GONE);
        localOfficeSection.removeViews(1, localOfficeSection.getChildCount() - 1);
        if (contact.field_offices == null || contact.field_offices.length == 0) {
            localOfficeButton.setVisibility(View.GONE);
        } else {
            localOfficeButton.setVisibility(View.VISIBLE);
            localOfficeButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    localOfficeButton.setOnClickListener(null);
                    expandLocalOfficeSection(contact);
                }
            });
        }
    }

    // Show a bit about whether they've been contacted yet
    final List<String> previousCalls = AppSingleton.getInstance(this).getDatabaseHelper()
            .getCallResults(mIssue.id, contact.id);
    if (previousCalls.size() > 0) {
        showContactChecked(previousCalls);
    } else {
        contactChecked.setVisibility(View.GONE);
        contactChecked.setOnClickListener(null);
    }
}
 
源代码26 项目: android   文件: IssueActivity.java
private void populateRepView(View repView, Contact contact, final int index,
                             List<String> previousCalls) {
    TextView contactName = repView.findViewById(R.id.contact_name);
    final ImageView repImage = repView.findViewById(R.id.rep_image);
    ImageView contactChecked = repView.findViewById(R.id.contact_done_img);
    TextView contactReason = repView.findViewById(R.id.contact_reason);
    TextView contactWarning = repView.findViewById(R.id.contact_warning);
    contactName.setText(contact.name);
    contactWarning.setVisibility(View.GONE);
    if (!TextUtils.isEmpty(contact.area)) {
        contactReason.setText(contact.area);
        if (TextUtils.equals(contact.area, "US House") && mIssue.isSplit) {
            contactWarning.setVisibility(View.VISIBLE);
            contactWarning.setText(R.string.split_district_warning);
        }
        contactReason.setVisibility(View.VISIBLE);
    } else {
        contactReason.setVisibility(View.GONE);
    }
    if (!TextUtils.isEmpty(contact.photoURL)) {
        repImage.setVisibility(View.VISIBLE);
        Glide.with(getApplicationContext())
                .load(contact.photoURL)
                .asBitmap()
                .centerCrop()
                .into(new BitmapImageViewTarget(repImage) {
                    @Override
                    protected void setResource(Bitmap resource) {
                        RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(
                                repImage.getContext().getResources(), resource);
                        drawable.setCircular(true);
                        drawable.setGravity(Gravity.TOP);
                        repImage.setImageDrawable(drawable);
                    }
                });
    } else {
        repImage.setVisibility(View.GONE);
    }
    // Show a bit about whether they've been contacted yet
    if (previousCalls.size() > 0) {
        contactChecked.setImageLevel(1);
        contactChecked.setContentDescription(getResources().getString(
                R.string.contact_done_img_description));
    } else {
        contactChecked.setImageLevel(0);
        contactChecked.setContentDescription(null);
    }

    repView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(getApplicationContext(), RepCallActivity.class);
            intent.putExtra(KEY_ISSUE, mIssue);
            intent.putExtra(RepCallActivity.KEY_ADDRESS,
                    getIntent().getStringExtra(RepCallActivity.KEY_ADDRESS));
            intent.putExtra(RepCallActivity.KEY_ACTIVE_CONTACT_INDEX, index);
            startActivity(intent);
        }
    });
}
 
源代码27 项目: explorer   文件: ViewHolderImage.java
@Override
protected void bindIcon(File file, Boolean selected) {

    final int color = ContextCompat.getColor(context, getColorResource(file));

    Glide.with(context).load(file).asBitmap().fitCenter().into(new BitmapImageViewTarget(image) {

        @Override
        public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> animation) {

            this.view.setImageBitmap(resource);

            name.setBackgroundColor(Palette.from(resource).generate().getMutedColor(color));
        }
    });
}
 
源代码28 项目: glide-support   文件: ImageChunkAdapter.java
@Override public void onBindViewHolder(ImageChunkViewHolder holder, int position) {
	int left = 0, top = imageChunkHeight * position;
	int width = image.x, height = imageChunkHeight;
	if (position == getItemCount() - 1 && image.y % imageChunkHeight != 0) {
		height = image.y % imageChunkHeight; // height of last partial row, if any
	}
	Rect rect = new Rect(left, top, left + width, top + height);
	float viewWidth = width * ratio;
	float viewHeight = height * ratio;

	final String bind = String.format(Locale.ROOT, "Binding %s w=%d (%d->%f) h=%d (%d->%f)",
			rect.toShortString(),
			rect.width(), width, viewWidth,
			rect.height(), height, viewHeight);

	Context context = holder.itemView.getContext();
	// See https://docs.google.com/drawings/d/1KyOJkNd5Dlm8_awZpftzW7KtqgNR6GURvuF6RfB210g/edit?usp=sharing
	Glide
			.with(context)
			.load(url)
			.asBitmap()
			.placeholder(new ColorDrawable(Color.BLUE))
			.error(new ColorDrawable(Color.RED))
			// overshoot a little so fitCenter uses width's ratio (see minPercentage)
			.override(Math.round(viewWidth), (int)Math.ceil(viewHeight))
			.fitCenter()
			// Cannot use .imageDecoder, only decoder; see bumptech/glide#708
			//.imageDecoder(new RegionStreamDecoder(context, rect))
			.decoder(new RegionImageVideoDecoder(context, rect))
			.cacheDecoder(new RegionFileDecoder(context, rect))
			// Cannot use RESULT cache; see bumptech/glide#707
			.diskCacheStrategy(DiskCacheStrategy.SOURCE)
			.listener(new LoggingListener<String, Bitmap>(bind))
			.into(new BitmapImageViewTarget(holder.imageView) {
				@Override protected void setResource(Bitmap resource) {
					if (resource != null) {
						LayoutParams params = view.getLayoutParams();
						if (params.height != resource.getHeight()) {
							params.height = resource.getHeight();
						}
						view.setLayoutParams(params);
					}
					super.setResource(resource);
				}
			})
	;
}
 
源代码29 项目: glide-support   文件: TestFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
	super.onViewCreated(view, savedInstanceState);

	listView.setAdapter(new SimpleUrlAdapter(Glide.with(this), Arrays.asList(
			"https://s.yimg.com/pe/vguide/netflix.png",
			"https://s.yimg.com/pe/vguide/hulu.png",
			"https://s.yimg.com/pe/vguide/amazon.png",
			"https://s.yimg.com/pe/vguide/hbo.png",
			"https://s.yimg.com/pe/vguide/showtime.png",
			"https://s.yimg.com/pe/vguide/youtube.png",
			"https://s.yimg.com/pe/vguide/fox.png",
			"https://s.yimg.com/pe/vguide/cbs.png",
			"https://s.yimg.com/pe/vguide/nbc.png",
			"https://s.yimg.com/pe/vguide/abc.png",
			"https://s.yimg.com/pe/vguide/tbs.png",
			"https://s.yimg.com/pe/vguide/the-cw.png",
			"https://s.yimg.com/pe/vguide/crackle.png",
			"https://s.yimg.com/pe/vguide/a-e.png",
			"https://s.yimg.com/pe/vguide/abc-family.png",
			"https://s.yimg.com/pe/vguide/amc.png",
			"https://s.yimg.com/pe/vguide/cartoon-network.png",
			"https://s.yimg.com/pe/vguide/adult-swim.png",
			"https://s.yimg.com/pe/vguide/comedy-central.png",
			"https://s.yimg.com/pe/vguide/disney.png",
			"https://s.yimg.com/pe/vguide/lifetime.png",
			"https://s.yimg.com/pe/vguide/mtv.png",
			"https://s.yimg.com/pe/vguide/nick-com.png",
			"https://s.yimg.com/pe/vguide/pbs.png",
			"https://s.yimg.com/pe/vguide/bravo.png",
			"https://s.yimg.com/pe/vguide/fx.png",
			"https://s.yimg.com/pe/vguide/history.png",
			"https://s.yimg.com/pe/vguide/tnt.png",
			"https://s.yimg.com/pe/vguide/usa-network.png",
			"https://s.yimg.com/pe/vguide/vh-1.png",
			"https://s.yimg.com/pe/vguide/spike.png",
			"https://s.yimg.com/pe/vguide/bet.png",
			"https://s.yimg.com/pe/vguide/we-tv.png",
			"https://s.yimg.com/pe/vguide/food-network.png",
			"https://s.yimg.com/pe/vguide/epix.png",
			"https://s.yimg.com/pe/vguide/cinemax.png",
			"https://s.yimg.com/pe/vguide/xfinity.png"
	)) {
		@Override protected View onCreateView(LayoutInflater inflater, ViewGroup parent, int viewType) {
			return inflater.inflate(R.layout.github_601_item, parent, false);
		}
		int tempPosition = -1;
		@Override public void onBindViewHolder(
				SimpleViewHolder holder, @SuppressLint("RecyclerView") int position) {
			tempPosition = position;
			super.onBindViewHolder(holder, position);
		}
		@Override protected void load(Context context, RequestManager glide, String url, ImageView imageView)
				throws Exception {
			final String row = "pos" + tempPosition;
			glide
					.load(url)
					.asBitmap()
					.fitCenter()
					.listener(new LoggingListener<String, Bitmap>(Log.DEBUG, row))
					.into(new LoggingTarget<>(row, Log.VERBOSE, new BitmapImageViewTarget(imageView)))
			;
		}
	});
}
 
源代码30 项目: Pasta-for-Spotify   文件: AlbumListData.java
@Override
public void bindView(final ViewHolder holder) {
    if (holder.artist != null) {
        if (artists.size() > 0) {
            holder.artistName.setText(artists.get(0).artistName);
            holder.artistExtra.setText(albumDate);

            new Action<ArtistListData>() {
                @NonNull
                @Override
                public String id() {
                    return "gotoArtist";
                }

                @Nullable
                @Override
                protected ArtistListData run() throws InterruptedException {
                    return holder.pasta.getArtist(artists.get(0).artistId);
                }

                @Override
                protected void done(@Nullable ArtistListData result) {
                    if (result == null) {
                        holder.pasta.onError(holder.activity, "artist action");
                        return;
                    }

                    holder.artist.setTag(result);
                }
            }.execute();
        } else holder.artist.setVisibility(View.GONE);
    }

    holder.name.setText(albumName);
    holder.extra.setText(String.valueOf(tracks) + " track" + (tracks == 1 ? "" : "s"));

    if (!PreferenceUtils.isThumbnails(holder.pasta)) holder.image.setVisibility(View.GONE);
    else {
        Glide.with(holder.pasta).load(albumImage).asBitmap().placeholder(ImageUtils.getVectorDrawable(holder.pasta, R.drawable.preload)).into(new BitmapImageViewTarget(holder.image) {
            @Override
            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                super.onResourceReady(resource, glideAnimation);

                if (holder.bg == null) return;
                Palette.from(resource).generate(new Palette.PaletteAsyncListener() {
                    @Override
                    public void onGenerated(Palette palette) {

                        ValueAnimator animator = ValueAnimator.ofObject(new ArgbEvaluator(), Color.DKGRAY, palette.getDarkVibrantColor(Color.DKGRAY));
                        animator.setDuration(250);
                        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                            @Override
                            public void onAnimationUpdate(ValueAnimator animation) {
                                int color = (int) animation.getAnimatedValue();
                                holder.bg.setBackgroundColor(color);
                                holder.artist.setBackgroundColor(Color.argb(255, Math.max(Color.red(color) - 10, 0), Math.max(Color.green(color) - 10, 0), Math.max(Color.blue(color) - 10, 0)));
                            }
                        });
                        animator.start();
                    }
                });
            }
        });
    }
}
 
 类所在包
 类方法
 同包方法