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.open.file.manager.MainActivity.java

/**
 * Show dialog when "about" is clicked/* ww  w .  j  a  v  a 2s  .co  m*/
 */
private void showAboutDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View aboutdialogview = inflater.inflate(R.layout.aboutdialog, null);
    builder.setView(aboutdialogview);
    TextView bodyview = (TextView) aboutdialogview.findViewById(R.id.aboutcontent);
    bodyview.setText(Html.fromHtml(getString(R.string.aboutBody)));
    bodyview.setMovementMethod(LinkMovementMethod.getInstance());
    builder.setTitle(R.string.about);
    builder.setPositiveButton("OK", null);
    builder.create().show();
}

From source file:devicroft.burnboy.Activities.MainActivity.java

private void dispatchLicenseDialog() {
    Log.d(LOG_TAG, "dispatchLicenseDialog");
    AlertDialog d = new AlertDialog.Builder(this).setTitle("Licenses")
            .setMessage(Html.fromHtml(getString(R.string.license_fab) + "<br><br>"
                    + getString(R.string.license_mpandroidchart) + getString(R.string.app_name))) //https://stackoverflow.com/questions/3235131/set-textview-text-from-html-formatted-string-resource-in-xml
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();/*from ww  w  . ja v a  2 s . c o m*/
                }
            }).show();
    TextView textView = (TextView) d.findViewById(android.R.id.message);
    textView.setScroller(new Scroller(this));
    textView.setVerticalScrollBarEnabled(true);
    textView.setAllCaps(false);
    textView.setMovementMethod(new ScrollingMovementMethod());
}

From source file:com.gh4a.fragment.PullRequestFragment.java

private void fillData() {
    ImageView ivGravatar = (ImageView) mListHeaderView.findViewById(R.id.iv_gravatar);
    AvatarHandler.assignAvatar(ivGravatar, mPullRequest.getUser());
    ivGravatar.setTag(mPullRequest.getUser());
    ivGravatar.setOnClickListener(this);

    TextView tvExtra = (TextView) mListHeaderView.findViewById(R.id.tv_extra);
    tvExtra.setText(mPullRequest.getUser().getLogin());

    TextView tvTimestamp = (TextView) mListHeaderView.findViewById(R.id.tv_timestamp);
    tvTimestamp.setText(StringUtils.formatRelativeTime(getActivity(), mPullRequest.getCreatedAt(), true));

    String body = mPullRequest.getBodyHtml();
    TextView descriptionView = (TextView) mListHeaderView.findViewById(R.id.tv_desc);
    descriptionView.setMovementMethod(UiUtils.CHECKING_LINK_METHOD);
    if (!StringUtils.isBlank(body)) {
        body = HtmlUtils.format(body).toString();
        mImageGetter.bind(descriptionView, body, mPullRequest.getId());
    }/*from w  w w  .j  av a 2s . c  o m*/

    View milestoneGroup = mListHeaderView.findViewById(R.id.milestone_container);
    if (mPullRequest.getMilestone() != null) {
        TextView tvMilestone = (TextView) mListHeaderView.findViewById(R.id.tv_milestone);
        tvMilestone.setText(mPullRequest.getMilestone().getTitle());
        milestoneGroup.setVisibility(View.VISIBLE);
    } else {
        milestoneGroup.setVisibility(View.GONE);
    }

    View assigneeGroup = mListHeaderView.findViewById(R.id.assignee_container);
    if (mPullRequest.getAssignee() != null) {
        TextView tvAssignee = (TextView) mListHeaderView.findViewById(R.id.tv_assignee);
        tvAssignee.setText(mPullRequest.getAssignee().getLogin());

        ImageView ivAssignee = (ImageView) mListHeaderView.findViewById(R.id.iv_assignee);
        AvatarHandler.assignAvatar(ivAssignee, mPullRequest.getAssignee());
        ivAssignee.setTag(mPullRequest.getAssignee());
        ivAssignee.setOnClickListener(this);
        assigneeGroup.setVisibility(View.VISIBLE);
    } else {
        assigneeGroup.setVisibility(View.GONE);
    }

    if (mPullRequest.isMerged()) {
        setHighlightColors(R.attr.colorPullRequestMerged, R.attr.colorPullRequestMergedDark);
    } else if (Constants.Issue.STATE_CLOSED.equals(mPullRequest.getState())) {
        setHighlightColors(R.attr.colorIssueClosed, R.attr.colorIssueClosedDark);
    } else {
        setHighlightColors(R.attr.colorIssueOpen, R.attr.colorIssueOpenDark);
    }
}

From source file:com.anton.gavel.GavelMain.java

public void createDialog(int id) {
    if (progressDialog != null) {
        progressDialog.dismiss();//w w  w  .j av a 2s .co m
    }
    // handles creation of any dialogs by other actions
    switch (id) {
    case DIALOG_PI:
        //call custom dialog for collecting Personal Info
        PersonalInfoDialogFragment personalInfoDialog = new PersonalInfoDialogFragment();
        personalInfoDialog.setPersonalInfo(mPersonalInfo);
        personalInfoDialog.show(getSupportFragmentManager(), "PersonalInfoDialogFragment");
        break;
    case DIALOG_ABOUT:
        //construct a simple dialog to show text

        //get about text
        TextView aboutView = new TextView(this);
        aboutView.setText(R.string.about_text);
        aboutView.setMovementMethod(LinkMovementMethod.getInstance());//enable links
        aboutView.setPadding(50, 30, 50, 30);

        //build dialog
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
        alertDialog.setTitle("About")//title
                .setView(aboutView)//insert textview from above
                .setPositiveButton("Done", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).create() //build
                .show(); //display
        break;

    case DIALOG_SUBMISSION_ERR:
        AlertDialog.Builder submissionErrorDialog = new AlertDialog.Builder(this);
        submissionErrorDialog.setTitle("Submission Error")//title
                .setMessage("There was a problem submitting your complaint on the City's website.")//insert textview from above
                .setPositiveButton("Done", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).show(); //display
        break;

    case DIALOG_OTHER_COMPLAINT:
        final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        final EditText input = new EditText(this);
        input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS | InputType.TYPE_CLASS_TEXT);
        // capitalize letters + seperate words
        AlertDialog.Builder getComplaintDialog = new AlertDialog.Builder(this);
        getComplaintDialog.setTitle("Other...").setView(input)
                .setMessage("Give a categorical title for your complaint:")
                .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        String value = input.getText().toString();
                        // add the item to list and make it selected
                        complaintsAdapter.insert(value, 0);
                        complaintSpinner.setSelection(0);
                        complaintsAdapter.notifyDataSetChanged();
                        addToSubmitValues(value);

                        imm.toggleSoftInput(InputMethodManager.RESULT_HIDDEN, 0);//hide keyboard   
                        dialog.cancel();

                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        imm.toggleSoftInput(InputMethodManager.RESULT_HIDDEN, 0);//hide keyboard              
                        dialog.cancel();
                    }
                }).create();

        input.requestFocus();
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);// show keyboard

        getComplaintDialog.show();//show dialog
        break;
    case DIALOG_NO_GEOCODING:
        AlertDialog.Builder noGeoCoding = new AlertDialog.Builder(this);
        noGeoCoding.setTitle("Not Available")//title
                .setMessage(
                        "Your version of Android does not support location-based address lookup. This feature is only supported on Gingerbread and above.")//insert textview from above
                .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).show(); //display
        break;
    case DIALOG_INCOMPLETE_PERSONAL_INFORMATION:
        AlertDialog.Builder incompleteInfo = new AlertDialog.Builder(this);
        incompleteInfo.setTitle("Incomplete")//title
                .setMessage(
                        "Your personal information is incomplete. Select 'Edit Personal Information' from the menu and fill in all required fields")//insert textview from above
                .setPositiveButton("Done", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).show(); //display         
        break;
    case DIALOG_NO_COMPLAINT:
        AlertDialog.Builder noComplaint = new AlertDialog.Builder(this);
        noComplaint.setTitle("No Comlaint Specified")//title
                .setMessage("You must specify a complaint (e.g. barking dog).")//insert textview from above
                .setPositiveButton("Done", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).show(); //display
        break;
    case DIALOG_NO_LOCATION:
        AlertDialog.Builder incompleteComplaint = new AlertDialog.Builder(this);
        incompleteComplaint.setTitle("No Location Specified")//title
                .setMessage("You must specify a location (approximate street address) of the complaint.")//insert textview from above
                .setPositiveButton("Done", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).show(); //display         
    }

}

From source file:com.google.android.apps.iosched.ui.SessionDetailActivity.java

/** Build and add "moderator" tab. */
private void setupModeratorTab(Cursor sessionsCursor) {
    final TabHost host = getTabHost();

    // Insert Moderator when available
    final View moderatorBlock = findViewById(R.id.moderator_block);
    final String moderatorLink = sessionsCursor.getString(SessionsQuery.MODERATOR_LINK);
    final boolean validModerator = !TextUtils.isEmpty(moderatorLink);
    if (validModerator) {
        mModeratorUri = Uri.parse(moderatorLink);

        // Set link, but handle clicks manually
        final TextView textView = (TextView) findViewById(R.id.moderator_link);
        textView.setText(mModeratorUri.toString());
        textView.setMovementMethod(null);
        textView.setClickable(true);//  w  ww  .j  a  v a2s  .  c om
        textView.setFocusable(true);

        // Start background fetch of moderator status
        startModeratorStatusFetch(moderatorLink);

        moderatorBlock.setVisibility(View.VISIBLE);
    } else {
        moderatorBlock.setVisibility(View.GONE);
    }

    // Insert Wave when available
    final View waveBlock = findViewById(R.id.wave_block);
    final String waveLink = sessionsCursor.getString(SessionsQuery.WAVE_LINK);
    final boolean validWave = !TextUtils.isEmpty(waveLink);
    if (validWave) {
        // Rewrite incoming Wave URL to punch through user-agent check
        mWaveUri = Uri.parse(waveLink).buildUpon().appendQueryParameter("nouacheck", "1").build();

        // Set link, but handle clicks manually
        final TextView textView = (TextView) findViewById(R.id.wave_link);
        textView.setText(mWaveUri.toString());
        textView.setMovementMethod(null);
        textView.setClickable(true);
        textView.setFocusable(true);

        waveBlock.setVisibility(View.VISIBLE);
    } else {
        waveBlock.setVisibility(View.GONE);
    }

    if (validModerator || validWave) {
        // Moderator content comes from existing layout
        host.addTab(host.newTabSpec(TAG_MODERATOR).setIndicator(buildIndicator(R.string.session_interact))
                .setContent(R.id.tab_session_moderator));
    }
}

From source file:org.sufficientlysecure.ical.ui.MainActivity.java

private void showLegalNotices() {
    TextView text = new TextView(this);
    text.setText(Html.fromHtml(getString(R.string.legal_notices_html)));
    text.setMovementMethod(LinkMovementMethod.getInstance());
    new AlertDialog.Builder(this).setView(text).create().show();
}

From source file:com.juick.android.TagsFragment.java

private void reloadTags(final View view) {
    final View selectedContainer = myView.findViewById(R.id.selected_container);
    final View progressAll = myView.findViewById(R.id.progress_all);
    Thread thr = new Thread(new Runnable() {

        public void run() {
            Bundle args = getArguments();
            MicroBlog microBlog;//from w ww.  ja  v  a 2s. com
            JSONArray json = null;
            final int tagsUID = showMine ? uid : 0;
            if (PointMessageID.CODE.equals(args.getString("microblog"))) {
                microBlog = MainActivity.microBlogs.get(PointMessageID.CODE);
                json = ((PointMicroBlog) microBlog).getUserTags(view, uidS);
            } else {
                microBlog = MainActivity.microBlogs.get(JuickMessageID.CODE);
                json = ((JuickMicroBlog) microBlog).getUserTags(view, tagsUID);
            }
            if (isAdded()) {
                final SpannableStringBuilder tagsSSB = new SpannableStringBuilder();
                if (json != null) {
                    try {
                        int cnt = json.length();
                        ArrayList<TagSort> sortables = new ArrayList<TagSort>();
                        for (int i = 0; i < cnt; i++) {
                            final String tagg = json.getJSONObject(i).getString("tag");
                            final int messages = json.getJSONObject(i).getInt("messages");
                            sortables.add(new TagSort(tagg, messages));
                        }
                        Collections.sort(sortables);
                        HashMap<String, Double> scales = new HashMap<String, Double>();
                        for (int sz = 0, sortablesSize = sortables.size(); sz < sortablesSize; sz++) {
                            TagSort sortable = sortables.get(sz);
                            if (sz < 10) {
                                scales.put(sortable.tag, 2.0);
                            } else if (sz < 20) {
                                scales.put(sortable.tag, 1.5);
                            }
                        }
                        int start = 0;
                        if (microBlog instanceof JuickMicroBlog
                                && getArguments().containsKey("add_system_tags")) {
                            start = -4;
                        }
                        for (int i = start; i < cnt; i++) {
                            final String tagg;
                            switch (i) {
                            case -4:
                                tagg = "public";
                                break;
                            case -3:
                                tagg = "friends";
                                break;
                            case -2:
                                tagg = "notwitter";
                                break;
                            case -1:
                                tagg = "readonly";
                                break;
                            default:
                                tagg = json.getJSONObject(i).getString("tag");
                                break;

                            }
                            int index = tagsSSB.length();
                            tagsSSB.append("*" + tagg);
                            tagsSSB.setSpan(new URLSpan(tagg) {
                                @Override
                                public void onClick(View widget) {
                                    onTagClick(tagg, tagsUID);
                                }
                            }, index, tagsSSB.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                            Double scale = scales.get(tagg);
                            if (scale != null) {
                                tagsSSB.setSpan(new RelativeSizeSpan((float) scale.doubleValue()), index,
                                        tagsSSB.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                            }
                            tagOffsets.put(tagg, new TagOffsets(index, tagsSSB.length()));
                            tagsSSB.append(" ");

                        }
                    } catch (Exception ex) {
                        tagsSSB.append("Error: " + ex.toString());
                    }
                }
                if (getActivity() != null) {
                    // maybe already closed?
                    getActivity().runOnUiThread(new Runnable() {

                        public void run() {
                            TextView tv = (TextView) myView.findViewById(R.id.tags);
                            progressAll.setVisibility(View.GONE);
                            if (multi)
                                selectedContainer.setVisibility(View.VISIBLE);
                            tv.setText(tagsSSB, TextView.BufferType.SPANNABLE);
                            tv.setMovementMethod(LinkMovementMethod.getInstance());
                            MainActivity.restyleChildrenOrWidget(view);
                            final TextView selected = (TextView) myView.findViewById(R.id.selected);
                            selected.setVisibility(View.VISIBLE);
                        }
                    });
                }
            }
        }
    });
    thr.start();
}

From source file:com.yek.keyboard.ui.settings.AboutAnySoftKeyboardFragment.java

@Override
public void onViewStateRestored(Bundle savedInstanceState) {
    super.onViewStateRestored(savedInstanceState);
    TextView additionalSoftware = (TextView) getView().findViewById(R.id.about_legal_stuff_link);
    SpannableStringBuilder sb = new SpannableStringBuilder(additionalSoftware.getText());
    sb.clearSpans();//removing any previously (from instance-state) set click spans.
    sb.setSpan(new ClickableSpan() {
        @Override//w w  w  .j ava 2 s  . c o  m
        public void onClick(View widget) {
            FragmentChauffeurActivity activity = (FragmentChauffeurActivity) getActivity();
            activity.addFragmentToUi(new AdditionalSoftwareLicensesFragment(),
                    TransitionExperiences.DEEPER_EXPERIENCE_TRANSITION);
        }
    }, 0, additionalSoftware.getText().length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    additionalSoftware.setMovementMethod(LinkMovementMethod.getInstance());
    additionalSoftware.setText(sb);
}

From source file:com.google.samples.apps.iosched.myschedule.MyScheduleActivity.java

private void showAnnouncementDialogIfNeeded(Intent intent) {
    final String title = intent.getStringExtra(EXTRA_DIALOG_TITLE);
    final String message = intent.getStringExtra(EXTRA_DIALOG_MESSAGE);

    if (!mShowedAnnouncementDialog && !TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) {
        LOGD(TAG, "showAnnouncementDialogIfNeeded, title: " + title);
        LOGD(TAG, "showAnnouncementDialogIfNeeded, message: " + message);
        final String yes = intent.getStringExtra(EXTRA_DIALOG_YES);
        LOGD(TAG, "showAnnouncementDialogIfNeeded, yes: " + yes);
        final String no = intent.getStringExtra(EXTRA_DIALOG_NO);
        LOGD(TAG, "showAnnouncementDialogIfNeeded, no: " + no);
        final String url = intent.getStringExtra(EXTRA_DIALOG_URL);
        LOGD(TAG, "showAnnouncementDialogIfNeeded, url: " + url);
        final SpannableString spannable = new SpannableString(message == null ? "" : message);
        Linkify.addLinks(spannable, Linkify.WEB_URLS);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        if (!TextUtils.isEmpty(title)) {
            builder.setTitle(title);/*from w  w  w.ja v  a2s .  c o  m*/
        }
        builder.setMessage(spannable);
        if (!TextUtils.isEmpty(no)) {
            builder.setNegativeButton(no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
        }
        if (!TextUtils.isEmpty(yes)) {
            builder.setPositiveButton(yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    startActivity(intent);
                }
            });
        }
        final AlertDialog dialog = builder.create();
        dialog.show();
        final TextView messageView = (TextView) dialog.findViewById(android.R.id.message);
        if (messageView != null) {
            // makes the embedded links in the text clickable, if there are any
            messageView.setMovementMethod(LinkMovementMethod.getInstance());
        }
        mShowedAnnouncementDialog = true;
    }
}

From source file:de.j4velin.pedometer.ui.Activity_Main.java

public boolean optionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        getFragmentManager().popBackStackImmediate();
        break;/*from w  w  w.j a  v a 2 s  .  c o m*/
    case R.id.action_settings:
        getFragmentManager().beginTransaction().replace(android.R.id.content, new Fragment_Settings())
                .addToBackStack(null).commit();
        break;
    case R.id.action_leaderboard:
    case R.id.action_achievements:
        if (mGoogleApiClient.isConnected()) {
            startActivityForResult(item.getItemId() == R.id.action_achievements
                    ? Games.Achievements.getAchievementsIntent(mGoogleApiClient)
                    : Games.Leaderboards.getAllLeaderboardsIntent(mGoogleApiClient), RC_LEADERBOARDS);
        } else {
            AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
            builder2.setTitle(R.string.sign_in_necessary);
            builder2.setMessage(R.string.please_sign_in_with_your_google_account);
            builder2.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    getFragmentManager().beginTransaction()
                            .replace(android.R.id.content, new Fragment_Settings()).addToBackStack(null)
                            .commit();
                }
            });
            builder2.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder2.create().show();
        }
        break;
    case R.id.action_faq:
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://j4velin.de/faq/index.php?app=pm"))
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        break;
    case R.id.action_about:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.about);
        TextView tv = new TextView(this);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(R.string.about_text_links);
        try {
            tv.append(getString(R.string.about_app_version,
                    getPackageManager().getPackageInfo(getPackageName(), 0).versionName));
        } catch (NameNotFoundException e1) {
            // should not happen as the app is definitely installed when
            // seeing the dialog
            e1.printStackTrace();
        }
        tv.setMovementMethod(LinkMovementMethod.getInstance());
        builder.setView(tv);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.create().show();
        break;
    }
    return true;
}