Example usage for android.text.method LinkMovementMethod getInstance

List of usage examples for android.text.method LinkMovementMethod getInstance

Introduction

In this page you can find the example usage for android.text.method LinkMovementMethod getInstance.

Prototype

public static MovementMethod getInstance() 

Source Link

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/*  w w  w .  j a v  a2  s  .co  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

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

private static void createLink(View v, int id, String html) {
    TextView textView = (TextView) v.findViewById(id);
    textView.setClickable(true);/*from  www  . j a  v a 2 s .  co  m*/
    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  .  ja  v  a2  s  .  c  om
        Log.d(TAG, "NO " + widgetId);
    }
}

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.
 */// www .j  ava 2s.  com
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

/**
 * Make UI TextView a html link.//from   w  ww.j ava2  s  .c  om
 * 
 * @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:cc.softwarefactory.lokki.android.fragments.HelpFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    TextView textView = new TextView(getActivity());
    textView.setPadding(15, 15, 15, 15);
    textView.setMovementMethod(LinkMovementMethod.getInstance());

    ScrollView scroller = new ScrollView(getActivity());
    scroller.addView(textView);/*w w  w  .jav a2s.co m*/

    return scroller;
}

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   w w  w . j  av  a  2s  .c  o  m*/
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:io.pure.sixgrid.fragments.AboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.about, container, false);

    TextView tv = (TextView) rootView.findViewById(R.id.aboutTextView);
    tv.setMovementMethod(LinkMovementMethod.getInstance());

    Button bt = (Button) rootView.findViewById(R.id.license);
    bt.setOnClickListener(new View.OnClickListener() {
        @Override/*from  w w w .  ja va2  s.co m*/
        public void onClick(View v) {
            Intent i = new Intent(getActivity(), License.class);
            startActivity(i);
            getActivity().overridePendingTransition(R.anim.slide_up_bottom, R.anim.slide_down_bottom);
        }
    });

    Button ct = (Button) rootView.findViewById(R.id.custombt);
    ct.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(getActivity(), SimplePreference.class);
            startActivity(i);
            getActivity().overridePendingTransition(R.anim.slide_up_bottom, R.anim.slide_down_bottom);
            getActivity().finish();
        }
    });

    return rootView;
}

From source file:com.sismics.reader.activity.LicenseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.license_activity);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    aq.id(R.id.txtLicenses).text(Html.fromHtml(getString(R.string.licenses_content))).getTextView()
            .setMovementMethod(LinkMovementMethod.getInstance());
}