List of usage examples for android.app AlertDialog setButton
public void setButton(int whichButton, CharSequence text, OnClickListener listener)
From source file:hr.foicore.varazdinlandmarksdemo.POIMapActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_view_as_grid) { Intent i = new Intent(POIMapActivity.this, POIGridActivity.class); i.putExtra("playOn", mActionPlay); i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); // finish(); overridePendingTransition(0, 0); startActivityForResult(i, 1);// w w w.j av a 2s. c om overridePendingTransition(0, 0); } else if (id == R.id.action_directions) { if (mActionDirections == 1) { // cancel directions action item.setIcon(R.drawable.ic_action_directions); mActionDirections = 0; tvMapDirectionsInfo.setVisibility(View.INVISIBLE); if (mRoute != null) { mRoute.remove(); } } else if (mActionDirections == 0) { // set directions action on item.setIcon(R.drawable.ic_action_directions_pressed); mActionDirections = 1; gmm.handleMapWarningMessages(POIMapActivity.this, tvMapMessage); if (gmm.myLocationEnabled && gmm.internetEnabled) { Toast.makeText(POIMapActivity.this, POIMapActivity.this.getResources().getString(R.string.tap_route_destination), Toast.LENGTH_SHORT).show(); } else { tvMapMessage.setBackgroundColor( POIMapActivity.this.getResources().getColor(R.color.red_transparent)); item.setIcon(R.drawable.ic_action_directions); mActionDirections = 0; tvMapDirectionsInfo.setVisibility(View.INVISIBLE); } } else { // mActionDirections == 3 item.setIcon(R.drawable.ic_action_directions); mActionDirections = 0; tvMapDirectionsInfo.setVisibility(View.INVISIBLE); if (mRoute != null) { mRoute.remove(); } } } else if (id == R.id.action_play) { if (mActionPlay) { // cancel play mode gmm.addAllMarkers(POIMapActivity.this); item.setIcon(R.drawable.ic_action_play); mActionPlay = false; miDirections.setIcon(R.drawable.ic_action_directions); mActionDirections = 0; tvMapDirectionsInfo.setVisibility(View.INVISIBLE); if (mRoute != null) { mRoute.remove(); } } else { gmm.addPlayMarkers(POIMapActivity.this); item.setIcon(R.drawable.ic_action_pause_red); if (gmm.activePOIMarker != null) { drawUserDestRoute(gmm.activePOIMarker.getPosition()); } mActionPlay = true; } } else if (id == R.id.action_google_map_type) { // get google map type names String[] googleMapTypeNames = getResources().getStringArray(R.array.google_map_type_names); // creating and Building the Dialog AlertDialog.Builder builderMapType = new AlertDialog.Builder(this); builderMapType.setTitle(getResources().getString(R.string.action_google_map_type)); builderMapType.setSingleChoiceItems(googleMapTypeNames, selectedMapType, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item != selectedMapType) { switchGoogleMapType(item); // save selected type in settings SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences(POIMapActivity.this); SharedPreferences.Editor editor = preferences.edit(); editor.putString("googleMapType", String.valueOf(item)); editor.commit(); } mapTypeDialog.dismiss(); } }); mapTypeDialog = builderMapType.create(); mapTypeDialog.show(); } else if (id == R.id.action_legal_notices) { String licenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getApplicationContext()); AlertDialog.Builder licenseDialog = new AlertDialog.Builder(POIMapActivity.this); licenseDialog.setTitle(getString(R.string.action_legal_notices)); licenseDialog.setMessage(licenseInfo); licenseDialog.show(); } else if (id == R.id.action_scan_qr_code) { handleQRcodeScanRequest(); } else if (id == R.id.action_about) { String about = getString(R.string.about_application); AlertDialog alertDialog; alertDialog = new AlertDialog.Builder(POIMapActivity.this).create(); alertDialog.setTitle(getString(R.string.action_about)); alertDialog.setMessage(Html.fromHtml(about)); alertDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); alertDialog.show(); } return super.onOptionsItemSelected(item); }
From source file:net.toload.main.hd.ui.ShareDialog.java
public void confirmShareDialog(final String imtype) { AlertDialog alertDialog = new AlertDialog.Builder(activity).create(); if (imtype.equalsIgnoreCase(Lime.DB_RELATED)) { alertDialog.setTitle(activity.getResources().getString(R.string.share_dialog_related_title)); alertDialog.setMessage(activity.getResources().getString(R.string.share_dialog_related_title_message)); } else {//from www. j a va2 s . c o m alertDialog.setTitle(activity.getResources().getString(R.string.share_dialog_title)); alertDialog.setMessage(activity.getResources().getString(R.string.share_dialog_title_message)); } if (!imtype.equalsIgnoreCase(Lime.DB_RELATED)) { alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, activity.getResources().getString(R.string.share_lime_cin), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (imtype.equals(Lime.DB_RELATED)) { // Call Share IM Processes ((MainActivity) activity).initialShareRelated(); dismiss(); sharedialog.dismiss(); } else { // Call Share IM Processes ((MainActivity) activity).initialShare(imtype); dismiss(); sharedialog.dismiss(); } } }); } alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, activity.getResources().getString(R.string.share_lime_db), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (imtype.equals(Lime.DB_RELATED)) { ((MainActivity) activity).initialShareRelatedDb(); dismiss(); sharedialog.dismiss(); } else { // Call Share IM Processes ((MainActivity) activity).initialShareDb(imtype); dismiss(); sharedialog.dismiss(); } } }); alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, activity.getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.show(); }
From source file:org.trosnoth.serveradmin.GameStateActivity.java
protected Dialog onCreateDialog(int id) { if (id == 1001) { AlertDialog.Builder builder;/*from w w w . j ava 2 s .c om*/ AlertDialog alertDialog; Context mContext = GameStateActivity.this; LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.time_dialog, (ViewGroup) findViewById(R.id.layout_root)); final EditText secs = (EditText) layout.findViewById(R.id.editSeconds); secs.setFilters(InputFilters.integerFilter(59)); final EditText mins = (EditText) layout.findViewById(R.id.editMinutes); builder = new AlertDialog.Builder(mContext); builder.setView(layout); alertDialog = builder.create(); alertDialog.setTitle(R.string.game_state_adjust_time); alertDialog.setButton(-1, getApplicationContext().getString(R.string.save), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // Get the values from the EditTexts in the dialog String minStr = mins.getText().toString(); String secStr = secs.getText().toString(); // Convert the minute value int minInt; if (minStr.length() == 0) { minInt = 0; } else { minInt = Integer.valueOf(minStr); } // Convert the second value int secInt; if (secStr.length() == 0) { secInt = 0; } else { secInt = Integer.valueOf(secStr); } // Send it through to the server int totalSeconds = minInt * 60 + secInt; Log.i(LOGTAG, "Adjusting time remaining: " + totalSeconds); if (totalSeconds > 0) { telnet.send("game.setTimeRemaining(" + totalSeconds + ")"); } else { telnet.send("game.setTimeRemaining(None)"); } update(); } }); alertDialog.setButton(-2, getApplicationContext().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); return alertDialog; } return null; }
From source file:com.aniruddhc.acemusic.player.FoldersFragment.FilesFoldersFragment.java
/** * Displays a "Rename" dialog and renames the specified file/folder. * * @param path The path of the folder/file that needs to be renamed. *//* ww w .j a va 2 s . c o m*/ public void rename(String path) { final File renameFile = new File(path); final AlertDialog renameAlertDialog = new AlertDialog.Builder(getActivity()).create(); final EditText fileEditText = new EditText(getActivity()); fileEditText.setHint(R.string.file_name); fileEditText.setSingleLine(true); fileEditText.setText(renameFile.getName()); renameAlertDialog.setView(fileEditText); renameAlertDialog.setTitle(R.string.rename); renameAlertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, mContext.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { renameAlertDialog.dismiss(); } }); renameAlertDialog.setButton(DialogInterface.BUTTON_POSITIVE, mContext.getResources().getString(R.string.rename), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Check if the new file name is empty. if (fileEditText.getText().toString().isEmpty()) { Toast.makeText(getActivity(), R.string.enter_a_name_for_folder, Toast.LENGTH_LONG) .show(); } else { File newNameFile = null; try { newNameFile = new File(renameFile.getParentFile().getCanonicalPath() + "/" + fileEditText.getText().toString()); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getActivity(), R.string.folder_could_not_be_renamed, Toast.LENGTH_LONG).show(); return; } try { if (renameFile.isDirectory()) FileUtils.moveDirectory(renameFile, newNameFile); else FileUtils.moveFile(renameFile, newNameFile); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getActivity(), R.string.folder_could_not_be_renamed, Toast.LENGTH_LONG).show(); return; } Toast.makeText(getActivity(), R.string.folder_renamed, Toast.LENGTH_SHORT).show(); renameAlertDialog.dismiss(); refreshListView(); } } }); renameAlertDialog.show(); }
From source file:com.data.pack.ViewVideo.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.videoplay);/* www . j a va 2s . c o 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:de.tum.frm2.nicos_android.gui.MainActivity.java
@Override public void handleSignal(String signal, Object data, Object args) { switch (signal) { case "broken": final String error = (String) data; // Connection is broken. Try to disconnect what's left and go back to login screen. NicosClient.getClient().unregisterCallbackHandler(this); NicosClient.getClient().disconnect(); if (!_visible) return; // Activity is still visible, user probably didn't intend to shut down connection. // We display an error. runOnUiThread(new Runnable() { @Override/* ww w . ja v a 2s . c o m*/ public void run() { AlertDialog alertDialog; try { alertDialog = new AlertDialog.Builder(MainActivity.this).create(); alertDialog.setTitle("Disconnected"); alertDialog.setMessage(error); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Okay", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); } catch (Exception e) { try { finish(); } catch (Exception e2) { // User probably quit the application. } // Activity isn't running anymore // (user probably put application in background). } } }); break; case "cache": on_client_cache((Object[]) data); break; case "status": // data = tuple of (status, linenumber) _current_status = (int) ((Object[]) data)[0]; break; case "message": final ArrayList msgList = (ArrayList) data; if ((int) msgList.get(2) == NicosMessageLevel.ERROR) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), NicosMessageLevel.level2name(NicosMessageLevel.ERROR) + ": " + msgList.get(3), Toast.LENGTH_SHORT).show(); } }); } break; case "error": final String msg = (String) data; runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); } }); break; } }
From source file:cm.aptoide.pt.ScheduledDownloads.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Builder dialogBuilder = new AlertDialog.Builder(this); final AlertDialog scheduleDialog = dialogBuilder.create(); // AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); switch (item.getItemId()) { case 0://from w w w. j av a 2s . c o m for (String scheduledDownload : scheduledDownloadsHashMap.keySet()) { scheduledDownloadsHashMap.get(scheduledDownload).toggleChecked(); } adapter.notifyDataSetInvalidated(); break; case 1: if (isAllChecked()) { scheduleDialog.setTitle(getText(R.string.schDwnBtn)); scheduleDialog.setIcon(android.R.drawable.ic_menu_close_clear_cancel); scheduleDialog.setCancelable(false); scheduleDialog.setMessage(getText(R.string.schDown_sureremove)); scheduleDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { for (String scheduledDownload : scheduledDownloadsHashMap.keySet()) { if (scheduledDownloadsHashMap.get(scheduledDownload).checked) { db.deleteScheduledDownload(scheduledDownload); } } getSupportLoaderManager().restartLoader(0, null, ScheduledDownloads.this); return; } }); scheduleDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }); scheduleDialog.show(); } else { Toast toast = Toast.makeText(this, getString(R.string.schDown_nodownloadselect), Toast.LENGTH_SHORT); toast.show(); } break; default: break; } return true; }
From source file:com.linkbubble.util.YouTubeEmbedHelper.java
AlertDialog getEmbedResultsDialog() { if (mEmbedInfo.size() > 0) { ListView listView = new ListView(mContext); listView.setAdapter(new EmbedItemAdapter()); AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setView(listView);//from ww w . j a v a 2 s. c o m builder.setIcon(mYouTubeResolveInfo.loadIcon(mContext.getPackageManager())); builder.setTitle(R.string.title_youtube_embed_to_load); final AlertDialog alertDialog = builder.create(); alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { EmbedInfo embedInfo = (EmbedInfo) view.getTag(); if (embedInfo != null) { loadYouTubeVideo(embedInfo.mId); } alertDialog.dismiss(); } }); return alertDialog; } else { final AlertDialog alertDialog = new AlertDialog.Builder(mContext).create(); alertDialog.setTitle(R.string.youtube_embed_error_title); alertDialog.setMessage(mContext.getString(R.string.youtube_embed_error_summary)); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, mContext.getResources().getString(R.string.action_ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { alertDialog.dismiss(); } }); alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); return alertDialog; } }
From source file:info.zamojski.soft.towercollector.MainActivity.java
private void displayUploadResultDialog(Bundle extras) { int descriptionId = extras.getInt(UploaderService.INTENT_KEY_RESULT_DESCRIPTION); try {/* www . j a v a2 s .c o m*/ String descriptionContent = getString(descriptionId); Log.d("displayUploadResultDialog(): Received extras: %s", descriptionId); // display dialog AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true); alertDialog.setTitle(R.string.uploader_result_dialog_title); alertDialog.setMessage(descriptionContent); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); alertDialog.show(); } catch (NotFoundException ex) { Log.w("displayUploadResultDialog(): Invalid string id received with intent extras: %s", descriptionId); MyApplication.getAnalytics().sendException(ex, Boolean.FALSE); ACRA.getErrorReporter().handleSilentException(ex); } }
From source file:net.cloudpath.xpressconnect.screens.ScreenBase.java
protected void alertThenDie(int paramInt1, String paramString, int paramInt2) { AlertDialog localAlertDialog = new AlertDialog.Builder(this).create(); if (localAlertDialog == null) { done(0);//from w ww.j a va2s.c o m return; } String str1 = getString(paramInt1); if (str1 == null) str1 = new String("Alert!"); localAlertDialog.setTitle(str1); localAlertDialog.setMessage(paramString); String str2 = getString(paramInt2); if (str2 == null) str2 = new String("Okay"); localAlertDialog.setButton(-2, str2, new DialogInterface.OnClickListener() { public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) { ScreenBase.this.quit(); } }); localAlertDialog.show(); }