List of usage examples for android.app AlertDialog setOnShowListener
public void setOnShowListener(@Nullable OnShowListener listener)
From source file:com.juick.android.MessageMenu.java
protected void runActions() { if (!isDialogMode()) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); final CharSequence[] items = new CharSequence[menuActions.size()]; for (int j = 0; j < items.length; j++) { items[j] = menuActions.get(j).title; }/* w w w.ja v a 2 s. com*/ builder.setItems(items, this); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { ColorsTheme.ColorTheme colorTheme = JuickMessagesAdapter.getColorTheme(activity); ColorDrawable divider = new ColorDrawable( colorTheme.getColor(ColorsTheme.ColorKey.COMMON_BACKGROUND, 0xFFFFFFFF)); alertDialog.getListView().setDivider(divider); alertDialog.getListView().setDividerHeight(1); } }); alertDialog.show(); final ListAdapter adapter = alertDialog.getListView().getAdapter(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity); float menuFontScale = 1; try { menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0")); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } final boolean compressedMenu = sp.getBoolean("compressedMenu", false); final boolean singleLineMenu = sp.getBoolean("singleLineMenu", false); final float finalMenuFontScale = menuFontScale; final int screenHeight = activity.getWindow().getWindowManager().getDefaultDisplay().getHeight(); alertDialog.getListView().setAdapter(new ListAdapter() { @Override public boolean areAllItemsEnabled() { return adapter.areAllItemsEnabled(); } @Override public boolean isEnabled(int position) { return adapter.isEnabled(position); } @Override public void registerDataSetObserver(DataSetObserver observer) { adapter.registerDataSetObserver(observer); } @Override public void unregisterDataSetObserver(DataSetObserver observer) { adapter.unregisterDataSetObserver(observer); } @Override public int getCount() { return items.length; } @Override public Object getItem(int position) { return adapter.getItem(position); } @Override public long getItemId(int position) { return adapter.getItemId(position); } @Override public boolean hasStableIds() { return adapter.hasStableIds(); } @Override public View getView(int position, View convertView, ViewGroup parent) { View retval = adapter.getView(position, null, parent); if (retval instanceof TextView) { TextView tv = (TextView) retval; if (compressedMenu) { int minHeight = (int) ((screenHeight * 0.7) / getCount()); tv.setMinHeight(minHeight); tv.setMinimumHeight(minHeight); } if (singleLineMenu) { tv.setSingleLine(true); tv.setEllipsize(TextUtils.TruncateAt.MIDDLE); } tv.setTextSize(22 * finalMenuFontScale); } return retval; } @Override public int getItemViewType(int position) { return adapter.getItemViewType(position); } @Override public int getViewTypeCount() { return adapter.getViewTypeCount(); } @Override public boolean isEmpty() { return adapter.isEmpty(); } }); } else { AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(activity, R.style.Theme_Sherlock)); View dialogView = activity.getLayoutInflater().inflate(R.layout.message_menu2, null); builder.setView(dialogView); builder.setCancelable(true); int width = activity.getWindowManager().getDefaultDisplay().getWidth(); View scrollView = dialogView.findViewById(R.id.scrollView); scrollView.getLayoutParams().width = (int) (width * 0.90); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { //MainActivity.restyleChildrenOrWidget(alertDialog.getWindow().getDecorView()); } }); TextView messageNo = (TextView) dialogView.findViewById(R.id.message_no); messageNo.setText(listSelectedItem.getDisplayMessageNo()); Spinner openUrl = (Spinner) dialogView.findViewById(R.id.open_url); Button singleURL = (Button) dialogView.findViewById(R.id.single_url); if (urls != null && urls.size() == 1) { singleURL.setVisibility(View.VISIBLE); openUrl.setVisibility(View.GONE); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(urls.get(0)); sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); singleURL.setText(sb); singleURL.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); launchURL(listSelectedItem.getMID(), urls.get(0)); } }); } else if (urls != null && urls.size() > 0) { singleURL.setVisibility(View.GONE); openUrl.setVisibility(View.VISIBLE); openUrl.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != 0) { alertDialog.dismiss(); launchURL(listSelectedItem.getMID(), urls.get(position)); } } @Override public void onNothingSelected(AdapterView<?> parent) { //To change body of implemented methods use File | Settings | File Templates. } }); urls.add(0, activity.getString(R.string.ClickToSelectURL)); openUrl.setAdapter(new BaseAdapter() { @Override public int getCount() { return urls.size(); } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View rowView = activity.getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null); TextView textView = (TextView) rowView.findViewById(android.R.id.text1); textView.setSingleLine(false); textView.setMaxLines(5); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(urls.get(position)); if (position == 0) { textView.setTextColor(0xFF808080); } else { sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } textView.setText(sb); return rowView; } }); } else { openUrl.setVisibility(View.GONE); singleURL.setVisibility(View.GONE); } final String UName = listSelectedItem.User.UName; View recommendMessage = dialogView.findViewById(R.id.recommend_message); View deleteMessage = dialogView.findViewById(R.id.delete_message); View saveMessage = dialogView.findViewById(R.id.save_message); View unsaveMessage = dialogView.findViewById(R.id.unsave_message); //View subscribeUser = dialogView.findViewById(R.id.subscribe_user); View subscribeMessage = dialogView.findViewById(R.id.subscribe_message); //View unsubscribeUser = dialogView.findViewById(R.id.unsubscribe_user); View unsubscribeMessage = dialogView.findViewById(R.id.unsubscribe_message); View translateMessage = dialogView.findViewById(R.id.translate_message); View shareMessage = dialogView.findViewById(R.id.share_message); //View blacklistUser = dialogView.findViewById(R.id.blacklist_user); //View filterUser = dialogView.findViewById(R.id.filter_user); //View userBlog = dialogView.findViewById(R.id.user_blog); //View userStats = dialogView.findViewById(R.id.user_stats); View openMessageInBrowser = dialogView.findViewById(R.id.open_message_in_browser); Button userCenter = (Button) dialogView.findViewById(R.id.user_center); if (null == dialogView.findViewById(R.id.column_3)) { // only for portrait userCenter.setText("@" + listSelectedItem.User.UName + " " + userCenter.getText()); } unsubscribeMessage.setEnabled(listSelectedItem.getRID() == 0); subscribeMessage.setEnabled(listSelectedItem.getRID() == 0); unsaveMessage.setEnabled(listSelectedItem.getRID() == 0); recommendMessage.setEnabled(listSelectedItem.getRID() == 0); if (UName.equalsIgnoreCase(JuickAPIAuthorizer.getJuickAccountName(activity.getApplicationContext()))) { recommendMessage.setVisibility(View.GONE); } else { deleteMessage.setVisibility(View.GONE); } if (messagesSource instanceof SavedMessagesSource) { saveMessage.setVisibility(View.GONE); } else { unsaveMessage.setVisibility(View.GONE); } recommendMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionRecommendMessage(); } }); deleteMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionDeleteMessage(); } }); saveMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionSaveMessage(); } }); unsaveMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUnsaveMessage(); } }); // subscribeUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionSubscribeUser(); // } // }); subscribeMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionSubscribeMessage(); } }); // unsubscribeUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUnsubscribeUser(); // } // }); unsubscribeMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUnsubscribeMessage(); } }); translateMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionTranslateMessage(); } }); shareMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionShareMessage(); } }); // blacklistUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionBlacklistUser(); // } // }); // filterUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionFilterUser(UName); // } // }); // userBlog.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUserBlog(); // } // }); // userStats.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUserStats(); // } // }); openMessageInBrowser.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionOpenMessageInBrowser(); } }); userCenter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUserCenter(); } }); completeInitDialogMode(alertDialog, dialogView); alertDialog.show(); } }
From source file:org.telegram.ui.ThemeActivity.java
private void openThemeCreate() { final EditTextBoldCursor editText = new EditTextBoldCursor(getParentActivity()); editText.setBackgroundDrawable(Theme.createEditTextDrawable(getParentActivity(), true)); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("NewTheme", R.string.NewTheme)); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialog, which) -> { });/*from ww w .ja v a2s . c om*/ LinearLayout linearLayout = new LinearLayout(getParentActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); builder.setView(linearLayout); final TextView message = new TextView(getParentActivity()); message.setText(LocaleController.formatString("EnterThemeName", R.string.EnterThemeName)); message.setTextSize(16); message.setPadding(AndroidUtilities.dp(23), AndroidUtilities.dp(12), AndroidUtilities.dp(23), AndroidUtilities.dp(6)); message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); linearLayout.addView(message, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); editText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); editText.setMaxLines(1); editText.setLines(1); editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); editText.setGravity(Gravity.LEFT | Gravity.TOP); editText.setSingleLine(true); editText.setImeOptions(EditorInfo.IME_ACTION_DONE); editText.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); editText.setCursorSize(AndroidUtilities.dp(20)); editText.setCursorWidth(1.5f); editText.setPadding(0, AndroidUtilities.dp(4), 0, 0); linearLayout.addView(editText, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, Gravity.TOP | Gravity.LEFT, 24, 6, 24, 0)); editText.setOnEditorActionListener((textView, i, keyEvent) -> { AndroidUtilities.hideKeyboard(textView); return false; }); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(dialog -> AndroidUtilities.runOnUIThread(() -> { editText.requestFocus(); AndroidUtilities.showKeyboard(editText); })); showDialog(alertDialog); alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> { if (editText.length() == 0) { Vibrator vibrator = (Vibrator) ApplicationLoader.applicationContext .getSystemService(Context.VIBRATOR_SERVICE); if (vibrator != null) { vibrator.vibrate(200); } AndroidUtilities.shakeView(editText, 2, 0); return; } ThemeEditorView themeEditorView = new ThemeEditorView(); String name = editText.getText().toString() + ".attheme"; themeEditorView.show(getParentActivity(), name); Theme.saveCurrentTheme(name, true); updateRows(); alertDialog.dismiss(); SharedPreferences preferences = MessagesController.getGlobalMainSettings(); if (preferences.getBoolean("themehint", false)) { return; } preferences.edit().putBoolean("themehint", true).commit(); try { Toast.makeText(getParentActivity(), LocaleController.getString("CreateNewThemeHelp", R.string.CreateNewThemeHelp), Toast.LENGTH_LONG).show(); } catch (Exception e) { FileLog.e(e); } }); }
From source file:com.juick.android.ThreadActivity.java
private void previewAndSendReply(final String msg) { final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); if (sp.getBoolean("previewReplies", false)) { final TextView tv = new TextView(this); JuickMessage jm = new JuickMessage(); jm.User = new JuickUser(); jm.User.UName = "You"; jm.Text = msg;//www. j a v a 2 s. c om jm.tags = new Vector<String>(); if (rid != 0) { // insert destination user name JuickMessage reply = tf.findReply(tf.getListView(), rid); if (reply != null) { jm.Text = "@" + reply.User.UName + " " + jm.Text; } } JuickMessagesAdapter.ParsedMessage parsedMessage = JuickMessagesAdapter.formatMessageText(this, jm, true); tv.setText(parsedMessage.textContent); tv.setPadding(10, 10, 10, 10); MainActivity.restyleChildrenOrWidget(tv); final AlertDialog dialog = new AlertDialog.Builder( new ContextThemeWrapper(this, R.style.Theme_Sherlock_Light)).setTitle("Post reply - preview") .setView(tv).setCancelable(true) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).setPositiveButton("Post reply", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); sendReplyMain(msg); } }).create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface i) { tv.setBackgroundColor(JuickMessagesAdapter.getColorTheme(dialog.getContext()).getBackground()); MainActivity.restyleChildrenOrWidget(tv); } }); dialog.show(); } else { sendReplyMain(msg); } }
From source file:org.mozilla.gecko.GeckoPreferences.java
protected Dialog onCreateDialog(int id) { AlertDialog.Builder builder = new AlertDialog.Builder(this); LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); AlertDialog dialog = null; switch (id) { case DIALOG_CREATE_MASTER_PASSWORD: final EditText input1 = getTextBox(R.string.masterpassword_password); final EditText input2 = getTextBox(R.string.masterpassword_confirm); linearLayout.addView(input1);//from www . jav a 2 s . co m linearLayout.addView(input2); builder.setTitle(R.string.masterpassword_create_title).setView((View) linearLayout) .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { JSONObject jsonPref = new JSONObject(); try { jsonPref.put("name", "privacy.masterpassword.enabled"); jsonPref.put("type", "string"); jsonPref.put("value", input1.getText().toString()); GeckoEvent event = GeckoEvent.createBroadcastEvent("Preferences:Set", jsonPref.toString()); GeckoAppShell.sendEventToGecko(event); } catch (Exception ex) { Log.e(LOGTAG, "Error setting masterpassword", ex); } return; } }).setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); dialog = builder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { public void onShow(DialogInterface dialog) { input1.setText(""); input2.setText(""); input1.requestFocus(); } }); PasswordTextWatcher watcher = new PasswordTextWatcher(input1, input2, dialog); input1.addTextChangedListener((TextWatcher) watcher); input2.addTextChangedListener((TextWatcher) watcher); break; case DIALOG_REMOVE_MASTER_PASSWORD: final EditText input = getTextBox(R.string.masterpassword_password); linearLayout.addView(input); builder.setTitle(R.string.masterpassword_remove_title).setView((View) linearLayout) .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { try { JSONObject jsonPref = new JSONObject(); jsonPref.put("name", "privacy.masterpassword.enabled"); jsonPref.put("type", "string"); jsonPref.put("value", input.getText().toString()); GeckoEvent event = GeckoEvent.createBroadcastEvent("Preferences:Set", jsonPref.toString()); GeckoAppShell.sendEventToGecko(event); } catch (Exception ex) { Log.e(LOGTAG, "Error setting masterpassword", ex); } return; } }).setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); dialog = builder.create(); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { input.setText(""); } }); break; default: return null; } return dialog; }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void showRatingAndDonationInfo() { AlertDialog.Builder alert = new AlertDialog.Builder(TvBrowser.this); alert.setTitle(R.string.you_like_it); View view = getLayoutInflater().inflate(R.layout.rating_and_donation, getParentViewGroup(), false); TextView ratingInfo = (TextView) view.findViewById(R.id.rating_info); Button rate = (Button) view.findViewById(R.id.rating_button); Button donate = (Button) view.findViewById(R.id.donation_button); if (!SettingConstants.GOOGLE_PLAY) { ratingInfo.setVisibility(View.GONE); rate.setVisibility(View.GONE); }// w w w. j a v a 2 s.co m ratingInfo.setText(Html.fromHtml(getString(R.string.rating_text))); ((TextView) view.findViewById(R.id.donation_info)).setText(Html.fromHtml(getString(R.string.donate_text))); final Button cancel = (Button) view.findViewById(R.id.rating_donation_cancel); cancel.setEnabled(false); alert.setView(view); alert.setCancelable(false); final AlertDialog d = alert.create(); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d.dismiss(); setRatingAndDonationInfoShown(); finish(); } }); donate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d.dismiss(); setRatingAndDonationInfoShown(); showDonationInfo(); } }); rate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d.dismiss(); final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object try { startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); } catch (android.content.ActivityNotFoundException anfe) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName))); } setRatingAndDonationInfoShown(); finish(); } }); d.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { new Thread("Cancel wait thread") { @Override public void run() { int count = 10; while (--count >= 0) { final int countValue = count + 1; handler.post(new Runnable() { @Override public void run() { cancel.setText( getString(R.string.not_now).replace("{0}", " (" + countValue + ")")); } }); try { sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } handler.post(new Runnable() { @Override public void run() { cancel.setText(getString(R.string.not_now).replace("{0}", "")); cancel.setEnabled(true); } }); } }.start(); } }); d.show(); }