List of usage examples for android.app AlertDialog show
public void show()
From source file:com.safecell.ManageProfile_Activity.java
void displayDialog(String title, String inputText, final int position) { LayoutInflater li = LayoutInflater.from(this); View dialogView = li.inflate(R.layout.dialog_edittext_input, null); dialogInputEditText = (EditText) dialogView.findViewById(R.id.DialogEditTextInputEditText); dialogInputEditText.setText(inputText); dialogInputEditText.setInputType(setInputTypeKeyBoard(position)); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(title).setInverseBackgroundForced(true).setView(dialogView).setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String text = dialogInputEditText.getText().toString(); if (!text.equalsIgnoreCase("")) { if (position == 2) { if (validationForEmailAddress(text)) { setDialogValuesListArrayAdapter(position); dialog.cancel(); } else { dialog.cancel(); }/* ww w . j a v a 2 s .c o m*/ } else { setDialogValuesListArrayAdapter(position); dialog.cancel(); } } else { Toast.makeText(context, "Blank not allowed.", Toast.LENGTH_SHORT).show(); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); }
From source file:com.example.fieldbokorig.FieldbookActivity.java
@Override protected Dialog onCreateDialog(int id) { // TODO: Create the dialogs here.. // Dialog dialog = null; switch (id) { case DIALOG_REMOVE_ID: // Create out AlterDialog Builder builder = new AlertDialog.Builder(this); builder.setMessage("Remove the selected fieldbooks?"); builder.setCancelable(true);/*from w ww .j a v a2 s . c o m*/ builder.setPositiveButton("Yes", new OkOnClickListener()); builder.setNegativeButton("No", new CancelOnClickListener()); AlertDialog alertDialog = builder.create(); alertDialog.show(); } return super.onCreateDialog(id); }
From source file:com.nbos.phonebook.sync.authenticator.AuthenticatorActivity.java
void createAccountWithFbId() { mPrefs = getPreferences(MODE_PRIVATE); SharedPreferences.Editor editor = mPrefs.edit(); editor.putString("access_token", facebook.getAccessToken()); editor.putLong("access_expires", facebook.getAccessExpires()); editor.commit();//from w ww .j a va 2 s . co m String access_token = mPrefs.getString("access_token", null); long expires = mPrefs.getLong("access_expires", 0); if (access_token != null) { facebook.setAccessToken(access_token); } if (expires != 0) { facebook.setAccessExpires(expires); } /* * Only call authorize if the access_token has expired. */ if (facebook.isSessionValid()) { Log.i(tag, "Session is valid"); JSONObject json; try { json = Util.parseJson(facebook.request("me", new Bundle())); Log.i(tag, "json: " + json); fbId = json.getString("id"); String username = json.getString("id"); JSONArray existingUser = new Cloud(getApplicationContext(), fbId, null).findExistingFbUser(fbId, countryCode + mPhone); Log.i(tag, "existingUser: " + existingUser.getString(0)); LayoutInflater factory = LayoutInflater.from(this); textEntryView = factory.inflate(R.layout.facebook_email_layout, null); TextView fbUsername = (TextView) textEntryView.findViewById(R.id.facebookLogin_email); TextView fbPassword = (TextView) textEntryView.findViewById(R.id.facebookLogin_password); Button fbAccountButton = (Button) textEntryView.findViewById(R.id.facebookLogin); if (existingUser.getString(0).trim().length() == 0) { Log.i(tag, "email: " + Text.isEmail(username)); if (!(Text.isEmail(username))) { AlertDialog.Builder newBuilder = new AlertDialog.Builder(this); newBuilder.setTitle("FbLogin to Phonebook"); newBuilder.setView(textEntryView); Button existingFbAccount = (Button) textEntryView .findViewById(R.id.existingAccountfacebookLogin); existingFbAccount.setVisibility(View.GONE); AlertDialog newAlert = newBuilder.create(); newAlert.show(); } } else { fbAccountButton.setVisibility(View.GONE); fbUsername.setText(existingUser.getString(0)); fbUsername.setEnabled(false); fbPassword.requestFocus(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("FbLogin to Phonebook"); builder.setView(textEntryView); AlertDialog alert = builder.create(); alert.show(); } //mPhone = mPhoneEdit.getText().toString(); //new Cloud(getApplicationContext(), userId, userId).loginWithFacebook(countryCode + mPhone); /*mUsername = userName; mPassword = userId;*/ //finishLogin(); // mUsernameEdit.setText(userName); // mPasswordEdit.setText(userId); Log.i(tag, "userName: " + username + " userId: " + fbId); Log.i(tag, "response:" + json); } catch (Exception e1) { Log.e(tag, "Exception logging on with Facebook: " + e1); e1.printStackTrace(); } catch (FacebookError e) { Log.e(tag, "Facebook error logging on with Facebook: " + e); e.printStackTrace(); } } }
From source file:com.wellsandwhistles.android.redditsp.reddit.prepared.RedditPreparedPost.java
public static void onActionMenuItemSelected(final RedditPreparedPost post, final AppCompatActivity activity, final Action action) { switch (action) { case UPVOTE://from w ww .j av a 2s . c o m post.action(activity, RedditAPI.ACTION_UPVOTE); break; case DOWNVOTE: post.action(activity, RedditAPI.ACTION_DOWNVOTE); break; case UNVOTE: post.action(activity, RedditAPI.ACTION_UNVOTE); break; case SAVE: post.action(activity, RedditAPI.ACTION_SAVE); break; case UNSAVE: post.action(activity, RedditAPI.ACTION_UNSAVE); break; case HIDE: post.action(activity, RedditAPI.ACTION_HIDE); break; case UNHIDE: post.action(activity, RedditAPI.ACTION_UNHIDE); break; case EDIT: final Intent editIntent = new Intent(activity, CommentEditActivity.class); editIntent.putExtra("commentIdAndType", post.src.getIdAndType()); editIntent.putExtra("commentText", StringEscapeUtils.unescapeHtml4(post.src.getRawSelfText())); editIntent.putExtra("isSelfPost", true); activity.startActivity(editIntent); break; case DELETE: new AlertDialog.Builder(activity).setTitle(R.string.accounts_delete).setMessage(R.string.delete_confirm) .setPositiveButton(R.string.action_delete, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.ACTION_DELETE); } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case REPORT: new AlertDialog.Builder(activity).setTitle(R.string.action_report) .setMessage(R.string.action_report_sure) .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.ACTION_REPORT); // TODO update the view to show the result // TODO don't forget, this also hides } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case EXTERNAL: { final Intent intent = new Intent(Intent.ACTION_VIEW); String url = (activity instanceof WebViewActivity) ? ((WebViewActivity) activity).getCurrentUrl() : post.src.getUrl(); intent.setData(Uri.parse(url)); activity.startActivity(intent); break; } case SELFTEXT_LINKS: { final HashSet<String> linksInComment = LinkHandler .computeAllLinks(StringEscapeUtils.unescapeHtml4(post.src.getRawSelfText())); if (linksInComment.isEmpty()) { General.quickToast(activity, R.string.error_toast_no_urls_in_self); } else { final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]); final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setItems(linksArr, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { LinkHandler.onLinkClicked(activity, linksArr[which], false, post.src.getSrc()); dialog.dismiss(); } }); final AlertDialog alert = builder.create(); alert.setTitle(R.string.action_selftext_links); alert.setCanceledOnTouchOutside(true); alert.show(); } break; } case SAVE_IMAGE: { ((BaseActivity) activity).requestPermissionWithCallback(Manifest.permission.WRITE_EXTERNAL_STORAGE, new SaveImageCallback(activity, post.src.getUrl())); break; } case SHARE: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, post.src.getTitle()); mailer.putExtra(Intent.EXTRA_TEXT, post.src.getUrl()); activity.startActivity(Intent.createChooser(mailer, activity.getString(R.string.action_share))); break; } case SHARE_COMMENTS: { final boolean shareAsPermalink = PrefsUtility.pref_behaviour_share_permalink(activity, PreferenceManager.getDefaultSharedPreferences(activity)); final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, "Comments for " + post.src.getTitle()); if (shareAsPermalink) { mailer.putExtra(Intent.EXTRA_TEXT, Constants.Reddit.getNonAPIUri(post.src.getPermalink()).toString()); } else { mailer.putExtra(Intent.EXTRA_TEXT, Constants.Reddit .getNonAPIUri(Constants.Reddit.PATH_COMMENTS + post.src.getIdAlone()).toString()); } activity.startActivity( Intent.createChooser(mailer, activity.getString(R.string.action_share_comments))); break; } case SHARE_IMAGE: { ((BaseActivity) activity).requestPermissionWithCallback(Manifest.permission.WRITE_EXTERNAL_STORAGE, new ShareImageCallback(activity, post.src.getUrl())); break; } case COPY: { ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); manager.setText(post.src.getUrl()); break; } case GOTO_SUBREDDIT: { try { final Intent intent = new Intent(activity, PostListingActivity.class); intent.setData(SubredditPostListURL.getSubreddit(post.src.getSubreddit()).generateJsonUri()); activity.startActivityForResult(intent, 1); } catch (RedditSubreddit.InvalidSubredditNameException e) { Toast.makeText(activity, R.string.invalid_subreddit_name, Toast.LENGTH_LONG).show(); } break; } case USER_PROFILE: LinkHandler.onLinkClicked(activity, new UserProfileURL(post.src.getAuthor()).toString()); break; case PROPERTIES: PostPropertiesDialog.newInstance(post.src.getSrc()).show(activity.getSupportFragmentManager(), null); break; case COMMENTS: ((PostSelectionListener) activity).onPostCommentsSelected(post); new Thread() { @Override public void run() { post.markAsRead(activity); } }.start(); break; case LINK: ((PostSelectionListener) activity).onPostSelected(post); break; case COMMENTS_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((PostSelectionListener) activity).onPostCommentsSelected(post); break; case LINK_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((PostSelectionListener) activity).onPostSelected(post); break; case ACTION_MENU: showActionMenu(activity, post); break; case REPLY: final Intent intent = new Intent(activity, CommentReplyActivity.class); intent.putExtra(CommentReplyActivity.PARENT_ID_AND_TYPE_KEY, post.src.getIdAndType()); intent.putExtra(CommentReplyActivity.PARENT_MARKDOWN_KEY, post.src.getUnescapedSelfText()); activity.startActivity(intent); break; case BACK: activity.onBackPressed(); break; case PIN: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); List<String> pinnedSubreddits = PrefsUtility.pref_pinned_subreddits(activity, PreferenceManager.getDefaultSharedPreferences(activity)); if (!pinnedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_pinned_subreddits_add(activity, PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName); } else { Toast.makeText(activity, R.string.mainmenu_toast_pinned, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; case UNPIN: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); List<String> pinnedSubreddits = PrefsUtility.pref_pinned_subreddits(activity, PreferenceManager.getDefaultSharedPreferences(activity)); if (pinnedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_pinned_subreddits_remove(activity, PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName); } else { Toast.makeText(activity, R.string.mainmenu_toast_not_pinned, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; case BLOCK: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); List<String> blockedSubreddits = PrefsUtility.pref_blocked_subreddits(activity, PreferenceManager.getDefaultSharedPreferences(activity)); if (!blockedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_blocked_subreddits_add(activity, PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName); } else { Toast.makeText(activity, R.string.mainmenu_toast_blocked, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; case UNBLOCK: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); List<String> blockedSubreddits = PrefsUtility.pref_blocked_subreddits(activity, PreferenceManager.getDefaultSharedPreferences(activity)); if (blockedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_blocked_subreddits_remove(activity, PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName); } else { Toast.makeText(activity, R.string.mainmenu_toast_not_blocked, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; case SUBSCRIBE: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); RedditSubredditSubscriptionManager subMan = RedditSubredditSubscriptionManager .getSingleton(activity, RedditAccountManager.getInstance(activity).getDefaultAccount()); if (subMan.getSubscriptionState( subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.NOT_SUBSCRIBED) { subMan.subscribe(subredditCanonicalName, activity); Toast.makeText(activity, R.string.options_subscribing, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(activity, R.string.mainmenu_toast_subscribed, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; case UNSUBSCRIBE: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); RedditSubredditSubscriptionManager subMan = RedditSubredditSubscriptionManager .getSingleton(activity, RedditAccountManager.getInstance(activity).getDefaultAccount()); if (subMan.getSubscriptionState( subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.SUBSCRIBED) { subMan.unsubscribe(subredditCanonicalName, activity); Toast.makeText(activity, R.string.options_unsubscribing, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(activity, R.string.mainmenu_toast_not_subscribed, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; } }
From source file:li.barter.fragments.ChatsFragment.java
@Override public void onDialogClick(final DialogInterface dialog, final int which) { if ((mChatDialogFragment != null) && mChatDialogFragment.getDialog().equals(dialog)) { if (which == 0) { final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // set title alertDialogBuilder.setTitle("Confirm"); // set dialog message alertDialogBuilder.setMessage(getResources().getString(R.string.delete_chat_alert_message)) .setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int id) { deleteChat(mDeleteChatId); dialog.dismiss(); }// w ww. java2s . c om }).setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog final AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } else if (which == 1) { final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // set title alertDialogBuilder.setTitle("Confirm"); // set dialog message alertDialogBuilder.setMessage(getResources().getString(R.string.block_user_alert_message)) .setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int id) { blockUser(mBlockUserId); dialog.dismiss(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog final AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } } else { super.onDialogClick(dialog, which); } }
From source file:com.google.android.apps.paco.ExploreDataActivity.java
private View renderMultiSelectListButton(final Long id, final TextView textview) { DialogInterface.OnMultiChoiceClickListener multiselectListDialogListener = new DialogInterface.OnMultiChoiceClickListener() { @Override//from www. j ava 2s .c o m public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { if (checkedChoices.get(id) != null) { checkedChoices.get(id).add(inputIds.get(which)); } else { List<Long> tempList = new ArrayList<Long>(); tempList.add(inputIds.get(which)); checkedChoices.put(id, tempList); } } else { checkedChoices.get(id).remove(inputIds.get(which)); if (checkedChoices.get(id).isEmpty()) checkedChoices.remove(id); } } }; AlertDialog.Builder builder = new AlertDialog.Builder(mainLayout.getContext()); builder.setTitle(R.string.make_selections); boolean[] checkedChoicesBoolArray = new boolean[inputIds.size()]; int count = inputIds.size(); if (checkedChoices.get(id) != null) { for (int i = 0; i < count; i++) { checkedChoicesBoolArray[i] = checkedChoices.get(id).contains(inputIds.get(i)); } } String[] listChoices = new String[inputIds.size()]; inpNames.toArray(listChoices); builder.setMultiChoiceItems(listChoices, checkedChoicesBoolArray, multiselectListDialogListener); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { getLabelWithSelectedVariables(id, textview); } }); AlertDialog multiSelectListDialog = builder.create(); multiSelectListDialog.show(); return multiSelectListDialog.getListView(); }
From source file:com.example.fieldbokorig.RetrieveFieldbookFromSharesActivity.java
@Override protected Dialog onCreateDialog(int id) { // TODO: Create the dialogs here.. Dialog dialog = null;//w w w . j a v a 2 s . c o m switch (id) { case DIALOG_RETRIEVE_ID: // Create out AlterDialog Builder builder = new AlertDialog.Builder(this); builder.setMessage("Retrieve the selected files?"); builder.setCancelable(true); builder.setPositiveButton("Yes", new retrieveOnClickListener()); builder.setNegativeButton("No", new cancelOnClickListener()); AlertDialog alertDialog = builder.create(); alertDialog.show(); break; case DIALOG_DELETE_ID: // Delete selected fieldbook Builder builder2 = new AlertDialog.Builder(this); builder2.setMessage("Permanently delete the selected files?"); builder2.setCancelable(true); builder2.setPositiveButton("Yes", new deleteOnClickListener()); builder2.setNegativeButton("No", new cancelOnClickListener()); //use the same for both dialogs alertDialog = builder2.create(); alertDialog.show(); break; } return super.onCreateDialog(id); }
From source file:azad.hallaji.farzad.com.masirezendegi.PageVirayesh.java
private void jostaruzunueymahziba(String message) { LayoutInflater inflater = this.getLayoutInflater(); View dialogView = inflater.inflate(R.layout.alert_dialog_login, null); final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); dialogBuilder.setView(dialogView);/* ww w . j a v a2 s . c o m*/ TextView textView = (TextView) dialogView.findViewById(R.id.aaT); TextView textVie = (TextView) dialogView.findViewById(R.id.aT); textView.setText(message); textVie.setVisibility(View.INVISIBLE); Button button = (Button) dialogView.findViewById(R.id.buttombastan); final AlertDialog alertDialog = dialogBuilder.create(); alertDialog.show(); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.cancel(); /*Intent intent = new Intent(PageVirayesh.this,PageVirayesh.class); startActivity(intent);*/ } }); }
From source file:com.jesjimher.bicipalma.MesProperesActivity.java
public boolean onItemLongClick(final AdapterView<?> parent, final View v, final int position, final long id) { final CharSequence[] items = getResources().getTextArray(R.array.menu_contextual); AlertDialog.Builder b = new AlertDialog.Builder(this); final ResultadoBusqueda rb = (ResultadoBusqueda) parent.getAdapter().getItem(position); b.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { dialog.dismiss();//from w w w . ja v a 2 s . co m switch (item) { case 0: onItemClick(parent, v, position, id); break; case 1: //TODO: Pasar a GMaps la versin localizada de "Current location" para que haga l la bsqueda de origen String latlongactual = lBest.getLatitude() + "," + lBest.getLongitude(); String latlongdestino = rb.getEstacion().getLoc().getLatitude() + "," + rb.getEstacion().getLoc().getLongitude(); Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse( "http://maps.google.com/maps?saddr=" + latlongactual + "&daddr=" + latlongdestino)); startActivity(intent); break; } } }); AlertDialog alert = b.create(); alert.show(); return true; }
From source file:dk.kasperbaago.JSONHandler.JSONHandler.java
/** * Shows an error to the user, if the request fails. * Callback is NOT called if this is shown. To still run callback and use your own error handler, use showErrMsg(false); *///from w ww.j a v a 2 s.c o m private void showErrorMsg() { AlertDialog alert = new AlertDialog.Builder(this.context).create(); alert.setTitle(this.errorMsgTitle); alert.setMessage(this.errorMsgTxt); alert.setButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.show(); }