@ColorInt private int getSelectedColor() { if (colorChooserCustomFrame != null && colorChooserCustomFrame.getVisibility() == View.VISIBLE) { return selectedCustomColor; } int color = 0; if (subIndex() > -1) color = mColorsSub[topIndex()][subIndex()]; else if (topIndex() > -1) color = mColorsTop[topIndex()]; if (color == 0) { int fallback = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) fallback = DialogUtils.resolveColor(getActivity(), android.R.attr.colorAccent); color = DialogUtils.resolveColor(getActivity(), R.attr.colorAccent, fallback); } return color; }
@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); } } }
public static void setTint(@NonNull RadioButton radioButton, @ColorInt int color) { final int disabledColor = DialogUtils.getDisabledColor(radioButton.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(radioButton.getContext(), R.attr.colorControlNormal), color, disabledColor, disabledColor }); setTint(radioButton, sl); }
/** * 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; } }
private void init(Context context, 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); }
/** * @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; }
@ColorInt private int getSelectedColor() { if (colorChooserCustomFrame != null && colorChooserCustomFrame.getVisibility() == View.VISIBLE) { return selectedCustomColor; } int color = 0; if (subIndex() > -1) { color = colorsSub[topIndex()][subIndex()]; } else if (topIndex() > -1) { color = colorsTop[topIndex()]; } if (color == 0) { int fallback = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { fallback = DialogUtils.resolveColor(getActivity(), android.R.attr.colorAccent); } color = DialogUtils.resolveColor(getActivity(), R.attr.colorAccent, fallback); } return color; }
@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; Log.i(TAG, "onColorSelection: #"+ Integer.toHexString(color)); setStateItem(ElementAppItem.APP_TYPE_COLOR, "#"+Integer.toHexString(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); } } }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.kustom, menu); super.onCreateOptionsMenu(menu, inflater); MenuItem mSearchItem = menu.findItem(R.id.search); SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchItem); mSearchView.setQueryHint(getString(getSearchHintRes())); mSearchView.setOnQueryTextListener(this); mSearchView.setOnCloseListener(this); mSearchView.setImeOptions(EditorInfo.IME_ACTION_DONE); if (getActivity() != null) { final MainActivity act = (MainActivity) getActivity(); TintUtils.themeSearchView( act.getToolbar(), mSearchView, DialogUtils.resolveColor(act, R.attr.tab_icon_color)); } }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.zooper, menu); super.onCreateOptionsMenu(menu, inflater); MenuItem mSearchItem = menu.findItem(R.id.search); SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchItem); mSearchView.setQueryHint(getString(R.string.search_widgets)); mSearchView.setOnQueryTextListener(this); mSearchView.setOnCloseListener(this); mSearchView.setImeOptions(EditorInfo.IME_ACTION_DONE); if (getActivity() != null) { final MainActivity act = (MainActivity) getActivity(); TintUtils.themeSearchView( act.getToolbar(), mSearchView, DialogUtils.resolveColor(act, R.attr.tab_icon_color)); } }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.cab_requests, menu); super.onCreateOptionsMenu(menu, inflater); synchronized (LOCK) { MenuItem selectAll = menu.findItem(R.id.selectAll); try { final Activity act = getActivity(); final int tintColor = DialogUtils.resolveColor(act, R.attr.toolbar_icons_color); if (mAdapter == null || mAdapter.getSelectedCount() == 0) { selectAll.setIcon( TintUtils.createTintedDrawable(act, R.drawable.ic_action_selectall, tintColor)); } else { selectAll.setIcon( TintUtils.createTintedDrawable(act, R.drawable.ic_action_close, tintColor)); } } catch (Throwable e) { e.printStackTrace(); selectAll.setVisible(false); } selectAll.setVisible(mAppsLoaded); } }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.icons, menu); super.onCreateOptionsMenu(menu, inflater); MenuItem mSearchItem = menu.findItem(R.id.search); SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchItem); mSearchView.setQueryHint(getString(R.string.search_icons)); mSearchView.setOnQueryTextListener(this); mSearchView.setOnCloseListener(this); mSearchView.setImeOptions(EditorInfo.IME_ACTION_DONE); if (getActivity() != null) { final BaseThemedActivity act = (BaseThemedActivity) getActivity(); TintUtils.themeSearchView( act.getToolbar(), mSearchView, DialogUtils.resolveColor(act, R.attr.tab_icon_color)); } }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.wallpapers, menu); super.onCreateOptionsMenu(menu, inflater); MenuItem mSearchItem = menu.findItem(R.id.search); SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchItem); mSearchView.setQueryHint(getString(R.string.search_wallpapers)); mSearchView.setOnQueryTextListener(this); mSearchView.setOnCloseListener(this); mSearchView.setImeOptions(EditorInfo.IME_ACTION_DONE); if (getActivity() != null) { final MainActivity act = (MainActivity) getActivity(); TintUtils.themeSearchView( act.getToolbar(), mSearchView, DialogUtils.resolveColor(act, R.attr.tab_icon_color)); } }
@Override public void onBindViewHolder(ApplyVH holder, int position) { if (getItemViewType(position) == 1) { holder.icon.setColorFilter( DialogUtils.resolveColor(mContext, android.R.attr.textColorSecondary), PorterDuff.Mode.SRC_IN); return; } if (mQuickApplyLauncher != null) { position--; } final Launcher launcher = mLaunchers[position]; holder.title.setText(launcher.title); holder.icon.setBackgroundColor(launcher.color); holder.title.setBackgroundColor(launcher.colorDark); holder.icon.setImageResource(launcher.icon); holder.card.setCardBackgroundColor(launcher.color); }
@SuppressLint("PrivateResource") @Override protected void onStart() { super.onStart(); final Toolbar toolbar = getToolbar(); if (toolbar != null) { final int titleColor = DialogUtils.resolveColor(this, R.attr.toolbar_title_color); final int iconColor = DialogUtils.resolveColor(this, R.attr.toolbar_icons_color); toolbar.setTitleTextColor(titleColor); Utils.setOverflowButtonColor(this, iconColor); if (TintUtils.isColorLight(titleColor)) { toolbar.setPopupTheme(R.style.ThemeOverlay_AppCompat_Light); } else { toolbar.setPopupTheme(R.style.ThemeOverlay_AppCompat); } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_picker); ButterKnife.bind(this); toolbar.setTitle(R.string.select_icon); setSupportActionBar(toolbar); //noinspection ConstantConditions getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_action_close); if (toolbar.getNavigationIcon() != null) { toolbar.setNavigationIcon( TintUtils.createTintedDrawable( toolbar.getNavigationIcon(), DialogUtils.resolveColor(this, R.attr.tab_icon_color))); } getFragmentManager() .beginTransaction() .replace(R.id.container, IconsFragment.create(true)) .commit(); }
public static Drawable createCardSelector(Context context) { final int accentColor = DialogUtils.resolveColor(context, R.attr.colorAccent); final boolean darkTheme = Config.get().darkTheme(); final int activated = TintUtils.adjustAlpha(accentColor, darkTheme ? 0.5f : 0.3f); final int pressed = TintUtils.adjustAlpha(accentColor, darkTheme ? 0.75f : 0.6f); final StateListDrawable baseSelector = new StateListDrawable(); baseSelector.addState(new int[] {android.R.attr.state_activated}, new ColorDrawable(activated)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return new RippleDrawable( ColorStateList.valueOf(accentColor), baseSelector, new ColorDrawable(Color.WHITE)); } baseSelector.addState(new int[] {}, new ColorDrawable(Color.TRANSPARENT)); baseSelector.addState(new int[] {android.R.attr.state_pressed}, new ColorDrawable(pressed)); return baseSelector; }
protected void invalidateInputMinMaxIndicator(EditText inputMinMax, int currentLength) { if (inputMinMax != null) { int materialBlue = ContextCompat.getColor(getActivity(), com.afollestad.materialdialogs.R.color.md_material_blue_600); int widgetColor = DialogUtils.resolveColor(getActivity(), com.afollestad.materialdialogs.R.attr.colorAccent, materialBlue); if (Build.VERSION.SDK_INT >= 21) { widgetColor = DialogUtils.resolveColor(getActivity(), android.R.attr.colorAccent, widgetColor); } final boolean isDisabled = currentLength > 20; final int colorText = isDisabled ? ContextCompat.getColor(getActivity(), R.color.red) : -1; final int colorWidget = isDisabled ? ContextCompat.getColor(getActivity(), R.color.red) : widgetColor; inputMinMax.setTextColor(colorText); MDTintHelper.setTint(inputMinMax, colorWidget); } }
protected void invalidateInputMinMaxIndicator(EditText input, int currentLength) { if (input != null) { int materialBlue = ContextCompat.getColor(this, com.afollestad.materialdialogs.R.color.md_material_blue_600); int widgetColor = DialogUtils.resolveColor(this, com.afollestad.materialdialogs.R.attr.colorAccent, materialBlue); if (Build.VERSION.SDK_INT >= 21) { widgetColor = DialogUtils.resolveColor(this, android.R.attr.colorAccent, widgetColor); } final boolean isDisabled = currentLength > 20; final int colorText = isDisabled ? ContextCompat.getColor(this, R.color.red) : -1; final int colorWidget = isDisabled ? ContextCompat.getColor(this, R.color.red) : widgetColor; input.setTextColor(colorText); MDTintHelper.setTint(input, colorWidget); } }
public static void setTint(@NonNull RadioButton radioButton, @ColorInt int color) { ColorStateList sl = new ColorStateList(new int[][]{ new int[]{-android.R.attr.state_checked}, new int[]{android.R.attr.state_checked} }, new int[]{ DialogUtils.resolveColor(radioButton.getContext(), R.attr.colorControlNormal), color }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { radioButton.setButtonTintList(sl); } else { Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material)); DrawableCompat.setTintList(d, sl); radioButton.setButtonDrawable(d); } }
public static void setTint(@NonNull CheckBox box, @ColorInt int color) { ColorStateList sl = new ColorStateList(new int[][]{ new int[]{-android.R.attr.state_checked}, new int[]{android.R.attr.state_checked} }, new int[]{ DialogUtils.resolveColor(box.getContext(), R.attr.colorControlNormal), color }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { box.setButtonTintList(sl); } else { Drawable drawable = DrawableCompat.wrap(ContextCompat.getDrawable(box.getContext(), R.drawable.abc_btn_check_material)); DrawableCompat.setTintList(drawable, sl); box.setButtonDrawable(drawable); } }
public HorizontalProgressDrawable(Context context) { super(new Drawable[]{ new SingleHorizontalProgressDrawable(context), new SingleHorizontalProgressDrawable(context), new SingleHorizontalProgressDrawable(context) }); setId(0, android.R.id.background); mTrackDrawable = (SingleHorizontalProgressDrawable) getDrawable(0); setId(1, android.R.id.secondaryProgress); mSecondaryProgressDrawable = (SingleHorizontalProgressDrawable) getDrawable(1); float disabledAlpha = DialogUtils.resolveFloat(context, android.R.attr.disabledAlpha); mSecondaryAlpha = Math.round(disabledAlpha * 0xFF); mSecondaryProgressDrawable.setAlpha(mSecondaryAlpha); mSecondaryProgressDrawable.setShowTrack(false); setId(2, android.R.id.progress); mProgressDrawable = (SingleHorizontalProgressDrawable) getDrawable(2); mProgressDrawable.setShowTrack(false); }
/** * 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 (mStacked != stacked || force) { setGravity(stacked ? (Gravity.CENTER_VERTICAL | mStackedGravity.getGravityInt()) : Gravity.CENTER); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { //noinspection ResourceType setTextAlignment(stacked ? mStackedGravity.getTextAlignment() : TEXT_ALIGNMENT_CENTER); } DialogUtils.setBackgroundCompat(this, stacked ? mStackedBackground : mDefaultBackground); if (stacked) { setPadding(mStackedEndPadding, getPaddingTop(), mStackedEndPadding, getPaddingBottom()); } /* Else the padding was properly reset by the drawable */ mStacked = stacked; } }
private void init(Context context, AttributeSet attrs, int defStyleAttr) { Resources r = context.getResources(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MDRootLayout, defStyleAttr, 0); mReducePaddingNoTitleNoButtons = a.getBoolean(R.styleable.MDRootLayout_md_reduce_padding_no_title_no_buttons, true); a.recycle(); mNoTitlePaddingFull = r.getDimensionPixelSize(R.dimen.md_notitle_vertical_padding); mButtonPaddingFull = r.getDimensionPixelSize(R.dimen.md_button_frame_vertical_padding); mButtonHorizontalEdgeMargin = r.getDimensionPixelSize(R.dimen.md_button_padding_frame_side); mButtonBarHeight = r.getDimensionPixelSize(R.dimen.md_button_height); mDividerPaint = new Paint(); mDividerWidth = r.getDimensionPixelSize(R.dimen.md_divider_height); mDividerPaint.setColor(DialogUtils.resolveColor(context, R.attr.md_divider_color)); setWillNotDraw(false); }
/** * @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."); if (maxLength < 1) throw new IllegalArgumentException("Max length for input dialogs cannot be less than 1."); this.inputMinLength = minLength; this.inputMaxLength = maxLength; if (errorColor == 0) { this.inputRangeErrorColor = DialogUtils.getColor(context, R.color.md_edittext_error); } else { this.inputRangeErrorColor = errorColor; } return this; }
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); }
@Override public void onColorSelection(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); } } }
public static void setTint(RadioButton radioButton, @ColorInt int color) { final int disabledColor = DialogUtils.getDisabledColor(radioButton.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(radioButton.getContext(), R.attr.colorControlNormal), color, disabledColor, disabledColor }); setTint(radioButton, sl); }
public static void setTint(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); }
/** * 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; } }
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); }
/** @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; }
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); }
@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); }
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; } }
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); }
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); }
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); }
@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); }