public static final boolean addJUstHighLightLinks(TextView text, int mask) {
    if (mask == 0) {
      return false;
    }

    CharSequence t = text.getText();

    if (t instanceof Spannable) {
      if (addLinks((Spannable) t, mask)) {
        // addLinkMovementMethod(text);
        return true;
      }

      return false;
    } else {
      SpannableString s = SpannableString.valueOf(t);

      if (addLinks(s, mask)) {
        // addLinkMovementMethod(text);
        text.setText(s);

        return true;
      }

      return false;
    }
  }
예제 #2
0
파일: TextUtil.java 프로젝트: kachi1227/gjk
    /**
     * Scans the text of the provided TextView and turns all occurrences of the link types indicated
     * in the mask into clickable links. If matches are found the movement method for the TextView
     * is set to LinkMovementMethod.
     */
    public static final boolean addLinks(
        TextView text, int mask, Map<Long, Pair<String, Long>> profileMap) {
      if (mask == 0) {
        return false;
      }

      CharSequence t = text.getText();

      if (t instanceof Spannable) {
        if (addLinks((Spannable) t, mask, profileMap)) {
          addLinkMovementMethod(text);
          return true;
        }

        return false;
      } else {
        SpannableString s = SpannableString.valueOf(t);

        if (addLinks(s, mask, profileMap)) {
          addLinkMovementMethod(text);
          text.setText(s);

          return true;
        }

        return false;
      }
    }
        @Override
        public boolean onTouch(View v, MotionEvent event) {

          Layout layout = ((TextView) v).getLayout();

          int x = (int) event.getX();
          int y = (int) event.getY();
          int offset = 0;
          if (layout != null) {

            int line = layout.getLineForVertical(y);
            offset = layout.getOffsetForHorizontal(line, x);
          }

          TextView tv = (TextView) v;
          SpannableString value = SpannableString.valueOf(tv.getText());

          LinkMovementMethod.getInstance().onTouchEvent(tv, value, event);

          switch (event.getActionMasked()) {
            case MotionEvent.ACTION_DOWN:
              WeburlSpan[] urlSpans = value.getSpans(0, value.length(), WeburlSpan.class);
              boolean find = false;
              int findStart = 0;
              int findEnd = 0;
              for (WeburlSpan urlSpan : urlSpans) {
                int start = value.getSpanStart(urlSpan);
                int end = value.getSpanEnd(urlSpan);
                if (start <= offset && offset <= end) {
                  find = true;
                  findStart = start;
                  findEnd = end;

                  break;
                }
              }

              if (find) {
                BackgroundColorSpan bkcolor = new BackgroundColorSpan(0xff89660f);
                value.setSpan(bkcolor, findStart, findEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                ((TextView) v).setText(value);
              }

              return find;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
              BackgroundColorSpan[] backgroundColorSpans =
                  value.getSpans(0, value.length(), BackgroundColorSpan.class);
              for (BackgroundColorSpan bkcolor : backgroundColorSpans) {
                value.removeSpan(bkcolor);
                ((TextView) v).setText(value);
              }
              break;
          }

          return false;
        }
  public static final void addJustHighLightLinks(
      TextView text,
      Pattern p,
      String scheme,
      MatchFilter matchFilter,
      TransformFilter transformFilter) {
    SpannableString s = SpannableString.valueOf(text.getText());

    if (addLinks(s, p, scheme, matchFilter, transformFilter)) {
      text.setText(s);
    }
  }
  public static final SpannableString getJustHighLightLinks(
      CharSequence s,
      Pattern p,
      String scheme,
      MatchFilter matchFilter,
      TransformFilter transformFilter) {
    SpannableString value = SpannableString.valueOf(s);

    if (addLinks(value, p, scheme, matchFilter, transformFilter)) {
      return value;
    }

    return new SpannableString(s);
  }
  public static final SpannableString addJUstHighLightLinks(CharSequence text, int mask) {
    if (mask == 0) {
      return SpannableString.valueOf(text);
    }

    CharSequence t = text;

    if (t instanceof Spannable) {
      if (addLinks((Spannable) t, mask)) {
        // addLinkMovementMethod(text);
        return SpannableString.valueOf(t);
      }

    } else {
      SpannableString s = SpannableString.valueOf(t);

      if (addLinks(s, mask)) {
        // addLinkMovementMethod(text);
        return s;
      }
    }

    return SpannableString.valueOf(text);
  }
예제 #7
0
파일: TextUtil.java 프로젝트: kachi1227/gjk
    public static void removeSpans(TextView textView) {
      CharSequence t = textView.getText();

      if (t instanceof Spannable) {
        Spannable span = (Spannable) t;
        URLSpan[] old = span.getSpans(0, span.length(), URLSpan.class);
        for (int i = old.length - 1; i >= 0; i--) {
          span.removeSpan(old[i]);
        }
      } else {
        SpannableString span = SpannableString.valueOf(t);
        URLSpan[] old = span.getSpans(0, span.length(), URLSpan.class);
        for (int i = old.length - 1; i >= 0; i--) {
          span.removeSpan(old[i]);
        }
      }
    }
 public static Spannable a(CharSequence paramCharSequence, int paramInt)
 {
   int k = 0;
   SpannableString localSpannableString = SpannableString.valueOf(paramCharSequence);
   StyleSpan[] arrayOfStyleSpan = (StyleSpan[])localSpannableString.getSpans(0, localSpannableString.length(), StyleSpan.class);
   paramCharSequence = arrayOfStyleSpan;
   if (arrayOfStyleSpan.length == 0)
   {
     localSpannableString.setSpan(new StyleSpan(1), 0, localSpannableString.length(), 33);
     paramCharSequence = (StyleSpan[])localSpannableString.getSpans(0, localSpannableString.length(), StyleSpan.class);
   }
   int m = paramCharSequence.length;
   while (k < m)
   {
     arrayOfStyleSpan = paramCharSequence[k];
     if (arrayOfStyleSpan.getStyle() == 1) {
       StringUtils.a(localSpannableString, arrayOfStyleSpan, new ForegroundColorSpan(paramInt));
     }
     k += 1;
   }
   return localSpannableString;
 }