DialogPermission.java
2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.hjx.personalcenter.util;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.provider.Settings;
import android.util.Log;
/**
* 权限提示对话框
* Created by yf on 2016/7/25.
*/
public class DialogPermission {
Context mContext;
String mNotice;
public DialogPermission(Context context, String notice) {
mContext = context;
mNotice = notice;
showDialog();
}
private void showDialog() {
new AlertDialog.Builder(mContext).setTitle("系统提示")//设置对话框标题
.setMessage(mNotice)//设置显示的内容
.setPositiveButton("设置", new DialogInterface.OnClickListener() {//添加确定按钮
@Override
public void onClick(DialogInterface dialog, int which) {//确定按钮的响应事件
Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
mContext.startActivity(intent);
}
}).setNegativeButton("放弃", new DialogInterface.OnClickListener() {//添加返回按钮
@Override
public void onClick(DialogInterface dialog, int which) {//响应事件
Log.i("DialogPermission", "Dialog关闭");
}
}).show();//在按键响应事件中显示此对话框
}
/**
* 显示进度条
*
* @param context 环境
* @param title 标题
* @param message 信息
* @param indeterminate 确定性
* @param cancelable 可撤销
* @return
*/
public static ProgressDialog showProgress(Context context,
CharSequence title, CharSequence message, boolean indeterminate,
boolean cancelable, DialogInterface.OnDismissListener listener) {
ProgressDialog dialog = new ProgressDialog(context);
dialog.setTitle(title);
dialog.setMessage(message);
dialog.setIndeterminate(indeterminate);
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(false);
// dialog.setDefaultButton(false);
if (cancelable && listener != null)
dialog.setOnDismissListener(listener);
dialog.show();
return dialog;
}
private void closeProgress() {
try {
if (mProgress != null) {
mProgress.dismiss();
mProgress = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
private ProgressDialog mProgress = null;
}