List of usage examples for android.app AlertDialog.Builder setCancelable
public void setCancelable(boolean flag)
From source file:com.dwdesign.tweetings.fragment.BaseStatusesListFragment.java
protected void translate(final ParcelableStatus status) { ThreadPolicy tp = ThreadPolicy.LAX; StrictMode.setThreadPolicy(tp);//from w ww .j a v a 2 s . co m String language = Locale.getDefault().getLanguage(); String url = "http://api.microsofttranslator.com/v2/Http.svc/Translate?contentType=" + URLEncoder.encode("text/plain") + "&appId=" + BING_TRANSLATE_API_KEY + "&from=&to=" + language + "&text="; url = url + URLEncoder.encode(status.text_plain); try { HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(new HttpGet(url)); BufferedReader reader = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), "UTF-8")); String sResponse; StringBuilder s = new StringBuilder(); while ((sResponse = reader.readLine()) != null) { s = s.append(sResponse); } String finalString = s.toString(); finalString = finalString .replace("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">", ""); finalString = finalString.replace("</string>", ""); AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity()); builder.setTitle(getString(R.string.translate)); builder.setMessage(finalString); builder.setCancelable(true); builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); //Toast.makeText(getActivity(), finalString, Toast.LENGTH_LONG).show(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.mendhak.gpslogger.common.PrefsIO.java
public Dialog ChooseFileDialog() { File myDir = new File(defPath); if (!myDir.exists()) return null; Utilities.LogDebug("Asking user the file to use for import of settings"); File[] enumeratedFiles = myDir.listFiles(new FilenameFilter() { @Override/* w w w.j ava 2s. c o m*/ public boolean accept(File dir, String name) { return name.endsWith("." + extension); } }); final int len = enumeratedFiles.length; List<String> fileList = new ArrayList<String>(len); for (File f : enumeratedFiles) { fileList.add(f.getName()); } fileList.add(context.getString(R.string.Browse)); final String[] files = fileList.toArray(new String[fileList.size()]); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(context.getString(R.string.SelectFile)); builder.setItems(files, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (item < len) { curFileName = defPath + File.separator + files[item]; ImportFile(); } else BrowseFile(); } }); builder.setCancelable(true); return builder.create(); }
From source file:ch.uzh.supersede.feedbacklibrary.utils.Utils.java
/** * This method is used in the host application in the onRequestPermissionsResult method in case if a PUSH feedback is triggered. * * @param requestCode the request code to be handled in the onRequestPermissionsResult method of the calling activity * @param permissions the permissions/* w w w . j a v a 2s .com*/ * @param grantResults the granted results * @param activity the activity from where the method is called * @param permission the requested permission * @param dialogTitle the dialog title for the rationale * @param dialogMessage the dialog message for the rationale */ public static void onRequestPermissionsResultCase(final int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults, @NonNull final Activity activity, @NonNull final String permission, final int dialogTitle, final int dialogMessage, final long applicationId, @NonNull final String baseURL, @NonNull final String language) { final Intent intent = new Intent(activity, FeedbackActivity.class); intent.putExtra(FeedbackActivity.EXTRA_KEY_APPLICATION_ID, applicationId); intent.putExtra(FeedbackActivity.EXTRA_KEY_BASE_URL, baseURL); intent.putExtra(FeedbackActivity.EXTRA_KEY_LANGUAGE, language); if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // Permission was already granted. Taking a screenshot of the current screen automatically and open the FeedbackActivity from the feedback library startActivity(activity, intent, baseURL, true); } else { if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { // The user denied the permission without checking 'Never ask again'. Show the rationale AlertDialog.Builder alertBuilder = new AlertDialog.Builder(activity); alertBuilder.setTitle(dialogTitle); alertBuilder.setMessage(dialogMessage); alertBuilder.setPositiveButton(R.string.supersede_feedbacklibrary_retry_string, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { ActivityCompat.requestPermissions(activity, new String[] { permission }, requestCode); } }); alertBuilder.setNegativeButton(R.string.supersede_feedbacklibrary_not_now_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); startActivity(activity, intent, baseURL, false); } }); alertBuilder.setCancelable(false); alertBuilder.show(); } else { // Open the FeedbackActivity from the feedback library without automatically taking a screenshot startActivity(activity, intent, baseURL, false); } } }
From source file:com.remobile.dialogs.Notification.java
/** * Builds and shows a native Android prompt dialog with given title, message, buttons. * This dialog only shows up to 3 buttons. Any labels after that will be ignored. * The following results are returned to the JavaScript callback identified by callbackId: * buttonIndex Index number of the button selected * input1 The text entered in the prompt dialog box * * @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 callbackContext The callback context. *//*from w w w . j a va 2s .c om*/ public synchronized void prompt(final String message, final String title, final JSONArray buttonLabels, final String defaultText, final CallbackContext callbackContext) { final Activity activity = this.cordova.getActivity(); Runnable runnable = new Runnable() { public void run() { final EditText promptInput = new EditText(activity); promptInput.setHint(defaultText); AlertDialog.Builder dlg = createDialog(); // new AlertDialog.Builder(this.cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(false); dlg.setView(promptInput); final JSONObject result = new JSONObject(); // First button if (buttonLabels.length() > 0) { try { dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 1); result.put("input1", promptInput.getText().toString().trim().length() == 0 ? defaultText : promptInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } } // Second button if (buttonLabels.length() > 1) { try { dlg.setNeutralButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 2); result.put("input1", promptInput.getText().toString().trim().length() == 0 ? defaultText : promptInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } } // Third button if (buttonLabels.length() > 2) { try { dlg.setPositiveButton(buttonLabels.getString(2), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 3); result.put("input1", promptInput.getText().toString().trim().length() == 0 ? defaultText : promptInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } } dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); try { result.put("buttonIndex", 0); result.put("input1", promptInput.getText().toString().trim().length() == 0 ? defaultText : promptInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); changeTextDirection(dlg); } ; }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:org.thomasamsler.android.flashcards.fragment.CardSetsFragment.java
private void deleteCardSet(final int listItemPosition) { AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setMessage(R.string.delete_card_set_dialog_message); builder.setCancelable(false); builder.setPositiveButton(R.string.delete_card_set_dialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { CardSet cardSet = mCardSets.get(listItemPosition); List<CardSet> cardSets = mDataSource.getCardSets(); if (cardSets.contains(cardSet)) { mDataSource.deleteCardSet(cardSet); }/*from w ww. j a v a 2s. c om*/ mCardSets.remove(listItemPosition); Collections.sort(mCardSets); mArrayAdapter.notifyDataSetChanged(); } }); builder.setNegativeButton(R.string.delete_card_set_dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:com.almunt.jgcaap.systemupdater.MainActivity.java
public void RetryDownload(final String filename, String errordetails) { AlertDialog.Builder builder1 = new AlertDialog.Builder(MainActivity.this); builder1.setTitle("There was an error downloading"); builder1.setMessage("Would you like to retry the download?\n" + "Error Details:\n" + errordetails); builder1.setCancelable(true); builder1.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { progressDialog = new ProgressDialog(MainActivity.this); progressDialog.setTitle("Downloading " + filename); progressDialog.setMessage("Initializing Download..."); progressDialog.setIndeterminate(false); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.show();/*w w w . ja v a 2 s . c o m*/ Intent intent = new Intent(MainActivity.this, DownloadService.class); intent.putExtra("url", filename); intent.putExtra("receiver", new DownloadReceiver(new Handler())); startService(intent); } }); builder1.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); AlertDialog alert11 = builder1.create(); alert11.show(); }
From source file:com.kawakawaplanning.rssreader.Main.MainActivity.java
public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menuitem1: Intent intent = new Intent(); intent.setClassName("com.kawakawaplanning.rssreader", "com.kawakawaplanning.rssreader.Edit.EditActivity"); startActivity(intent);/*from w w w . j av a 2 s.com*/ finish(); break; case R.id.menuitem4: check(); break; case R.id.menuitem5: AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.opensourcelicense, (ViewGroup) findViewById(R.id.rootLayout)); setSpannableString(view); alertDialogBuilder.setTitle(""); alertDialogBuilder.setView(view); alertDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); alertDialogBuilder.setCancelable(true); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); break; } return false; }
From source file:com.otaupdater.OTAUpdaterActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Context context = getApplicationContext(); cfg = Config.getInstance(context);//from w ww .j a v a 2s . co m if (!cfg.hasProKey()) { bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), billingSrvConn = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { billingSrvConn = null; } @Override public void onServiceConnected(ComponentName name, IBinder binder) { IInAppBillingService service = IInAppBillingService.Stub.asInterface(binder); try { Bundle owned = service.getPurchases(3, getPackageName(), "inapp", null); ArrayList<String> ownedItems = owned.getStringArrayList("INAPP_PURCHASE_ITEM_LIST"); ArrayList<String> ownedItemData = owned .getStringArrayList("INAPP_PURCHASE_DATA_LIST"); if (ownedItems != null && ownedItemData != null) { for (int q = 0; q < ownedItems.size(); q++) { if (ownedItems.get(q).equals(Config.PROKEY_SKU)) { JSONObject itemData = new JSONObject(ownedItemData.get(q)); cfg.setKeyPurchaseToken(itemData.getString("purchaseToken")); break; } } } } catch (RemoteException ignored) { } catch (JSONException e) { e.printStackTrace(); } unbindService(this); billingSrvConn = null; } }, Context.BIND_AUTO_CREATE); } boolean data = Utils.dataAvailable(this); boolean wifi = Utils.wifiConnected(this); if (!data || !wifi) { final boolean nodata = !data && !wifi; if ((nodata && !cfg.getIgnoredDataWarn()) || (!nodata && !cfg.getIgnoredWifiWarn())) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(nodata ? R.string.alert_nodata_title : R.string.alert_nowifi_title); builder.setMessage(nodata ? R.string.alert_nodata_message : R.string.alert_nowifi_message); builder.setCancelable(false); builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); builder.setNeutralButton(R.string.alert_wifi_settings, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Intent i = new Intent(Settings.ACTION_WIFI_SETTINGS); startActivity(i); } }); builder.setPositiveButton(R.string.ignore, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (nodata) { cfg.setIgnoredDataWarn(true); } else { cfg.setIgnoredWifiWarn(true); } dialog.dismiss(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); } } Utils.updateDeviceRegistration(this); CheckinReceiver.setDailyAlarm(this); if (!PropUtils.isRomOtaEnabled() && !PropUtils.isKernelOtaEnabled() && !cfg.getIgnoredUnsupportedWarn()) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.alert_unsupported_title); builder.setMessage(R.string.alert_unsupported_message); builder.setCancelable(false); builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); builder.setPositiveButton(R.string.ignore, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { cfg.setIgnoredUnsupportedWarn(true); dialog.dismiss(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); } setContentView(R.layout.main); Fragment adFragment = getFragmentManager().findFragmentById(R.id.ads); if (adFragment != null) getFragmentManager().beginTransaction().hide(adFragment).commit(); ViewPager mViewPager = (ViewPager) findViewById(R.id.pager); bar = getActionBar(); assert bar != null; bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE); bar.setTitle(R.string.app_name); TabsAdapter mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bar.newTab().setText(R.string.main_about), AboutTab.class); ActionBar.Tab romTab = bar.newTab().setText(R.string.main_rom); if (cfg.hasStoredRomUpdate()) romTab.setIcon(R.drawable.ic_action_warning); romTabIdx = mTabsAdapter.addTab(romTab, ROMTab.class); ActionBar.Tab kernelTab = bar.newTab().setText(R.string.main_kernel); if (cfg.hasStoredKernelUpdate()) kernelTab.setIcon(R.drawable.ic_action_warning); kernelTabIdx = mTabsAdapter.addTab(kernelTab, KernelTab.class); if (!handleNotifAction(getIntent())) { if (cfg.hasStoredRomUpdate() && !cfg.isDownloadingRom()) { cfg.getStoredRomUpdate().showUpdateNotif(this); } if (cfg.hasStoredKernelUpdate() && !cfg.isDownloadingKernel()) { cfg.getStoredKernelUpdate().showUpdateNotif(this); } if (savedInstanceState != null) { bar.setSelectedNavigationItem(savedInstanceState.getInt(KEY_TAB, 0)); } } }
From source file:com.vv.androidreview.ui.activites.PermissionsActivity.java
private void showMissingPermissionDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(PermissionsActivity.this); builder.setTitle(R.string.help);//w w w. j av a2 s. co m builder.setMessage(R.string.string_help_text); // ?, builder.setNegativeButton(R.string.quit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setResult(PERMISSIONS_DENIED); finish(); } }); builder.setPositiveButton(R.string.settings, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startAppSettings(); } }); builder.setCancelable(false); builder.show(); }
From source file:com.flowzr.activity.BlotterFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { long accountId = blotterFilter.getAccountId(); Intent intent = null;/*from w w w . j a v a2s .c o m*/ switch (item.getItemId()) { case R.id.action_list_template: createFromTemplate(); return true; // case R.id.action_list_template: // ((MainActivity) getActivity()).loadTabFragment(new TemplatesListActivity(),R.layout.blotter, new Bundle(),MainActivity.TAB_BLOTTER); // return true; case R.id.action_mass_op: intent = new Intent(getActivity(), EntityListActivity.class); intent.putExtra(EntityListActivity.REQUEST_MASS_OP, true); blotterFilter.toIntent(intent); startActivity(intent); //((MainActivity) getActivity()).loadTabFragment(new MassOpActivity(),R.layout.blotter_mass_op, new Bundle(),MainActivity.TAB_BLOTTER); return true; case R.id.bAdd: addItem(NEW_TRANSACTION_REQUEST, TransactionActivity.class); return true; case R.id.bTransfer: addItem(NEW_TRANSFER_REQUEST, TransferActivity.class); return true; case R.id.opt_menu_month: // call credit card bill activity sending account id intent = new Intent(this.getActivity(), MonthlyViewActivity.class); intent.putExtra(MonthlyViewActivity.ACCOUNT_EXTRA, accountId); intent.putExtra(MonthlyViewActivity.BILL_PREVIEW_EXTRA, false); startActivityForResult(intent, MONTHLY_VIEW_REQUEST); return true; case R.id.action_filter: intent = new Intent(BlotterFragment.this.getActivity(), BlotterFilterActivity.class); blotterFilter.toIntent(intent); intent.putExtra(BlotterFilterActivity.IS_ACCOUNT_FILTER, isAccountBlotter && blotterFilter.getAccountId() > 0); startActivityForResult(intent, FILTER_REQUEST); return true; case R.id.opt_menu_bill: if (accountId != -1) { Account account = em.getAccount(accountId); intent = new Intent(this.getActivity(), MonthlyViewActivity.class); intent.putExtra(MonthlyViewActivity.ACCOUNT_EXTRA, accountId); // call credit card bill activity sending account id if (account.paymentDay > 0 && account.closingDay > 0) { intent.putExtra(MonthlyViewActivity.BILL_PREVIEW_EXTRA, true); startActivityForResult(intent, BILL_PREVIEW_REQUEST); return true; } else { // display message: need payment and closing day AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this.getActivity()); dlgAlert.setMessage(R.string.statement_error); dlgAlert.setTitle(R.string.ccard_statement); dlgAlert.setPositiveButton(R.string.ok, null); dlgAlert.setCancelable(true); dlgAlert.create().show(); return true; } } else { return true; } default: return super.onOptionsItemSelected(item); } }