public static Bitmap getBitmap(GlideDrawable glideDrawable) { if (glideDrawable instanceof GlideBitmapDrawable) { return ((GlideBitmapDrawable) glideDrawable).getBitmap(); } else if (glideDrawable instanceof GifDrawable) { return ((GifDrawable) glideDrawable).getFirstFrame(); } return null; } }
@Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) { super.onResourceReady(resource, animation); if (!autoplayGifs) { resource.stop(); } BadgedFourThreeImageView badgedImageView = (BadgedFourThreeImageView) getView(); if (resource instanceof GlideBitmapDrawable) { Palette.from(((GlideBitmapDrawable) resource).getBitmap()) .clearFilters() .generate(this); } else if (resource instanceof GifDrawable) { Bitmap image = ((GifDrawable) resource).getFirstFrame(); Palette.from(image).clearFilters().generate(this); // look at the corner to determine the gif badge color int cornerSize = (int) (56 * getView().getContext().getResources().getDisplayMetrics ().scaledDensity); Bitmap corner = Bitmap.createBitmap(image, image.getWidth() - cornerSize, image.getHeight() - cornerSize, cornerSize, cornerSize); boolean isDark = ColorUtils.isDark(corner); corner.recycle(); badgedImageView.setBadgeColor(ContextCompat.getColor(getView().getContext(), isDark ? R.color.gif_badge_dark_image : R.color.gif_badge_light_image)); } }
@Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) { super.onResourceReady(resource, animation); if (!autoplayGifs) { resource.stop(); } BadgedFourThreeImageView badgedImageView = (BadgedFourThreeImageView) getView(); if (resource instanceof GlideBitmapDrawable) { Palette.from(((GlideBitmapDrawable) resource).getBitmap()) .clearFilters() .generate(this); } else if (resource instanceof GifDrawable) { Bitmap image = ((GifDrawable) resource).getFirstFrame(); Palette.from(image).clearFilters().generate(this); // look at the corner to determine the gif badge color int cornerSize = (int) (56 * getView().getContext().getResources().getDisplayMetrics ().scaledDensity); Bitmap corner = Bitmap.createBitmap(image, image.getWidth() - cornerSize, image.getHeight() - cornerSize, cornerSize, cornerSize); boolean isDark = ColorUtils.isDark(corner); corner.recycle(); badgedImageView.setBadgeColor(ContextCompat.getColor(getView().getContext(), isDark ? R.color.gif_badge_dark_image : R.color.gif_badge_light_image)); } }
@Override public void recycle() { bitmapPool.put(drawable.getBitmap()); } }
@Override public int getSize() { return Util.getBitmapByteSize(drawable.getBitmap()); }
@Override public boolean onResourceReady( GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { onBitmapReady(GlideBitmapDrawable.class.cast(resource).getBitmap()); return false; }
@Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { mImageIcon.setImageDrawable(resource); GlideBitmapDrawable drawable = (GlideBitmapDrawable) mImageIcon.getDrawable().getCurrent(); Bitmap bitmap = drawable.getBitmap(); } }
public static Bitmap getBitmap(GlideDrawable glideDrawable) { if (glideDrawable instanceof GlideBitmapDrawable) { return ((GlideBitmapDrawable) glideDrawable).getBitmap(); } else if (glideDrawable instanceof GifDrawable) { return ((GifDrawable) glideDrawable).getFirstFrame(); } return null; } }
@Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { Bitmap bitmap = ((GlideBitmapDrawable) resource.getCurrent()).getBitmap(); changeUIColors(bitmap); return false; } })
@Override public void onClick(View v) { Bundle b = new Bundle(); b.putSerializable(BookInfoResponse.serialVersionName, bookInfo); Bitmap bitmap; GlideBitmapDrawable imageDrawable = (GlideBitmapDrawable) holder.iv_book_img.getDrawable(); if (imageDrawable != null) { bitmap = imageDrawable.getBitmap(); b.putParcelable("book_img", bitmap); } Intent intent = new Intent(holder.itemView.getContext(), BookDetailsActivity.class); intent.putExtras(b); // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // if (BaseActivity.activity == null) { // UIUtils.startActivity(intent); // return; // } //// ActivityOptionsCompat options = ActivityOptionsCompat. //// makeSceneTransitionAnimation(BaseActivity.activity, holder.iv_book_img, "book_img"); //// BaseActivity.activity.startActivity(intent, options.toBundle()); // } else { // UIUtils.startActivity(intent); //} holder.itemView.getContext().startActivity(intent); } });
@Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { if(resource != null && resource.getCurrent() instanceof GlideBitmapDrawable){ if(callback == null){ imageView.setImageBitmap(((GlideBitmapDrawable)resource.getCurrent()).getBitmap()); }else{ callback.callBack(imgUrl, imageView, ((GlideBitmapDrawable)resource.getCurrent()).getBitmap()); } } return false; } };
@Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { Bitmap bitmap = ((GlideBitmapDrawable) resource.getCurrent()).getBitmap(); Palette palette = Palette.generate(bitmap); int defaultColor = 0xFF333333; int color = palette.getDarkMutedColor(defaultColor); holder.itemView.setBackgroundColor(color); return false; } })
@Override public void onClick(View view) { if (mIsCropped) { Bitmap bitmap; Drawable drawable = mImageView.getDrawable(); if (drawable instanceof GlideBitmapDrawable) { // if imageview has drawable of type GlideBitmapDrawable bitmap = ((GlideBitmapDrawable) mImageView.getDrawable().getCurrent()) .getBitmap(); } else { // if imageView stores cropped image drawable which is of type drawable bitmap = ((BitmapDrawable) mImageView.getDrawable()).getBitmap(); } // if image was cropped, delete old file // and store new bitmap on that location mPhotoPath = PhotoHelper.saveBitmapAsFile(mPhotoPath, bitmap); } // start PhotoEditActivity, passing it the file path for cropped photo Intent intent = new Intent(PhotoSendActivity.this, PhotoEditActivity.class); intent.putExtra(Intent.EXTRA_TEXT, mPhotoPath); startActivity(intent); // activity transition animation ActivityTransitionAnim.transition(PhotoSendActivity.this); } });
@Override public void onClick(View view) { Bitmap bitmap; Drawable drawable = mImageView.getDrawable(); if (drawable instanceof GlideBitmapDrawable) { // if imageview has drawable of type GlideBitmapDrawable bitmap = ((GlideBitmapDrawable) mImageView.getDrawable().getCurrent()) .getBitmap(); } else { // if imageView stores cropped image drawable which is of type drawable bitmap = ((BitmapDrawable) mImageView.getDrawable()).getBitmap(); } /* Most phone cameras are landscape, meaning if you take the photo in portrait, the resulting photos will be rotated 90 degrees. Hence used the displayed image with correct orientation and saved that in the current photo path. */ // delete old file and store new bitmap on that location // used the displayed image and saved it in the mPhotoPath mPhotoPath = PhotoHelper.saveBitmapAsFile(mPhotoPath, bitmap); // add the file path of cropped image sendIntent.putExtra(Intent.EXTRA_TEXT, mPhotoPath); startActivity(sendIntent); // activity transition animation ActivityTransitionAnim.transition(PhotoSendActivity.this); } });
@Override public void onClick(View v) { Bundle b = new Bundle(); b.putParcelable("BookDetail", bookInfo); b.putString("bookId", bookInfo.getId()); Bitmap bitmap; GlideBitmapDrawable imageDrawable = (GlideBitmapDrawable) ((EBookListHolder) holder).iv_book_img.getDrawable(); if (imageDrawable != null) { bitmap = imageDrawable.getBitmap(); b.putParcelable("book_img", bitmap); } Intent intent = new Intent(mContext, EBookDetailActivity.class); intent.putExtras(b); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (BaseActivity.activity == null) { UIUtils.startActivity(intent); return; } ActivityOptionsCompat options = ActivityOptionsCompat. makeSceneTransitionAnimation(BaseActivity.activity, ((EBookListHolder) holder).iv_book_img, "book_img"); BaseActivity.activity.startActivity(intent, options.toBundle()); } else { UIUtils.startActivity(intent); } } });
return; Bitmap bitmap = glideBitmapDrawable.getBitmap(); if (bitmap == null) { return;
@Override public void onClick(View v) { Bundle b = new Bundle(); b.putSerializable(BookInfoResponse.serialVersionName, bookInfo); Bitmap bitmap; GlideBitmapDrawable imageDrawable = (GlideBitmapDrawable) ((BookListHolder) holder).iv_book_img.getDrawable(); if (imageDrawable != null) { bitmap = imageDrawable.getBitmap(); b.putParcelable("book_img", bitmap); } Intent intent = new Intent(UIUtils.getContext(), BookDetailActivity.class); intent.putExtras(b); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (BaseActivity.activity == null) { UIUtils.startActivity(intent); return; } ActivityOptionsCompat options = ActivityOptionsCompat. makeSceneTransitionAnimation(BaseActivity.activity, ((BookListHolder) holder).iv_book_img, "book_img"); BaseActivity.activity.startActivity(intent, options.toBundle()); } else { UIUtils.startActivity(intent); } } });
private void initEvent() { Glide.with(UIUtils.getContext()) .load(mBookInfoResponse.getImages().getLarge()) .into(iv_book_img); tv_title.setText(mBookInfoResponse.getTitle()); ratingBar_hots.setRating(Float.valueOf(mBookInfoResponse.getRating().getAverage()) / 2); tv_hots_num.setText(mBookInfoResponse.getRating().getAverage()); mContentView.setOnClickListener(v -> { Bundle b = new Bundle(); b.putSerializable(BookInfoResponse.serialVersionName, mBookInfoResponse); Bitmap bitmap; bitmap = ((GlideBitmapDrawable) (iv_book_img.getDrawable())).getBitmap(); b.putParcelable("book_img", bitmap); Intent intent = new Intent(UIUtils.getContext(), BookDetailActivity.class); intent.putExtras(b); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (BaseActivity.activity == null) { UIUtils.startActivity(intent); return; } ActivityOptionsCompat options = ActivityOptionsCompat. makeSceneTransitionAnimation(BaseActivity.activity, iv_book_img, "book_img"); BaseActivity.activity.startActivity(intent, options.toBundle()); } else { UIUtils.startActivity(intent); } }); }