Example usage for android.app AlertDialog.Builder create

List of usage examples for android.app AlertDialog.Builder create

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder create.

Prototype

public void create() 

Source Link

Document

Forces immediate creation of the dialog.

Usage

From source file:com.zertinteractive.wallpaper.MainActivity.java

public void reminderDialog() {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    View dialogView = this.getLayoutInflater().inflate(R.layout.alert_label_editor, null);
    dialogBuilder.setView(dialogView);//  w  ww  . j  a  v a  2  s  .c om
    final AlertDialog alertDialog = dialogBuilder.create();

    ImageView rate_app_dialog_button = (ImageView) dialogView.findViewById(R.id.rate_app_dialog_button);
    ImageView no_thanks_dialog_button = (ImageView) dialogView.findViewById(R.id.no_thanks_dialog_button);
    ImageView edidremind_dialog_button = (ImageView) dialogView.findViewById(R.id.remind_dialog_button);

    rate_app_dialog_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openUri(PLAY_STORE_URL);
        }
    });
    no_thanks_dialog_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            alertDialog.dismiss();
        }
    });
    edidremind_dialog_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            alertDialog.dismiss();
        }
    });
    alertDialog.show();
}

From source file:eu.operando.operandoapp.OperandoProxyStatus.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.settings_menu:
        Intent settingsIntent = new Intent(mainContext.getContext(), SettingActivity.class);
        startActivity(settingsIntent);/*from   ww  w. jav  a  2  s  . c o  m*/
        return true;
    case R.id.apn_menu: {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.action_apn);
        builder.setPositiveButton(android.R.string.cancel, null);
        builder.setNegativeButton("Open APN Settings", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                Intent apnIntent = new Intent(android.provider.Settings.ACTION_APN_SETTINGS);
                apnIntent.putExtra("sub_id", 1); //SubscriptionManager.NAME_SOURCE_SIM_SOURCE
                startActivity(apnIntent);
            }
        });
        String message = "In order to enable OperandoApp proxy while using wireless networks (e.g. 3G), you will need to modify the corresponding Access Point configuration for your provider. Please set the following values:\n\nProxy: 127.0.0.1\nPort: 8899";
        builder.setMessage(message);
        builder.create().show();

        return true;
    }
    case R.id.help_menu:
        Toast.makeText(this, "You have selected HELP (To be added).", Toast.LENGTH_SHORT).show();
        return true;
    case R.id.about_menu:
        Intent aboutIntent = new Intent(mainContext.getContext(), AboutActivity.class);
        startActivity(aboutIntent);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:fi.mikuz.boarder.gui.internet.Uploads.java

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    final InternetFullBoard board = ((BoardListAdapter) mListView.getAdapter()).getItem(position);

    if (!board.getUploaderUsername().equals("")) {
        final CharSequence[] items = { "Edit", "Delete" };

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(board.getBoardName());
        builder.setItems(items, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                if (item == 0) {
                    boardUploader(board, InternetMenu.PHP_OPERATION_EDIT);
                } else if (item == 1) {
                    AlertDialog.Builder deleteBuilder = new AlertDialog.Builder(Uploads.this);
                    deleteBuilder.setTitle("Deleting upload");
                    deleteBuilder.setMessage("Are you sure you want to permanently delete upload '"
                            + board.getBoardName() + "'?");

                    deleteBuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            HashMap<String, String> sendList = new HashMap<String, String>();
                            sendList.put(InternetMenu.UPLOADER_ID_KEY, mUserId);
                            sendList.put(InternetMenu.SESSION_TOKEN_KEY, mSessionToken);
                            sendList.put(InternetMenu.BOARD_ID_KEY, Integer.toString(board.getBoardId()));
                            new ConnectionManager(Uploads.this, InternetMenu.mDeleteUploadedBoardURL, sendList);
                        }//from   w  w  w .  j a  va2  s  .  co m
                    });
                    deleteBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.dismiss();
                        }
                    });
                    AlertDialog deleteAlert = deleteBuilder.create();
                    deleteAlert.show();
                }
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }
}

From source file:com.raceyourself.android.samsung.ProviderService.java

private void popupSuccessDialog() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("RaceYourself Gear Edition").setMessage(
            "Connected to Gear.\n\nRaceYourself is ready to go!\n\nIt's important to keep Gear connected to your phone when you workout, so RaceYourself can use the GPS in your phone.")
            .setCancelable(false).setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(@SuppressWarnings("unused") final DialogInterface dialog,
                        @SuppressWarnings("unused") final int id) {
                    Preference.setBoolean(SUCCESS_KEY, Boolean.TRUE);
                }//from  ww w  .j a v  a  2s.  c  o m
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                    // nothing - just dismiss dialog
                }
            });
    alert = builder.create();
    alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    alert.show();
}

From source file:dev.ukanth.ufirewall.Api.java

public static void alertDialog(final Context ctx, String msgText) {
    if (ctx != null) {
        AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
        builder.setMessage(msgText).setCancelable(false).setPositiveButton(ctx.getString(R.string.OK),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }/*ww  w.  j av a 2 s. c om*/
                });
        AlertDialog alert = builder.create();
        alert.show();
    }
}

From source file:cm.aptoide.pt.ApkInfo.java

public void loadMalware(final MalwareStatus malwareStatus) {
    runOnUiThread(new Runnable() {

        @Override/*w ww . j a  v  a  2 s. co m*/
        public void run() {
            try {
                EnumApkMalware apkStatus = EnumApkMalware
                        .valueOf(malwareStatus.getStatus().toUpperCase(Locale.ENGLISH));
                Log.d("ApkInfoMalware-malwareStatus", malwareStatus.getStatus());
                Log.d("ApkInfoMalware-malwareReason", malwareStatus.getReason());

                switch (apkStatus) {
                case SCANNED:
                    ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.trusted));
                    ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_scanned);
                    ((LinearLayout) findViewById(R.id.badge_layout)).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            View trustedView = LayoutInflater.from(ApkInfo.this)
                                    .inflate(R.layout.dialog_anti_malware, null);
                            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ApkInfo.this)
                                    .setView(trustedView);
                            final AlertDialog trustedDialog = dialogBuilder.create();
                            trustedDialog.setIcon(R.drawable.badge_scanned);
                            trustedDialog.setTitle(getString(R.string.app_trusted, viewApk.getName()));
                            trustedDialog.setCancelable(true);

                            TextView tvSignatureValidation = (TextView) trustedView
                                    .findViewById(R.id.tv_signature_validation);
                            tvSignatureValidation.setText(getString(R.string.signature_verified));
                            ImageView check_signature = (ImageView) trustedView
                                    .findViewById(R.id.check_signature);
                            check_signature.setImageResource(R.drawable.ic_yes);

                            trustedDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    trustedDialog.dismiss();
                                }
                            });
                            trustedDialog.show();
                        }
                    });
                    break;
                //             case UNKNOWN:
                //                ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.unknown));
                //                ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_unknown);
                //                break;
                case WARN:
                    ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.warning));
                    ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_warn);
                    ((LinearLayout) findViewById(R.id.badge_layout)).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            View warnView = LayoutInflater.from(ApkInfo.this)
                                    .inflate(R.layout.dialog_anti_malware, null);
                            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ApkInfo.this)
                                    .setView(warnView);
                            final AlertDialog warnDialog = dialogBuilder.create();
                            warnDialog.setIcon(R.drawable.badge_warn);
                            warnDialog.setTitle(getString(R.string.app_warning, viewApk.getName()));
                            warnDialog.setCancelable(true);

                            TextView tvSignatureValidation = (TextView) warnView
                                    .findViewById(R.id.tv_signature_validation);
                            tvSignatureValidation.setText(getString(R.string.signature_not_verified));
                            ImageView check_signature = (ImageView) warnView.findViewById(R.id.check_signature);
                            check_signature.setImageResource(R.drawable.ic_failed);

                            warnDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    warnDialog.dismiss();
                                }
                            });
                            warnDialog.show();
                        }
                    });
                    break;
                //             case CRITICAL:
                //                ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.critical));
                //                ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_critical);
                //                break;
                default:
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    });

}

From source file:com.raceyourself.android.samsung.ProviderService.java

private void popupGpsDialog() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("RaceYourself works best with GPS.\n\nWould you like to enable your GPS now?")
            .setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(@SuppressWarnings("unused") final DialogInterface dialog,
                        @SuppressWarnings("unused") final int id) {
                    Intent gps = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    gps.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(gps);//from w ww  .j  a  va 2 s.c  o  m
                }
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                    dialog.cancel();
                }
            }).setTitle("RaceYourself Gear Edition");
    alert = builder.create();
    alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    alert.show();
}

From source file:com.safecell.HomeScreenActivity.java

public void showGPSStatusAlert(String provider) {

    // Log.v("Safecell", "" + provider);

    String title = "";
    String message = "";

    if (LocationManager.GPS_PROVIDER.equals(provider)) {
        return;/*from  www .  ja  v a  2  s  . com*/
    }

    if (provider == null) {
        title = "GPS is not enabled.";
        message = "GPS is not enabled. Please enable it.";
    } else {
        title = "GPS is not enabled.";
        message = "GPS is not enabled. Please enable it. \nMeanwhile, background trip tracking will be disabled.";
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setTitle(title);
    builder.setMessage(message);
    builder.setCancelable(false);

    builder.setPositiveButton("Launch Settings", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            launchGPSOptions();
        }
    });

    if (LocationManager.NETWORK_PROVIDER.equals(provider)) {
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
    }

    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.phonegap.Notification.java

/**
 * Builds and shows a native Android confirm dialog with given title, message, buttons.
 * This dialog only shows up to 3 buttons.  Any labels after that will be ignored.
 * The index of the button pressed will be returned to the JavaScript callback identified by callbackId.
 * //  www .  ja va 2 s .  c  om
 * @param message       The message the dialog should display
 * @param title       The title of the dialog
 * @param buttonLabels    A comma separated list of button labels (Up to 3 buttons)
 * @param callbackId   The callback id
 */
public synchronized void confirm(final String message, final String title, String buttonLabels,
        final String callbackId) {

    final PhonegapActivity ctx = this.ctx;
    final Notification notification = this;
    final String[] fButtons = buttonLabels.split(",");

    Runnable runnable = new Runnable() {
        public void run() {
            AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(false);

            // First button
            if (fButtons.length > 0) {
                dlg.setPositiveButton(fButtons[0], new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        notification.success(new PluginResult(PluginResult.Status.OK, 1), callbackId);
                    }
                });
            }

            // Second button
            if (fButtons.length > 1) {
                dlg.setNeutralButton(fButtons[1], new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        notification.success(new PluginResult(PluginResult.Status.OK, 2), callbackId);
                    }
                });
            }

            // Third button
            if (fButtons.length > 2) {
                dlg.setNegativeButton(fButtons[2], new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        notification.success(new PluginResult(PluginResult.Status.OK, 3), callbackId);
                    }
                });
            }

            dlg.create();
            dlg.show();
        };
    };
    this.ctx.runOnUiThread(runnable);
}

From source file:com.jonbanjo.cupsprint.CertificateActivity.java

public void doimport(View view) {
    try {/*from w w w  .  j av a2 s  . com*/
        String url = "https://" + host.getText().toString() + ":" + port.getText().toString();
        importButton.setEnabled(false);
        new importer().execute(url).get(3000, TimeUnit.MILLISECONDS);
    } catch (Exception e) {

    } finally {
        importButton.setEnabled(true);
    }
    if (certChain == null) {
        return;
    }

    for (X509Certificate cert : certChain) {
        try {
            cert.checkValidity();
        } catch (Exception e) {
            showToast(e.toString());
            return;
        }

    }
    String certString = certChain[0].toString();
    final String alias = certChain[0].getSubjectX500Principal().getName();
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Add Certificate?").setMessage(certString)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    try {
                        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
                        keyPairGenerator.initialize(1024);
                        KeyPair keyPair = keyPairGenerator.generateKeyPair();
                        PrivateKey privateKey = keyPair.getPrivate();
                        trustStore.setKeyEntry(alias, privateKey, JfSSLScheme.password.toCharArray(),
                                certChain);
                        FileOutputStream outputStream = openFileOutput(JfSSLScheme.trustfile, MODE_PRIVATE);
                        trustStore.store(outputStream, JfSSLScheme.password.toCharArray());
                        outputStream.flush();
                        outputStream.close();
                        certListAdaptor.add(alias);
                    } catch (Exception e) {
                        System.out.println(e.toString());
                        return;
                    }
                }
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog dialog = builder.create();
    dialog.show();

}