List of usage examples for android.app ProgressDialog setCancelable
public void setCancelable(boolean flag)
From source file:edu.wpi.khufnagle.lighthousenavigator.PhotographsActivity.java
/** * Display the UI defined in activity_photographs.xml upon activity start. *//* w w w . j av a 2 s .c om*/ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.activity_photographs); /* * Add "up" button functionality in the left of application icon in * top-left corner, allowing user to return to "welcome" screen */ final ActionBar ab = this.getSupportActionBar(); ab.setDisplayHomeAsUpEnabled(true); ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); /* * Create "navigation spinner" in activity action bar that allows user to * view a different content screen */ final ArrayAdapter<CharSequence> navDropDownAdapter = ArrayAdapter.createFromResource(this, R.array.ab_content_activities_names, R.layout.ab_navigation_dropdown_item); ab.setListNavigationCallbacks(navDropDownAdapter, this); ab.setSelectedNavigationItem(ContentActivity.PHOTOGRAPHS.getABDropDownListIndex()); // Retrieve name of lighthouse that user is viewing final Bundle extras = this.getIntent().getExtras(); final String lighthouseNameSelected = extras.getString("lighthousename"); // Lighthouse data guaranteed to exist ("Welcome" activity performs data // existence validation) final LighthouseDataParser lighthouseInformationParser = new LighthouseDataParser( this.getApplicationContext(), lighthouseNameSelected); lighthouseInformationParser.parseLighthouseData(); this.currentLighthouse = lighthouseInformationParser.getLighthouse(); /* * Complete Flickr downloading task only if a network connection exists * _and_ the cache is empty or contains information about a lighthouse * other than the "desired" one */ this.userConnectedToInternet = this.networkConnectionExists(); FlickrDownloadHandler downloadHandler = null; if (this.userConnectedToInternet) { if (!this.photoCacheExists()) { if (!PhotographsActivity.downloadingThreadStarted) { Log.d("LIGHTNAVDEBUG", "Creating dialog..."); // Display dialog informing user about download progress final ProgressDialog flickrPhotoDownloadDialog = new ProgressDialog(this, ProgressDialog.STYLE_SPINNER); flickrPhotoDownloadDialog.setTitle("Downloading Flickr photos"); flickrPhotoDownloadDialog.setMessage("Downloading photographs from Flickr..."); flickrPhotoDownloadDialog.setCancelable(true); flickrPhotoDownloadDialog.show(); final HashSet<Photograph> flickrPhotos = new HashSet<Photograph>(); /* * Start background thread that will complete actual downloading * process */ PhotographsActivity.downloadingThreadStarted = true; downloadHandler = new FlickrDownloadHandler(this, this.currentLighthouse, flickrPhotos, flickrPhotoDownloadDialog); final FlickrPhotoDownloadThread downloadThread = new FlickrPhotoDownloadThread( this.getApplicationContext(), this.currentLighthouse, downloadHandler, PhotographsActivity.XML_DOWNLOAD_COMPLETE, PhotographsActivity.INTERRUPT); Log.d("LIGHTNAVDEBUG", "Flickr download XML thread started"); downloadThread.start(); /* * Interrupt (stop) currently-running thread if user cancels * downloading operation explicitly */ flickrPhotoDownloadDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface di) { if (downloadThread.isAlive()) { downloadThread.interrupt(); } else if (PhotographsActivity.this.parseOutputThread != null && PhotographsActivity.this.parseOutputThread.isAlive()) { PhotographsActivity.this.parseOutputThread.interrupt(); } else { // Do nothing } } }); } } else { final ArrayList<Photograph> lighthousePhotos = this.currentLighthouse.getAlbum() .get(ActivityVisible.PHOTOGRAPHS); lighthousePhotos.clear(); final File downloadCacheDir = new File(this.getFilesDir() + "/download-cache/"); final File[] downloadCacheDirContents = downloadCacheDir.listFiles(); for (int i = 0; i < downloadCacheDirContents.length; i++) { final String downloadCacheDirContentName = downloadCacheDirContents[i].getName(); final String[] downloadCacheDirContentPieces = downloadCacheDirContentName.split("_"); final Long photoID = Long.parseLong(downloadCacheDirContentPieces[2]); final String ownerName = downloadCacheDirContentPieces[3].replace("~", " "); final String creativeCommonsLicenseIDString = downloadCacheDirContentPieces[4].substring(0, 1); final int creativeCommonsLicenseID = Integer.parseInt(creativeCommonsLicenseIDString); final CreativeCommonsLicenseType licenseType = CreativeCommonsLicenseType .convertToLicenseEnum(creativeCommonsLicenseID); lighthousePhotos.add(new Photograph(photoID, ownerName, licenseType, "/download-cache/" + downloadCacheDirContentName)); } this.currentLighthouse.getAlbum().put(ActivityVisible.PHOTOGRAPHS, lighthousePhotos); } } if (!this.userConnectedToInternet || this.userConnectedToInternet && this.photoCacheExists() || downloadHandler != null && downloadHandler.getFlickrOperationsComplete()) { // Display first photograph as "selected" photograph in top-left corner // by default final ArrayList<Photograph> photoSet = this.currentLighthouse.getAlbum() .get(ActivityVisible.PHOTOGRAPHS); final Photograph currentPhotoOnLeftSide = photoSet.get(0); final ImageView currentPhotoView = (ImageView) this.findViewById(R.id.iv_photographs_current_image); if (this.userConnectedToInternet) { currentPhotoView.setImageDrawable(Drawable.createFromPath( PhotographsActivity.this.getFilesDir() + currentPhotoOnLeftSide.getInternalStorageLoc())); } else { currentPhotoView.setImageResource(currentPhotoOnLeftSide.getResID()); } // Add credits for "default" main photograph final TextView owner = (TextView) this.findViewById(R.id.tv_photographs_photographer); final TextView licenseType = (TextView) this.findViewById(R.id.tv_photographs_license); owner.setText("Uploaded by: " + currentPhotoOnLeftSide.getOwner()); licenseType.setText("License: " + currentPhotoOnLeftSide.getLicenseTypeAbbreviation()); /* * Display Google Map as a SupportMapFragment (instead of MapFragment * for compatibility with Android 2.x) */ /* * BIG thanks to http://www.truiton.com/2013/05/ * android-supportmapfragment-example/ for getting this part of the app * working */ final FragmentManager fm = this.getSupportFragmentManager(); final Fragment mapFragment = fm.findFragmentById(R.id.frag_photographs_map); final SupportMapFragment smf = (SupportMapFragment) mapFragment; smf.getMap(); final GoogleMap supportMap = smf.getMap(); /* * Center map at lighthouse location, at a zoom level of 12 with no * tilt, facing due north */ final LatLng lighthouseLocation = new LatLng(this.currentLighthouse.getCoordinates().getLatitude(), this.currentLighthouse.getCoordinates().getLongitude()); final float zoomLevel = 12.0f; final float tiltAngle = 0.0f; final float bearing = 0.0f; final CameraPosition cameraPos = new CameraPosition(lighthouseLocation, zoomLevel, tiltAngle, bearing); supportMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPos)); /* * Allows user to open a maps application (such as Google Maps) upon * selecting the map fragment */ /* * Courtesy of: * http://stackoverflow.com/questions/6205827/how-to-open-standard * -google-map-application-from-my-application */ supportMap.setOnMapClickListener(new OnMapClickListener() { @Override public void onMapClick(LatLng lighthouseCoordinates) { final String uri = String.format(Locale.US, "geo:%f,%f", lighthouseCoordinates.latitude, lighthouseCoordinates.longitude); final Intent googleMapsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); PhotographsActivity.this.startActivity(googleMapsIntent); } }); this.gv = (GridView) this.findViewById(R.id.gv_photographs_thumbnails); /* * Photographs in the "current lighthouse album" are from Flickr if the * album is empty or if the first (or _any_) of the elements in the * album do not have a "proper" static resource ID */ this.photosFromFlickr = this.currentLighthouse.getAlbum().get(ActivityVisible.PHOTOGRAPHS).isEmpty() || this.currentLighthouse.getAlbum().get(ActivityVisible.PHOTOGRAPHS).iterator().next() .getResID() == 0; final LighthouseImageAdapter thumbnailAdapter = new LighthouseImageAdapter(this, this.currentLighthouse.getAlbum().get(ActivityVisible.PHOTOGRAPHS), this.photosFromFlickr); this.gv.setAdapter(thumbnailAdapter); this.gv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { // Determine which photograph from the list was selected... final Photograph photoClicked = (Photograph) thumbnailAdapter.getItem(position); final int photoClickedResID = photoClicked.getResID(); // ...and change the information in the top-left corner // accordingly if (PhotographsActivity.this.userConnectedToInternet) { currentPhotoView.setImageDrawable(Drawable.createFromPath( PhotographsActivity.this.getFilesDir() + photoClicked.getInternalStorageLoc())); } else { currentPhotoView.setImageResource(photoClickedResID); } owner.setText("Uploaded by: " + photoClicked.getOwner()); licenseType.setText("License: " + photoClicked.getLicenseTypeAbbreviation()); } }); } }
From source file:fm.smart.r1.activity.ItemActivity.java
public void addToList(final String item_id) { final ProgressDialog myOtherProgressDialog = new ProgressDialog(this); myOtherProgressDialog.setTitle("Please Wait ..."); myOtherProgressDialog.setMessage("Adding item to study list ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread add = new Thread() { public void run() { ItemActivity.add_item_result = addItemToList(Main.default_study_list_id, item_id, ItemActivity.this); myOtherProgressDialog.dismiss(); ItemActivity.this.runOnUiThread(new Thread() { public void run() { final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create(); dialog.setTitle(ItemActivity.add_item_result.getTitle()); dialog.setMessage(ItemActivity.add_item_result.getMessage()); ItemActivity.add_item_result = null; dialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }/*from w ww . jav a2s. co m*/ }); dialog.show(); } }); } }; myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { add.interrupt(); } }); OnCancelListener ocl = new OnCancelListener() { public void onCancel(DialogInterface arg0) { add.interrupt(); } }; myOtherProgressDialog.setOnCancelListener(ocl); closeMenu(); myOtherProgressDialog.show(); add.start(); }
From source file:com.microsoft.live.sample.skydrive.SkyDriveActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == FilePicker.PICK_FILE_REQUEST) { if (resultCode == RESULT_OK) { String filePath = data.getStringExtra(FilePicker.EXTRA_FILE_PATH); if (TextUtils.isEmpty(filePath)) { showToast("No file was choosen."); return; }/*from w w w. j a va2 s. c om*/ File file = new File(filePath); final ProgressDialog uploadProgressDialog = new ProgressDialog(SkyDriveActivity.this); uploadProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); uploadProgressDialog.setMessage("Uploading..."); uploadProgressDialog.setCancelable(true); uploadProgressDialog.show(); final LiveOperation operation = mClient.uploadAsync(mCurrentFolderId, file.getName(), file, new LiveUploadOperationListener() { @Override public void onUploadProgress(int totalBytes, int bytesRemaining, LiveOperation operation) { int percentCompleted = computePrecentCompleted(totalBytes, bytesRemaining); uploadProgressDialog.setProgress(percentCompleted); } @Override public void onUploadFailed(LiveOperationException exception, LiveOperation operation) { uploadProgressDialog.dismiss(); showToast(exception.getMessage()); } @Override public void onUploadCompleted(LiveOperation operation) { uploadProgressDialog.dismiss(); JSONObject result = operation.getResult(); if (result.has(JsonKeys.ERROR)) { JSONObject error = result.optJSONObject(JsonKeys.ERROR); String message = error.optString(JsonKeys.MESSAGE); String code = error.optString(JsonKeys.CODE); showToast(code + ": " + message); return; } loadFolder(mCurrentFolderId); } }); uploadProgressDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { operation.cancel(); } }); } } }
From source file:bikebadger.RideFragment.java
public void SaveGPXFileOnNewThreadWithDialog(final String path) { final ProgressDialog pd = new ProgressDialog(getActivity()); pd.setProgressStyle(ProgressDialog.STYLE_SPINNER); final File gpxFile = new File(path); pd.setMessage("Saving \"" + gpxFile.getName() + "\""); pd.setIndeterminate(true);//from w w w. j a v a 2 s. c o m pd.setCancelable(false); pd.show(); Thread mThread = new Thread() { @Override public void run() { mRideManager.ExportWaypointsTrack(); pd.dismiss(); if (mRideManager.mWaypoints != null) { getActivity().runOnUiThread(new Runnable() { public void run() { //Toast.makeText(getActivity(), "Hello", Toast.LENGTH_SHORT).show(); MyToast.Show(getActivity(), "\"" + gpxFile.getName() + "\" saved", Color.BLACK); } }); } } }; mThread.start(); }
From source file:bikebadger.RideFragment.java
public void OpenGPXFileOnNewThreadWithDialog(final String path) { final ProgressDialog pd = new ProgressDialog(getActivity()); pd.setProgressStyle(ProgressDialog.STYLE_SPINNER); final File gpxFile = new File(path); pd.setMessage("Loading \"" + gpxFile.getName() + "\""); pd.setIndeterminate(true);/*from ww w .j a va2 s . c om*/ pd.setCancelable(false); pd.show(); Thread mThread = new Thread() { @Override public void run() { mRideManager.OpenGPXFile(path); pd.dismiss(); if (mRideManager.mWaypoints != null) { getActivity().runOnUiThread(new Runnable() { public void run() { //Toast.makeText(getActivity(), "Hello", Toast.LENGTH_SHORT).show(); MyToast.Show(getActivity(), "\"" + gpxFile.getName() + "\" loaded (" + mRideManager.mWaypoints.size() + ")", Color.BLACK); } }); } } }; mThread.start(); }
From source file:com.yeldi.yeldibazaar.AppDetails.java
private ProgressDialog createProgressDialog(String file, int p, int max) { final ProgressDialog pd = new ProgressDialog(this); pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); pd.setMessage(getString(R.string.download_server) + ":\n " + file); pd.setMax(max);// w ww . ja v a 2 s.com pd.setProgress(p); pd.setCancelable(true); pd.setCanceledOnTouchOutside(false); pd.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { downloadHandler.cancel(); } }); pd.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { pd.cancel(); } }); pd.show(); return pd; }
From source file:com.microsoft.live.sample.skydrive.SkyDriveActivity.java
@Override protected Dialog onCreateDialog(final int id, final Bundle bundle) { Dialog dialog = null;// w w w .java2s . c o m switch (id) { case DIALOG_DOWNLOAD_ID: { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Download").setMessage("This file will be downloaded to the sdcard.") .setPositiveButton("OK", new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final ProgressDialog progressDialog = new ProgressDialog(SkyDriveActivity.this); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setMessage("Downloading..."); progressDialog.setCancelable(true); progressDialog.show(); String fileId = bundle.getString(JsonKeys.ID); String name = bundle.getString(JsonKeys.NAME); File file = new File(Environment.getExternalStorageDirectory(), name); final LiveDownloadOperation operation = mClient.downloadAsync(fileId + "/content", file, new LiveDownloadOperationListener() { @Override public void onDownloadProgress(int totalBytes, int bytesRemaining, LiveDownloadOperation operation) { int percentCompleted = computePrecentCompleted(totalBytes, bytesRemaining); progressDialog.setProgress(percentCompleted); } @Override public void onDownloadFailed(LiveOperationException exception, LiveDownloadOperation operation) { progressDialog.dismiss(); showToast(exception.getMessage()); } @Override public void onDownloadCompleted(LiveDownloadOperation operation) { progressDialog.dismiss(); showToast("File downloaded."); } }); progressDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { operation.cancel(); } }); } }).setNegativeButton("Cancel", new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); dialog = builder.create(); break; } } if (dialog != null) { dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { removeDialog(id); } }); } return dialog; }
From source file:fm.smart.r1.ItemActivity.java
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); // this should be called once image has been chosen by user // using requestCode to pass item id - haven't worked out any other way // to do it//w ww.j av a2 s . c o m // if (requestCode == SELECT_IMAGE) if (resultCode == Activity.RESULT_OK) { // TODO check if user is logged in if (LoginActivity.isNotLoggedIn(this)) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(this, LoginActivity.class.getName()); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // avoid navigation back to this? LoginActivity.return_to = ItemActivity.class.getName(); LoginActivity.params = new HashMap<String, String>(); LoginActivity.params.put("item_id", (String) item.getId()); startActivity(intent); // TODO in this case forcing the user to rechoose the image // seems a little // rude - should probably auto-submit here ... } else { // Bundle extras = data.getExtras(); // String sentence_id = (String) extras.get("sentence_id"); final ProgressDialog myOtherProgressDialog = new ProgressDialog(this); myOtherProgressDialog.setTitle("Please Wait ..."); myOtherProgressDialog.setMessage("Uploading image ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread add_image = new Thread() { public void run() { // TODO needs to check for interruptibility String sentence_id = Integer.toString(requestCode); Uri selectedImage = data.getData(); // Bitmap bitmap = Media.getBitmap(getContentResolver(), // selectedImage); // ByteArrayOutputStream bytes = new // ByteArrayOutputStream(); // bitmap.compress(Bitmap.CompressFormat.JPEG, 40, // bytes); // ByteArrayInputStream fileInputStream = new // ByteArrayInputStream( // bytes.toByteArray()); // TODO Might have to save to file system first to get // this // to work, // argh! // could think of it as saving to cache ... // add image to sentence FileInputStream is = null; FileOutputStream os = null; File file = null; ContentResolver resolver = getContentResolver(); try { Bitmap bitmap = Media.getBitmap(getContentResolver(), selectedImage); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes); // ByteArrayInputStream bais = new // ByteArrayInputStream(bytes.toByteArray()); // FileDescriptor fd = // resolver.openFileDescriptor(selectedImage, // "r").getFileDescriptor(); // is = new FileInputStream(fd); String filename = "test.jpg"; File dir = ItemActivity.this.getDir("images", MODE_WORLD_READABLE); file = new File(dir, filename); os = new FileOutputStream(file); // while (bais.available() > 0) { // / os.write(bais.read()); // } os.write(bytes.toByteArray()); os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (os != null) { try { os.close(); } catch (IOException e) { } } if (is != null) { try { is.close(); } catch (IOException e) { } } } // File file = new // File(Uri.decode(selectedImage.toString())); // ensure item is in users default list ItemActivity.add_item_result = new AddItemResult(Main.lookup.addItemToGoal(Main.transport, Main.default_study_goal_id, item.getId(), null)); Result result = ItemActivity.add_item_result; if (ItemActivity.add_item_result.success() || ItemActivity.add_item_result.alreadyInList()) { // ensure sentence is in users default goal ItemActivity.add_sentence_goal_result = new AddSentenceResult( Main.lookup.addSentenceToGoal(Main.transport, Main.default_study_goal_id, item.getId(), sentence_id, null)); result = ItemActivity.add_sentence_goal_result; if (ItemActivity.add_sentence_goal_result.success()) { String media_entity = "http://test.com/test.jpg"; String author = "tansaku"; String author_url = "http://smart.fm/users/tansaku"; Log.d("DEBUG-IMAGE-URI", selectedImage.toString()); ItemActivity.add_image_result = addImage(file, media_entity, author, author_url, "1", sentence_id, (String) item.getId(), Main.default_study_goal_id); result = ItemActivity.add_image_result; } } final Result display = result; myOtherProgressDialog.dismiss(); ItemActivity.this.runOnUiThread(new Thread() { public void run() { final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create(); dialog.setTitle(display.getTitle()); dialog.setMessage(display.getMessage()); dialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (ItemActivity.add_image_result != null && ItemActivity.add_image_result.success()) { ItemListActivity.loadItem(ItemActivity.this, item.getId().toString()); } } }); dialog.show(); } }); } }; myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { add_image.interrupt(); } }); OnCancelListener ocl = new OnCancelListener() { public void onCancel(DialogInterface arg0) { add_image.interrupt(); } }; myOtherProgressDialog.setOnCancelListener(ocl); closeMenu(); myOtherProgressDialog.show(); add_image.start(); } } }
From source file:com.doplgangr.secrecy.views.FilesListFragment.java
void changePassphrase() { final View dialogView = View.inflate(context, R.layout.change_passphrase, null); new AlertDialog.Builder(context).setTitle(getString(R.string.Vault__change_password)).setView(dialogView) .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String oldPassphrase = ((EditText) dialogView.findViewById(R.id.oldPassphrase)).getText() .toString(); String newPassphrase = ((EditText) dialogView.findViewById(R.id.newPassphrase)).getText() .toString(); String confirmNewPassphrase = ((EditText) dialogView.findViewById(R.id.confirmPassphrase)) .getText().toString(); ProgressDialog progressDialog = new ProgressDialog(context); progressDialog.setMessage(CustomApp.context.getString(R.string.Vault__changing_password)); progressDialog.setIndeterminate(true); progressDialog.setCancelable(false); progressDialog.show(); changePassphraseInBackground(oldPassphrase, newPassphrase, confirmNewPassphrase, progressDialog); }// ww w . j a va2 s . co m }).setNegativeButton(R.string.CANCEL, Util.emptyClickListener).show(); }
From source file:com.cellbots.logger.LoggerActivity.java
@Override protected Dialog onCreateDialog(int id) { if (id != PROGRESS_ID) { return super.onCreateDialog(id); }//from ww w .j av a 2 s . com final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setCancelable(false); // The setMessage call must be in both onCreateDialog and // onPrepareDialog otherwise it will // fail to update the dialog in onPrepareDialog. progressDialog.setMessage("Processing..."); return progressDialog; }