导航菜单

页面标题

页面副标题

Petal Maps v4.7.0.310001 - ThemeImageView.java 源代码

正在查看: Petal Maps v4.7.0.310001 应用的 ThemeImageView.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.huawei.phoneservice.faq.base.widget;

import android.R;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.PorterDuffXfermode;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.util.AttributeSet;
import androidx.annotation.ColorInt;
import androidx.annotation.Keep;
import androidx.appcompat.widget.AppCompatImageView;
import com.huawei.phoneservice.faq.base.R$color;
import com.huawei.phoneservice.faq.base.R$styleable;
import com.huawei.phoneservice.faq.base.util.FaqCommonUtils;
import com.huawei.phoneservice.faq.base.util.FaqLogger;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

@Keep
public class ThemeImageView extends AppCompatImageView {
    private static final Set<Integer> BLACK_SET = new HashSet();
    static final String TAG = "ThemeImageView";
    private int anInt;
    private Bitmap bitmap;
    private Integer integer;
    private Paint mClearPaint;
    private Bitmap normalBitmap;
    private Integer pressFilterColor;
    private int pressFilterColorId;
    private Bitmap pressedBitmap;

    public ThemeImageView(Context context) {
        super(context);
        this.integer = null;
        this.pressFilterColor = null;
    }

    public static Bitmap drawableToBitmap(Drawable drawable) {
        Bitmap bitmap = null;
        if (drawable == null) {
            return null;
        }
        try {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != -1 ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
            Canvas canvas = new Canvas(bitmap);
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            drawable.draw(canvas);
            return bitmap;
        } catch (IllegalArgumentException unused) {
            FaqLogger.w(TAG, "drawableToBitmap IllegalArgumentException");
            return bitmap;
        }
    }

    private boolean filter(Drawable drawable) {
        Set<Integer> set = BLACK_SET;
        synchronized (set) {
            try {
                if (!FaqCommonUtils.isEmpty(set) && drawable != null && drawable.getConstantState() != null) {
                    Iterator<Integer> it = set.iterator();
                    while (it.hasNext()) {
                        Drawable drawable2 = getResources().getDrawable(it.next().intValue());
                        if (drawable2 != null && drawable.getConstantState().equals(drawable2.getConstantState())) {
                            return false;
                        }
                    }
                    return true;
                }
                return true;
            } finally {
            }
        }
    }

    private Drawable getImageDrawable() throws IllegalArgumentException {
        Paint paint = new Paint(1);
        if (this.normalBitmap == null) {
            this.normalBitmap = Bitmap.createBitmap(this.bitmap.getWidth(), this.bitmap.getHeight(), this.bitmap.getConfig());
        }
        if (this.pressedBitmap == null) {
            this.pressedBitmap = Bitmap.createBitmap(this.bitmap.getWidth(), this.bitmap.getHeight(), this.bitmap.getConfig());
        }
        Canvas canvas = new Canvas(this.normalBitmap);
        paint.setColorFilter(getNormalFilter());
        canvas.drawPaint(this.mClearPaint);
        canvas.drawBitmap(this.bitmap, new Matrix(), paint);
        canvas.setBitmap(this.pressedBitmap);
        paint.setColorFilter(getPressedFilter());
        canvas.drawPaint(this.mClearPaint);
        canvas.drawBitmap(this.bitmap, new Matrix(), paint);
        if (isInEditMode()) {
            return setSelector(new BitmapDrawable((Resources) null, this.normalBitmap), new BitmapDrawable((Resources) null, this.pressedBitmap));
        }
        Resources resources = getResources();
        return setSelector(new BitmapDrawable(resources, this.normalBitmap), new BitmapDrawable(resources, this.pressedBitmap));
    }

    private void init(Context context, AttributeSet attributeSet) {
        int intValue;
        if (attributeSet != null) {
            TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R$styleable.ThemeImageView);
            this.anInt = obtainStyledAttributes.getResourceId(R$styleable.ThemeImageView_normal_color, R$color.faq_base_sdk_themeImageView_normal);
            this.pressFilterColorId = obtainStyledAttributes.getResourceId(R$styleable.ThemeImageView_pressed_color, 0);
            obtainStyledAttributes.recycle();
        }
        if (this.anInt != 0) {
            setInteger(getResources().getColor(this.anInt));
        }
        if (this.pressFilterColorId == 0) {
            if (this.integer != null) {
                intValue = (int) (r3.intValue() * 0.8d);
            }
            Paint paint = new Paint();
            this.mClearPaint = paint;
            paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
            updateDrawable();
        }
        intValue = getResources().getColor(this.pressFilterColorId);
        setPressFilterColor(intValue);
        Paint paint2 = new Paint();
        this.mClearPaint = paint2;
        paint2.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        updateDrawable();
    }

    public static StateListDrawable setSelector(Drawable drawable, Drawable drawable2) {
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(new int[]{R.attr.state_enabled, R.attr.state_pressed}, drawable2);
        stateListDrawable.addState(new int[0], drawable);
        return stateListDrawable;
    }

    public ColorFilter getNormalFilter() {
        Integer num = this.integer;
        return new PorterDuffColorFilter(num == null ? getResources().getColor(this.anInt) : num.intValue(), PorterDuff.Mode.SRC_IN);
    }

    public ColorFilter getPressedFilter() {
        Integer num = this.pressFilterColor;
        return new PorterDuffColorFilter(num == null ? getResources().getColor(this.pressFilterColorId) : num.intValue(), PorterDuff.Mode.SRC_IN);
    }

    public void setImageDrawable(Drawable drawable) {
        if (this.pressFilterColorId != 0 && drawable != null && drawable.getConstantState() != null && filter(drawable) && !(drawable instanceof StateListDrawable)) {
            try {
                Bitmap drawableToBitmap = drawableToBitmap(drawable);
                this.bitmap = drawableToBitmap;
                if (drawableToBitmap != null) {
                    drawable = getImageDrawable();
                }
            } catch (IllegalArgumentException e) {
                FaqLogger.e(TAG, e + "setImageDrawable error");
            }
        }
        super.setImageDrawable(drawable);
    }

    public void setImageResource(int i) {
        setImageDrawable(getResources().getDrawable(i));
    }

    public ThemeImageView setInteger(@ColorInt int i) {
        this.integer = Integer.valueOf(i);
        return this;
    }

    public ThemeImageView setPressFilterColor(@ColorInt int i) {
        this.pressFilterColor = Integer.valueOf(i);
        return this;
    }

    public void updateDrawable() {
        if (this.bitmap == null && getDrawable() != null) {
            this.bitmap = drawableToBitmap(getDrawable());
        }
        Bitmap bitmap = this.bitmap;
        if (bitmap == null || bitmap.isRecycled()) {
            return;
        }
        try {
            super.setImageDrawable(getImageDrawable());
        } catch (IllegalArgumentException e) {
            FaqLogger.e(TAG, e + "setImageDrawable error");
        }
    }

    public ThemeImageView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.integer = null;
        this.pressFilterColor = null;
        init(context, attributeSet);
    }

    public ThemeImageView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.integer = null;
        this.pressFilterColor = null;
        init(context, attributeSet);
    }
}