下面列出了怎么用android.content.DialogInterface.OnCancelListener的API类实例代码及写法,或者点击链接到github查看源代码。
private void showLoadingDialog() {
dismisLoadingDialog();
this.loadingDialog = new LoadingDialog((Context) this, 2131100006);
this.loadingDialog.show();
this.loadingDialog.setOnCancelListener(new OnCancelListener(this) {
final /* synthetic */ ChinaMobileWebPayActivity this$0;
{
if (HotFix.PREVENT_VERIFY) {
System.out.println(VerifyLoad.class);
}
this.this$0 = this$0;
}
public void onCancel(DialogInterface dialog) {
this.this$0.showFailedDialog();
}
});
}
private void reload()
{
relayout_alert.setVisibility(View.GONE);
if (pageIndex == 0)
{
progressDialog(R.string.loading_label);
dialog.setOnCancelListener(new OnCancelListener()
{
@Override
public void onCancel(DialogInterface arg0)
{
finish();
}
});
}
videoListViewHandler.getRecordVideoList(date, iCam,pageIndex,isAllCamera);
}
/**
*
* @Title showSheet
* @Description TODO(这里用一句话描述这个方法的作用)
* @param mContext
* 上下文环境
* @param actionSheetConfig
* ActionSheet配置项
* @param actionSheetItemSelected
* ActionSheet Item选中监听
* @param cancelListener
* 取消按钮的监听,无需监听可传null
* @return Dialog 返回类型
*/
@SuppressLint("NewApi")
public void show(final Activity activity,
ActionSheetConfig actionSheetConfig,
final OnActionSheetItemSelected actionSheetItemSelected,
OnCancelListener cancelListener) {
switch (actionSheetConfig.actionsheetStyle) {
case ACTIONSHEET_IOS:
new ActionSheet4IOS().show(activity, actionSheetConfig,
actionSheetItemSelected, cancelListener);
break;
case ACTIONSHEET_WECHAT:
new ActionSheet4WeChat().show(activity, actionSheetConfig,
actionSheetItemSelected, cancelListener);
break;
default:
new ActionSheet4WeChat().show(activity, actionSheetConfig,
actionSheetItemSelected, cancelListener);
}
}
private void showProgress() {
if (loadingDialog == null) {
if (splash > 0) {
Log.i("SplashActivity Showing splash");
setContentView(splash);
} else {
Log.i("SplashActivity Showing progress");
loadingDialog = ProgressDialog.show(this, null, "Starting...", true, true);
loadingDialog.setCanceledOnTouchOutside(false);
loadingDialog.setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface dialog) {
dialogCancelled = true;
finish();
}
});
}
}
}
public static AlertDialog showAlert(final Context context, final String title, final String msg, final View view, final DialogInterface.OnClickListener lOk,
final DialogInterface.OnClickListener lCancel) {
if (context instanceof Activity && ((Activity) context).isFinishing()) {
return null;
}
final Builder builder = new AlertDialog.Builder(context);
builder.setTitle(title);
builder.setMessage(msg);
builder.setView(view);
builder.setPositiveButton(R.string.app_ok, lOk);
builder.setNegativeButton(R.string.app_cancel, lCancel);
// builder.setCancelable(true);
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
if (lCancel != null) {
lCancel.onClick(dialog, 0);
}
}
});
final AlertDialog alert = builder.create();
alert.show();
return alert;
}
/**
* Connects to the Gatt service of the device to download a web page and displays a progress bar
* for the title.
* @param deviceAddress The mac address of the bar
* @param title The title of the web page being downloaded
*/
public void connect(String deviceAddress, String title) {
running = true;
String progressTitle = activity.getString(R.string.page_loading_title) + " " + title;
progress = new ProgressDialog(activity);
progress.setCancelable(true);
progress.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
Log.i(TAG, "Dialog box canceled");
close();
}
});
progress.setTitle(progressTitle);
progress.setMessage(activity.getString(R.string.page_loading_message));
progress.show();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
mBluetoothGatt = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress)
.connectGatt(activity, false, BluetoothSite.this);
}
});
}
private void showDialogWithHTML(Resources resources, String htmlChangelog) {
CharSequence title = resources.getString(R.string.title_changelog);
title = String.format("%s v%s", title, getAppVersion());
final WebView webView = new WebView(mActivity);
webView.loadDataWithBaseURL(null, htmlChangelog, "text/html", "utf-8", null);
final AlertDialog.Builder builder = new AlertDialog.Builder(mActivity).setTitle(title)
.setView(webView)
.setPositiveButton(resources.getString(R.string.changelog_close), new Dialog.OnClickListener() {
public void onClick(final DialogInterface dialogInterface, final int i) {
dialogInterface.dismiss();
}
})
.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
dialog.dismiss();
}
});
builder.create().show();
}
@Override
protected void onPreExecute() {
super.onPreExecute();
this.api = AppContext.getApiClient();
this.pd = new ProgressDialog(this.mEditProfilePage);
this.pd.setMessage("正在更新头像...");
this.pd.setIndeterminate(true);
this.pd.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(final DialogInterface dialog) {
UpdateProfileImageTask.this.isCancelled = true;
cancel(true);
}
});
this.pd.show();
}
@Override
protected void onPreExecute() {
super.onPreExecute();
this.api = AppContext.getApiClient();
this.pd = new ProgressDialog(this.mContext);
this.pd.setMessage("正在更新个人资料...");
this.pd.setIndeterminate(true);
this.pd.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(final DialogInterface dialog) {
UpdateProfileTask.this.isCancelled = true;
cancel(true);
}
});
this.pd.show();
}
public static ProgressDialog showProgress(CharSequence title, CharSequence message, Context context,
OnCancelListener listener) {
final ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.setCancelable(true);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setOnCancelListener(listener);
progressDialog.setTitle(title);
progressDialog.setMessage(message);
progressDialog.show();
return progressDialog;
}
private void showMapWithLocationClient() {
String str1 = getResources().getString(R.string.Making_sure_your_location);
progressDialog = new ProgressDialog(this);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setMessage(str1);
progressDialog.setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface arg0) {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
Log.d("map", "cancel retrieve location");
finish();
}
});
progressDialog.show();
mLocClient = new LocationClient(this);
mLocClient.registerLocationListener(myListener);
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);// 打开gps
// option.setCoorType("bd09ll"); //设置坐标类型
// Johnson change to use gcj02 coordination. chinese national standard
// so need to conver to bd09 everytime when draw on baidu map
option.setCoorType("gcj02");
option.setScanSpan(30000);
option.setAddrType("all");
mLocClient.setLocOption(option);
}
/**
*
* @Title showSheet
* @param activity
* 上下文环境
* @param actionSheetConfig
* ActionSheet配置项
* @param actionSheetItemSelected
* ActionSheet Item选中监听
* @param cancelListener
* 取消按钮的监听,无需监听可传null
* @return Dialog 返回类型
*/
@SuppressLint("NewApi")
public Dialog show(final Activity activity,
ActionSheetConfig actionSheetConfig,
final OnActionSheetItemSelected actionSheetItemSelected,
OnCancelListener cancelListener) {
final Dialog dlg = new Dialog(activity, R.style.ActionSheet);
LinearLayout layout = this.getLayout(activity, dlg, actionSheetConfig,
actionSheetItemSelected);
TextView mCancel = (TextView) layout.findViewById(R.id.cancel);
mCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
actionSheetItemSelected.onActionSheetItemSelected(activity, 0);
dlg.dismiss();
}
});
Window w = dlg.getWindow();
WindowManager.LayoutParams lp = w.getAttributes();
lp.x = 0;
final int cMakeBottom = -1000;
lp.y = cMakeBottom;
lp.gravity = Gravity.BOTTOM;
dlg.onWindowAttributesChanged(lp);
dlg.setCanceledOnTouchOutside(false);
if (cancelListener != null)
dlg.setOnCancelListener(cancelListener);
dlg.setContentView(layout);
dlg.show();
// 设置点击弹窗外部取消actionsheet
dlg.setCanceledOnTouchOutside(true);
return dlg;
}
private void showMapWithLocationClient() {
String str1 = getResources().getString(R.string.Making_sure_your_location);
progressDialog = new ProgressDialog(this);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setMessage(str1);
progressDialog.setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface arg0) {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
Log.d("map", "cancel retrieve location");
finish();
}
});
progressDialog.show();
mLocClient = new LocationClient(this);
mLocClient.registerLocationListener(myListener);
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);// open gps
// option.setCoorType("bd09ll");
// Johnson change to use gcj02 coordination. chinese national standard
// so need to conver to bd09 everytime when draw on baidu map
option.setCoorType("gcj02");
option.setScanSpan(30000);
option.setAddrType("all");
mLocClient.setLocOption(option);
}
private void showMapWithLocationClient() {
progressDialog = new ProgressDialog(this);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setMessage("正在确定你的位置...");
progressDialog.setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface arg0) {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
Log.d("map", "cancel retrieve location");
finish();
}
});
progressDialog.show();
mLocClient = new LocationClient(this);
mLocClient.registerLocationListener(myListener);
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);// 打开gps
// option.setCoorType("bd09ll"); //设置坐标类型
// Johnson change to use gcj02 coordination. chinese national standard
// so need to conver to bd09 everytime when draw on baidu map
option.setCoorType("gcj02");
option.setScanSpan(30000);
option.setAddrType("all");
mLocClient.setLocOption(option);
}
public GenericInputDialogBuilder(final Context pContext, final int pTitleResID, final int pMessageResID, final int pErrorResID, final int pIconResID, final String pDefaultText, final Callback<T> pSuccessCallback, final OnCancelListener pOnCancelListener) {
this.mContext = pContext;
this.mTitleResID = pTitleResID;
this.mMessageResID = pMessageResID;
this.mErrorResID = pErrorResID;
this.mIconResID = pIconResID;
this.mDefaultText = pDefaultText;
this.mSuccessCallback = pSuccessCallback;
this.mOnCancelListener = pOnCancelListener;
}
/**
* Inits the views.
*/
private void initViews() {
btnAddQR = (Button) findViewById(R.id.btnAddQR);
btnAddGokit = (Button) findViewById(R.id.btnAddGokit);
ivBack=(ImageView) findViewById(R.id.ivBack);
lvDevices = (ListView) findViewById(R.id.lvDevices);
tvTips = (TextView) findViewById(R.id.tvTips);
loadingDialog = new ProgressDialog(this);
loadingDialog.setMessage("加载中,请稍候.");
loadingDialog.setCancelable(false);
deviceList = new ArrayList<XPGWifiDevice>();
adapter = new SearchListAdapter(this, deviceList);
lvDevices.setAdapter(adapter);
noNetworkDialog = DialogManager.getNoNetworkDialog(this);
noNetworkDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
isWaitingWifi = false;
}
});
allDeviceList = new ArrayList<XPGWifiDevice>();
Bundle mBundle = getIntent().getExtras();
if (mBundle != null) {
isRegister = mBundle.getBoolean("isRegister");
}
}
@Deprecated
public static EasyProgressDialog showProgressDialog(Context context, String title, String message,
boolean canCancelable, OnCancelListener listener) {
EasyProgressDialog dialog = getDialog();
if (dialog != null && dialog.getContext() != context) {
// maybe existing dialog is running in a destroyed activity cotext we should recreate one
dismissProgressDialog();
LogUtil.e("dialog", "there is a leaked window here,orign context: " + dialog.getContext() + " now: " + context);
dialog = null;
}
if (dialog == null) {
dialog = new EasyProgressDialog(context, message);
sProgressDialogRef = new WeakReference<>(dialog);
}
if (!TextUtils.isEmpty(title)) {
dialog.setTitle(title);
}
if (!TextUtils.isEmpty(message)) {
dialog.setMessage(message);
}
dialog.setCancelable(canCancelable);
dialog.setOnCancelListener(listener);
dialog.show();
return dialog;
}
public static AlertDialog showAlert(final Context context, final String title, final View view, final DialogInterface.OnCancelListener lCancel) {
if (context instanceof Activity && ((Activity) context).isFinishing()) {
return null;
}
final Builder builder = new AlertDialog.Builder(context);
builder.setTitle(title);
builder.setView(view);
// builder.setCancelable(true);
builder.setOnCancelListener(lCancel);
final AlertDialog alert = builder.create();
alert.show();
return alert;
}
public static ProgressDialog showProgressDlg(final Context context, final String title, final String message, final boolean indeterminate, final boolean cancelable, final OnCancelListener lCancel) {
MMAppMgr.activate(true);
return ProgressDialog.show(context, title, message, indeterminate, cancelable, new DialogInterface.OnCancelListener() {
@Override
public void onCancel(final DialogInterface dialog) {
if (lCancel != null) {
lCancel.onCancel(dialog);
}
MMAppMgr.activate(false);
}
});
}
public GenericInputDialogBuilder(final Context pContext, final int pTitleResID, final int pMessageResID, final int pErrorResID, final int pIconResID, final String pDefaultText, final Callback<T> pSuccessCallback, final OnCancelListener pOnCancelListener){
this.mContext = pContext;
this.mTitleResID = pTitleResID;
this.mMessageResID = pMessageResID;
this.mErrorResID = pErrorResID;
this.mIconResID = pIconResID;
this.mDefaultText = pDefaultText;
this.mSuccessCallback = pSuccessCallback;
this.mOnCancelListener = pOnCancelListener;
}
private void getNC() {
List<NameValuePair> targVar = new ArrayList<NameValuePair>();
targVar.add(Wenku8Interface.getNovelContent(currentAid, currentCid,
GlobalConfig.getFetchLanguage()));
final asyncNovelContentTask ast = new asyncNovelContentTask();
ast.execute(targVar);
pDialog = new ProgressDialog(parentActivity);
pDialog.setTitle(getResources().getString(R.string.load_status));
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(true);
pDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
ast.cancel(true);
pDialog.dismiss();
pDialog = null;
}
});
pDialog.setMessage(getResources().getString(R.string.load_loading));
pDialog.setProgress(0);
pDialog.setMax(1);
pDialog.show();
return;
}
private void loadSearchResultList() {
// the result is just 10 records, so don't need "isLoading"
List<NameValuePair> targVarList = new ArrayList<NameValuePair>();
if (plus == 1) {
targVarList.add(Wenku8Interface.searchNovelByNovelName(name,
GlobalConfig.getFetchLanguage()));
} else if (plus == 2) {
targVarList.add(Wenku8Interface.searchNovelByAuthorName(name,
GlobalConfig.getFetchLanguage()));
}
isSearching = true;
final asyncSearchTask ast = new asyncSearchTask();
ast.execute(targVarList);
pDialog = new ProgressDialog(parentActivity);
pDialog.setTitle(getResources().getString(R.string.search_ing));
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(true);
pDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
isSearching = false;
if (pDialog != null)
pDialog.dismiss();
pDialog = null;
}
});
pDialog.setMessage(getResources().getString(R.string.search_fetching));
pDialog.setProgress(0);
pDialog.setMax(1);
pDialog.show();
return;
}
private void getNC() {
List<NameValuePair> targVar = new ArrayList<NameValuePair>();
targVar.add(Wenku8Interface.getNovelContent(currentAid, currentCid,
GlobalConfig.getFetchLanguage()));
final asyncNovelContentTask ast = new asyncNovelContentTask();
ast.execute(targVar);
pDialog = new ProgressDialog(parentActivity);
pDialog.setTitle(getResources().getString(R.string.load_status));
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(true);
pDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
ast.cancel(true);
pDialog.dismiss();
pDialog = null;
}
});
pDialog.setMessage(getResources().getString(R.string.load_loading));
pDialog.setProgress(0);
pDialog.setMax(1);
pDialog.show();
return;
}
private void loadSearchResultList() {
// the result is just 10 records, so don't need "isLoading"
List<NameValuePair> targVarList = new ArrayList<NameValuePair>();
if (plus == 1) {
targVarList.add(Wenku8Interface.searchNovelByNovelName(name,
GlobalConfig.getFetchLanguage()));
} else if (plus == 2) {
targVarList.add(Wenku8Interface.searchNovelByAuthorName(name,
GlobalConfig.getFetchLanguage()));
}
isSearching = true;
final asyncSearchTask ast = new asyncSearchTask();
ast.execute(targVarList);
pDialog = new ProgressDialog(parentActivity);
pDialog.setTitle(getResources().getString(R.string.search_ing));
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(true);
pDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
isSearching = false;
if (pDialog != null)
pDialog.dismiss();
pDialog = null;
}
});
pDialog.setMessage(getResources().getString(R.string.search_fetching));
pDialog.setProgress(0);
pDialog.setMax(1);
pDialog.show();
return;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = ProgressDialog.show(mActivity, "",
mActivity.getString(R.string.just_a_moment));
mProgressDialog.setCanceledOnTouchOutside(true);
mProgressDialog.setCancelable(true);
mProgressDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dlg) {
GetRequestToken.this.cancel(true);
}
});
}
@Override
protected void onPreExecute() {
progress = ProgressDialog.show(MainActivity.this, null, getString(R.string.progress_get_view_url_title), true, true, new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
ShowNotificationTask.this.cancel(true);
}
});
}
/** Connect to a chosen Bluetooth Device using whatever BLE Stack is available. **/
public static BluetoothLEStack connectToBluetoothLEStack(BluetoothDevice device, Activity hostActivity, String uuidStringRepresentation, OnCancelListener onCancelConnectionAttempt){
bluetoothConnectionWaitWindow = new ProgressDialog(hostActivity);
bluetoothConnectionWaitWindow.setTitle("Connecting to Bluetooth Radio " + device.getAddress());
bluetoothConnectionWaitWindow.setMessage("Please wait...");
bluetoothConnectionWaitWindow.setCancelable(false);
if (onCancelConnectionAttempt != null){
bluetoothConnectionWaitWindow.setCancelable(true);
bluetoothConnectionWaitWindow.setOnCancelListener(onCancelConnectionAttempt);
}
bluetoothConnectionWaitWindow.setIndeterminate(true);
bluetoothConnectionWaitWindow.show();
if (singleton != null){
singleton.disconnect();
singleton.connect(device, hostActivity);
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2){
singleton = new AndroidBleStack(device, null, hostActivity);
} else {
//See if Samsung (Broadcom-based) Bluetooth Low Energy stack will work- works on Android 4.1 and 4.2
singleton = new SamsungBleStack(device, hostActivity);
}
}
return singleton;
}
protected CustomLoadDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
}
protected DialogUtil(Context context, boolean cancelable, OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
}
protected DownloadCacheDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
if (HotFix.PREVENT_VERIFY) {
System.out.println(VerifyLoad.class);
}
super(context, cancelable, cancelListener);
}