List of usage examples for android.app AlertDialog.Builder show
public void show()
From source file:br.com.anteros.vendas.gui.AnexoCadastroActivity.java
/** * Anexar arquivos/*from w ww .jav a 2s . c om*/ */ private void anexarArquivos() { String items[] = { "Imagem", "Outros tipos" }; AlertDialog.Builder ab = new AlertDialog.Builder(this); ab.setTitle("Seleo de arquivos"); ab.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface d, int choice) { if (choice == 0) { selecionarImagem(); } else if (choice == 1) { selecionarOutrosTiposArquivo(); } } }); ab.show(); }
From source file:com.flat20.fingerplay.FingerPlayActivity.java
private void unableToVerifyLicense(String message, boolean showSubscripeButton) { AlertDialog.Builder builder = new AlertDialog.Builder(this) .setMessage(getString(R.string.dialog_subs_check_failed, message)) .setNegativeButton(getString(R.string.exit), new DialogInterface.OnClickListener() { @Override/*from w w w . ja v a 2s.c om*/ public void onClick(DialogInterface dialog, int which) { finish(); } }).setCancelable(false); if (showSubscripeButton) { builder.setPositiveButton(getString(R.string.subscribe), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { subscribe(); } }); } builder.show(); }
From source file:com.vuze.android.remote.AndroidUtils.java
@SuppressWarnings("ConstantConditions") public static void openSingleAlertDialog(Activity ownerActivity, AlertDialog.Builder builder, final OnDismissListener dismissListener) { // We should always be on the UI Thread, so no need to synchronize if (hasAlertDialogOpen) { if (currentSingleDialog == null || currentSingleDialog.getOwnerActivity() == null || !currentSingleDialog.getOwnerActivity().isFinishing()) { if (DEBUG) { Log.e(TAG, "Already have Alert Dialog Open " + currentSingleDialog); }//from w w w .ja v a2 s. co m return; } } if (DEBUG && hasAlertDialogOpen) { Log.e(TAG, "hasAlertDialogOpen flag ON, but dialog isn't showing"); } hasAlertDialogOpen = true; try { currentSingleDialog = builder.show(); currentSingleDialog.setOwnerActivity(ownerActivity); if (DEBUG) { Log.d(TAG, "Alert Dialog Open " + getCompressedStackTrace()); } // Note: There's a builder.setOnDismissListener(), but it's API 17 currentSingleDialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { hasAlertDialogOpen = false; if (dismissListener != null) { dismissListener.onDismiss(dialog); } } }); } catch (BadTokenException bte) { // android.view.WindowManager$BadTokenException: Unable to add window -- // token android.os.BinderProxy@42043ff8 is not valid; is your activity // running? // ignore. We checked activity.isFinishing() earlier.. not much we // can do Log.e(TAG, "AlertDialog", bte); } }
From source file:net.reichholf.dreamdroid.activities.MovieListActivity.java
protected void onListItemClick(ListView l, View v, int position, long id) { mMovie = mMapList.get(position);//from ww w .java 2s.c om CharSequence[] actions = { getText(R.string.zap), getText(R.string.delete), getText(R.string.stream) }; AlertDialog.Builder adBuilder = new AlertDialog.Builder(this); adBuilder.setTitle(getText(R.string.pick_action)); adBuilder.setItems(actions, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: zapTo(mMovie.getString(Movie.REFERENCE)); break; case 1: showDialog(DIALOG_DELETE_MOVIE_CONFIRM_ID); break; case 2: streamFile(mMovie.getString(Movie.FILE_NAME)); default: return; } } }); adBuilder.show(); }
From source file:at.ac.tuwien.detlef.activities.MainActivity.java
private void onRefreshDone(String msg, RefreshDoneNotification notificationType) { numPodSync.set(-1);/*from w w w . j a v a2 s. co m*/ progressDialog.dismiss(); hideRefreshProgressBar(); Log.d(TAG, "notificationType: " + notificationType); switch (notificationType) { case TOAST: default: Toast.makeText(this, msg, REFRESH_MSG_DURATION_MS).show(); break; case DIALOG: final AlertDialog.Builder b = new AlertDialog.Builder(this); b.setTitle("Refresh done."); b.setMessage(msg); b.setPositiveButton(android.R.string.ok, null); b.show(); break; } }
From source file:com.masteriti.manager.AccountsActivity.java
/** * Sets up the 'connect' screen content. *///w ww. jav a2 s . c o m private void setConnectScreenContent() { List<String> accounts = getGoogleAccounts(); if (accounts.size() == 0) { // Show a dialog and invoke the "Add Account" activity if requested AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setMessage(R.string.needs_account); builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT)); } }); builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); builder.setIcon(android.R.drawable.stat_sys_warning); builder.setTitle(R.string.attention); builder.show(); } else { final ListView listView = (ListView) findViewById(R.id.select_account); listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts)); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); listView.setItemChecked(mAccountSelectedPosition, true); final Button connectButton = (Button) findViewById(R.id.connect); connectButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Set "connecting" status SharedPreferences prefs = Util.getSharedPreferences(mContext); prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit(); // Get account name mAccountSelectedPosition = listView.getCheckedItemPosition(); TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition); // Register register((String) account.getText()); finish(); } }); } }
From source file:com.nest5.businessClient.AccountsActivity.java
/** * Sets up the 'connect' screen content. *///from w ww. ja va 2s.co m private void setConnectScreenContent() { List<String> accounts = getGoogleAccounts(); if (accounts.size() == 0) { // Show a dialog and invoke the "Add Account" activity if requested AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setMessage(R.string.needs_account); builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT)); } }); builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); } }); builder.setIcon(android.R.drawable.stat_sys_warning); builder.setTitle(R.string.attention); builder.show(); } else { final ListView listView = (ListView) findViewById(R.id.select_account); listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts)); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); listView.setItemChecked(mAccountSelectedPosition, true); final Button connectButton = (Button) findViewById(R.id.connect); connectButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // Set "connecting" status SharedPreferences prefs = Util.getSharedPreferences(mContext); prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit(); // Get account name mAccountSelectedPosition = listView.getCheckedItemPosition(); TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition); // Register register((String) account.getText()); finish(); } }); } // internetConnectionStatus = (ImageView) findViewById(R.id.header_connection_status); SharedPreferences prefs = Util.getSharedPreferences(mContext); if (!isNetworkAvailable()) { internetConnectionStatus.setImageResource(R.drawable.error); prefs.edit().putInt(Util.INTERNET_CONNECTION, Util.INTERNET_DISCONNECTED).commit(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage( "No tienes una conexin a internet activa. Habiltala haciendo click en aceptar y seleccionando luego una red.") .setCancelable(false).setPositiveButton("Aceptar", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS); startActivityForResult(intent, 1); } }).setNegativeButton("Cancelar", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { finish(); } }).show(); } else { prefs.edit().putInt(Util.INTERNET_CONNECTION, Util.INTERNET_CONNECTED).commit(); } }
From source file:ca.spencerelliott.mercury.Changesets.java
private synchronized void startThread() { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); //Create the thread that will process the incoming feed load_thread = new Thread() { @Override/*from w w w.jav a2 s . c o m*/ public void run() { changesets_list.clear(); DatabaseHelper db_helper = DatabaseHelper.getInstance(getApplicationContext()); EncryptionHelper encrypt_helper = EncryptionHelper.getInstance("DEADBEEF".toCharArray(), new byte[] { 'L', 'O', 'L' }); //Get the repository information from the local database Beans.RepositoryBean repo_type = db_helper.getRepository(repo_id, encrypt_helper); AtomHandler feed_handler = null; //Detect the type of repository and create a parser based on that switch (repo_type.getType()) { case Mercury.RepositoryTypes.HGSERVE: feed_handler = new HGWebAtomHandler(); break; case Mercury.RepositoryTypes.GOOGLECODE: feed_handler = new GoogleCodeAtomHandler(); break; case Mercury.RepositoryTypes.BITBUCKET: feed_handler = new BitbucketAtomHandler(); break; case Mercury.RepositoryTypes.CODEPLEX: feed_handler = new CodePlexAtomHandler(); break; } HttpURLConnection conn = null; boolean connected = false; try { // XXX We need to use our own factory to make all ssl certs work HttpsURLConnection.setDefaultSSLSocketFactory(NaiveSSLSocketFactory.getSocketFactory()); String repo_url_string = (repo_type.getUrl().endsWith("/") || repo_type.getUrl().endsWith("\\") ? feed_handler .formatURL(repo_type.getUrl().substring(0, repo_type.getUrl().length() - 1)) : feed_handler.formatURL(repo_type.getUrl())); switch (repo_type.getType()) { case Mercury.RepositoryTypes.BITBUCKET: //Only add the token if the user requested it if (repo_type.getAuthentication() == Mercury.AuthenticationTypes.TOKEN) repo_url_string = repo_url_string + "?token=" + repo_type.getSSHKey(); break; } URL repo_url = new URL(repo_url_string); conn = (HttpURLConnection) repo_url.openConnection(); //Check to see if the user enabled HTTP authentication if (repo_type.getAuthentication() == Mercury.AuthenticationTypes.HTTP) { //Get their username and password byte[] decrypted_info = (repo_type.getUsername() + ":" + repo_type.getPassword()) .getBytes(); //Add the header to the http request conn.setRequestProperty("Authorization", "Basic " + Base64.encodeBytes(decrypted_info)); } conn.connect(); connected = true; } catch (ClientProtocolException e2) { AlertDialog.Builder alert = new AlertDialog.Builder(getBaseContext()); alert.setMessage("There was a problem with the HTTP protocol"); alert.setPositiveButton(android.R.string.ok, null); alert.show(); //Do not allow the app to continue with loading connected = false; } catch (IOException e2) { AlertDialog.Builder alert = new AlertDialog.Builder(getBaseContext()); alert.setMessage("Server did not respond with a valid HTTP response"); alert.setPositiveButton(android.R.string.ok, null); alert.show(); //Do not allow the app to continue with loading connected = false; } catch (NullPointerException e3) { } catch (Exception e) { } BufferedReader reader = null; //Create a new reader based on the information retrieved if (connected) { try { reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); } catch (IllegalStateException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } else { list_handler.sendEmptyMessage(CANCELLED); return; } //Make sure both the feed handler and info loaded from the web are not null if (reader != null && feed_handler != null) { try { Xml.parse(reader, feed_handler); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } } else { list_handler.sendEmptyMessage(CANCELLED); return; } //Stored beans in the devices database ArrayList<Beans.ChangesetBean> stored_beans = null; if (prefs.getBoolean("caching", false)) { long last_insert = db_helper.getHighestID(DatabaseHelper.DB_TABLE_CHANGESETS, repo_id); if (last_insert >= 0) { //Get all of the stored changesets stored_beans = db_helper.getAllChangesets(repo_id, null); String rev_id = ""; //Try to find the revision id of the bean that has the id of the last inserted value for (Beans.ChangesetBean b : stored_beans) { if (b.getID() == last_insert) { rev_id = b.getRevisionID(); break; } } //Trim the list starting from this revision feed_handler.trimStartingFromRevision(rev_id); } } //Create a new bundle for the progress Bundle progress_bundle = new Bundle(); //Retreive all the beans from the handler ArrayList<Beans.ChangesetBean> beans = feed_handler.getAllChangesets(); int bean_count = beans.size(); //Store the amount of changesets progress_bundle.putInt("max", bean_count); //Create a new message and store the bundle and what type of message it is Message msg = new Message(); msg.setData(progress_bundle); msg.what = SETUP_COUNT; list_handler.sendMessage(msg); //Add each of the beans to the list for (int i = 0; i < bean_count; i++) { String commit_text = beans.get(i).getTitle(); Date commit_date = new Date(beans.get(i).getUpdated()); changesets_list.add(createChangeset( (commit_text.length() > 30 ? commit_text.substring(0, 30) + "..." : commit_text), beans.get(i).getRevisionID() + " - " + commit_date.toLocaleString())); //Store the current progress of the changeset loading progress_bundle.putInt("progress", i); //Reuse the old message and send an update progress message msg = new Message(); msg.setData(progress_bundle); msg.what = UPDATE_PROGRESS; list_handler.sendMessage(msg); } //Get the current count of changesets and the shared preferences long changeset_count = db_helper.getChangesetCount(repo_id); if (prefs.getBoolean("caching", false)) { //Get all of the stored beans from the device if not already done if (stored_beans == null) stored_beans = db_helper.getAllChangesets(repo_id, null); //Add all the changesets from the device for (Beans.ChangesetBean b : stored_beans) { changesets_list.add(createChangeset( (b.getTitle().length() > 30 ? (b.getTitle().substring(0, 30)) + "..." : b.getTitle()), b.getRevisionID() + " - " + new Date(b.getUpdated()).toLocaleString())); } //Reverse the list so the oldest changesets are stored first Collections.reverse(beans); //Iterate through each bean and add it to the device's database for (Beans.ChangesetBean b : beans) { db_helper.insert(b, repo_id); } //Get the amount of changesets allowed to be stored on the device int max_changes = Integer.parseInt(prefs.getString("max_changesets", "-1")); //Delete the oldest changesets if too many have been stored if (changeset_count > max_changes) { db_helper.deleteNumChangesets(repo_id, (changeset_count - max_changes)); } } else if (changeset_count > 0) { //Since the user does not have caching enabled, delete the changesets db_helper.deleteAllChangesets(repo_id); } //Update the tables to the newest revision if (!beans.isEmpty()) db_helper.updateLastRev(repo_id, beans.get(0).getRevisionID()); //Add all of the data to the changeset list changesets_data.addAll(beans); if (prefs.getBoolean("caching", false)) changesets_data.addAll(stored_beans); //Clean up the sql connection db_helper.cleanup(); db_helper = null; //Notify the handler that the loading of the list was successful list_handler.sendEmptyMessage(SUCCESSFUL); } }; //Start the thread load_thread.start(); }
From source file:app.CT.BTCCalculator.fragments.ProfitFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); View view = getView();//from ww w.j a v a 2 s. co m BusProvider.getInstance().register(this); // Initialize text fields. assert view != null; btcBought = (EditText) view.findViewById(R.id.btcBought); btcBoughtPrice = (EditText) view.findViewById(R.id.btcBoughtPrice); btcSell = (EditText) view.findViewById(R.id.btcSell); btcSellPrice = (EditText) view.findViewById(R.id.btcSellPrice); transPercent = (EditText) view.findViewById(R.id.transPercent); feeTransResult = (TextView) view.findViewById(R.id.transFeeCost); subtotalResult = (TextView) view.findViewById(R.id.subtotal); totalProfitResult = (TextView) view.findViewById(R.id.totalProfit); Button calculate = (Button) view.findViewById(R.id.calculate); // EditText element is clicked in order to enable and show the keyboard to the user. // The corresponding XML element has android:imeOptions="actionNext". // All EditText elements below are now programmed to show keyboard when pressed. btcBought.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showSoftKeyboard(v); } }); btcBoughtPrice.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showSoftKeyboard(v); } }); btcSell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showSoftKeyboard(v); } }); btcSellPrice.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showSoftKeyboard(v); } }); btcBoughtPrice.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { containsCurrentRate[0] = false; } }); btcSellPrice.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { containsCurrentRate[1] = false; } }); calculate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { float buyAmount, buyCost, sellAmount, sellPrice, subtotalCost, subtotalPrice, subtotal, fee, total; boolean validTrans = true; boolean didItWork = true; // Error checking to prevent crashes. try { // Gets the input entered from the user. buyAmount = Float.valueOf(btcBought.getText().toString()); buyCost = Float.valueOf(btcBoughtPrice.getText().toString()); sellAmount = Float.valueOf(btcSell.getText().toString()); sellPrice = Float.valueOf(btcSellPrice.getText().toString()); feePercent = (Float.valueOf(transPercent.getText().toString())) / 100.0f; if (sellAmount > buyAmount) { // Create new dialog popup. final AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity()); alertDialog.setTitle("Error"); alertDialog.setMessage("You cannot sell more than you own."); alertDialog.setCancelable(false); alertDialog.setNeutralButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // If this button is clicked, close current dialog. dialog.cancel(); } }); alertDialog.show(); validTrans = false; } // Calculations to output. subtotalCost = buyAmount * buyCost; subtotalPrice = sellPrice * sellAmount; subtotal = subtotalPrice - subtotalCost; fee = subtotalPrice * feePercent; total = subtotal - fee; if (validTrans) { feeTransResult.setText(String.format("$%s", String.valueOf(roundTwoDecimals(fee)))); subtotalResult.setText(String.format("$%s", String.valueOf(roundTwoDecimals(subtotal)))); totalProfitResult.setText(String.format("$%s", String.valueOf(roundTwoDecimals(total)))); } } catch (Exception e) { // Sets bool to false in order to execute "finally" block below. didItWork = false; } finally { if (!didItWork) { // Creates new dialog popup. final AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(getActivity()); alertDialog2.setTitle("Error"); alertDialog2.setMessage("Please fill in all fields."); alertDialog2.setCancelable(false); alertDialog2.setNeutralButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // If this button is clicked, close current dialog. dialog.cancel(); } }); // Show the dialog. alertDialog2.show(); } } } }); }
From source file:com.photon.phresco.nativeapp.eshop.activity.PhrescoActivity.java
/** * Show error message dialog box with OK and Cancel buttons * * @param errorMessage// w w w .ja v a 2 s.co m * @param cancelFlag */ private void showErrorDialog(String errorMessage, boolean cancelFlag) { PhrescoLogger.info(TAG + "showErrorDialog : cancelFlag = " + cancelFlag); try { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setMessage(errorMessage).setTitle(R.string.app_name).setCancelable(false); @SuppressWarnings("unused") AlertDialog alert = builder.show(); } catch (Exception ex) { PhrescoLogger.info(TAG + "showErrorDialog: " + ex.toString()); PhrescoLogger.warning(ex); } }