LinkifyCompat.java 11.8 KB
package android.support.v4.text.util;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.util.PatternsCompat;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.method.MovementMethod;
import android.text.style.URLSpan;
import android.text.util.Linkify;
import android.text.util.Linkify.MatchFilter;
import android.text.util.Linkify.TransformFilter;
import android.webkit.WebView;
import android.widget.TextView;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class LinkifyCompat
{
  private static final String[] a = new String[0];
  private static final Comparator<a> b = new Comparator() {};
  
  private static String a(@NonNull String paramString, @NonNull String[] paramArrayOfString, Matcher paramMatcher, @Nullable Linkify.TransformFilter paramTransformFilter)
  {
    int k = 1;
    if (paramTransformFilter != null) {}
    for (paramMatcher = paramTransformFilter.transformUrl(paramMatcher, paramString);; paramMatcher = paramString)
    {
      int i = 0;
      int j;
      if (i < paramArrayOfString.length) {
        if (paramMatcher.regionMatches(true, 0, paramArrayOfString[i], 0, paramArrayOfString[i].length()))
        {
          paramString = paramMatcher;
          j = k;
          if (!paramMatcher.regionMatches(false, 0, paramArrayOfString[i], 0, paramArrayOfString[i].length()))
          {
            paramString = paramArrayOfString[i] + paramMatcher.substring(paramArrayOfString[i].length());
            j = k;
          }
        }
      }
      for (;;)
      {
        paramMatcher = paramString;
        if (j == 0)
        {
          paramMatcher = paramString;
          if (paramArrayOfString.length > 0) {
            paramMatcher = paramArrayOfString[0] + paramString;
          }
        }
        return paramMatcher;
        i += 1;
        break;
        j = 0;
        paramString = paramMatcher;
      }
    }
  }
  
  private static void a(@NonNull TextView paramTextView)
  {
    MovementMethod localMovementMethod = paramTextView.getMovementMethod();
    if (((localMovementMethod == null) || (!(localMovementMethod instanceof LinkMovementMethod))) && (paramTextView.getLinksClickable())) {
      paramTextView.setMovementMethod(LinkMovementMethod.getInstance());
    }
  }
  
  private static void a(String paramString, int paramInt1, int paramInt2, Spannable paramSpannable)
  {
    paramSpannable.setSpan(new URLSpan(paramString), paramInt1, paramInt2, 33);
  }
  
  private static final void a(ArrayList<a> paramArrayList, Spannable paramSpannable)
  {
    paramSpannable = paramSpannable.toString();
    int i = 0;
    for (;;)
    {
      try
      {
        str = WebView.findAddress(paramSpannable);
        if (str != null)
        {
          int j = paramSpannable.indexOf(str);
          if (j >= 0)
          {
            locala = new a();
            int k = str.length() + j;
            locala.c = (j + i);
            locala.d = (i + k);
            paramSpannable = paramSpannable.substring(k);
            i += k;
          }
        }
      }
      catch (UnsupportedOperationException paramArrayList)
      {
        try
        {
          a locala;
          String str = URLEncoder.encode(str, "UTF-8");
          locala.b = ("geo:0,0?q=" + str);
          paramArrayList.add(locala);
        }
        catch (UnsupportedEncodingException localUnsupportedEncodingException) {}
        paramArrayList = paramArrayList;
      }
      return;
    }
  }
  
  private static void a(ArrayList<a> paramArrayList, Spannable paramSpannable, Pattern paramPattern, String[] paramArrayOfString, Linkify.MatchFilter paramMatchFilter)
  {
    paramPattern = paramPattern.matcher(paramSpannable);
    while (paramPattern.find())
    {
      int i = paramPattern.start();
      int j = paramPattern.end();
      if ((paramMatchFilter == null) || (paramMatchFilter.acceptMatch(paramSpannable, i, j)))
      {
        a locala = new a();
        locala.b = a(paramPattern.group(0), paramArrayOfString, paramPattern, null);
        locala.c = i;
        locala.d = j;
        paramArrayList.add(locala);
      }
    }
  }
  
  public static final void addLinks(@NonNull TextView paramTextView, @NonNull Pattern paramPattern, @Nullable String paramString)
  {
    addLinks(paramTextView, paramPattern, paramString, null, null, null);
  }
  
  public static final void addLinks(@NonNull TextView paramTextView, @NonNull Pattern paramPattern, @Nullable String paramString, @Nullable Linkify.MatchFilter paramMatchFilter, @Nullable Linkify.TransformFilter paramTransformFilter)
  {
    addLinks(paramTextView, paramPattern, paramString, null, paramMatchFilter, paramTransformFilter);
  }
  
  public static final void addLinks(@NonNull TextView paramTextView, @NonNull Pattern paramPattern, @Nullable String paramString, @Nullable String[] paramArrayOfString, @Nullable Linkify.MatchFilter paramMatchFilter, @Nullable Linkify.TransformFilter paramTransformFilter)
  {
    SpannableString localSpannableString = SpannableString.valueOf(paramTextView.getText());
    if (addLinks(localSpannableString, paramPattern, paramString, paramArrayOfString, paramMatchFilter, paramTransformFilter))
    {
      paramTextView.setText(localSpannableString);
      a(paramTextView);
    }
  }
  
  public static final boolean addLinks(@NonNull Spannable paramSpannable, int paramInt)
  {
    if (paramInt == 0) {
      return false;
    }
    Object localObject1 = (URLSpan[])paramSpannable.getSpans(0, paramSpannable.length(), URLSpan.class);
    int i = localObject1.length - 1;
    while (i >= 0)
    {
      paramSpannable.removeSpan(localObject1[i]);
      i -= 1;
    }
    if ((paramInt & 0x4) != 0) {
      Linkify.addLinks(paramSpannable, 4);
    }
    localObject1 = new ArrayList();
    Object localObject2;
    if ((paramInt & 0x1) != 0)
    {
      localObject2 = PatternsCompat.AUTOLINK_WEB_URL;
      Linkify.MatchFilter localMatchFilter = Linkify.sUrlMatchFilter;
      a((ArrayList)localObject1, paramSpannable, (Pattern)localObject2, new String[] { "http://", "https://", "rtsp://" }, localMatchFilter);
    }
    if ((paramInt & 0x2) != 0) {
      a((ArrayList)localObject1, paramSpannable, PatternsCompat.AUTOLINK_EMAIL_ADDRESS, new String[] { "mailto:" }, null);
    }
    if ((paramInt & 0x8) != 0) {
      a((ArrayList)localObject1, paramSpannable);
    }
    b((ArrayList)localObject1, paramSpannable);
    if (((ArrayList)localObject1).size() == 0) {
      return false;
    }
    localObject1 = ((ArrayList)localObject1).iterator();
    while (((Iterator)localObject1).hasNext())
    {
      localObject2 = (a)((Iterator)localObject1).next();
      if (((a)localObject2).a == null) {
        a(((a)localObject2).b, ((a)localObject2).c, ((a)localObject2).d, paramSpannable);
      }
    }
    return true;
  }
  
  public static final boolean addLinks(@NonNull Spannable paramSpannable, @NonNull Pattern paramPattern, @Nullable String paramString)
  {
    return addLinks(paramSpannable, paramPattern, paramString, null, null, null);
  }
  
  public static final boolean addLinks(@NonNull Spannable paramSpannable, @NonNull Pattern paramPattern, @Nullable String paramString, @Nullable Linkify.MatchFilter paramMatchFilter, @Nullable Linkify.TransformFilter paramTransformFilter)
  {
    return addLinks(paramSpannable, paramPattern, paramString, null, paramMatchFilter, paramTransformFilter);
  }
  
  public static final boolean addLinks(@NonNull Spannable paramSpannable, @NonNull Pattern paramPattern, @Nullable String paramString, @Nullable String[] paramArrayOfString, @Nullable Linkify.MatchFilter paramMatchFilter, @Nullable Linkify.TransformFilter paramTransformFilter)
  {
    String str = paramString;
    if (paramString == null) {
      str = "";
    }
    if (paramArrayOfString != null)
    {
      paramString = paramArrayOfString;
      if (paramArrayOfString.length > 0) {}
    }
    else
    {
      paramString = a;
    }
    String[] arrayOfString = new String[paramString.length + 1];
    arrayOfString[0] = str.toLowerCase(Locale.ROOT);
    int i = 0;
    if (i < paramString.length)
    {
      paramArrayOfString = paramString[i];
      if (paramArrayOfString == null) {}
      for (paramArrayOfString = "";; paramArrayOfString = paramArrayOfString.toLowerCase(Locale.ROOT))
      {
        arrayOfString[(i + 1)] = paramArrayOfString;
        i += 1;
        break;
      }
    }
    paramPattern = paramPattern.matcher(paramSpannable);
    boolean bool1 = false;
    label181:
    label185:
    for (;;)
    {
      int j;
      if (paramPattern.find())
      {
        i = paramPattern.start();
        j = paramPattern.end();
        if (paramMatchFilter == null) {
          break label181;
        }
      }
      for (boolean bool2 = paramMatchFilter.acceptMatch(paramSpannable, i, j);; bool2 = true)
      {
        if (!bool2) {
          break label185;
        }
        a(a(paramPattern.group(0), arrayOfString, paramPattern, paramTransformFilter), i, j, paramSpannable);
        bool1 = true;
        break;
        return bool1;
      }
    }
  }
  
  public static final boolean addLinks(@NonNull TextView paramTextView, int paramInt)
  {
    if (paramInt == 0) {
      return false;
    }
    Object localObject = paramTextView.getText();
    if ((localObject instanceof Spannable))
    {
      if (addLinks((Spannable)localObject, paramInt))
      {
        a(paramTextView);
        return true;
      }
      return false;
    }
    localObject = SpannableString.valueOf((CharSequence)localObject);
    if (addLinks((Spannable)localObject, paramInt))
    {
      a(paramTextView);
      paramTextView.setText((CharSequence)localObject);
      return true;
    }
    return false;
  }
  
  private static final void b(ArrayList<a> paramArrayList, Spannable paramSpannable)
  {
    int j = 0;
    Object localObject = (URLSpan[])paramSpannable.getSpans(0, paramSpannable.length(), URLSpan.class);
    int i = 0;
    a locala;
    while (i < localObject.length)
    {
      locala = new a();
      locala.a = localObject[i];
      locala.c = paramSpannable.getSpanStart(localObject[i]);
      locala.d = paramSpannable.getSpanEnd(localObject[i]);
      paramArrayList.add(locala);
      i += 1;
    }
    Collections.sort(paramArrayList, b);
    int k = paramArrayList.size();
    if (j < k - 1)
    {
      localObject = (a)paramArrayList.get(j);
      locala = (a)paramArrayList.get(j + 1);
      if ((((a)localObject).c <= locala.c) && (((a)localObject).d > locala.c)) {
        if (locala.d <= ((a)localObject).d) {
          i = j + 1;
        }
      }
    }
    for (;;)
    {
      if (i != -1)
      {
        localObject = ((a)paramArrayList.get(i)).a;
        if (localObject != null) {
          paramSpannable.removeSpan(localObject);
        }
        paramArrayList.remove(i);
        k -= 1;
        break;
        if (((a)localObject).d - ((a)localObject).c > locala.d - locala.c)
        {
          i = j + 1;
          continue;
        }
        if (((a)localObject).d - ((a)localObject).c >= locala.d - locala.c) {
          break label295;
        }
        i = j;
        continue;
      }
      j += 1;
      break;
      return;
      label295:
      i = -1;
    }
  }
  
  @Retention(RetentionPolicy.SOURCE)
  public static @interface LinkifyMask {}
  
  static final class a
  {
    URLSpan a;
    String b;
    int c;
    int d;
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/android/support/v4/text/util/LinkifyCompat.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */