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:com.jamesgiang.aussnowcam.Utils.java

public static void About(Context c) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(c);
    dialogBuilder.setTitle(R.string.app_name);
    dialogBuilder.setIcon(R.drawable.icon);
    TextView textView = new TextView(c);
    SpannableString s = new SpannableString(c.getString(R.string.about_info));
    Linkify.addLinks(s, Linkify.WEB_URLS);
    textView.setText(s);//ww  w . j a  v  a 2s. c  o m
    textView.setGravity(Gravity.CENTER);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    dialogBuilder.setView(textView);
    dialogBuilder.show();
}

From source file:com.google.samples.apps.ourstreets.view.ViewUtils.java

/**
 * Sets a text on a {@link TextView}, provided via viewResId, within a parent view.
 * If there's a web url in the tag the text will be converted from Html, respecting tags.
 *
 * @param parent The view's parent.//w w  w  .  ja va  2  s  .  c  om
 * @param viewResId The resource to resolve.
 * @param text The text to set.
 */
public static void setTextOn(@NonNull View parent, @IdRes int viewResId, @Nullable CharSequence text) {
    if (TextUtils.isEmpty(text)) {
        text = "";
    }
    View view = parent.findViewById(viewResId);
    if (view instanceof TextView) {
        TextView textView = (TextView) view;
        // Only perform Html conversion if there's actually an Url in the text.
        if (Patterns.WEB_URL.matcher(text).find()) {
            textView.setText(Html.fromHtml(text.toString()));
            textView.setMovementMethod(LinkMovementMethod.getInstance());
        } else {
            textView.setText(text);
        }
    }
}

From source file:com.vuze.android.remote.AndroidUtilsUI.java

public static void linkify(TextView tv) {
    tv.setMovementMethod(LinkMovementMethod.getInstance());
    CharSequence t = tv.getText();
    if (!(t instanceof SpannableString)) {
        return;/*from  w  w  w  .ja  v  a2 s  .  c o  m*/
    }
    SpannableString text = (SpannableString) t;

    int len = text.length();

    int next;
    for (int i = 0; i < text.length(); i = next) {
        next = text.nextSpanTransition(i, len, URLSpan.class);
        URLSpan[] old = text.getSpans(i, next, URLSpan.class);
        for (int j = old.length - 1; j >= 0; j--) {
            text.removeSpan(old[j]);

            UrlSpan2 span2 = new UrlSpan2(old[j].getURL());
            text.setSpan(span2, i, next, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }

}

From source file:dev.drsoran.moloko.util.UIUtils.java

public final static void makeLink(TextView textView, Spannable text, ClickableSpan onClickHandler) {
    if (onClickHandler != null) {
        text.setSpan(onClickHandler, 0, text.length(), 0);
    }// w  ww.ja  va  2  s .  c  o m

    textView.setMovementMethod(LinkMovementMethod.getInstance());
    textView.setText(text, BufferType.SPANNABLE);
}

From source file:de.j4velin.mapsmeasure.Dialogs.java

/**
 * @param c the Context//  w w  w  .ja v a  2s .  co m
 * @return the about dialog
 */
public static Dialog getAbout(final Context c) {
    AlertDialog.Builder builder = new AlertDialog.Builder(c);
    builder.setTitle(R.string.about);

    TextView tv = new TextView(c);
    int pad = (Util.dpToPx(c, 10));
    tv.setPadding(pad, pad, pad, pad);

    try {
        tv.setText(R.string.about_text);
        tv.append(c.getString(R.string.app_version,
                c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionName));
        tv.setMovementMethod(LinkMovementMethod.getInstance());
    } catch (NameNotFoundException e1) {
        // should not happen as the app is definitely installed when
        // seeing the dialog
        e1.printStackTrace();
    }
    builder.setView(tv);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    return builder.create();
}

From source file:com.moubry.worthwatching.ui.BaseActivity.java

public static AlertDialog createWhatsNewAlert(Context context) {
    final TextView message = new TextView(context);
    final SpannableString s = new SpannableString(context.getText(R.string.whats_new_message));
    Linkify.addLinks(s, Linkify.WEB_URLS);
    message.setPadding(10, 10, 10, 10);//from  ww  w .  java2  s  .  c om
    message.setText(s);
    message.setLinkTextColor(context.getResources().getColor(R.color.blue));
    message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    message.setMovementMethod(LinkMovementMethod.getInstance());

    return new AlertDialog.Builder(context).setTitle(R.string.title_whats_new).setCancelable(true)
            .setPositiveButton("OK", null).setView(message).create();
}

From source file:com.example.testcutontopview.AboutFragment.java

private void setLinkMovementMethod(TextView... textViews) {
    for (TextView view : textViews) {
        view.setMovementMethod(LinkMovementMethod.getInstance());
    }/*  w  w w.  j  av  a  2  s.c om*/
}

From source file:com.adnanbal.fxdedektifi.forex.presentation.view.fragment.TermsAndConditionsFragment.java

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

    TextView documentView = v.findViewById(R.id.termsDoc);
    documentView.setMovementMethod(new ScrollingMovementMethod());

    return v;/* ww w  .j  a  v  a2 s  . c o  m*/
}

From source file:com.achow101.bitcointalkforum.AboutActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about);
    setupActionBar();//from  www.jav a2  s  .c  om
    TextView about = (TextView) findViewById(R.id.about);
    about.setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:org.residuum.sensosc.AboutActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about);
    String versionString = getResources().getString(R.string.app_name);
    try {//from w w  w . ja v  a2s. c  o  m
        versionString += " " + getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    TextView nameAndVersion = (TextView) findViewById(R.id.name_and_version);
    nameAndVersion.setText(versionString);
    TextView javaOsc = (TextView) findViewById(R.id.javaosc_links);
    javaOsc.setMovementMethod(LinkMovementMethod.getInstance());
    javaOsc.setText(Html.fromHtml(getResources().getString(R.string.about_license_javaosc)));
    TextView buglinks = (TextView) findViewById(R.id.buglinks);
    buglinks.setMovementMethod(LinkMovementMethod.getInstance());
    buglinks.setText(Html.fromHtml(getResources().getString(R.string.about_buglinks)));
    getActionBar().setDisplayHomeAsUpEnabled(true);
}