mac
2024-03-25 a67980d23f9e2d27345fd12e7a889f4cc52695f7
app/src/main/java/com/hdl/photovoltaic/utils/GlideUtils.java
@@ -9,6 +9,7 @@
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.text.TextUtils;
import android.widget.ImageView;
import androidx.annotation.Nullable;
@@ -28,6 +29,7 @@
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.other.HdlLogLogic;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import java.io.InputStream;
@@ -46,9 +48,12 @@
     * @param imageview 显示图片组件
     */
    public static void getGeneralImage(Context context, String url, ImageView imageview) {
        if (TextUtils.isEmpty(url) || !url.startsWith("http://")) {
            return;
        }
        Glide.with(context)
                .load(url)
                .apply(getRequestOptions())
                .apply(getRequestOptions(false))
                .into(imageview);
    }
@@ -61,9 +66,12 @@
     * @param granularRoundedCorners 设置图片角度
     */
    public static void getGranularRoundedCornersImage(Context context, String url, ImageView imageview, GranularRoundedCorners granularRoundedCorners) {
        if (TextUtils.isEmpty(url) || !url.startsWith("http://")) {
            return;
        }
        Glide.with(context)
                .load(url)
                .apply(getRequestOptions())
                .apply(getRequestOptions(false))
                .transform(granularRoundedCorners)//new GranularRoundedCorners(30f,80f,80f,30f)
                .into(imageview);
    }
@@ -76,10 +84,13 @@
     * @param imageview      显示图片组件
     * @param roundedCorners 设置图片角度值
     */
    public static void getRoundedCornersImage(Context context, String url, ImageView imageview, RoundedCorners roundedCorners) {
    public static void getRoundedCornersImage(Context context, String url, ImageView imageview, RoundedCorners roundedCorners, boolean userImage) {
        if (TextUtils.isEmpty(url) || !url.startsWith("http://")) {
            return;
        }
        Glide.with(context)
                .load(url)
                .apply(getRequestOptions())
                .apply(getRequestOptions(userImage))
                .transform(new CenterCrop(), roundedCorners)//Glide加载图片圆角效果与ImageView的ScaleType冲突问题
//                .transform(roundedCorners)
                .into(imageview);
@@ -92,21 +103,31 @@
     * @param url       图片地址
     * @param imageview 显示图片组件
     */
    public static void getCircleCropImage(Context context, String url, ImageView imageview) {
    public static void getCircleCropImage(Context context, String url, ImageView imageview, boolean userImage) {
        if (TextUtils.isEmpty(url) || !url.startsWith("http://")) {
            return;
        }
        Glide.with(context)
                .load(url)
                .apply(getRequestOptions())
                .apply(getRequestOptions(userImage))
                .transform(new CircleCrop())
                .into(imageview);
    }
    private static RequestOptions getRequestOptions() {
        return new RequestOptions()
                .placeholder(R.drawable.default_user)
                .error(R.drawable.default_user)
                .fallback(R.drawable.default_user);
    private static RequestOptions getRequestOptions(boolean userImage) {
        if (userImage) {
            return new RequestOptions()
                    .placeholder(R.drawable.default_image)
                    .error(R.drawable.default_image)
                    .fallback(R.drawable.default_image);
        } else {
            return new RequestOptions()
                    .placeholder(R.drawable.default_user)
                    .error(R.drawable.default_user)
                    .fallback(R.drawable.default_user);
//                .override(113, 130);
        }
    }