Files
rr3-apk/decompiled-community/sources/androidx/core/widget/TextViewCompat.java
Daniel Elliott c080f0d97f Add Discord community version (64-bit only)
- Added realracing3-community.apk (71.57 MB)
- Removed 32-bit support (armeabi-v7a)
- Only includes arm64-v8a libraries
- Decompiled source code included
- Added README-community.md with analysis
2026-02-18 15:48:36 -08:00

596 lines
25 KiB
Java

package androidx.core.widget;
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.content.res.ColorStateList;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.icu.text.DecimalFormatSymbols;
import android.os.Build;
import android.text.Editable;
import android.text.PrecomputedText;
import android.text.TextDirectionHeuristic;
import android.text.TextDirectionHeuristics;
import android.text.TextPaint;
import android.text.method.PasswordTransformationMethod;
import android.util.TypedValue;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import androidx.annotation.DrawableRes;
import androidx.annotation.FloatRange;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
import androidx.annotation.ReplaceWith;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.annotation.StyleRes;
import androidx.core.text.PrecomputedTextCompat;
import androidx.core.util.Preconditions;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/* loaded from: classes.dex */
public final class TextViewCompat {
public static final int AUTO_SIZE_TEXT_TYPE_NONE = 0;
public static final int AUTO_SIZE_TEXT_TYPE_UNIFORM = 1;
@Retention(RetentionPolicy.SOURCE)
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
public @interface AutoSizeTextType {
}
private TextViewCompat() {
}
@ReplaceWith(expression = "textView.setCompoundDrawablesRelative(start, top, end, bottom)")
@Deprecated
public static void setCompoundDrawablesRelative(@NonNull TextView textView, @Nullable Drawable drawable, @Nullable Drawable drawable2, @Nullable Drawable drawable3, @Nullable Drawable drawable4) {
textView.setCompoundDrawablesRelative(drawable, drawable2, drawable3, drawable4);
}
@ReplaceWith(expression = "textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom)")
@Deprecated
public static void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, @Nullable Drawable drawable, @Nullable Drawable drawable2, @Nullable Drawable drawable3, @Nullable Drawable drawable4) {
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, drawable2, drawable3, drawable4);
}
@ReplaceWith(expression = "textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom)")
@Deprecated
public static void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, @DrawableRes int i, @DrawableRes int i2, @DrawableRes int i3, @DrawableRes int i4) {
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(i, i2, i3, i4);
}
@ReplaceWith(expression = "textView.getMaxLines()")
@Deprecated
public static int getMaxLines(@NonNull TextView textView) {
return textView.getMaxLines();
}
@ReplaceWith(expression = "textView.getMinLines()")
@Deprecated
public static int getMinLines(@NonNull TextView textView) {
return textView.getMinLines();
}
public static void setTextAppearance(@NonNull TextView textView, @StyleRes int i) {
textView.setTextAppearance(i);
}
@NonNull
@ReplaceWith(expression = "textView.getCompoundDrawablesRelative()")
@Deprecated
public static Drawable[] getCompoundDrawablesRelative(@NonNull TextView textView) {
return textView.getCompoundDrawablesRelative();
}
/* JADX WARN: Multi-variable type inference failed */
public static void setAutoSizeTextTypeWithDefaults(@NonNull TextView textView, int i) {
if (Build.VERSION.SDK_INT >= 27) {
Api26Impl.setAutoSizeTextTypeWithDefaults(textView, i);
} else if (textView instanceof AutoSizeableTextView) {
((AutoSizeableTextView) textView).setAutoSizeTextTypeWithDefaults(i);
}
}
/* JADX WARN: Multi-variable type inference failed */
public static void setAutoSizeTextTypeUniformWithConfiguration(@NonNull TextView textView, int i, int i2, int i3, int i4) throws IllegalArgumentException {
if (Build.VERSION.SDK_INT >= 27) {
Api26Impl.setAutoSizeTextTypeUniformWithConfiguration(textView, i, i2, i3, i4);
} else if (textView instanceof AutoSizeableTextView) {
((AutoSizeableTextView) textView).setAutoSizeTextTypeUniformWithConfiguration(i, i2, i3, i4);
}
}
/* JADX WARN: Multi-variable type inference failed */
public static void setAutoSizeTextTypeUniformWithPresetSizes(@NonNull TextView textView, @NonNull int[] iArr, int i) throws IllegalArgumentException {
if (Build.VERSION.SDK_INT >= 27) {
Api26Impl.setAutoSizeTextTypeUniformWithPresetSizes(textView, iArr, i);
} else if (textView instanceof AutoSizeableTextView) {
((AutoSizeableTextView) textView).setAutoSizeTextTypeUniformWithPresetSizes(iArr, i);
}
}
/* JADX WARN: Multi-variable type inference failed */
public static int getAutoSizeTextType(@NonNull TextView textView) {
if (Build.VERSION.SDK_INT >= 27) {
return Api26Impl.getAutoSizeTextType(textView);
}
if (textView instanceof AutoSizeableTextView) {
return ((AutoSizeableTextView) textView).getAutoSizeTextType();
}
return 0;
}
/* JADX WARN: Multi-variable type inference failed */
public static int getAutoSizeStepGranularity(@NonNull TextView textView) {
if (Build.VERSION.SDK_INT >= 27) {
return Api26Impl.getAutoSizeStepGranularity(textView);
}
if (textView instanceof AutoSizeableTextView) {
return ((AutoSizeableTextView) textView).getAutoSizeStepGranularity();
}
return -1;
}
/* JADX WARN: Multi-variable type inference failed */
public static int getAutoSizeMinTextSize(@NonNull TextView textView) {
if (Build.VERSION.SDK_INT >= 27) {
return Api26Impl.getAutoSizeMinTextSize(textView);
}
if (textView instanceof AutoSizeableTextView) {
return ((AutoSizeableTextView) textView).getAutoSizeMinTextSize();
}
return -1;
}
/* JADX WARN: Multi-variable type inference failed */
public static int getAutoSizeMaxTextSize(@NonNull TextView textView) {
if (Build.VERSION.SDK_INT >= 27) {
return Api26Impl.getAutoSizeMaxTextSize(textView);
}
if (textView instanceof AutoSizeableTextView) {
return ((AutoSizeableTextView) textView).getAutoSizeMaxTextSize();
}
return -1;
}
/* JADX WARN: Multi-variable type inference failed */
@NonNull
public static int[] getAutoSizeTextAvailableSizes(@NonNull TextView textView) {
if (Build.VERSION.SDK_INT >= 27) {
return Api26Impl.getAutoSizeTextAvailableSizes(textView);
}
return textView instanceof AutoSizeableTextView ? ((AutoSizeableTextView) textView).getAutoSizeTextAvailableSizes() : new int[0];
}
@ReplaceWith(expression = "textView.setCustomSelectionActionModeCallback(callback)")
@Deprecated
public static void setCustomSelectionActionModeCallback(@NonNull TextView textView, @NonNull ActionMode.Callback callback) {
textView.setCustomSelectionActionModeCallback(wrapCustomSelectionActionModeCallback(textView, callback));
}
@Nullable
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
public static ActionMode.Callback wrapCustomSelectionActionModeCallback(@NonNull TextView textView, @Nullable ActionMode.Callback callback) {
return (Build.VERSION.SDK_INT > 27 || (callback instanceof OreoCallback) || callback == null) ? callback : new OreoCallback(callback, textView);
}
@Nullable
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
public static ActionMode.Callback unwrapCustomSelectionActionModeCallback(@Nullable ActionMode.Callback callback) {
return callback instanceof OreoCallback ? ((OreoCallback) callback).getWrappedCallback() : callback;
}
@RequiresApi(26)
public static class OreoCallback implements ActionMode.Callback {
private static final int MENU_ITEM_ORDER_PROCESS_TEXT_INTENT_ACTIONS_START = 100;
private final ActionMode.Callback mCallback;
private boolean mCanUseMenuBuilderReferences;
private boolean mInitializedMenuBuilderReferences = false;
private Class<?> mMenuBuilderClass;
private Method mMenuBuilderRemoveItemAtMethod;
private final TextView mTextView;
@NonNull
public ActionMode.Callback getWrappedCallback() {
return this.mCallback;
}
public OreoCallback(ActionMode.Callback callback, TextView textView) {
this.mCallback = callback;
this.mTextView = textView;
}
@Override // android.view.ActionMode.Callback
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
return this.mCallback.onCreateActionMode(actionMode, menu);
}
@Override // android.view.ActionMode.Callback
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
recomputeProcessTextMenuItems(menu);
return this.mCallback.onPrepareActionMode(actionMode, menu);
}
@Override // android.view.ActionMode.Callback
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
return this.mCallback.onActionItemClicked(actionMode, menuItem);
}
@Override // android.view.ActionMode.Callback
public void onDestroyActionMode(ActionMode actionMode) {
this.mCallback.onDestroyActionMode(actionMode);
}
private void recomputeProcessTextMenuItems(Menu menu) {
Context context = this.mTextView.getContext();
PackageManager packageManager = context.getPackageManager();
if (!this.mInitializedMenuBuilderReferences) {
this.mInitializedMenuBuilderReferences = true;
try {
Class<?> cls = Class.forName("com.android.internal.view.menu.MenuBuilder");
this.mMenuBuilderClass = cls;
this.mMenuBuilderRemoveItemAtMethod = cls.getDeclaredMethod("removeItemAt", Integer.TYPE);
this.mCanUseMenuBuilderReferences = true;
} catch (ClassNotFoundException | NoSuchMethodException unused) {
this.mMenuBuilderClass = null;
this.mMenuBuilderRemoveItemAtMethod = null;
this.mCanUseMenuBuilderReferences = false;
}
}
try {
Method declaredMethod = (this.mCanUseMenuBuilderReferences && this.mMenuBuilderClass.isInstance(menu)) ? this.mMenuBuilderRemoveItemAtMethod : 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> supportedActivities = getSupportedActivities(context, packageManager);
for (int i = 0; i < supportedActivities.size(); i++) {
ResolveInfo resolveInfo = supportedActivities.get(i);
menu.add(0, 0, i + 100, resolveInfo.loadLabel(packageManager)).setIntent(createProcessTextIntentForResolveInfo(resolveInfo, this.mTextView)).setShowAsAction(1);
}
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException unused2) {
}
}
private List<ResolveInfo> getSupportedActivities(Context context, PackageManager packageManager) {
ArrayList arrayList = new ArrayList();
if (!(context instanceof Activity)) {
return arrayList;
}
for (ResolveInfo resolveInfo : packageManager.queryIntentActivities(createProcessTextIntent(), 0)) {
if (isSupportedActivity(resolveInfo, context)) {
arrayList.add(resolveInfo);
}
}
return arrayList;
}
private boolean isSupportedActivity(ResolveInfo resolveInfo, Context context) {
if (context.getPackageName().equals(resolveInfo.activityInfo.packageName)) {
return true;
}
ActivityInfo activityInfo = resolveInfo.activityInfo;
if (!activityInfo.exported) {
return false;
}
String str = activityInfo.permission;
return str == null || context.checkSelfPermission(str) == 0;
}
private Intent createProcessTextIntentForResolveInfo(ResolveInfo resolveInfo, TextView textView) {
Intent putExtra = createProcessTextIntent().putExtra("android.intent.extra.PROCESS_TEXT_READONLY", !isEditable(textView));
ActivityInfo activityInfo = resolveInfo.activityInfo;
return putExtra.setClassName(activityInfo.packageName, activityInfo.name);
}
private boolean isEditable(TextView textView) {
return (textView instanceof Editable) && textView.onCheckIsTextEditor() && textView.isEnabled();
}
private Intent createProcessTextIntent() {
return new Intent().setAction("android.intent.action.PROCESS_TEXT").setType("text/plain");
}
}
public static void setFirstBaselineToTopHeight(@NonNull TextView textView, @IntRange(from = 0) @Px int i) {
int i2;
Preconditions.checkArgumentNonnegative(i);
if (Build.VERSION.SDK_INT >= 28) {
Api28Impl.setFirstBaselineToTopHeight(textView, i);
return;
}
Paint.FontMetricsInt fontMetricsInt = textView.getPaint().getFontMetricsInt();
if (textView.getIncludeFontPadding()) {
i2 = fontMetricsInt.top;
} else {
i2 = fontMetricsInt.ascent;
}
if (i > Math.abs(i2)) {
textView.setPadding(textView.getPaddingLeft(), i + i2, textView.getPaddingRight(), textView.getPaddingBottom());
}
}
public static void setLastBaselineToBottomHeight(@NonNull TextView textView, @IntRange(from = 0) @Px int i) {
int i2;
Preconditions.checkArgumentNonnegative(i);
Paint.FontMetricsInt fontMetricsInt = textView.getPaint().getFontMetricsInt();
if (textView.getIncludeFontPadding()) {
i2 = fontMetricsInt.bottom;
} else {
i2 = fontMetricsInt.descent;
}
if (i > Math.abs(i2)) {
textView.setPadding(textView.getPaddingLeft(), textView.getPaddingTop(), textView.getPaddingRight(), i - i2);
}
}
public static int getFirstBaselineToTopHeight(@NonNull TextView textView) {
return textView.getPaddingTop() - textView.getPaint().getFontMetricsInt().top;
}
public static int getLastBaselineToBottomHeight(@NonNull TextView textView) {
return textView.getPaddingBottom() + textView.getPaint().getFontMetricsInt().bottom;
}
public static void setLineHeight(@NonNull TextView textView, @IntRange(from = 0) @Px int i) {
Preconditions.checkArgumentNonnegative(i);
if (i != textView.getPaint().getFontMetricsInt(null)) {
textView.setLineSpacing(i - r0, 1.0f);
}
}
public static void setLineHeight(@NonNull TextView textView, int i, @FloatRange(from = 0.0d) float f) {
if (Build.VERSION.SDK_INT >= 34) {
Api34Impl.setLineHeight(textView, i, f);
} else {
setLineHeight(textView, Math.round(TypedValue.applyDimension(i, f, textView.getResources().getDisplayMetrics())));
}
}
@NonNull
public static PrecomputedTextCompat.Params getTextMetricsParams(@NonNull TextView textView) {
if (Build.VERSION.SDK_INT >= 28) {
return new PrecomputedTextCompat.Params(Api28Impl.getTextMetricsParams(textView));
}
PrecomputedTextCompat.Params.Builder builder = new PrecomputedTextCompat.Params.Builder(new TextPaint(textView.getPaint()));
builder.setBreakStrategy(Api23Impl.getBreakStrategy(textView));
builder.setHyphenationFrequency(Api23Impl.getHyphenationFrequency(textView));
builder.setTextDirection(getTextDirectionHeuristic(textView));
return builder.build();
}
public static void setTextMetricsParams(@NonNull TextView textView, @NonNull PrecomputedTextCompat.Params params) {
textView.setTextDirection(getTextDirection(params.getTextDirection()));
textView.getPaint().set(params.getTextPaint());
Api23Impl.setBreakStrategy(textView, params.getBreakStrategy());
Api23Impl.setHyphenationFrequency(textView, params.getHyphenationFrequency());
}
public static void setPrecomputedText(@NonNull TextView textView, @NonNull PrecomputedTextCompat precomputedTextCompat) {
if (Build.VERSION.SDK_INT >= 29) {
textView.setText(Api28Impl.castToCharSequence(precomputedTextCompat.getPrecomputedText()));
} else {
if (!getTextMetricsParams(textView).equalsWithoutTextDirection(precomputedTextCompat.getParams())) {
throw new IllegalArgumentException("Given text can not be applied to TextView.");
}
textView.setText(precomputedTextCompat);
}
}
private static TextDirectionHeuristic getTextDirectionHeuristic(@NonNull TextView textView) {
if (textView.getTransformationMethod() instanceof PasswordTransformationMethod) {
return TextDirectionHeuristics.LTR;
}
if (Build.VERSION.SDK_INT >= 28 && (textView.getInputType() & 15) == 3) {
byte directionality = Character.getDirectionality(Api28Impl.getDigitStrings(Api24Impl.getInstance(textView.getTextLocale()))[0].codePointAt(0));
if (directionality == 1 || directionality == 2) {
return TextDirectionHeuristics.RTL;
}
return TextDirectionHeuristics.LTR;
}
boolean z = textView.getLayoutDirection() == 1;
switch (textView.getTextDirection()) {
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
default:
if (!z) {
break;
} else {
break;
}
}
return TextDirectionHeuristics.LTR;
}
private static int getTextDirection(@NonNull TextDirectionHeuristic textDirectionHeuristic) {
TextDirectionHeuristic textDirectionHeuristic2;
TextDirectionHeuristic textDirectionHeuristic3 = TextDirectionHeuristics.FIRSTSTRONG_RTL;
if (textDirectionHeuristic == textDirectionHeuristic3 || textDirectionHeuristic == (textDirectionHeuristic2 = 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 == textDirectionHeuristic2) {
return 6;
}
return textDirectionHeuristic == textDirectionHeuristic3 ? 7 : 1;
}
public static void setCompoundDrawableTintList(@NonNull TextView textView, @Nullable ColorStateList colorStateList) {
Preconditions.checkNotNull(textView);
Api23Impl.setCompoundDrawableTintList(textView, colorStateList);
}
@Nullable
public static ColorStateList getCompoundDrawableTintList(@NonNull TextView textView) {
Preconditions.checkNotNull(textView);
return Api23Impl.getCompoundDrawableTintList(textView);
}
public static void setCompoundDrawableTintMode(@NonNull TextView textView, @Nullable PorterDuff.Mode mode) {
Preconditions.checkNotNull(textView);
Api23Impl.setCompoundDrawableTintMode(textView, mode);
}
@Nullable
public static PorterDuff.Mode getCompoundDrawableTintMode(@NonNull TextView textView) {
Preconditions.checkNotNull(textView);
return Api23Impl.getCompoundDrawableTintMode(textView);
}
@RequiresApi(26)
public static class Api26Impl {
private Api26Impl() {
}
public static void setAutoSizeTextTypeWithDefaults(TextView textView, int i) {
textView.setAutoSizeTextTypeWithDefaults(i);
}
public static void setAutoSizeTextTypeUniformWithConfiguration(TextView textView, int i, int i2, int i3, int i4) {
textView.setAutoSizeTextTypeUniformWithConfiguration(i, i2, i3, i4);
}
public static void setAutoSizeTextTypeUniformWithPresetSizes(TextView textView, int[] iArr, int i) {
textView.setAutoSizeTextTypeUniformWithPresetSizes(iArr, i);
}
public static int getAutoSizeTextType(TextView textView) {
return textView.getAutoSizeTextType();
}
public static int getAutoSizeStepGranularity(TextView textView) {
return textView.getAutoSizeStepGranularity();
}
public static int getAutoSizeMinTextSize(TextView textView) {
return textView.getAutoSizeMinTextSize();
}
public static int getAutoSizeMaxTextSize(TextView textView) {
return textView.getAutoSizeMaxTextSize();
}
public static int[] getAutoSizeTextAvailableSizes(TextView textView) {
return textView.getAutoSizeTextAvailableSizes();
}
}
@RequiresApi(28)
public static class Api28Impl {
public static CharSequence castToCharSequence(PrecomputedText precomputedText) {
return precomputedText;
}
private Api28Impl() {
}
public static void setFirstBaselineToTopHeight(TextView textView, int i) {
textView.setFirstBaselineToTopHeight(i);
}
public static PrecomputedText.Params getTextMetricsParams(TextView textView) {
return textView.getTextMetricsParams();
}
public static String[] getDigitStrings(DecimalFormatSymbols decimalFormatSymbols) {
return decimalFormatSymbols.getDigitStrings();
}
}
@RequiresApi(23)
public static class Api23Impl {
private Api23Impl() {
}
public static int getBreakStrategy(TextView textView) {
return textView.getBreakStrategy();
}
public static void setBreakStrategy(TextView textView, int i) {
textView.setBreakStrategy(i);
}
public static int getHyphenationFrequency(TextView textView) {
return textView.getHyphenationFrequency();
}
public static void setHyphenationFrequency(TextView textView, int i) {
textView.setHyphenationFrequency(i);
}
public static PorterDuff.Mode getCompoundDrawableTintMode(TextView textView) {
return textView.getCompoundDrawableTintMode();
}
public static ColorStateList getCompoundDrawableTintList(TextView textView) {
return textView.getCompoundDrawableTintList();
}
public static void setCompoundDrawableTintList(TextView textView, ColorStateList colorStateList) {
textView.setCompoundDrawableTintList(colorStateList);
}
public static void setCompoundDrawableTintMode(TextView textView, PorterDuff.Mode mode) {
textView.setCompoundDrawableTintMode(mode);
}
}
@RequiresApi(24)
public static class Api24Impl {
private Api24Impl() {
}
public static DecimalFormatSymbols getInstance(Locale locale) {
return DecimalFormatSymbols.getInstance(locale);
}
}
@RequiresApi(34)
public static class Api34Impl {
private Api34Impl() {
}
public static void setLineHeight(@NonNull TextView textView, int i, @FloatRange(from = 0.0d) float f) {
textView.setLineHeight(i, f);
}
}
}