List of usage examples for android.text.method LinkMovementMethod LinkMovementMethod
LinkMovementMethod
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 . ja va 2s .co 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:com.irccloud.android.activity.MainActivity.java
private void show_topic_popup() { if (buffer == null) return;// w w w . j a v a 2 s . c o m ChannelsDataSource.Channel c = ChannelsDataSource.getInstance().getChannelForBuffer(buffer.bid); if (c != null) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB); View v = getLayoutInflater().inflate(R.layout.dialog_topic, null); if (c.topic_text.length() > 0) { String author = ""; if (c.topic_author != null && c.topic_author.length() > 0) { author = " Set by " + c.topic_author; if (c.topic_time > 0) { author += " on " + DateFormat.getDateTimeInstance().format(new Date(c.topic_time * 1000)); } v.findViewById(R.id.setBy).setVisibility(View.VISIBLE); ((TextView) v.findViewById(R.id.setBy)).setText(author); } ((TextView) v.findViewById(R.id.topic)).setText(ColorFormatter.html_to_spanned( ColorFormatter.emojify(ColorFormatter.irc_to_html(TextUtils.htmlEncode(c.topic_text))), true, server)); } else { ((TextView) v.findViewById(R.id.topic)).setText("No topic set."); } if (c.mode.length() > 0) { v.findViewById(R.id.mode).setVisibility(View.VISIBLE); ((TextView) v.findViewById(R.id.mode)).setText("Mode: +" + c.mode); for (ChannelsDataSource.Mode m : c.modes) { switch (m.mode) { case "i": v.findViewById(R.id.mode_i).setVisibility(View.VISIBLE); break; case "k": v.findViewById(R.id.mode_k).setVisibility(View.VISIBLE); ((TextView) v.findViewById(R.id.key)).setText(m.param); break; case "m": v.findViewById(R.id.mode_m).setVisibility(View.VISIBLE); break; case "n": v.findViewById(R.id.mode_n).setVisibility(View.VISIBLE); break; case "p": v.findViewById(R.id.mode_p).setVisibility(View.VISIBLE); break; case "s": v.findViewById(R.id.mode_s).setVisibility(View.VISIBLE); break; case "t": v.findViewById(R.id.mode_t).setVisibility(View.VISIBLE); break; } } } builder.setView(v); builder.setNegativeButton("Close", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); boolean canEditTopic; if (c.hasMode("t")) { UsersDataSource.User self_user = UsersDataSource.getInstance().getUser(buffer.bid, server.nick); canEditTopic = (self_user != null && (self_user.mode.contains(server != null ? server.MODE_OPER : "Y") || self_user.mode.contains(server != null ? server.MODE_OWNER : "q") || self_user.mode.contains(server != null ? server.MODE_ADMIN : "a") || self_user.mode.contains(server != null ? server.MODE_OP : "o") || self_user.mode.contains(server != null ? server.MODE_HALFOP : "h"))); } else { canEditTopic = true; } if (canEditTopic) { builder.setPositiveButton("Edit Topic", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); editTopic(); } }); } final AlertDialog dialog = builder.create(); dialog.setOwnerActivity(MainActivity.this); dialog.show(); ((TextView) v.findViewById(R.id.topic)).setMovementMethod(new LinkMovementMethod() { @Override public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) { if (super.onTouchEvent(widget, buffer, event) && event.getAction() == MotionEvent.ACTION_UP) { dialog.dismiss(); return true; } return false; } }); } }