package X6FRs_4.IMuAHx_6.WwEq_13;

import X6FRs_4.IMuAHx_6.Nm6q_10.PGPF6hQ_2;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.icu.text.DecimalFormatSymbols;
import android.os.Build;
import android.text.Editable;
import android.text.TextDirectionHeuristic;
import android.text.TextDirectionHeuristics;
import android.text.TextPaint;
import android.text.method.PasswordTransformationMethod;
import android.util.Log;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
/* compiled from: TextViewCompat.java */
/* loaded from: classes.dex */
public final class Xgtqvk_8 {
    public static Field KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public static boolean f507KQgRr5e_0;
    public static Field QxJ9d_1;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public static boolean f508QxJ9d_1;

    public static Field KQgRr5e_0(String str) {
        Field field = null;
        try {
            field = TextView.class.getDeclaredField(str);
            field.setAccessible(true);
            return field;
        } catch (NoSuchFieldException unused) {
            Log.e("TextViewCompat", "Could not retrieve " + str + " field.");
            return field;
        }
    }

    public static void Mqv2r_3(TextView textView, int i) {
        if (Build.VERSION.SDK_INT >= 23) {
            textView.setTextAppearance(i);
        } else {
            textView.setTextAppearance(textView.getContext(), i);
        }
    }

    public static int PGPF6hQ_2(TextView textView) {
        if (Build.VERSION.SDK_INT >= 16) {
            return textView.getMaxLines();
        }
        if (!f508QxJ9d_1) {
            QxJ9d_1 = KQgRr5e_0("mMaxMode");
            f508QxJ9d_1 = true;
        }
        Field field = QxJ9d_1;
        if (field == null || KQgRr5e_0(field, textView) != 1) {
            return -1;
        }
        if (!f507KQgRr5e_0) {
            KQgRr5e_0 = KQgRr5e_0("mMaximum");
            f507KQgRr5e_0 = true;
        }
        Field field2 = KQgRr5e_0;
        if (field2 != null) {
            return KQgRr5e_0(field2, textView);
        }
        return -1;
    }

    public static void QxJ9d_1(TextView textView, int i) {
        int i2;
        X6FRs_4.IMuAHx_6.KNBe_11.FSaI4_7.KQgRr5e_0(i);
        Paint.FontMetricsInt fontMetricsInt = textView.getPaint().getFontMetricsInt();
        if (Build.VERSION.SDK_INT >= 16 && !textView.getIncludeFontPadding()) {
            i2 = fontMetricsInt.descent;
        } else {
            i2 = fontMetricsInt.bottom;
        }
        if (i > Math.abs(i2)) {
            textView.setPadding(textView.getPaddingLeft(), textView.getPaddingTop(), textView.getPaddingRight(), i - i2);
        }
    }

    public static int KQgRr5e_0(Field field, TextView textView) {
        try {
            return field.getInt(textView);
        } catch (IllegalAccessException unused) {
            Log.d("TextViewCompat", "Could not retrieve value of " + field.getName() + " field.");
            return -1;
        }
    }

    public static void KQgRr5e_0(TextView textView, Drawable drawable, Drawable drawable2, Drawable drawable3, Drawable drawable4) {
        int i = Build.VERSION.SDK_INT;
        if (i >= 18) {
            textView.setCompoundDrawablesRelative(drawable, drawable2, drawable3, drawable4);
        } else if (i >= 17) {
            boolean z = textView.getLayoutDirection() == 1;
            Drawable drawable5 = z ? drawable3 : drawable;
            if (!z) {
                drawable = drawable3;
            }
            textView.setCompoundDrawables(drawable5, drawable2, drawable, drawable4);
        } else {
            textView.setCompoundDrawables(drawable, drawable2, drawable3, drawable4);
        }
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public static Drawable[] m330KQgRr5e_0(TextView textView) {
        int i = Build.VERSION.SDK_INT;
        if (i >= 18) {
            return textView.getCompoundDrawablesRelative();
        }
        if (i >= 17) {
            boolean z = textView.getLayoutDirection() == 1;
            Drawable[] compoundDrawables = textView.getCompoundDrawables();
            if (z) {
                Drawable drawable = compoundDrawables[2];
                Drawable drawable2 = compoundDrawables[0];
                compoundDrawables[0] = drawable;
                compoundDrawables[2] = drawable2;
            }
            return compoundDrawables;
        }
        return textView.getCompoundDrawables();
    }

    public static int QxJ9d_1(TextView textView) {
        return textView.getPaddingBottom() + textView.getPaint().getFontMetricsInt().bottom;
    }

    public static void PGPF6hQ_2(TextView textView, int i) {
        X6FRs_4.IMuAHx_6.KNBe_11.FSaI4_7.KQgRr5e_0(i);
        int fontMetricsInt = textView.getPaint().getFontMetricsInt(null);
        if (i != fontMetricsInt) {
            textView.setLineSpacing(i - fontMetricsInt, 1.0f);
        }
    }

    public static ActionMode.Callback KQgRr5e_0(TextView textView, ActionMode.Callback callback) {
        int i = Build.VERSION.SDK_INT;
        return (i < 26 || i > 27 || (callback instanceof KQgRr5e_0)) ? callback : new KQgRr5e_0(callback, textView);
    }

    public static void KQgRr5e_0(TextView textView, int i) {
        int i2;
        X6FRs_4.IMuAHx_6.KNBe_11.FSaI4_7.KQgRr5e_0(i);
        if (Build.VERSION.SDK_INT >= 28) {
            textView.setFirstBaselineToTopHeight(i);
            return;
        }
        Paint.FontMetricsInt fontMetricsInt = textView.getPaint().getFontMetricsInt();
        if (Build.VERSION.SDK_INT >= 16 && !textView.getIncludeFontPadding()) {
            i2 = fontMetricsInt.ascent;
        } else {
            i2 = fontMetricsInt.top;
        }
        if (i > Math.abs(i2)) {
            textView.setPadding(textView.getPaddingLeft(), i - (-i2), textView.getPaddingRight(), textView.getPaddingBottom());
        }
    }

    /* compiled from: TextViewCompat.java */
    /* loaded from: classes.dex */
    public static class KQgRr5e_0 implements ActionMode.Callback {
        public final ActionMode.Callback KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public final TextView f509KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public Class f510KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public Method f511KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public boolean f512KQgRr5e_0;
        public boolean QxJ9d_1 = false;

        public KQgRr5e_0(ActionMode.Callback callback, TextView textView) {
            this.KQgRr5e_0 = callback;
            this.f509KQgRr5e_0 = textView;
        }

        public final void KQgRr5e_0(Menu menu) {
            Context context = this.f509KQgRr5e_0.getContext();
            PackageManager packageManager = context.getPackageManager();
            if (!this.QxJ9d_1) {
                this.QxJ9d_1 = true;
                try {
                    Class<?> cls = Class.forName("com.android.internal.view.menu.MenuBuilder");
                    this.f510KQgRr5e_0 = cls;
                    this.f511KQgRr5e_0 = cls.getDeclaredMethod("removeItemAt", Integer.TYPE);
                    this.f512KQgRr5e_0 = true;
                } catch (ClassNotFoundException | NoSuchMethodException unused) {
                    this.f510KQgRr5e_0 = null;
                    this.f511KQgRr5e_0 = null;
                    this.f512KQgRr5e_0 = false;
                }
            }
            try {
                Method declaredMethod = (this.f512KQgRr5e_0 && this.f510KQgRr5e_0.isInstance(menu)) ? this.f511KQgRr5e_0 : menu.getClass().getDeclaredMethod("removeItemAt", Integer.TYPE);
                for (int size = menu.size() - 1; size >= 0; size--) {
                    MenuItem item = menu.getItem(size);
                    if (item.getIntent() != null && "android.intent.action.PROCESS_TEXT".equals(item.getIntent().getAction())) {
                        declaredMethod.invoke(menu, Integer.valueOf(size));
                    }
                }
                List<ResolveInfo> KQgRr5e_0 = KQgRr5e_0(context, packageManager);
                for (int i = 0; i < KQgRr5e_0.size(); i++) {
                    ResolveInfo resolveInfo = KQgRr5e_0.get(i);
                    menu.add(0, 0, i + 100, resolveInfo.loadLabel(packageManager)).setIntent(KQgRr5e_0(resolveInfo, this.f509KQgRr5e_0)).setShowAsAction(1);
                }
            } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException unused2) {
            }
        }

        @Override // android.view.ActionMode.Callback
        public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
            return this.KQgRr5e_0.onActionItemClicked(actionMode, menuItem);
        }

        @Override // android.view.ActionMode.Callback
        public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
            return this.KQgRr5e_0.onCreateActionMode(actionMode, menu);
        }

        @Override // android.view.ActionMode.Callback
        public void onDestroyActionMode(ActionMode actionMode) {
            this.KQgRr5e_0.onDestroyActionMode(actionMode);
        }

        @Override // android.view.ActionMode.Callback
        public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
            KQgRr5e_0(menu);
            return this.KQgRr5e_0.onPrepareActionMode(actionMode, menu);
        }

        public final List<ResolveInfo> KQgRr5e_0(Context context, PackageManager packageManager) {
            ArrayList arrayList = new ArrayList();
            if (context instanceof Activity) {
                for (ResolveInfo resolveInfo : packageManager.queryIntentActivities(KQgRr5e_0(), 0)) {
                    if (KQgRr5e_0(resolveInfo, context)) {
                        arrayList.add(resolveInfo);
                    }
                }
                return arrayList;
            }
            return arrayList;
        }

        public final boolean KQgRr5e_0(ResolveInfo resolveInfo, Context context) {
            if (context.getPackageName().equals(resolveInfo.activityInfo.packageName)) {
                return true;
            }
            ActivityInfo activityInfo = resolveInfo.activityInfo;
            if (activityInfo.exported) {
                String str = activityInfo.permission;
                return str == null || context.checkSelfPermission(str) == 0;
            }
            return false;
        }

        public final Intent KQgRr5e_0(ResolveInfo resolveInfo, TextView textView) {
            Intent putExtra = KQgRr5e_0().putExtra("android.intent.extra.PROCESS_TEXT_READONLY", !KQgRr5e_0(textView));
            ActivityInfo activityInfo = resolveInfo.activityInfo;
            return putExtra.setClassName(activityInfo.packageName, activityInfo.name);
        }

        public final boolean KQgRr5e_0(TextView textView) {
            return (textView instanceof Editable) && textView.onCheckIsTextEditor() && textView.isEnabled();
        }

        public final Intent KQgRr5e_0() {
            return new Intent().setAction("android.intent.action.PROCESS_TEXT").setType("text/plain");
        }
    }

    public static int KQgRr5e_0(TextView textView) {
        return textView.getPaddingTop() - textView.getPaint().getFontMetricsInt().top;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public static PGPF6hQ_2.KQgRr5e_0 m328KQgRr5e_0(TextView textView) {
        if (Build.VERSION.SDK_INT >= 28) {
            return new PGPF6hQ_2.KQgRr5e_0(textView.getTextMetricsParams());
        }
        PGPF6hQ_2.KQgRr5e_0.C0042KQgRr5e_0 c0042KQgRr5e_0 = new PGPF6hQ_2.KQgRr5e_0.C0042KQgRr5e_0(new TextPaint(textView.getPaint()));
        if (Build.VERSION.SDK_INT >= 23) {
            c0042KQgRr5e_0.KQgRr5e_0(textView.getBreakStrategy());
            c0042KQgRr5e_0.QxJ9d_1(textView.getHyphenationFrequency());
        }
        if (Build.VERSION.SDK_INT >= 18) {
            c0042KQgRr5e_0.KQgRr5e_0(m329KQgRr5e_0(textView));
        }
        return c0042KQgRr5e_0.KQgRr5e_0();
    }

    public static void KQgRr5e_0(TextView textView, PGPF6hQ_2.KQgRr5e_0 kQgRr5e_0) {
        if (Build.VERSION.SDK_INT >= 18) {
            textView.setTextDirection(KQgRr5e_0(kQgRr5e_0.m316KQgRr5e_0()));
        }
        if (Build.VERSION.SDK_INT < 23) {
            float textScaleX = kQgRr5e_0.m317KQgRr5e_0().getTextScaleX();
            textView.getPaint().set(kQgRr5e_0.m317KQgRr5e_0());
            if (textScaleX == textView.getTextScaleX()) {
                textView.setTextScaleX((textScaleX / 2.0f) + 1.0f);
            }
            textView.setTextScaleX(textScaleX);
            return;
        }
        textView.getPaint().set(kQgRr5e_0.m317KQgRr5e_0());
        textView.setBreakStrategy(kQgRr5e_0.KQgRr5e_0());
        textView.setHyphenationFrequency(kQgRr5e_0.QxJ9d_1());
    }

    public static void KQgRr5e_0(TextView textView, X6FRs_4.IMuAHx_6.Nm6q_10.PGPF6hQ_2 pGPF6hQ_2) {
        if (m328KQgRr5e_0(textView).KQgRr5e_0(pGPF6hQ_2.KQgRr5e_0())) {
            textView.setText(pGPF6hQ_2);
            return;
        }
        throw new IllegalArgumentException("Given text can not be applied to TextView.");
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public static TextDirectionHeuristic m329KQgRr5e_0(TextView textView) {
        if (textView.getTransformationMethod() instanceof PasswordTransformationMethod) {
            return TextDirectionHeuristics.LTR;
        }
        if (Build.VERSION.SDK_INT >= 28 && (textView.getInputType() & 15) == 3) {
            byte directionality = Character.getDirectionality(DecimalFormatSymbols.getInstance(textView.getTextLocale()).getDigitStrings()[0].codePointAt(0));
            if (directionality != 1 && directionality != 2) {
                return TextDirectionHeuristics.LTR;
            }
            return TextDirectionHeuristics.RTL;
        }
        boolean z = textView.getLayoutDirection() == 1;
        switch (textView.getTextDirection()) {
            case 2:
                return TextDirectionHeuristics.ANYRTL_LTR;
            case 3:
                return TextDirectionHeuristics.LTR;
            case 4:
                return TextDirectionHeuristics.RTL;
            case 5:
                return TextDirectionHeuristics.LOCALE;
            case 6:
                return TextDirectionHeuristics.FIRSTSTRONG_LTR;
            case 7:
                return TextDirectionHeuristics.FIRSTSTRONG_RTL;
            default:
                if (z) {
                    return TextDirectionHeuristics.FIRSTSTRONG_RTL;
                }
                return TextDirectionHeuristics.FIRSTSTRONG_LTR;
        }
    }

    public static int KQgRr5e_0(TextDirectionHeuristic textDirectionHeuristic) {
        if (textDirectionHeuristic == TextDirectionHeuristics.FIRSTSTRONG_RTL || textDirectionHeuristic == TextDirectionHeuristics.FIRSTSTRONG_LTR) {
            return 1;
        }
        if (textDirectionHeuristic == TextDirectionHeuristics.ANYRTL_LTR) {
            return 2;
        }
        if (textDirectionHeuristic == TextDirectionHeuristics.LTR) {
            return 3;
        }
        if (textDirectionHeuristic == TextDirectionHeuristics.RTL) {
            return 4;
        }
        if (textDirectionHeuristic == TextDirectionHeuristics.LOCALE) {
            return 5;
        }
        if (textDirectionHeuristic == TextDirectionHeuristics.FIRSTSTRONG_LTR) {
            return 6;
        }
        return textDirectionHeuristic == TextDirectionHeuristics.FIRSTSTRONG_RTL ? 7 : 1;
    }
}
