public class DialogUtil {
public static AlertDialog getAlertDialog(final Context ctx, String title, String msg) {
Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(title);
builder.setMessage(msg);
return builder.create();
}
public static AlertDialog getAlertDialog(final Context ctx, String title, String msg,
DialogInterface.OnClickListener positiveListener) {
Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(title);
builder.setMessage(msg);
builder.setPositiveButton(ctx.getResources().getString(R.string.str_setting_confirm), positiveListener);
return builder.create();
}
public static AlertDialog getAlertDialog(final Context ctx, String title, String msg,
DialogInterface.OnClickListener positiveListener, DialogInterface.OnClickListener negativeListener) {
Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(title);
builder.setMessage(msg);
builder.setPositiveButton(ctx.getResources().getString(R.string.str_setting_confirm), positiveListener);
if (null != negativeListener) {
builder.setNegativeButton(ctx.getResources().getString(R.string.str_setting_cancel), negativeListener);
} else {
builder.setNegativeButton(ctx.getResources().getString(R.string.str_setting_cancel),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
}
return builder.create();
}
public static AlertDialog getTextAlertDialog(final Context ctx, String title, String msg, View view,
DialogInterface.OnClickListener positiveListener, DialogInterface.OnClickListener negativeListener) {
Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(title);
builder.setMessage(msg);
builder.setView(view);
builder.setPositiveButton(ctx.getResources().getString(R.string.str_setting_confirm), positiveListener);
builder.setNegativeButton(ctx.getResources().getString(R.string.str_setting_cancel),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
return builder.create();
}
public static Dialog getDoubleButtonDialog(final Context ctx, String msg, Button.OnClickListener positiveListener) {
final Dialog dialog = new Dialog(ctx);
// Get the layout inflater
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
//add by rc at 2016-8-4
dialog.getWindow().setGravity(Gravity.BOTTOM);
//ead
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_module_double);
Button confirm = (Button) dialog.findViewById(R.id.confirm_double_dialog);
Button cancel = (Button) dialog.findViewById(R.id.deny_double_dialog);
TextView tv_msg = (TextView) dialog.findViewById(R.id.textview_double_dialog);
tv_msg.setText(msg);
confirm.setOnClickListener(positiveListener);
cancel.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
return dialog;
}
public static Dialog getDoubleButtonDialog(final Context ctx, String msg, Button.OnClickListener positiveListener,
Button.OnClickListener negativeListener) {
final Dialog dialog = new Dialog(ctx);
// Get the layout inflater
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
//add by rc at 2016-8-4
dialog.getWindow().setGravity(Gravity.BOTTOM);
//ead
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_module_double);
Button confirm = (Button) dialog.findViewById(R.id.confirm_double_dialog);
Button cancel = (Button) dialog.findViewById(R.id.deny_double_dialog);
TextView tv_msg = (TextView) dialog.findViewById(R.id.textview_double_dialog);
tv_msg.setText(msg);
confirm.setOnClickListener(positiveListener);
cancel.setOnClickListener(negativeListener);
return dialog;
}
public static Dialog getDoubleButtonDialog(final Context ctx, String msg, String confirm_msg, String cancel_msg,
Button.OnClickListener positiveListener, Button.OnClickListener negativeListener) {
final Dialog dialog = new Dialog(ctx);
// Get the layout inflater
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
//add by rc at 2016-8-4
dialog.getWindow().setGravity(Gravity.BOTTOM);
//ead
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_module_double);
Button confirm = (Button) dialog.findViewById(R.id.confirm_double_dialog);
Button cancel = (Button) dialog.findViewById(R.id.deny_double_dialog);
confirm.setText(confirm_msg);
cancel.setText(cancel_msg);
TextView tv_msg = (TextView) dialog.findViewById(R.id.textview_double_dialog);
tv_msg.setText(msg);
confirm.setOnClickListener(positiveListener);
cancel.setOnClickListener(negativeListener);
return dialog;
}
public static Dialog getSingleButtonDialog(final Context ctx, String msg, Button.OnClickListener positiveListener) {
final Dialog dialog = new Dialog(ctx);
// Get the layout inflater
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
//add by rc at 2016-8-4
dialog.getWindow().setGravity(Gravity.BOTTOM);
//ead
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_module_single);
Button confirm = (Button) dialog.findViewById(R.id.confirm_single_dialog);
TextView tv_msg = (TextView) dialog.findViewById(R.id.textview_single_dialog);
tv_msg.setText(msg);
confirm.setOnClickListener(positiveListener);
return dialog;
}
public static Dialog getSingleButtonDialog(final Context ctx, String msg, String confirm_msg,
Button.OnClickListener positiveListener) {
final Dialog dialog = new Dialog(ctx);
// Get the layout inflater
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
//add by rc at 2016-8-4
dialog.getWindow().setGravity(Gravity.BOTTOM);
//ead
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_module_single);
Button confirm = (Button) dialog.findViewById(R.id.confirm_single_dialog);
confirm.setText(confirm_msg);
TextView tv_msg = (TextView) dialog.findViewById(R.id.textview_single_dialog);
tv_msg.setText(msg);
confirm.setOnClickListener(positiveListener);
return dialog;
}
public static Dialog getSingleButtonDialog(final Context ctx, String msg) {
try {
final Dialog dialog = new Dialog(ctx);
// Get the layout inflater
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.getWindow().getDecorView().setPadding(0, 0, 0, 0); // 灏辫兘澶熸按骞冲崰婊′簡
//add by rc at 2016-8-4
dialog.getWindow().setGravity(Gravity.BOTTOM);
//ead
// dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// bug161@2016-3-25
dialog.setContentView(R.layout.dialog_module_single);
Button confirm = (Button) dialog.findViewById(R.id.confirm_single_dialog);
TextView tv_msg = (TextView) dialog.findViewById(R.id.textview_single_dialog);
tv_msg.setText(msg);
confirm.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
return dialog;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/*
* public static AlertDialog getViewDialog( final Context ctx, String title,
* String msg, View view ) { Builder builder = new AlertDialog.Builder( ctx
* ); if ( null != title) builder.setTitle(title); if ( null != msg)
* builder.setMessage(msg); if ( null != view) builder.setView(view);
*
* return builder.create(); }
*/
public static AlertDialog getListDialog(final Context ctx, String title, String msg, int items,
DialogInterface.OnClickListener listener) {
Builder builder = new AlertDialog.Builder(ctx);
if (null != title)
builder.setTitle(title);
if (null != msg)
builder.setMessage(msg);
builder.setItems(items, listener);
return builder.create();
}
// ningyb 20160314
public static Dialog getResendDialog(final Context ctx, String msg, String confirm_msg, String cancel_msg,
Button.OnClickListener positiveListener, Button.OnClickListener negativeListener) {
final Dialog dialog = new Dialog(ctx);
// Get the layout inflater
Window win = dialog.getWindow();
win.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
win.setGravity(Gravity.BOTTOM);
win.getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams lp = win.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
win.setAttributes(lp);
// dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_module_resend);
Button confirm = (Button) dialog.findViewById(R.id.confirm_double_dialog);
Button cancel = (Button) dialog.findViewById(R.id.deny_double_dialog);
if (confirm_msg != null && !"".equals(confirm_msg)) {
confirm.setText(confirm_msg);
}
if (cancel_msg != null && !"".equals(cancel_msg)) {
cancel.setText(cancel_msg);
}
TextView tv_msg = (TextView) dialog.findViewById(R.id.textview_double_dialog);
if (msg != null && !"".equals(msg)) {
tv_msg.setText(msg);
}
confirm.setOnClickListener(positiveListener);
cancel.setOnClickListener(negativeListener);
return dialog;
}
}
public static AlertDialog getAlertDialog(final Context ctx, String title, String msg) {
Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(title);
builder.setMessage(msg);
return builder.create();
}
public static AlertDialog getAlertDialog(final Context ctx, String title, String msg,
DialogInterface.OnClickListener positiveListener) {
Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(title);
builder.setMessage(msg);
builder.setPositiveButton(ctx.getResources().getString(R.string.str_setting_confirm), positiveListener);
return builder.create();
}
public static AlertDialog getAlertDialog(final Context ctx, String title, String msg,
DialogInterface.OnClickListener positiveListener, DialogInterface.OnClickListener negativeListener) {
Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(title);
builder.setMessage(msg);
builder.setPositiveButton(ctx.getResources().getString(R.string.str_setting_confirm), positiveListener);
if (null != negativeListener) {
builder.setNegativeButton(ctx.getResources().getString(R.string.str_setting_cancel), negativeListener);
} else {
builder.setNegativeButton(ctx.getResources().getString(R.string.str_setting_cancel),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
}
return builder.create();
}
public static AlertDialog getTextAlertDialog(final Context ctx, String title, String msg, View view,
DialogInterface.OnClickListener positiveListener, DialogInterface.OnClickListener negativeListener) {
Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(title);
builder.setMessage(msg);
builder.setView(view);
builder.setPositiveButton(ctx.getResources().getString(R.string.str_setting_confirm), positiveListener);
builder.setNegativeButton(ctx.getResources().getString(R.string.str_setting_cancel),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
return builder.create();
}
public static Dialog getDoubleButtonDialog(final Context ctx, String msg, Button.OnClickListener positiveListener) {
final Dialog dialog = new Dialog(ctx);
// Get the layout inflater
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
//add by rc at 2016-8-4
dialog.getWindow().setGravity(Gravity.BOTTOM);
//ead
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_module_double);
Button confirm = (Button) dialog.findViewById(R.id.confirm_double_dialog);
Button cancel = (Button) dialog.findViewById(R.id.deny_double_dialog);
TextView tv_msg = (TextView) dialog.findViewById(R.id.textview_double_dialog);
tv_msg.setText(msg);
confirm.setOnClickListener(positiveListener);
cancel.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
return dialog;
}
public static Dialog getDoubleButtonDialog(final Context ctx, String msg, Button.OnClickListener positiveListener,
Button.OnClickListener negativeListener) {
final Dialog dialog = new Dialog(ctx);
// Get the layout inflater
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
//add by rc at 2016-8-4
dialog.getWindow().setGravity(Gravity.BOTTOM);
//ead
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_module_double);
Button confirm = (Button) dialog.findViewById(R.id.confirm_double_dialog);
Button cancel = (Button) dialog.findViewById(R.id.deny_double_dialog);
TextView tv_msg = (TextView) dialog.findViewById(R.id.textview_double_dialog);
tv_msg.setText(msg);
confirm.setOnClickListener(positiveListener);
cancel.setOnClickListener(negativeListener);
return dialog;
}
public static Dialog getDoubleButtonDialog(final Context ctx, String msg, String confirm_msg, String cancel_msg,
Button.OnClickListener positiveListener, Button.OnClickListener negativeListener) {
final Dialog dialog = new Dialog(ctx);
// Get the layout inflater
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
//add by rc at 2016-8-4
dialog.getWindow().setGravity(Gravity.BOTTOM);
//ead
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_module_double);
Button confirm = (Button) dialog.findViewById(R.id.confirm_double_dialog);
Button cancel = (Button) dialog.findViewById(R.id.deny_double_dialog);
confirm.setText(confirm_msg);
cancel.setText(cancel_msg);
TextView tv_msg = (TextView) dialog.findViewById(R.id.textview_double_dialog);
tv_msg.setText(msg);
confirm.setOnClickListener(positiveListener);
cancel.setOnClickListener(negativeListener);
return dialog;
}
public static Dialog getSingleButtonDialog(final Context ctx, String msg, Button.OnClickListener positiveListener) {
final Dialog dialog = new Dialog(ctx);
// Get the layout inflater
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
//add by rc at 2016-8-4
dialog.getWindow().setGravity(Gravity.BOTTOM);
//ead
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_module_single);
Button confirm = (Button) dialog.findViewById(R.id.confirm_single_dialog);
TextView tv_msg = (TextView) dialog.findViewById(R.id.textview_single_dialog);
tv_msg.setText(msg);
confirm.setOnClickListener(positiveListener);
return dialog;
}
public static Dialog getSingleButtonDialog(final Context ctx, String msg, String confirm_msg,
Button.OnClickListener positiveListener) {
final Dialog dialog = new Dialog(ctx);
// Get the layout inflater
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
//add by rc at 2016-8-4
dialog.getWindow().setGravity(Gravity.BOTTOM);
//ead
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_module_single);
Button confirm = (Button) dialog.findViewById(R.id.confirm_single_dialog);
confirm.setText(confirm_msg);
TextView tv_msg = (TextView) dialog.findViewById(R.id.textview_single_dialog);
tv_msg.setText(msg);
confirm.setOnClickListener(positiveListener);
return dialog;
}
public static Dialog getSingleButtonDialog(final Context ctx, String msg) {
try {
final Dialog dialog = new Dialog(ctx);
// Get the layout inflater
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.getWindow().getDecorView().setPadding(0, 0, 0, 0); // 灏辫兘澶熸按骞冲崰婊′簡
//add by rc at 2016-8-4
dialog.getWindow().setGravity(Gravity.BOTTOM);
//ead
// dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// bug161@2016-3-25
dialog.setContentView(R.layout.dialog_module_single);
Button confirm = (Button) dialog.findViewById(R.id.confirm_single_dialog);
TextView tv_msg = (TextView) dialog.findViewById(R.id.textview_single_dialog);
tv_msg.setText(msg);
confirm.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
return dialog;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/*
* public static AlertDialog getViewDialog( final Context ctx, String title,
* String msg, View view ) { Builder builder = new AlertDialog.Builder( ctx
* ); if ( null != title) builder.setTitle(title); if ( null != msg)
* builder.setMessage(msg); if ( null != view) builder.setView(view);
*
* return builder.create(); }
*/
public static AlertDialog getListDialog(final Context ctx, String title, String msg, int items,
DialogInterface.OnClickListener listener) {
Builder builder = new AlertDialog.Builder(ctx);
if (null != title)
builder.setTitle(title);
if (null != msg)
builder.setMessage(msg);
builder.setItems(items, listener);
return builder.create();
}
// ningyb 20160314
public static Dialog getResendDialog(final Context ctx, String msg, String confirm_msg, String cancel_msg,
Button.OnClickListener positiveListener, Button.OnClickListener negativeListener) {
final Dialog dialog = new Dialog(ctx);
// Get the layout inflater
Window win = dialog.getWindow();
win.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
win.setGravity(Gravity.BOTTOM);
win.getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams lp = win.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
win.setAttributes(lp);
// dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_module_resend);
Button confirm = (Button) dialog.findViewById(R.id.confirm_double_dialog);
Button cancel = (Button) dialog.findViewById(R.id.deny_double_dialog);
if (confirm_msg != null && !"".equals(confirm_msg)) {
confirm.setText(confirm_msg);
}
if (cancel_msg != null && !"".equals(cancel_msg)) {
cancel.setText(cancel_msg);
}
TextView tv_msg = (TextView) dialog.findViewById(R.id.textview_double_dialog);
if (msg != null && !"".equals(msg)) {
tv_msg.setText(msg);
}
confirm.setOnClickListener(positiveListener);
cancel.setOnClickListener(negativeListener);
return dialog;
}
}