package com.demo.app.ui.dialog; import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.view.LayoutInflater; import android.view.View; import android.widget.FrameLayout; import android.widget.TextView; import com.demo.app.R; import com.demo.lib.common.util.SystemCommon; /** * 用户协议弹框 */ public class ExitDialog extends Dialog { private static String TAG = "ExitDialog"; public ExitDialog(Context context) { super(context); this.setCancelable(false); } public ExitDialog(Context context, int theme) { super(context, theme); this.setCancelable(false); } public static class Builder { private Activity context; private OnClickListener positiveButtonClickListener; private OnClickListener negativeButtonClickListener; public Builder(Activity context) { this.context = context; } public Builder setPositiveClickListener( OnClickListener listener) { this.positiveButtonClickListener = listener; return this; } public Builder setNegativeClickListener(OnClickListener listener) { this.negativeButtonClickListener = listener; return this; } public ExitDialog create() { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final ExitDialog dialog = new ExitDialog(context, R.style.Dialog); dialog.setCanceledOnTouchOutside(false); final View layout = inflater.inflate(R.layout.dialog_exit, null); dialog.addContentView(layout, new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT)); TextView tv_positive = layout.findViewById(R.id.tv_positive); TextView tv_negative = layout.findViewById(R.id.tv_negative); // set the confirm button if (positiveButtonClickListener != null) { tv_positive.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { positiveButtonClickListener.onClick(dialog, DialogInterface.BUTTON_POSITIVE); } }); } if (negativeButtonClickListener != null) { tv_negative.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { negativeButtonClickListener.onClick(dialog, DialogInterface.BUTTON_NEGATIVE); } }); } dialog.setContentView(layout); android.view.WindowManager.LayoutParams params = dialog.getWindow() .getAttributes(); params.width = (int) ((SystemCommon.getScreenWidth(context) * 3) / 4); params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT; dialog.getWindow().setAttributes(params); return dialog; } } public interface MeasureCallBack { void onMeasure(int height); } }