Java 类com.afollestad.materialdialogs.MaterialDialog.Builder 实例源码

项目:GitHub    文件:MaterialEditTextPreference.java   
@Override protected void showDialog(Bundle state) {
    Builder mBuilder = new MaterialDialog.Builder(getContext())
            .title(getDialogTitle())
            .icon(getDialogIcon())
            .positiveText(getPositiveButtonText())
            .negativeText(getNegativeButtonText())
            .dismissListener(this)
            .onAny(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    switch (which) {
                        default:
                            MaterialEditTextPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                            break;
                        case NEUTRAL:
                            MaterialEditTextPreference.this.onClick(dialog, DialogInterface.BUTTON_NEUTRAL);
                            break;
                        case NEGATIVE:
                            MaterialEditTextPreference.this.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
                            break;
                    }
                }
            })
            .dismissListener(this);

    @SuppressLint("InflateParams")
    View layout = LayoutInflater.from(getContext()).inflate(R.layout.md_stub_inputpref, null);
    onBindDialogView(layout);

    MDTintHelper.setTint(editText, color);

    TextView message = (TextView) layout.findViewById(android.R.id.message);
    if (getDialogMessage() != null && getDialogMessage().toString().length() > 0) {
        message.setVisibility(View.VISIBLE);
        message.setText(getDialogMessage());
    } else {
        message.setVisibility(View.GONE);
    }
    mBuilder.customView(layout, false);

    PrefUtil.registerOnActivityDestroyListener(this, this);

    dialog = mBuilder.build();
    if (state != null)
        dialog.onRestoreInstanceState(state);
    requestInputMethod(dialog);

    dialog.show();
}
项目:Native-Clip-Board    文件:WidgetNumberPicker.java   
@Override
protected void showDialog(Bundle state) {

    mPref = getPreferenceManager().getSharedPreferences();

    Builder mBuilder = new MaterialDialog.Builder(getContext())
    .title(getTitle())
    .positiveText(getPositiveButtonText())
    .negativeText(getNegativeButtonText())
    .callback(new ButtonCallback() {

        @Override
        public void onPositive(MaterialDialog dialog) {
            if(mMaxValue==21){
            mPref.edit().putInt(getKey(), Integer.parseInt(values[picker.getValue()-1]) ).commit();
            }else mPref.edit().putInt(getKey(), picker.getValue()).commit();
        }

        //super.onDialogClosed(positiveResult);

    });

    LayoutInflater inflater = LayoutInflater.from(getContext());
       mView=inflater.inflate(R.layout.dialog_number_picker, null);
    picker = (NumberPicker) mView.findViewById(R.id.number_picker);
    picker.setMaxValue(mMaxValue);
    picker.setMinValue(mMinValue);
    try {
        Field f1 = Class.forName("android.widget.NumberPicker").getDeclaredField("mSelectionDivider");
        f1.setAccessible(true);
        ((Drawable) f1.get(picker)).setColorFilter(mColor, PorterDuff.Mode.SRC_ATOP);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if(mMaxValue==21){
        for(int i = 0; i < 20; i++){
            values[i]=""+((i+1)*5);
        }
        values[20]=""+9999;
    picker.setDisplayedValues(values);
    }

       onBindDialogView(mView);
       mBuilder.customView(mView, false);

       mBuilder.show();
}
项目:material-dialogs    文件:MaterialEditTextPreference.java   
@Override
protected void showDialog(Bundle state) {
  Builder mBuilder =
      new MaterialDialog.Builder(getContext())
          .title(getDialogTitle())
          .icon(getDialogIcon())
          .positiveText(getPositiveButtonText())
          .negativeText(getNegativeButtonText())
          .dismissListener(this)
          .onAny(
              new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(MaterialDialog dialog, DialogAction which) {
                  switch (which) {
                    default:
                      MaterialEditTextPreference.this.onClick(
                          dialog, DialogInterface.BUTTON_POSITIVE);
                      break;
                    case NEUTRAL:
                      MaterialEditTextPreference.this.onClick(
                          dialog, DialogInterface.BUTTON_NEUTRAL);
                      break;
                    case NEGATIVE:
                      MaterialEditTextPreference.this.onClick(
                          dialog, DialogInterface.BUTTON_NEGATIVE);
                      break;
                  }
                }
              })
          .dismissListener(this);

  @SuppressLint("InflateParams")
  View layout = LayoutInflater.from(getContext()).inflate(R.layout.md_stub_inputpref, null);
  onBindDialogView(layout);

  MDTintHelper.setTint(editText, color);

  TextView message = (TextView) layout.findViewById(android.R.id.message);
  if (getDialogMessage() != null && getDialogMessage().toString().length() > 0) {
    message.setVisibility(View.VISIBLE);
    message.setText(getDialogMessage());
  } else {
    message.setVisibility(View.GONE);
  }
  mBuilder.customView(layout, false);

  PrefUtil.registerOnActivityDestroyListener(this, this);

  dialog = mBuilder.build();
  if (state != null) {
    dialog.onRestoreInstanceState(state);
  }
  requestInputMethod(dialog);

  dialog.show();
}