Пример #1
0
  @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
  }
Пример #2
0
 // Receives callback from color chooser dialog
 @Override
 public void onColorSelection(@NonNull ColorChooserDialog dialog, @ColorInt int color) {
   if (dialog.isAccentMode()) {
     accentPreselect = color;
     ThemeSingleton.get().positiveColor = DialogUtils.getActionTextStateList(this, color);
     ThemeSingleton.get().neutralColor = DialogUtils.getActionTextStateList(this, color);
     ThemeSingleton.get().negativeColor = DialogUtils.getActionTextStateList(this, color);
     ThemeSingleton.get().widgetColor = color;
   } else {
     primaryPreselect = color;
     if (getSupportActionBar() != null)
       getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color));
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
       getWindow().setStatusBarColor(CircleView.shiftColorDown(color));
       getWindow().setNavigationBarColor(color);
     }
   }
 }
Пример #3
0
 @OnClick(R.id.customView_webView)
 public void showCustomWebView() {
   int accentColor = ThemeSingleton.get().widgetColor;
   if (accentColor == 0) accentColor = ContextCompat.getColor(this, R.color.material_teal_500);
   ChangelogDialog.create(false, accentColor).show(getSupportFragmentManager(), "changelog");
 }