Search in sources :

Example 1 with TextInputEditText

use of android.support.design.widget.TextInputEditText in project Shuttle by timusus.

the class TintHelper method setTintAuto.

@SuppressWarnings("deprecation")
@SuppressLint("PrivateResource")
static void setTintAuto(@NonNull final View view, @ColorInt final int color, boolean background, final boolean isDark) {
    if (!background) {
        if (view instanceof RadioButton) {
            setTint((RadioButton) view, color, isDark);
        } else if (view instanceof SeekBar) {
            setTint((SeekBar) view, color, isDark);
        } else if (view instanceof ProgressBar) {
            setTint((ProgressBar) view, color);
        } else if (view instanceof EditText) {
            setTint((EditText) view, color, isDark);
        } else if (view instanceof CheckBox) {
            setTint((CheckBox) view, color, isDark);
        } else if (view instanceof ImageView) {
            setTint((ImageView) view, color);
        } else if (view instanceof Switch) {
            setTint((Switch) view, color, isDark);
        } else if (view instanceof SwitchCompat) {
            setTint((SwitchCompat) view, color, isDark);
        } else {
            background = true;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !background && view.getBackground() instanceof RippleDrawable) {
            // Ripples for the above views (e.g. when you tap and hold a switch or checkbox)
            RippleDrawable rd = (RippleDrawable) view.getBackground();
            final int unchecked = ContextCompat.getColor(view.getContext(), isDark ? R.color.ripple_material_dark : R.color.ripple_material_light);
            final int checked = Util.adjustAlpha(color, 0.4f);
            final ColorStateList sl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_activated, -android.R.attr.state_checked }, new int[] { android.R.attr.state_activated }, new int[] { android.R.attr.state_checked } }, new int[] { unchecked, checked, checked });
            rd.setColor(sl);
        }
    }
    if (background) {
        // Need to tint the background of a view
        if (view instanceof FloatingActionButton || view instanceof Button) {
            setTintSelector(view, color, false, isDark);
        } else if (view.getBackground() != null) {
            Drawable drawable = view.getBackground();
            if (drawable != null) {
                if (view instanceof TextInputEditText) {
                    drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
                } else {
                    drawable = createTintedDrawable(drawable, color);
                    Util.setBackgroundCompat(view, drawable);
                }
            }
        }
    }
}
Also used : TextInputEditText(android.support.design.widget.TextInputEditText) EditText(android.widget.EditText) SeekBar(android.widget.SeekBar) Drawable(android.graphics.drawable.Drawable) RippleDrawable(android.graphics.drawable.RippleDrawable) ColorStateList(android.content.res.ColorStateList) RadioButton(android.widget.RadioButton) SuppressLint(android.annotation.SuppressLint) RippleDrawable(android.graphics.drawable.RippleDrawable) Switch(android.widget.Switch) RadioButton(android.widget.RadioButton) Button(android.widget.Button) FloatingActionButton(android.support.design.widget.FloatingActionButton) CheckBox(android.widget.CheckBox) FloatingActionButton(android.support.design.widget.FloatingActionButton) TextInputEditText(android.support.design.widget.TextInputEditText) ImageView(android.widget.ImageView) ProgressBar(android.widget.ProgressBar) SwitchCompat(android.support.v7.widget.SwitchCompat) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 ColorStateList (android.content.res.ColorStateList)1 Drawable (android.graphics.drawable.Drawable)1 RippleDrawable (android.graphics.drawable.RippleDrawable)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 TextInputEditText (android.support.design.widget.TextInputEditText)1 SwitchCompat (android.support.v7.widget.SwitchCompat)1 Button (android.widget.Button)1 CheckBox (android.widget.CheckBox)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1 ProgressBar (android.widget.ProgressBar)1 RadioButton (android.widget.RadioButton)1 SeekBar (android.widget.SeekBar)1 Switch (android.widget.Switch)1