public class SsPromptDialogMgr implements View.OnClickListener {
public final static String TAG = SsPromptDialogMgr.class.getName()
private Context mContext
private Dialog dialog
public static SsPromptDialogMgr make() {
SsPromptDialogMgr instance = new SsPromptDialogMgr()
return instance
}
private DialogInterface.OnDismissListener mOnDismissListener
private DialogInterface.OnShowListener mOnShowListener
public SsPromptDialogMgr setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
this.mOnDismissListener = onDismissListener
return this
}
public SsPromptDialogMgr setOnShowListener(DialogInterface.OnShowListener onShowListener) {
this.mOnShowListener = onShowListener
return this
}
public void showDialog(Context context) {
if (context == null) {
return
}
this.mContext = context
dialog = new Dialog(context)
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
Window window = dialog.getWindow()
LinearLayout.LayoutParams centerParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT)
centerParam.bottomMargin = 5
centerParam.topMargin = 5
centerParam.gravity = Gravity.CENTER
LinearLayout.LayoutParams textParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT)
textParam.weight = 1
LinearLayout dialogLayout = new LinearLayout(mContext)
dialogLayout.setOrientation(LinearLayout.VERTICAL)
dialogLayout.setPadding(10,10,10,10)
TextView titleView = new TextView(context)
titleView.setTextColor(Color.parseColor("#56abe4"))
titleView.setPadding(10,10,10,10)
titleView.setTextSize(18)
titleView.setGravity(Gravity.CENTER)
TextView promptView = new TextView(context)
promptView.setPadding(10,10,10,10)
promptView.setTextSize(14)
TextView doFeedbackView = new TextView(context)
doFeedbackView.setTextColor(Color.parseColor("#56abe4"))
doFeedbackView.setTag("doFeedbackView")
doFeedbackView.setTextSize(15)
TextView cancelView = new TextView(context)
cancelView.setTextSize(15)
cancelView.setTextColor(Color.parseColor("#56abe4"))
cancelView.setTag("cancelView")
titleView.setText(FeedbackOverallMgr.getInstance().DIALOG_TITLE)
promptView.setText(FeedbackOverallMgr.getInstance().DIALOG_PROMPT)
doFeedbackView.setText("我要反馈")
doFeedbackView.setGravity(Gravity.CENTER)
cancelView.setText("取消")
cancelView.setGravity(Gravity.CENTER)
promptView.setTextColor(Color.parseColor("#B6000000"))
doFeedbackView.setOnClickListener(this)
cancelView.setOnClickListener(this)
cancelView.setPadding(20,0,20,10)
doFeedbackView.setPadding(20,0,20,10)
LinearLayout bottomLayout = new LinearLayout(mContext)
bottomLayout.setOrientation(LinearLayout.HORIZONTAL)
bottomLayout.addView(doFeedbackView,textParam)
bottomLayout.addView(cancelView,textParam)
bottomLayout.setPadding(10,10,10,10)
dialogLayout.addView(titleView,centerParam)
dialogLayout.addView(promptView,centerParam)
dialogLayout.addView(bottomLayout,centerParam)
int roundRadius = 15
GradientDrawable backGround = new GradientDrawable()
backGround.setColor(Color.WHITE)
backGround.setCornerRadius(roundRadius)
backGround.setStroke(5,Color.WHITE)
window.setContentView(dialogLayout)
window.setBackgroundDrawable(backGround)
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (mOnDismissListener != null) {
mOnDismissListener.onDismiss(dialog)
}
}
})
dialog.show()
if(mOnShowListener != null)
{
mOnShowListener.onShow(dialog)
}
}
@Override
public void onClick(View v) {
String tag = (String) v.getTag()
if (tag != null && tag.equals("doFeedbackView")) {
DoScreenShot.shoot((Activity) mContext)
Intent intent = new Intent(mContext, ScreenShotActivity.class)
mContext.startActivity(intent)
}
dialog.dismiss()
}
}