content: package androidx.core.text;
  
  import android.os.Build;
  import android.text.Layout;
  import android.text.PrecomputedText;
  import android.text.Spannable;
  import android.text.SpannableString;
  import android.text.StaticLayout;
  import android.text.TextDirectionHeuristic;
  import android.text.TextDirectionHeuristics;
  import android.text.TextPaint;
  import android.text.TextUtils;
  import android.text.style.MetricAffectingSpan;
  import androidx.core.os.TraceCompat;
  import androidx.core.util.ObjectsCompat;
  import androidx.core.util.Preconditions;
  import java.util.ArrayList;
  import java.util.concurrent.Callable;
  import java.util.concurrent.Executor;
  import java.util.concurrent.Executors;
  import java.util.concurrent.Future;
  import java.util.concurrent.FutureTask;
  
  public class PrecomputedTextCompat implements Spannable {
      private static final char LINE_FEED = '\n';
      private static Executor sExecutor = null;
      private static final Object sLock = new Object();
      private final int[] mParagraphEnds;
      private final Params mParams;
      private final Spannable mText;
      private final PrecomputedText mWrapped;
  
      public static final class Params {
          private final int mBreakStrategy;
          private final int mHyphenationFrequency;
          private final TextPaint mPaint;
          private final TextDirectionHeuristic mTextDir;
          final PrecomputedText.Params mWrapped;
  
          public static class Builder {
              private int mBreakStrategy;
              private int mHyphenationFrequency;
              private final TextPaint mPaint;
              private TextDirectionHeuristic mTextDir;
  
              public Builder(TextPaint paint) {
                  this.mPaint = paint;
                  if (Build.VERSION.SDK_INT >= 23) {
                      this.mBreakStrategy = 1;
                      this.mHyphenationFrequency = 1;
                  } else {
                      this.mHyphenationFrequency = 0;
                      this.mBreakStrategy = 0;
                  }
                  if (Build.VERSION.SDK_INT >= 18) {
                      this.mTextDir = TextDirectionHeuristics.FIRSTSTRONG_LTR;
                  } else {
                      this.mTextDir = null;
                  }
              }
  
              public Params build() {
                  return new Params(this.mPaint, this.mTextDir, this.mBreakStrategy, this.mHyphenationFrequency);
              }
  
              public Builder setBreakStrategy(int strategy) {
                  this.mBreakStrategy = strategy;
                  return this;
              }
  
              public Builder setHyphenationFrequency(int frequency) {
                  this.mHyphenationFrequency = frequency;
                  return this;
              }
  
              public Builder setTextDirection(TextDirectionHeuristic textDir) {
                  this.mTextDir = textDir;
                  return this;
              }
          }
  
          public Params(PrecomputedText.Params wrapped) {
              this.mPaint = wrapped.getTextPaint();
              this.mTextDir = wrapped.getTextDirection();
              this.mBreakStrategy = wrapped.getBreakStrategy();
              this.mHyphenationFrequency = wrapped.getHyphenationFrequency();
              this.mWrapped = Build.VERSION.SDK_INT >= 29 ? wrapped : null;
          }
  
          Params(TextPaint paint, TextDirectionHeuristic textDir, int strategy, int frequency) {
              if (Build.VERSION.SDK_INT >= 29) {
                  this.mWrapped = new PrecomputedText.Params.Builder(paint).setBreakStrategy(strategy).setHyphenationFrequency(frequency).setTextDirection(textDir).build();
              } else {
                  this.mWrapped = null;
              }
              this.mPaint = paint;
              this.mTextDir = textDir;
              this.mBreakStrategy = strategy;
              this.mHyphenationFrequency = frequency;
          }
  
          public boolean equals(Object o) {
              if (o == this) {
                  return true;
              }
              if (!(o instanceof Params)) {
                  return false;
              }
              Params params = (Params) o;
              if (!equalsWithoutTextDirection(params)) {
                  return false;
              }
              return Build.VERSION.SDK_INT < 18 || this.mTextDir == params.getTextDirection();
          }
  
          public boolean equalsWithoutTextDirection(Params other) {
              if ((Build.VERSION.SDK_INT >= 23 && (this.mBreakStrategy != other.getBreakStrategy() || this.mHyphenationFrequency != other.getHyphenationFrequency())) || this.mPaint.getTextSize() != other.getTextPaint().getTextSize() || this.mPaint.getTextScaleX() != other.getTextPaint().getTextScaleX() || this.mPaint.getTextSkewX() != other.getTextPaint().getTextSkewX()) {
                  return false;
              }
              if ((Build.VERSION.SDK_INT >= 21 && (this.mPaint.getLetterSpacing() != other.getTextPaint().getLetterSpacing() || !TextUtils.equals(this.mPaint.getFontFeatureSettings(), other.getTextPaint().getFontFeatureSettings()))) || this.mPaint.getFlags() != other.getTextPaint().getFlags()) {
                  return false;
              }
              if (Build.VERSION.SDK_INT >= 24) {
                  if (!this.mPaint.getTextLocales().equals(other.getTextPaint().getTextLocales())) {
                      return false;
                  }
              } else if (Build.VERSION.SDK_INT >= 17 && !this.mPaint.getTextLocale().equals(other.getTextPaint().getTextLocale())) {
                  return false;
              }
              return this.mPaint.getTypeface() == null ? other.getTextPaint().getTypeface() == null : this.mPaint.getTypeface().equals(other.getTextPaint().getTypeface());
          }
  
          public int getBreakStrategy() {
              return this.mBreakStrategy;
          }
  
          public int getHyphenationFrequency() {
              return this.mHyphenationFrequency;
          }
  
          public TextDirectionHeuristic getTextDirection() {
              return this.mTextDir;
          }
  
          public TextPaint getTextPaint() {
              return this.mPaint;
          }
  
          public int hashCode() {
              if (Build.VERSION.SDK_INT >= 24) {
                  return ObjectsCompat.hash(Float.valueOf(this.mPaint.getTextSize()), Float.valueOf(this.mPaint.getTextScaleX()), Float.valueOf(this.mPaint.getTextSkewX()), Float.valueOf(this.mPaint.getLetterSpacing()), Integer.valueOf(this.mPaint.getFlags()), this.mPaint.getTextLocales(), this.mPaint.getTypeface(), Boolean.valueOf(this.mPaint.isElegantTextHeight()), this.mTextDir, Integer.valueOf(this.mBreakStrategy), Integer.valueOf(this.mHyphenationFrequency));
              } else if (Build.VERSION.SDK_INT >= 21) {
                  return ObjectsCompat.hash(Float.valueOf(this.mPaint.getTextSize()), Float.valueOf(this.mPaint.getTextScaleX()), Float.valueOf(this.mPaint.getTextSkewX()), Float.valueOf(this.mPaint.getLetterSpacing()), Integer.valueOf(this.mPaint.getFlags()), this.mPaint.getTextLocale(), this.mPaint.getTypeface(), Boolean.valueOf(this.mPaint.isElegantTextHeight()), this.mTextDir, Integer.valueOf(this.mBreakStrategy), Integer.valueOf(this.mHyphenationFrequency));
              } else if (Build.VERSION.SDK_INT >= 18) {
                  return ObjectsCompat.hash(Float.valueOf(this.mPaint.getTextSize()), Float.valueOf(this.mPaint.getTextScaleX()), Float.valueOf(this.mPaint.getTextSkewX()), Integer.valueOf(this.mPaint.getFlags()), this.mPaint.getTextLocale(), this.mPaint.getTypeface(), this.mTextDir, Integer.valueOf(this.mBreakStrategy), Integer.valueOf(this.mHyphenationFrequency));
              } else if (Build.VERSION.SDK_INT >= 17) {
                  return ObjectsCompat.hash(Float.valueOf(this.mPaint.getTextSize()), Float.valueOf(this.mPaint.getTextScaleX()), Float.valueOf(this.mPaint.getTextSkewX()), Integer.valueOf(this.mPaint.getFlags()), this.mPaint.getTextLocale(), this.mPaint.getTypeface(), this.mTextDir, Integer.valueOf(this.mBreakStrategy), Integer.valueOf(this.mHyphenationFrequency));
              } else {
                  return ObjectsCompat.hash(Float.valueOf(this.mPaint.getTextSize()), Float.valueOf(this.mPaint.getTextScaleX()), Float.valueOf(this.mPaint.getTextSkewX()), Integer.valueOf(this.mPaint.getFlags()), this.mPaint.getTypeface(), this.mTextDir, Integer.valueOf(this.mBreakStrategy), Integer.valueOf(this.mHyphenationFrequency));
              }
          }
  
          public String toString() {
              StringBuilder sb = new StringBuilder("{");
              sb.append("textSize=" + this.mPaint.getTextSize());
              sb.append(", textScaleX=" + this.mPaint.getTextScaleX());
              sb.append(", textSkewX=" + this.mPaint.getTextSkewX());
              if (Build.VERSION.SDK_INT >= 21) {
                  sb.append(", letterSpacing=" + this.mPaint.getLetterSpacing());
                  sb.append(", elegantTextHeight=" + this.mPaint.isElegantTextHeight());
              }
              if (Build.VERSION.SDK_INT >= 24) {
                  sb.append(", textLocale=" + this.mPaint.getTextLocales());
              } else if (Build.VERSION.SDK_INT >= 17) {
                  sb.append(", textLocale=" + this.mPaint.getTextLocale());
              }
              sb.append(", typeface=" + this.mPaint.getTypeface());
              if (Build.VERSION.SDK_INT >= 26) {
                  sb.append(", variationSettings=" + this.mPaint.getFontVariationSettings());
              }
              sb.append(", textDir=" + this.mTextDir);
              sb.append(", breakStrategy=" + this.mBreakStrategy);
              sb.append(", hyphenationFrequency=" + this.mHyphenationFrequency);
              sb.append("}");
              return sb.toString();
          }
      }
  
      private static class PrecomputedTextFutureTask extends FutureTask<PrecomputedTextCompat> {
  
          private static class PrecomputedTextCallback implements Callable<PrecomputedTextCompat> {
              private Params mParams;
              private CharSequence mText;
  
              PrecomputedTextCallback(Params params, CharSequence cs) {
                  this.mParams = params;
                  this.mText = cs;
              }
  
              public PrecomputedTextCompat call() throws Exception {
                  return PrecomputedTextCompat.create(this.mText, this.mParams);
              }
          }
  
          PrecomputedTextFutureTask(Params params, CharSequence text) {
              super(new PrecomputedTextCallback(params, text));
          }
      }
  
      private PrecomputedTextCompat(PrecomputedText precomputed, Params params) {
          this.mText = precomputed;
          this.mParams = params;
          PrecomputedText precomputedText = null;
          this.mParagraphEnds = null;
          this.mWrapped = Build.VERSION.SDK_INT >= 29 ? precomputed : precomputedText;
      }
  
      private PrecomputedTextCompat(CharSequence text, Params params, int[] paraEnds) {
          this.mText = new SpannableString(text);
          this.mParams = params;
          this.mParagraphEnds = paraEnds;
          this.mWrapped = null;
      }
  
      public static PrecomputedTextCompat create(CharSequence text, Params params) {
          Preconditions.checkNotNull(text);
          Preconditions.checkNotNull(params);
          try {
              TraceCompat.beginSection("PrecomputedText");
              if (Build.VERSION.SDK_INT >= 29 && params.mWrapped != null) {
                  return new PrecomputedTextCompat(PrecomputedText.create(text, params.mWrapped), params);
              }
              ArrayList arrayList = new ArrayList();
              int length = text.length();
              int i = 0;
              while (i < length) {
                  int indexOf = TextUtils.indexOf(text, LINE_FEED, i, length);
                  int i2 = indexOf < 0 ? length : indexOf + 1;
                  arrayList.add(Integer.valueOf(i2));
                  i = i2;
              }
              int[] iArr = new int[arrayList.size()];
              for (int i3 = 0; i3 < arrayList.size(); i3++) {
                  iArr[i3] = ((Integer) arrayList.get(i3)).intValue();
              }
              if (Build.VERSION.SDK_INT >= 23) {
                  StaticLayout.Builder.obtain(text, 0, text.length(), params.getTextPaint(), Integer.MAX_VALUE).setBreakStrategy(params.getBreakStrategy()).setHyphenationFrequency(params.getHyphenationFrequency()).setTextDirection(params.getTextDirection()).build();
              } else if (Build.VERSION.SDK_INT >= 21) {
                  new StaticLayout(text, params.getTextPaint(), Integer.MAX_VALUE, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
              }
              PrecomputedTextCompat precomputedTextCompat = new PrecomputedTextCompat(text, params, iArr);
              TraceCompat.endSection();
              return precomputedTextCompat;
          } finally {
              TraceCompat.endSection();
          }
      }
  
      public static Future<PrecomputedTextCompat> getTextFuture(CharSequence charSequence, Params params, Executor executor) {
          PrecomputedTextFutureTask precomputedTextFutureTask = new PrecomputedTextFutureTask(params, charSequence);
          if (executor == null) {
              synchronized (sLock) {
                  if (sExecutor == null) {
                      sExecutor = Executors.newFixedThreadPool(1);
                  }
                  executor = sExecutor;
              }
          }
          executor.execute(precomputedTextFutureTask);
          return precomputedTextFutureTask;
      }
  
      public char charAt(int index) {
          return this.mText.charAt(index);
      }
  
      public int getParagraphCount() {
          return Build.VERSION.SDK_INT >= 29 ? this.mWrapped.getParagraphCount() : this.mParagraphEnds.length;
      }
  
      public int getParagraphEnd(int paraIndex) {
          Preconditions.checkArgumentInRange(paraIndex, 0, getParagraphCount(), "paraIndex");
          return Build.VERSION.SDK_INT >= 29 ? this.mWrapped.getParagraphEnd(paraIndex) : this.mParagraphEnds[paraIndex];
      }
  
      public int getParagraphStart(int paraIndex) {
          Preconditions.checkArgumentInRange(paraIndex, 0, getParagraphCount(), "paraIndex");
          if (Build.VERSION.SDK_INT >= 29) {
              return this.mWrapped.getParagraphStart(paraIndex);
          }
          if (paraIndex == 0) {
              return 0;
          }
          return this.mParagraphEnds[paraIndex - 1];
      }
  
      public Params getParams() {
          return this.mParams;
      }
  
      public PrecomputedText getPrecomputedText() {
          Spannable spannable = this.mText;
          if (spannable instanceof PrecomputedText) {
              return (PrecomputedText) spannable;
          }
          return null;
      }
  
      public int getSpanEnd(Object tag) {
          return this.mText.getSpanEnd(tag);
      }
  
      public int getSpanFlags(Object tag) {
          return this.mText.getSpanFlags(tag);
      }
  
      public int getSpanStart(Object tag) {
          return this.mText.getSpanStart(tag);
      }
  
      public <T> T[] getSpans(int start, int end, Class<T> cls) {
          return Build.VERSION.SDK_INT >= 29 ? this.mWrapped.getSpans(start, end, cls) : this.mText.getSpans(start, end, cls);
      }
  
      public int length() {
          return this.mText.length();
      }
  
      public int nextSpanTransition(int start, int limit, Class type) {
          return this.mText.nextSpanTransition(start, limit, type);
      }
  
      public void removeSpan(Object what) {
          if (what instanceof MetricAffectingSpan) {
              throw new IllegalArgumentException("MetricAffectingSpan can not be removed from PrecomputedText.");
          } else if (Build.VERSION.SDK_INT >= 29) {
              this.mWrapped.removeSpan(what);
          } else {
              this.mText.removeSpan(what);
          }
      }
  
      public void setSpan(Object what, int start, int end, int flags) {
          if (what instanceof MetricAffectingSpan) {
              throw new IllegalArgumentException("MetricAffectingSpan can not be set to PrecomputedText.");
          } else if (Build.VERSION.SDK_INT >= 29) {
              this.mWrapped.setSpan(what, start, end, flags);
          } else {
              this.mText.setSpan(what, start, end, flags);
          }
      }
  
      public CharSequence subSequence(int start, int end) {
          return this.mText.subSequence(start, end);
      }
  
      public String toString() {
          return this.mText.toString();
      }
  }
  