List of usage examples for android.app ProgressDialog setOnCancelListener
public void setOnCancelListener(@Nullable OnCancelListener listener)
From source file:fm.smart.r1.activity.CreateSoundActivity.java
public void onClick(View v) { String threegpfile_name = "test.3gp_amr"; String amrfile_name = "test.amr"; File dir = this.getDir("sounds", MODE_WORLD_READABLE); final File threegpfile = new File(dir, threegpfile_name); File amrfile = new File(dir, amrfile_name); String path = threegpfile.getAbsolutePath(); Log.d("CreateSoundActivity", path); Log.d("CreateSoundActivity", (String) button.getText()); if (button.getText().equals("Start")) { try {//from w w w .j a v a2 s . c o m recorder = new MediaRecorder(); // ContentValues values = new ContentValues(3); // // values.put(MediaStore.MediaColumns.TITLE, "test"); // values.put(MediaStore.MediaColumns.DATE_ADDED, // System.currentTimeMillis()); // values.put(MediaStore.MediaColumns.MIME_TYPE, // MediaRecorder.OutputFormat.THREE_GPP); // // ContentResolver contentResolver = new ContentResolver(this); // // Uri base = MediaStore.Audio.INTERNAL_CONTENT_URI; // Uri newUri = contentResolver.insert(base, values); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(path); recorder.prepare(); button.setText("Stop"); recorder.start(); } catch (Exception e) { Log.w(TAG, e); } } else { FileOutputStream os = null; FileInputStream is = null; try { recorder.stop(); recorder.release(); // Now the object cannot be reused button.setEnabled(false); // ThreegpReader tr = new ThreegpReader(threegpfile); // os = new FileOutputStream(amrfile); // tr.extractAmr(os); is = new FileInputStream(threegpfile); playSound(is.getFD()); final String media_entity = "http://test.com/test.mp3"; final String author = "tansaku"; final String author_url = "http://smart.fm/users/tansaku"; if (Main.isNotLoggedIn(this)) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(this, LoginActivity.class.getName()); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); LoginActivity.return_to = CreateSoundActivity.class.getName(); LoginActivity.params = new HashMap<String, String>(); LoginActivity.params.put("item_id", item_id); LoginActivity.params.put("list_id", list_id); LoginActivity.params.put("id", id); LoginActivity.params.put("to_record", to_record); LoginActivity.params.put("sound_type", sound_type); startActivity(intent); } else { final ProgressDialog myOtherProgressDialog = new ProgressDialog(this); myOtherProgressDialog.setTitle("Please Wait ..."); myOtherProgressDialog.setMessage("Creating Sound ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread create_sound = new Thread() { public void run() { // TODO make this interruptable .../*if // (!this.isInterrupted())*/ CreateSoundActivity.create_sound_result = createSound(threegpfile, media_entity, author, author_url, "1", id); myOtherProgressDialog.dismiss(); } }; myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { create_sound.interrupt(); } }); OnCancelListener ocl = new OnCancelListener() { public void onCancel(DialogInterface arg0) { create_sound.interrupt(); } }; myOtherProgressDialog.setOnCancelListener(ocl); myOtherProgressDialog.show(); create_sound.start(); } } catch (Exception e) { Log.w(TAG, e); } finally { if (os != null) { try { os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (is != null) { try { is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }
From source file:com.owncloud.android.authentication.AuthenticatorActivity.java
/** * {@inheritDoc}//ww w . j av a 2s . co m */ @Override protected Dialog onCreateDialog(int id) { Dialog dialog = null; switch (id) { case DIALOG_LOGIN_PROGRESS: { // / simple progress dialog ProgressDialog working_dialog = new ProgressDialog(this); working_dialog.setMessage(getResources().getString(R.string.auth_trying_to_login)); working_dialog.setIndeterminate(true); working_dialog.setCancelable(true); working_dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { // / TODO study if this is enough Log_OC.i(TAG, "Login canceled"); if (mOperationThread != null) { mOperationThread.interrupt(); finish(); } } }); dialog = working_dialog; break; } case DIALOG_OAUTH2_LOGIN_PROGRESS: { ProgressDialog working_dialog = new ProgressDialog(this); working_dialog.setMessage(String.format("Getting authorization")); working_dialog.setIndeterminate(true); working_dialog.setCancelable(true); working_dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { Log_OC.i(TAG, "Login canceled"); finish(); } }); dialog = working_dialog; break; } case DIALOG_SSL_VALIDATOR: { // / TODO start to use new dialog interface, at least for this (it // is a FragmentDialog already) dialog = SslValidatorDialog.newInstance(this, mLastSslUntrustedServerResult, this); break; } case DIALOG_CERT_NOT_SAVED: { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved)); builder.setCancelable(false); builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); }; }); dialog = builder.create(); break; } default: Log_OC.e(TAG, "Incorrect dialog called with id = " + id); } return dialog; }
From source file:com.juick.android.UserCenterActivity.java
private void enableJAM(final Runnable then) { if (!MainActivity.isJAMServiceRunning(UserCenterActivity.this)) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCancelable(true);// ww w .jav a 2 s .c om builder.setMessage(R.string.JAMNotEnabledEnable); builder.setTitle(getString(R.string.JuickAdvancedFunctionality)); builder.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(UserCenterActivity.this); sp.edit().putBoolean("enableJAMessaging", true).commit(); MainActivity.toggleJAMessaging(UserCenterActivity.this, true); final ProgressDialog pd = new ProgressDialog(UserCenterActivity.this); dialog.cancel(); pd.setIndeterminate(true); pd.setMessage(getString(R.string.WaitingForService)); final Thread thread = new Thread() { @Override public void run() { while (true) { try { JAMService instance = JAMService.instance; if (instance != null) { JAXMPPClient client = instance.client; if (client != null && client.loggedIn) { runOnUiThread(new Runnable() { @Override public void run() { pd.cancel(); then.run(); } }); } } Thread.sleep(500); } catch (InterruptedException e) { break; } } super.run(); //To change body of overridden methods use File | Settings | File Templates. } }; thread.start(); pd.setCancelable(true); pd.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { thread.interrupt(); } }); pd.show(); } }); builder.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); builder.show(); } else { then.run(); } return; }
From source file:edu.wpi.khufnagle.lighthousenavigator.PhotographsActivity.java
/** * Display the UI defined in activity_photographs.xml upon activity start. *//* w w w . j ava 2 s.co m*/ @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:nf.frex.android.FrexActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode != Activity.RESULT_OK) { return;//from w w w . j av a 2s . c o m } if (requestCode == R.id.manage_fractals && data.getAction().equals(Intent.ACTION_VIEW)) { final Uri imageUri = data.getData(); if (imageUri != null) { File imageFile = new File(imageUri.getPath()); String configName = FrexIO.getFilenameWithoutExt(imageFile); File paramFile = new File(imageFile.getParent(), configName + FrexIO.PARAM_FILE_EXT); try { FileInputStream fis = new FileInputStream(paramFile); try { readFrexDoc(fis, configName); } finally { fis.close(); } } catch (IOException e) { Toast.makeText(FrexActivity.this, getString(R.string.error_msg, e.getLocalizedMessage()), Toast.LENGTH_SHORT).show(); } } } else if (requestCode == R.id.settings) { view.getGenerator().setNumTasks(SettingsActivity.getNumTasks(this)); } else if (requestCode == SELECT_PICTURE_REQUEST_CODE) { final Uri imageUri = data.getData(); final ColorQuantizer colorQuantizer = new ColorQuantizer(); final ProgressDialog progressDialog = new ProgressDialog(FrexActivity.this); final DialogInterface.OnCancelListener cancelListener = new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (progressDialog.isShowing()) { progressDialog.dismiss(); } colorQuantizer.cancel(); } }; final ColorQuantizer.ProgressListener progressListener = new ColorQuantizer.ProgressListener() { @Override public void progress(final String msg, final int iter, final int maxIter) { runOnUiThread(new Runnable() { @Override public void run() { progressDialog.setMessage(msg); progressDialog.setProgress(iter); } }); } }; progressDialog.setTitle(getString(R.string.get_pal_from_img_title)); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setCancelable(true); progressDialog.setOnCancelListener(cancelListener); progressDialog.setMax(colorQuantizer.getMaxIterCount()); progressDialog.show(); Thread thread = new Thread(new Runnable() { @Override public void run() { Bitmap bitmap; try { bitmap = FrexIO.readBitmap(getContentResolver(), imageUri, 256); } catch (IOException e) { alert("I/O error: " + e.getLocalizedMessage()); return; } ColorScheme colorScheme = colorQuantizer.quantize(bitmap, progressListener); progressDialog.dismiss(); if (colorScheme != null) { Log.d(TAG, "SELECT_PICTURE_REQUEST_CODE: Got colorScheme"); String colorSchemeId = "$" + imageUri.toString(); colorSchemes.add(colorSchemeId, colorScheme); view.setColorSchemeId(colorSchemeId); view.setColorScheme(colorScheme); view.recomputeColors(); runOnUiThread(new Runnable() { @Override public void run() { Log.d(TAG, "SELECT_PICTURE_REQUEST_CODE: showDialog(R.id.colors)"); showDialog(R.id.colors); } }); } } }); thread.start(); } }
From source file:com.piusvelte.sonet.core.SonetCreatePost.java
protected void getPhoto(Uri uri) { final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Uri, Void, String> asyncTask = new AsyncTask<Uri, Void, String>() { @Override// w w w . j a v a 2 s . com protected String doInBackground(Uri... imgUri) { String[] projection = new String[] { MediaStore.Images.Media.DATA }; String path = null; Cursor c = getContentResolver().query(imgUri[0], projection, null, null, null); if ((c != null) && c.moveToFirst()) { path = c.getString(c.getColumnIndex(projection[0])); } else { // some file manages send the path through the uri path = imgUri[0].getPath(); } c.close(); return path; } @Override protected void onPostExecute(String path) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (path != null) setPhoto(path); else (Toast.makeText(SonetCreatePost.this, "error retrieving the photo path", Toast.LENGTH_LONG)) .show(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); loadingDialog.show(); asyncTask.execute(uri); }
From source file:com.shafiq.myfeedle.core.MyfeedleCreatePost.java
protected void getPhoto(Uri uri) { final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Uri, Void, String> asyncTask = new AsyncTask<Uri, Void, String>() { @Override//from w ww . ja v a2s . c o m protected String doInBackground(Uri... imgUri) { String[] projection = new String[] { MediaStore.Images.Media.DATA }; String path = null; Cursor c = getContentResolver().query(imgUri[0], projection, null, null, null); if ((c != null) && c.moveToFirst()) { path = c.getString(c.getColumnIndex(projection[0])); } else { // some file manages send the path through the uri path = imgUri[0].getPath(); } c.close(); return path; } @Override protected void onPostExecute(String path) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (path != null) setPhoto(path); else (Toast.makeText(MyfeedleCreatePost.this, "error retrieving the photo path", Toast.LENGTH_LONG)) .show(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); loadingDialog.show(); asyncTask.execute(uri); }
From source file:fm.smart.r1.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 goal ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread add = new Thread() { public void run() { ItemActivity.add_item_result = new AddItemResult( Main.lookup.addItemToGoal(Main.transport, Main.default_study_goal_id, item_id, null)); 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 w w . j ava 2s .c o 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: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 w w . jav a2 s .c o 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:fm.smart.r1.activity.CreateExampleActivity.java
public void onClick(View v) { EditText exampleInput = (EditText) findViewById(R.id.create_example_sentence); EditText translationInput = (EditText) findViewById(R.id.create_example_translation); EditText exampleTransliterationInput = (EditText) findViewById(R.id.sentence_transliteration); EditText translationTransliterationInput = (EditText) findViewById(R.id.translation_transliteration); final String example = exampleInput.getText().toString(); final String translation = translationInput.getText().toString(); if (TextUtils.isEmpty(example) || TextUtils.isEmpty(translation)) { Toast t = Toast.makeText(this, "Example and translation are required fields", 150); t.setGravity(Gravity.CENTER, 0, 0); t.show();/*from w w w .jav a 2 s .com*/ } else { final String example_language_code = Utils.LANGUAGE_MAP.get(example_language); final String translation_language_code = Utils.LANGUAGE_MAP.get(translation_language); final String example_transliteration = exampleTransliterationInput.getText().toString(); final String translation_transliteration = translationTransliterationInput.getText().toString(); if (Main.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 = CreateExampleActivity.class.getName(); LoginActivity.params = new HashMap<String, String>(); LoginActivity.params.put("list_id", list_id); LoginActivity.params.put("item_id", item_id); LoginActivity.params.put("example", example); LoginActivity.params.put("translation", translation); LoginActivity.params.put("example_language", example_language); LoginActivity.params.put("translation_language", translation_language); LoginActivity.params.put("example_transliteration", example_transliteration); LoginActivity.params.put("translation_transliteration", translation_transliteration); startActivity(intent); } else { final ProgressDialog myOtherProgressDialog = new ProgressDialog(this); myOtherProgressDialog.setTitle("Please Wait ..."); myOtherProgressDialog.setMessage("Creating Example ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread create_example = new Thread() { public void run() { // TODO make this interruptable .../*if // (!this.isInterrupted())*/ try { // TODO failures here could derail all ... CreateExampleActivity.add_item_list_result = ItemActivity.addItemToList(list_id, item_id, CreateExampleActivity.this); CreateExampleActivity.create_example_result = createExample(example, example_language_code, example_transliteration, translation, translation_language_code, translation_transliteration, item_id, list_id); CreateExampleActivity.add_sentence_list_result = ItemActivity.addSentenceToList( CreateExampleActivity.create_example_result.http_response, item_id, list_id, CreateExampleActivity.this); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } myOtherProgressDialog.dismiss(); } }; myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { create_example.interrupt(); } }); OnCancelListener ocl = new OnCancelListener() { public void onCancel(DialogInterface arg0) { create_example.interrupt(); } }; myOtherProgressDialog.setOnCancelListener(ocl); myOtherProgressDialog.show(); create_example.start(); } } }