private void invalidateDynamicButtonColors() { final Builder builder = getBuilder(); if (builder.mDynamicButtonColor) { final MaterialDialog dialog = (MaterialDialog) getDialog(); int selectedColor = getSelectedColor(); dialog.getActionButton(DialogAction.POSITIVE).setTextColor(selectedColor); dialog.getActionButton(DialogAction.NEUTRAL).setTextColor(selectedColor); } }
private void requestGplusPermission() { final String[] PERMISSIONS = {Manifest.permission.GET_ACCOUNTS, Manifest.permission.INTERNET}; if (ActivityCompat.shouldShowRequestPermissionRationale( getActivity(), Manifest.permission.GET_ACCOUNTS) || ActivityCompat.shouldShowRequestPermissionRationale( getActivity(), Manifest.permission.INTERNET)) { // Provide an additional rationale to the user if the permission was not granted // and the user would benefit from additional context for the use of the permission. // For example, if the request has been denied previously. String fab_skin = (BaseActivity.accentSkin); final MaterialDialog materialDialog = Futils.showBasicDialog( getActivity(), fab_skin, theme, new String[] { getResources().getString(R.string.grantgplus), getResources().getString(R.string.grantper), getResources().getString(R.string.grant), getResources().getString(R.string.cancel), null }); materialDialog .getActionButton(DialogAction.POSITIVE) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { ActivityCompat.requestPermissions(getActivity(), PERMISSIONS, 66); materialDialog.dismiss(); } }); materialDialog .getActionButton(DialogAction.NEGATIVE) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { getActivity().finish(); } }); materialDialog.setCancelable(false); materialDialog.show(); } else { // Contact permissions have not been granted yet. Request them directly. ActivityCompat.requestPermissions(getActivity(), PERMISSIONS, 66); } }
@OnClick(R.id.customView) public void showCustomView() { MaterialDialog dialog = new MaterialDialog.Builder(this) .title(R.string.googleWifi) .customView(R.layout.dialog_customview, true) .positiveText(R.string.connect) .negativeText(android.R.string.cancel) .onPositive( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { showToast("Password: " + passwordInput.getText().toString()); } }) .build(); positiveAction = dialog.getActionButton(DialogAction.POSITIVE); //noinspection ConstantConditions passwordInput = (EditText) dialog.getCustomView().findViewById(R.id.password); passwordInput.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) { positiveAction.setEnabled(s.toString().trim().length() > 0); } @Override public void afterTextChanged(Editable s) {} }); // Toggling the show password CheckBox will mask or unmask the password input EditText CheckBox checkbox = (CheckBox) dialog.getCustomView().findViewById(R.id.showPassword); checkbox.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { passwordInput.setInputType( !isChecked ? InputType.TYPE_TEXT_VARIATION_PASSWORD : InputType.TYPE_CLASS_TEXT); passwordInput.setTransformationMethod( !isChecked ? PasswordTransformationMethod.getInstance() : null); } }); int widgetColor = ThemeSingleton.get().widgetColor; MDTintHelper.setTint( checkbox, widgetColor == 0 ? ContextCompat.getColor(this, R.color.material_teal_500) : widgetColor); MDTintHelper.setTint( passwordInput, widgetColor == 0 ? ContextCompat.getColor(this, R.color.material_teal_500) : widgetColor); dialog.show(); positiveAction.setEnabled(false); // disabled by default }
private void showCustomView() { MaterialDialog dialog = new MaterialDialog.Builder(this) .title(R.string.googleWifi) .positiveText(R.string.agree) .customView(R.layout.dialog_customview) .positiveText(R.string.connect) .negativeText(android.R.string.cancel) .callback( new MaterialDialog.Callback() { @Override public void onPositive(MaterialDialog dialog) { Toast.makeText( getApplicationContext(), "Password: " + passwordInput.getText().toString(), Toast.LENGTH_SHORT) .show(); } @Override public void onNegative(MaterialDialog dialog) {} }) .build(); positiveAction = dialog.getActionButton(DialogAction.POSITIVE); passwordInput = (EditText) dialog.getCustomView().findViewById(R.id.password); passwordInput.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) { positiveAction.setEnabled(s.toString().trim().length() > 0); } @Override public void afterTextChanged(Editable s) {} }); // Toggling the show password CheckBox will mask or unmask the password input EditText ((CheckBox) dialog.getCustomView().findViewById(R.id.showPassword)) .setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { passwordInput.setInputType( !isChecked ? InputType.TYPE_TEXT_VARIATION_PASSWORD : InputType.TYPE_CLASS_TEXT); passwordInput.setTransformationMethod( !isChecked ? PasswordTransformationMethod.getInstance() : null); } }); dialog.show(); positiveAction.setEnabled(false); // disabled by default }
public void notifyPasswordValidation(boolean valid) { final MaterialDialog dialog = (MaterialDialog) getDialog(); final View positive = dialog.getActionButton(DialogAction.POSITIVE); final View negative = dialog.getActionButton(DialogAction.NEGATIVE); toggleButtonsEnabled(true); if (valid) { if (mStage == Stage.NEW_FINGERPRINT_ENROLLED && mUseFingerprintFutureCheckBox.isChecked()) { // Re-create the key so that fingerprints including new ones are validated. Digitus.get().recreateKey(); mStage = Stage.FINGERPRINT; } mPassword.setText(""); mCallback.onFingerprintDialogAuthenticated(); dismiss(); } else { mPasswordDescriptionTextView.setText(R.string.password_not_recognized); final int red = ContextCompat.getColor(getActivity(), R.color.material_red_500); MDTintHelper.setTint(mPassword, red); ((TextView) positive).setTextColor(red); ((TextView) negative).setTextColor(red); } }
private void toggleButtonsEnabled(boolean enabled) { MaterialDialog dialog = (MaterialDialog) getDialog(); dialog.getActionButton(DialogAction.POSITIVE).setEnabled(enabled); dialog.getActionButton(DialogAction.NEGATIVE).setEnabled(enabled); }
public void addTask(final View view) { boolean wrapInScrollView = true; final MaterialDialog dialog = new MaterialDialog.Builder(this) .title("Create task") .customView(R.layout.layout, wrapInScrollView) .positiveText("Add") .negativeText("Cancel") .build(); // Create the SPINNER to select the LIST Spinner spinner = (Spinner) dialog.findViewById(R.id.spinner); CharSequence[] charSequences = new CharSequence[groups.size() - 3]; int j = 0; for (int i = 0; i < groups.size(); i++) { if (i == 1 || i == 2 || i == (groups.size() - 1)) { } else { charSequences[j] = groups.get(i).getName(); j++; } } // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>( this, android.R.layout.simple_spinner_dropdown_item, charSequences); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner spinner.setAdapter(adapter); final EditText taskName = (EditText) dialog.findViewById(R.id.editText); final Spinner listId = (Spinner) dialog.findViewById(R.id.spinner); dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false); taskName.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) dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true); else dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false); } }); dialog .getBuilder() .onPositive( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) { if (taskName.getText().toString().isEmpty()) return; Task task = new Task(); task.setAuthor(ParseUser.getCurrentUser()); task.setUuidString(); task.setName(taskName.getText().toString()); task.setDraft(true); task.setImportant(false); task.setDone(false); saveTask(task, (int) listId.getSelectedItemId()); } }); dialog.show(); }
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = this.getArguments(); position = bundle.getInt("position", 0); int favoriteId = bundle.getInt("favoriteId", 0); favoriteIsSelected = bundle.getBoolean("favoriteIsSelected", false); db = new DatabaseHelper(activity); favorite = db.getFavorite(favoriteId); MaterialDialog dialog = new MaterialDialog.Builder(activity) .title(R.string.edit_favorite) .customView(R.layout.add_edit_favorite_dialog, true) .positiveText(R.string.dialog_positive_text) .negativeText(android.R.string.cancel) .onPositive( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { inputName = input.getText().toString().trim(); if (iconPath == 0) { iconPath = favorite.getFavoriteImage(); } favorite.setFavoriteImage(iconPath); favorite.setFavoriteName(inputName); favorite.setSelected(favoriteIsSelected); db.updateFavorite(favorite); db.closeDB(); reloadHost(); } }) .build(); favoriteImage = (ImageView) dialog.findViewById(R.id.favorite_image); int iconName = favorite.getFavoriteImage(); if (iconName == 0) { iconName = R.drawable.image_favorites; } favoriteImage.setImageResource(iconName); favoriteImage.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { favoriteImages = new FavoriteImages(); View view = activity.getLayoutInflater().inflate(R.layout.icon_selector_grid, null); GridView gridView = (GridView) view.findViewById(R.id.icons_grid_view); gridView.setAdapter(new IconAdapter(activity, favoriteImages.getFavoriteImagesIds())); gridView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { favoriteImage.setImageResource(favoriteImages.getFavoriteImageId(position)); iconPath = favoriteImages.getFavoriteImageId(position); positiveAction.setEnabled(true); gridDialog.dismiss(); } }); gridDialog = new MaterialDialog.Builder(activity).customView(gridView, false).build(); gridDialog.show(); } }); input = (EditText) dialog.findViewById(R.id.favorite_name); input.requestFocus(); input.setText(favorite.getFavoriteName()); positiveAction = dialog.getActionButton(DialogAction.POSITIVE); input.addTextChangedListener(new OnTextChange(positiveAction)); positiveAction.setEnabled(false); return dialog; }