List of usage examples for android.content DialogInterface cancel
void cancel();
From source file:com.dwdesign.tweetings.fragment.BaseStatusesListFragment.java
protected void translate(final ParcelableStatus status) { ThreadPolicy tp = ThreadPolicy.LAX; StrictMode.setThreadPolicy(tp);// w ww. ja v a 2 s . c om 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.brandroidtools.filemanager.activities.PickerActivity.java
/** * Method that displays a dialog with a {@link NavigationFragment} to select the * proposed file// w ww .j a va 2 s . c o m */ private void init() { final boolean pickingDirectory; final Intent intent = getIntent(); if (isFilePickIntent(intent)) { // ok Log.d(TAG, "PickerActivity: got file pick intent: " + String.valueOf(intent)); //$NON-NLS-1$ pickingDirectory = false; } else if (isDirectoryPickIntent(getIntent())) { // ok Log.d(TAG, "PickerActivity: got folder pick intent: " + String.valueOf(intent)); //$NON-NLS-1$ pickingDirectory = true; } else { Log.d(TAG, "PickerActivity got unrecognized intent: " + String.valueOf(intent)); //$NON-NLS-1$ setResult(Activity.RESULT_CANCELED); finish(); return; } // Display restrictions Map<DisplayRestrictions, Object> restrictions = new HashMap<DisplayRestrictions, Object>(); //- Mime/Type restriction String mimeType = getIntent().getType(); if (mimeType != null) { if (!MimeTypeHelper.isMimeTypeKnown(this, mimeType)) { Log.i(TAG, String.format("Mime type %s unknown, falling back to wildcard.", //$NON-NLS-1$ mimeType)); mimeType = MimeTypeHelper.ALL_MIME_TYPES; } restrictions.put(DisplayRestrictions.MIME_TYPE_RESTRICTION, mimeType); } // Other restrictions Bundle extras = getIntent().getExtras(); Log.d(TAG, "PickerActivity. extras: " + String.valueOf(extras)); //$NON-NLS-1$ if (extras != null) { //-- File size if (extras.containsKey(android.provider.MediaStore.Audio.Media.EXTRA_MAX_BYTES)) { long size = extras.getLong(android.provider.MediaStore.Audio.Media.EXTRA_MAX_BYTES); restrictions.put(DisplayRestrictions.SIZE_RESTRICTION, Long.valueOf(size)); } //-- Local filesystems only if (extras.containsKey(Intent.EXTRA_LOCAL_ONLY)) { boolean localOnly = extras.getBoolean(Intent.EXTRA_LOCAL_ONLY); restrictions.put(DisplayRestrictions.LOCAL_FILESYSTEM_ONLY_RESTRICTION, Boolean.valueOf(localOnly)); } } if (pickingDirectory) { restrictions.put(DisplayRestrictions.DIRECTORY_ONLY_RESTRICTION, Boolean.TRUE); } // Create or use the console if (!initializeConsole()) { // Something when wrong. Display a message and exit DialogHelper.showToast(this, R.string.msgs_cant_create_console, Toast.LENGTH_SHORT); cancel(); return; } // Create the root file this.mRootView = getLayoutInflater().inflate(R.layout.picker, null, false); this.mRootView.post(new Runnable() { @Override public void run() { measureHeight(); } }); // Breadcrumb Breadcrumb breadcrumb = (Breadcrumb) this.mRootView.findViewById(R.id.breadcrumb_view); // Set the free disk space warning level of the breadcrumb widget String fds = Preferences.getSharedPreferences().getString( FileManagerSettings.SETTINGS_DISK_USAGE_WARNING_LEVEL.getId(), (String) FileManagerSettings.SETTINGS_DISK_USAGE_WARNING_LEVEL.getDefaultValue()); breadcrumb.setFreeDiskSpaceWarningLevel(Integer.parseInt(fds)); // Navigation view this.mNavigationFragment = (NavigationFragment) getSupportFragmentManager() .findFragmentById(R.id.navigation_fragment); this.mNavigationFragment.setRestrictions(restrictions); this.mNavigationFragment.setOnFilePickedListener(this); this.mNavigationFragment.setOnDirectoryChangedListener(this); this.mNavigationFragment.setBreadcrumb(breadcrumb); // Apply the current theme applyTheme(); // Create the dialog this.mDialog = DialogHelper.createDialog(this, R.drawable.ic_launcher, pickingDirectory ? R.string.directory_picker_title : R.string.picker_title, this.mRootView); this.mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dlg, int which) { dlg.cancel(); } }); if (pickingDirectory) { this.mDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.select), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dlg, int which) { PickerActivity.this.mFso = PickerActivity.this.mCurrentDirectory; dlg.dismiss(); } }); } this.mDialog.setCancelable(true); this.mDialog.setOnCancelListener(this); this.mDialog.setOnDismissListener(this); DialogHelper.delegateDialogShow(this, this.mDialog); // Set content description of storage volume button ButtonItem fs = (ButtonItem) this.mRootView.findViewById(R.id.ab_filesystem_info); fs.setContentDescription(getString(R.string.actionbar_button_storage_cd)); final File initialDir = getInitialDirectoryFromIntent(getIntent()); final String rootDirectory; if (initialDir != null) { rootDirectory = initialDir.getAbsolutePath(); } else { rootDirectory = FileHelper.ROOT_DIRECTORY; } this.mHandler = new Handler(); this.mHandler.post(new Runnable() { @Override public void run() { // Navigate to. The navigation view will redirect to the appropriate directory PickerActivity.this.mNavigationFragment.changeCurrentDir(rootDirectory); } }); }
From source file:com.duy.pascal.ui.editor.EditorActivity.java
public void insertColor() { ColorPickerDialogBuilder.with(this) .setPositiveButton(getString(R.string.select), new ColorPickerClickListener() { @Override//from w ww.jav a 2 s.c om public void onClick(DialogInterface d, int lastSelectedColor, Integer[] allColors) { EditorFragment currentFragment = mPagerAdapter.getCurrentFragment(); if (currentFragment != null) { currentFragment.insert(String.valueOf(lastSelectedColor)); Toast.makeText(EditorActivity.this, getString(R.string.inserted_color) + lastSelectedColor, Toast.LENGTH_SHORT) .show(); } } }).setNegativeButton(R.string.close, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).build().show(); }
From source file:com.speed.traquer.app.Feedback_rate_taxi.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK)) { if (actv_comp_taxi.length() != 0 || inputTaxi.length() != 0) { final AlertDialog.Builder alertBox = new AlertDialog.Builder(Feedback_rate_taxi.this); alertBox.setIcon(R.drawable.info_icon); alertBox.setCancelable(false); alertBox.setTitle("Do you want to cancel feedback?"); alertBox.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { // finish used for destroyed activity easyTracker.send(MapBuilder.createEvent("Feedback taxi", "Cancel Feedback taxi (Yes)", "Feedback taxi event", null).build()); finish();//w w w . ja v a2s . co m Intent intent = new Intent(Feedback_rate_taxi.this, Speedometer.class); Feedback_rate_taxi.this.startActivity(intent); } }); alertBox.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { easyTracker.send(MapBuilder.createEvent("Feedback taxi", "Cancel Feedback taxi (No)", "Feedback taxi event", null).build()); dialog.cancel(); } }); alertBox.show(); } else { NavUtils.navigateUpFromSameTask(this); return true; } } return super.onKeyDown(keyCode, event); }
From source file:com.example.dany.jjdraw.MainActivity.java
@Override public void onClick(View view) { if (view.getId() == R.id.draw_btn) { final Dialog brushDialog = new Dialog(this); brushDialog.setTitle("Brush size"); brushDialog.setContentView(R.layout.brush_chooser); ImageButton smallBtn = (ImageButton) brushDialog.findViewById(R.id.small_brush); smallBtn.setOnClickListener(new OnClickListener() { @Override//from w w w . j a v a 2s .c o m public void onClick(View v) { drawView.setBrushSize(smallBrush); drawView.setLastBrushSize(smallBrush); drawView.setErase(false); brushDialog.dismiss(); } }); ImageButton mediumBtn = (ImageButton) brushDialog.findViewById(R.id.medium_brush); mediumBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { drawView.setBrushSize(mediumBrush); drawView.setLastBrushSize(mediumBrush); drawView.setErase(false); brushDialog.dismiss(); } }); ImageButton largeBtn = (ImageButton) brushDialog.findViewById(R.id.large_brush); largeBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { drawView.setBrushSize(largeBrush); drawView.setLastBrushSize(largeBrush); drawView.setErase(false); brushDialog.dismiss(); } }); brushDialog.show(); } else if (view.getId() == R.id.erase_btn) { //switch to erase - choose size final Dialog brushDialog = new Dialog(this); brushDialog.setTitle("Eraser size"); brushDialog.setContentView(R.layout.brush_chooser); ImageButton smallBtn = (ImageButton) brushDialog.findViewById(R.id.small_brush); smallBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { drawView.setErase(true); drawView.setBrushSize(smallBrush); brushDialog.dismiss(); } }); ImageButton mediumBtn = (ImageButton) brushDialog.findViewById(R.id.medium_brush); mediumBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { drawView.setErase(true); drawView.setBrushSize(mediumBrush); brushDialog.dismiss(); } }); ImageButton largeBtn = (ImageButton) brushDialog.findViewById(R.id.large_brush); largeBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { drawView.setErase(true); drawView.setBrushSize(largeBrush); brushDialog.dismiss(); } }); brushDialog.show(); } else if (view.getId() == R.id.new_btn) { //new button AlertDialog.Builder newDialog = new AlertDialog.Builder(this); newDialog.setTitle("New drawing"); newDialog.setMessage("Start new drawing (you will lose the current drawing)?"); newDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { drawView.startNew(null); dialog.dismiss(); } }); newDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); newDialog.show(); } else if (view.getId() == R.id.save_btn) { //save drawing AlertDialog.Builder saveDialog = new AlertDialog.Builder(this); saveDialog.setTitle("Save drawing"); saveDialog.setMessage("Save drawing to device Gallery?"); saveDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //save drawing drawView.setDrawingCacheEnabled(true); String imgSaved = MediaStore.Images.Media.insertImage(MainActivity.this.getContentResolver(), drawView.getDrawingCache(), UUID.randomUUID().toString() + ".png", "drawing"); if (imgSaved != null) { Toast savedToast = Toast.makeText(getApplicationContext(), "Drawing saved to Gallery!", Toast.LENGTH_SHORT); savedToast.show(); } else { for (int i = 0; i < 3; i++) { // tried to increase the duration Toast unsavedToast = Toast.makeText(getApplicationContext(), "Oops! Image could not be saved. " + "Explicit write permission to storage device may required." + "Check Settings->" + "Application Manager->" + "JJDraw->" + "Permissions.", Toast.LENGTH_LONG); unsavedToast.show(); } } drawView.destroyDrawingCache(); } }); saveDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); saveDialog.show(); } }
From source file:cc.echonet.coolmicapp.MainActivity.java
@Override public void onBackPressed() { // Write your code here if (isThreadOn) { AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this); alertDialog.setTitle("Stop Broadcasting?"); alertDialog.setMessage("Tap [ Ok ] to stop broadcasting."); alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { backyes = false;//from w w w .j a v a2s. c om dialog.cancel(); } }); alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { backyes = true; dialog.cancel(); invalidateOptionsMenu(); start_button.clearAnimation(); start_button.setBackground(buttonColor); start_button.setText(R.string.start_broadcast); ClearLED(); android.os.Process.killProcess(android.os.Process.myPid()); } }); alertDialog.show(); } else { android.os.Process.killProcess(android.os.Process.myPid()); } }
From source file:com.safecell.LoginActivity.java
public void quitDialog(Context context, String title, String message) { boolean flag = false; new AlertDialog.Builder(context).setMessage(message).setTitle(title) .setNeutralButton("Quit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel();/*from w w w .jav a 2 s . co m*/ LoginActivity.this.finish(); } }).show(); }
From source file:com.honeycomb.cocos2dx.Soccer.java
public void quitGame(JSONObject prms) { AlertDialog.Builder exitbuilder = new AlertDialog.Builder(this); exitbuilder.setTitle("Girl Superhero").setMessage(com.honeycomb.cocos2dx.R.string.QUIT_MESSAGE) .setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { AndroidNDKHelper.SendMessageWithParameters("resetListener", getDict()); }//from w w w.j a va2 s. co m }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog stopalert = exitbuilder.create(); stopalert.show(); }
From source file:com.safecell.LoginActivity.java
private void quitDialog(String title, String message) { new AlertDialog.Builder(context).setMessage(message).setTitle(title) .setNeutralButton("Quit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); finish();/*from ww w. ja v a 2s . c om*/ } }).show(); }
From source file:br.com.GUI.perfil.PerfilAluno.java
public void tirarFoto() { AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity()); alertDialog.setTitle("Selecione o mtodo"); alertDialog.setMessage("Deseja usar qual aplicativo para importar sua foto?"); alertDialog.setIcon(R.drawable.profile); alertDialog.setPositiveButton("Camera", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { usarCamera();/* www . ja v a 2s . co m*/ } }); alertDialog.setNegativeButton("Galeria", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { usarGaleria(); dialog.cancel(); } }); alertDialog.show(); }