List of usage examples for android.app AlertDialog show
public void show()
From source file:com.romanenco.gitt.BrowserActivity.java
/** * When pull from origin there are several case. * 1. We are in TAG (detached head): will inform user to * checkout a branch first.//w ww.j a v a 2s. c om * 2. Authentication required: ask for password (no passwd save). * 3. Anonymous user: just poll. */ private void pullFromOrigin() { if (current.getUserName() == null) { //no authentication required current.setState(Repo.State.Busy); DAO dao = new DAO(BrowserActivity.this); dao.open(true); dao.update(current); dao.close(); Intent pull = new Intent(this, GitService.class); pull.putExtra(GitService.COMMAND, GitService.Command.Pull); pull.putExtra(GitService.REPO, current); startService(pull); Intent main = new Intent(this, MainActivity.class); main.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(main); } else { String req = getString(R.string.passwd_request, current.getUserName()); final EditText passwd = new EditText(this); passwd.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); AlertDialog dlg = new AlertDialog.Builder(this).setMessage(req) .setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String password = passwd.getText().toString(); if (TextUtils.isEmpty(password)) { pullFromOrigin(); } else { current.setState(Repo.State.Busy); DAO dao = new DAO(BrowserActivity.this); dao.open(true); dao.update(current); dao.close(); Intent pull = new Intent(BrowserActivity.this, GitService.class); pull.putExtra(GitService.COMMAND, GitService.Command.Pull); pull.putExtra(GitService.REPO, current); pull.putExtra(GitService.AUTH_PASSWD, password); startService(pull); Intent main = new Intent(BrowserActivity.this, MainActivity.class); main.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(main); } } }).setNegativeButton(getString(android.R.string.cancel), null).create(); dlg.setCanceledOnTouchOutside(false); dlg.setView(passwd); dlg.show(); } }
From source file:ac.robinson.mediaphone.MediaPhoneActivity.java
protected void deleteNarrativeDialog(final String frameInternalId) { AlertDialog.Builder builder = new AlertDialog.Builder(MediaPhoneActivity.this); builder.setTitle(R.string.delete_narrative_confirmation); builder.setMessage(R.string.delete_narrative_hint); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setNegativeButton(android.R.string.cancel, null); builder.setPositiveButton(R.string.button_delete, new DialogInterface.OnClickListener() { @Override/*from w w w. ja v a 2 s.c o m*/ public void onClick(DialogInterface dialog, int whichButton) { ContentResolver contentResolver = getContentResolver(); FrameItem currentFrame = FramesManager.findFrameByInternalId(contentResolver, frameInternalId); final String narrativeId = currentFrame.getParentId(); int numFramesDeleted = FramesManager.countFramesByParentId(contentResolver, narrativeId); AlertDialog.Builder builder = new AlertDialog.Builder(MediaPhoneActivity.this); builder.setTitle(R.string.delete_narrative_second_confirmation); builder.setMessage(getResources().getQuantityString(R.plurals.delete_narrative_second_hint, numFramesDeleted, numFramesDeleted)); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setNegativeButton(android.R.string.cancel, null); builder.setPositiveButton(R.string.button_delete, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { ContentResolver contentResolver = getContentResolver(); NarrativeItem narrativeToDelete = NarrativesManager .findNarrativeByInternalId(contentResolver, narrativeId); narrativeToDelete.setDeleted(true); NarrativesManager.updateNarrative(contentResolver, narrativeToDelete); UIUtilities.showToast(MediaPhoneActivity.this, R.string.delete_narrative_succeeded); onBackPressed(); } }); AlertDialog alert = builder.create(); alert.show(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:ac.robinson.mediaphone.MediaPhoneActivity.java
public void processIncomingFiles(Message msg) { // deal with messages from the BluetoothObserver Bundle fileData = msg.peekData();//from w w w . j a v a 2 s.c o m if (fileData == null) { return; // error - no parameters passed } String importedFileName = fileData.getString(MediaUtilities.KEY_FILE_NAME); if (importedFileName == null) { if (msg.what == MediaUtilities.MSG_IMPORT_SERVICE_REGISTERED) { onBluetoothServiceRegistered(); } return; // error - no filename } // get the imported file object final File importedFile = new File(importedFileName); if (!importedFile.canRead() || !importedFile.canWrite()) { if (MediaPhone.IMPORT_DELETE_AFTER_IMPORTING) { importedFile.delete(); // error - probably won't work, but might // as well try; doesn't throw, so is okay } return; } final int messageType = msg.what; switch (messageType) { case MediaUtilities.MSG_RECEIVED_IMPORT_FILE: UIUtilities.showToast(MediaPhoneActivity.this, R.string.import_starting); break; case MediaUtilities.MSG_RECEIVED_SMIL_FILE: case MediaUtilities.MSG_RECEIVED_HTML_FILE: case MediaUtilities.MSG_RECEIVED_MOV_FILE: if (MediaPhone.IMPORT_CONFIRM_IMPORTING) { if (MediaPhoneActivity.this.isFinishing()) { if (!(MediaPhoneActivity.this instanceof NarrativeBrowserActivity)) { // TODO: send a delayed message to the next task? (can't from NarrativeBrowser - app exit) } } else { AlertDialog.Builder builder = new AlertDialog.Builder(MediaPhoneActivity.this); builder.setTitle(R.string.import_file_confirmation); // fake that we're using the SMIL file if we're actually using .sync.jpg builder.setMessage(getString(R.string.import_file_hint, importedFile.getName().replace(MediaUtilities.SYNC_FILE_EXTENSION, "") .replace(MediaUtilities.SMIL_FILE_EXTENSION, ""))); builder.setIcon(android.R.drawable.ic_dialog_info); builder.setNegativeButton(R.string.import_not_now, null); builder.setPositiveButton(R.string.import_file, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { importFiles(messageType, importedFile); } }); AlertDialog alert = builder.create(); alert.show(); } } else { importFiles(messageType, importedFile); } break; } }
From source file:org.csp.everyaware.offline.Map.java
public final void createLegalNoticesDialog(Activity activity) { AlertDialog ad = new AlertDialog.Builder(activity).create(); ad.setCancelable(false); // This blocks the 'BACK' button ad.setMessage(GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(activity.getApplicationContext())); ad.setButton("OK", new DialogInterface.OnClickListener() { @Override//from w w w . j a va 2 s . c o m public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); ad.show(); }
From source file:fm.smart.r1.activity.CreateSoundActivity.java
public void onWindowFocusChanged(boolean bool) { super.onWindowFocusChanged(bool); Log.d("DEBUG", "onWindowFocusChanged"); if (CreateSoundActivity.create_sound_result != null) { synchronized (CreateSoundActivity.create_sound_result) { final AlertDialog dialog = new AlertDialog.Builder(this).create(); final boolean success = CreateSoundActivity.create_sound_result.success(); dialog.setTitle(CreateSoundActivity.create_sound_result.getTitle()); dialog.setMessage(CreateSoundActivity.create_sound_result.getMessage()); CreateSoundActivity.create_sound_result = null; dialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO avoid moving to item list if previous thread was // interrupted? create_sound.isInterrupted() but need // user to be aware if we // have created sound already - progress dialog is set // cancelable, so back button will work? maybe should // avoid encouraging cancel // on POST operations ... not sure what to do if no // response from server - guess we will time out // eventually ... // if (success) { // want to go back to individual item screen now ... ItemListActivity.loadItem(CreateSoundActivity.this, item_id); // } // TODO might want to go to different screens depending // on type of error, e.g. permission issue versus // network // error }//from w w w.j av a 2 s .co m }); dialog.show(); } } }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Creates an alert with an OK button.//w ww . j a v a2 s.c o m * * @param context * @param msgResourceId */ public static void dialog_showAlertOkDialog(Context context, int titleResourceId, int msgResourceId) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage(context.getResources().getString(msgResourceId)).setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); if (titleResourceId != 0) { builder.setTitle(context.getResources().getString(titleResourceId)); } AlertDialog alert = builder.create(); alert.show(); }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Creates an alert with an OK button.//from w w w . j a v a2s.c o m * * @param context * @param message */ public static void dialog_showAlertOkDialog(Context context, String tittle, String message) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage(message).setCancelable(false).setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); if (tittle != null && tittle.length() > 0) { builder.setTitle(tittle); } AlertDialog alert = builder.create(); alert.show(); }
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; }/*from www . j a v a 2s .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:hr.foicore.varazdinlandmarksdemo.POIMapActivity.java
public void handleQRcodeScanRequest() { Intent intent = new Intent("com.google.zxing.client.android.SCAN"); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); intent.putExtra("SAVE_HISTORY", false); try {//from w ww . j a v a2s . co m startActivityForResult(intent, 0); // request code is 0 } catch (ActivityNotFoundException e) { // No application to view, ask to download one AlertDialog alertDialog = new AlertDialog.Builder(POIMapActivity.this).create();// context).create(); alertDialog.setTitle(getResources().getString(R.string.qr_scanner_not_found)); alertDialog.setMessage(getResources().getString(R.string.install_it_now_question)); alertDialog.setButton(Dialog.BUTTON_NEGATIVE, getResources().getString(R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); alertDialog.setButton(Dialog.BUTTON_POSITIVE, getResources().getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { try { // TODO test this startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=qr+scanner&c=apps"))); } catch (android.content.ActivityNotFoundException anfe) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/search?q=qr+scanner&c=apps"))); } } }); alertDialog.show(); } }
From source file:cgeo.geocaching.CacheListActivity.java
private void showLicenseConfirmationDialog() { final AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle(res.getString(R.string.license)); dialog.setMessage(res.getString(R.string.err_license)); dialog.setCancelable(true);/*from w ww . j a v a2 s . com*/ dialog.setNegativeButton(res.getString(R.string.license_dismiss), new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int id) { Cookies.clearCookies(); dialog.cancel(); } }); dialog.setPositiveButton(res.getString(R.string.license_show), new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int id) { Cookies.clearCookies(); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.geocaching.com/software/agreement.aspx?ID=0"))); } }); final AlertDialog alert = dialog.create(); alert.show(); }