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.github.jobs.ui.fragment.JobDetailsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    Bundle arguments = getArguments();/*w ww  .  j a  v a 2s .c  o m*/
    String jobId = arguments.getString(KEY_JOB_ID);
    mJob = new Job();
    mJob.setId(jobId);
    mJob = adapter.findFirst(mJob);
    if (mJob == null) {
        mJob = new Job();
        Toast.makeText(getActivity(), R.string.error_getting_job_info, Toast.LENGTH_LONG).show();
    }
    setHasOptionsMenu(true);

    TextView title = (TextView) getView().findViewById(R.id.title);
    title.setText(StringUtils.trim(mJob.getTitle()));

    TextView description = (TextView) getView().findViewById(R.id.description);
    String jobDescription = mJob.getDescription();
    if (jobDescription != null) {
        description.setText(Html.fromHtml(jobDescription));
        description.setMovementMethod(LinkMovementMethod.getInstance());
    }

    TextView company = (TextView) getView().findViewById(R.id.company);
    company.setText(mJob.getCompany());

    TextView companyUrl = (TextView) getView().findViewById(R.id.company_url);
    if (mJob.getCompanyUrl() == null) {
        companyUrl.setVisibility(View.GONE);
    } else {
        SpannableString content = new SpannableString(mJob.getCompanyUrl());
        content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
        companyUrl.setText(content);
        companyUrl.setOnClickListener(this);
        companyUrl.setVisibility(View.VISIBLE);
    }

    TextView companyLocation = (TextView) getView().findViewById(R.id.company_location);
    if (mJob.getLocation() == null) {
        companyLocation.setVisibility(View.GONE);
    } else {
        companyLocation.setText(mJob.getLocation());
        companyLocation.setVisibility(View.VISIBLE);
    }

    if (!JobDetailsActivity.FULL_TIME.equalsIgnoreCase(mJob.getType())) {
        getView().findViewById(R.id.full_time).setVisibility(View.INVISIBLE);
    }

    mBackground = (ImageView) getView().findViewById(R.id.job_details_background);
    setLogoBackground();
}

From source file:com.gh4a.activities.ReleaseInfoActivity.java

private void fillNotes(String bodyHtml) {
    TextView body = (TextView) findViewById(R.id.tv_release_notes);

    if (!StringUtils.isBlank(bodyHtml)) {
        bodyHtml = HtmlUtils.format(bodyHtml).toString();
        mImageGetter.bind(body, bodyHtml, mRelease.getId());
        body.setMovementMethod(UiUtils.CHECKING_LINK_METHOD);
    } else {//from  ww w. java2s. c  om
        body.setText(R.string.release_no_releasenotes);
    }

    body.setVisibility(View.VISIBLE);
    findViewById(R.id.pb_releasenotes).setVisibility(View.GONE);
}

From source file:eu.se_bastiaan.popcorntimeremote.iab.DonationFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Activity activity = getActivity();/*from w ww  .j a  v a  2s.c o m*/
    assert activity != null;

    View view = getActivity().getLayoutInflater().inflate(R.layout.donation_dialog, null, false);

    AlertDialog.Builder builder = new AlertDialog.Builder(activity).setTitle(R.string.donation_title)
            .setView(view).setNegativeButton(android.R.string.cancel, null);

    TextView info = (TextView) view.findViewById(R.id.info);
    info.setText(Html.fromHtml(getString(R.string.donation_info)));
    info.setMovementMethod(new LinkMovementMethod());

    mError = (TextView) view.findViewById(R.id.error);
    mProgressBar = (ProgressBar) view.findViewById(android.R.id.progress);
    mGridView = (GridView) view.findViewById(R.id.grid);
    mGridView.setAdapter(new DonationAdapter(getActivity(), mDonationList, mInventorySet));
    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            DonationAdapter adapter = (DonationAdapter) parent.getAdapter();
            Donation donation = adapter.getItem(position);

            if (!mInventorySet.contains(donation.sku)) {
                /**
                 * See {@link sharedcode.turboeditor.iab.DonationFragment#verifyDeveloperPayload(Purchase)}.
                 */
                String payload = "";
                try {
                    mHelper.launchPurchaseFlow(getActivity(), donation.sku, RC_REQUEST,
                            mPurchaseFinishedListener, payload);
                } catch (Exception e) {
                    Toast.makeText(getActivity(), "Failed to launch a purchase flow.", Toast.LENGTH_SHORT)
                            .show();
                }
            } else {
                Toast.makeText(getActivity(), getString(R.string.donation_item_bought), Toast.LENGTH_LONG);
            }
        }
    });

    final AlertDialog alertDialog;

    alertDialog = builder.create();

    initBilling();

    return alertDialog;
}

From source file:org.liberty.android.fantastischmemo.downloader.DownloaderSS.java

protected void fetchDatabase(final DownloadItem di) {
    View alertView = View.inflate(this, R.layout.link_alert, null);
    TextView textView = (TextView) alertView.findViewById(R.id.link_alert_message);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    textView.setText(//  w ww  .  ja v  a2s .c  o m
            Html.fromHtml(getString(R.string.downloader_download_alert_message) + di.getDescription()));

    new AlertDialog.Builder(this).setView(alertView)
            .setTitle(getString(R.string.downloader_download_alert) + di.getTitle())
            .setPositiveButton(getString(R.string.yes_text), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                    mProgressDialog = ProgressDialog.show(DownloaderSS.this,
                            getString(R.string.loading_please_wait), getString(R.string.loading_downloading));
                    new Thread() {
                        public void run() {
                            try {
                                downloadDatabase(di);
                                mHandler.post(new Runnable() {
                                    public void run() {
                                        mProgressDialog.dismiss();
                                        String dbpath = AMEnv.DEFAULT_ROOT_PATH;
                                        new AlertDialog.Builder(DownloaderSS.this)
                                                .setTitle(R.string.downloader_download_success)
                                                .setMessage(
                                                        getString(R.string.downloader_download_success_message)
                                                                + dbpath + di.getTitle() + ".db")
                                                .setPositiveButton(R.string.ok_text, null).create().show();
                                    }
                                });

                            } catch (final Exception e) {
                                Log.e(TAG, "Error downloading", e);
                                mHandler.post(new Runnable() {
                                    public void run() {
                                        mProgressDialog.dismiss();
                                        new AlertDialog.Builder(DownloaderSS.this)
                                                .setTitle(R.string.downloader_download_fail)
                                                .setMessage(getString(R.string.downloader_download_fail_message)
                                                        + " " + e.toString())
                                                .setPositiveButton(R.string.ok_text, null).create().show();
                                    }
                                });
                            }
                        }
                    }.start();
                }
            }).setNegativeButton(getString(R.string.no_text), null).show();
}

From source file:com.vuze.android.remote.dialog.DialogFragmentFilterByTags.java

@NonNull
@Override/*  www  . ja va 2  s.c o m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    SessionInfo sessionInfo = getSessionInfo();
    List<Map<?, ?>> tags = sessionInfo == null ? null : sessionInfo.getTags();
    if (tags != null && tags.size() > 0) {
        TreeMap<String, Long> map = new TreeMap<>();
        for (Object o : tags) {
            if (o instanceof Map) {
                Map<?, ?> mapTag = (Map<?, ?>) o;
                long uid = MapUtils.getMapLong(mapTag, "uid", 0);
                String name = MapUtils.getMapString(mapTag, "name", "??");
                int type = MapUtils.getMapInt(mapTag, "type", 0);
                if (type == 3) {
                    // type-name will be "Manual" :(
                    name = "Tag: " + name;
                } else {
                    String typeName = MapUtils.getMapString(mapTag, "type-name", null);
                    if (typeName != null) {
                        name = typeName + ": " + name;
                    }
                }
                map.put(name, uid);
            }
        }

        long[] vals = new long[map.size()];
        String[] strings = map.keySet().toArray(new String[map.keySet().size()]);
        for (int i = 0; i < vals.length; i++) {
            vals[i] = map.get(strings[i]);
        }

        filterByList = new ValueStringArray(vals, strings);
    }

    if (filterByList == null) {
        filterByList = AndroidUtils.getValueStringArray(getResources(), R.array.filterby_list);
    }

    AndroidUtils.AlertDialogBuilder alertDialogBuilder = AndroidUtils.createAlertDialogBuilder(getActivity(),
            R.layout.dialog_filter_by);

    View view = alertDialogBuilder.view;
    AlertDialog.Builder builder = alertDialogBuilder.builder;

    // get our tabHost from the xml
    TabHost tabHost = (TabHost) view.findViewById(R.id.filterby_tabhost);
    tabHost.setup();

    // create tab 1
    TabHost.TabSpec spec1 = tabHost.newTabSpec("tab1");
    spec1.setIndicator("States");
    spec1.setContent(R.id.filterby_sv_state);
    tabHost.addTab(spec1);
    //create tab2
    TabHost.TabSpec spec2 = tabHost.newTabSpec("tab2");
    spec2.setIndicator("Tags");
    spec2.setContent(R.id.filterby_tv_tags);
    tabHost.addTab(spec2);

    int height = AndroidUtilsUI.dpToPx(32);
    tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;
    tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;

    TextView tvState = (TextView) view.findViewById(R.id.filterby_tv_state);
    tvState.setMovementMethod(LinkMovementMethod.getInstance());

    final TextView tvTags = (TextView) view.findViewById(R.id.filterby_tv_tags);
    tvTags.setMovementMethod(LinkMovementMethod.getInstance());

    // for API <= 10 (maybe 11?), otherwise tags will display on one line
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (!tabId.equals("tab2")) {
                return;
            }
            tvTags.post(new Runnable() {
                @Override
                public void run() {
                    spanTags.updateTags();
                }
            });
        }
    });

    builder.setTitle(R.string.filterby_title);

    // Add action buttons
    builder.setPositiveButton(R.string.action_filterby, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            if (mapSelectedTag == null) {
                return;
            }
            long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1);
            String name = MapUtils.getMapString(mapSelectedTag, "name", "??");

            mListener.filterBy(uidSelected, name, true);
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            DialogFragmentFilterByTags.this.getDialog().cancel();
        }
    });

    List<Map<?, ?>> manualTags = new ArrayList<>();
    List<Map<?, ?>> stateTags = new ArrayList<>();

    if (sessionInfo != null) {
        // Dialog never gets called wehn getTags has no tags
        List<Map<?, ?>> allTags = sessionInfo.getTags();
        if (allTags != null) {
            for (Map<?, ?> mapTag : allTags) {
                int type = MapUtils.getMapInt(mapTag, "type", 0);
                switch (type) {
                case 0:
                case 1:
                case 2:
                    stateTags.add(mapTag);
                    break;
                case 3: // manual
                    manualTags.add(mapTag);
                    break;
                }
            }
        }
    }

    SpanTagsListener l = new SpanTagsListener() {
        @Override
        public void tagClicked(Map mapTag, String name) {
            mapSelectedTag = mapTag;
            // todo: long click, don't exit
            long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1);
            mListener.filterBy(uidSelected, name, true);
            DialogFragmentFilterByTags.this.getDialog().dismiss();
        }

        @Override
        public int getTagState(Map mapTag, String name) {
            if (mapSelectedTag == null) {
                return SpanTags.TAG_STATE_UNSELECTED;
            }
            long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1);
            if (uidSelected == -1) {
                return SpanTags.TAG_STATE_UNSELECTED;
            }
            long uidQuery = MapUtils.getMapLong(mapTag, "uid", -1);
            return uidQuery == uidSelected ? SpanTags.TAG_STATE_SELECTED : SpanTags.TAG_STATE_UNSELECTED;
        }
    };
    spanTags = new SpanTags(getActivity(), sessionInfo, tvTags, l);
    spanTags.setTagMaps(manualTags);
    spanTags.setShowIcon(false);
    spanTags.updateTags();

    SpanTags spanState = new SpanTags(getActivity(), sessionInfo, tvState, l);
    spanState.setTagMaps(stateTags);
    spanState.setShowIcon(false);
    spanState.updateTags();

    return builder.create();
}

From source file:com.limewoodmedia.nsdroid.fragments.IssuesFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    root = inflater.inflate(R.layout.issues, null, false);
    list = (ListView) root.findViewById(R.id.issues_list);
    title = (TextView) root.findViewById(R.id.issues_title);
    title.setText(//from   www .ja va 2 s .c om
            getResources().getString(R.string.issues_title, NationInfo.getInstance(getActivity()).getName()));
    ViewTreeObserver observer = title.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            list.setPadding(list.getPaddingLeft(),
                    title.getHeight() - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15,
                            getResources().getDisplayMetrics()),
                    list.getPaddingRight(), list.getPaddingBottom());
        }
    });
    text = (TextView) root.findViewById(R.id.issues_text);
    text.setVisibility(View.GONE);

    issues = new ArrayList<Issue>();
    listAdapter = new ArrayAdapter<Issue>(context, 0, issues) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view;
            TextView text;

            if (convertView == null) {
                view = inflater.inflate(R.layout.issue_list_item, null);
                text = (TextView) view.findViewById(R.id.issue_item);
                text.setMovementMethod(LinkMovementMethod.getInstance());
            } else {
                view = convertView;
                text = (TextView) view.findViewById(R.id.issue_item);
            }
            Issue issue = getItem(position);
            String txt = "&#8226; <a href=\"com.limewoodMedia.nsdroid.issue://" + issue.id + "\">" + issue.name
                    + "</a> ";
            text.setText(Html.fromHtml(txt));

            return view;
        }
    };
    list.setAdapter(listAdapter);

    return root;
}

From source file:com.keylesspalace.tusky.LoginActivity.java

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

    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("lightTheme", false)) {
        setTheme(R.style.AppTheme_Light);
    }/*from w  w  w.jav  a 2  s . co m*/

    setContentView(R.layout.activity_login);
    ButterKnife.bind(this);

    if (savedInstanceState != null) {
        domain = savedInstanceState.getString("domain");
        clientId = savedInstanceState.getString("clientId");
        clientSecret = savedInstanceState.getString("clientSecret");
    } else {
        domain = null;
        clientId = null;
        clientSecret = null;
    }

    preferences = getSharedPreferences(getString(R.string.preferences_file_key), Context.MODE_PRIVATE);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onButtonClick(editText);
        }
    });

    final Context context = this;

    whatsAnInstance.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog dialog = new AlertDialog.Builder(context).setMessage(R.string.dialog_whats_an_instance)
                    .setPositiveButton(R.string.action_close, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).show();
            TextView textView = (TextView) dialog.findViewById(android.R.id.message);
            textView.setMovementMethod(LinkMovementMethod.getInstance());
        }
    });
}

From source file:org.liberty.android.fantastischmemopro.downloader.DownloaderFE.java

@Override
protected void fetchDatabase(final DownloadItem di) {
    View alertView = View.inflate(this, R.layout.link_alert, null);
    TextView textView = (TextView) alertView.findViewById(R.id.link_alert_message);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    textView.setText(/*from w ww  .  j a v  a2  s  .  c  om*/
            Html.fromHtml(getString(R.string.downloader_download_alert_message) + di.getDescription()));

    new AlertDialog.Builder(this).setView(alertView)
            .setTitle(getString(R.string.downloader_download_alert) + di.getTitle())
            .setPositiveButton(getString(R.string.yes_text), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                    mProgressDialog = ProgressDialog.show(DownloaderFE.this,
                            getString(R.string.loading_please_wait), getString(R.string.loading_downloading));
                    new Thread() {
                        public void run() {
                            try {
                                downloadDatabase(di);
                                mHandler.post(new Runnable() {
                                    public void run() {
                                        mProgressDialog.dismiss();
                                        String dbpath = Environment.getExternalStorageDirectory()
                                                .getAbsolutePath() + getString(R.string.default_dir);
                                        new AlertDialog.Builder(DownloaderFE.this)
                                                .setTitle(R.string.downloader_download_success)
                                                .setMessage(
                                                        getString(R.string.downloader_download_success_message)
                                                                + dbpath + di.getTitle() + ".db")
                                                .setPositiveButton(R.string.ok_text, null).create().show();
                                    }
                                });

                            } catch (final Exception e) {
                                Log.e(TAG, "Error downloading", e);
                                mHandler.post(new Runnable() {
                                    public void run() {
                                        mProgressDialog.dismiss();
                                        new AlertDialog.Builder(DownloaderFE.this)
                                                .setTitle(R.string.downloader_download_fail)
                                                .setMessage(getString(R.string.downloader_download_fail_message)
                                                        + " " + e.toString())
                                                .setPositiveButton(R.string.ok_text, null).create().show();
                                    }
                                });
                            }
                        }
                    }.start();
                }
            }).setNegativeButton(getString(R.string.no_text), null).show();
}

From source file:com.nuvolect.securesuite.data.SqlSyncTest.java

public void pingPongConfirmDiag(final Activity act) {

    m_act = act;//from  w w w. ja  v a2 s  .co  m

    if (!WebUtil.companionServerAssigned()) {
        Toast.makeText(act, "Configure companion device for test to operate", Toast.LENGTH_LONG).show();
        return;
    }

    String title = "Pyramid comm test with companion device";
    String message = "This is a non-destructive network performance test. "
            + "Payload size is incrementally increased.";

    AlertDialog.Builder builder = new AlertDialog.Builder(act);
    builder.setTitle(title);
    builder.setMessage(Html.fromHtml(message));
    builder.setIcon(CConst.SMALL_ICON);
    builder.setCancelable(true);

    builder.setPositiveButton("Start test", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

            setProgressCallback(m_act, pingPongCallbacks);
            pingPongProgress(act);
            SqlSyncTest.getInstance().init();// Small amount of init on UI thread
            WorkerCommand.quePingTest(m_act);// Heavy lifting on non-UI thread
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

            dialog_alert.cancel();
        }
    });
    dialog_alert = builder.create();
    dialog_alert.show();

    // Activate the HTML
    TextView tv = ((TextView) dialog_alert.findViewById(android.R.id.message));
    tv.setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:com.achep.base.ui.DialogBuilder.java

/**
 * Builds dialog's view//from   w w w . j  a  v  a 2s.  co m
 *
 * @throws IllegalArgumentException when type is not one of defined.
 * @see #LAYOUT_COMMON
 * @see #LAYOUT_SKELETON
 */
public View createView(int type) {
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    ViewGroup rootLayout = (ViewGroup) createSkeleton();
    ViewGroup contentLayout = rootLayout;

    switch (type) {
    case LAYOUT_COMMON:
        final boolean hasMessageOnly = mView == null && mViewRes == 0;
        final int layoutResource = mContentViewRes != 0 ? mContentViewRes
                : hasMessageOnly ? R.layout.dialog_message : R.layout.dialog_content;

        ViewStub viewStub = (ViewStub) inflater.inflate(R.layout.dialog_main_body, rootLayout, true)
                .findViewById(R.id.placeholder);
        viewStub.setLayoutResource(layoutResource);

        contentLayout = (ViewGroup) viewStub.inflate().findViewById(R.id.content);
        if (contentLayout == null)
            contentLayout = rootLayout;
        TextView messageView = (TextView) contentLayout.findViewById(R.id.message);

        if (messageView != null) {
            if (!TextUtils.isEmpty(mMessageText)) {
                messageView.setMovementMethod(new LinkMovementMethod());
                messageView.setText(mMessageText);
            } else {
                ViewGroup vg = (ViewGroup) messageView.getParent();
                vg.removeView(messageView);
            }
        }

        // Fall down.
    case LAYOUT_SKELETON:

        if (mViewRes != 0) {
            inflater.inflate(mViewRes, contentLayout, true);
        } else if (mView != null) {
            contentLayout.addView(mView);
        }

        return rootLayout;
    default:
        throw new IllegalArgumentException();
    }
}