use of vip.kuaifan.weiui.extend.integration.glide.request.RequestOptions in project weiui by kuaifan.
the class RequestBuilder method buildThumbnailRequestRecursive.
private Request buildThumbnailRequestRecursive(Target<TranscodeType> target, RequestListener<TranscodeType> targetListener, @Nullable RequestCoordinator 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, targetListener, requestOptions, coordinator, transitionOptions, priority, overrideWidth, overrideHeight);
isThumbnailBuilt = true;
// Recursively generate thumbnail requests.
Request thumbRequest = thumbnailBuilder.buildRequestRecursive(target, targetListener, 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, targetListener, requestOptions, coordinator, transitionOptions, priority, overrideWidth, overrideHeight);
RequestOptions thumbnailOptions = requestOptions.clone().sizeMultiplier(thumbSizeMultiplier);
Request thumbnailRequest = obtainRequest(target, targetListener, thumbnailOptions, coordinator, transitionOptions, getThumbnailPriority(priority), overrideWidth, overrideHeight);
coordinator.setRequests(fullRequest, thumbnailRequest);
return coordinator;
} else {
// Base case: no thumbnail.
return obtainRequest(target, targetListener, requestOptions, parentCoordinator, transitionOptions, priority, overrideWidth, overrideHeight);
}
}
use of vip.kuaifan.weiui.extend.integration.glide.request.RequestOptions in project weiui by kuaifan.
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 vip.kuaifan.weiui.extend.integration.glide.request.target.Target} used to wrap the given {@link ImageView}.
*/
@NonNull
public ViewTarget<ImageView, TranscodeType> into(@NonNull 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(glideContext.buildImageViewTarget(view, transcodeClass), /*targetListener=*/
null, requestOptions);
}
use of vip.kuaifan.weiui.extend.integration.glide.request.RequestOptions in project weiui by kuaifan.
the class PictureImageGridAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
if (getItemViewType(position) == PictureConfig.TYPE_CAMERA) {
HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
headerHolder.headerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (imageSelectChangedListener != null) {
imageSelectChangedListener.onTakePhoto();
}
}
});
} else {
final ViewHolder contentHolder = (ViewHolder) holder;
final LocalMedia image = images.get(showCamera ? position - 1 : position);
image.position = contentHolder.getAdapterPosition();
final String path = image.getPath();
final String pictureType = image.getPictureType();
if (is_checked_num) {
notifyCheckChanged(contentHolder, image);
}
selectImage(contentHolder, isSelected(image), false);
final int mediaMimeType = PictureMimeType.isPictureType(pictureType);
boolean gif = PictureMimeType.isGif(pictureType);
contentHolder.tv_isGif.setVisibility(gif ? View.VISIBLE : View.GONE);
if (mimeType == PictureMimeType.ofAudio()) {
contentHolder.tv_duration.setVisibility(View.VISIBLE);
Drawable drawable = ContextCompat.getDrawable(context, R.drawable.picture_audio);
StringUtils.modifyTextViewDrawable(contentHolder.tv_duration, drawable, 0);
} else {
Drawable drawable = ContextCompat.getDrawable(context, R.drawable.video_icon);
StringUtils.modifyTextViewDrawable(contentHolder.tv_duration, drawable, 0);
contentHolder.tv_duration.setVisibility(mediaMimeType == PictureConfig.TYPE_VIDEO ? View.VISIBLE : View.GONE);
}
boolean eqLongImg = PictureMimeType.isLongImg(image);
contentHolder.tv_long_chart.setVisibility(eqLongImg ? View.VISIBLE : View.GONE);
long duration = image.getDuration();
contentHolder.tv_duration.setText(DateUtils.timeParse(duration));
if (mimeType == PictureMimeType.ofAudio()) {
contentHolder.iv_picture.setImageResource(R.drawable.audio_placeholder);
} else {
RequestOptions options = new RequestOptions();
if (overrideWidth <= 0 && overrideHeight <= 0) {
options.sizeMultiplier(sizeMultiplier);
} else {
options.override(overrideWidth, overrideHeight);
}
options.diskCacheStrategy(DiskCacheStrategy.ALL);
options.centerCrop();
options.placeholder(R.drawable.image_placeholder);
Glide.with(context).asBitmap().load(path).apply(options).into(contentHolder.iv_picture);
}
if (enablePreview || enablePreviewVideo || enablePreviewAudio) {
contentHolder.ll_check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 如原图路径不存在或者路径存在但文件不存在
if (!new File(path).exists()) {
Toast.makeText(context.getApplicationContext(), context.getString(R.string.picture_error), Toast.LENGTH_LONG).show();
return;
}
changeCheckboxState(contentHolder, image);
}
});
}
contentHolder.contentView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 如原图路径不存在或者路径存在但文件不存在
if (!new File(path).exists()) {
Toast.makeText(context.getApplicationContext(), context.getString(R.string.picture_error), Toast.LENGTH_LONG).show();
return;
}
int index = showCamera ? position - 1 : position;
boolean eqResult = mediaMimeType == PictureConfig.TYPE_IMAGE && enablePreview || mediaMimeType == PictureConfig.TYPE_VIDEO && (enablePreviewVideo || selectMode == PictureConfig.SINGLE) || mediaMimeType == PictureConfig.TYPE_AUDIO && (enablePreviewAudio || selectMode == PictureConfig.SINGLE);
if (eqResult) {
imageSelectChangedListener.onPictureClick(image, index);
} else {
changeCheckboxState(contentHolder, image);
}
}
});
}
}
use of vip.kuaifan.weiui.extend.integration.glide.request.RequestOptions in project weiui by kuaifan.
the class PicturePhotoGalleryAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
String path = "";
CutInfo photoInfo = list.get(position);
if (photoInfo != null) {
path = photoInfo.getPath();
}
if (photoInfo.isCut()) {
holder.iv_dot.setVisibility(View.VISIBLE);
holder.iv_dot.setImageResource(R.drawable.ucrop_oval_true);
} else {
holder.iv_dot.setVisibility(View.GONE);
}
RequestOptions options = new RequestOptions().placeholder(R.color.ucrop_color_grey).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL);
Glide.with(context).load(path).transition(DrawableTransitionOptions.withCrossFade()).apply(options).into(holder.mIvPhoto);
}
use of vip.kuaifan.weiui.extend.integration.glide.request.RequestOptions in project weiui by kuaifan.
the class weiuiAdDialog method create.
/**
************************************************************************************************
*/
/**
************************************************************************************************
*/
/**
************************************************************************************************
*/
public static void create(WXSDKInstance mWXSDKInstance, JSONObject json, JSCallback callback) {
if (mWXSDKInstance == null || json == null) {
return;
}
String imgUrl = weiuiParse.parseStr(json.getString("imgUrl"), json.getString("img"));
if (imgUrl == null || imgUrl.isEmpty()) {
return;
}
Context mContext = mWXSDKInstance.getContext();
if (mContext == null) {
return;
}
String dialogName = weiuiParse.parseStr(json.getString("dialogName"), weiuiCommon.randomString(8));
int dialogWidth = weiuiParse.parseInt(json.getString("width"));
int dialogHeight = weiuiParse.parseInt(json.getString("height"));
boolean showClose = weiuiParse.parseBool(json.getString("showClose"), true);
boolean backClose = weiuiParse.parseBool(json.getString("backClose"), true);
//
if (callback != null) {
Map<String, Object> newData = new HashMap<>();
newData.put("status", "load");
newData.put("dialogName", dialogName);
newData.put("imgUrl", imgUrl);
callback.invokeAndKeepAlive(newData);
}
Glide.with(mContext).asBitmap().load(imgUrl).apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL)).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
PageActivity.startTransparentPage(mContext, new JSCallback() {
@Override
public void invoke(Object data) {
if (callback != null) {
callback.invoke(data);
}
}
@Override
public void invokeAndKeepAlive(Object data) {
Map<String, Object> retData = weiuiMap.objectToMap(data);
String pageName = weiuiParse.parseStr(retData.get("pageName"));
String status = weiuiParse.parseStr(retData.get("status"));
PageBean mBean = weiuiPage.getPageBean(pageName);
if (mBean == null) {
return;
}
if (status.equals("create")) {
Activity mActivity = (Activity) mBean.getContext();
Animation mAnimation = AnimationUtils.loadAnimation(mActivity, R.anim.in_to_down);
//
View tmpView = LayoutInflater.from(mActivity).inflate(R.layout.dialog_ad, null);
ImageView tmpImage = tmpView.findViewById(R.id.v_activity_picture);
ImageView tmpClose = tmpView.findViewById(R.id.v_activity_close);
ViewGroup fullBox = tmpView.findViewById(R.id.float_full_box);
//
if (callback != null) {
tmpImage.setOnClickListener(view -> {
Map<String, Object> newData = (Map<String, Object>) data;
newData.put("status", "click");
newData.put("dialogName", dialogName);
newData.put("imgUrl", imgUrl);
callback.invokeAndKeepAlive(newData);
});
}
if (showClose) {
tmpClose.setVisibility(View.VISIBLE);
tmpClose.setOnClickListener(view -> close(dialogName));
}
if (mActivity instanceof PageActivity) {
((PageActivity) mActivity).setOnBackPressed(() -> !backClose || close(dialogName));
}
//
DialogBean tmpBean = new DialogBean();
tmpBean.setDialogName(dialogName);
tmpBean.setImgUrl(imgUrl);
tmpBean.setPageName(mBean.getPageName());
tmpBean.setContext(mBean.getContext());
tmpBean.setView(tmpView);
mAdDialogList.add(tmpBean);
//
ViewGroup.LayoutParams params = tmpImage.getLayoutParams();
if (dialogWidth > 0 && dialogHeight > 0) {
params.width = weiuiScreenUtils.weexPx2dp(mWXSDKInstance, dialogWidth);
params.height = weiuiScreenUtils.weexPx2dp(mWXSDKInstance, dialogHeight);
} else if (dialogWidth > 0) {
params.width = weiuiScreenUtils.weexPx2dp(mWXSDKInstance, dialogWidth);
params.height = (int) weiuiCommon.scaleHeight(params.width, resource.getWidth(), resource.getHeight());
} else if (dialogHeight > 0) {
params.height = weiuiScreenUtils.weexPx2dp(mWXSDKInstance, dialogHeight);
params.width = (int) weiuiCommon.scaleWidth(params.height, resource.getWidth(), resource.getHeight());
} else {
params.width = (int) (ScreenUtils.getScreenWidth() * 0.75);
params.height = (int) weiuiCommon.scaleHeight(params.width, resource.getWidth(), resource.getHeight());
}
tmpImage.setLayoutParams(params);
tmpImage.setImageBitmap(resource);
fullBox.startAnimation(mAnimation);
//
if (callback != null) {
Map<String, Object> newData = (Map<String, Object>) data;
newData.put("status", "show");
newData.put("dialogName", dialogName);
newData.put("imgUrl", imgUrl);
callback.invokeAndKeepAlive(newData);
}
//
((FrameLayout) mActivity.findViewById(R.id.v_body)).addView(tmpView);
}
if (callback != null) {
if (data instanceof Map) {
Map<String, Object> newData = (Map<String, Object>) data;
newData.put("dialogName", dialogName);
newData.put("imgUrl", imgUrl);
callback.invokeAndKeepAlive(newData);
} else {
callback.invokeAndKeepAlive(data);
}
}
}
});
}
});
}
Aggregations