Search in sources :

Example 1 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project LeafPic by HoraApps.

the class VideoFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    playVideoIcon.setOnClickListener(v -> {
        Uri uri = StorageHelper.getUriForFile(getContext(), media.getFile());
        Intent intent = new Intent(Intent.ACTION_VIEW).setDataAndType(uri, media.getMimeType());
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(intent);
    });
    // TODO: See where we can move this. Seems like boilerplate code that belongs in
    // a utility class or Builder of some sort.
    RequestOptions options = new RequestOptions().signature(media.getSignature()).centerCrop().diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);
    Glide.with(getContext()).load(media.getUri()).apply(options).into(previewView);
    setTapListener(previewView);
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) Intent(android.content.Intent) Uri(android.net.Uri)

Example 2 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project LeafPic by HoraApps.

the class MediaAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    Media f = media.get(position);
    // holder.path.setTag(f);
    holder.icon.setVisibility(View.GONE);
    holder.layout.setBackgroundColor(getThemeHelper().getPrimaryColor());
    holder.gifIcon.setVisibility(f.isGif() ? View.VISIBLE : View.GONE);
    RequestOptions options = new RequestOptions().signature(f.getSignature()).format(DecodeFormat.PREFER_RGB_565).centerCrop().placeholder(placeholder).diskCacheStrategy(DiskCacheStrategy.RESOURCE);
    Glide.with(holder.imageView.getContext()).load(f.getUri()).apply(options).thumbnail(0.5f).into(holder.imageView);
    if (f.isVideo()) {
        holder.icon.setVisibility(View.VISIBLE);
        holder.path.setVisibility(View.VISIBLE);
        holder.path.setText(f.getName());
        /*holder.path.setTextColor(ContextCompat.getColor(holder.path.getContext(), R.color.md_dark_primary_text));
            holder.path.setBackgroundColor(
                    ColorPalette.getTransparentColor(
                            ContextCompat.getColor(holder.path.getContext(), R.color.md_black_1000), 100));*/
        // ANIMS
        holder.icon.animate().alpha(1).setDuration(250);
        holder.path.animate().alpha(1).setDuration(250);
    } else {
        holder.icon.setVisibility(View.GONE);
        holder.path.setVisibility(View.GONE);
        holder.icon.animate().alpha(0).setDuration(250);
        holder.path.animate().alpha(0).setDuration(250);
    }
    if (f.isSelected()) {
        holder.icon.setIcon(CommunityMaterial.Icon.cmd_check);
        holder.icon.setVisibility(View.VISIBLE);
        holder.imageView.setColorFilter(0x88000000, PorterDuff.Mode.SRC_ATOP);
        holder.layout.setPadding(15, 15, 15, 15);
        // ANIMS
        holder.icon.animate().alpha(1).setDuration(250);
    } else {
        holder.imageView.clearColorFilter();
        holder.layout.setPadding(0, 0, 0, 0);
    }
    holder.layout.setOnClickListener(v -> {
        if (selecting()) {
            notifySelected(f.toggleSelected());
            notifyItemChanged(holder.getAdapterPosition());
        } else
            actionsListener.onItemSelected(holder.getAdapterPosition());
    });
    holder.layout.setOnLongClickListener(v -> {
        if (!selecting()) {
            // If it is the first long press
            notifySelected(f.toggleSelected());
            notifyItemChanged(holder.getAdapterPosition());
        } else {
            selectAllUpTo(f);
        }
        return true;
    });
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) Media(org.horaapps.leafpic.data.Media)

Example 3 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project RxTools by vondear.

the class ActivityRxPhoto method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch(requestCode) {
        case // 选择相册之后的处理
        RxPhotoTool.GET_IMAGE_FROM_PHONE:
            if (resultCode == RESULT_OK) {
                // RxPhotoTool.cropImage(ActivityUser.this, );// 裁剪图片
                initUCrop(data.getData());
            }
            break;
        case // 选择照相机之后的处理
        RxPhotoTool.GET_IMAGE_BY_CAMERA:
            if (resultCode == RESULT_OK) {
                /* data.getExtras().get("data");*/
                // RxPhotoTool.cropImage(ActivityUser.this, RxPhotoTool.imageUriFromCamera);// 裁剪图片
                initUCrop(RxPhotoTool.imageUriFromCamera);
            }
            break;
        case // 普通裁剪后的处理
        RxPhotoTool.CROP_IMAGE:
            RequestOptions options = new RequestOptions().placeholder(R.drawable.circle_elves_ball).error(R.drawable.circle_elves_ball).diskCacheStrategy(DiskCacheStrategy.RESOURCE);
            Glide.with(mContext).load(RxPhotoTool.cropImageUri).apply(options).thumbnail(0.5f).into(mIvAvatar);
            // RequestUpdateAvatar(new File(RxPhotoTool.getRealFilePath(mContext, RxPhotoTool.cropImageUri)));
            break;
        case // UCrop裁剪之后的处理
        UCrop.REQUEST_CROP:
            if (resultCode == RESULT_OK) {
                resultUri = UCrop.getOutput(data);
                roadImageView(resultUri, mIvAvatar);
                RxSPTool.putContent(mContext, "AVATAR", resultUri.toString());
            } else if (resultCode == UCrop.RESULT_ERROR) {
                final Throwable cropError = UCrop.getError(data);
            }
            break;
        case // UCrop裁剪错误之后的处理
        UCrop.RESULT_ERROR:
            final Throwable cropError = UCrop.getError(data);
            break;
        default:
            break;
    }
    super.onActivityResult(requestCode, resultCode, data);
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions)

Example 4 with RequestOptions

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

the class RequestBuilder method into.

/**
 * Sets the {@link ImageView} the resource will be loaded into, cancels any existing loads into
 * the view, and frees any resources Glide may have previously loaded into the view so they may be
 * reused.
 *
 * @see RequestManager#clear(Target)
 *
 * @param view The view to cancel previous loads for and load the new resource into.
 * @return The
 * {@link com.bumptech.glide.request.target.Target} used to wrap the given {@link ImageView}.
 */
public Target<TranscodeType> into(ImageView view) {
    Util.assertMainThread();
    Preconditions.checkNotNull(view);
    RequestOptions requestOptions = this.requestOptions;
    if (!requestOptions.isTransformationSet() && requestOptions.isTransformationAllowed() && view.getScaleType() != null) {
        // View's scale type.
        switch(view.getScaleType()) {
            case CENTER_CROP:
                requestOptions = requestOptions.clone().optionalCenterCrop();
                break;
            case CENTER_INSIDE:
                requestOptions = requestOptions.clone().optionalCenterInside();
                break;
            case FIT_CENTER:
            case FIT_START:
            case FIT_END:
                requestOptions = requestOptions.clone().optionalFitCenter();
                break;
            case FIT_XY:
                requestOptions = requestOptions.clone().optionalCenterInside();
                break;
            case CENTER:
            case MATRIX:
            default:
        }
    }
    return into(context.buildImageViewTarget(view, transcodeClass), requestOptions);
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions)

Example 5 with RequestOptions

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

the class RequestBuilder method buildRequestRecursive.

private Request buildRequestRecursive(Target<TranscodeType> target, @Nullable ThumbnailRequestCoordinator parentCoordinator, TransitionOptions<?, ? super TranscodeType> transitionOptions, Priority priority, int overrideWidth, int overrideHeight, RequestOptions requestOptions) {
    if (thumbnailBuilder != null) {
        // Recursive case: contains a potentially recursive thumbnail request builder.
        if (isThumbnailBuilt) {
            throw new IllegalStateException("You cannot use a request as both the main request and a " + "thumbnail, consider using clone() on the request(s) passed to thumbnail()");
        }
        TransitionOptions<?, ? super TranscodeType> thumbTransitionOptions = thumbnailBuilder.transitionOptions;
        // that may have been applied on the thumbnail request explicitly.
        if (thumbnailBuilder.isDefaultTransitionOptionsSet) {
            thumbTransitionOptions = transitionOptions;
        }
        Priority thumbPriority = thumbnailBuilder.requestOptions.isPrioritySet() ? thumbnailBuilder.requestOptions.getPriority() : getThumbnailPriority(priority);
        int thumbOverrideWidth = thumbnailBuilder.requestOptions.getOverrideWidth();
        int thumbOverrideHeight = thumbnailBuilder.requestOptions.getOverrideHeight();
        if (Util.isValidDimensions(overrideWidth, overrideHeight) && !thumbnailBuilder.requestOptions.isValidOverride()) {
            thumbOverrideWidth = requestOptions.getOverrideWidth();
            thumbOverrideHeight = requestOptions.getOverrideHeight();
        }
        ThumbnailRequestCoordinator coordinator = new ThumbnailRequestCoordinator(parentCoordinator);
        Request fullRequest = obtainRequest(target, requestOptions, coordinator, transitionOptions, priority, overrideWidth, overrideHeight);
        isThumbnailBuilt = true;
        // Recursively generate thumbnail requests.
        Request thumbRequest = thumbnailBuilder.buildRequestRecursive(target, coordinator, thumbTransitionOptions, thumbPriority, thumbOverrideWidth, thumbOverrideHeight, thumbnailBuilder.requestOptions);
        isThumbnailBuilt = false;
        coordinator.setRequests(fullRequest, thumbRequest);
        return coordinator;
    } else if (thumbSizeMultiplier != null) {
        // Base case: thumbnail multiplier generates a thumbnail request, but cannot recurse.
        ThumbnailRequestCoordinator coordinator = new ThumbnailRequestCoordinator(parentCoordinator);
        Request fullRequest = obtainRequest(target, requestOptions, coordinator, transitionOptions, priority, overrideWidth, overrideHeight);
        RequestOptions thumbnailOptions = requestOptions.clone().sizeMultiplier(thumbSizeMultiplier);
        Request thumbnailRequest = obtainRequest(target, thumbnailOptions, coordinator, transitionOptions, getThumbnailPriority(priority), overrideWidth, overrideHeight);
        coordinator.setRequests(fullRequest, thumbnailRequest);
        return coordinator;
    } else {
        // Base case: no thumbnail.
        return obtainRequest(target, requestOptions, parentCoordinator, transitionOptions, priority, overrideWidth, overrideHeight);
    }
}
Also used : ThumbnailRequestCoordinator(com.bumptech.glide.request.ThumbnailRequestCoordinator) RequestOptions(com.bumptech.glide.request.RequestOptions) Request(com.bumptech.glide.request.Request) SingleRequest(com.bumptech.glide.request.SingleRequest)

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