List of usage examples for android.app AlertDialog show
public void show()
From source file:info.xuluan.podcast.SearchActivity.java
@Override protected void onListItemClick(ListView l, View v, int position, long id) { final SearchItem item = mItems.get(position); String content = item.content; AlertDialog d = new AlertDialog.Builder(this).setIcon(R.drawable.alert_dialog_icon).setTitle(item.title) .setMessage(Html.fromHtml(content)) .setPositiveButton(R.string.subscribe, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Subscription sub = new Subscription(item.url); sub.link = item.link; String tags = SearchActivity.this.mEditText.getText().toString(); String content = "<tag>" + tags + "</tag>"; content += "<content>" + item.content + "</content>"; sub.comment = content; int rc = sub.subscribe(getContentResolver()); if (rc == Subscription.ADD_FAIL_DUP) { Toast.makeText(SearchActivity.this, getResources().getString(R.string.already_subscribed), Toast.LENGTH_SHORT) .show(); } else if (rc == Subscription.ADD_SUCCESS) { Toast.makeText(SearchActivity.this, getResources().getString(R.string.success), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(SearchActivity.this, getResources().getString(R.string.fail), Toast.LENGTH_SHORT).show(); }/* w ww .j ava2 s . co m*/ mServiceBinder.start_update(); } }).setNegativeButton(R.string.menu_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { /* User clicked Cancel so do some stuff */ } }).create(); d.show(); }
From source file:it.unipr.ce.dsg.gamidroid.activities.NAM4JAndroidActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { String message = getResources().getString(R.string.exitOnBackButtonPressed); if (keyCode == KeyEvent.KEYCODE_BACK) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(message).setCancelable(false).setPositiveButton( getResources().getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface iDialog, int id) { stopService(new Intent(context, DeviceMonitorService.class)); // Unregistering the broadcast receivers // unregisterReceiver(bReceiver); unregisterReceiver(mConnReceiver); unregisterReceiver(wifiReceiver); if (connected) { close = true; /* * The progress dialog is not created by * the AsyncTask because the peer just * sends a message to the bootstrap. * This takes very few time and the * dialog would disappear almost * immediately. By showing it before * executing the AsyncTask, it can stay * on the screen until the bootstrap * informs the peer that it is part of * the network. Thus, the dialog is * removed from the function listening * for received messages * onReceivedMessage(String). *///from w ww. j a v a2 s . c o m dialog = new ProgressDialog(NAM4JAndroidActivity.this); dialog.setMessage(NAM4JAndroidActivity.this.getString(R.string.pwLeaving)); dialog.show(); new LeaveNetwork(null).execute(); connected = false; } else { // finish(); // AFTER LEAVING THE NETWORK, THE APP GETS CLOSED /* * Notify the system to finalize and * collect all objects of the app on * exit so that the virtual machine * running the app can be killed by the * system without causing issues. * * NOTE: If this is set to true then the * virtual machine will not be killed * until all of its threads have closed. */ System.runFinalizersOnExit(true); /* * Force the system to close the app * down completely instead of retaining * it in the background. The virtual * machine that runs the app will be * killed. The app will be completely * created as a new app in a new virtual * machine running in a new process if * the user starts the app again. */ System.exit(0); } } }).setNegativeButton(getResources().getString(R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); return true; } else if (keyCode == KeyEvent.KEYCODE_MENU) { displaySideMenu(); } return super.onKeyDown(keyCode, event); // return true; }
From source file:com.data.pack.ViewVideo.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.videoplay);/*ww w. ja v a 2 s . co m*/ Intent i = getIntent(); Bundle extras = i.getExtras(); filename = extras.getString("workoutname"); workoutID = extras.getString("workoutID"); UserName = extras.getString("UserName"); userID = extras.getString("userID"); // l= (View)findViewById(R.id.btnnavigation); btnQuit = (Button) findViewById(R.id.headeQuitricon); // btnplay =(Button)findViewById(R.id.btnplay); placeData = new PlaceDataSQL(this); GlobalData.appcount++; if (arrVoVideoName == null) arrVoVideoName = new ArrayList<VOWorkoutVideos>(); GlobalData.viewvideochange = 0; if (videoPathes == null) videoPathes = new ArrayList<Object>(); WindowManager.LayoutParams params = getWindow().getAttributes(); params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON; // params.screenBrightness = 10; getWindow().setAttributes(params); if (obUser.getSelectedLanguage().equals("1")) { YesString = "Yes"; strLeaveVideo = "You are about to exit the Video. Are you sure ?"; NoString = "No"; } else { YesString = "Ja"; QuitString = "verlassen"; strLeaveVideo = "Du bist dabei das Video zu beenden, bist Du sicher ?"; NoString = "Nein"; } count = 1; // Toast.makeText(getBaseContext(), "countcountcountcount" // +count,Toast.LENGTH_LONG).show(); // btnQuit =(Button) findViewById(R.id.headeQuitricon); btnQuit.setText(QuitString); btnQuit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // Intent intent = new Intent(sharescreen.this, // HomeScreen.class); // // intent.putExtra("userID", userID); // startActivity(intent); AlertDialog alertDialog = new AlertDialog.Builder(ViewVideo.this).create(); if (mVideoView.isPlaying()) { mVideoView.pause(); } alertDialog.setTitle("fitness4.me"); alertDialog.setMessage(strLeaveVideo); alertDialog.setButton(-1, YesString, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { try { GlobalData.viewvideochange = 1; Intent intent = new Intent(ViewVideo.this, FitnessforMeActivity.class); startActivity(intent); if (mVideoView != null) mVideoView.stopPlayback(); } catch (Exception e) { // TODO: handle exception } } }); alertDialog.setButton(-2, NoString, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { GlobalData.viewvideochange = 0; mVideoView.start(); dialog.cancel(); } }); try { alertDialog.show(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); mycontroller = new MediaController(this); mVideoView = (VideoView) findViewById(R.id.surface_view); mVideoView.setMediaController(null); AdView adView = (AdView) this.findViewById(R.id.adView); if (GlobalData.allPurchased == true) { adView.setVisibility(View.GONE); } else { adView.setVisibility(View.VISIBLE); adView.loadAd(new AdRequest()); } try { myTimer = new Timer(); myTimer.schedule(new TimerTask() { @Override public void run() { TimerMethod(); } }, 1, 1000); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } mVideoView.setOnCompletionListener(myVideoViewCompletionListener); getDataAndPopulate(); }
From source file:com.df.app.procedures.CarRecogniseLayout.java
/** * VIN??//from w ww . j a va 2 s .com */ private void checkVinAndGetCarSettings() { InputMethodManager imm = (InputMethodManager) rootView.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(findViewById(R.id.vin_edit).getWindowToken(), 0); final String vinString = getEditViewText(rootView, R.id.vin_edit); // ? if (vinString.equals("")) { Toast.makeText(rootView.getContext(), "VIN?", Toast.LENGTH_SHORT).show(); findViewById(R.id.vin_edit).requestFocus(); return; } // VIN? if (!isVin(vinString)) { View view1 = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.popup_layout, null); TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea); TextView content = new TextView(view1.getContext()); content.setText("VIN?: " + vinString + "\n" + "VIN?????\n"); content.setTextSize(20f); contentArea.addView(content); setTextView(view1, R.id.title, getResources().getString(R.string.alert)); AlertDialog dialog = new AlertDialog.Builder(rootView.getContext()).setView(view1) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { setEditViewText(rootView, R.id.brand_edit, ""); findViewById(R.id.brand_select_button).setEnabled(false); // ???VIN getCarSettingsFromServer(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { findViewById(R.id.vin_edit).requestFocus(); } }).create(); dialog.show(); return; } setEditViewText(rootView, R.id.brand_edit, ""); findViewById(R.id.brand_select_button).setEnabled(false); // ???VIN getCarSettingsFromServer(); }
From source file:com.nexes.manager.EventHandler.java
/** * This private method is used to display options the user can select when * the tool box button is pressed. The WIFI option is commented out as it * doesn't seem to fit with the overall idea of the application. However to * display it, just uncomment the below code and the code in the * AndroidManifest.xml file./* www. ja v a 2 s.c o m*/ */ private void display_dialog(int type) { AlertDialog.Builder builder; AlertDialog dialog; switch (type) { case MANAGE_DIALOG: // un-comment WIFI Info here and in the manifest file // to display WIFI info. Also uncomment and change case number below CharSequence[] options = { "Process Info", /* "Wifi Info", */ "Application backup" }; builder = new AlertDialog.Builder(mContext); builder.setTitle("Tool Box"); builder.setIcon(R.drawable.toolbox); builder.setItems(options, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int index) { Intent i; switch (index) { case 0: i = new Intent(mContext, ProcessManager.class); mContext.startActivity(i); break; /* * case 1: i = new Intent(context, WirelessManager.class); * context.startActivity(i); break; */ case 1: i = new Intent(mContext, ApplicationBackup.class); mContext.startActivity(i); break; } } }); dialog = builder.create(); dialog.show(); break; } }
From source file:com.df.dfcarchecker.CarCheck.CarCheckBasicInfoFragment.java
public void PictureMatch() { View view = this.inflater.inflate(R.layout.ci_dialog, null); AlertDialog dialog = new AlertDialog.Builder(rootView.getContext()).setTitle("?").setView(view) .setPositiveButton(R.string.ci_attention_match, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // setPictureMatchEdit(true); }//w w w. j a v a 2 s . c om }).setNegativeButton(R.string.ci_attention_notmatch, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // ? setPictureMatchEdit(false); } }).create(); dialog.show(); }
From source file:com.ezac.gliderlogs.FlightOverviewActivity.java
public void DoServices() { // get services.xml view LayoutInflater li = LayoutInflater.from(context); servicesView = li.inflate(R.layout.services, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); // set prompts.xml to alertdialog builder alertDialogBuilder.setView(servicesView); final EditText userInput = (EditText) servicesView.findViewById(R.id.editTextDialogUserInput); // set dialog message alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override//from w ww . j a v a 2 s.co m public void onClick(DialogInterface dialog, int id) { // get user input and set it to result if (userInput.getText().toString().equals("To3Myd4T")) { Log.d(TAG, "ok, user request to delete all, do it"); CheckBox csv_ok = (CheckBox) servicesView.findViewById(R.id.service_csv); CheckBox db_ok = (CheckBox) servicesView.findViewById(R.id.service_db); // make a copy to csv file if (csv_ok.isChecked()) { GliderLogToCSV("gliderlogs.db", "ezac"); makeToast("Export naar een CSV bestand is uitgevoerd !", 2); } // make a copy to sqlite database file if (db_ok.isChecked()) { GliderLogToDB("com.ezac.gliderlogs", "gliderlogs.db", "ezac"); makeToast("Export naar een DB bestand is uitgevoerd !", 2); } if (csv_ok.isChecked() || db_ok.isChecked()) { sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); } // remove records from flights table DoDrop(); // import support tables (glider, members, passengers & reservations) // and any starts for this day DoImport(); } else { makeToast("De gebruikte service code is niet correct !", 0); Log.d(TAG, "Fail, user service code error >" + userInput.getText().toString() + "<"); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
private void optionSubmit() { if (ActivityShare.registerDevice(this)) { int[] uid = (mAppAdapter == null ? new int[0] : mAppAdapter.getSelectedOrVisibleUid(AppListAdapter.cSelectAppNone)); if (uid.length == 0) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(R.string.app_name); alertDialogBuilder.setMessage(R.string.msg_select); alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); alertDialogBuilder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { }/* w w w .ja va 2 s . c o m*/ }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } else if (uid.length <= ActivityShare.cSubmitLimit) { if (mAppAdapter != null) { Intent intent = new Intent(ActivityShare.ACTION_SUBMIT); intent.putExtra(ActivityShare.cInteractive, true); intent.putExtra(ActivityShare.cUidList, uid); startActivity(intent); } } else { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(R.string.app_name); alertDialogBuilder.setMessage(getString(R.string.msg_limit, ActivityShare.cSubmitLimit + 1)); alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); alertDialogBuilder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } } }
From source file:RhodesService.java
private File downloadPackage(String url) throws IOException { final Context ctx = RhodesActivity.getContext(); final Thread thisThread = Thread.currentThread(); final Runnable cancelAction = new Runnable() { public void run() { thisThread.interrupt();//from w w w. j a v a 2s .c om } }; BroadcastReceiver downloadReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(ACTION_ASK_CANCEL_DOWNLOAD)) { AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setMessage("Cancel download?"); AlertDialog dialog = builder.create(); dialog.setButton(AlertDialog.BUTTON_POSITIVE, ctx.getText(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { cancelAction.run(); } }); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, ctx.getText(android.R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Nothing } }); dialog.show(); } else if (action.equals(ACTION_CANCEL_DOWNLOAD)) { cancelAction.run(); } } }; IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_ASK_CANCEL_DOWNLOAD); filter.addAction(ACTION_CANCEL_DOWNLOAD); ctx.registerReceiver(downloadReceiver, filter); File tmpFile = null; InputStream is = null; OutputStream os = null; try { updateDownloadNotification(url, -1, 0); /* List<File> folders = new ArrayList<File>(); folders.add(Environment.getDownloadCacheDirectory()); folders.add(Environment.getDataDirectory()); folders.add(ctx.getCacheDir()); folders.add(ctx.getFilesDir()); try { folders.add(new File(ctx.getPackageManager().getApplicationInfo(ctx.getPackageName(), 0).dataDir)); } catch (NameNotFoundException e1) { // Ignore } folders.add(Environment.getExternalStorageDirectory()); for (File folder : folders) { File tmpRootFolder = new File(folder, "rhodownload"); File tmpFolder = new File(tmpRootFolder, ctx.getPackageName()); if (tmpFolder.exists()) deleteFilesInFolder(tmpFolder.getAbsolutePath()); else tmpFolder.mkdirs(); File of = new File(tmpFolder, UUID.randomUUID().toString() + ".apk"); Logger.D(TAG, "Check path " + of.getAbsolutePath() + "..."); try { os = new FileOutputStream(of); } catch (FileNotFoundException e) { Logger.D(TAG, "Can't open file " + of.getAbsolutePath() + ", check next path"); continue; } Logger.D(TAG, "File " + of.getAbsolutePath() + " succesfully opened for write, start download app"); tmpFile = of; break; } */ tmpFile = ctx.getFileStreamPath(UUID.randomUUID().toString() + ".apk"); os = ctx.openFileOutput(tmpFile.getName(), Context.MODE_WORLD_READABLE); Logger.D(TAG, "Download " + url + " to " + tmpFile.getAbsolutePath() + "..."); URL u = new URL(url); URLConnection conn = u.openConnection(); int totalBytes = -1; if (conn instanceof HttpURLConnection) { HttpURLConnection httpConn = (HttpURLConnection) conn; totalBytes = httpConn.getContentLength(); } is = conn.getInputStream(); int downloaded = 0; updateDownloadNotification(url, totalBytes, downloaded); long prevProgress = 0; byte[] buf = new byte[65536]; for (;;) { if (thisThread.isInterrupted()) { tmpFile.delete(); Logger.D(TAG, "Download of " + url + " was canceled"); return null; } int nread = is.read(buf); if (nread == -1) break; //Logger.D(TAG, "Downloading " + url + ": got " + nread + " bytes..."); os.write(buf, 0, nread); downloaded += nread; if (totalBytes > 0) { // Update progress view only if current progress is greater than // previous by more than 10%. Otherwise, if update it very frequently, // user will no have chance to click on notification view and cancel if need long progress = downloaded * 10 / totalBytes; if (progress > prevProgress) { updateDownloadNotification(url, totalBytes, downloaded); prevProgress = progress; } } } Logger.D(TAG, "File stored to " + tmpFile.getAbsolutePath()); return tmpFile; } catch (IOException e) { if (tmpFile != null) tmpFile.delete(); throw e; } finally { try { if (is != null) is.close(); } catch (IOException e) { } try { if (os != null) os.close(); } catch (IOException e) { } mNM.cancel(DOWNLOAD_PACKAGE_ID); ctx.unregisterReceiver(downloadReceiver); } }