-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPopupsUtils.java
70 lines (59 loc) · 2.81 KB
/
PopupsUtils.java
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
import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
/**
* Created by Hasan Mhd Amin on 10/6/2016.
*/
public class PopupsUtils {
private static AlertDialog alertDialog;
public static void showAlertDialog(final Context context, boolean cancelable,
@Nullable String title, String message,
String positiveButtonText, @Nullable DialogInterface.OnClickListener positiveButtonListener,
String negativeButtonText, @Nullable DialogInterface.OnClickListener negativeButtonListener) {
if (alertDialog == null || !alertDialog.isShowing()) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
if (title != null)
builder.setTitle(title);
builder.setMessage(message);
if (positiveButtonText != null) {
if (positiveButtonListener != null) {
builder.setPositiveButton(positiveButtonText, positiveButtonListener);
} else {
builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
alertDialog.dismiss();
}
});
}
}
if (negativeButtonText != null) {
if (negativeButtonListener != null) {
builder.setNegativeButton(negativeButtonText, negativeButtonListener);
} else {
builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
alertDialog.dismiss();
}
});
}
}
alertDialog = builder.create();
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(context, R.color.colorPrimary));
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(ContextCompat.getColor(context, R.color.colorPrimary));
}
});
alertDialog.setCancelable(cancelable);
alertDialog.show();
}
}
public static void hideAlertDialog() {
if (alertDialog != null && alertDialog.isShowing()) {
alertDialog.dismiss();
}
}
}