|
@@ -1,224 +0,0 @@
|
|
|
-/*
|
|
|
- * Copyright (ConfigColor) 2016 CaMnter yuanyu.camnter@gmail.com
|
|
|
- *
|
|
|
- * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
- * you may not use this file except in compliance with the License.
|
|
|
- * You may obtain a copy of the License at
|
|
|
- *
|
|
|
- * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
- *
|
|
|
- * Unless required by applicable law or agreed to in writing, software
|
|
|
- * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
- * See the License for the specific language governing permissions and
|
|
|
- * limitations under the License.
|
|
|
- */
|
|
|
-
|
|
|
-package com.ysnows.base.utils.glide;
|
|
|
-
|
|
|
-import android.content.Context;
|
|
|
-import android.text.TextUtils;
|
|
|
-import android.widget.ImageView;
|
|
|
-
|
|
|
-import com.bumptech.glide.Glide;
|
|
|
-import com.bumptech.glide.Priority;
|
|
|
-import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|
|
-import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
|
|
-import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
|
|
|
-import com.bumptech.glide.request.RequestOptions;
|
|
|
-import com.ysnows.base.R;
|
|
|
-import com.ysnows.base.utils.UiUtils;
|
|
|
-
|
|
|
-/**
|
|
|
- * Description:GlideUtils
|
|
|
- * Created by:CaMnter
|
|
|
- * Time:2016-01-04 22:19
|
|
|
- */
|
|
|
-public class GlideUtils {
|
|
|
-
|
|
|
-
|
|
|
- private static final String TAG = "GlideUtils";
|
|
|
-
|
|
|
-
|
|
|
- public static RequestOptions picOptionsto = new RequestOptions()
|
|
|
-
|
|
|
- .diskCacheStrategy(DiskCacheStrategy.ALL);
|
|
|
-
|
|
|
-
|
|
|
- public static RequestOptions getoptions(Context context) {
|
|
|
- RequestOptions options = new RequestOptions()
|
|
|
- .centerCrop()
|
|
|
- .transform(new GlideCircleTransform(context))
|
|
|
- .skipMemoryCache(true)
|
|
|
- .dontAnimate()
|
|
|
- .circleCrop()
|
|
|
- .override(100, 100)
|
|
|
- .diskCacheStrategy(DiskCacheStrategy.ALL);
|
|
|
- return options;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public static void lImg(Context context, String url, ImageView imageView, boolean isCircle, boolean hasPlaceHolder) {
|
|
|
-
|
|
|
- if (!TextUtils.isEmpty(url)) {
|
|
|
- if (context != null) {
|
|
|
-
|
|
|
- Glide.with(context)
|
|
|
- .load(url)
|
|
|
- //这个是设置渐显的效果
|
|
|
- .transition(new DrawableTransitionOptions().crossFade(150))//渐显效果
|
|
|
- .apply(getoptions(context))
|
|
|
- .into(imageView);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //是否是圆,不是圆,大小没有限定
|
|
|
- public static void lImg(Context context, String url, ImageView imageView, boolean isCircle) {
|
|
|
-
|
|
|
- if (!TextUtils.isEmpty(url)) {
|
|
|
- if (context != null) {
|
|
|
- RequestOptions CirmyOptions;
|
|
|
-
|
|
|
- if (isCircle) {//圆形图片
|
|
|
- CirmyOptions = new RequestOptions()
|
|
|
- .centerCrop()
|
|
|
- .circleCrop()
|
|
|
- .skipMemoryCache(true)
|
|
|
- .placeholder(R.drawable.ic_default_avatar)
|
|
|
- .diskCacheStrategy(DiskCacheStrategy.ALL)
|
|
|
- .skipMemoryCache(true);
|
|
|
- } else {
|
|
|
- CirmyOptions = new RequestOptions()
|
|
|
- .diskCacheStrategy(DiskCacheStrategy.ALL)
|
|
|
- .skipMemoryCache(true)
|
|
|
- .placeholder(R.drawable.bg_need_error)
|
|
|
- .centerCrop()
|
|
|
- .error(R.drawable.bg_need_error)
|
|
|
- .skipMemoryCache(true);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- Glide.with(context)
|
|
|
- .load(getRealImg(url))
|
|
|
- //这个是设置渐显的效果
|
|
|
- .transition(new DrawableTransitionOptions().crossFade(150))//渐显效果
|
|
|
- .apply(CirmyOptions)
|
|
|
- .into(imageView);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static String getRealImg(String url) {
|
|
|
- //&& !url.contains(".gif")
|
|
|
- if (!url.contains("http") && !url.contains("https")) {
|
|
|
- return url;
|
|
|
- } else if (url.contains("x-oss-process=image")) {
|
|
|
- return url + "/format,webp/quality,Q_75";
|
|
|
- } else {
|
|
|
- return url + "?x-oss-process=image/format,webp/quality,Q_75";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public static RequestOptions baseOptions() {
|
|
|
-
|
|
|
- return new RequestOptions()
|
|
|
- .skipMemoryCache(true)
|
|
|
- .error(R.drawable.bg_need_error)
|
|
|
- .placeholder(R.drawable.bg_need_error)
|
|
|
- .diskCacheStrategy(DiskCacheStrategy.ALL);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public static RequestOptions baseOptionsNormal() {
|
|
|
-
|
|
|
- return new RequestOptions()
|
|
|
- .skipMemoryCache(true)
|
|
|
- .error(R.drawable.bg_need_error)
|
|
|
- .placeholder(R.drawable.bg_need_error)
|
|
|
- .diskCacheStrategy(DiskCacheStrategy.ALL);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public static RequestOptions myOption = new RequestOptions()
|
|
|
- .centerInside()
|
|
|
- .diskCacheStrategy(DiskCacheStrategy.ALL);
|
|
|
-
|
|
|
- //不是圆,没有限定大小
|
|
|
- public static void lImg(Context context, String url, ImageView imageVie) {
|
|
|
- Glide.with(context)
|
|
|
- .load(url)
|
|
|
- .apply(myOption)
|
|
|
- .into(imageVie);
|
|
|
- }
|
|
|
-
|
|
|
- private static RequestOptions myOptionto = new RequestOptions()
|
|
|
- .centerCrop()
|
|
|
- .diskCacheStrategy(DiskCacheStrategy.ALL)
|
|
|
- .error(R.drawable.bg_need_error)
|
|
|
- .skipMemoryCache(true);
|
|
|
-
|
|
|
- //不是圆,没有限定大小
|
|
|
- public static void lImgTo(Context context, String url, ImageView imageVie) {
|
|
|
- Glide.with(context)
|
|
|
- .load(url)
|
|
|
- .apply(myOptionto)
|
|
|
- .transition(new DrawableTransitionOptions().crossFade(150))//渐显效果
|
|
|
- .into(imageVie);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public static RequestOptions fixedOptions = new RequestOptions()
|
|
|
- .override(200, 200)
|
|
|
- .placeholder(R.drawable.bg_need_error)
|
|
|
- .error(R.drawable.bg_need_error)
|
|
|
- .diskCacheStrategy(DiskCacheStrategy.ALL);
|
|
|
-
|
|
|
-
|
|
|
- public static void fixedLimgN(Context context, String url, ImageView imageView) {
|
|
|
- Glide.with(context)
|
|
|
- .load(url)
|
|
|
- .apply(fixedOptions)
|
|
|
- .into(imageView);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public static RequestOptions myOptionAdapter4 = new RequestOptions()
|
|
|
- .diskCacheStrategy(DiskCacheStrategy.ALL)
|
|
|
- .skipMemoryCache(true)
|
|
|
- .priority(Priority.HIGH)
|
|
|
- .error(R.drawable.bg_need_error);
|
|
|
-
|
|
|
-
|
|
|
- //给定角度 大小没有限制
|
|
|
- public static void lImgRound(Context context, String url, ImageView imageView, int radius) {
|
|
|
- if (!TextUtils.isEmpty(url)) {
|
|
|
- if (context != null) {
|
|
|
-
|
|
|
- //设置图片圆角角度
|
|
|
- RoundedCorners roundedCorners = new RoundedCorners(UiUtils.dp2px(context, radius));
|
|
|
-
|
|
|
- RequestOptions myOptions = new RequestOptions()
|
|
|
- .centerCrop()
|
|
|
- .bitmapTransform(roundedCorners)
|
|
|
- .placeholder(R.drawable.bg_need_error)
|
|
|
- .diskCacheStrategy(DiskCacheStrategy.ALL)
|
|
|
- .error(R.drawable.bg_need_error);
|
|
|
-
|
|
|
-
|
|
|
- Glide.with(context)
|
|
|
- .load(url)
|
|
|
- .apply(myOptions)
|
|
|
- .into(imageView);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|