public class MyFragmentActivity extends FragmentActivity {
    private FragmentManager fm ;
    private FragmentTransaction ft;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment);
        fm = getFragmentManager();
        ft = fm.beginTransaction();
        ft.replace(R.id.framelayout, new Fl(),fm.getClass().getName());
        ft.addToBackStack(null);
        ft.commitAllowingStateLoss();

    }
} public class TransitionHomeActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transition_home);
    }

    public void simpleSharedElementTransition(View view) {
        Intent intent = new Intent(this, SimpleSharedTransitionActivity.class);
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, findViewById(R.id.simple_shared), "test");
        startActivity(intent, options.toBundle());

    }

    public void customSharedElementTransition(View view) {
        Intent intent = new Intent(this, CustomSharedTransitionActivity.class);
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, findViewById(R.id.custom_shared), "custom");
        startActivity(intent, options.toBundle());
    }

    public void imgSharedElementTransition(View view) {
        Intent intent = new Intent(this, ImageSharedTransitionActivity.class);
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, findViewById(R.id.img_shared), "img");
        ActivityOptions options2 = ActivityOptions.makeScaleUpAnimation(view, view.getWidth() / 2, view.getHeight() / 2, 0, 0);
        ActivityOptions options3 = ActivityOptions.makeSceneTransitionAnimation(this);
        ActivityOptions options4 = ActivityOptions.makeThumbnailScaleUpAnimation(view, BitmapFactory.decodeResource(getResources(), R.mipmap.pic), view.getWidth() / 2, view.getHeight() / 2);
        startActivity(intent, options.toBundle());
//        overridePendingTransition(0, 0);
    }

    public void Palette(View view) {
        //在子线程可以使用同步操作
//        ImageView mImageView = (ImageView) findViewById(R.id.iv);
        final TextView mTextView = (TextView) findViewById(R.id.test);
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.mipmap.pic);

        Palette.generateAsync(bmp, new Palette.PaletteAsyncListener() {
            @Override
            public void onGenerated(Palette palette) {
                Palette.Swatch a = palette.getVibrantSwatch();//有活力
                Palette.Swatch b = palette.getDarkVibrantSwatch();//有活力 暗色
                Palette.Swatch c = palette.getLightVibrantSwatch();//有活力 亮色
                Palette.Swatch d = palette.getMutedSwatch();//柔和
                Palette.Swatch e = palette.getDarkMutedSwatch();//柔和 暗色
                Palette.Swatch f = palette.getLightMutedSwatch();//柔和 亮色 我们从以上颜色中可以获取到如下颜色值：
                int color1 = a.getBodyTextColor();//内容颜色
                int color2 = a.getTitleTextColor();//标题颜色
                int color3 = a.getRgb();//rgb颜色 </span>
                if(null != a) {
//                    mTextView.setBackgroundColor(swatch.getRgb());
                    mTextView.setTextColor(a.getRgb());
                }
            }
        });
    }
} public class ButtonRectangular extends TitleView {

    private Drawable bgEnabled;
    private Drawable bgDisenabled;

    private int colorEnabled;
    private int colorDisenabled;

    public ButtonRectangular(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    public ButtonRectangular(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public ButtonRectangular(Context context) {
        super(context);
    }


    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected View createView() {
        View view = View.inflate(getContext(), R.layout.button_rectangular_9_16, this);
        colorEnabled = getResources().getColor(R.color.FF3C00);
        colorDisenabled = getResources().getColor(R.color.AEAEAE);
        bgEnabled = getResources().getDrawable(R.drawable.ripple_bg_item, null);
        bgDisenabled = getResources().getDrawable(R.color.EEEEEE, null);
        return view;
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    public void setEnabled(boolean enabled){
        super.setEnabled(enabled);
        if(enabled){
            bg.setBackground(bgEnabled);
            textView.setTextColor(colorEnabled);
        }else{
            bg.setBackground(bgDisenabled);
            textView.setTextColor(colorDisenabled);
        }
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    public void setBackgroundEnabled(Drawable drawable){
        this.bgEnabled = drawable;
        if(isEnabled()){
            bg.setBackground(bgEnabled);
        }
    }

    public void setTextColorEnabled(int color){
        this.colorEnabled = color;
        if(isEnabled()){
            textView.setTextColor(colorEnabled);
        }
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    public void setBackgroundDisenabled(Drawable drawable){
        this.bgDisenabled = drawable;
        if(!isEnabled()){
            bg.setBackground(bgDisenabled);
        }
    }

    public void setTextColorDisennabled(int color){
        this.colorDisenabled = color;
        if(!isEnabled()){
            textView.setTextColor(colorDisenabled);
            RippleDrawable rd = null;
        }
    }

} public class ButtonRoundCorner extends TitleView {

    public ButtonRoundCorner(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    public ButtonRoundCorner(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public ButtonRoundCorner(Context context) {
        super(context);
    }

    @Override
    protected View createView() {
        View view = View.inflate(getContext(), R.layout.button_rounded_corrner_9_16, this);
        return view;
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    public void setBackgroundColor(int colorPressed, int colorNormal){
        StateListDrawable sd = new StateListDrawable();
        int[] state_pressed = new int[]{android.R.attr.state_pressed};
        int[] state_normal = new int[]{android.R.attr.state_enabled};

        GradientDrawable pressed = new GradientDrawable();
        pressed.setColor(colorPressed);
        pressed.setCornerRadius(10);

        GradientDrawable enable = new GradientDrawable();
        enable.setColor(colorNormal);
        enable.setCornerRadius(10);

        sd.addState(state_pressed, pressed);
        sd.addState(state_normal, enable);
        bg.setBackground(sd);
    }

    /**
     * invalid
     * @param drawable
     */
    @Deprecated
    public void setBackground(Drawable drawable) {
    }



} public class ButtonSwitch extends FrameLayout{
    protected Resources resources;
    protected Switch mSwitch;
    public ButtonSwitch(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }
    public ButtonSwitch(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
    public ButtonSwitch(Context context) {
        super(context);
        init();
    }

    protected View createView() {
        View view = View.inflate(getContext(), R.layout.button_switch_9_16, null);

        return view;
    }


    public void setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener listener){
        mSwitch.setOnCheckedChangeListener(listener);
    }
    public void setOnCheck(boolean isCheck){
        mSwitch.setChecked(isCheck);
    }

    public boolean isChecked(){
        return mSwitch.isChecked();
    }

    public void setWidth(int width){
        ViewGroup.LayoutParams layoutParams = mSwitch.getLayoutParams();
        layoutParams.width = width;
        mSwitch.setLayoutParams(layoutParams);
    }

    public void setHeight(int height){
        ViewGroup.LayoutParams layoutParams = mSwitch.getLayoutParams();
        layoutParams.height = height;
        mSwitch.setLayoutParams(layoutParams);
    }

    void init(){
        resources = getResources();
        View view = createView();
        this.addView(view);
        mSwitch = (Switch) view.findViewById(R.id.set_switch);
    }

    public void setOnTouch(OnTouchListener onTouchListener){
        mSwitch.setOnTouchListener(onTouchListener);
    }
} public class CodeDialog extends BaseDialog {

    private static CodeDialog instance;
    private TextView title, error;
    private ImageView code, clear, load;
    private EditText editText;

    // 是否正在请求
    private boolean isReq;

    public static CodeDialog getInstance() {
        if (instance == null) {
            instance = new CodeDialog();
        }
        return instance;
    }

    @Override
    protected void init() {
        title = (TextView) dialog.findViewById(R.id.txt);
        code = (ImageView) dialog.findViewById(R.id.code);
        editText = (EditText) dialog.findViewById(R.id.editText);
        clear = (ImageView) dialog.findViewById(R.id.clear);
        load = (ImageView) dialog.findViewById(R.id.load);
        error = (TextView) dialog.findViewById(R.id.txt_error);
        clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editText.setText("");
            }
        });
        error.setVisibility(View.GONE);
        load.setVisibility(View.GONE);
        clear.setVisibility(View.GONE);
    }

    public void setData(String titleString, String imgBase64, final CodeInputSuccess listener, View.OnClickListener incodeOnClickListener) {
        isReq = false;
        error.setVisibility(View.GONE);
        load.clearAnimation();
        load.setVisibility(View.GONE);
        clear.setVisibility(View.GONE);
        title.setText(titleString);
        code.setImageBitmap(BitmapUtil.stringtoBitmap(imgBase64));
        code.setOnClickListener(incodeOnClickListener);
        editText.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.length() > 0 && !isReq) {
                    load.clearAnimation();
                    load.setVisibility(View.GONE);
                    clear.setVisibility(View.VISIBLE);
                }
                if (listener != null && s.length() == 4 && !isReq) {
                    listener.codeInputSuccess(s.toString());
                }
                if (s.length() == 0 && !isReq) {
                    load.clearAnimation();
                    load.setVisibility(View.GONE);
                    clear.setVisibility(View.GONE);
                }
            }
        });
    }

    public void setImgCode(String imgBase64) {
        isReq = false;
        code.setImageBitmap(BitmapUtil.stringtoBitmap(imgBase64));
        load.clearAnimation();
        load.setVisibility(View.GONE);
        clear.setVisibility(View.GONE);
    }

    public void showError(String msg) {
        error.setText(msg);
        error.setVisibility(View.VISIBLE);
        load.clearAnimation();
        load.setVisibility(View.GONE);
        clear.setVisibility(View.GONE);
        editText.setText("");
    }

    public void hideError() {
        error.setVisibility(View.GONE);
    }

    public void hideLoad() {
        isReq = false;
        load.clearAnimation();
        load.setVisibility(View.GONE);
    }

    public void showLoad() {
        isReq = true;
        load.setVisibility(View.VISIBLE);
        clear.setVisibility(View.GONE);
        Animation operatingAnim = AnimationUtils.loadAnimation(dialog.getContext(), R.anim.loading_anim);
        LinearInterpolator lin = new LinearInterpolator();
        operatingAnim.setInterpolator(lin);
        load.setAnimation(operatingAnim);
        load.startAnimation(operatingAnim);
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }

    @Override
    protected void onDialogCancel() {
        load.clearAnimation();
    }

} public interface CodeInputSuccess {
    void codeInputSuccess(String code);
} public class HintOneBtnDialog extends BaseDialog {

    private static HintOneBtnDialog instance;

    public static HintOneBtnDialog getInstance(){
        if(instance==null){
            instance = new HintOneBtnDialog();
        }
        return instance;
    }


    @Override
    protected void init() {

    }

    @Override
    protected void onDialogCancel() {
        dialog = null;
        instance = null;
    }
} public class TextHintDialog extends BaseDialog {
    private static TextHintDialog instance;

    private TextHintDialog() {
    }


    public static TextHintDialog getInstance() {
        if (instance == null) {
            instance = new TextHintDialog();
        }
        return instance;
    }

    @Override
    protected void init() {

    }

    @Override
    protected void onDialogCancel() {
        dialog = null;
        instance = null;
    }
} public class EnterItem extends SettingItemView {
    public EnterItem(Context context) {
        super(context);
    }

    public EnterItem(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public EnterItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected View createView() {
        View view = View.inflate(getContext(), R.layout.view_setting_9_16,this);
        return view;
    }
} public class SwitchItem extends SettingItemView{

    protected ButtonSwitch buttonSwitch;
    public SwitchItem(Context context) {
        super(context);
    }

    public SwitchItem(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SwitchItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected View createView() {
        View view = View.inflate(getContext(), R.layout.view_switch_9_16, this);
        buttonSwitch = (ButtonSwitch) view.findViewById(R.id.set_switch);
        return view;
    }





    /**
     * 为buttonSwitch设置OnCheckedChangeListener
     * @param changeListener OnCheckChangeListener
     */
    public void setOncheckChangeListener(CompoundButton.OnCheckedChangeListener changeListener){
        buttonSwitch.setOnCheckedChangeListener(changeListener);
    }

    /**
     * 返回ButtonSwitch是否选中
     * @return
     */
    public boolean isChecked(){
        return buttonSwitch.isChecked();
    }

    /**
     * 设置ButtonSwitch是否选中
     * @param isCheck
     */
    public void setChecked(boolean isCheck){
        buttonSwitch.setOnCheck(isCheck);
    }


} public class Title extends TitleView {

    private View btnBack,reduce,add,menu,headBg;
    private ImageView imgBack,imgMenu,imgAdd,imgReduce;

    public Title(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public Title(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public Title(Context context) {
        super(context);
    }

    @Override
    protected View createView() {
        View view = adapterView();
        btnBack = view.findViewById(R.id.back);
        headBg = view.findViewById(R.id.bg);
        menu = view.findViewById(R.id.rel_menu);
        add = view.findViewById(R.id.rel_add);
        reduce = view.findViewById(R.id.rel_reduce);
        imgBack = (ImageView) view.findViewById(R.id.back_ib);
        imgMenu = (ImageView)view.findViewById(R.id.btn_menu);
        imgReduce = (ImageView)view.findViewById(R.id.btn_reduce);
        imgAdd = (ImageView)view.findViewById(R.id.btn_add);
        return view;
    }

    /**
     * 设置按钮的隐藏 （不设置，默认全部显示）true为隐藏，false为不隐藏
     */
    public void setButtonVisibility(boolean isHideBack,boolean isHideAdd,boolean isHideReduce,boolean isHideMenu){
        if(isHideAdd) {
            add.setVisibility(GONE);
        }else{
            add.setVisibility(VISIBLE);
        }
        if(isHideMenu) {
            menu.setVisibility(GONE);
        }else{
            menu.setVisibility(VISIBLE);
        }
        if(isHideReduce) {
            reduce.setVisibility(GONE);
        }else{
            reduce.setVisibility(VISIBLE);
        }
        if(isHideBack) {
            btnBack.setVisibility(GONE);
        }else{
            btnBack.setVisibility(VISIBLE);
        }
    }

    public void setAllWhite(){
        imgReduce.setImageResource(R.drawable.ic_j_white);
        imgAdd.setImageResource(R.drawable.ic_add_white);
        imgMenu.setImageResource(R.drawable.ic_more_white);
        imgBack.setImageResource(R.drawable.ic_back_white);
    }

    public void setAllBlack(){
        imgReduce.setImageResource(R.drawable.ic_j_black);
        imgAdd.setImageResource(R.drawable.ic_add_black);
        imgMenu.setImageResource(R.drawable.ic_more_black);
        imgBack.setImageResource(R.drawable.ic_back_black);
    }

    public void setImageViewBackDrawable(int drawable) {
        imgBack.setImageResource(drawable);
    }

    public void setImageViewMenuDrawable(int drawable){
        imgMenu.setImageResource(drawable);
    }

    public void setImageViewAddDrawable(int drawable){
        imgAdd.setImageResource(drawable);
    }

    public void setImageVireReduceDrawable(int drawable){
        imgReduce.setImageResource(drawable);
    }

    public void setMenuClickListener(OnClickListener listener4Back,OnClickListener listener4Add,OnClickListener listener4Reduce,OnClickListener listener4Menu){
        menu.setOnClickListener(listener4Menu);
        reduce.setOnClickListener(listener4Reduce);
        add.setOnClickListener(listener4Add);
        btnBack.setOnClickListener(listener4Back);
    }

    public void setHeadBgColor(int color) {
        headBg.setBackgroundColor(color);
    }

    private View adapterView() {
        switch (Adaptation.proportion) {
            case Adaptation.SCREEN_9_16:
                return View.inflate(getContext(), R.layout.title_9_16, this);
            case Adaptation.SCREEN_3_4:
                return View.inflate(getContext(), R.layout.title_9_16, this);
            case Adaptation.SCREEN_4_3:
                return View.inflate(getContext(), R.layout.title_16_9, this);
            case Adaptation.SCREEN_16_9:
                return View.inflate(getContext(), R.layout.title_16_9, this);
            default:
                return View.inflate(getContext(), R.layout.title_9_16, this);
        }
    }


} public class DialogCreater {

    public static HintDialog createHintDialog(Context context, int iconId, String textLeft, String textRight, String message, View.OnClickListener left, View.OnClickListener right,boolean isSystem) {
        HintDialog dialogProxy = HintDialog.getInstance();
        if (dialogProxy.hasDialog()) {
            return dialogProxy;
        }
        Dialog dialog = setHintDialogContentView(context);
        ImageView img = (ImageView) dialog.findViewById(R.id.img);
        img.setImageResource(iconId);
        TextView tvMsg = (TextView) dialog.findViewById(R.id.content);
        TextView btnLeft = (TextView) dialog.findViewById(R.id.left);
        TextView btnRight = (TextView) dialog.findViewById(R.id.right);
        tvMsg.setText(message);
        btnLeft.setText(textLeft);
        btnLeft.setOnClickListener(left);
        if(isSystem){
            dialogProxy.setSystemDialog(dialog);
        }else {
            dialogProxy.setDialog(dialog);
        }
        View line = dialog.findViewById(R.id.line2);

        if (TextUtils.isEmpty(textRight)) {
            btnRight.setVisibility(View.GONE);
            line.setVisibility(View.GONE);
            if (Adaptation.proportion == Adaptation.SCREEN_9_16) {
                btnLeft.setBackgroundResource(R.drawable.ripple_bg_bottom);
            } else if (Adaptation.proportion == Adaptation.SCREEN_16_9) {
                btnLeft.setBackgroundResource(R.drawable.ripple_bg_bottom_t1);
            }

            btnLeft.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 2));
        } else {
            btnRight.setVisibility(View.VISIBLE);
            line.setVisibility(View.VISIBLE);
            if (Adaptation.proportion == Adaptation.SCREEN_9_16) {
                btnLeft.setBackgroundResource(R.drawable.ripple_bg_left_bottom);
            } else if (Adaptation.proportion == Adaptation.SCREEN_16_9) {
                btnLeft.setBackgroundResource(R.drawable.ripple_bg_left_bottom_t1);
            }
            btnRight.setText(textRight);
            btnRight.setOnClickListener(right);
        }
        return dialogProxy;
    }

    public static TextHintDialog createTextHintDialog(Context context, String title, String textLeft, String textRight, String message, View.OnClickListener left, View.OnClickListener right,boolean isSystem) {
        TextHintDialog dialogProxy = TextHintDialog.getInstance();
        if (dialogProxy.hasDialog()) {
            return dialogProxy;
        }
        Dialog dialog = setTextHintDialogContentView(context);
        TextView tvTitle = (TextView) dialog.findViewById(R.id.dialog_title);
        TextView tvMsg = (TextView) dialog.findViewById(R.id.dialog_msg);
        TextView btnLeft = (TextView) dialog.findViewById(R.id.left);
        TextView btnRight = (TextView) dialog.findViewById(R.id.right);
        if(TextUtils.isEmpty(title)){
            tvTitle.setVisibility(View.GONE);
        }else {
            tvTitle.setVisibility(View.VISIBLE);
            tvTitle.setText(title);
        }
        tvMsg.setText(message);
        btnLeft.setText(textLeft);
        btnLeft.setOnClickListener(left);
        if(isSystem){
            dialogProxy.setSystemDialog(dialog);
        }else {
            dialogProxy.setDialog(dialog);
        }
        View line = dialog.findViewById(R.id.line_view);

        if (TextUtils.isEmpty(textRight)) {
            btnRight.setVisibility(View.GONE);
            line.setVisibility(View.GONE);
            if (Adaptation.proportion == Adaptation.SCREEN_9_16) {
                btnLeft.setBackgroundResource(R.drawable.ripple_bg_bottom);
            } else if (Adaptation.proportion == Adaptation.SCREEN_16_9) {
                btnLeft.setBackgroundResource(R.drawable.ripple_bg_bottom_t1);
            }
            btnLeft.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 2));
        } else {
            btnRight.setVisibility(View.VISIBLE);
            line.setVisibility(View.VISIBLE);
            if (Adaptation.proportion == Adaptation.SCREEN_9_16) {
                btnLeft.setBackgroundResource(R.drawable.ripple_bg_left_bottom);
            } else if (Adaptation.proportion == Adaptation.SCREEN_16_9) {
                btnLeft.setBackgroundResource(R.drawable.ripple_bg_left_bottom_t1);
            }
            btnRight.setText(textRight);
            btnRight.setOnClickListener(right);
        }
        return dialogProxy;
    }


    public static EditTextDialog createEditTextDialog(Context context, String textLeft, String textRight, String title, View.OnClickListener left, View.OnClickListener right) {
        EditTextDialog dialogProxy = EditTextDialog.getInstance();
        if (dialogProxy.hasDialog()) {
            return dialogProxy;
        }
        Dialog dialog = setEditTextDialogContentView(context);
        TextView tvMsg = (TextView) dialog.findViewById(R.id.title);
        TextView btnLeft = (TextView) dialog.findViewById(R.id.left);
        TextView btnRight = (TextView) dialog.findViewById(R.id.right);
        tvMsg.setText(title);
        btnLeft.setText(textLeft);
        btnRight.setText(textRight);
        btnLeft.setOnClickListener(left);
        btnRight.setOnClickListener(right);
        dialog.findViewById(R.id.clear).setVisibility(View.INVISIBLE);
        dialogProxy.setDialog(dialog);
        return dialogProxy;
    }

    public static EditPwdDialog createEditPwdDialog(Context context, String textLeft, String textRight, String title, View.OnClickListener left, View.OnClickListener right) {
        EditPwdDialog dialogProxy = EditPwdDialog.getInstance();
        if (dialogProxy.hasDialog()) {
            return dialogProxy;
        }
        Dialog dialog = setEditPwdDialogContentView(context);
        TextView tvMsg = (TextView) dialog.findViewById(R.id.title);
        TextView btnLeft = (TextView) dialog.findViewById(R.id.left);
        TextView btnRight = (TextView) dialog.findViewById(R.id.right);
        tvMsg.setText(title);
        btnLeft.setText(textLeft);
        btnRight.setText(textRight);
        btnLeft.setOnClickListener(left);
        btnRight.setOnClickListener(right);
        dialogProxy.setDialog(dialog);
        return dialogProxy;
    }

    public static ListDialog createListDialog(Context context, String title, String cancel, String[] items) {
        ListDialog dialogProxy = ListDialog.getInstance();
        if (dialogProxy.hasDialog()) {
            return dialogProxy;
        }
        Dialog dialog = setListDialogContentView(context);
        TextView tvMsg = (TextView) dialog.findViewById(R.id.title);
        tvMsg.setText(title);
        TextView tvCancel = (TextView) dialog.findViewById(R.id.btn_cancel);
        tvCancel.setText(cancel);
        dialogProxy.setDialog(dialog);
        dialogProxy.setData(items);
        return dialogProxy;
    }

    public static LoadingDialog createLoadingDialog(Context context, String msg) {
        LoadingDialog dialogProxy = LoadingDialog.getInstance();
        if (dialogProxy.hasDialog()) {
            return dialogProxy;
        }
        Dialog dialog = setLoadingDialogContentView(context);
        TextView tvMsg = (TextView) dialog.findViewById(R.id.msg);
        tvMsg.setText(msg);
        dialogProxy.setDialog(dialog);
        return dialogProxy;
    }

    public static HintOneBtnDialog createHintOneBtnDialog(Context context, String head, String msg, String cancel, View.OnClickListener cancelClickListener) {
        HintOneBtnDialog hintOneBtnDialog = HintOneBtnDialog.getInstance();
        if (hintOneBtnDialog.hasDialog()) {
            return hintOneBtnDialog;
        }
        Dialog dialog = setHintOneBtnDialogContentView(context);
        TextView head1 = (TextView) dialog.findViewById(R.id.head);
        TextView msg1 = (TextView) dialog.findViewById(R.id.msg);
        TextView btn = (TextView) dialog.findViewById(R.id.btnTxt);
        if (TextUtils.isEmpty(head)) {
            head1.setVisibility(View.GONE);
        } else {
            head1.setVisibility(View.VISIBLE);
            head1.setText(head);
        }
        if (TextUtils.isEmpty(msg)) {
            msg1.setVisibility(View.GONE);
        } else {
            msg1.setVisibility(View.VISIBLE);
            msg1.setText(msg);
        }
        if (TextUtils.isEmpty(cancel)) {
            btn.setVisibility(View.GONE);
        } else {
            btn.setVisibility(View.VISIBLE);
            btn.setText(cancel);
        }
        btn.setOnClickListener(cancelClickListener);
        hintOneBtnDialog.setDialog(dialog);
        return hintOneBtnDialog;
    }


    private static Dialog setHintOneBtnDialogContentView(Context context) {
        switch (Adaptation.proportion) {
            case Adaptation.SCREEN_9_16:
                String model = Build.MODEL;
                if(model.contains("m1")||model.contains("M1")){
                    return getDialog(context, R.layout.dialog_hint_one_btn_9_16_m1);
                }else {
                    return getDialog(context, R.layout.dialog_hint_one_btn_9_16);
                }
            case Adaptation.SCREEN_3_4:
                break;
            case Adaptation.SCREEN_4_3:
                break;
            case Adaptation.SCREEN_16_9:
                return getDialog(context, R.layout.dialog_hint_one_btn_16_9);
            default:
                return getDialog(context, R.layout.dialog_hint_one_btn_16_9);
        }
        return null;
    }


	public static CodeDialog createCodeDialog(Context context){
		final CodeDialog codeDialog = CodeDialog.getInstance();

		if(codeDialog.hasDialog()){
			return codeDialog;
		}
		Dialog dialog = setCodeDialogContentView(context);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(true);
		codeDialog.setDialog(dialog);
		return codeDialog;
	}

	private static Dialog setCodeDialogContentView(Context context){
		switch (Adaptation.proportion){
			case Adaptation.SCREEN_9_16:
                String model = Build.MODEL;
                if (model.contains("M1") || model.contains("m1")) {
                    return getDialog(context, R.layout.dialog_code_9_16_m1);
                }else {
                    return getDialog(context, R.layout.dialog_code_9_16);
                }
			case Adaptation.SCREEN_3_4:
				return getDialog(context, R.layout.dialog_code_9_16);
			case Adaptation.SCREEN_4_3:
				return getDialog(context, R.layout.dialog_code_16_9);
			case Adaptation.SCREEN_16_9:
				return getDialog(context, R.layout.dialog_code_16_9);
			default:
				return getDialog(context, R.layout.dialog_code_9_16);
		}
	}

    private static Dialog getDialog(Context context, int layoutId) {
        Dialog dialog = new Dialog(context, R.style.defaultDialogStyle);
        dialog.setContentView(layoutId);
        dialog.getWindow().getAttributes().gravity = Gravity.CENTER; //居中
        dialog.setCanceledOnTouchOutside(true); //点击空白不取消
        dialog.setCancelable(false); //点击返回按钮不取消
        return dialog;
    }


    private static Dialog setEditPwdDialogContentView(Context context) {
        switch (Adaptation.proportion) {
            case Adaptation.SCREEN_9_16:
                String model = Build.MODEL;
                if(model.contains("M1")||model.equals("m1")){
                    return getDialog(context, R.layout.dialog_edit_pwd_9_16_m1);
                }else {
                    return getDialog(context, R.layout.dialog_edit_pwd_9_16);
                }
            case Adaptation.SCREEN_3_4:
                break;
            case Adaptation.SCREEN_4_3:
                break;
            case Adaptation.SCREEN_16_9:
                return getDialog(context, R.layout.dialog_edit_pwd_16_9);
        }
        return null;
    }

    private static Dialog setEditTextDialogContentView(Context context) {
        switch (Adaptation.proportion) {
            case Adaptation.SCREEN_9_16:
                String model = Build.MODEL;
                if(model.contains("m1")||model.contains("M1")){
                    return getDialog(context, R.layout.dialog_edit_text_9_16_m1);
                }else {
                    return getDialog(context, R.layout.dialog_edit_text_9_16);
                }
            case Adaptation.SCREEN_3_4:
                break;
            case Adaptation.SCREEN_4_3:
                break;
            case Adaptation.SCREEN_16_9:
                return getDialog(context, R.layout.dialog_edit_text_16_9);
        }
        return null;
    }

    private static Dialog setListDialogContentView(Context context) {
        switch (Adaptation.proportion) {
            case Adaptation.SCREEN_9_16:
                return getDialog(context, R.layout.dialog_item_select_9_16);
            case Adaptation.SCREEN_3_4:
                break;
            case Adaptation.SCREEN_4_3:
                break;
            case Adaptation.SCREEN_16_9:
                return getDialog(context, R.layout.dialog_item_select_16_9);
        }
        return null;
    }

    private static Dialog setLoadingDialogContentView(Context context) {
        switch (Adaptation.proportion) {
            case Adaptation.SCREEN_9_16:
                return getDialog(context, R.layout.dialog_loading_9_16);
            case Adaptation.SCREEN_3_4:
                return getDialog(context, R.layout.dialog_loading_9_16);
            case Adaptation.SCREEN_4_3:
                return getDialog(context, R.layout.dialog_loading_16_9);
            case Adaptation.SCREEN_16_9:
                return getDialog(context, R.layout.dialog_loading_16_9);
            default:
                return getDialog(context, R.layout.dialog_loading_9_16);
        }
    }

    private static Dialog setHintDialogContentView(Context context) {
        switch (Adaptation.proportion) {
            case Adaptation.SCREEN_9_16:
                String model = Build.MODEL;
                if(model.contains("M1")||model.contains("m1")){
                    return getDialog(context, R.layout.dialog_hint_9_16_m1);
                }else {
                    return getDialog(context, R.layout.dialog_hint_9_16);
                }
            case Adaptation.SCREEN_3_4:
                return getDialog(context, R.layout.dialog_hint_9_16);
            case Adaptation.SCREEN_16_9:
                return getDialog(context, R.layout.dialog_hint_16_9);
            case Adaptation.SCREEN_4_3:
                return getDialog(context, R.layout.dialog_hint_16_9);
            default:
                return getDialog(context, R.layout.dialog_hint_9_16);
        }
    }

    private static Dialog setTextHintDialogContentView(Context context) {
        switch (Adaptation.proportion) {
            case Adaptation.SCREEN_9_16:
                String modle = Build.MODEL;
                if(modle.contains("m1")||modle.contains("M1")){
                    return getDialog(context, R.layout.dialog_text_hint_9_16_m1);
                }else {
                    return getDialog(context, R.layout.dialog_text_hint_9_16);
                }
            case Adaptation.SCREEN_3_4:
                return getDialog(context, R.layout.dialog_text_hint_9_16);
            case Adaptation.SCREEN_4_3:
                return getDialog(context, R.layout.dialog_text_hint_4_3);
            case Adaptation.SCREEN_16_9:
                return getDialog(context, R.layout.dialog_text_hint_4_3);
            default:
                return getDialog(context, R.layout.dialog_text_hint_9_16);
        }
    }

} public class EditPwdDialog extends BaseEditDialog {

    public static final String TAG = "EditPwdDialog";

    private static EditPwdDialog instance;

    private ImageView eye;
    private View eyeRegion;
    private TextView error;
    private Drawable eyeNo;
    private Drawable eyeYes;
    private boolean pwdVisible = false;
    private RelativeLayout clear;

    private EditPwdDialog() {
    }


    public static EditPwdDialog getInstance(){
        if(instance == null){
            instance = new EditPwdDialog();
        }
        return instance;
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void init() {
        eyeNo = resources.getDrawable(R.drawable.eye_no, null);
        eyeYes = resources.getDrawable(R.drawable.eye_yes, null);
        error = (TextView) dialog.findViewById(R.id.error);
        editText = (EditText) dialog.findViewById(R.id.edit);
        eye = (ImageView) dialog.findViewById(R.id.eye);
        eyeRegion = dialog.findViewById(R.id.eye_region);
        clear = (RelativeLayout) dialog.findViewById(R.id.rel_clear);
        clear.setVisibility(View.GONE);
        clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editText.setText("");
            }
        });
        eyeRegion.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(pwdVisible){
                    pwdVisible = false;
                    eye.setImageDrawable(eyeNo);
                    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                }else{
                    pwdVisible = true;
                    eye.setImageDrawable(eyeYes);
                    editText.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                }
                editText.setSelection(editText.getText().length());
                Log.d(TAG, "onClick:"+pwdVisible);
            }
        });

        editText.addTextChangedListener(textWatcher);
    }


    TextWatcher textWatcher = new TextWatcher(){
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int start, int count, int after) {
                error.setVisibility(View.INVISIBLE);
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if(editable.length()>0){
                clear.setVisibility(View.VISIBLE);
            }else{
                clear.setVisibility(View.GONE);
            }
        }
    };

    /**
     * show error
     * @param errorText
     */
    public void showError(String errorText){
        error.setText(errorText);
        error.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onDialogCancel() {
        editText.setText("");
        instance = null;
    }

} public class EditTextDialog extends BaseEditDialog {

    private static EditTextDialog instance;

    private View clear;

    private EditTextDialog() {
    }


    public static EditTextDialog getInstance(){
        if(instance == null){
            instance = new EditTextDialog();
        }
        return instance;
    }

    @Override
    protected void init() {
        editText = (EditText) dialog.findViewById(R.id.edit);
        clear = dialog.findViewById(R.id.clear);
        editText.addTextChangedListener(textWatcher);
        clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                editText.setText("");
            }
        });
    }

    @Override
    protected void onDialogCancel() {
        editText.setText("");
        instance = null;
    }

    TextWatcher textWatcher = new TextWatcher(){
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int start, int count, int after) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            if(editable.length()>0){
                clear.setVisibility(View.VISIBLE);
            }else{
                clear.setVisibility(View.INVISIBLE);
            }
        }
    };

    /**
     * 设置输入框的文字
     * @param content
     */
    public void setText(String content){
        editText.setText(content);
    }


} public class HintDialog extends BaseDialog {

    private static HintDialog instance;

    private HintDialog() {

    }

    public static HintDialog getInstance() {
        if (instance == null) {
            instance = new HintDialog();
        }
        return instance;
    }

    @Override
    protected void init() {

    }

    @Override
    protected void onDialogCancel() {
        dialog = null;
        instance = null;
    }

} public class ListDialog extends BaseDialog {

    private static ListDialog instance;

    private LinearLayout list;

    private ScrollView scrollView;

    private ItemClickListener itemClickListener;

    private ListDialog() {
    }

    public static ListDialog getInstance(){
        if(instance == null){
            instance = new ListDialog();
        }
        return instance;
    }

    public void setItemClickListener(ItemClickListener listener){
        this.itemClickListener = listener;
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void init() {
        scrollView = (ScrollView) dialog.findViewById(R.id.scrollView);
        list = (LinearLayout) dialog.findViewById(R.id.list);
        View cancel =  dialog.findViewById(R.id.btn_cancel);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cancel();
            }
        });
    }

    @Override
    protected void onDialogCancel() {
        dialog = null;
        instance = null;
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    public void setData(String[] items){
        list.removeAllViews();
        float itemHeight = getHeight();
        LogUtil.d("ListDialog",itemHeight+"");
        ViewGroup.LayoutParams layoutParams = (ViewGroup.LayoutParams) scrollView.getLayoutParams();
        int height = 0;
        for(int i=0;i<items.length;i++){
            String itemStr = items[i];
            View view = inflatView();
            TextView text = (TextView) view.findViewById(R.id.text);
            text.setText(itemStr);
            view.setTag(i);
            view.setOnClickListener(new ItemClick());
            list.addView(view);
            if(i<=3){
                height+=itemHeight;
            }

        }
        layoutParams.height = height + 10;
        scrollView.setLayoutParams(layoutParams);
    }

    class ItemClick implements View.OnClickListener{

        @Override
        public void onClick(View view) {
            int pos = (int) view.getTag();
            if(itemClickListener!=null){
                itemClickListener.OnItemClick(pos);
            }
        }
    }

    public interface ItemClickListener{
        void OnItemClick(int position);
    }

    private  float getHeight() {
        switch (Adaptation.proportion) {
            case Adaptation.SCREEN_9_16:
                return resources.getDimension(R.dimen.itemHeight);
            case Adaptation.SCREEN_3_4:
                break;
            case Adaptation.SCREEN_4_3:
                break;
            case Adaptation.SCREEN_16_9:
                return resources.getDimension(R.dimen.itemHeightT1);
        }
        return 0;
    }

    private View inflatView(){
        switch (Adaptation.proportion) {
            case Adaptation.SCREEN_9_16:
                return View.inflate(dialog.getContext(), R.layout.item_text_9_16, null);
            case Adaptation.SCREEN_3_4:
                break;
            case Adaptation.SCREEN_4_3:
                break;
            case Adaptation.SCREEN_16_9:
                return View.inflate(dialog.getContext(), R.layout.item_text_16_9, null);
        }
        return null;
    }
} public class LoadingDialog extends BaseDialog {

    private static LoadingDialog instance;
    private TextView loadingMsg;
    private View loadingProgress;
    private LoadingDialog() {
    }


    public static LoadingDialog getInstance(){
        if(instance == null){
            instance = new LoadingDialog();
        }
        return instance;
    }

    @Override
    protected void init() {
        loadingProgress = dialog.findViewById(R.id.progress);
        loadingMsg = (TextView) dialog.findViewById(R.id.msg);
    }

    @Override
    protected void onDialogCancel() {
        dialog = null;
        instance = null;
    }

    @Override
    public void show() {
        super.show();
        if(dialog!=null&&dialog.getContext()!=null) {
            Animation operatingAnim = AnimationUtils.loadAnimation(dialog.getContext(), R.anim.loading_anim);
            LinearInterpolator lin = new LinearInterpolator();
            operatingAnim.setInterpolator(lin);
            loadingProgress.setAnimation(operatingAnim);
            loadingProgress.startAnimation(operatingAnim);
        }
    }

    public void setLoadingMsgSize(int size){
        loadingMsg.setTextSize(TypedValue.COMPLEX_UNIT_SP,size);
    }
} public class TitleHead extends FrameLayout{

    private View mView;
    private TextView title;

    public TitleHead(Context context) {
        super(context);
        init();
    }

    public TitleHead(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public TitleHead(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){
        mView = getView();
        title = (TextView) mView.findViewById(R.id.txt);
    }

    private View getView(){
        switch (Adaptation.proportion) {
            case Adaptation.SCREEN_9_16:
                return View.inflate(getContext(), R.layout.title_head_9_16, this);
            case Adaptation.SCREEN_3_4:
                return View.inflate(getContext(), R.layout.title_head_9_16, this);
            case Adaptation.SCREEN_4_3:
                return View.inflate(getContext(), R.layout.title_head_16_9, this);
            case Adaptation.SCREEN_16_9:
                return View.inflate(getContext(), R.layout.title_head_16_9, this);
            default:
                return View.inflate(getContext(), R.layout.title_head_9_16, this);
        }
    }

    public void setTextColor(int color){
        title.setTextColor(color);
    }

    public void setBackground(int res){
        mView.setBackgroundColor(res);
    }
} public class Adaptation {

    public static int screenHeight = 0;
    public static int screenWidth = 0;
    public static float screenDensity = 0;
    public static int densityDpi = 0;
    // public static int version = Integer.valueOf(android.os.Build.VERSION.SDK_INT);

    public static final int SCREEN_9_16 = 1;    // 9:16
    public static final int SCREEN_3_4 = 2;     // 3:4
    public static final int SCREEN_4_3 = 3;     // 4:3
    public static final int SCREEN_16_9 = 4;    // 16:9
    public static int proportion = SCREEN_9_16;

    // public static final float PROPORTION_9_16 = 0.56f;    // 9:16
    // public static final float PROPORTION_3_4 = 0.75f;     // 3:4
    // public static final float PROPORTION_4_3 = 1.33f;     // 4:3
    // public static final float PROPORTION_16_9 = 1.77f;    // 16:9

    public static final float AVERAGE1 = 0.655f;    // (9:16+3:4)/2
    public static final float AVERAGE2 = 1.04f;     // (3:4+4:3)/2
    public static final float AVERAGE3 = 1.55f;     // (4:3+16:9)/2

    public static void init(Context context) {
        if (screenDensity == 0 || screenWidth == 0 || screenHeight == 0) {
            DisplayMetrics dm = new DisplayMetrics();
            WindowManager wm = (WindowManager) context
                    .getSystemService(Context.WINDOW_SERVICE);
            wm.getDefaultDisplay().getMetrics(dm);
            Adaptation.screenDensity = dm.density;
            Adaptation.screenHeight = dm.heightPixels;
            Adaptation.screenWidth = dm.widthPixels;
            Adaptation.densityDpi = dm.densityDpi;
        }

        float proportionF = (float) screenWidth / (float) screenHeight;

        if (proportionF <= AVERAGE1) {
            proportion = SCREEN_9_16;
        } else if (proportionF <= AVERAGE2) {
            proportion = SCREEN_3_4;
        } else if (proportionF <= AVERAGE3) {
            proportion = SCREEN_4_3;
        } else if (proportionF > AVERAGE3) {
            proportion = SCREEN_16_9;
        }

        Log.i("SCREEN CONFIG", "screenHeight:" + screenHeight + ";screenWidth:"
                + screenWidth + ";screenDensity:" + screenDensity
                + ";densityDpi:" + densityDpi);

    }

} public class VersionView {

    private Context mContext;
    private WindowManager windowManager;// 用于可拖动的浮动窗口
    private WindowManager.LayoutParams windowParams;// 浮动窗口的参数
    private TextView mText;
    //是否被添加过
    private boolean isAdded = false;

    public VersionView(Context mContext) {
        this.mContext = mContext;
        initView();
    }

    private void initView() {
        mText = new TextView(mContext);
        mText.setText("release");
        mText.setTextColor(Color.parseColor("#ffffff"));
        mText.setWidth(80);
        mText.setHeight(50);
        mText.setGravity(Gravity.CENTER);
        mText.setBackgroundColor(Color.parseColor("#cc000000"));
        if (windowManager == null) {
            setWindowParams(0, 0);
            windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        }
    }

    /**
     * 显示
     */
    public void showInfo(String info) {
        mText.setText("" + info);
        if (!isAdded) {
            windowManager.addView(mText, windowParams);
            isAdded = true;
        }
    }

    /**
     * 隐藏
     */
    public void hide() {
        if (windowManager != null && mText != null && isAdded) {
            windowManager.removeView(mText);
            isAdded = false;
        }
    }

    private void setWindowParams(int x, int y) {
        // 建立item的缩略图
        windowParams = new WindowManager.LayoutParams();
        windowParams.gravity = Gravity.BOTTOM | Gravity.RIGHT;// 这个必须加
        // 得到preview左上角相对于屏幕的坐标
        windowParams.x = x;
        windowParams.y = y;
        // 设置宽和高
        windowParams.width = 80;
        windowParams.height = 50;
        windowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
        windowParams.format = PixelFormat.TRANSLUCENT;
        windowParams.windowAnimations = 0;
    }
}
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Toast;
import sunmi.sunmidesign.fragment.MyFragmentActivity;
import sunmi.sunmidesign.transitions.TransitionHomeActivity;
import sunmi.sunmiui.button.ButtonRectangular;
import sunmi.sunmiui.button.ButtonRoundCorner;
import sunmi.sunmiui.button.ButtonSwitch;
import sunmi.sunmiui.dialog.CodeDialog;
import sunmi.sunmiui.dialog.CodeInputSuccess;
import sunmi.sunmiui.dialog.HintOneBtnDialog;
import sunmi.sunmiui.dialog.TextHintDialog;
import sunmi.sunmiui.title.EnterItem;
import sunmi.sunmiui.title.SwitchItem;
import sunmi.sunmiui.title.Title;
import sunmi.sunmiui.dialog.DialogCreater;
import sunmi.sunmiui.dialog.EditPwdDialog;
import sunmi.sunmiui.dialog.EditTextDialog;
import sunmi.sunmiui.dialog.HintDialog;
import sunmi.sunmiui.dialog.ListDialog;
import sunmi.sunmiui.dialog.LoadingDialog;
import sunmi.sunmiui.title.TitleHead;
import sunmi.sunmiui.utils.Adaptation;
import sunmi.sunmiui.window.VersionView;
package sunmi.sunmidesign;



public class MainActivity extends Activity {
    TextHintDialog textHintDialog;
    HintDialog dialog;
    EditTextDialog editTextDialog;
    EditPwdDialog editPwdDialog;
    ListDialog listDialog;
    LoadingDialog loadingDialog;
    SwitchItem switchButtonView;
    Title title;
    CodeDialog codeDialog;
    ButtonSwitch buttonSwitch;
    ButtonRectangular buttonRectangular;
    ButtonRoundCorner buttonRoundCorner;
    EnterItem enterItem;