java类com.afollestad.materialdialogs.util.DialogUtils的实例源码

MDButton.java 文件源码 项目:material-dialogs 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Set if the button should be displayed in stacked mode. This should only be called from
 * MDRootLayout's onMeasure, and we must be measured after calling this.
 */
/* package */ void setStacked(boolean stacked, boolean force) {
  if (this.stacked != stacked || force) {

    setGravity(
        stacked ? (Gravity.CENTER_VERTICAL | stackedGravity.getGravityInt()) : Gravity.CENTER);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
      //noinspection ResourceType
      setTextAlignment(stacked ? stackedGravity.getTextAlignment() : TEXT_ALIGNMENT_CENTER);
    }

    DialogUtils.setBackgroundCompat(this, stacked ? stackedBackground : defaultBackground);
    if (stacked) {
      setPadding(stackedEndPadding, getPaddingTop(), stackedEndPadding, getPaddingBottom());
    } /* Else the padding was properly reset by the drawable */

    this.stacked = stacked;
  }
}
MDRootLayout.java 文件源码 项目:material-dialogs 阅读 31 收藏 0 点赞 0 评论 0
private void init(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
  Resources r = context.getResources();

  TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MDRootLayout, defStyleAttr, 0);
  reducePaddingNoTitleNoButtons =
      a.getBoolean(R.styleable.MDRootLayout_md_reduce_padding_no_title_no_buttons, true);
  a.recycle();

  noTitlePaddingFull = r.getDimensionPixelSize(R.dimen.md_notitle_vertical_padding);
  buttonPaddingFull = r.getDimensionPixelSize(R.dimen.md_button_frame_vertical_padding);

  buttonHorizontalEdgeMargin = r.getDimensionPixelSize(R.dimen.md_button_padding_frame_side);
  buttonBarHeight = r.getDimensionPixelSize(R.dimen.md_button_height);

  dividerPaint = new Paint();
  dividerWidth = r.getDimensionPixelSize(R.dimen.md_divider_height);
  dividerPaint.setColor(DialogUtils.resolveColor(context, R.attr.md_divider_color));
  setWillNotDraw(false);
}
MaterialDialog.java 文件源码 项目:material-dialogs 阅读 24 收藏 0 点赞 0 评论 0
/** @param errorColor Pass in 0 for the default red error color (as specified in guidelines). */
public Builder inputRange(
    @IntRange(from = 0, to = Integer.MAX_VALUE) int minLength,
    @IntRange(from = -1, to = Integer.MAX_VALUE) int maxLength,
    @ColorInt int errorColor) {
  if (minLength < 0) {
    throw new IllegalArgumentException(
        "Min length for input dialogs " + "cannot be less than 0.");
  }
  this.inputMinLength = minLength;
  this.inputMaxLength = maxLength;
  if (errorColor == 0) {
    this.inputRangeErrorColor = DialogUtils.getColor(context, R.color.md_edittext_error);
  } else {
    this.inputRangeErrorColor = errorColor;
  }
  if (this.inputMinLength > 0) {
    this.inputAllowEmpty = false;
  }
  return this;
}
MaterialEditTextPreference.java 文件源码 项目:GitHub 阅读 21 收藏 0 点赞 0 评论 0
private void init(Context context, AttributeSet attrs) {
    PrefUtil.setLayoutResource(context, this, attrs);
    int fallback;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        fallback = DialogUtils.resolveColor(context, android.R.attr.colorAccent);
    else fallback = 0;
    fallback = DialogUtils.resolveColor(context, R.attr.colorAccent, fallback);
    color = DialogUtils.resolveColor(context, R.attr.md_widget_color, fallback);

    editText = new AppCompatEditText(context, attrs);
    // Give it an ID so it can be saved/restored
    editText.setId(android.R.id.edit);
    editText.setEnabled(true);
}
MainActivity.java 文件源码 项目:GitHub 阅读 13 收藏 0 点赞 0 评论 0
@Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);

    handler = new Handler();
    primaryPreselect = DialogUtils.resolveColor(this, R.attr.colorPrimary);
    accentPreselect = DialogUtils.resolveColor(this, R.attr.colorAccent);
}
DialogInit.java 文件源码 项目:GitHub 阅读 25 收藏 0 点赞 0 评论 0
private static void setupInputDialog(final MaterialDialog dialog) {
    final MaterialDialog.Builder builder = dialog.builder;
    dialog.input = (EditText) dialog.view.findViewById(android.R.id.input);
    if (dialog.input == null) return;
    dialog.setTypeface(dialog.input, builder.regularFont);
    if (builder.inputPrefill != null)
        dialog.input.setText(builder.inputPrefill);
    dialog.setInternalInputCallback();
    dialog.input.setHint(builder.inputHint);
    dialog.input.setSingleLine();
    dialog.input.setTextColor(builder.contentColor);
    dialog.input.setHintTextColor(DialogUtils.adjustAlpha(builder.contentColor, 0.3f));
    MDTintHelper.setTint(dialog.input, dialog.builder.widgetColor);

    if (builder.inputType != -1) {
        dialog.input.setInputType(builder.inputType);
        if (builder.inputType != InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD &&
                (builder.inputType & InputType.TYPE_TEXT_VARIATION_PASSWORD) == InputType.TYPE_TEXT_VARIATION_PASSWORD) {
            // If the flags contain TYPE_TEXT_VARIATION_PASSWORD, apply the password transformation method automatically
            dialog.input.setTransformationMethod(PasswordTransformationMethod.getInstance());
        }
    }

    dialog.inputMinMax = (TextView) dialog.view.findViewById(R.id.md_minMax);
    if (builder.inputMinLength > 0 || builder.inputMaxLength > -1) {
        dialog.invalidateInputMinMaxIndicator(dialog.input.getText().toString().length(),
                !builder.inputAllowEmpty);
    } else {
        dialog.inputMinMax.setVisibility(View.GONE);
        dialog.inputMinMax = null;
    }
}
MDTintHelper.java 文件源码 项目:GitHub 阅读 24 收藏 0 点赞 0 评论 0
public static void setTint(@NonNull CheckBox box, @ColorInt int color) {
    final int disabledColor = DialogUtils.getDisabledColor(box.getContext());
    ColorStateList sl = new ColorStateList(new int[][]{
            new int[]{android.R.attr.state_enabled, -android.R.attr.state_checked},
            new int[]{android.R.attr.state_enabled, android.R.attr.state_checked},
            new int[]{-android.R.attr.state_enabled, -android.R.attr.state_checked},
            new int[]{-android.R.attr.state_enabled, android.R.attr.state_checked}
    }, new int[]{
            DialogUtils.resolveColor(box.getContext(), R.attr.colorControlNormal),
            color,
            disabledColor,
            disabledColor
    });
    setTint(box, sl);
}
MDTintHelper.java 文件源码 项目:GitHub 阅读 26 收藏 0 点赞 0 评论 0
private static ColorStateList createEditTextColorStateList(
        @NonNull Context context, @ColorInt int color) {
    int[][] states = new int[3][];
    int[] colors = new int[3];
    int i = 0;
    states[i] = new int[]{-android.R.attr.state_enabled};
    colors[i] = DialogUtils.resolveColor(context, R.attr.colorControlNormal);
    i++;
    states[i] = new int[]{-android.R.attr.state_pressed, -android.R.attr.state_focused};
    colors[i] = DialogUtils.resolveColor(context, R.attr.colorControlNormal);
    i++;
    states[i] = new int[]{};
    colors[i] = color;
    return new ColorStateList(states, colors);
}
MaterialDialog.java 文件源码 项目:GitHub 阅读 25 收藏 0 点赞 0 评论 0
protected final Drawable getListSelector() {
    if (builder.listSelector != 0)
        return ResourcesCompat.getDrawable(builder.context.getResources(), builder.listSelector, null);
    final Drawable d = DialogUtils.resolveDrawable(builder.context, R.attr.md_list_selector);
    if (d != null) return d;
    return DialogUtils.resolveDrawable(getContext(), R.attr.md_list_selector);
}
MaterialDialog.java 文件源码 项目:GitHub 阅读 29 收藏 0 点赞 0 评论 0
@Override
public final void onShow(DialogInterface dialog) {
    if (input != null) {
        DialogUtils.showKeyboard(this, builder);
        if (input.getText().length() > 0)
            input.setSelection(input.getText().length());
    }
    super.onShow(dialog);
}


问题


面经


文章

微信
公众号

扫码关注公众号