List of usage examples for android.app ProgressDialog setProgressStyle
public void setProgressStyle(int style)
From source file:id.ridon.keude.AppDetailsData.java
private ProgressDialog getProgressDialog(String file) { if (progressDialog == null) { final ProgressDialog pd = new ProgressDialog(this); pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); pd.setMessage(getString(R.string.download_server) + ":\n " + file); pd.setCancelable(true);//from w w w .j ava 2 s .co m pd.setCanceledOnTouchOutside(false); // The indeterminate-ness will get overridden on the first progress event we receive. pd.setIndeterminate(true); pd.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { Log.d(TAG, "User clicked 'cancel' on download, attempting to interrupt download thread."); if (downloadHandler != null) { downloadHandler.cancel(); cleanUpFinishedDownload(); } else { Log.e(TAG, "Tried to cancel, but the downloadHandler doesn't exist."); } progressDialog = null; Toast.makeText(AppDetails.this, getString(R.string.download_cancelled), Toast.LENGTH_LONG) .show(); } }); pd.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { pd.cancel(); } }); progressDialog = pd; } return progressDialog; }
From source file:org.odk.collect.android.activities.GoogleDriveActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case PROGRESS_DIALOG: Collect.getInstance().getActivityLogger().logAction(this, "onCreateDialog.PROGRESS_DIALOG", "show"); ProgressDialog progressDialog = new ProgressDialog(this); DialogInterface.OnClickListener loadingButtonListener = new DialogInterface.OnClickListener() { @Override/* w w w.j av a2 s. c om*/ public void onClick(DialogInterface dialog, int which) { Collect.getInstance().getActivityLogger().logAction(this, "onCreateDialog.PROGRESS_DIALOG", "cancel"); dialog.dismiss(); getFileTask.cancel(true); getFileTask.setGoogleDriveFormDownloadListener(null); } }; progressDialog.setTitle(getString(R.string.downloading_data)); progressDialog.setMessage(alertMsg); progressDialog.setIndeterminate(true); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setCancelable(false); progressDialog.setButton(getString(R.string.cancel), loadingButtonListener); return progressDialog; case GOOGLE_USER_DIALOG: AlertDialog.Builder gudBuilder = new AlertDialog.Builder(this); gudBuilder.setTitle(getString(R.string.no_google_account)); gudBuilder.setMessage(getString(R.string.google_set_account)); gudBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); gudBuilder.setCancelable(false); return gudBuilder.create(); } return null; }
From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java
private void sendRegistrationRequest(final String email) { final ProgressDialog progressDialog = new ProgressDialog(RegistrationActivity2.this); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setMessage(getString(R.string.registration_sending_email, email)); progressDialog.setCancelable(true);/*from w ww . j a va2 s . c om*/ progressDialog.show(); final SafeRunnable showErrorDialog = new SafeRunnable() { @Override protected void safeRun() throws Exception { T.UI(); progressDialog.dismiss(); AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this); builder.setMessage(R.string.error_please_try_again); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); } }; final String timestamp = "" + mWiz.getTimestamp(); final String registrationId = mWiz.getRegistrationId(); final String deviceId = mWiz.getDeviceId(); mWorkerHandler.post(new SafeRunnable() { @Override protected void safeRun() throws Exception { T.REGISTRATION(); String version = "2"; String requestSignature = Security.sha256(version + email + " " + timestamp + " " + deviceId + " " + registrationId + " " + CloudConstants.REGISTRATION_EMAIL_SIGNATURE); HttpPost httppost = new HttpPost(CloudConstants.REGISTRATION_REQUEST_URL); try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6); nameValuePairs.add(new BasicNameValuePair("version", version)); nameValuePairs.add(new BasicNameValuePair("email", email)); nameValuePairs.add(new BasicNameValuePair("registration_time", timestamp)); nameValuePairs.add(new BasicNameValuePair("device_id", deviceId)); nameValuePairs.add(new BasicNameValuePair("registration_id", registrationId)); nameValuePairs.add(new BasicNameValuePair("request_signature", requestSignature)); nameValuePairs.add(new BasicNameValuePair("install_id", mWiz.getInstallationId())); nameValuePairs.add(new BasicNameValuePair("request_id", UUID.randomUUID().toString())); nameValuePairs.add(new BasicNameValuePair("language", Locale.getDefault().getLanguage())); nameValuePairs.add(new BasicNameValuePair("country", Locale.getDefault().getCountry())); nameValuePairs.add(new BasicNameValuePair("app_id", CloudConstants.APP_ID)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = mHttpClient.execute(httppost); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 200) { mUIHandler.post(new SafeRunnable() { @Override protected void safeRun() throws Exception { T.UI(); mWiz.setEmail(email); mWiz.save(); progressDialog.dismiss(); mWiz.proceedToNextPage(); showNotification(); } }); } else if (statusCode == 502) { final HttpEntity entity = response.getEntity(); mUIHandler.post(new SafeRunnable() { @Override protected void safeRun() throws Exception { T.UI(); progressDialog.dismiss(); AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this); boolean stringSet = false; if (entity != null) { @SuppressWarnings("unchecked") final Map<String, Object> responseMap = (Map<String, Object>) org.json.simple.JSONValue .parse(new InputStreamReader(entity.getContent())); if (responseMap != null) { String result = (String) responseMap.get("result"); if (result != null) { builder.setMessage(result); stringSet = true; } } } if (!stringSet) { builder.setMessage(R.string.registration_email_not_valid); } builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); } }); } else { mUIHandler.post(showErrorDialog); } } catch (ClientProtocolException e) { L.d(e); mUIHandler.post(showErrorDialog); } catch (IOException e) { L.d(e); mUIHandler.post(showErrorDialog); } } }); }
From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java
private void registerWithAccessToken(final String accessToken) { final String timestamp = "" + mWiz.getTimestamp(); final String deviceId = mWiz.getDeviceId(); final String registrationId = mWiz.getRegistrationId(); final String installId = mWiz.getInstallationId(); // Make call to Rogerthat webfarm final ProgressDialog progressDialog = new ProgressDialog(RegistrationActivity2.this); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog/*from www. j a v a 2 s . c o m*/ .setMessage(getString(R.string.registration_activating_account, getString(R.string.app_name))); progressDialog.setCancelable(false); progressDialog.show(); final SafeRunnable showErrorDialog = new SafeRunnable() { @Override protected void safeRun() throws Exception { T.UI(); progressDialog.dismiss(); AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this); builder.setMessage(R.string.registration_facebook_error); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); } }; mWorkerHandler.post(new SafeRunnable() { @Override protected void safeRun() throws Exception { T.REGISTRATION(); String version = "1"; String signature = Security.sha256(version + " " + installId + " " + timestamp + " " + deviceId + " " + registrationId + " " + accessToken + CloudConstants.REGISTRATION_MAIN_SIGNATURE); HttpPost httppost = new HttpPost(CloudConstants.REGISTRATION_FACEBOOK_URL); try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(8); nameValuePairs.add(new BasicNameValuePair("version", version)); nameValuePairs.add(new BasicNameValuePair("registration_time", timestamp)); nameValuePairs.add(new BasicNameValuePair("device_id", deviceId)); nameValuePairs.add(new BasicNameValuePair("registration_id", registrationId)); nameValuePairs.add(new BasicNameValuePair("signature", signature)); nameValuePairs.add(new BasicNameValuePair("install_id", installId)); nameValuePairs.add(new BasicNameValuePair("access_token", accessToken)); nameValuePairs.add(new BasicNameValuePair("language", Locale.getDefault().getLanguage())); nameValuePairs.add(new BasicNameValuePair("country", Locale.getDefault().getCountry())); nameValuePairs.add(new BasicNameValuePair("app_id", CloudConstants.APP_ID)); nameValuePairs.add( new BasicNameValuePair("use_xmpp_kick", CloudConstants.USE_XMPP_KICK_CHANNEL + "")); nameValuePairs.add(new BasicNameValuePair("GCM_registration_id", mGCMRegistrationId)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = mHttpClient.execute(httppost); int statusCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); if (entity == null) { mUIHandler.post(showErrorDialog); return; } @SuppressWarnings("unchecked") final Map<String, Object> responseMap = (Map<String, Object>) JSONValue .parse(new InputStreamReader(entity.getContent())); if (statusCode != 200 || responseMap == null) { if (statusCode == 500 && responseMap != null) { final String errorMessage = (String) responseMap.get("error"); if (errorMessage != null) { mUIHandler.post(new SafeRunnable() { @Override protected void safeRun() throws Exception { T.UI(); progressDialog.dismiss(); AlertDialog.Builder builder = new AlertDialog.Builder( RegistrationActivity2.this); builder.setMessage(errorMessage); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); } }); return; } } mUIHandler.post(showErrorDialog); return; } JSONObject account = (JSONObject) responseMap.get("account"); final String email = (String) responseMap.get("email"); mAgeAndGenderSet = (Boolean) responseMap.get("age_and_gender_set"); final RegistrationInfo info = new RegistrationInfo(email, new Credentials((String) account.get("account"), (String) account.get("password"))); mUIHandler.post(new SafeRunnable() { @Override protected void safeRun() throws Exception { T.UI(); mWiz.setEmail(email); mWiz.save(); hideNotification(); tryConnect(progressDialog, 1, getString(R.string.registration_establish_connection, email, getString(R.string.app_name)) + " ", info); } }); } catch (Exception e) { L.d(e); mUIHandler.post(showErrorDialog); } } }); }
From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java
private void onPinEntered() { final String pin = mEnterPinEditText.getText().toString(); // Validate pin code if (!RegexPatterns.PIN.matcher(pin).matches()) { AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this); builder.setMessage(R.string.registration_invalid_pin); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show();/* w w w . ja va 2 s . c om*/ return; } // Make call to Rogerthat webfarm final ProgressDialog progressDialog = new ProgressDialog(RegistrationActivity2.this); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog .setMessage(getString(R.string.registration_activating_account, getString(R.string.app_name))); progressDialog.setCancelable(false); progressDialog.show(); final SafeRunnable showErrorDialog = new SafeRunnable() { @Override protected void safeRun() throws Exception { T.UI(); progressDialog.dismiss(); AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this); builder.setMessage(R.string.registration_sending_pin_error); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); } }; final String email = mWiz.getEmail(); final String timestamp = "" + mWiz.getTimestamp(); final String registrationId = mWiz.getRegistrationId(); final String deviceId = mWiz.getDeviceId(); mWorkerHandler.post(new SafeRunnable() { @Override protected void safeRun() throws Exception { T.REGISTRATION(); String version = "2"; String pinSignature = Security.sha256(version + " " + email + " " + timestamp + " " + deviceId + " " + registrationId + " " + pin + CloudConstants.REGISTRATION_PIN_SIGNATURE); HttpPost httppost = new HttpPost(CloudConstants.REGISTRATION_PIN_URL); try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6); nameValuePairs.add(new BasicNameValuePair("version", version)); nameValuePairs.add(new BasicNameValuePair("email", email)); nameValuePairs.add(new BasicNameValuePair("registration_time", timestamp)); nameValuePairs.add(new BasicNameValuePair("device_id", deviceId)); nameValuePairs.add(new BasicNameValuePair("registration_id", registrationId)); nameValuePairs.add(new BasicNameValuePair("pin_code", pin)); nameValuePairs.add(new BasicNameValuePair("pin_signature", pinSignature)); nameValuePairs.add(new BasicNameValuePair("request_id", UUID.randomUUID().toString())); nameValuePairs.add(new BasicNameValuePair("app_id", CloudConstants.APP_ID)); nameValuePairs.add( new BasicNameValuePair("use_xmpp_kick", CloudConstants.USE_XMPP_KICK_CHANNEL + "")); nameValuePairs.add(new BasicNameValuePair("GCM_registration_id", mGCMRegistrationId)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = mHttpClient.execute(httppost); int statusCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); if (statusCode != 200 || entity == null) { mUIHandler.post(showErrorDialog); return; } @SuppressWarnings("unchecked") final Map<String, Object> responseMap = (Map<String, Object>) org.json.simple.JSONValue .parse(new InputStreamReader(entity.getContent())); if ("success".equals(responseMap.get("result"))) { JSONObject account = (JSONObject) responseMap.get("account"); final RegistrationInfo info = new RegistrationInfo(email, new Credentials((String) account.get("account"), (String) account.get("password"))); mAgeAndGenderSet = (Boolean) responseMap.get("age_and_gender_set"); mUIHandler.post(new SafeRunnable() { @Override protected void safeRun() throws Exception { T.UI(); hideNotification(); tryConnect(progressDialog, 1, getString(R.string.registration_establish_connection, email, getString(R.string.app_name)) + " ", info); } }); } else { final long attempts_left = (Long) responseMap.get("attempts_left"); mUIHandler.post(new SafeRunnable() { @Override protected void safeRun() throws Exception { T.UI(); progressDialog.dismiss(); if (attempts_left > 0) { AlertDialog.Builder builder = new AlertDialog.Builder( RegistrationActivity2.this); builder.setMessage(getString(R.string.registration_incorrect_pin, email)); builder.setTitle(getString(R.string.registration_incorrect_pin_dialog_title)); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); mEnterPinEditText.setText(""); } else { hideNotification(); new AlertDialog.Builder(RegistrationActivity2.this) .setMessage(getString(R.string.registration_no_attempts_left)) .setCancelable(true).setPositiveButton(R.string.try_again, null) .create().show(); mWiz.reInit(); mWiz.goBackToPrevious(); return; } } }); } } catch (Exception e) { L.d(e); mUIHandler.post(showErrorDialog); } } }); }
From source file:com.xperia64.timidityae.TimidityActivity.java
public void saveWavPart2(final String finalval, final String needToRename) { Intent new_intent = new Intent(); new_intent.setAction(getResources().getString(R.string.msrv_rec)); new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 15); new_intent.putExtra(getResources().getString(R.string.msrv_outfile), finalval); sendBroadcast(new_intent); final ProgressDialog prog; prog = new ProgressDialog(TimidityActivity.this); prog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { @Override/*from w w w. java2s .c o m*/ public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); prog.setTitle("Converting to WAV"); prog.setMessage("Converting..."); prog.setIndeterminate(false); prog.setCancelable(false); prog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); prog.show(); new Thread(new Runnable() { @Override public void run() { while (!localfinished && prog.isShowing()) { prog.setMax(JNIHandler.maxTime); prog.setProgress(JNIHandler.currTime); try { Thread.sleep(25); } catch (InterruptedException e) { } } if (!localfinished) { JNIHandler.stop(); TimidityActivity.this.runOnUiThread(new Runnable() { public void run() { Toast.makeText(TimidityActivity.this, "Conversion canceled", Toast.LENGTH_SHORT).show(); if (!Globals.keepWav) { if (new File(finalval).exists()) new File(finalval).delete(); } else { fileFrag.getDir(fileFrag.currPath); } } }); } else { TimidityActivity.this.runOnUiThread(new Runnable() { public void run() { String trueName = finalval; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null && needToRename != null) { if (Globals.renameDocumentFile(TimidityActivity.this, finalval, needToRename)) { trueName = needToRename; } else { trueName = "Error"; } } Toast.makeText(TimidityActivity.this, "Wrote " + trueName, Toast.LENGTH_SHORT).show(); prog.dismiss(); fileFrag.getDir(fileFrag.currPath); } }); } } }).start(); }
From source file:ac.robinson.mediaphone.MediaPhoneActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case R.id.dialog_importing_in_progress: ProgressDialog importDialog = new ProgressDialog(MediaPhoneActivity.this); importDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); importDialog.setMessage(getString(R.string.import_progress)); importDialog.setCancelable(false); mImportFramesProgressDialog = importDialog; mImportFramesDialogShown = true; return importDialog; case R.id.dialog_export_narrative_in_progress: ProgressDialog exportDialog = new ProgressDialog(MediaPhoneActivity.this); exportDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); exportDialog.setMessage(getString(R.string.background_task_progress)); exportDialog.setCancelable(false); exportDialog.setIndeterminate(true); mExportNarrativeDialogShown = true; return exportDialog; case R.id.dialog_mov_creator_in_progress: ProgressDialog movDialog = new ProgressDialog(MediaPhoneActivity.this); movDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); movDialog.setMessage(getString(R.string.mov_export_task_progress)); movDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.mov_export_run_in_background), new DialogInterface.OnClickListener() { @Override/*from w w w .j a v a 2 s . co m*/ public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); mExportVideoDialogShown = false; } }); movDialog.setCancelable(false); movDialog.setIndeterminate(true); mExportVideoDialogShown = true; return movDialog; case R.id.dialog_background_runner_in_progress: ProgressDialog runnerDialog = new ProgressDialog(MediaPhoneActivity.this); runnerDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); runnerDialog.setMessage(getString(R.string.background_task_progress)); runnerDialog.setCancelable(false); runnerDialog.setIndeterminate(true); mBackgroundRunnerDialogShown = true; return runnerDialog; default: return super.onCreateDialog(id); } }
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 a v a 2s . c om*/ } 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: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// w w w .j av a 2 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:net.nightwhistler.pageturner.fragment.ReadingFragment.java
public void performSearch(String query) { LOG.debug("Starting search for: " + query); final ProgressDialog searchProgress = new ProgressDialog(context); searchProgress.setOwnerActivity(getActivity()); searchProgress.setCancelable(true);// w w w.ja v a 2 s .c o m searchProgress.setMax(100); searchProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); final int[] counter = { 0 }; //Yes, this is essentially a pointer to an int :P final SearchTextTask task = new SearchTextTask(bookView.getBook()); task.setOnPreExecute(() -> { searchProgress.setMessage(getString(R.string.search_wait)); searchProgress.show(); // Hide on-screen keyboard if it is showing InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); }); task.setOnProgressUpdate((values) -> { if (isAdded()) { LOG.debug("Found match at index=" + values[0].getIndex() + ", offset=" + values[0].getStart() + " with context " + values[0].getDisplay()); SearchResult res = values[0]; if (res.getDisplay() != null) { counter[0] = counter[0] + 1; String update = String.format(getString(R.string.search_hits), counter[0]); searchProgress.setMessage(update); } searchProgress.setProgress(bookView.getPercentageFor(res.getIndex(), res.getStart())); } }); task.setOnCancelled((result) -> { if (isAdded()) { Toast.makeText(context, R.string.search_cancelled, Toast.LENGTH_LONG).show(); } }); task.setOnPostExecute((result) -> { searchProgress.dismiss(); if (!task.isCancelled() && isAdded()) { List<SearchResult> resultList = result.getOrElse(new ArrayList<>()); if (resultList.size() > 0) { searchResults = resultList; showSearchResultDialog(resultList); } else { Toast.makeText(context, R.string.search_no_matches, Toast.LENGTH_LONG).show(); } } }); searchProgress.setOnCancelListener(dialog -> task.cancel(true)); executeTask(task, query); }