55207730
孙向锦
批次表決UI修改
|
1
2
3
4
|
package com.sunvote.xpadapp.dialog;
import android.app.AlertDialog;
import android.content.Context;
|
81252b84
孙向锦
C5 vote
|
5
6
|
import android.content.DialogInterface;
import android.os.Build;
|
55207730
孙向锦
批次表決UI修改
|
7
8
9
10
11
12
13
|
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
|
81252b84
孙向锦
C5 vote
|
14
|
import com.sunvote.xpadapp.MainActivity;
|
55207730
孙向锦
批次表決UI修改
|
15
16
17
18
19
20
21
|
import com.sunvote.xpadapp.R;
public class ToastAlertDialog {
private AlertDialog dialog;
private AlertDialog.Builder builder;
private TextView messageView ;
|
55207730
孙向锦
批次表決UI修改
|
22
|
private Handler handler;
|
81252b84
孙向锦
C5 vote
|
23
|
private Context context;
|
55207730
孙向锦
批次表決UI修改
|
24
25
26
27
28
29
30
|
public ToastAlertDialog setMessage(CharSequence message) {
messageView.setText(message);
return this;
}
public ToastAlertDialog(Context context){
|
81252b84
孙向锦
C5 vote
|
31
|
this.context = context;
|
55207730
孙向锦
批次表決UI修改
|
32
33
34
|
builder = new AlertDialog.Builder(context);
handler = new Handler(Looper.getMainLooper());
builder.setCancelable(true);
|
81252b84
孙向锦
C5 vote
|
35
36
37
38
39
40
|
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface d) {
handler.postDelayed(hideMenu,10);
}
});
|
55207730
孙向锦
批次表決UI修改
|
41
42
|
View rootView = LayoutInflater.from(context).inflate(R.layout.toast_dialog,null);
messageView = rootView.findViewById(R.id.message);
|
55207730
孙向锦
批次表決UI修改
|
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
|
rootView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(dialog != null){
dialog.dismiss();
}
}
});
builder.setView(rootView);
}
Runnable close = new Runnable() {
@Override
public void run() {
if(dialog != null){
dialog.dismiss();
}
}
};
public void show(){
if(dialog == null){
dialog = builder.create();
}
WindowManager.LayoutParams lp= dialog.getWindow().getAttributes();
lp.width=750;
lp.height=380;
lp.alpha = 0.6f;
dialog.getWindow().setAttributes(lp);
dialog.show();
|
81252b84
孙向锦
C5 vote
|
73
|
hideBottomUIMenu();
|
55207730
孙向锦
批次表決UI修改
|
74
75
76
77
78
79
|
handler.postDelayed(close,2000);
}
public static ToastAlertDialog makeText(Context context, CharSequence text){
return new ToastAlertDialog(context).setMessage(text);
}
|
81252b84
孙向锦
C5 vote
|
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
private Runnable hideMenu = new Runnable() {
@Override
public void run() {
hideBottomUIMenu();
}
};
public void hideBottomUIMenu(){
if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower
View v = dialog.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if (Build.VERSION.SDK_INT >= 19) {
View decorView = dialog.getWindow().getDecorView();
if(context instanceof MainActivity){
MainActivity mainActivity = (MainActivity)context;
decorView = mainActivity.getWindow().getDecorView();
}
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | 0x00002000;
decorView.setSystemUiVisibility(uiOptions);
}
}
|
55207730
孙向锦
批次表決UI修改
|
102
|
}
|