List of usage examples for android.text.style URLSpan getURL
public String getURL()
From source file:com.android.mail.browse.MessageHeaderView.java
private static void stripUnderlines(TextView textView, Account account) { final Spannable spannable = (Spannable) textView.getText(); final URLSpan[] urls = textView.getUrls(); for (URLSpan span : urls) { final int start = spannable.getSpanStart(span); final int end = spannable.getSpanEnd(span); spannable.removeSpan(span);//from w w w . j av a2s .c om span = new EmailAddressSpan(account, span.getURL().substring(7)); spannable.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } }
From source file:com.silentcircle.accounts.AccountStep1.java
private void stripUnderlines(TextView textView) { Spannable s = (Spannable) textView.getText(); URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class); for (URLSpan span : spans) { int start = s.getSpanStart(span); int end = s.getSpanEnd(span); s.removeSpan(span);//ww w. j a v a 2 s . c o m span = new URLSpanNoUnderline(span.getURL()); s.setSpan(span, start, end, 0); } textView.setText(s); }
From source file:com.keylesspalace.tusky.util.LinkHelper.java
/** * Finds links, mentions, and hashtags in a piece of text and makes them clickable, associating * them with callbacks to notify when they're clicked. * * @param view the returned text will be put in * @param content containing text with mentions, links, or hashtags * @param mentions any '@' mentions which are known to be in the content * @param listener to notify about particular spans that are clicked *///from w w w .j a v a2 s.c o m public static void setClickableText(TextView view, Spanned content, @Nullable Status.Mention[] mentions, final LinkListener listener) { SpannableStringBuilder builder = new SpannableStringBuilder(content); URLSpan[] urlSpans = content.getSpans(0, content.length(), URLSpan.class); for (URLSpan span : urlSpans) { int start = builder.getSpanStart(span); int end = builder.getSpanEnd(span); int flags = builder.getSpanFlags(span); CharSequence text = builder.subSequence(start, end); if (text.charAt(0) == '#') { final String tag = text.subSequence(1, text.length()).toString(); ClickableSpan newSpan = new ClickableSpan() { @Override public void onClick(View widget) { listener.onViewTag(tag); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); } }; builder.removeSpan(span); builder.setSpan(newSpan, start, end, flags); } else if (text.charAt(0) == '@' && mentions != null && mentions.length > 0) { String accountUsername = text.subSequence(1, text.length()).toString(); /* There may be multiple matches for users on different instances with the same * username. If a match has the same domain we know it's for sure the same, but if * that can't be found then just go with whichever one matched last. */ String id = null; for (Status.Mention mention : mentions) { if (mention.localUsername.equalsIgnoreCase(accountUsername)) { id = mention.id; if (mention.url.contains(getDomain(span.getURL()))) { break; } } } if (id != null) { final String accountId = id; ClickableSpan newSpan = new ClickableSpan() { @Override public void onClick(View widget) { listener.onViewAccount(accountId); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); } }; builder.removeSpan(span); builder.setSpan(newSpan, start, end, flags); } } else { ClickableSpan newSpan = new CustomURLSpan(span.getURL()); builder.removeSpan(span); builder.setSpan(newSpan, start, end, flags); } } view.setText(builder); view.setLinksClickable(true); view.setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:org.thoughtcrime.securesms.ConversationItem.java
private SpannableString linkifyMessageBody(SpannableString messageBody, boolean shouldLinkifyAllLinks) { boolean hasLinks = Linkify.addLinks(messageBody, shouldLinkifyAllLinks ? Linkify.ALL : 0); if (hasLinks) { URLSpan[] urlSpans = messageBody.getSpans(0, messageBody.length(), URLSpan.class); for (URLSpan urlSpan : urlSpans) { int start = messageBody.getSpanStart(urlSpan); int end = messageBody.getSpanEnd(urlSpan); messageBody.setSpan(new LongClickCopySpan(urlSpan.getURL()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }/*from ww w .j a va2 s.co m*/ } return messageBody; }
From source file:com.hippo.nimingban.ui.ListActivity.java
private Spanned fixURLSpan(Spanned spanned) { Spannable spannable;//from w w w .j a va2 s . c o m if (spanned instanceof Spannable) { spannable = (Spannable) spanned; } else { spannable = new SpannableString(spanned); } URLSpan[] urlSpans = spannable.getSpans(0, spanned.length(), URLSpan.class); if (urlSpans == null) { return spanned; } for (URLSpan urlSpan : urlSpans) { String url = urlSpan.getURL(); if (TextUtils.isEmpty(url)) { spannable.removeSpan(urlSpan); } try { new URL(url); } catch (MalformedURLException e) { URL absoluteUrl; // It might be relative path try { // Use absolute url absoluteUrl = new URL(new URL(ACUrl.HOST), url); int start = spannable.getSpanStart(urlSpan); int end = spannable.getSpanEnd(urlSpan); spannable.removeSpan(urlSpan); spannable.setSpan(new URLSpan(absoluteUrl.toString()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } catch (MalformedURLException e1) { // Can't get url spannable.removeSpan(urlSpan); } } } return spannable; }
From source file:com.keylesspalace.tusky.ComposeActivity.java
int calculateTextLength() { int offset = 0; URLSpan[] urlSpans = textEditor.getUrls(); if (urlSpans != null) { for (URLSpan span : urlSpans) { offset += Math.max(0, span.getURL().length() - MAXIMUM_URL_LENGTH); }//from w w w . j ava 2s .com } int length = textEditor.length() - offset; if (statusHideText) { length += contentWarningEditor.length(); } return length; }
From source file:com.tct.mail.browse.MessageHeaderView.java
private void stripUnderlines(TextView textView, Account account) { final Spannable spannable = (Spannable) textView.getText(); final URLSpan[] urls = textView.getUrls(); for (URLSpan span : urls) { final int start = spannable.getSpanStart(span); final int end = spannable.getSpanEnd(span); spannable.removeSpan(span);/*from w w w.j av a 2s . co m*/ //TS: rong-tang 2016-04-19 EMAIL BUGFIX-1951808 MOD_S span = new EmailAddressSpan(getContext(), account, span.getURL().substring(7), mContactInfoSource); ((EmailAddressSpan) span).setFragmentManager(mFragmentManager); //TS: rong-tang 2016-04-19 EMAIL BUGFIX-1951808 MOD_E spannable.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } }
From source file:org.de.jmg.learn._MainActivity.java
public void getVokabel(final boolean showBeds, boolean LoadNext, boolean requestFocusEdWord, boolean DontPrompt) throws Exception { if (iv != null) { iv.setVisibility(View.GONE); }/* ww w . j a v a 2 s . c o m*/ if (iv2 != null) iv2.setVisibility(View.GONE); try { if (_btnRight == null) return; EndEdit(DontPrompt); setBtnsEnabled(true); if (showBeds && _vok.getIndex() >= 1) { _btnRight.setEnabled(true); _btnWrong.setEnabled(true); _btnEdit.setEnabled(true); _btnSkip.setEnabled(true); _btnView.setEnabled(true); } else { _btnRight.setEnabled(false); _btnWrong.setEnabled(false); if (_vok.getIndex() < 1) { _btnEdit.setEnabled(false); _btnSkip.setEnabled(false); _btnView.setEnabled(false); } } if (LoadNext) _vok.setLernIndex((short) (_vok.getLernIndex() + 1)); View v; TextView t; String txtBed = getString(R.string.cloze); if (showBeds) { v = findViewById(R.id.txtMeaning1); t = (TextView) v; assert t != null; t.setText(lib.getSpanableString(_vok.getBedeutung1())); txtBed = t.getText().toString(); } v = findViewById(R.id.word); t = (TextView) v; assert t != null; String txtWord = getString(R.string.cloze); if (!_vok.reverse || showBeds) { t.setText(lib.getSpanableString(_vok.getWort()), TextView.BufferType.SPANNABLE); txtWord = t.getText().toString(); txtWord = replaceClozes(txtWord, txtBed); speak(txtWord, _vok.getLangWord(), "word", true); } else { t.setText(""); } if (_vok.getSprache() == EnumSprachen.Hebrew || _vok.getSprache() == EnumSprachen.Griechisch || (_vok.getFontWort().getName().equalsIgnoreCase("Cardo"))) { t.setTypeface(_vok.TypefaceCardo); _txtedWord.setTypeface(_vok.TypefaceCardo); } else { t.setTypeface(Typeface.DEFAULT); _txtedWord.setTypeface(Typeface.DEFAULT); } t.scrollTo(0, 0); v = findViewById(R.id.Comment); t = (TextView) v; assert t != null; t.setVisibility(View.VISIBLE); SpannableString tspanKom = lib.getSpanableString(_vok.getKommentar()); URLSpan[] urlSpans = tspanKom.getSpans(0, tspanKom.length(), URLSpan.class); for (final URLSpan span : urlSpans) { int start = tspanKom.getSpanStart(span); int end = tspanKom.getSpanEnd(span); String txt = tspanKom.toString().substring(start, end); if (txtIsPicture(txt)) { tspanKom.removeSpan(span); tspanKom.setSpan(new urlclickablespan(span.getURL()) { @Override public void onClick(View widget) { Bitmap b; try { b = lib.downloadpicture(this.url); } catch (Exception ex) { b = null; } if (b != null) { if (iv == null) { iv = new ImageView(context); SetTouchListener(iv); } b = resizeBM(b); iv.setImageBitmap(b); if (iv.getParent() == null) { try { LayoutParams p = _txtMeaning1.getLayoutParams(); //p.width = LayoutParams.WRAP_CONTENT; //p.height = LayoutParams.WRAP_CONTENT; rellayoutMain.addView(iv, p); } catch (Exception ex) { Log.e("addImageView", ex.getMessage(), ex); } } else { Log.d("ImageView", "exists"); } _txtMeaning1.setVisibility(View.GONE); iv.setVisibility(View.VISIBLE); } } }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } t.setText(tspanKom, TextView.BufferType.SPANNABLE); if (_vok.getSprache() == EnumSprachen.Hebrew || _vok.getSprache() == EnumSprachen.Griechisch || (_vok.getFontKom().getName().equalsIgnoreCase("Cardo"))) { t.setTypeface(_vok.TypefaceCardo); _txtedKom.setTypeface(_vok.TypefaceCardo); } else { t.setTypeface(Typeface.DEFAULT); _txtedKom.setTypeface(Typeface.DEFAULT); } if (_isSmallDevice && libString.IsNullOrEmpty(t.getText().toString())) { t.setVisibility(View.GONE); } else { t.setVisibility(View.VISIBLE); } t.scrollTo(0, 0); v = findViewById(R.id.txtMeaning1); t = (TextView) v; assert t != null; if (!libString.IsNullOrEmpty(_vok.getBedeutung2())) { t.setImeOptions(EditorInfo.IME_ACTION_NEXT); } if (_vok.reverse || showBeds) { SpannableString tspan = lib.getSpanableString(_vok.getBedeutung1()); //final String picname = _main.getString(R.string.picture); t.setVisibility(View.VISIBLE); if (txtIsPicture(tspan.toString())) { URLSpan urlspn[] = tspan.getSpans(0, tspan.length(), URLSpan.class); for (URLSpan url : urlspn) { Bitmap b; try { b = lib.downloadpicture(url.getURL()); } catch (Exception ex) { b = null; } if (b != null) { if (iv == null) { iv = new ImageView(context); SetTouchListener(iv); } b = resizeBM(b); iv.setImageBitmap(b); if (iv.getParent() == null) { try { LayoutParams p = t.getLayoutParams(); //p.width = LayoutParams.WRAP_CONTENT; //p.height = LayoutParams.WRAP_CONTENT; rellayoutMain.addView(iv, p); } catch (Exception ex) { Log.e("Imagview", ex.getMessage(), ex); } } else { Log.d("ImageView", "exists"); } t.setVisibility(View.GONE); iv.setVisibility(View.VISIBLE); } } } else { // iv.setVisibility(View.GONE); t.setVisibility(View.VISIBLE); } t.setText(tspan); } else { t.setText(Vokabel.getComment(_vok.getBedeutung1())); } if (_vok.reverse || showBeds) { String txt = t.getText().toString(); txt = replaceClozes(txt, txtWord); speak(txt, _vok.getLangMeaning(), "meaning1", _vok.reverse); } if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) { t.setTypeface(_vok.TypefaceCardo); } else { t.setTypeface(Typeface.DEFAULT); } t.setOnFocusChangeListener(FocusListenerMeaning1); t.scrollTo(0, 0); v = findViewById(R.id.txtMeaning2); t = (TextView) v; assert t != null; t.setText((_vok.reverse || showBeds ? _vok.getBedeutung2() : Vokabel.getComment(_vok.getBedeutung2()))); if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) { t.setTypeface(_vok.TypefaceCardo); } else { t.setTypeface(Typeface.DEFAULT); } if (libString.IsNullOrEmpty(_vok.getBedeutung2()) || _vok.getCardMode()) { t.setVisibility(View.GONE); _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_DONE); } else { t.setVisibility(View.VISIBLE); _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_NEXT); if (_vok.reverse || showBeds) { String txt = t.getText().toString(); //if (txtWord != null) // txt = txt.replaceAll("_{2,}", txtWord).replaceAll("\\.{4,}", txtWord); speak(txt, _vok.getLangMeaning(), "meaning2"); } } v = findViewById(R.id.txtMeaning3); t = (TextView) v; assert t != null; t.setText((_vok.reverse || showBeds ? _vok.getBedeutung3() : Vokabel.getComment(_vok.getBedeutung3()))); if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) { t.setTypeface(_vok.TypefaceCardo); } else { t.setTypeface(Typeface.DEFAULT); } if (libString.IsNullOrEmpty(_vok.getBedeutung3()) || _vok.getCardMode()) { t.setVisibility(View.GONE); _txtMeaning2.setImeOptions(EditorInfo.IME_ACTION_DONE); } else { t.setVisibility(View.VISIBLE); _txtMeaning2.setImeOptions(EditorInfo.IME_ACTION_NEXT); _txtMeaning3.setImeOptions(EditorInfo.IME_ACTION_DONE); if (_vok.reverse || showBeds) { String txt = t.getText().toString(); //if (txtWord != null) // txt = txt.replaceAll("_{2,}", txtWord).replaceAll("\\.{4,}", txtWord); speak(txt, _vok.getLangMeaning(), "meaning3"); } } if (_vok.reverse && showBeds) speak(txtWord, _vok.getLangWord(), "word"); lib.setBgEditText(_txtMeaning1, _MeaningBG); lib.setBgEditText(_txtMeaning2, _MeaningBG); lib.setBgEditText(_txtMeaning3, _MeaningBG); if (!_isSmallDevice && !requestFocusEdWord) { _txtMeaning1.requestFocus(); } else { if (!requestFocusEdWord) _txtWord.requestFocus(); else _txtedWord.requestFocus(); } SetActionBarTitle(); _scrollView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { lib.removeLayoutListener(_scrollView.getViewTreeObserver(), this); hideKeyboard(); if (showBeds) { _scrollView.scrollTo(0, _txtMeaning1.getTop()); } else { _txtWord.requestFocus(); _scrollView.fullScroll(View.FOCUS_UP); } } }); } catch (Exception e) { lib.ShowException(_main, e); } }
From source file:com.irccloud.android.activity.MainActivity.java
@SuppressLint("NewApi") @SuppressWarnings("deprecation") private void showUserPopup(UsersDataSource.User user, Spanned message) { ArrayList<String> itemList = new ArrayList<String>(); final String[] items; final Spanned text_to_copy = message; selected_user = user;//w ww. j av a 2 s . co m AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB); if (message != null) { if (message.getSpans(0, message.length(), URLSpan.class).length > 0) itemList.add("Copy URL"); itemList.add("Copy Message"); } if (selected_user != null) { itemList.add("Whois"); itemList.add("Send a message"); itemList.add("Mention"); itemList.add("Invite to a channel"); itemList.add("Ignore"); if (buffer.type.equalsIgnoreCase("channel")) { UsersDataSource.User self_user = UsersDataSource.getInstance().getUser(buffer.bid, server.nick); if (self_user != null && self_user.mode != null) { if (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")) { if (selected_user.mode.contains(server != null ? server.MODE_OP : "o")) itemList.add("Deop"); else itemList.add("Op"); } if (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")) { itemList.add("Kick"); itemList.add("Ban"); } } } itemList.add("Copy Hostmask"); } items = itemList.toArray(new String[itemList.size()]); if (selected_user != null) if (selected_user.hostmask != null && selected_user.hostmask.length() > 0) builder.setTitle(selected_user.nick + "\n(" + selected_user.hostmask + ")"); else builder.setTitle(selected_user.nick); else builder.setTitle("Message"); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int item) { if (conn == null || buffer == null) return; AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB); View view; final TextView prompt; final EditText input; AlertDialog dialog; if (items[item].equals("Copy Message")) { if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService( CLIPBOARD_SERVICE); clipboard.setText(text_to_copy); } else { @SuppressLint("ServiceCast") android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService( CLIPBOARD_SERVICE); if (clipboard != null) { android.content.ClipData clip = android.content.ClipData .newPlainText("IRCCloud Message", text_to_copy); clipboard.setPrimaryClip(clip); } else { Toast.makeText(MainActivity.this, "Unable to copy message. Please try again.", Toast.LENGTH_SHORT).show(); return; } } Toast.makeText(MainActivity.this, "Message copied to clipboard", Toast.LENGTH_SHORT).show(); } else if (items[item].equals("Copy Hostmask")) { if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService( CLIPBOARD_SERVICE); clipboard.setText(selected_user.nick + "!" + selected_user.hostmask); } else { @SuppressLint("ServiceCast") android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService( CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("Hostmask", selected_user.nick + "!" + selected_user.hostmask); clipboard.setPrimaryClip(clip); } Toast.makeText(MainActivity.this, "Hostmask copied to clipboard", Toast.LENGTH_SHORT).show(); } else if (items[item].equals("Copy URL") && text_to_copy != null) { final ArrayList<String> urlListItems = new ArrayList<String>(); for (URLSpan o : text_to_copy.getSpans(0, text_to_copy.length(), URLSpan.class)) { String url = o.getURL(); url = url.replace(getResources().getString(R.string.IMAGE_SCHEME) + "://", "http://"); url = url.replace(getResources().getString(R.string.IMAGE_SCHEME_SECURE) + "://", "https://"); if (server != null) { url = url.replace( getResources().getString(R.string.IRCCLOUD_SCHEME) + "://cid/" + server.cid + "/", ((server.ssl > 0) ? "ircs://" : "irc://") + server.hostname + ":" + server.port + "/"); } urlListItems.add(url); } if (urlListItems.size() == 1) { if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService( CLIPBOARD_SERVICE); clipboard.setText(urlListItems.get(0)); } else { @SuppressLint("ServiceCast") android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService( CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData .newPlainText(urlListItems.get(0), urlListItems.get(0)); clipboard.setPrimaryClip(clip); } Toast.makeText(MainActivity.this, "URL copied to clipboard", Toast.LENGTH_SHORT).show(); } else { builder = new AlertDialog.Builder(MainActivity.this); builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB); builder.setTitle("Choose a URL"); builder.setItems(urlListItems.toArray(new String[urlListItems.size()]), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService( CLIPBOARD_SERVICE); clipboard.setText(urlListItems.get(i)); } else { @SuppressLint("ServiceCast") android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService( CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData .newPlainText(urlListItems.get(i), urlListItems.get(i)); clipboard.setPrimaryClip(clip); } Toast.makeText(MainActivity.this, "URL copied to clipboard", Toast.LENGTH_SHORT).show(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog = builder.create(); dialog.setOwnerActivity(MainActivity.this); dialog.getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); dialog.show(); } } else if (items[item].equals("Whois")) { conn.whois(buffer.cid, selected_user.nick, null); } else if (items[item].equals("Send a message")) { conn.say(buffer.cid, null, "/query " + selected_user.nick); } else if (items[item].equals("Mention")) { if (!getSharedPreferences("prefs", 0).getBoolean("mentionTip", false)) { Toast.makeText(MainActivity.this, "Double-tap a message to quickly reply to the sender", Toast.LENGTH_LONG).show(); SharedPreferences.Editor editor = getSharedPreferences("prefs", 0).edit(); editor.putBoolean("mentionTip", true); editor.commit(); } onUserDoubleClicked(selected_user.nick); } else if (items[item].equals("Invite to a channel")) { view = getDialogTextPrompt(); prompt = (TextView) view.findViewById(R.id.prompt); input = (EditText) view.findViewById(R.id.textInput); input.setText(""); prompt.setText("Invite " + selected_user.nick + " to a channel"); builder.setTitle(server.name + " (" + server.hostname + ":" + (server.port) + ")"); builder.setView(view); builder.setPositiveButton("Invite", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { conn.invite(buffer.cid, input.getText().toString(), selected_user.nick); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog = builder.create(); dialog.setOwnerActivity(MainActivity.this); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); dialog.show(); } else if (items[item].equals("Ignore")) { view = getDialogTextPrompt(); prompt = (TextView) view.findViewById(R.id.prompt); input = (EditText) view.findViewById(R.id.textInput); input.setText("*!" + selected_user.hostmask); prompt.setText("Ignore messages for " + selected_user.nick + " at this hostmask"); builder.setTitle(server.name + " (" + server.hostname + ":" + (server.port) + ")"); builder.setView(view); builder.setPositiveButton("Ignore", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { conn.ignore(buffer.cid, input.getText().toString()); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog = builder.create(); dialog.setOwnerActivity(MainActivity.this); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); dialog.show(); } else if (items[item].equals("Op")) { conn.mode(buffer.cid, buffer.name, "+" + (server != null ? server.MODE_OP : "o") + " " + selected_user.nick); } else if (items[item].equals("Deop")) { conn.mode(buffer.cid, buffer.name, "-" + (server != null ? server.MODE_OP : "o") + " " + selected_user.nick); } else if (items[item].equals("Kick")) { view = getDialogTextPrompt(); prompt = (TextView) view.findViewById(R.id.prompt); input = (EditText) view.findViewById(R.id.textInput); input.setText(""); prompt.setText("Give a reason for kicking"); builder.setTitle(server.name + " (" + server.hostname + ":" + (server.port) + ")"); builder.setView(view); builder.setPositiveButton("Kick", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { conn.kick(buffer.cid, buffer.name, selected_user.nick, input.getText().toString()); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog = builder.create(); dialog.setOwnerActivity(MainActivity.this); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); dialog.show(); } else if (items[item].equals("Ban")) { view = getDialogTextPrompt(); prompt = (TextView) view.findViewById(R.id.prompt); input = (EditText) view.findViewById(R.id.textInput); input.setText("*!" + selected_user.hostmask); prompt.setText("Add a banmask for " + selected_user.nick); builder.setTitle(server.name + " (" + server.hostname + ":" + (server.port) + ")"); builder.setView(view); builder.setPositiveButton("Ban", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { conn.mode(buffer.cid, buffer.name, "+b " + input.getText().toString()); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog = builder.create(); dialog.setOwnerActivity(MainActivity.this); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); dialog.show(); } dialogInterface.dismiss(); } }); AlertDialog dialog = builder.create(); dialog.setOwnerActivity(this); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { MessageViewFragment mvf = (MessageViewFragment) getSupportFragmentManager() .findFragmentById(R.id.messageViewFragment); if (mvf != null) mvf.longPressOverride = false; } }); dialog.show(); }