List of usage examples for android.widget TextView setMovementMethod
public final void setMovementMethod(MovementMethod movement)
From source file:net.gsantner.opoc.util.ContextUtils.java
/** * Load html into a {@link Spanned} object and set the * {@link TextView}'s text using {@link TextView#setText(CharSequence)} *//*from ww w .jav a 2 s . c o m*/ public void setHtmlToTextView(TextView textView, String html) { textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setText(new SpannableString(htmlToSpanned(html))); }
From source file:com.gh4a.activities.IssueActivity.java
private void fillData() { // set details inside listview header ImageView ivGravatar = (ImageView) mListHeaderView.findViewById(R.id.iv_gravatar); AvatarHandler.assignAvatar(ivGravatar, mIssue.getUser()); ivGravatar.setOnClickListener(this); TextView tvState = (TextView) mHeader.findViewById(R.id.tv_state); boolean closed = Constants.Issue.STATE_CLOSED.equals(mIssue.getState()); int stateTextResId = closed ? R.string.closed : R.string.open; int stateColorAttributeId = closed ? R.attr.colorIssueClosed : R.attr.colorIssueOpen; tvState.setText(getString(stateTextResId).toUpperCase(Locale.getDefault())); transitionHeaderToColor(stateColorAttributeId, closed ? R.attr.colorIssueClosedDark : R.attr.colorIssueOpenDark); UiUtils.trySetListOverscrollColor(mRecyclerView, UiUtils.resolveColor(this, stateColorAttributeId)); TextView tvExtra = (TextView) mListHeaderView.findViewById(R.id.tv_extra); tvExtra.setText(ApiHelpers.getUserLogin(this, mIssue.getUser())); TextView tvTimestamp = (TextView) mListHeaderView.findViewById(R.id.tv_timestamp); tvTimestamp.setText(StringUtils.formatRelativeTime(this, mIssue.getCreatedAt(), true)); TextView tvTitle = (TextView) mHeader.findViewById(R.id.tv_title); tvTitle.setText(mIssue.getTitle());// w w w .j a va 2 s .c o m String body = mIssue.getBodyHtml(); TextView descriptionView = (TextView) mListHeaderView.findViewById(R.id.tv_desc); if (!StringUtils.isBlank(body)) { body = HtmlUtils.format(body).toString(); mImageGetter.bind(descriptionView, body, mIssue.getNumber()); } descriptionView.setMovementMethod(UiUtils.CHECKING_LINK_METHOD); View milestoneGroup = mListHeaderView.findViewById(R.id.milestone_container); if (mIssue.getMilestone() != null) { TextView tvMilestone = (TextView) mListHeaderView.findViewById(R.id.tv_milestone); tvMilestone.setText(mIssue.getMilestone().getTitle()); milestoneGroup.setVisibility(View.VISIBLE); } else { milestoneGroup.setVisibility(View.GONE); } View assigneeGroup = mListHeaderView.findViewById(R.id.assignee_container); if (mIssue.getAssignee() != null) { TextView tvAssignee = (TextView) mListHeaderView.findViewById(R.id.tv_assignee); tvAssignee.setText(mIssue.getAssignee().getLogin()); ImageView ivAssignee = (ImageView) mListHeaderView.findViewById(R.id.iv_assignee); AvatarHandler.assignAvatar(ivAssignee, mIssue.getAssignee()); ivAssignee.setOnClickListener(this); assigneeGroup.setVisibility(View.VISIBLE); } else { assigneeGroup.setVisibility(View.GONE); } List<Label> labels = mIssue.getLabels(); View labelGroup = mListHeaderView.findViewById(R.id.label_container); if (labels != null && !labels.isEmpty()) { TextView labelView = (TextView) mListHeaderView.findViewById(R.id.labels); SpannableStringBuilder builder = new SpannableStringBuilder(); for (Label label : labels) { int pos = builder.length(); IssueLabelSpan span = new IssueLabelSpan(this, label, true); builder.append(label.getName()); builder.setSpan(span, pos, pos + label.getName().length(), 0); } labelView.setText(builder); labelGroup.setVisibility(View.VISIBLE); } else { labelGroup.setVisibility(View.GONE); } TextView tvPull = (TextView) mListHeaderView.findViewById(R.id.tv_pull); if (mIssue.getPullRequest() != null && mIssue.getPullRequest().getDiffUrl() != null) { tvPull.setVisibility(View.VISIBLE); tvPull.setOnClickListener(this); } else { tvPull.setVisibility(View.GONE); } mHeader.setVisibility(View.VISIBLE); updateFabVisibility(); updateCommentLockState(); }
From source file:com.gmail.taneza.ronald.carbs.main.MainActivity.java
private void showAboutDialog() { StringBuilder sb = new StringBuilder(); sb.append(String.format(Locale.getDefault(), "%s%n", getText(R.string.app_name))); sb.append(String.format(Locale.getDefault(), "%s: %s%n%n", getText(R.string.about_version_label), getVersion()));/*from w w w .j a va2 s .c o m*/ sb.append(String.format(Locale.getDefault(), "%s", getText(R.string.about_info))); SpannableString aboutString = new SpannableString(sb.toString()); Linkify.addLinks(aboutString, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES); LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); TextView aboutBodyView = (TextView) layoutInflater.inflate(R.layout.dialog_about, null); aboutBodyView.setText(aboutString); aboutBodyView.setMovementMethod(new LinkMovementMethod()); new AlertDialog.Builder(this).setTitle(R.string.about).setView(aboutBodyView) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do nothing } }).show(); }
From source file:org.mozilla.gecko.home.HistoryPanel.java
private void updateUiFromCursor(Cursor c) { if (c != null && c.getCount() > 0) { if (RestrictedProfiles.isAllowed(getActivity(), Restriction.DISALLOW_CLEAR_HISTORY)) { mClearHistoryButton.setVisibility(View.VISIBLE); }// w w w. ja v a 2s . co m return; } // Cursor is empty, so hide the "Clear browsing history" button, // and set the empty view if it hasn't been set already. mClearHistoryButton.setVisibility(View.GONE); if (mEmptyView == null) { // Set empty panel view. We delay this so that the empty view won't flash. final ViewStub emptyViewStub = (ViewStub) getView().findViewById(R.id.home_empty_view_stub); mEmptyView = emptyViewStub.inflate(); final ImageView emptyIcon = (ImageView) mEmptyView.findViewById(R.id.home_empty_image); emptyIcon.setImageResource(R.drawable.icon_most_recent_empty); final TextView emptyText = (TextView) mEmptyView.findViewById(R.id.home_empty_text); emptyText.setText(R.string.home_most_recent_empty); final TextView emptyHint = (TextView) mEmptyView.findViewById(R.id.home_empty_hint); final String hintText = getResources().getString(R.string.home_most_recent_emptyhint); final SpannableStringBuilder hintBuilder = formatHintText(hintText); if (hintBuilder != null) { emptyHint.setText(hintBuilder); emptyHint.setMovementMethod(LinkMovementMethod.getInstance()); emptyHint.setVisibility(View.VISIBLE); } mList.setEmptyView(mEmptyView); } }
From source file:com.gh4a.IssueActivity.java
private void fillData() { new LoadCommentsTask(this).execute(); Typeface boldCondensed = getApplicationContext().boldCondensed; ListView lvComments = (ListView) findViewById(R.id.list_view); // set details inside listview header LayoutInflater infalter = getLayoutInflater(); LinearLayout mHeader = (LinearLayout) infalter.inflate(R.layout.issue_header, lvComments, false); mHeader.setClickable(false);// www .j av a 2 s .c o m lvComments.addHeaderView(mHeader, null, false); RelativeLayout rlComment = (RelativeLayout) findViewById(R.id.rl_comment); if (!isAuthorized()) { rlComment.setVisibility(View.GONE); } TextView tvCommentTitle = (TextView) mHeader.findViewById(R.id.comment_title); mCommentAdapter = new CommentAdapter(IssueActivity.this, new ArrayList<Comment>(), mIssue.getNumber(), mIssue.getState(), mRepoOwner, mRepoName); lvComments.setAdapter(mCommentAdapter); ImageView ivGravatar = (ImageView) mHeader.findViewById(R.id.iv_gravatar); aq.id(R.id.iv_gravatar).image(GravatarUtils.getGravatarUrl(mIssue.getUser().getGravatarId()), true, false, 0, 0, aq.getCachedImage(R.drawable.default_avatar), AQuery.FADE_IN); ivGravatar.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { getApplicationContext().openUserInfoActivity(IssueActivity.this, mIssue.getUser().getLogin(), null); } }); TextView tvExtra = (TextView) mHeader.findViewById(R.id.tv_extra); TextView tvState = (TextView) mHeader.findViewById(R.id.tv_state); TextView tvTitle = (TextView) mHeader.findViewById(R.id.tv_title); TextView tvDescTitle = (TextView) mHeader.findViewById(R.id.desc_title); tvDescTitle.setTypeface(getApplicationContext().boldCondensed); tvDescTitle.setTextColor(Color.parseColor("#0099cc")); tvCommentTitle.setTypeface(getApplicationContext().boldCondensed); tvCommentTitle.setTextColor(Color.parseColor("#0099cc")); tvCommentTitle .setText(getResources().getString(R.string.issue_comments) + " (" + mIssue.getComments() + ")"); TextView tvDesc = (TextView) mHeader.findViewById(R.id.tv_desc); tvDesc.setMovementMethod(LinkMovementMethod.getInstance()); TextView tvMilestone = (TextView) mHeader.findViewById(R.id.tv_milestone); ImageView ivComment = (ImageView) findViewById(R.id.iv_comment); if (Gh4Application.THEME == R.style.DefaultTheme) { ivComment.setImageResource(R.drawable.social_send_now_dark); } ivComment.setBackgroundResource(R.drawable.abs__list_selector_holo_dark); ivComment.setPadding(5, 2, 5, 2); ivComment.setOnClickListener(this); tvExtra.setText(mIssue.getUser().getLogin() + "\n" + pt.format(mIssue.getCreatedAt())); tvState.setTextColor(Color.WHITE); if ("closed".equals(mIssue.getState())) { tvState.setBackgroundResource(R.drawable.default_red_box); tvState.setText("C\nL\nO\nS\nE\nD"); } else { tvState.setBackgroundResource(R.drawable.default_green_box); tvState.setText("O\nP\nE\nN"); } tvTitle.setText(mIssue.getTitle()); tvTitle.setTypeface(boldCondensed); boolean showInfoBox = false; if (mIssue.getAssignee() != null) { showInfoBox = true; TextView tvAssignee = (TextView) mHeader.findViewById(R.id.tv_assignee); tvAssignee.setText(mIssue.getAssignee().getLogin() + " is assigned"); tvAssignee.setVisibility(View.VISIBLE); tvAssignee.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { getApplicationContext().openUserInfoActivity(IssueActivity.this, mIssue.getAssignee().getLogin(), null); } }); ImageView ivAssignee = (ImageView) mHeader.findViewById(R.id.iv_assignee); aq.id(R.id.iv_assignee).image(GravatarUtils.getGravatarUrl(mIssue.getAssignee().getGravatarId()), true, false, 0, 0, aq.getCachedImage(R.drawable.default_avatar), AQuery.FADE_IN); ivAssignee.setVisibility(View.VISIBLE); ivAssignee.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { getApplicationContext().openUserInfoActivity(IssueActivity.this, mIssue.getAssignee().getLogin(), null); } }); } if (mIssue.getMilestone() != null) { showInfoBox = true; tvMilestone.setText( getResources().getString(R.string.issue_milestone) + ": " + mIssue.getMilestone().getTitle()); } else { tvMilestone.setVisibility(View.GONE); } String body = mIssue.getBodyHtml(); if (!StringUtils.isBlank(body)) { HttpImageGetter imageGetter = new HttpImageGetter(this); body = HtmlUtils.format(body).toString(); imageGetter.bind(tvDesc, body, mIssue.getNumber()); } LinearLayout llLabels = (LinearLayout) findViewById(R.id.ll_labels); List<Label> labels = mIssue.getLabels(); if (labels != null && !labels.isEmpty()) { showInfoBox = true; for (Label label : labels) { TextView tvLabel = new TextView(this); tvLabel.setSingleLine(true); tvLabel.setText(label.getName()); tvLabel.setTextAppearance(this, R.style.default_text_small); tvLabel.setBackgroundColor(Color.parseColor("#" + label.getColor())); tvLabel.setPadding(5, 2, 5, 2); int r = Color.red(Color.parseColor("#" + label.getColor())); int g = Color.green(Color.parseColor("#" + label.getColor())); int b = Color.blue(Color.parseColor("#" + label.getColor())); if (r + g + b < 383) { tvLabel.setTextColor(getResources().getColor(android.R.color.primary_text_dark)); } else { tvLabel.setTextColor(getResources().getColor(android.R.color.primary_text_light)); } llLabels.addView(tvLabel); View v = new View(this); v.setLayoutParams(new LayoutParams(5, LayoutParams.WRAP_CONTENT)); llLabels.addView(v); } } else { llLabels.setVisibility(View.GONE); } TextView tvPull = (TextView) mHeader.findViewById(R.id.tv_pull); if (mIssue.getPullRequest() != null && mIssue.getPullRequest().getDiffUrl() != null) { showInfoBox = true; tvPull.setVisibility(View.VISIBLE); tvPull.setOnClickListener(this); } if (!showInfoBox) { RelativeLayout rl = (RelativeLayout) mHeader.findViewById(R.id.info_box); rl.setVisibility(View.GONE); } }
From source file:org.thoughtcrime.securesms.logsubmit.SubmitLogFragment.java
private TextView handleBuildSuccessTextView(final String logUrl) { TextView showText = new TextView(getActivity()); showText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); showText.setPadding(15, 30, 15, 30); showText.setText(getString(R.string.log_submit_activity__copy_this_url_and_add_it_to_your_issue, logUrl)); showText.setAutoLinkMask(Activity.RESULT_OK); showText.setMovementMethod(LinkMovementMethod.getInstance()); showText.setOnLongClickListener(new View.OnLongClickListener() { @Override//from ww w . java2 s . co m public boolean onLongClick(View v) { @SuppressWarnings("deprecation") ClipboardManager manager = (ClipboardManager) getActivity() .getSystemService(Activity.CLIPBOARD_SERVICE); manager.setText(logUrl); Toast.makeText(getActivity(), R.string.log_submit_activity__copied_to_clipboard, Toast.LENGTH_SHORT) .show(); return true; } }); Linkify.addLinks(showText, Linkify.WEB_URLS); return showText; }
From source file:com.slushpupie.deskclock.DeskClock.java
protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_CHANGELOG: AlertDialog.Builder builder = new AlertDialog.Builder(this); // Standard AlertDialog does not support HTML-style links. // So rebuild the ScrollView->TextView with the appropriate // settings and set the view directly. TextView tv = new TextView(this); tv.setPadding(5, 5, 5, 5);/* www . j a va 2 s.c o m*/ tv.setLinksClickable(true); tv.setMovementMethod(LinkMovementMethod.getInstance()); tv.setText(R.string.changeLog); tv.setTextAppearance(this, android.R.style.TextAppearance_Medium); ScrollView sv = new ScrollView(this); sv.setPadding(14, 2, 10, 12); sv.addView(tv); builder.setView(sv).setCancelable(false).setTitle(R.string.changeLogTitle) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(DeskClock.this); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("pref_changelog", false); editor.putString("last_changelog", getString(R.string.app_version)); editor.commit(); } }); return builder.create(); default: return null; } }
From source file:com.cpd.activities.NewsOpenActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_news_open); if (getResources().getBoolean(R.bool.portrait_only)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } else {//from w ww. j a v a 2 s .c o m setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER); } Intent intent = getIntent(); mNewsVo = (NewsVo) intent.getSerializableExtra(AppTags.NEWS_VO); TrackerUtils.clickNewsArticle(mNewsVo.title); final TextView articleTextView = (TextView) findViewById(R.id.news_activity_text); mLoader = new NewsLoader(new NewsParser.NewsReady() { @Override public void OnNewsReady(NewsVo newsArticle) { mConnectionTries++; /* Avoid infinite loop */ if (mConnectionTries <= ConnectionUtils.MAX_NETWORK_TENTATIVES) { if (newsArticle.articleText == null) { mLoader.run(mNewsVo, true); } else { // Interpret HTML tags mConnectionTries = 0; articleTextView.setText(Html.fromHtml(newsArticle.articleText)); articleTextView.setMovementMethod(LinkMovementMethod.getInstance()); if (DebugUtils.DEBUG) Log.d(TAG, "Opened article: " + newsArticle.title); } } else { if (DebugUtils.ERROR) Log.e(TAG, "Not connecting to news!"); } } }); mLoader.run(mNewsVo, true); // The RssParser already gives the title and image. Therefore, we can load this content // while the NewsParser is running. Toolbar toolbar = (Toolbar) findViewById(R.id.news_open_toolbar); setSupportActionBar(toolbar); ImageView imageView = (ImageView) findViewById(R.id.news_activity_picture); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { openImageActivity(); } }); Picasso.with(this).load(mNewsVo.imgLargeUrl).into(imageView); TextView titleView = (TextView) findViewById(R.id.news_activity_title); titleView.setText(mNewsVo.title); }
From source file:com.silentcircle.accounts.AccountStep1.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); View stepView = inflater.inflate(R.layout.provisioning_bp_s1, container, false); if (stepView == null) return null; ProvisioningActivity.FilterEnter filterEnter = new ProvisioningActivity.FilterEnter(); mUsernameInput = (EditText) stepView.findViewById(R.id.ProvisioningUsernameInput); mUsernameInput.addTextChangedListener(filterEnter); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mUsernameInput.setBackground(mUsernameInput.getBackground().getConstantState().newDrawable()); mUsernameLayout = (TextInputLayout) stepView.findViewById(R.id.ProvisioningUsernameLayout); mUsernameLayout.setErrorEnabled(true); mPasswordInput = (EditText) stepView.findViewById(R.id.ProvisioningPasswordInput); mPasswordInput.setTag("current_password"); mPasswordLayout = (TextInputLayout) stepView.findViewById(R.id.ProvisioningPasswordLayout); mPasswordLayout.setErrorEnabled(true); mUsernameInput.addTextChangedListener(new TextWatcher() { @Override/*from w w w .j ava 2 s .com*/ public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { boolean newState = s.toString().contains("@"); if (newState != loginSso) { loginSso = newState; updateVisibility(); } mUserValid = checkValid(mUsernameInput, mUsernameLayout, null, false); updateLoginButton(); } }); mUsernameInput.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { // scroll up to try to make sure password field also visible scrollViewToTop(mUsernameLayout); } else { checkValid(mUsernameInput, mUsernameLayout, getString(R.string.provisioning_user_req), false); } } }); mUsernameInput.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { return actionId == EditorInfo.IME_ACTION_NEXT && !checkValid(mUsernameInput, mUsernameLayout, getString(R.string.provisioning_user_req), true); } }); mPasswordInput.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { mPassValid = checkValid(mPasswordInput, mPasswordLayout, null, false); updateLoginButton(); } }); mPasswordInput.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { // make sure password field visible if (!hasFocus) { checkValid(mPasswordInput, mPasswordLayout, getString(R.string.provisioning_password_req), false); } } }); mPasswordInput.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { return actionId == EditorInfo.IME_ACTION_DONE && !checkValid(mPasswordInput, mPasswordLayout, getString(R.string.provisioning_password_req), true); } }); mRegisterNew = (Button) stepView.findViewById(R.id.registerNew); mRegisterNew.setOnClickListener(this); mLoginExisting = (Button) stepView.findViewById(R.id.loginExisting); mLoginExisting.setOnClickListener(this); mLoginSavedText = mLoginExisting.getText(); // FIXME: Remove when account creation is enabled // only allow create account when a license code is present // the following three lines should be removed when freemium support is to be included in the product Bundle args = getArguments(); if (args == null || TextUtils.isEmpty(args.getString(AuthenticatorActivity.ARG_RONIN_CODE, null))) mRegisterNew.setVisibility(View.GONE); mShowPassword = (CheckBox) stepView.findViewById(R.id.ShowPassword); mShowPassword.setOnClickListener(this); mUserFields = (RelativeLayout) stepView.findViewById(R.id.ProvisioningUserFields); ((TextView) stepView.findViewById(R.id.ProvisioningVersion)).setText("version " + BuildConfig.VERSION_NAME); TextView privacy = (TextView) stepView.findViewById(R.id.ProvisioningPrivacy); privacy.setText(Html.fromHtml("<a href=\"https://accounts.silentcircle.com/privacy-policy\">" + getResources().getString(R.string.provisioning_privacy) + "</a>")); privacy.setMovementMethod(LinkMovementMethod.getInstance()); stripUnderlines(privacy); TextView terms = (TextView) stepView.findViewById(R.id.ProvisioningTerms); terms.setText(Html.fromHtml("<a href=\"https://accounts.silentcircle.com/terms\">" + getResources().getString(R.string.provisioning_terms) + "</a>")); terms.setMovementMethod(LinkMovementMethod.getInstance()); stripUnderlines(terms); mForgotPassword = (TextView) stepView.findViewById(R.id.ProvisioningForgotPassword); mForgotPassword.setText(Html.fromHtml("<a href=\"https://accounts.silentcircle.com/account/recover/\">" + getResources().getString(R.string.provisioning_forgot_pwd) + "</a>")); mForgotPassword.setMovementMethod(LinkMovementMethod.getInstance()); stripUnderlines(mForgotPassword); mScrollView = (ScrollView) stepView.findViewById(R.id.ProvisioningScrollFrameLayout); Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), "fonts/TiemposHeadline-Regular.otf"); TextView tv = (TextView) stepView.findViewById(R.id.AppText); tv.setTypeface(tf); stepView.setBackgroundColor(getResources().getColor(R.color.auth_background_grey)); if (ConfigurationUtilities.mEnableDevDebOptions) { mEnvironmentButton = (Button) stepView.findViewById(R.id.switchConfiguration); mEnvironmentButton.setVisibility(View.VISIBLE); mEnvironmentButton .setText(ConfigurationUtilities.mUseDevelopConfiguration ? R.string.switch_to_production : R.string.switch_to_develop); mEnvironmentButton.setOnClickListener(this); } return stepView; }