package com.camnter.newlife.widget;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.TextView;

import com.camnter.newlife.R;

/**
 * Description：CustomDialog
 * Created by：CaMnter
 * Time：2015-12-10 14:38
 */
public class MenuDialog extends Dialog {

    private TextView caseTV;
    private TextView helpTV;

    public MenuDialog(Context context) {
        super(context, R.style.menu_dialog);
        this.initViews(context);
    }

    /**
     * Creates a dialog window that uses a custom dialog style.
     * <p/>
     * The supplied {@code context} is used to obtain the window manager and
     * base theme used to present the dialog.
     * <p/>
     * The supplied {@code theme} is applied on top of the context's theme. See
     * <a href="{@docRoot}guide/topics/resources/available-resources.html#stylesandthemes">
     * Style and Theme Resources</a> for more information about defining and
     * using styles.
     *
     * @param context    the context in which the dialog should run
     * @param themeResId a style resource describing the theme to use for the
     *                   window, or {@code 0} to use the default dialog theme
     */
    public MenuDialog(Context context, int themeResId) {
        super(context, themeResId);
        this.initViews(context);
    }

    public MenuDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.initViews(context);
    }

    private void initViews(Context context) {
        this.setContentView(R.layout.dialog_menu);
        this.caseTV = (TextView) this.findViewById(R.id.dialog_menu_case_tv);
        this.helpTV = (TextView) this.findViewById(R.id.dialog_menu_help_tv);
    }


    public void setTextDrawable(Drawable drawable) {
        if (drawable == null) return;
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
    }

    public static class DialogBuilder {
        private static String contextHashCode;
        private static MenuDialog dialog;
        public static DialogBuilder ourInstance;

        public static DialogBuilder getInstance(Context context) {
            if (ourInstance == null) ourInstance = new DialogBuilder();
            String hashCode = String.valueOf(context.hashCode());
            /**
             * 不同一个Activity
             */
            if (!hashCode.equals(String.valueOf(contextHashCode))) {
                contextHashCode = hashCode;
                dialog = new MenuDialog(context);
            }
            return ourInstance;
        }

        public DialogBuilder setCaseListenser(View.OnClickListener listener) {
            dialog.caseTV.setOnClickListener(listener);
            return this;
        }

        public DialogBuilder setHelpListener(View.OnClickListener listener) {
            dialog.helpTV.setOnClickListener(listener);
            return this;
        }

        public DialogBuilder setCanceledOnTouchOutside(boolean cancel) {
            dialog.setCanceledOnTouchOutside(cancel);
            return this;
        }

        public MenuDialog getDialog() {
            return dialog;
        }

    }

}
@@ -136,34 +136,8 @@
 le;%0A
-import android.view.View;%0A
 impo
@@ -2007,1258 +2007,6 @@
  %7D%0A%0A
-    public static class DialogBuilder %7B%0A        private static String contextHashCode;%0A        private static MenuDialog dialog;%0A        public static DialogBuilder ourInstance;%0A%0A        public static DialogBuilder getInstance(Context context) %7B%0A            if (ourInstance == null) ourInstance = new DialogBuilder();%0A            String hashCode = String.valueOf(context.hashCode());%0A            /**%0A             * %E4%B8%8D%E5%90%8C%E4%B8%80%E4%B8%AAActivity%0A             */%0A            if (!hashCode.equals(String.valueOf(contextHashCode))) %7B%0A                contextHashCode = hashCode;%0A                dialog = new MenuDialog(context);%0A            %7D%0A            return ourInstance;%0A        %7D%0A%0A        public DialogBuilder setCaseListenser(View.OnClickListener listener) %7B%0A            dialog.caseTV.setOnClickListener(listener);%0A            return this;%0A        %7D%0A%0A        public DialogBuilder setHelpListener(View.OnClickListener listener) %7B%0A            dialog.helpTV.setOnClickListener(listener);%0A            return this;%0A        %7D%0A%0A        public DialogBuilder setCanceledOnTouchOutside(boolean cancel) %7B%0A            dialog.setCanceledOnTouchOutside(cancel);%0A            return this;%0A        %7D%0A%0A        public MenuDialog getDialog() %7B%0A            return dialog;%0A        %7D%0A%0A    %7D%0A
 %0A%7D

update MenuDialog