Search in sources :

Example 1 with MDButton

use of com.afollestad.materialdialogs.internal.MDButton in project CoCoin by Nightonke.

the class AccountBookSettingActivity method userRegister.

private void userRegister() {
    registerDialog = new MaterialDialog.Builder(this).title(R.string.go_register).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).customView(R.layout.dialog_user_register, true).build();
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    registerDialogView = registerDialog.getCustomView();
    registerDialogButton = (CircularProgressButton) registerDialogView.findViewById(R.id.button);
    registerDialogButton.setTypeface(CoCoinUtil.GetTypeface());
    registerDialogButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            registerDialogButton.setProgress(1);
            registerDialog.setCancelable(false);
            // User register, a new user////////////////////////////////////////////////////////////////////////
            final User user = new User();
            // basic info
            user.setUsername(registerUserName.getText().toString());
            user.setPassword(registerPassword.getText().toString());
            user.setEmail(registerUserEmail.getText().toString());
            user.setAndroidId(CoCoinApplication.getAndroidId());
            if (BuildConfig.DEBUG)
                Log.d("CoCoin", "Android Id: " + user.getAndroidId());
            // settings info
            // user.setLogo();
            user.setIsMonthLimit(SettingManager.getInstance().getIsMonthLimit());
            user.setMonthLimit(SettingManager.getInstance().getMonthLimit());
            user.setIsColorRemind(SettingManager.getInstance().getIsColorRemind());
            user.setMonthWarning(SettingManager.getInstance().getMonthWarning());
            user.setRemindColor(SettingManager.getInstance().getRemindColor());
            user.setIsForbidden(SettingManager.getInstance().getIsForbidden());
            user.setAccountBookName(SettingManager.getInstance().getAccountBookName());
            user.setAccountBookPassword(SettingManager.getInstance().getPassword());
            // Todo store tag order
            user.setShowPicture(SettingManager.getInstance().getShowPicture());
            user.setIsHollow(SettingManager.getInstance().getIsHollow());
            user.setLogoObjectId("");
            user.signUp(CoCoinApplication.getAppContext(), new SaveListener() {

                @Override
                public void onSuccess() {
                    registerDialogButton.setProgress(0);
                    registerDialog.setCancelable(true);
                    registerDialogButton.setIdleText(getResourceString(R.string.register_complete));
                    // if register successfully/////////////////////////////////////////////////////////////////////////
                    SettingManager.getInstance().setLoggenOn(true);
                    SettingManager.getInstance().setUserName(registerUserName.getText().toString());
                    SettingManager.getInstance().setUserEmail(registerUserEmail.getText().toString());
                    SettingManager.getInstance().setUserPassword(registerPassword.getText().toString());
                    showToast(4, registerUserName.getText().toString());
                    // if login successfully////////////////////////////////////////////////////////////////////////////
                    user.login(CoCoinApplication.getAppContext(), new SaveListener() {

                        @Override
                        public void onSuccess() {
                            SettingManager.getInstance().setTodayViewInfoShouldChange(true);
                            updateViews();
                        // use a new method
                        //                                RecordManager.updateOldRecordsToServer();
                        }

                        @Override
                        public void onFailure(int code, String msg) {
                        // if login failed//////////////////////////////////////////////////////////////////////////////////
                        }
                    });
                    final Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            if (registerDialog != null)
                                registerDialog.dismiss();
                            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, 0);
                        }
                    }, 500);
                }

                // if register failed///////////////////////////////////////////////////////////////////////////////
                @Override
                public void onFailure(int code, String msg) {
                    if (BuildConfig.DEBUG)
                        Log.d("CoCoin", "Register failed: " + msg);
                    String tip = getResourceString(R.string.network_disconnection);
                    if (msg.charAt(1) == 's')
                        tip = getResourceString(R.string.user_name_exist);
                    if (msg.charAt(0) == 'e')
                        tip = getResourceString(R.string.user_email_exist);
                    if (msg.charAt(1) == 'n')
                        tip = getResourceString(R.string.user_mobile_exist);
                    registerDialogButton.setIdleText(tip);
                    registerDialogButton.setProgress(0);
                    registerDialog.setCancelable(true);
                }
            });
        }
    });
    final MDButton positiveAction = registerDialog.getActionButton(DialogAction.POSITIVE);
    positiveAction.setEnabled(false);
    final EmailValidator emailValidator = new EmailValidator();
    TextView userNameTV = (TextView) registerDialog.getCustomView().findViewById(R.id.register_user_name_text);
    TextView userEmailTV = (TextView) registerDialog.getCustomView().findViewById(R.id.register_user_email_text);
    TextView userPasswordTV = (TextView) registerDialog.getCustomView().findViewById(R.id.register_password_text);
    userNameTV.setTypeface(CoCoinUtil.GetTypeface());
    userEmailTV.setTypeface(CoCoinUtil.GetTypeface());
    userPasswordTV.setTypeface(CoCoinUtil.GetTypeface());
    registerUserName = (MaterialEditText) registerDialog.getCustomView().findViewById(R.id.register_user_name);
    registerUserEmail = (MaterialEditText) registerDialog.getCustomView().findViewById(R.id.register_user_email);
    registerPassword = (MaterialEditText) registerDialog.getCustomView().findViewById(R.id.register_password);
    registerUserName.setTypeface(CoCoinUtil.GetTypeface());
    registerUserName.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) {
            boolean emailOK = emailValidator.validate(registerUserEmail.getText().toString());
            registerDialogButton.setEnabled(0 < registerUserName.getText().toString().length() && registerUserName.getText().toString().length() <= 16 && registerPassword.getText().toString().length() > 0 && emailOK);
            if (emailValidator.validate(registerUserEmail.getText().toString())) {
                registerUserEmail.validate();
            } else {
                registerUserEmail.invalidate();
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    registerUserEmail.setTypeface(CoCoinUtil.GetTypeface());
    registerUserEmail.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) {
            boolean emailOK = emailValidator.validate(registerUserEmail.getText().toString());
            registerDialogButton.setEnabled(0 < registerUserName.getText().toString().length() && registerUserName.getText().toString().length() <= 16 && registerPassword.getText().toString().length() > 0 && emailOK);
            if (emailValidator.validate(registerUserEmail.getText().toString())) {
                registerUserEmail.validate();
            } else {
                registerUserEmail.invalidate();
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    registerPassword.setTypeface(CoCoinUtil.GetTypeface());
    registerPassword.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) {
            boolean emailOK = emailValidator.validate(registerUserEmail.getText().toString());
            registerDialogButton.setEnabled(0 < registerUserName.getText().toString().length() && registerUserName.getText().toString().length() <= 16 && registerPassword.getText().toString().length() > 0 && emailOK);
            if (emailValidator.validate(registerUserEmail.getText().toString())) {
                registerUserEmail.validate();
            } else {
                registerUserEmail.invalidate();
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    registerDialog.show();
}
Also used : SaveListener(cn.bmob.v3.listener.SaveListener) MDButton(com.afollestad.materialdialogs.internal.MDButton) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) EmailValidator(com.nightonke.saver.util.EmailValidator) Handler(android.os.Handler) InputMethodManager(android.view.inputmethod.InputMethodManager) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) RiseNumberTextView(com.nightonke.saver.ui.RiseNumberTextView) View(android.view.View) TextView(android.widget.TextView) MaterialIconView(net.steamcrafted.materialiconlib.MaterialIconView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) RiseNumberTextView(com.nightonke.saver.ui.RiseNumberTextView) TextView(android.widget.TextView)

Example 2 with MDButton

use of com.afollestad.materialdialogs.internal.MDButton in project CoCoin by Nightonke.

the class AccountBookSettingActivity method userLogin.

private void userLogin() {
    loginDialog = new MaterialDialog.Builder(this).title(R.string.go_login).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).customView(R.layout.dialog_user_login, true).build();
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    loginDialogView = loginDialog.getCustomView();
    loginDialogButton = (CircularProgressButton) loginDialogView.findViewById(R.id.button);
    loginDialogButton.isIndeterminateProgressMode();
    loginDialogButton.setProgress(0);
    loginDialogButton.setTypeface(CoCoinUtil.GetTypeface());
    loginDialogButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            loginDialog.setCancelable(false);
            loginDialogButton.setProgress(1);
            // the user ask to login////////////////////////////////////////////////////////////////////////////
            final User user = new User();
            user.setUsername(loginUserName.getText().toString());
            user.setPassword(loginPassword.getText().toString());
            user.login(CoCoinApplication.getAppContext(), new SaveListener() {

                // try with user name///////////////////////////////////////////////////////////////////////////////
                @Override
                public void onSuccess() {
                    loginDialog.setCancelable(true);
                    loginDialogButton.setProgress(0);
                    loginDialogButton.setIdleText(getResourceString(R.string.login_complete));
                    // login successfully through user name/////////////////////////////////////////////////////////////
                    SettingManager.getInstance().setTodayViewInfoShouldChange(true);
                    User loginUser = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
                    if (!CoCoinApplication.getAndroidId().equals(loginUser.getAndroidId())) {
                        // 2 users on one mobile////////////////////////////////////////////////////////////////////////////
                        showToast(7, "unique...");
                        return;
                    }
                    SettingManager.getInstance().setLoggenOn(true);
                    SettingManager.getInstance().setUserName(loginUserName.getText().toString());
                    SettingManager.getInstance().setUserEmail(loginUser.getEmail());
                    updateViews();
                    // use a new method
                    //                        RecordManager.updateOldRecordsToServer();
                    whetherSyncSettingsFromServer();
                    showToast(6, loginUserName.getText().toString());
                    final Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            if (loginDialog != null)
                                loginDialog.dismiss();
                            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, 0);
                        }
                    }, 500);
                }

                // login fail through user name/////////////////////////////////////////////////////////////////////
                @Override
                public void onFailure(int code, String msg) {
                    // try with user email//////////////////////////////////////////////////////////////////////////////
                    user.setEmail(loginUserName.getText().toString());
                    user.login(CoCoinApplication.getAppContext(), new SaveListener() {

                        @Override
                        public void onSuccess() {
                            loginDialog.setCancelable(true);
                            loginDialogButton.setProgress(0);
                            loginDialogButton.setIdleText(getResourceString(R.string.login_complete));
                            // login successfully through user email////////////////////////////////////////////////////////////
                            SettingManager.getInstance().setTodayViewInfoShouldChange(true);
                            User loginUser = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
                            if (!CoCoinApplication.getAndroidId().equals(loginUser.getAndroidId())) {
                                // 2 users on one mobile////////////////////////////////////////////////////////////////////////////
                                showToast(7, "unique...");
                                return;
                            }
                            String userName = loginUser.getUsername();
                            SettingManager.getInstance().setLoggenOn(true);
                            SettingManager.getInstance().setUserName(userName);
                            SettingManager.getInstance().setUserEmail(loginUserName.getText().toString());
                            SettingManager.getInstance().setUserPassword(loginPassword.getText().toString());
                            updateViews();
                            // use a new method
                            //                                RecordManager.updateOldRecordsToServer();
                            whetherSyncSettingsFromServer();
                            showToast(6, userName);
                            final Handler handler = new Handler();
                            handler.postDelayed(new Runnable() {

                                @Override
                                public void run() {
                                    if (loginDialog != null)
                                        loginDialog.dismiss();
                                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                                    imm.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, 0);
                                }
                            }, 500);
                        }

                        // login fail through user name and email///////////////////////////////////////////////////////////
                        @Override
                        public void onFailure(int code, String msg) {
                            loginDialog.setCancelable(true);
                            loginDialogButton.setProgress(0);
                            String tip = getResourceString(R.string.network_disconnection);
                            if (msg.charAt(0) == 'u')
                                tip = getResourceString(R.string.user_name_or_password_incorrect);
                            if (msg.charAt(1) == 'n')
                                tip = getResourceString(R.string.user_mobile_exist);
                            loginDialogButton.setIdleText(tip);
                        }
                    });
                }
            });
        }
    });
    final MDButton positiveAction = loginDialog.getActionButton(DialogAction.POSITIVE);
    positiveAction.setEnabled(false);
    TextView userNameTV = (TextView) loginDialog.getCustomView().findViewById(R.id.login_user_name_text);
    TextView userPasswordTV = (TextView) loginDialog.getCustomView().findViewById(R.id.login_password_text);
    userNameTV.setTypeface(CoCoinUtil.GetTypeface());
    userPasswordTV.setTypeface(CoCoinUtil.GetTypeface());
    loginUserName = (MaterialEditText) loginDialog.getCustomView().findViewById(R.id.login_user_name);
    loginPassword = (MaterialEditText) loginDialog.getCustomView().findViewById(R.id.login_password);
    loginUserName.setTypeface(CoCoinUtil.GetTypeface());
    loginUserName.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) {
            loginDialogButton.setEnabled(0 < loginUserName.getText().toString().length() && 0 < loginPassword.getText().toString().length());
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    loginPassword.setTypeface(CoCoinUtil.GetTypeface());
    loginPassword.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) {
            loginDialogButton.setEnabled(0 < loginUserName.getText().toString().length() && 0 < loginPassword.getText().toString().length());
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    loginDialog.show();
}
Also used : SaveListener(cn.bmob.v3.listener.SaveListener) MDButton(com.afollestad.materialdialogs.internal.MDButton) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) Handler(android.os.Handler) InputMethodManager(android.view.inputmethod.InputMethodManager) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) RiseNumberTextView(com.nightonke.saver.ui.RiseNumberTextView) View(android.view.View) TextView(android.widget.TextView) MaterialIconView(net.steamcrafted.materialiconlib.MaterialIconView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) RiseNumberTextView(com.nightonke.saver.ui.RiseNumberTextView) TextView(android.widget.TextView)

Example 3 with MDButton

use of com.afollestad.materialdialogs.internal.MDButton in project material-dialogs by afollestad.

the class DialogInit method init.

@SuppressWarnings("ConstantConditions")
@UiThread
public static void init(final MaterialDialog dialog) {
    final MaterialDialog.Builder builder = dialog.builder;
    // Set cancelable flag and dialog background color
    dialog.setCancelable(builder.cancelable);
    dialog.setCanceledOnTouchOutside(builder.canceledOnTouchOutside);
    if (builder.backgroundColor == 0) {
        builder.backgroundColor = DialogUtils.resolveColor(builder.context, R.attr.md_background_color, DialogUtils.resolveColor(dialog.getContext(), R.attr.colorBackgroundFloating));
    }
    if (builder.backgroundColor != 0) {
        GradientDrawable drawable = new GradientDrawable();
        drawable.setCornerRadius(builder.context.getResources().getDimension(R.dimen.md_bg_corner_radius));
        drawable.setColor(builder.backgroundColor);
        dialog.getWindow().setBackgroundDrawable(drawable);
    }
    // Retrieve color theme attributes
    if (!builder.positiveColorSet) {
        builder.positiveColor = DialogUtils.resolveActionTextColorStateList(builder.context, R.attr.md_positive_color, builder.positiveColor);
    }
    if (!builder.neutralColorSet) {
        builder.neutralColor = DialogUtils.resolveActionTextColorStateList(builder.context, R.attr.md_neutral_color, builder.neutralColor);
    }
    if (!builder.negativeColorSet) {
        builder.negativeColor = DialogUtils.resolveActionTextColorStateList(builder.context, R.attr.md_negative_color, builder.negativeColor);
    }
    if (!builder.widgetColorSet) {
        builder.widgetColor = DialogUtils.resolveColor(builder.context, R.attr.md_widget_color, builder.widgetColor);
    }
    // Retrieve default title/content colors
    if (!builder.titleColorSet) {
        final int titleColorFallback = DialogUtils.resolveColor(dialog.getContext(), android.R.attr.textColorPrimary);
        builder.titleColor = DialogUtils.resolveColor(builder.context, R.attr.md_title_color, titleColorFallback);
    }
    if (!builder.contentColorSet) {
        final int contentColorFallback = DialogUtils.resolveColor(dialog.getContext(), android.R.attr.textColorSecondary);
        builder.contentColor = DialogUtils.resolveColor(builder.context, R.attr.md_content_color, contentColorFallback);
    }
    if (!builder.itemColorSet) {
        builder.itemColor = DialogUtils.resolveColor(builder.context, R.attr.md_item_color, builder.contentColor);
    }
    // Retrieve references to views
    dialog.title = (TextView) dialog.view.findViewById(R.id.md_title);
    dialog.icon = (ImageView) dialog.view.findViewById(R.id.md_icon);
    dialog.titleFrame = dialog.view.findViewById(R.id.md_titleFrame);
    dialog.content = (TextView) dialog.view.findViewById(R.id.md_content);
    dialog.recyclerView = (RecyclerView) dialog.view.findViewById(R.id.md_contentRecyclerView);
    dialog.checkBoxPrompt = (CheckBox) dialog.view.findViewById(R.id.md_promptCheckbox);
    // Button views initially used by checkIfStackingNeeded()
    dialog.positiveButton = (MDButton) dialog.view.findViewById(R.id.md_buttonDefaultPositive);
    dialog.neutralButton = (MDButton) dialog.view.findViewById(R.id.md_buttonDefaultNeutral);
    dialog.negativeButton = (MDButton) dialog.view.findViewById(R.id.md_buttonDefaultNegative);
    // Don't allow the submit button to not be shown for input dialogs
    if (builder.inputCallback != null && builder.positiveText == null) {
        builder.positiveText = builder.context.getText(android.R.string.ok);
    }
    // Set up the initial visibility of action buttons based on whether or not text was set
    dialog.positiveButton.setVisibility(builder.positiveText != null ? View.VISIBLE : View.GONE);
    dialog.neutralButton.setVisibility(builder.neutralText != null ? View.VISIBLE : View.GONE);
    dialog.negativeButton.setVisibility(builder.negativeText != null ? View.VISIBLE : View.GONE);
    // Set up the focus of action buttons
    dialog.positiveButton.setFocusable(true);
    dialog.neutralButton.setFocusable(true);
    dialog.negativeButton.setFocusable(true);
    if (builder.positiveFocus) {
        dialog.positiveButton.requestFocus();
    }
    if (builder.neutralFocus) {
        dialog.neutralButton.requestFocus();
    }
    if (builder.negativeFocus) {
        dialog.negativeButton.requestFocus();
    }
    // Setup icon
    if (builder.icon != null) {
        dialog.icon.setVisibility(View.VISIBLE);
        dialog.icon.setImageDrawable(builder.icon);
    } else {
        Drawable d = DialogUtils.resolveDrawable(builder.context, R.attr.md_icon);
        if (d != null) {
            dialog.icon.setVisibility(View.VISIBLE);
            dialog.icon.setImageDrawable(d);
        } else {
            dialog.icon.setVisibility(View.GONE);
        }
    }
    // Setup icon size limiting
    int maxIconSize = builder.maxIconSize;
    if (maxIconSize == -1) {
        maxIconSize = DialogUtils.resolveDimension(builder.context, R.attr.md_icon_max_size);
    }
    if (builder.limitIconToDefaultSize || DialogUtils.resolveBoolean(builder.context, R.attr.md_icon_limit_icon_to_default_size)) {
        maxIconSize = builder.context.getResources().getDimensionPixelSize(R.dimen.md_icon_max_size);
    }
    if (maxIconSize > -1) {
        dialog.icon.setAdjustViewBounds(true);
        dialog.icon.setMaxHeight(maxIconSize);
        dialog.icon.setMaxWidth(maxIconSize);
        dialog.icon.requestLayout();
    }
    // Setup divider color in case content scrolls
    if (!builder.dividerColorSet) {
        final int dividerFallback = DialogUtils.resolveColor(dialog.getContext(), R.attr.md_divider);
        builder.dividerColor = DialogUtils.resolveColor(builder.context, R.attr.md_divider_color, dividerFallback);
    }
    dialog.view.setDividerColor(builder.dividerColor);
    // Setup title and title frame
    if (dialog.title != null) {
        dialog.setTypeface(dialog.title, builder.mediumFont);
        dialog.title.setTextColor(builder.titleColor);
        dialog.title.setGravity(builder.titleGravity.getGravityInt());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            //noinspection ResourceType
            dialog.title.setTextAlignment(builder.titleGravity.getTextAlignment());
        }
        if (builder.title == null) {
            dialog.titleFrame.setVisibility(View.GONE);
        } else {
            dialog.title.setText(builder.title);
            dialog.titleFrame.setVisibility(View.VISIBLE);
        }
    }
    // Setup content
    if (dialog.content != null) {
        dialog.content.setMovementMethod(new LinkMovementMethod());
        dialog.setTypeface(dialog.content, builder.regularFont);
        dialog.content.setLineSpacing(0f, builder.contentLineSpacingMultiplier);
        if (builder.linkColor == null) {
            dialog.content.setLinkTextColor(DialogUtils.resolveColor(dialog.getContext(), android.R.attr.textColorPrimary));
        } else {
            dialog.content.setLinkTextColor(builder.linkColor);
        }
        dialog.content.setTextColor(builder.contentColor);
        dialog.content.setGravity(builder.contentGravity.getGravityInt());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            //noinspection ResourceType
            dialog.content.setTextAlignment(builder.contentGravity.getTextAlignment());
        }
        if (builder.content != null) {
            dialog.content.setText(builder.content);
            dialog.content.setVisibility(View.VISIBLE);
        } else {
            dialog.content.setVisibility(View.GONE);
        }
    }
    // Setup prompt checkbox
    if (dialog.checkBoxPrompt != null) {
        dialog.checkBoxPrompt.setText(builder.checkBoxPrompt);
        dialog.checkBoxPrompt.setChecked(builder.checkBoxPromptInitiallyChecked);
        dialog.checkBoxPrompt.setOnCheckedChangeListener(builder.checkBoxPromptListener);
        dialog.setTypeface(dialog.checkBoxPrompt, builder.regularFont);
        dialog.checkBoxPrompt.setTextColor(builder.contentColor);
        MDTintHelper.setTint(dialog.checkBoxPrompt, builder.widgetColor);
    }
    // Setup action buttons
    dialog.view.setButtonGravity(builder.buttonsGravity);
    dialog.view.setButtonStackedGravity(builder.btnStackedGravity);
    dialog.view.setStackingBehavior(builder.stackingBehavior);
    boolean textAllCaps;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        textAllCaps = DialogUtils.resolveBoolean(builder.context, android.R.attr.textAllCaps, true);
        if (textAllCaps) {
            textAllCaps = DialogUtils.resolveBoolean(builder.context, R.attr.textAllCaps, true);
        }
    } else {
        textAllCaps = DialogUtils.resolveBoolean(builder.context, R.attr.textAllCaps, true);
    }
    MDButton positiveTextView = dialog.positiveButton;
    dialog.setTypeface(positiveTextView, builder.mediumFont);
    positiveTextView.setAllCapsCompat(textAllCaps);
    positiveTextView.setText(builder.positiveText);
    positiveTextView.setTextColor(builder.positiveColor);
    dialog.positiveButton.setStackedSelector(dialog.getButtonSelector(DialogAction.POSITIVE, true));
    dialog.positiveButton.setDefaultSelector(dialog.getButtonSelector(DialogAction.POSITIVE, false));
    dialog.positiveButton.setTag(DialogAction.POSITIVE);
    dialog.positiveButton.setOnClickListener(dialog);
    dialog.positiveButton.setVisibility(View.VISIBLE);
    MDButton negativeTextView = dialog.negativeButton;
    dialog.setTypeface(negativeTextView, builder.mediumFont);
    negativeTextView.setAllCapsCompat(textAllCaps);
    negativeTextView.setText(builder.negativeText);
    negativeTextView.setTextColor(builder.negativeColor);
    dialog.negativeButton.setStackedSelector(dialog.getButtonSelector(DialogAction.NEGATIVE, true));
    dialog.negativeButton.setDefaultSelector(dialog.getButtonSelector(DialogAction.NEGATIVE, false));
    dialog.negativeButton.setTag(DialogAction.NEGATIVE);
    dialog.negativeButton.setOnClickListener(dialog);
    dialog.negativeButton.setVisibility(View.VISIBLE);
    MDButton neutralTextView = dialog.neutralButton;
    dialog.setTypeface(neutralTextView, builder.mediumFont);
    neutralTextView.setAllCapsCompat(textAllCaps);
    neutralTextView.setText(builder.neutralText);
    neutralTextView.setTextColor(builder.neutralColor);
    dialog.neutralButton.setStackedSelector(dialog.getButtonSelector(DialogAction.NEUTRAL, true));
    dialog.neutralButton.setDefaultSelector(dialog.getButtonSelector(DialogAction.NEUTRAL, false));
    dialog.neutralButton.setTag(DialogAction.NEUTRAL);
    dialog.neutralButton.setOnClickListener(dialog);
    dialog.neutralButton.setVisibility(View.VISIBLE);
    // Setup list dialog stuff
    if (builder.listCallbackMultiChoice != null) {
        dialog.selectedIndicesList = new ArrayList<>();
    }
    if (dialog.recyclerView != null) {
        if (builder.adapter == null) {
            // Determine list type
            if (builder.listCallbackSingleChoice != null) {
                dialog.listType = MaterialDialog.ListType.SINGLE;
            } else if (builder.listCallbackMultiChoice != null) {
                dialog.listType = MaterialDialog.ListType.MULTI;
                if (builder.selectedIndices != null) {
                    dialog.selectedIndicesList = new ArrayList<>(Arrays.asList(builder.selectedIndices));
                    builder.selectedIndices = null;
                }
            } else {
                dialog.listType = MaterialDialog.ListType.REGULAR;
            }
            builder.adapter = new DefaultRvAdapter(dialog, MaterialDialog.ListType.getLayoutForType(dialog.listType));
        } else if (builder.adapter instanceof MDAdapter) {
            // Notify simple list adapter of the dialog it belongs to
            ((MDAdapter) builder.adapter).setDialog(dialog);
        }
    }
    // Setup progress dialog stuff if needed
    setupProgressDialog(dialog);
    // Setup input dialog stuff if needed
    setupInputDialog(dialog);
    // Setup custom views
    if (builder.customView != null) {
        ((MDRootLayout) dialog.view.findViewById(R.id.md_root)).noTitleNoPadding();
        FrameLayout frame = (FrameLayout) dialog.view.findViewById(R.id.md_customViewFrame);
        dialog.customViewFrame = frame;
        View innerView = builder.customView;
        if (innerView.getParent() != null) {
            ((ViewGroup) innerView.getParent()).removeView(innerView);
        }
        if (builder.wrapCustomViewInScroll) {
            /* Apply the frame padding to the content, this allows the ScrollView to draw it's
                   over scroll glow without clipping */
            final Resources r = dialog.getContext().getResources();
            final int framePadding = r.getDimensionPixelSize(R.dimen.md_dialog_frame_margin);
            final ScrollView sv = new ScrollView(dialog.getContext());
            int paddingTop = r.getDimensionPixelSize(R.dimen.md_content_padding_top);
            int paddingBottom = r.getDimensionPixelSize(R.dimen.md_content_padding_bottom);
            sv.setClipToPadding(false);
            if (innerView instanceof EditText) {
                // Setting padding to an EditText causes visual errors, set it to the parent instead
                sv.setPadding(framePadding, paddingTop, framePadding, paddingBottom);
            } else {
                // Setting padding to scroll view pushes the scroll bars out, don't do it if not necessary (like above)
                sv.setPadding(0, paddingTop, 0, paddingBottom);
                innerView.setPadding(framePadding, 0, framePadding, 0);
            }
            sv.addView(innerView, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            innerView = sv;
        }
        frame.addView(innerView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    }
    // Setup user listeners
    if (builder.showListener != null) {
        dialog.setOnShowListener(builder.showListener);
    }
    if (builder.cancelListener != null) {
        dialog.setOnCancelListener(builder.cancelListener);
    }
    if (builder.dismissListener != null) {
        dialog.setOnDismissListener(builder.dismissListener);
    }
    if (builder.keyListener != null) {
        dialog.setOnKeyListener(builder.keyListener);
    }
    // Setup internal show listener
    dialog.setOnShowListenerInternal();
    // Other internal initialization
    dialog.invalidateList();
    dialog.setViewInternal(dialog.view);
    dialog.checkIfListInitScroll();
    // Min height and max width calculations
    WindowManager wm = dialog.getWindow().getWindowManager();
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    final int windowWidth = size.x;
    final int windowHeight = size.y;
    final int windowVerticalPadding = builder.context.getResources().getDimensionPixelSize(R.dimen.md_dialog_vertical_margin);
    final int windowHorizontalPadding = builder.context.getResources().getDimensionPixelSize(R.dimen.md_dialog_horizontal_margin);
    final int maxWidth = builder.context.getResources().getDimensionPixelSize(R.dimen.md_dialog_max_width);
    final int calculatedWidth = windowWidth - (windowHorizontalPadding * 2);
    dialog.view.setMaxHeight(windowHeight - windowVerticalPadding * 2);
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = Math.min(maxWidth, calculatedWidth);
    dialog.getWindow().setAttributes(lp);
}
Also used : MDButton(com.afollestad.materialdialogs.internal.MDButton) ArrayList(java.util.ArrayList) WindowManager(android.view.WindowManager) EditText(android.widget.EditText) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) IndeterminateHorizontalProgressDrawable(me.zhanghai.android.materialprogressbar.IndeterminateHorizontalProgressDrawable) HorizontalProgressDrawable(me.zhanghai.android.materialprogressbar.HorizontalProgressDrawable) IndeterminateProgressDrawable(me.zhanghai.android.materialprogressbar.IndeterminateProgressDrawable) LinkMovementMethod(android.text.method.LinkMovementMethod) Point(android.graphics.Point) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) GradientDrawable(android.graphics.drawable.GradientDrawable) Point(android.graphics.Point) MDAdapter(com.afollestad.materialdialogs.internal.MDAdapter) ScrollView(android.widget.ScrollView) MDRootLayout(com.afollestad.materialdialogs.internal.MDRootLayout) FrameLayout(android.widget.FrameLayout) Resources(android.content.res.Resources) Display(android.view.Display) UiThread(android.support.annotation.UiThread)

Example 4 with MDButton

use of com.afollestad.materialdialogs.internal.MDButton in project AntennaPod by AntennaPod.

the class ProxyDialog method setTestRequired.

private void setTestRequired(boolean required) {
    if (required) {
        testSuccessful = false;
        MDButton button = dialog.getActionButton(DialogAction.POSITIVE);
        button.setText(context.getText(R.string.proxy_test_label));
        button.setEnabled(true);
    } else {
        testSuccessful = true;
        MDButton button = dialog.getActionButton(DialogAction.POSITIVE);
        button.setText(context.getText(android.R.string.ok));
        button.setEnabled(true);
    }
}
Also used : MDButton(com.afollestad.materialdialogs.internal.MDButton)

Aggregations

MDButton (com.afollestad.materialdialogs.internal.MDButton)4 View (android.view.View)3 TextView (android.widget.TextView)3 Handler (android.os.Handler)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 BmobUser (cn.bmob.v3.BmobUser)2 SaveListener (cn.bmob.v3.listener.SaveListener)2 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 User (com.nightonke.saver.model.User)2 RiseNumberTextView (com.nightonke.saver.ui.RiseNumberTextView)2 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)2 MaterialIconView (net.steamcrafted.materialiconlib.MaterialIconView)2 Resources (android.content.res.Resources)1 Point (android.graphics.Point)1 Drawable (android.graphics.drawable.Drawable)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 UiThread (android.support.annotation.UiThread)1 RecyclerView (android.support.v7.widget.RecyclerView)1