下面列出了android.app.ProgressDialog#setButton ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void detectLocation() {
if (WidgetRefreshIconService.isRotationActive) {
return;
}
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setMessage(getString(R.string.progressDialog_gps_locate));
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.setIndeterminate(true);
mProgressDialog.setCancelable(false);
mProgressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
dialog.dismiss();
} catch (SecurityException e) {
appendLog(MainActivity.this, TAG, "Cancellation error", e);
}
}
});
updateNetworkLocation();
mProgressDialog.show();
refreshDialogHandler = new Handler(Looper.getMainLooper());
}
public QueryPlayTask(Context context) {
this.context = context;
progressDialog = new ProgressDialog(context);
progressDialog.setIndeterminate(true);
progressDialog.setMessage(getString(R.string.loading));
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
cancel(true);
}
});
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
cancel(true);
}
});
}
protected void onPreExecute() {
pd = new ProgressDialog(mFragment.getActivity());
pd.setCancelable(false);
pd.setIndeterminate(false);
if (mShouldMove) {
pd.setTitle(R.string.move);
pd.setMessage(mContext.getResources().getString(R.string.moving_file));
} else {
pd.setTitle(R.string.copy);
pd.setMessage(mContext.getResources().getString(R.string.copying_file));
}
pd.setButton(DialogInterface.BUTTON_NEUTRAL, mContext.getResources().getString(R.string.run_in_background),
(arg0, arg1) -> pd.dismiss());
pd.show();
}
FeedbackSenderTask(Feedback feedback) {
this.feedback = feedback;
alertDialog = new ProgressDialog(mActivity);
alertDialog.setTitle(mWaitDialogTitle);
alertDialog.setMessage(mWaitDialogMessage);
alertDialog.setIndeterminate(false);
alertDialog.setCancelable(false);
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.setMax(100);
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, mWaitDialogCancelButtonText,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
FeedbackSenderTask.this.cancel();
}
});
alertDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
alertDialog.show();
}
});
this.properties = new HashMap<>();
this.tags = new ArrayList<>();
}
private void showDialog() {
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage(getString(R.string.rotate_the_device));
mProgressDialog.setCancelable(false);
mProgressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (mTaskId != -1) {
SimpleTask task = (SimpleTask) TaskExecutor.getInstance().getTask(mTaskId);
if (task != null) {
task.cancel();
}
}
}
});
mProgressDialog.show();
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
ProgressDialog progressDialog = new ProgressDialog(getActivity());
progressDialog.setMessage(getString(R.string.rotate_the_device));
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(false);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (mTaskId != -1) {
SimpleTask task = (SimpleTask) TaskExecutor.getInstance().getTask(mTaskId);
if (task != null) {
task.cancel();
}
}
}
});
return progressDialog;
}
/**
* {@inheritDoc}
*/
@Override
protected void onPreExecute() {
shareCopyDialog = new ProgressDialog(activity);
shareCopyDialog
.setMessage("Preparing internal GeoPackage for sharing");
shareCopyDialog.setCancelable(false);
shareCopyDialog.setIndeterminate(true);
shareCopyDialog.setButton(ProgressDialog.BUTTON_NEGATIVE,
"Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
cancel(true);
}
});
shareCopyDialog.show();
}
/**
* pre execute - show dialog
*/
@Override
protected void onPreExecute() {
saveDialog = new ProgressDialog(activity);
saveDialog
.setMessage("Saving GeoPackage to Downloads");
saveDialog.setCancelable(false);
saveDialog.setIndeterminate(true);
saveDialog.setButton(ProgressDialog.BUTTON_NEGATIVE,
"Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
cancel(true);
}
});
saveDialog.show();
}
public UploadFile(Context context, DropboxAPI<?> api, String dropboxPath,
File file) {
// We set the context this way so we don't accidentally leak activities
mContext = context.getApplicationContext();
mFileLen = file.length();
mApi = api;
mPath = dropboxPath;
mFile = file;
mDialog = new ProgressDialog(context);
mDialog.setMax(100);
mDialog.setMessage("Uploading " + file.getName());
mDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mDialog.setProgress(0);
mDialog.setButton("Cancel", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// This will cancel the putFile operation
mRequest.abort();
}
});
mDialog.show();
}
/**
* Shows a progress dialog for the given job.
*
* @param job to track progress from
*/
private void showProgressDialog(Job job) {
// create a progress dialog to show download progress
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Generate Offline Map Job");
progressDialog.setMessage("Taking map offline...");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setIndeterminate(false);
progressDialog.setProgress(0);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", (dialog, which) -> job.cancel());
progressDialog.show();
// show the job's progress with the progress dialog
job.addProgressChangedListener(() -> progressDialog.setProgress(job.getProgress()));
// dismiss dialog when job is done
job.addJobDoneListener(progressDialog::dismiss);
}
@PhonkMethod(description = "Starts recording", example = "")
@PhonkMethodParam(params = {"showProgressBoolean"})
public PAudioRecorder record(String fileName) {
init();
recorder.setOutputFile(getAppRunner().getProject().getFullPathForFile(fileName));
try {
recorder.prepare();
} catch (Exception e) {
e.printStackTrace();
}
if (showProgress && getActivity() != null) {
mProgressDialog = new ProgressDialog(getActivity());
mProgressDialog.setTitle("Record!");
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Stop recording",
(dialog, whichButton) -> {
mProgressDialog.dismiss();
stop();
});
mProgressDialog.setOnCancelListener(p1 -> stop());
mProgressDialog.show();
}
recorder.start();
return this;
}
@Override
protected void onCreateContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setContentView(R.layout.fragment_download_test, container);
ButterKnife.bind(this, getContentView());
progressDialog = new ProgressDialog(getActivity());
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "cancel", (dialog, which) -> {
if (downloadTask != null) {
downloadTask.cancel();
}
dialog.dismiss();
});
etUrl.setText("https://pkg1.zhimg.com/zhihu/futureve-app-zhihuwap-ca40fb89fbd4fb3a3884429e1c897fe2-release-6.23.0(1778).apk");
}
private void detectLocation() {
boolean isGPSEnabled = locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)
&& locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean isNetworkEnabled = locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)
&& locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setMessage(getString(R.string.progressDialog_gps_locate));
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.setIndeterminate(true);
mProgressDialog.setCancelable(false);
mProgressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
locationManager.removeUpdates(mLocationListener);
} catch (SecurityException e) {
Log.e(TAG, "Cancellation error", e);
}
}
});
if (isNetworkEnabled) {
networkRequestLocation();
mProgressDialog.show();
} else {
if (isGPSEnabled) {
gpsRequestLocation();
mProgressDialog.show();
} else {
showSettingsAlert();
}
}
}
@Override
public void onSendPostStart(boolean progressMode) {
progressDialog = new ProgressDialog(this);
progressDialog.setCancelable(true);
progressDialog.setCanceledOnTouchOutside(false);
if (progressMode) {
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setProgressNumberFormat("%1$d / %2$d KB");
}
progressDialog.setOnCancelListener(sendPostCancelListener);
progressDialog.setButton(ProgressDialog.BUTTON_POSITIVE, getString(R.string.action_minimize),
sendPostMinimizeListener);
onSendPostChangeProgressState(progressMode, SendPostTask.ProgressState.CONNECTING, -1, -1);
progressDialog.show();
}
/**
* Load tiles
*
* @param activity
* @param callback
* @param active
* @param geoPackage
* @param tableName
* @param tileGenerator
*/
private static void loadTiles(Activity activity, ILoadTilesTask callback,
GeoPackageDatabases active, GeoPackage geoPackage, String tableName, TileGenerator tileGenerator) {
ProgressDialog progressDialog = new ProgressDialog(activity);
final LoadTilesTask loadTilesTask = new LoadTilesTask(activity,
callback, progressDialog, active);
tileGenerator.setProgress(loadTilesTask);
loadTilesTask.setTileGenerator(tileGenerator);
progressDialog.setMessage(activity
.getString(R.string.geopackage_create_tiles_label)
+ ": "
+ geoPackage.getName() + " - " + tableName);
progressDialog.setCancelable(false);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setIndeterminate(false);
progressDialog.setMax(tileGenerator.getTileCount());
progressDialog.setButton(ProgressDialog.BUTTON_NEGATIVE,
activity.getString(R.string.button_cancel_label),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
loadTilesTask.cancel(true);
}
});
loadTilesTask.execute();
}
protected void onPreExecute() {
if (overrideFile)
outputFile.delete();
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdir();
}
if (!URL.endsWith("/"))
URL = URL + "/";
if (!URL.startsWith("http://")
&& !URL.startsWith("https://"))
URL = "http://" + URL;
if (!hide) {
downloadDialog = new ProgressDialog(mContext);
downloadDialog.setTitle(mContext.getResources().getString(R.string.connecting));
downloadDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
downloadDialog.setCancelable(false);
downloadDialog.setMessage(URL);
if (cancelable)
downloadDialog.setButton(DialogInterface.BUTTON_NEGATIVE, mContext.getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
thisDownloader.cancel(false);
if (outputFile.exists())
outputFile.delete();
}
});
downloadDialog.show();
}
}
/**
* Show progress UI elements.
*
* @param exportTileCacheJob used to track progress and cancel when required
*/
private void createProgressDialog(ExportTileCacheJob exportTileCacheJob) {
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Export Tile Cache Job");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel",
(dialogInterface, i) -> exportTileCacheJob.cancel());
progressDialog.show();
exportTileCacheJob.addProgressChangedListener(() -> progressDialog.setProgress(exportTileCacheJob.getProgress()));
exportTileCacheJob.addJobDoneListener(progressDialog::dismiss);
}
@NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);
// create a dialog to show progress
final ProgressDialog progressDialog = new ProgressDialog(getActivity());
progressDialog.setTitle(mTitle);
progressDialog.setMessage(mMessage);
progressDialog.setIndeterminate(false);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMax(100);
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, mCancel, (dialog, which) -> onDismiss(dialog));
return progressDialog;
}
@NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);
// create a dialog to show progress
final ProgressDialog progressDialog = new ProgressDialog(getActivity());
progressDialog.setTitle(mTitle);
progressDialog.setMessage(mMessage);
progressDialog.setIndeterminate(false);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMax(100);
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, mCancel, (dialog, which) -> onDismiss(dialog));
return progressDialog;
}
@Override
public void onClick(View v) {
Resources resources = activity.getResources();
ImageButton buttonPause= (ImageButton) activity.findViewById(R.id.pauseBtn);
buttonPause.setEnabled(true);
ImageButton buttonrecord= (ImageButton) activity.findViewById(R.id.recordBtn);
if (!activity.measurementService.isStoring()) {
// Start recording
buttonrecord.setImageResource(R.drawable.button_record_pressed);
buttonrecord.setEnabled(false);
activity.measurementService.startStorage();
// Force service to stay alive even if this activity is killed (Foreground service)
activity.startService(new Intent(activity, MeasurementService.class));
} else {
// Stop measurement
activity.measurementService.stopRecording();
// Show computing progress dialog
ProgressDialog myDialog = new ProgressDialog(activity);
if (!activity.measurementService.isCanceled()) {
myDialog.setMessage(resources.getString(R.string.measurement_processlastsamples,
activity.measurementService.getAudioProcess().getRemainingNotProcessSamples()));
myDialog.setCancelable(false);
myDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
resources.getText(R.string.text_CANCEL_data_transfer),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
activity.measurementService.cancel();
}
});
myDialog.show();
}
// Launch processing end activity
new Thread(new WaitEndOfProcessing(activity, myDialog)).start();
}
activity.initGuiState();
}