what-the-bank/sources/io/github/inflationx/calligraphy3/CalligraphyUtils.java

378 lines
15 KiB
Java

package io.github.inflationx.calligraphy3;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.text.Editable;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Base64;
import android.util.TypedValue;
import android.widget.TextView;
import java.nio.charset.StandardCharsets;
/* loaded from: classes.dex */
public final class CalligraphyUtils {
public static final int[] ANDROID_ATTR_TEXT_APPEARANCE;
private static byte a = 0;
private static int d = 0;
private static int e = 1;
private static Boolean sAppCompatViewCheck;
private static Boolean sToolbarCheck;
private static void b(String str, Object[] objArr) {
byte[] decode = Base64.decode(str, 0);
byte[] bArr = new byte[decode.length];
for (int i = 0; i < decode.length; i++) {
bArr[i] = (byte) (decode[(decode.length - i) - 1] ^ a);
}
objArr[0] = new String(bArr, StandardCharsets.UTF_8);
}
public static CharSequence applyTypefaceSpan(CharSequence charSequence, Typeface typeface) {
if (charSequence != null && charSequence.length() > 0) {
if (!(charSequence instanceof Spannable)) {
charSequence = new SpannableString(charSequence);
}
((Spannable) charSequence).setSpan(TypefaceUtils.getSpan(typeface), 0, charSequence.length(), 33);
}
return charSequence;
}
public static boolean applyFontToTextView(TextView textView, Typeface typeface) {
return applyFontToTextView(textView, typeface, false);
}
public static boolean applyFontToTextView(TextView textView, Typeface typeface, boolean z) {
if (textView == null || typeface == null) {
return false;
}
textView.setPaintFlags(textView.getPaintFlags() | 129);
textView.setTypeface(typeface);
if (!z) {
return true;
}
textView.setText(applyTypefaceSpan(textView.getText(), typeface), TextView.BufferType.SPANNABLE);
textView.addTextChangedListener(new TextWatcher(typeface) { // from class: io.github.inflationx.calligraphy3.CalligraphyUtils.1
final Typeface val$typeface;
@Override // android.text.TextWatcher
public final void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override // android.text.TextWatcher
public final void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
{
this.val$typeface = typeface;
}
@Override // android.text.TextWatcher
public final void afterTextChanged(Editable editable) {
CalligraphyUtils.applyTypefaceSpan(editable, this.val$typeface);
}
});
return true;
}
public static boolean applyFontToTextView(Context context, TextView textView, String str) {
return applyFontToTextView(context, textView, str, false);
}
static boolean applyFontToTextView(Context context, TextView textView, String str, boolean z) {
if (textView == null || context == null) {
return false;
}
return applyFontToTextView(textView, TypefaceUtils.load(context.getAssets(), str), z);
}
static void applyFontToTextView(Context context, TextView textView, CalligraphyConfig calligraphyConfig) {
applyFontToTextView(context, textView, calligraphyConfig, false);
}
static void applyFontToTextView(Context context, TextView textView, CalligraphyConfig calligraphyConfig, boolean z) {
if (context == null || textView == null || calligraphyConfig == null || !calligraphyConfig.isFontSet()) {
return;
}
applyFontToTextView(context, textView, calligraphyConfig.getFontPath(), z);
}
public static void applyFontToTextView(Context context, TextView textView, CalligraphyConfig calligraphyConfig, String str) {
applyFontToTextView(context, textView, calligraphyConfig, str, false);
}
/* JADX INFO: Access modifiers changed from: package-private */
public static void applyFontToTextView(Context context, TextView textView, CalligraphyConfig calligraphyConfig, String str, boolean z) {
if (context == null || textView == null || calligraphyConfig == null) {
return;
}
if (TextUtils.isEmpty(str) || !applyFontToTextView(context, textView, str, z)) {
applyFontToTextView(context, textView, calligraphyConfig, z);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* JADX WARN: Code restructure failed: missing block: B:38:0x002e, code lost:
r8 = r6.getResources().getResourceEntryName(r8[0]);
*/
/* JADX WARN: Code restructure failed: missing block: B:7:0x001d, code lost:
r8 = r6.getResources().getResourceEntryName(r8[1]);
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public static java.lang.String pullFontPathFromView(android.content.Context r6, android.util.AttributeSet r7, int[] r8) {
/*
r0 = 2
int r1 = r0 % r0
int r1 = io.github.inflationx.calligraphy3.CalligraphyUtils.d
int r1 = r1 + 85
int r2 = r1 % 128
io.github.inflationx.calligraphy3.CalligraphyUtils.e = r2
int r1 = r1 % r0
r1 = 0
if (r8 == 0) goto Lcc
if (r7 == 0) goto Lcc
int r2 = r2 + 87
int r3 = r2 % 128
io.github.inflationx.calligraphy3.CalligraphyUtils.d = r3
int r2 = r2 % r0
r3 = -1
r4 = 0
r5 = 1
if (r2 == 0) goto L2e
android.content.res.Resources r2 = r6.getResources() // Catch: android.content.res.Resources.NotFoundException -> Lcc
r8 = r8[r5] // Catch: android.content.res.Resources.NotFoundException -> Lcc
java.lang.String r8 = r2.getResourceEntryName(r8) // Catch: android.content.res.Resources.NotFoundException -> Lcc
int r2 = r7.getAttributeResourceValue(r1, r8, r3)
if (r2 <= 0) goto L70
goto L3e
L2e:
android.content.res.Resources r2 = r6.getResources() // Catch: android.content.res.Resources.NotFoundException -> Lcc
r8 = r8[r4] // Catch: android.content.res.Resources.NotFoundException -> Lcc
java.lang.String r8 = r2.getResourceEntryName(r8) // Catch: android.content.res.Resources.NotFoundException -> Lcc
int r2 = r7.getAttributeResourceValue(r1, r8, r3)
if (r2 <= 0) goto L70
L3e:
int r7 = io.github.inflationx.calligraphy3.CalligraphyUtils.d
int r7 = r7 + 97
int r8 = r7 % 128
io.github.inflationx.calligraphy3.CalligraphyUtils.e = r8
int r7 = r7 % r0
java.lang.String r8 = ",*,)"
if (r7 == 0) goto L68
java.lang.String r7 = r6.getString(r2)
boolean r8 = r7.startsWith(r8)
if (r8 == 0) goto L74
r8 = 4
java.lang.String r7 = r7.substring(r8)
java.lang.Object[] r8 = new java.lang.Object[r5]
b(r7, r8)
r7 = r8[r4]
java.lang.String r7 = (java.lang.String) r7
java.lang.String r7 = r7.intern()
goto L74
L68:
java.lang.String r6 = r6.getString(r2)
r6.startsWith(r8)
throw r1
L70:
java.lang.String r7 = r7.getAttributeValue(r1, r8)
L74:
if (r7 == 0) goto Lc2
java.lang.String r8 = "?"
boolean r8 = r7.startsWith(r8)
if (r8 == 0) goto Lc2
int r8 = r7.length()
if (r8 <= r5) goto Lc2
java.lang.String r8 = r7.substring(r5)
boolean r2 = android.text.TextUtils.isDigitsOnly(r8)
if (r2 == 0) goto Lc2
int r8 = java.lang.Integer.parseInt(r8)
android.util.TypedValue r2 = new android.util.TypedValue
r2.<init>()
android.content.res.Resources$Theme r6 = r6.getTheme()
r6.resolveAttribute(r8, r2, r5)
int r6 = r2.type
r8 = 3
if (r6 != r8) goto Lc2
java.lang.CharSequence r6 = r2.string
if (r6 == 0) goto Lc2
int r6 = io.github.inflationx.calligraphy3.CalligraphyUtils.e
int r6 = r6 + 95
int r7 = r6 % 128
io.github.inflationx.calligraphy3.CalligraphyUtils.d = r7
int r6 = r6 % r0
if (r6 != 0) goto Lb9
java.lang.CharSequence r6 = r2.string
java.lang.String r7 = r6.toString()
goto Lc2
Lb9:
java.lang.CharSequence r6 = r2.string
r6.toString()
r1.hashCode()
throw r1
Lc2:
int r6 = io.github.inflationx.calligraphy3.CalligraphyUtils.d
int r6 = r6 + 99
int r8 = r6 % 128
io.github.inflationx.calligraphy3.CalligraphyUtils.e = r8
int r6 = r6 % r0
return r7
Lcc:
int r6 = io.github.inflationx.calligraphy3.CalligraphyUtils.d
int r6 = r6 + 37
int r7 = r6 % 128
io.github.inflationx.calligraphy3.CalligraphyUtils.e = r7
int r6 = r6 % r0
if (r6 == 0) goto Ld8
return r1
Ld8:
r1.hashCode()
throw r1
*/
throw new UnsupportedOperationException("Method not decompiled: io.github.inflationx.calligraphy3.CalligraphyUtils.pullFontPathFromView(android.content.Context, android.util.AttributeSet, int[]):java.lang.String");
}
/* JADX INFO: Access modifiers changed from: package-private */
public static String pullFontPathFromStyle(Context context, AttributeSet attributeSet, int[] iArr) {
TypedArray obtainStyledAttributes;
if (iArr == null || attributeSet == null || (obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, iArr)) == null) {
return null;
}
try {
String string = obtainStyledAttributes.getString(0);
if (!TextUtils.isEmpty(string)) {
obtainStyledAttributes.recycle();
return string;
}
} catch (Exception unused) {
} catch (Throwable th) {
obtainStyledAttributes.recycle();
throw th;
}
obtainStyledAttributes.recycle();
return null;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static String pullFontPathFromTextAppearance(Context context, AttributeSet attributeSet, int[] iArr) {
if (iArr != null && attributeSet != null) {
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, ANDROID_ATTR_TEXT_APPEARANCE);
int i = -1;
if (obtainStyledAttributes != null) {
try {
i = obtainStyledAttributes.getResourceId(0, -1);
} catch (Exception unused) {
return null;
} finally {
obtainStyledAttributes.recycle();
}
}
TypedArray obtainStyledAttributes2 = context.obtainStyledAttributes(i, iArr);
if (obtainStyledAttributes2 != null) {
try {
return obtainStyledAttributes2.getString(0);
} catch (Exception unused2) {
} finally {
obtainStyledAttributes2.recycle();
}
}
}
return null;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static String pullFontPathFromTheme(Context context, int i, int[] iArr) {
if (i == -1 || iArr == null) {
return null;
}
Resources.Theme theme = context.getTheme();
TypedValue typedValue = new TypedValue();
theme.resolveAttribute(i, typedValue, true);
TypedArray obtainStyledAttributes = theme.obtainStyledAttributes(typedValue.resourceId, iArr);
try {
return obtainStyledAttributes.getString(0);
} catch (Exception unused) {
return null;
} finally {
obtainStyledAttributes.recycle();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public static String pullFontPathFromTheme(Context context, int i, int i2, int[] iArr) {
TypedArray obtainStyledAttributes;
if (i != -1 && iArr != null) {
Resources.Theme theme = context.getTheme();
TypedValue typedValue = new TypedValue();
theme.resolveAttribute(i, typedValue, true);
TypedArray obtainStyledAttributes2 = theme.obtainStyledAttributes(typedValue.resourceId, new int[]{i2});
try {
int resourceId = obtainStyledAttributes2.getResourceId(0, -1);
if (resourceId != -1 && (obtainStyledAttributes = context.obtainStyledAttributes(resourceId, iArr)) != null) {
try {
return obtainStyledAttributes.getString(0);
} catch (Exception unused) {
} finally {
obtainStyledAttributes.recycle();
}
}
return null;
} catch (Exception unused2) {
} finally {
obtainStyledAttributes2.recycle();
}
}
return null;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static boolean canCheckForV7Toolbar() {
if (sToolbarCheck == null) {
try {
Class.forName("androidx.appcompat.widget.Toolbar");
sToolbarCheck = Boolean.TRUE;
} catch (ClassNotFoundException unused) {
sToolbarCheck = Boolean.FALSE;
}
}
return sToolbarCheck.booleanValue();
}
/* JADX INFO: Access modifiers changed from: package-private */
public static boolean canAddV7AppCompatViews() {
if (sAppCompatViewCheck == null) {
try {
Class.forName("androidx.appcompat.widget.AppCompatTextView");
sAppCompatViewCheck = Boolean.TRUE;
} catch (ClassNotFoundException unused) {
sAppCompatViewCheck = Boolean.FALSE;
}
}
return sAppCompatViewCheck.booleanValue();
}
private CalligraphyUtils() {
}
static void c() {
a = (byte) 6;
}
static {
c();
ANDROID_ATTR_TEXT_APPEARANCE = new int[]{android.R.attr.textAppearance};
sToolbarCheck = null;
sAppCompatViewCheck = null;
}
}