Example usage for android.widget TextView setMovementMethod

List of usage examples for android.widget TextView setMovementMethod

Introduction

In this page you can find the example usage for android.widget TextView setMovementMethod.

Prototype

public final void setMovementMethod(MovementMethod movement) 

Source Link

Document

Sets the android.text.method.MovementMethod for handling arrow key movement for this TextView.

Usage

From source file:Main.java

public static void setClickable(final TextView textView) {
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    Spannable sp = (Spannable) textView.getText();
    ImageSpan[] images = sp.getSpans(0, textView.getText().length(), ImageSpan.class);

    for (ImageSpan span : images) {
        final String image_src = span.getSource();
        final int start = sp.getSpanStart(span);
        final int end = sp.getSpanEnd(span);

        ClickableSpan click_span = new ClickableSpan() {
            @Override/*from   w  ww. ja v a 2s  .  c o  m*/
            public void onClick(View widget) {
                String[] strs = image_src.split("/");
                String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/LilyClient/"
                        + strs[strs.length - 2] + "-" + strs[strs.length - 1];

                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setType("image/*");
                intent.setDataAndType(Uri.fromFile(new File(filePath)), "image/*");
                textView.getContext().startActivity(intent);

            }
        };
        ClickableSpan[] click_spans = sp.getSpans(start, end, ClickableSpan.class);
        if (click_spans.length != 0) {
            for (ClickableSpan c_span : click_spans) {
                sp.removeSpan(c_span);
            }
        }
        sp.setSpan(click_span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}

From source file:Main.java

private static void createLink(View v, int id, String html) {
    TextView textView = (TextView) v.findViewById(id);
    textView.setClickable(true);/*from w ww.  j av  a2  s . com*/
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    textView.setText(Html.fromHtml(html));
}

From source file:Main.java

public static void linkify(View view, int widgetId) {
    TextView textview = (TextView) view.findViewById(widgetId);
    if (textview != null) {
        textview.setMovementMethod(LinkMovementMethod.getInstance());
    } else {/*from  w  ww .j  a  v a2s  .c  o m*/
        Log.d(TAG, "NO " + widgetId);
    }
}

From source file:Main.java

/**
 * Make UI TextView a html link./*from   w  ww . j ava  2s  .co  m*/
 * 
 * @param context the context
 * @param textView the text view
 * @param html the html containing link info
 */
public static void makeTextViewAHTMLLink(final Context context, TextView textView, String html) {
    textView.setLinksClickable(true);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    CharSequence sequence = Html.fromHtml(html);
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(sequence);
    URLSpan[] urls = spannableStringBuilder.getSpans(0, sequence.length(), URLSpan.class);
    for (final URLSpan urlSpan : urls) {
        int start = spannableStringBuilder.getSpanStart(urlSpan);
        int end = spannableStringBuilder.getSpanEnd(urlSpan);
        int flags = spannableStringBuilder.getSpanFlags(urlSpan);
        ClickableSpan clickable = new ClickableSpan() {
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlSpan.getURL()));
                context.startActivity(intent);
            }

            @Override
            public void updateDrawState(TextPaint textPaint) {
                super.updateDrawState(textPaint);
                textPaint.setUnderlineText(false);
            }
        };
        spannableStringBuilder.removeSpan(urlSpan);
        spannableStringBuilder.setSpan(clickable, start, end, flags);
    }
    textView.setText(spannableStringBuilder);
}

From source file:com.microsoft.mimickeralarm.utilities.GeneralUtilities.java

public static void enableLinks(TextView view) {
    if (view != null) {
        view.setMovementMethod(LinkMovementMethod.getInstance());
        GeneralUtilities.stripUnderlines(view);
    }//from w  ww .j a  v a  2 s.  co m
}

From source file:Main.java

/**
 * Populate the given {@link TextView} with the requested text, formatting
 * through {@link Html#fromHtml(String)} when applicable. Also sets
 * {@link TextView#setMovementMethod} so inline links are handled.
 *//*from  ww  w.j  a  v  a2 s.  co m*/
public static void setTextMaybeHtml(TextView view, String text) {
    if (TextUtils.isEmpty(text)) {
        view.setText("");
        return;
    }
    if (text.contains("<") && text.contains(">")) {
        view.setText(Html.fromHtml(text));
        view.setMovementMethod(LinkMovementMethod.getInstance());
    } else {
        view.setText(text);
    }
}

From source file:Main.java

public static void buildLink(TextView view, String url) {
    Log.d(TAG, "buildLink(view = " + view + ", url = " + url + ")");

    StringBuilder sb = new StringBuilder();
    sb.append("<a href='").append(url).append("'>").append(view.getText()).append("</a>");
    view.setText(Html.fromHtml(sb.toString()));
    view.setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:Main.java

/**
 * Populate the given {@link TextView} with the requested text, formatting
 * through {@link Html#fromHtml(String)} when applicable. Also sets
 * {@link TextView#setMovementMethod} so inline links are handled.
 *///from ww w  . ja  v a2  s  .  c om
public static void setTextMaybeHtml(TextView view, String text) {
    if (TextUtils.isEmpty(text)) {
        view.setText("");
        return;
    }
    if ((text.contains("<") && text.contains(">")) || REGEX_HTML_ESCAPE.matcher(text).find()) {
        view.setText(Html.fromHtml(text));
        view.setMovementMethod(LinkMovementMethod.getInstance());
    } else {
        view.setText(text);
    }
}

From source file:com.memetro.android.alerts.CommentDialog.java

public static void showDialog(final Context context, String comment, String creator, boolean isMine,
        final Long id) {

    final Dialog mDialog = new Dialog(context);
    mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mDialog.setContentView(R.layout.comment_dialog);
    mDialog.setCancelable(true);//ww w.j a  v  a  2 s  .  c o  m

    TextView titleText = (TextView) mDialog.findViewById(R.id.title);
    TextView messageText = (TextView) mDialog.findViewById(R.id.message);
    Button closeButton = (Button) mDialog.findViewById(R.id.close);
    Button deleteButton = (Button) mDialog.findViewById(R.id.delete);

    titleText.setText(titleText.getText().toString() + " " + creator);
    messageText.setMovementMethod(ScrollingMovementMethod.getInstance());
    messageText.setText(comment);

    if (isMine) {
        deleteButton.setVisibility(View.VISIBLE);
        deleteButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new DeleteInBg(context, String.valueOf(id)).execute();
                mDialog.dismiss();
                // TODO Refrescar las alertas
            }
        });
    }

    closeButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mDialog.dismiss();
        }
    });

    mDialog.show();

}

From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java

private static TextView getTextView(Context context, LinearLayout.LayoutParams params, StringBuffer buffer) {
    TextView textView = new TextView(context);
    textView.setTextColor(Color.BLACK);
    textView.setLayoutParams(params);/*from w w  w .  j  av  a 2 s  .c  o  m*/
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    textView.setTextSize(getTextSize(context));
    textView.setText(Html.fromHtml(buffer.toString()));
    return textView;
}