ToastAlertDialog.java
1.98 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
package com.sunvote.xpadapp.dialog;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import com.sunvote.xpadapp.R;
public class ToastAlertDialog {
private AlertDialog dialog;
private AlertDialog.Builder builder;
private TextView messageView ;
private TextView confirm;
private Handler handler;
public ToastAlertDialog setMessage(CharSequence message) {
messageView.setText(message);
return this;
}
public ToastAlertDialog(Context context){
builder = new AlertDialog.Builder(context);
handler = new Handler(Looper.getMainLooper());
builder.setCancelable(true);
View rootView = LayoutInflater.from(context).inflate(R.layout.toast_dialog,null);
messageView = rootView.findViewById(R.id.message);
confirm = rootView.findViewById(R.id.confirm);
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();
handler.postDelayed(close,2000);
}
public static ToastAlertDialog makeText(Context context, CharSequence text){
return new ToastAlertDialog(context).setMessage(text);
}
}