Initial commit
This commit is contained in:
81
sources/androidx/core/text/ICUCompat.java
Normal file
81
sources/androidx/core/text/ICUCompat.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package androidx.core.text;
|
||||
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Locale;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class ICUCompat {
|
||||
private static Method a;
|
||||
private static Method b;
|
||||
|
||||
static {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
try {
|
||||
b = Class.forName("libcore.icu.ICU").getMethod("addLikelySubtags", Locale.class);
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
Class<?> cls = Class.forName("libcore.icu.ICU");
|
||||
if (cls != null) {
|
||||
a = cls.getMethod("getScript", String.class);
|
||||
b = cls.getMethod("addLikelySubtags", String.class);
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
a = null;
|
||||
b = null;
|
||||
Log.w("ICUCompat", e2);
|
||||
}
|
||||
}
|
||||
|
||||
private static String a(String str) {
|
||||
try {
|
||||
if (a != null) {
|
||||
return (String) a.invoke(null, str);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.w("ICUCompat", e);
|
||||
} catch (InvocationTargetException e2) {
|
||||
Log.w("ICUCompat", e2);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String b(Locale locale) {
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
String a2 = a(locale);
|
||||
if (a2 != null) {
|
||||
return a(a2);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return ((Locale) b.invoke(null, locale)).getScript();
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.w("ICUCompat", e);
|
||||
return locale.getScript();
|
||||
} catch (InvocationTargetException e2) {
|
||||
Log.w("ICUCompat", e2);
|
||||
return locale.getScript();
|
||||
}
|
||||
}
|
||||
|
||||
private static String a(Locale locale) {
|
||||
String locale2 = locale.toString();
|
||||
try {
|
||||
if (b != null) {
|
||||
return (String) b.invoke(null, locale2);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.w("ICUCompat", e);
|
||||
} catch (InvocationTargetException e2) {
|
||||
Log.w("ICUCompat", e2);
|
||||
}
|
||||
return locale2;
|
||||
}
|
||||
}
|
255
sources/androidx/core/text/PrecomputedTextCompat.java
Normal file
255
sources/androidx/core/text/PrecomputedTextCompat.java
Normal file
@@ -0,0 +1,255 @@
|
||||
package androidx.core.text;
|
||||
|
||||
import android.os.Build;
|
||||
import android.text.PrecomputedText;
|
||||
import android.text.Spannable;
|
||||
import android.text.TextDirectionHeuristic;
|
||||
import android.text.TextDirectionHeuristics;
|
||||
import android.text.TextPaint;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.MetricAffectingSpan;
|
||||
import androidx.core.util.ObjectsCompat;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class PrecomputedTextCompat implements Spannable {
|
||||
private final Spannable a;
|
||||
private final Params b;
|
||||
private final PrecomputedText c;
|
||||
|
||||
public Params a() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
public PrecomputedText b() {
|
||||
Spannable spannable = this.a;
|
||||
if (spannable instanceof PrecomputedText) {
|
||||
return (PrecomputedText) spannable;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override // java.lang.CharSequence
|
||||
public char charAt(int i) {
|
||||
return this.a.charAt(i);
|
||||
}
|
||||
|
||||
@Override // android.text.Spanned
|
||||
public int getSpanEnd(Object obj) {
|
||||
return this.a.getSpanEnd(obj);
|
||||
}
|
||||
|
||||
@Override // android.text.Spanned
|
||||
public int getSpanFlags(Object obj) {
|
||||
return this.a.getSpanFlags(obj);
|
||||
}
|
||||
|
||||
@Override // android.text.Spanned
|
||||
public int getSpanStart(Object obj) {
|
||||
return this.a.getSpanStart(obj);
|
||||
}
|
||||
|
||||
@Override // android.text.Spanned
|
||||
public <T> T[] getSpans(int i, int i2, Class<T> cls) {
|
||||
return Build.VERSION.SDK_INT >= 28 ? (T[]) this.c.getSpans(i, i2, cls) : (T[]) this.a.getSpans(i, i2, cls);
|
||||
}
|
||||
|
||||
@Override // java.lang.CharSequence
|
||||
public int length() {
|
||||
return this.a.length();
|
||||
}
|
||||
|
||||
@Override // android.text.Spanned
|
||||
public int nextSpanTransition(int i, int i2, Class cls) {
|
||||
return this.a.nextSpanTransition(i, i2, cls);
|
||||
}
|
||||
|
||||
@Override // android.text.Spannable
|
||||
public void removeSpan(Object obj) {
|
||||
if (obj instanceof MetricAffectingSpan) {
|
||||
throw new IllegalArgumentException("MetricAffectingSpan can not be removed from PrecomputedText.");
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
this.c.removeSpan(obj);
|
||||
} else {
|
||||
this.a.removeSpan(obj);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.text.Spannable
|
||||
public void setSpan(Object obj, int i, int i2, int i3) {
|
||||
if (obj instanceof MetricAffectingSpan) {
|
||||
throw new IllegalArgumentException("MetricAffectingSpan can not be set to PrecomputedText.");
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
this.c.setSpan(obj, i, i2, i3);
|
||||
} else {
|
||||
this.a.setSpan(obj, i, i2, i3);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // java.lang.CharSequence
|
||||
public CharSequence subSequence(int i, int i2) {
|
||||
return this.a.subSequence(i, i2);
|
||||
}
|
||||
|
||||
@Override // java.lang.CharSequence
|
||||
public String toString() {
|
||||
return this.a.toString();
|
||||
}
|
||||
|
||||
public static final class Params {
|
||||
private final TextPaint a;
|
||||
private final TextDirectionHeuristic b;
|
||||
private final int c;
|
||||
private final int d;
|
||||
final PrecomputedText.Params e;
|
||||
|
||||
public static class Builder {
|
||||
private final TextPaint a;
|
||||
private TextDirectionHeuristic b;
|
||||
private int c;
|
||||
private int d;
|
||||
|
||||
public Builder(TextPaint textPaint) {
|
||||
this.a = textPaint;
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
this.c = 1;
|
||||
this.d = 1;
|
||||
} else {
|
||||
this.d = 0;
|
||||
this.c = 0;
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 18) {
|
||||
this.b = TextDirectionHeuristics.FIRSTSTRONG_LTR;
|
||||
} else {
|
||||
this.b = null;
|
||||
}
|
||||
}
|
||||
|
||||
public Builder a(int i) {
|
||||
this.c = i;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder b(int i) {
|
||||
this.d = i;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder a(TextDirectionHeuristic textDirectionHeuristic) {
|
||||
this.b = textDirectionHeuristic;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Params a() {
|
||||
return new Params(this.a, this.b, this.c, this.d);
|
||||
}
|
||||
}
|
||||
|
||||
Params(TextPaint textPaint, TextDirectionHeuristic textDirectionHeuristic, int i, int i2) {
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
this.e = new PrecomputedText.Params.Builder(textPaint).setBreakStrategy(i).setHyphenationFrequency(i2).setTextDirection(textDirectionHeuristic).build();
|
||||
} else {
|
||||
this.e = null;
|
||||
}
|
||||
this.a = textPaint;
|
||||
this.b = textDirectionHeuristic;
|
||||
this.c = i;
|
||||
this.d = i2;
|
||||
}
|
||||
|
||||
public int a() {
|
||||
return this.c;
|
||||
}
|
||||
|
||||
public int b() {
|
||||
return this.d;
|
||||
}
|
||||
|
||||
public TextDirectionHeuristic c() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
public TextPaint d() {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || !(obj instanceof Params)) {
|
||||
return false;
|
||||
}
|
||||
Params params = (Params) obj;
|
||||
PrecomputedText.Params params2 = this.e;
|
||||
if (params2 != null) {
|
||||
return params2.equals(params.e);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 23 && (this.c != params.a() || this.d != params.b())) {
|
||||
return false;
|
||||
}
|
||||
if ((Build.VERSION.SDK_INT >= 18 && this.b != params.c()) || this.a.getTextSize() != params.d().getTextSize() || this.a.getTextScaleX() != params.d().getTextScaleX() || this.a.getTextSkewX() != params.d().getTextSkewX()) {
|
||||
return false;
|
||||
}
|
||||
if ((Build.VERSION.SDK_INT >= 21 && (this.a.getLetterSpacing() != params.d().getLetterSpacing() || !TextUtils.equals(this.a.getFontFeatureSettings(), params.d().getFontFeatureSettings()))) || this.a.getFlags() != params.d().getFlags()) {
|
||||
return false;
|
||||
}
|
||||
int i = Build.VERSION.SDK_INT;
|
||||
if (i >= 24) {
|
||||
if (!this.a.getTextLocales().equals(params.d().getTextLocales())) {
|
||||
return false;
|
||||
}
|
||||
} else if (i >= 17 && !this.a.getTextLocale().equals(params.d().getTextLocale())) {
|
||||
return false;
|
||||
}
|
||||
if (this.a.getTypeface() == null) {
|
||||
if (params.d().getTypeface() != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this.a.getTypeface().equals(params.d().getTypeface())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int i = Build.VERSION.SDK_INT;
|
||||
return i >= 24 ? ObjectsCompat.a(Float.valueOf(this.a.getTextSize()), Float.valueOf(this.a.getTextScaleX()), Float.valueOf(this.a.getTextSkewX()), Float.valueOf(this.a.getLetterSpacing()), Integer.valueOf(this.a.getFlags()), this.a.getTextLocales(), this.a.getTypeface(), Boolean.valueOf(this.a.isElegantTextHeight()), this.b, Integer.valueOf(this.c), Integer.valueOf(this.d)) : i >= 21 ? ObjectsCompat.a(Float.valueOf(this.a.getTextSize()), Float.valueOf(this.a.getTextScaleX()), Float.valueOf(this.a.getTextSkewX()), Float.valueOf(this.a.getLetterSpacing()), Integer.valueOf(this.a.getFlags()), this.a.getTextLocale(), this.a.getTypeface(), Boolean.valueOf(this.a.isElegantTextHeight()), this.b, Integer.valueOf(this.c), Integer.valueOf(this.d)) : i >= 18 ? ObjectsCompat.a(Float.valueOf(this.a.getTextSize()), Float.valueOf(this.a.getTextScaleX()), Float.valueOf(this.a.getTextSkewX()), Integer.valueOf(this.a.getFlags()), this.a.getTextLocale(), this.a.getTypeface(), this.b, Integer.valueOf(this.c), Integer.valueOf(this.d)) : i >= 17 ? ObjectsCompat.a(Float.valueOf(this.a.getTextSize()), Float.valueOf(this.a.getTextScaleX()), Float.valueOf(this.a.getTextSkewX()), Integer.valueOf(this.a.getFlags()), this.a.getTextLocale(), this.a.getTypeface(), this.b, Integer.valueOf(this.c), Integer.valueOf(this.d)) : ObjectsCompat.a(Float.valueOf(this.a.getTextSize()), Float.valueOf(this.a.getTextScaleX()), Float.valueOf(this.a.getTextSkewX()), Integer.valueOf(this.a.getFlags()), this.a.getTypeface(), this.b, Integer.valueOf(this.c), Integer.valueOf(this.d));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("textSize=" + this.a.getTextSize());
|
||||
sb.append(", textScaleX=" + this.a.getTextScaleX());
|
||||
sb.append(", textSkewX=" + this.a.getTextSkewX());
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
sb.append(", letterSpacing=" + this.a.getLetterSpacing());
|
||||
sb.append(", elegantTextHeight=" + this.a.isElegantTextHeight());
|
||||
}
|
||||
int i = Build.VERSION.SDK_INT;
|
||||
if (i >= 24) {
|
||||
sb.append(", textLocale=" + this.a.getTextLocales());
|
||||
} else if (i >= 17) {
|
||||
sb.append(", textLocale=" + this.a.getTextLocale());
|
||||
}
|
||||
sb.append(", typeface=" + this.a.getTypeface());
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
sb.append(", variationSettings=" + this.a.getFontVariationSettings());
|
||||
}
|
||||
sb.append(", textDir=" + this.b);
|
||||
sb.append(", breakStrategy=" + this.c);
|
||||
sb.append(", hyphenationFrequency=" + this.d);
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Params(PrecomputedText.Params params) {
|
||||
this.a = params.getTextPaint();
|
||||
this.b = params.getTextDirection();
|
||||
this.c = params.getBreakStrategy();
|
||||
this.d = params.getHyphenationFrequency();
|
||||
this.e = params;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
package androidx.core.text;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public interface TextDirectionHeuristicCompat {
|
||||
boolean a(CharSequence charSequence, int i, int i2);
|
||||
}
|
160
sources/androidx/core/text/TextDirectionHeuristicsCompat.java
Normal file
160
sources/androidx/core/text/TextDirectionHeuristicsCompat.java
Normal file
@@ -0,0 +1,160 @@
|
||||
package androidx.core.text;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class TextDirectionHeuristicsCompat {
|
||||
public static final TextDirectionHeuristicCompat a;
|
||||
public static final TextDirectionHeuristicCompat b;
|
||||
|
||||
private static class AnyStrong implements TextDirectionAlgorithm {
|
||||
static final AnyStrong b = new AnyStrong(true);
|
||||
private final boolean a;
|
||||
|
||||
static {
|
||||
new AnyStrong(false);
|
||||
}
|
||||
|
||||
private AnyStrong(boolean z) {
|
||||
this.a = z;
|
||||
}
|
||||
|
||||
@Override // androidx.core.text.TextDirectionHeuristicsCompat.TextDirectionAlgorithm
|
||||
public int a(CharSequence charSequence, int i, int i2) {
|
||||
int i3 = i2 + i;
|
||||
boolean z = false;
|
||||
while (i < i3) {
|
||||
int a = TextDirectionHeuristicsCompat.a(Character.getDirectionality(charSequence.charAt(i)));
|
||||
if (a != 0) {
|
||||
if (a != 1) {
|
||||
continue;
|
||||
i++;
|
||||
} else if (!this.a) {
|
||||
return 1;
|
||||
}
|
||||
} else if (this.a) {
|
||||
return 0;
|
||||
}
|
||||
z = true;
|
||||
i++;
|
||||
}
|
||||
if (z) {
|
||||
return this.a ? 1 : 0;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
private static class FirstStrong implements TextDirectionAlgorithm {
|
||||
static final FirstStrong a = new FirstStrong();
|
||||
|
||||
private FirstStrong() {
|
||||
}
|
||||
|
||||
@Override // androidx.core.text.TextDirectionHeuristicsCompat.TextDirectionAlgorithm
|
||||
public int a(CharSequence charSequence, int i, int i2) {
|
||||
int i3 = i2 + i;
|
||||
int i4 = 2;
|
||||
while (i < i3 && i4 == 2) {
|
||||
i4 = TextDirectionHeuristicsCompat.b(Character.getDirectionality(charSequence.charAt(i)));
|
||||
i++;
|
||||
}
|
||||
return i4;
|
||||
}
|
||||
}
|
||||
|
||||
private interface TextDirectionAlgorithm {
|
||||
int a(CharSequence charSequence, int i, int i2);
|
||||
}
|
||||
|
||||
private static abstract class TextDirectionHeuristicImpl implements TextDirectionHeuristicCompat {
|
||||
private final TextDirectionAlgorithm a;
|
||||
|
||||
TextDirectionHeuristicImpl(TextDirectionAlgorithm textDirectionAlgorithm) {
|
||||
this.a = textDirectionAlgorithm;
|
||||
}
|
||||
|
||||
private boolean b(CharSequence charSequence, int i, int i2) {
|
||||
int a = this.a.a(charSequence, i, i2);
|
||||
if (a == 0) {
|
||||
return true;
|
||||
}
|
||||
if (a != 1) {
|
||||
return a();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract boolean a();
|
||||
|
||||
@Override // androidx.core.text.TextDirectionHeuristicCompat
|
||||
public boolean a(CharSequence charSequence, int i, int i2) {
|
||||
if (charSequence == null || i < 0 || i2 < 0 || charSequence.length() - i2 < i) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return this.a == null ? a() : b(charSequence, i, i2);
|
||||
}
|
||||
}
|
||||
|
||||
private static class TextDirectionHeuristicInternal extends TextDirectionHeuristicImpl {
|
||||
private final boolean b;
|
||||
|
||||
TextDirectionHeuristicInternal(TextDirectionAlgorithm textDirectionAlgorithm, boolean z) {
|
||||
super(textDirectionAlgorithm);
|
||||
this.b = z;
|
||||
}
|
||||
|
||||
@Override // androidx.core.text.TextDirectionHeuristicsCompat.TextDirectionHeuristicImpl
|
||||
protected boolean a() {
|
||||
return this.b;
|
||||
}
|
||||
}
|
||||
|
||||
private static class TextDirectionHeuristicLocale extends TextDirectionHeuristicImpl {
|
||||
static final TextDirectionHeuristicLocale b = new TextDirectionHeuristicLocale();
|
||||
|
||||
TextDirectionHeuristicLocale() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override // androidx.core.text.TextDirectionHeuristicsCompat.TextDirectionHeuristicImpl
|
||||
protected boolean a() {
|
||||
return TextUtilsCompat.b(Locale.getDefault()) == 1;
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
new TextDirectionHeuristicInternal(null, false);
|
||||
new TextDirectionHeuristicInternal(null, true);
|
||||
a = new TextDirectionHeuristicInternal(FirstStrong.a, false);
|
||||
b = new TextDirectionHeuristicInternal(FirstStrong.a, true);
|
||||
new TextDirectionHeuristicInternal(AnyStrong.b, false);
|
||||
TextDirectionHeuristicLocale textDirectionHeuristicLocale = TextDirectionHeuristicLocale.b;
|
||||
}
|
||||
|
||||
static int a(int i) {
|
||||
if (i != 0) {
|
||||
return (i == 1 || i == 2) ? 0 : 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int b(int i) {
|
||||
if (i != 0) {
|
||||
if (i == 1 || i == 2) {
|
||||
return 0;
|
||||
}
|
||||
switch (i) {
|
||||
case 14:
|
||||
case 15:
|
||||
break;
|
||||
case 16:
|
||||
case 17:
|
||||
return 0;
|
||||
default:
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
26
sources/androidx/core/text/TextUtilsCompat.java
Normal file
26
sources/androidx/core/text/TextUtilsCompat.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package androidx.core.text;
|
||||
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import java.util.Locale;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class TextUtilsCompat {
|
||||
private static final Locale a = new Locale("", "");
|
||||
|
||||
private static int a(Locale locale) {
|
||||
byte directionality = Character.getDirectionality(locale.getDisplayName(locale).charAt(0));
|
||||
return (directionality == 1 || directionality == 2) ? 1 : 0;
|
||||
}
|
||||
|
||||
public static int b(Locale locale) {
|
||||
if (Build.VERSION.SDK_INT >= 17) {
|
||||
return TextUtils.getLayoutDirectionFromLocale(locale);
|
||||
}
|
||||
if (locale == null || locale.equals(a)) {
|
||||
return 0;
|
||||
}
|
||||
String b = ICUCompat.b(locale);
|
||||
return b == null ? a(locale) : (b.equalsIgnoreCase("Arab") || b.equalsIgnoreCase("Hebr")) ? 1 : 0;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user