List of usage examples for android.app ProgressDialog show
public void show()
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 . j a va2s. c om } 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(); } } }
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//ww w.ja v a 2 s. 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(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.microsoft.onedrive.apiexplorer.ItemFragment.java
/** * Copies an item onto the current destination in the copy preferences * @param item The item to copy/*from w w w. j a va 2 s . c om*/ */ private void copy(final Item item) { final BaseApplication app = (BaseApplication) getActivity().getApplication(); final IOneDriveClient oneDriveClient = app.getOneDriveClient(); final ItemReference parentReference = new ItemReference(); parentReference.id = getCopyPrefs().getString(COPY_DESTINATION_PREF_KEY, null); final ProgressDialog dialog = new ProgressDialog(getActivity(), ProgressDialog.STYLE_HORIZONTAL); dialog.setTitle("Copying item"); dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); dialog.setMessage("Waiting for copy to complete"); final IProgressCallback<Item> progressCallback = new IProgressCallback<Item>() { @Override public void progress(final long current, final long max) { dialog.setMax((int) current); dialog.setMax((int) max); } @Override public void success(final Item item) { dialog.dismiss(); final String string = getString(R.string.copy_success_message, item.name, item.parentReference.path); Toast.makeText(getActivity(), string, Toast.LENGTH_LONG).show(); } @Override public void failure(final ClientException error) { dialog.dismiss(); new AlertDialog.Builder(getActivity()).setTitle(R.string.error_title).setMessage(error.getMessage()) .setNegativeButton(R.string.close, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { dialog.dismiss(); } }).create().show(); } }; final DefaultCallback<AsyncMonitor<Item>> callback = new DefaultCallback<AsyncMonitor<Item>>( getActivity()) { @Override public void success(final AsyncMonitor<Item> itemAsyncMonitor) { final int millisBetweenPoll = 1000; itemAsyncMonitor.pollForResult(millisBetweenPoll, progressCallback); } }; oneDriveClient.getDrive().getItems(item.id).getCopy(item.name, parentReference).buildRequest() .create(callback); dialog.show(); }
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 w w . ja v a 2 s. co 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.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 www . j a v a 2 s. co m } 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 (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 = CreateExampleActivity.class.getName(); LoginActivity.params = new HashMap<String, String>(); LoginActivity.params.put("goal_id", goal_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_goal_result = new AddItemResult( Main.lookup.addItemToGoal(Main.transport, goal_id, item_id, null)); Result result = null; try { result = Main.lookup.createExample(Main.transport, translation, translation_language_code, translation, null, null, null); JSONObject json = new JSONObject(result.http_response); String text = json.getString("text"); String translation_id = json.getString("id"); result = Main.lookup.createExample(Main.transport, example, example_language_code, example_transliteration, translation_id, item_id, goal_id); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } CreateExampleActivity.create_example_result = new CreateExampleResult(result); } 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(); } } }
From source file:cm.aptoide.pt.MainActivity.java
private void dialogAddStore(final String url, final String username, final String password) { final ProgressDialog pd = new ProgressDialog(mContext); pd.setMessage(getString(R.string.please_wait)); pd.show(); new Thread(new Runnable() { @Override//from w w w. j a v a2 s.c om public void run() { try { addStore(url, username, password); } catch (Exception e) { e.printStackTrace(); } finally { runOnUiThread(new Runnable() { @Override public void run() { if (pd.isShowing()) { pd.dismiss(); } refreshAvailableList(true); } }); } } }).start(); }
From source file:nf.frex.android.FrexActivity.java
private void setWallpaper() { final WallpaperManager wallpaperManager = WallpaperManager.getInstance(FrexActivity.this); final int desiredWidth = wallpaperManager.getDesiredMinimumWidth(); final int desiredHeight = wallpaperManager.getDesiredMinimumHeight(); final Image image = view.getImage(); final int imageWidth = image.getWidth(); final int imageHeight = image.getHeight(); final boolean useDesiredSize = desiredWidth > imageWidth || desiredHeight > imageHeight; DialogInterface.OnClickListener noListener = new DialogInterface.OnClickListener() { @Override//from ww w .j a va2 s. c o m public void onClick(DialogInterface dialog, int which) { // ok } }; if (useDesiredSize) { showYesNoDialog(this, R.string.set_wallpaper, getString(R.string.wallpaper_compute_msg, desiredWidth, desiredHeight), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final Image wallpaperImage; try { wallpaperImage = new Image(desiredWidth, desiredHeight); } catch (OutOfMemoryError e) { alert(getString(R.string.out_of_memory)); return; } final ProgressDialog progressDialog = new ProgressDialog(FrexActivity.this); Generator.ProgressListener progressListener = new Generator.ProgressListener() { int numLines; @Override public void onStarted(int numTasks) { } @Override public void onSomeLinesComputed(int taskId, int line1, int line2) { numLines += 1 + line2 - line1; progressDialog.setProgress(numLines); } @Override public void onStopped(boolean cancelled) { progressDialog.dismiss(); if (!cancelled) { setWallpaper(wallpaperManager, wallpaperImage); } } }; final Generator wallpaperGenerator = new Generator(view.getGeneratorConfig(), SettingsActivity.NUM_CORES, progressListener); DialogInterface.OnCancelListener cancelListener = new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (progressDialog.isShowing()) { progressDialog.dismiss(); } wallpaperGenerator.cancel(); } }; progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setCancelable(true); progressDialog.setMax(desiredHeight); progressDialog.setOnCancelListener(cancelListener); progressDialog.show(); Arrays.fill(wallpaperImage.getValues(), FractalView.MISSING_VALUE); wallpaperGenerator.start(wallpaperImage, false); } }, noListener, null); } else { showYesNoDialog(this, R.string.set_wallpaper, getString(R.string.wallpaper_replace_msg), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setWallpaper(wallpaperManager, image); } }, noListener, null); } }
From source file:com.piusvelte.sonet.core.SonetNotifications.java
@Override public boolean onContextItemSelected(final MenuItem item) { if (item.getItemId() == CLEAR) { final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() { @Override//from w ww .j av a 2 s. com protected Void doInBackground(Void... arg0) { // clear all notifications ContentValues values = new ContentValues(); values.put(Notifications.CLEARED, 1); SonetNotifications.this.getContentResolver().update( Notifications.getContentUri(SonetNotifications.this), values, Notifications._ID + "=?", new String[] { Long.toString(((AdapterContextMenuInfo) item.getMenuInfo()).id) }); return null; } @Override protected void onPostExecute(Void result) { if (loadingDialog.isShowing()) { loadingDialog.dismiss(); } SonetNotifications.this.finish(); } }; 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(); } return super.onContextItemSelected(item); // clear }
From source file:fm.smart.r1.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 ww .j av a 2 s. c om 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 (LoginActivity.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("goal_id", goal_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", item_id, id, to_record); // this will also ensure item is in goal, but this // should be sentence // submission if we are handling sentence sound. if (sound_type.equals(Integer.toString(R.id.cue_sound))) { CreateSoundActivity.add_item_result = new AddItemResult( Main.lookup.addItemToGoal(Main.transport, Main.default_study_goal_id, item_id, CreateSoundActivity.create_sound_result.sound_id)); } else { // ensure item is in goal CreateSoundActivity.add_item_result = new AddItemResult(Main.lookup .addItemToGoal(Main.transport, Main.default_study_goal_id, item_id, null)); CreateSoundActivity.add_sentence_result = new AddSentenceResult( Main.lookup.addSentenceToGoal(Main.transport, Main.default_study_goal_id, item_id, id, CreateSoundActivity.create_sound_result.sound_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:cm.aptoide.pt.MainActivity.java
@Override public boolean onContextItemSelected(final MenuItem item) { final ProgressDialog pd; switch (item.getItemId()) { case 0://from w ww .j ava 2s . co m pd = new ProgressDialog(mContext); pd.setMessage(getString(R.string.please_wait)); pd.show(); pd.setCancelable(false); new Thread(new Runnable() { private boolean result = false; @Override public void run() { try { result = service.deleteStore(db, ((AdapterContextMenuInfo) item.getMenuInfo()).id); } catch (Exception e) { e.printStackTrace(); } finally { runOnUiThread(new Runnable() { @Override public void run() { pd.dismiss(); if (result) { refreshAvailableList(false); installedLoader.forceLoad(); updatesLoader.forceLoad(); } else { Toast toast = Toast.makeText(mContext, mContext.getString(R.string.error_delete_store), Toast.LENGTH_SHORT); toast.show(); } } }); } } }).start(); break; case 1: pd = new ProgressDialog(mContext); pd.setMessage(getString(R.string.please_wait)); pd.show(); pd.setCancelable(false); new Thread(new Runnable() { @Override public void run() { try { service.parseServer(db, db.getServer(((AdapterContextMenuInfo) item.getMenuInfo()).id, false)); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { runOnUiThread(new Runnable() { @Override public void run() { pd.dismiss(); refreshAvailableList(false); } }); } } }).start(); break; } return super.onContextItemSelected(item); }