List of usage examples for android.app AlertDialog.Builder setView
public void setView(View view)
From source file:com.codename1.impl.android.AndroidImplementation.java
@Override public Object showNativePicker(final int type, final Component source, final Object currentValue, final Object data) { if (getActivity() == null) { return null; }/*ww w . j av a2s . co m*/ final boolean[] canceled = new boolean[1]; final boolean[] dismissed = new boolean[1]; if (editInProgress()) { stopEditing(true); } if (type == Display.PICKER_TYPE_TIME) { class TimePick implements TimePickerDialog.OnTimeSetListener, TimePickerDialog.OnCancelListener, Runnable { int result = ((Integer) currentValue).intValue(); public void onTimeSet(TimePicker tp, int hour, int minute) { result = hour * 60 + minute; dismissed[0] = true; synchronized (this) { notify(); } } public void run() { while (!dismissed[0]) { synchronized (this) { try { wait(50); } catch (InterruptedException er) { } } } } @Override public void onCancel(DialogInterface di) { dismissed[0] = true; canceled[0] = true; synchronized (this) { notify(); } } } final TimePick pickInstance = new TimePick(); getActivity().runOnUiThread(new Runnable() { public void run() { int hour = ((Integer) currentValue).intValue() / 60; int minute = ((Integer) currentValue).intValue() % 60; TimePickerDialog tp = new TimePickerDialog(getActivity(), pickInstance, hour, minute, true) { @Override public void cancel() { super.cancel(); dismissed[0] = true; canceled[0] = true; } @Override public void dismiss() { super.dismiss(); dismissed[0] = true; } }; tp.setOnCancelListener(pickInstance); //DateFormat.is24HourFormat(activity)); tp.show(); } }); Display.getInstance().invokeAndBlock(pickInstance); if (canceled[0]) { return null; } return new Integer(pickInstance.result); } if (type == Display.PICKER_TYPE_DATE) { final java.util.Calendar cl = java.util.Calendar.getInstance(); if (currentValue != null) { cl.setTime((Date) currentValue); } class DatePick implements DatePickerDialog.OnDateSetListener, DatePickerDialog.OnCancelListener, Runnable { Date result = (Date) currentValue; public void onDateSet(DatePicker dp, int year, int month, int day) { java.util.Calendar c = java.util.Calendar.getInstance(); c.set(java.util.Calendar.YEAR, year); c.set(java.util.Calendar.MONTH, month); c.set(java.util.Calendar.DAY_OF_MONTH, day); result = c.getTime(); dismissed[0] = true; synchronized (this) { notify(); } } public void run() { while (!dismissed[0]) { synchronized (this) { try { wait(50); } catch (InterruptedException er) { } } } } public void onCancel(DialogInterface di) { result = null; dismissed[0] = true; canceled[0] = true; synchronized (this) { notify(); } } } final DatePick pickInstance = new DatePick(); getActivity().runOnUiThread(new Runnable() { public void run() { DatePickerDialog tp = new DatePickerDialog(getActivity(), pickInstance, cl.get(java.util.Calendar.YEAR), cl.get(java.util.Calendar.MONTH), cl.get(java.util.Calendar.DAY_OF_MONTH)) { @Override public void cancel() { super.cancel(); dismissed[0] = true; canceled[0] = true; } @Override public void dismiss() { super.dismiss(); dismissed[0] = true; } }; tp.setOnCancelListener(pickInstance); tp.show(); } }); Display.getInstance().invokeAndBlock(pickInstance); return pickInstance.result; } if (type == Display.PICKER_TYPE_STRINGS) { final String[] values = (String[]) data; class StringPick implements Runnable, NumberPicker.OnValueChangeListener { int result = -1; StringPick() { } public void run() { while (!dismissed[0]) { synchronized (this) { try { wait(50); } catch (InterruptedException er) { } } } } public void cancel() { dismissed[0] = true; canceled[0] = true; synchronized (this) { notify(); } } public void ok() { canceled[0] = false; dismissed[0] = true; synchronized (this) { notify(); } } @Override public void onValueChange(NumberPicker np, int oldVal, int newVal) { result = newVal; } } final StringPick pickInstance = new StringPick(); for (int iter = 0; iter < values.length; iter++) { if (values[iter].equals(currentValue)) { pickInstance.result = iter; break; } } if (pickInstance.result == -1 && values.length > 0) { // The picker will default to showing the first element anyways // If we don't set the result to 0, then the user has to first // scroll to a different number, then back to the first option // to pick the first option. pickInstance.result = 0; } getActivity().runOnUiThread(new Runnable() { public void run() { NumberPicker picker = new NumberPicker(getActivity()); if (source.getClientProperty("showKeyboard") == null) { picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); } picker.setMinValue(0); picker.setMaxValue(values.length - 1); picker.setDisplayedValues(values); picker.setOnValueChangedListener(pickInstance); if (pickInstance.result > -1) { picker.setValue(pickInstance.result); } RelativeLayout linearLayout = new RelativeLayout(getActivity()); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(50, 50); RelativeLayout.LayoutParams numPicerParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); numPicerParams.addRule(RelativeLayout.CENTER_HORIZONTAL); linearLayout.setLayoutParams(params); linearLayout.addView(picker, numPicerParams); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); alertDialogBuilder.setView(linearLayout); alertDialogBuilder.setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { pickInstance.ok(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); pickInstance.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } }); Display.getInstance().invokeAndBlock(pickInstance); if (canceled[0]) { return null; } if (pickInstance.result < 0) { return null; } return values[pickInstance.result]; } return null; }
From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java
@Override protected Dialog onCreateDialog(int id) { final Dialog dialog; ProgressDialog pdialog;// ww w . ja va2s. co m AlertDialog.Builder builder; LayoutInflater inflater; switch (id) { case Constants.DIALOG_LOGIN: dialog = new LoginDialog(this, mSettings, false) { @Override public void onLoginChosen(String user, String password) { removeDialog(Constants.DIALOG_LOGIN); new MyLoginTask(user, password).execute(); } }; break; case Constants.DIALOG_COMMENT_CLICK: dialog = new CommentClickDialog(this, mSettings); break; case Constants.DIALOG_REPLY: { dialog = new Dialog(this, mSettings.getDialogTheme()); dialog.setContentView(R.layout.compose_reply_dialog); final EditText replyBody = (EditText) dialog.findViewById(R.id.body); final Button replySaveButton = (Button) dialog.findViewById(R.id.reply_save_button); final Button replyCancelButton = (Button) dialog.findViewById(R.id.reply_cancel_button); replySaveButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mReplyTargetName != null) { new CommentReplyTask(mReplyTargetName).execute(replyBody.getText().toString()); dialog.dismiss(); } else { Common.showErrorToast("Error replying. Please try again.", Toast.LENGTH_SHORT, CommentsListActivity.this); } } }); replyCancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mVoteTargetThing.setReplyDraft(replyBody.getText().toString()); dialog.cancel(); } }); dialog.setCancelable(false); // disallow the BACK key dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { replyBody.setText(""); } }); break; } case Constants.DIALOG_EDIT: { dialog = new Dialog(this, mSettings.getDialogTheme()); dialog.setContentView(R.layout.compose_reply_dialog); final EditText replyBody = (EditText) dialog.findViewById(R.id.body); final Button replySaveButton = (Button) dialog.findViewById(R.id.reply_save_button); final Button replyCancelButton = (Button) dialog.findViewById(R.id.reply_cancel_button); replyBody.setText(mEditTargetBody); replySaveButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (mReplyTargetName != null) { new EditTask(mReplyTargetName).execute(replyBody.getText().toString()); dialog.dismiss(); } else { Common.showErrorToast("Error editing. Please try again.", Toast.LENGTH_SHORT, CommentsListActivity.this); } } }); replyCancelButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { dialog.cancel(); } }); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { replyBody.setText(""); } }); break; } case Constants.DIALOG_DELETE: builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())); builder.setTitle("Really delete this?"); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { removeDialog(Constants.DIALOG_DELETE); new DeleteTask(mDeleteTargetKind).execute(mReplyTargetName); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); dialog = builder.create(); break; case Constants.DIALOG_SORT_BY: builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())); builder.setTitle("Sort by:"); int selectedSortBy = -1; for (int i = 0; i < Constants.CommentsSort.SORT_BY_URL_CHOICES.length; i++) { if (Constants.CommentsSort.SORT_BY_URL_CHOICES[i].equals(mSettings.getCommentsSortByUrl())) { selectedSortBy = i; break; } } builder.setSingleChoiceItems(Constants.CommentsSort.SORT_BY_CHOICES, selectedSortBy, sortByOnClickListener); dialog = builder.create(); break; case Constants.DIALOG_REPORT: builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())); builder.setTitle("Really report this?"); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { removeDialog(Constants.DIALOG_REPORT); new ReportTask(mReportTargetName.toString()).execute(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); dialog = builder.create(); break; // "Please wait" case Constants.DIALOG_DELETING: pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme())); pdialog.setMessage("Deleting..."); pdialog.setIndeterminate(true); pdialog.setCancelable(true); dialog = pdialog; break; case Constants.DIALOG_EDITING: pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme())); pdialog.setMessage("Submitting edit..."); pdialog.setIndeterminate(true); pdialog.setCancelable(true); dialog = pdialog; break; case Constants.DIALOG_LOGGING_IN: pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme())); pdialog.setMessage("Logging in..."); pdialog.setIndeterminate(true); pdialog.setCancelable(true); dialog = pdialog; break; case Constants.DIALOG_REPLYING: pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme())); pdialog.setMessage("Sending reply..."); pdialog.setIndeterminate(true); pdialog.setCancelable(true); dialog = pdialog; break; case Constants.DIALOG_FIND: inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View content = inflater.inflate(R.layout.dialog_find, null); final EditText find_box = (EditText) content.findViewById(R.id.input_find_box); // final CheckBox wrap_box = (CheckBox) content.findViewById(R.id.find_wrap_checkbox); builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())); builder.setView(content); builder.setTitle(R.string.find).setPositiveButton(R.string.find, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String search_text = find_box.getText().toString().toLowerCase(); // findCommentText(search_text, wrap_box.isChecked(), false); findCommentText(search_text, true, false); } }).setNegativeButton("Cancel", null); dialog = builder.create(); break; default: throw new IllegalArgumentException("Unexpected dialog id " + id); } return dialog; }
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;/*from w w w. j a v a2 s . com*/ 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(); }
From source file:com.atahani.telepathy.ui.fragment.AboutDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); View customLayout = inflater.inflate(R.layout.fragment_about_dialog, null); //config app version information mAppPreferenceTools = new AppPreferenceTools(TApplication.applicationContext); AppCompatTextView txAndroidAppVerInfo = (AppCompatTextView) customLayout .findViewById(R.id.tx_android_ver_info); txAndroidAppVerInfo.setText(String.format(getString(R.string.label_telepathy_for_android), mAppPreferenceTools.getTheLastAppVersion())); txAndroidAppVerInfo.setOnClickListener(new View.OnClickListener() { @Override/*from w w w . ja va 2s .c o m*/ public void onClick(View v) { try { //open browser to navigate telepathy website Uri telepathyWebSiteUri = Uri.parse("https://github.com/atahani/telepathy-android.git"); startActivity(new Intent(Intent.ACTION_VIEW, telepathyWebSiteUri)); ((TelepathyBaseActivity) getActivity()).setAnimationOnStart(); } catch (Exception ex) { AndroidUtilities.processApplicationError(ex, true); if (isAdded() && getActivity() != null) { Snackbar.make(getActivity().findViewById(android.R.id.content), getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show(); } } } }); //config google play store link AppCompatTextView txRateUsOnGooglePlayStore = (AppCompatTextView) customLayout .findViewById(R.id.tx_rate_us_on_play_store); txRateUsOnGooglePlayStore.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //navigate to market for rate application Uri uri = Uri.parse("market://details?id=" + TApplication.applicationContext.getPackageName()); Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); // To count with Play market backstack, After pressing back button, // to taken back to our application, we need to add following flags to intent. goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); try { startActivity(goToMarket); ((TelepathyBaseActivity) getActivity()).setAnimationOnStart(); } catch (ActivityNotFoundException e) { startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + TApplication.applicationContext.getPackageName()))); } } }); //config twitter link AppCompatTextView txTwitterLink = (AppCompatTextView) customLayout.findViewById(R.id.tx_twitter_telepathy); txTwitterLink.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { // If Twitter app is not installed, start browser. Uri twitterUri = Uri.parse("http://twitter.com/"); startActivity(new Intent(Intent.ACTION_VIEW, twitterUri)); ((TelepathyBaseActivity) getActivity()).setAnimationOnStart(); } catch (Exception ex) { AndroidUtilities.processApplicationError(ex, true); if (isAdded() && getActivity() != null) { Snackbar.make(getActivity().findViewById(android.R.id.content), getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show(); } } } }); //config privacy link AppCompatTextView txPrivacyLink = (AppCompatTextView) customLayout.findViewById(R.id.tx_privacy); txPrivacyLink.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { //open browser to navigate privacy link Uri privacyPolicyUri = Uri .parse("https://github.com/atahani/telepathy-android/blob/master/LICENSE.md"); startActivity(new Intent(Intent.ACTION_VIEW, privacyPolicyUri)); ((TelepathyBaseActivity) getActivity()).setAnimationOnStart(); } catch (Exception ex) { AndroidUtilities.processApplicationError(ex, true); if (isAdded() && getActivity() != null) { Snackbar.make(getActivity().findViewById(android.R.id.content), getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show(); } } } }); //config report bug to open mail application and send bugs report AppCompatTextView txReportBug = (AppCompatTextView) customLayout.findViewById(R.id.tx_report_bug); txReportBug.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { final Intent emailIntent = new Intent(Intent.ACTION_SENDTO); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.label_report_bug_email_subject)); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailDeviceInformation()); emailIntent.setData(Uri.parse("mailto:" + getString(R.string.telepathy_report_bug_email))); startActivity(Intent.createChooser(emailIntent, getString(R.string.label_report_bug_choose_mail_app))); ((TelepathyBaseActivity) getActivity()).setAnimationOnStart(); } catch (Exception ex) { AndroidUtilities.processApplicationError(ex, true); if (isAdded() && getActivity() != null) { Snackbar.make(getActivity().findViewById(android.R.id.content), getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show(); } } } }); //config the about footer image view AboutFooterImageView footerImageView = (AboutFooterImageView) customLayout .findViewById(R.id.im_delete_user_account); footerImageView.setTouchOnImageViewEventListener(new AboutFooterImageView.touchOnImageViewEventListener() { @Override public void onDoubleTab() { try { //confirm account delete via alert dialog final AlertDialog.Builder confirmAccountDeleteDialog = new AlertDialog.Builder(getActivity()); confirmAccountDeleteDialog.setTitle(getString(R.string.label_delete_user_account)); confirmAccountDeleteDialog .setMessage(getString(R.string.label_delete_user_account_description)); confirmAccountDeleteDialog.setNegativeButton(getString(R.string.action_no), null); confirmAccountDeleteDialog.setPositiveButton(getString(R.string.action_yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //ok to delete account action final ProgressDialog progressDialog = new ProgressDialog(getActivity()); progressDialog.setCancelable(false); progressDialog.setCanceledOnTouchOutside(false); progressDialog .setMessage(getString(R.string.re_action_on_deleting_user_account)); progressDialog.show(); TService tService = ((TelepathyBaseActivity) getActivity()).getTService(); tService.deleteUserAccount(new Callback<TOperationResultModel>() { @Override public void success(TOperationResultModel tOperationResultModel, Response response) { if (getActivity() != null && isAdded()) { //broad cast to close all of the realm instance Intent intentToCloseRealm = new Intent( Constants.TELEPATHY_BASE_ACTIVITY_INTENT_FILTER); intentToCloseRealm.putExtra(Constants.ACTION_TO_DO_PARAM, Constants.CLOSE_REALM_DB); LocalBroadcastManager.getInstance(getActivity()) .sendBroadcastSync(intentToCloseRealm); mAppPreferenceTools.removeAllOfThePref(); // for sign out google first build GoogleAPIClient final GoogleApiClient googleApiClient = new GoogleApiClient.Builder( TApplication.applicationContext) .addApi(Auth.GOOGLE_SIGN_IN_API).build(); googleApiClient.connect(); googleApiClient.registerConnectionCallbacks( new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(Bundle bundle) { Auth.GoogleSignInApi.signOut(googleApiClient) .setResultCallback( new ResultCallback<Status>() { @Override public void onResult( Status status) { //also revoke google access Auth.GoogleSignInApi .revokeAccess( googleApiClient) .setResultCallback( new ResultCallback<Status>() { @Override public void onResult( Status status) { progressDialog .dismiss(); TelepathyBaseActivity currentActivity = (TelepathyBaseActivity) TApplication.mCurrentActivityInApplication; if (currentActivity != null) { Intent intent = new Intent( TApplication.applicationContext, SignInActivity.class); intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); currentActivity .startActivity( intent); currentActivity .setAnimationOnStart(); currentActivity .finish(); } } }); } }); } @Override public void onConnectionSuspended(int i) { //do nothing } }); } } @Override public void failure(RetrofitError error) { progressDialog.dismiss(); if (getActivity() != null && isAdded()) { CommonFeedBack commonFeedBack = new CommonFeedBack( getActivity().findViewById(android.R.id.content), getActivity()); commonFeedBack.checkCommonErrorAndBackUnCommonOne(error); } } }); } }); confirmAccountDeleteDialog.show(); } catch (Exception ex) { AndroidUtilities.processApplicationError(ex, true); if (isAdded() && getActivity() != null) { Snackbar.make(getActivity().findViewById(android.R.id.content), getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show(); } } } }); builder.setView(customLayout); return builder.create(); }
From source file:com.rfo.basic.Run.java
private void doInputDialog(DialogArgs args) { Context context = getContext(); Log.d(LOGTAG, "InputDialog context " + context); EditText text = new EditText(context); text.setText(args.mInputDefault);/*ww w . j a v a 2s . co m*/ Var.Val returnVal = args.mReturnVal; if (returnVal.isNumeric()) { text.setInputType(0x00003002); // Limits keys to signed decimal numbers } String btnLabel = args.mButton1; if (btnLabel == null) { btnLabel = "Ok"; } AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setView(text).setCancelable(true).setTitle(args.mTitle) // default null, no title displayed if null or empty .setPositiveButton(btnLabel, null); // need to override default View click handler to prevent // auto-dismiss, but can't do it until after show() builder.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { Log.d(LOGTAG, "Input Dialog onCancel"); mInputCancelled = true; // signal read by executeINPUT } }); final AlertDialog dialog = builder.create(); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { Log.d(LOGTAG, "Input Dialog onDismiss"); releaseLOCK(); // release the lock that executeINPUT is waiting for } }); dialog.getWindow().setSoftInputMode(android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); dialog.show(); dialog.getButton(DialogInterface.BUTTON_POSITIVE) // now we can replace the View click listener .setOnClickListener(new InputDialogClickListener(dialog, text, args)); // to prevent auto-dismiss }