Search in sources :

Example 1 with BitmapImageViewTarget

use of com.bumptech.glide.request.target.BitmapImageViewTarget in project GestureViews by alexvasilkov.

the class GlideHelper method loadResource.

public static void loadResource(@DrawableRes int drawableId, @NonNull ImageView image) {
    DisplayMetrics metrics = image.getResources().getDisplayMetrics();
    final int displayWidth = metrics.widthPixels;
    final int displayHeight = metrics.heightPixels;
    Glide.with(image.getContext()).load(drawableId).asBitmap().dontAnimate().diskCacheStrategy(DiskCacheStrategy.NONE).into(new BitmapImageViewTarget(image) {

        @Override
        public void getSize(final SizeReadyCallback cb) {
            // We don't want to load very big images on devices with small screens.
            // This will help Glide correctly choose images scale when reading them.
            super.getSize(new SizeReadyCallback() {

                @Override
                public void onSizeReady(int width, int height) {
                    cb.onSizeReady(displayWidth / 2, displayHeight / 2);
                }
            });
        }
    });
}
Also used : BitmapImageViewTarget(com.bumptech.glide.request.target.BitmapImageViewTarget) SizeReadyCallback(com.bumptech.glide.request.target.SizeReadyCallback) DisplayMetrics(android.util.DisplayMetrics)

Example 2 with BitmapImageViewTarget

use of com.bumptech.glide.request.target.BitmapImageViewTarget in project android by nextcloud.

the class AvatarGroupLayout method showFederatedShareAvatar.

private void showFederatedShareAvatar(Context context, String user, float avatarRadius, Resources resources, ImageView avatar) {
    // maybe federated share
    String[] split = user.split("@");
    String userId = split[0];
    String server = split[1];
    String url = "https://" + server + "/index.php/avatar/" + userId + "/" + resources.getInteger(R.integer.file_avatar_px);
    Drawable placeholder;
    try {
        placeholder = TextDrawable.createAvatarByUserId(userId, avatarRadius);
    } catch (Exception e) {
        Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
        placeholder = ThemeDrawableUtils.tintDrawable(ResourcesCompat.getDrawable(resources, R.drawable.account_circle_white, null), R.color.black);
    }
    avatar.setTag(null);
    Glide.with(context).load(url).asBitmap().placeholder(placeholder).error(placeholder).into(new BitmapImageViewTarget(avatar) {

        @Override
        protected void setResource(Bitmap resource) {
            RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(resources, resource);
            circularBitmapDrawable.setCircular(true);
            avatar.setImageDrawable(circularBitmapDrawable);
        }
    });
}
Also used : RoundedBitmapDrawable(androidx.core.graphics.drawable.RoundedBitmapDrawable) Bitmap(android.graphics.Bitmap) BitmapImageViewTarget(com.bumptech.glide.request.target.BitmapImageViewTarget) Drawable(android.graphics.drawable.Drawable) RoundedBitmapDrawable(androidx.core.graphics.drawable.RoundedBitmapDrawable)

Example 3 with BitmapImageViewTarget

use of com.bumptech.glide.request.target.BitmapImageViewTarget in project MovieGuide by esoxjem.

the class MoviesListingAdapter method onBindViewHolder.

@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));
        }
    });
}
Also used : Context(android.content.Context) Api(com.esoxjem.movieguide.Api) RequestOptions(com.bumptech.glide.request.RequestOptions) ButterKnife(butterknife.ButterKnife) LayoutInflater(android.view.LayoutInflater) ImageView(android.widget.ImageView) BitmapImageViewTarget(com.bumptech.glide.request.target.BitmapImageViewTarget) ViewGroup(android.view.ViewGroup) BindView(butterknife.BindView) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Glide(com.bumptech.glide.Glide) Priority(com.bumptech.glide.Priority) Bitmap(android.graphics.Bitmap) Transition(com.bumptech.glide.request.transition.Transition) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) R(com.esoxjem.movieguide.R) Palette(androidx.palette.graphics.Palette) Movie(com.esoxjem.movieguide.Movie) Bitmap(android.graphics.Bitmap) BitmapImageViewTarget(com.bumptech.glide.request.target.BitmapImageViewTarget) RequestOptions(com.bumptech.glide.request.RequestOptions)

Example 4 with BitmapImageViewTarget

use of com.bumptech.glide.request.target.BitmapImageViewTarget in project JustAndroid by chinaltz.

the class PictureAlbumDirectoryAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    final LocalMediaFolder folder = folders.get(position);
    String name = folder.getName();
    int imageNum = folder.getImageNum();
    String imagePath = folder.getFirstImagePath();
    boolean isChecked = folder.isChecked();
    int checkedNum = folder.getCheckedNum();
    holder.tv_sign.setVisibility(checkedNum > 0 ? View.VISIBLE : View.INVISIBLE);
    holder.itemView.setSelected(isChecked);
    Glide.with(holder.itemView.getContext()).load(imagePath).asBitmap().error(R.drawable.ic_placeholder).centerCrop().override(150, 150).diskCacheStrategy(DiskCacheStrategy.RESULT).into(new BitmapImageViewTarget(holder.first_image) {

        @Override
        protected void setResource(Bitmap resource) {
            RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), resource);
            circularBitmapDrawable.setCornerRadius(8);
            holder.first_image.setImageDrawable(circularBitmapDrawable);
        }
    });
    holder.image_num.setText("(" + imageNum + ")");
    holder.tv_folder_name.setText(name);
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (onItemClickListener != null)
                for (LocalMediaFolder mediaFolder : folders) {
                    mediaFolder.setChecked(false);
                }
            folder.setChecked(true);
            notifyDataSetChanged();
            onItemClickListener.onItemClick(folder.getName(), folder.getImages());
        }
    });
}
Also used : RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) LocalMediaFolder(com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMediaFolder) Bitmap(android.graphics.Bitmap) BitmapImageViewTarget(com.bumptech.glide.request.target.BitmapImageViewTarget) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 5 with BitmapImageViewTarget

use of com.bumptech.glide.request.target.BitmapImageViewTarget in project iosched by google.

the class MyIODialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getContext();
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    boolean signedIn = AccountUtils.hasActiveAccount(context);
    if (signedIn) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View titleView = inflater.inflate(R.layout.myio_auth_dialog_signedin_title, null);
        TextView name = (TextView) titleView.findViewById(R.id.name);
        TextView email = (TextView) titleView.findViewById(R.id.email);
        final ImageView avatar = (ImageView) titleView.findViewById(R.id.avatar);
        name.setText(AccountUtils.getActiveAccountDisplayName(context));
        email.setText(AccountUtils.getActiveAccountName(context));
        // Note: this may be null if the user has not set up a profile photo.
        Uri url = AccountUtils.getActiveAccountPhotoUrl(context);
        if (url != null) {
            Glide.with(context).load(url.toString()).asBitmap().fitCenter().placeholder(R.drawable.ic_default_avatar).into(new BitmapImageViewTarget(avatar) {

                @Override
                protected void setResource(Bitmap resource) {
                    RoundedBitmapDrawable roundedBmp = RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                    roundedBmp.setCircular(true);
                    avatar.setImageDrawable(roundedBmp);
                }
            });
        }
        builder.setCustomTitle(titleView);
        builder.setMessage(buildDialogText(context, R.string.my_io_body_intro_signed_in, R.string.my_io_dialog_first_bullet_point_signed_in, R.string.my_io_dialog_second_bullet_point_signed_in, R.string.my_io_dialog_third_bullet_point_signed_in, Color.BLACK));
    } else {
        builder.setMessage(buildDialogText(getContext(), R.string.my_io_body_intro_signed_out, R.string.my_io_dialog_first_bullet_point_signed_out, R.string.my_io_dialog_second_bullet_point_signed_out, R.string.my_io_dialog_third_bullet_point_signed_out, Color.BLACK));
    }
    builder.setPositiveButton(signedIn ? R.string.signout_prompt : R.string.signin_prompt, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            MyIOActivity myIOActivity = ((MyIOActivity) getActivity());
            if (AccountUtils.hasActiveAccount(myIOActivity)) {
                myIOActivity.signOut();
            } else {
                myIOActivity.signIn();
            }
            dismiss();
        }
    });
    return builder.create();
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) BitmapImageViewTarget(com.bumptech.glide.request.target.BitmapImageViewTarget) DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Uri(android.net.Uri) Bitmap(android.graphics.Bitmap) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.content.DialogInterface.OnClickListener) TextView(android.widget.TextView) ImageView(android.widget.ImageView) NonNull(android.support.annotation.NonNull)

Aggregations

BitmapImageViewTarget (com.bumptech.glide.request.target.BitmapImageViewTarget)5 Bitmap (android.graphics.Bitmap)4 View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 Context (android.content.Context)2 RoundedBitmapDrawable (android.support.v4.graphics.drawable.RoundedBitmapDrawable)2 LayoutInflater (android.view.LayoutInflater)2 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 NonNull (android.support.annotation.NonNull)1 AlertDialog (android.support.v7.app.AlertDialog)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 DisplayMetrics (android.util.DisplayMetrics)1 ViewGroup (android.view.ViewGroup)1 Nullable (androidx.annotation.Nullable)1 RoundedBitmapDrawable (androidx.core.graphics.drawable.RoundedBitmapDrawable)1