List of usage examples for android.content DialogInterface.OnClickListener DialogInterface.OnClickListener
DialogInterface.OnClickListener
From source file:com.vuze.android.remote.AndroidUtils.java
public static void showConnectionError(final Activity activity, final String errMsg, final boolean allowContinue) { if (AndroidUtils.DEBUG) { Log.d(TAG, "showConnectionError.string " + AndroidUtils.getCompressedStackTrace()); }// w w w . j av a 2s. co m if (activity == null) { Log.e(null, "No activity for error message " + errMsg); return; } activity.runOnUiThread(new Runnable() { public void run() { if (activity.isFinishing()) { if (DEBUG) { System.out.println("can't display -- finishing"); } return; } Builder builder = new AlertDialog.Builder(activity).setTitle(R.string.error_connecting) .setMessage(errMsg).setCancelable(true) .setNegativeButton(R.string.action_logout, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (activity.isTaskRoot()) { RemoteUtils.openRemoteList(activity); } activity.finish(); } }); if (allowContinue) { builder.setPositiveButton(R.string.button_continue, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); } AndroidUtils.openSingleAlertDialog(activity, builder); } }); }
From source file:no.digipost.android.gui.metadata.ExternalLinkWebview.java
private void showMissingPermissionsDialog() { String message = getString(R.string.externallink_permissions); AlertDialog.Builder builder = DialogUtitities.getAlertDialogBuilderWithMessage(this, message); builder.setPositiveButton(getString(R.string.externallink_continue), new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { dialog.dismiss();/*from w w w . j ava 2 s . c o m*/ finish(); } }); builder.create().show(); }
From source file:no.digipost.android.gui.metadata.ExternalLinkWebview.java
private void showDownloadSuccessDialog(final Context downloadContext) { String message = format(getString(R.string.externallink_download_success_message), fileName); AlertDialog.Builder builder = DialogUtitities.getAlertDialogBuilderWithMessage(downloadContext, message); builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { dialog.dismiss();//from w w w . ja v a 2 s . c o m finish(); } }); builder.create().show(); }
From source file:cm.aptoide.pt.ScheduledDownloads.java
private void continueLoading() { lv = (ListView) findViewById(android.R.id.list); db = Database.getInstance();/*from www . j a v a 2 s. c o m*/ adapter = new CursorAdapter(this, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) { @Override public View newView(Context context, Cursor arg1, ViewGroup arg2) { return LayoutInflater.from(context).inflate(R.layout.row_sch_download, null); } @Override public void bindView(View convertView, Context arg1, Cursor c) { // Planet to display ScheduledDownload scheduledDownload = scheduledDownloadsHashMap.get(c.getString(0)); // The child views in each row. CheckBox checkBoxScheduled; TextView textViewName; TextView textViewVersion; ImageView imageViewIcon; // Create a new row view if (convertView.getTag() == null) { // Find the child views. textViewName = (TextView) convertView.findViewById(R.id.name); textViewVersion = (TextView) convertView.findViewById(R.id.appversion); checkBoxScheduled = (CheckBox) convertView.findViewById(R.id.schDwnChkBox); imageViewIcon = (ImageView) convertView.findViewById(R.id.appicon); // Optimization: Tag the row with it's child views, so we don't have to // call findViewById() later when we reuse the row. convertView.setTag(new Holder(textViewName, textViewVersion, checkBoxScheduled, imageViewIcon)); // If CheckBox is toggled, update the planet it is tagged with. checkBoxScheduled.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CheckBox cb = (CheckBox) v; ScheduledDownload schDownload = (ScheduledDownload) cb.getTag(); schDownload.setChecked(cb.isChecked()); } }); } // Reuse existing row view else { // Because we use a ViewHolder, we avoid having to call findViewById(). Holder viewHolder = (Holder) convertView.getTag(); checkBoxScheduled = viewHolder.checkBoxScheduled; textViewVersion = viewHolder.textViewVersion; textViewName = viewHolder.textViewName; imageViewIcon = viewHolder.imageViewIcon; } // Tag the CheckBox with the Planet it is displaying, so that we can // access the planet in onClick() when the CheckBox is toggled. checkBoxScheduled.setTag(scheduledDownload); // Display planet data checkBoxScheduled.setChecked(scheduledDownload.isChecked()); textViewName.setText(scheduledDownload.getName()); textViewVersion.setText(scheduledDownload.getVername()); // Tag the CheckBox with the Planet it is displaying, so that we can // access the planet in onClick() when the CheckBox is toggled. checkBoxScheduled.setTag(scheduledDownload); // Display planet data checkBoxScheduled.setChecked(scheduledDownload.isChecked()); textViewName.setText(scheduledDownload.getName()); textViewVersion.setText("" + scheduledDownload.getVername()); ImageLoader.getInstance().displayImage(scheduledDownload.getIconPath(), imageViewIcon); } }; lv.setAdapter(adapter); getSupportLoaderManager().initLoader(0, null, this); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View item, int arg2, long arg3) { ScheduledDownload scheduledDownload = (ScheduledDownload) ((Holder) item.getTag()).checkBoxScheduled .getTag(); scheduledDownload.toggleChecked(); Holder viewHolder = (Holder) item.getTag(); viewHolder.checkBoxScheduled.setChecked(scheduledDownload.isChecked()); } }); IntentFilter filter = new IntentFilter("pt.caixamagica.aptoide.REDRAW"); registerReceiver(receiver, filter); Button installButton = (Button) findViewById(R.id.sch_down); // installButton.setText(getText(R.string.schDown_installselected)); installButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (isAllChecked()) { for (String scheduledDownload : scheduledDownloadsHashMap.keySet()) { if (scheduledDownloadsHashMap.get(scheduledDownload).checked) { ScheduledDownload schDown = scheduledDownloadsHashMap.get(scheduledDownload); ViewApk apk = new ViewApk(); apk.setApkid(schDown.getApkid()); apk.setName(schDown.getName()); apk.setVercode(schDown.getVercode()); apk.setIconPath(schDown.getIconPath()); apk.setVername(schDown.getVername()); apk.setRepoName(schDown.getRepoName()); serviceDownloadManager .startDownloadWithWebservice(serviceDownloadManager.getDownload(apk), apk); Toast toast = Toast.makeText(ScheduledDownloads.this, R.string.starting_download, Toast.LENGTH_SHORT); toast.show(); } } } else { Toast toast = Toast.makeText(ScheduledDownloads.this, R.string.schDown_nodownloadselect, Toast.LENGTH_SHORT); toast.show(); } } }); if (getIntent().hasExtra("downloadAll")) { Builder dialogBuilder = new AlertDialog.Builder(this); final AlertDialog scheduleDownloadDialog = dialogBuilder.create(); scheduleDownloadDialog.setTitle(getText(R.string.schDwnBtn)); scheduleDownloadDialog.setIcon(android.R.drawable.ic_dialog_alert); scheduleDownloadDialog.setCancelable(false); scheduleDownloadDialog.setMessage(getText(R.string.schDown_install)); scheduleDownloadDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { for (String scheduledDownload : scheduledDownloadsHashMap.keySet()) { ScheduledDownload schDown = scheduledDownloadsHashMap.get(scheduledDownload); ViewApk apk = new ViewApk(); apk.setApkid(schDown.getApkid()); apk.setName(schDown.getName()); apk.setVercode(schDown.getVercode()); apk.setIconPath(schDown.getIconPath()); apk.setVername(schDown.getVername()); apk.setRepoName(schDown.getRepoName()); serviceDownloadManager .startDownloadWithWebservice(serviceDownloadManager.getDownload(apk), apk); Toast toast = Toast.makeText(ScheduledDownloads.this, R.string.starting_download, Toast.LENGTH_SHORT); toast.show(); } finish(); } }); scheduleDownloadDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { finish(); } }); scheduleDownloadDialog.show(); } }
From source file:io.coldstart.android.TrapListActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.GCMStatus: { subscribeToMessages();//w ww .j a v a 2s . c o m return true; } case R.id.ChangeKey: { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit(); editor.putBoolean("firstRun", true); editor.putString("APIKey", ""); editor.putString("keyPassword", ""); editor.commit(); Intent intent = getIntent(); overridePendingTransition(0, 0); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); finish(); overridePendingTransition(0, 0); startActivity(intent); return true; } case R.id.PauseAlerts: { new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert) .setTitle("Delete Traps for selected host?") .setMessage( "Are you sure you want to logout?\nYou'll no longer receive any alerts, they won't be cached on the server and the app will close.") .setPositiveButton("Yes, Logout", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.i("onOptionsItemSelected", "Logging Out"); (new Thread() { public void run() { API api = new API(); try { if (api.logoutGCMAccount(settings.getString("APIKey", ""), settings.getString("keyPassword", ""), securityID)) { //We successfully logged out runOnUiThread(new Runnable() { public void run() { gcmStatus.setIcon(R.drawable.ic_action_gcm_failed); Toast.makeText(getApplicationContext(), "Succesfully logged out. Tap the GCM icon or relaunch app to login again", Toast.LENGTH_SHORT).show(); } }); } else { //TODO Popup to the user that there was a problem logging out runOnUiThread(new Runnable() { public void run() { gcmStatus.setIcon(R.drawable.ic_action_gcm_failed); Toast.makeText(getApplicationContext(), "There was a problem logging out.", Toast.LENGTH_SHORT) .show(); } }); } runOnUiThread(new Runnable() { public void run() { TrapListActivity.this.invalidateOptionsMenu(); } }); } catch (Exception e) { //TODO this is probably pretty bad! e.printStackTrace(); } } }).start(); } }).setNegativeButton("No", null).show(); return true; } case R.id.Settings: { Intent SettingsIntent = new Intent(TrapListActivity.this, SettingsFragment.class); this.startActivityForResult(SettingsIntent, DISPLAY_SETTINGS); return true; } case R.id.SeeAPIKey: { if (dialogFragment != null) dialogFragment.dismiss(); FragmentTransaction ft = getFragmentManager().beginTransaction(); Fragment prev = getFragmentManager().findFragmentByTag("dialog"); if (prev != null) { ft.remove(prev); Log.i("prev", "Removing"); } ft.addToBackStack(null); // Create and show the dialog. dialogFragment = ViewAPIKeyDialog.newInstance(settings.getString("APIKey", "")); dialogFragment.setCancelable(true); dialogFragment.show(ft, "dialog"); return true; } /*case R.id.Filters: { if(dialogFragment != null) dialogFragment.dismiss(); FragmentTransaction ft = getFragmentManager().beginTransaction(); Fragment prev = getFragmentManager().findFragmentByTag("dialog"); if (prev != null) { ft.remove(prev); Log.i("prev","Removing"); } ft.addToBackStack(null); // Create and show the dialog. dialogFragment = HostFilterDialog.newInstance(); dialogFragment.setCancelable(true); dialogFragment.show(ft, "dialog"); return true; }*/ } return false; }
From source file:com.vuze.android.remote.AndroidUtils.java
public static void showDialog(final Activity activity, final CharSequence title, final CharSequence msg) { activity.runOnUiThread(new Runnable() { public void run() { if (activity.isFinishing()) { if (DEBUG) { System.out.println("can't display -- finishing"); }//from w w w .ja v a2 s. c om return; } Builder builder = new AlertDialog.Builder(activity).setMessage(msg).setCancelable(true) .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); if (title != null) { builder.setTitle(title); } builder.show(); } }); }
From source file:org.guohai.android.cta.CoordinateTalk.java
/** ? */ private void inita() { locationInfo = new LocationInfo(); GSMManager gsm = new GSMManager(getApplicationContext(), locationInfo); GPSManager gps = new GPSManager(getApplicationContext(), locationInfo); LocationManagers = new ArrayList<ILocationManager>(); LocationManagers.add(gsm);/*from w w w . j a va2 s. c o m*/ LocationManagers.add(gps); //?? mMainHandler = new Handler(); openHandler(); textCoordinate.setText("" + locationInfo.Latitude + "\n?" + locationInfo.Longitude + "\n" + locationInfo.Altitude); if (!gps.IsOpen()) { new AlertDialog.Builder(CoordinateTalk.this).setTitle(R.string.setting_gps_title) .setMessage(R.string.setting_gps_info) .setPositiveButton(R.string.gps_setting, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS); startActivityForResult(intent, 0); } }).setNegativeButton(R.string.jump_gps_setting, null).show(); textCoordinate.setText("?GPS????"); } }
From source file:org.codecyprus.android_client.ui.ActivityStartQuiz.java
private void enterCode() { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(R.string.Enter_code); // Set an EditText view to get user input final EditText input = new EditText(this); alert.setView(input);// w ww . ja v a 2 s.co m alert.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { code = input.getText().toString(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }); alert.show(); }
From source file:com.iskrembilen.quasseldroid.gui.LoginActivity.java
@Override protected Dialog onCreateDialog(int id) { final Dialog dialog; switch (id) { case R.id.DIALOG_EDIT_CORE: //fallthrough case R.id.DIALOG_ADD_CORE: dialog = new Dialog(this); dialog.setContentView(R.layout.dialog_add_core); dialog.setTitle("Add new core"); OnClickListener buttonListener = new OnClickListener() { @Override/*from w w w . jav a 2 s. c o m*/ public void onClick(View v) { EditText nameField = (EditText) dialog.findViewById(R.id.dialog_name_field); EditText addressField = (EditText) dialog.findViewById(R.id.dialog_address_field); EditText portField = (EditText) dialog.findViewById(R.id.dialog_port_field); CheckBox sslBox = (CheckBox) dialog.findViewById(R.id.dialog_usessl_checkbox); if (v.getId() == R.id.cancel_button) { nameField.setText(""); addressField.setText(""); portField.setText(""); sslBox.setChecked(false); dialog.dismiss(); } else if (v.getId() == R.id.save_button && !nameField.getText().toString().equals("") && !addressField.getText().toString().equals("") && !portField.getText().toString().equals("")) { String name = nameField.getText().toString().trim(); String address = addressField.getText().toString().trim(); int port = Integer.parseInt(portField.getText().toString().trim()); boolean useSSL = sslBox.isChecked(); //TODO: Ken: mabye add some better check on what state the dialog is used for, edit/add. Atleast use a string from the resources so its the same if you change it. if ((String) dialog.getWindow().getAttributes().getTitle() == "Add new core") { dbHelper.addCore(name, address, port, useSSL); } else if ((String) dialog.getWindow().getAttributes().getTitle() == "Edit core") { dbHelper.updateCore(core.getSelectedItemId(), name, address, port, useSSL); } LoginActivity.this.updateCoreSpinner(); nameField.setText(""); addressField.setText(""); portField.setText(""); sslBox.setChecked(false); dialog.dismiss(); if ((String) dialog.getWindow().getAttributes().getTitle() == "Add new core") { Toast.makeText(LoginActivity.this, "Added core", Toast.LENGTH_LONG).show(); } else if ((String) dialog.getWindow().getAttributes().getTitle() == "Edit core") { Toast.makeText(LoginActivity.this, "Edited core", Toast.LENGTH_LONG).show(); } } } }; dialog.findViewById(R.id.cancel_button).setOnClickListener(buttonListener); dialog.findViewById(R.id.save_button).setOnClickListener(buttonListener); break; case R.id.DIALOG_NEW_CERTIFICATE: AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this); final SharedPreferences certPrefs = getSharedPreferences("CertificateStorage", Context.MODE_PRIVATE); builder.setMessage("Received a new certificate, do you trust it?\n" + hashedCert).setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { certPrefs.edit().putString("certificate", hashedCert).commit(); onConnect.onClick(null); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); dialog = builder.create(); break; default: dialog = null; break; } return dialog; }
From source file:nf.frex.android.FrexActivity.java
private void setWallpaper() { final WallpaperManager wallpaperManager = WallpaperManager.getInstance(FrexActivity.this); final int desiredWidth = wallpaperManager.getDesiredMinimumWidth(); final int desiredHeight = wallpaperManager.getDesiredMinimumHeight(); final Image image = view.getImage(); final int imageWidth = image.getWidth(); final int imageHeight = image.getHeight(); final boolean useDesiredSize = desiredWidth > imageWidth || desiredHeight > imageHeight; DialogInterface.OnClickListener noListener = new DialogInterface.OnClickListener() { @Override/*from www. j a v a2s . c o m*/ public void onClick(DialogInterface dialog, int which) { // ok } }; if (useDesiredSize) { showYesNoDialog(this, R.string.set_wallpaper, getString(R.string.wallpaper_compute_msg, desiredWidth, desiredHeight), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final Image wallpaperImage; try { wallpaperImage = new Image(desiredWidth, desiredHeight); } catch (OutOfMemoryError e) { alert(getString(R.string.out_of_memory)); return; } final ProgressDialog progressDialog = new ProgressDialog(FrexActivity.this); Generator.ProgressListener progressListener = new Generator.ProgressListener() { int numLines; @Override public void onStarted(int numTasks) { } @Override public void onSomeLinesComputed(int taskId, int line1, int line2) { numLines += 1 + line2 - line1; progressDialog.setProgress(numLines); } @Override public void onStopped(boolean cancelled) { progressDialog.dismiss(); if (!cancelled) { setWallpaper(wallpaperManager, wallpaperImage); } } }; final Generator wallpaperGenerator = new Generator(view.getGeneratorConfig(), SettingsActivity.NUM_CORES, progressListener); DialogInterface.OnCancelListener cancelListener = new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (progressDialog.isShowing()) { progressDialog.dismiss(); } wallpaperGenerator.cancel(); } }; progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setCancelable(true); progressDialog.setMax(desiredHeight); progressDialog.setOnCancelListener(cancelListener); progressDialog.show(); Arrays.fill(wallpaperImage.getValues(), FractalView.MISSING_VALUE); wallpaperGenerator.start(wallpaperImage, false); } }, noListener, null); } else { showYesNoDialog(this, R.string.set_wallpaper, getString(R.string.wallpaper_replace_msg), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setWallpaper(wallpaperManager, image); } }, noListener, null); } }