Example usage for android.content.res ColorStateList valueOf

List of usage examples for android.content.res ColorStateList valueOf

Introduction

In this page you can find the example usage for android.content.res ColorStateList valueOf.

Prototype

@NonNull
public static ColorStateList valueOf(@ColorInt int color) 

Source Link

Usage

From source file:com.google.cloud.android.dialogflow.ui.BubbleView.java

@SuppressWarnings("WrongConstant")
public BubbleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mTintIncoming = ColorStateList.valueOf(ContextCompat.getColor(context, R.color.incoming));
    mTintOutgoing = ColorStateList.valueOf(ContextCompat.getColor(context, R.color.outgoing));
    final Resources resources = getResources();
    mPaddingVertical = resources.getDimensionPixelSize(R.dimen.bubble_padding_vertical);
    mPaddingHorizontalShort = resources.getDimensionPixelSize(R.dimen.bubble_padding_horizontal_short);
    mPaddingHorizontalLong = resources.getDimensionPixelSize(R.dimen.bubble_padding_horizontal_long);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BubbleView);
    setDirection(a.getInt(R.styleable.BubbleView_direction, DIRECTION_INCOMING));
    a.recycle();/* ww w  .jav a 2 s  .  c  o m*/
}

From source file:com.agenmate.lollipop.util.ViewUtils.java

public static RippleDrawable createRipple(@ColorInt int color, @FloatRange(from = 0f, to = 1f) float alpha,
        boolean bounded) {
    color = ColorUtils.modifyAlpha(color, alpha);
    return new RippleDrawable(ColorStateList.valueOf(color), null,
            bounded ? new ColorDrawable(Color.WHITE) : null);
}

From source file:com.bobomee.android.common.util.EditUtil.java

public static void tintCursorDrawable(EditText editText, int color) {
    try {/*from  w ww .jav  a  2  s. c om*/
        Field fCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
        fCursorDrawableRes.setAccessible(true);
        int mCursorDrawableRes = fCursorDrawableRes.getInt(editText);
        Field fEditor = TextView.class.getDeclaredField("mEditor");
        fEditor.setAccessible(true);
        Object editor = fEditor.get(editText);
        Class<?> clazz = editor.getClass();
        Field fCursorDrawable = clazz.getDeclaredField("mCursorDrawable");
        fCursorDrawable.setAccessible(true);

        if (mCursorDrawableRes <= 0) {
            return;
        }

        Drawable cursorDrawable = editText.getContext().getResources().getDrawable(mCursorDrawableRes);
        if (cursorDrawable == null) {
            return;
        }

        Drawable tintDrawable = tintDrawable(cursorDrawable, ColorStateList.valueOf(color));
        Drawable[] drawables = new Drawable[] { tintDrawable, tintDrawable };
        fCursorDrawable.set(editor, drawables);
    } catch (Throwable ignored) {
    }
}

From source file:com.google.cloud.android.dialogflow.ui.AudioIndicatorView.java

public void setHearingVoice(boolean hearingVoice) {
    if (mHearingVoice == hearingVoice) {
        return;// w  w w . j ava  2  s.  c o  m
    }
    mHearingVoice = hearingVoice;
    if (hearingVoice) {
        stopAnimating();
        ImageViewCompat.setImageTintList(this, ColorStateList.valueOf(mColorHearingVoice));
    } else {
        startAnimating();
        ImageViewCompat.setImageTintList(this, ColorStateList.valueOf(mColorNormal));
    }
}

From source file:android.support.design.widget.FloatingActionButtonLollipop.java

@Override
void setBackgroundDrawable(ColorStateList backgroundTint, PorterDuff.Mode backgroundTintMode, int rippleColor,
        int borderWidth) {
    // Now we need to tint the shape background with the tint
    mShapeDrawable = DrawableCompat.wrap(createShapeDrawable());
    DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
    if (backgroundTintMode != null) {
        DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
    }//from   w  ww  . j  av a2s  .c o m

    final Drawable rippleContent;
    if (borderWidth > 0) {
        mBorderDrawable = createBorderDrawable(borderWidth, backgroundTint);
        rippleContent = new LayerDrawable(new Drawable[] { mBorderDrawable, mShapeDrawable });
    } else {
        mBorderDrawable = null;
        rippleContent = mShapeDrawable;
    }

    mRippleDrawable = new RippleDrawable(ColorStateList.valueOf(rippleColor), rippleContent, null);

    mContentBackground = mRippleDrawable;

    mShadowViewDelegate.setBackgroundDrawable(mRippleDrawable);
}

From source file:io.romain.passport.utils.glide.CityItemTarget.java

@Override
public void onLoadStarted(Drawable placeholder) {
    super.onLoadStarted(placeholder);
    mViewHolder.loading.setVisibility(View.VISIBLE);
    mViewHolder.content.setVisibility(View.GONE);

    mViewHolder.name.setTextColor(getColor(mViewHolder.name.getContext(), R.color.text_primary_dark));
    mViewHolder.remove.setImageTintList(
            ColorStateList.valueOf(getColor(mViewHolder.remove.getContext(), android.R.color.black)));
}

From source file:com.ww.administrator.demotest.util.ViewUtil.java

public static RippleDrawable createRipple(@NonNull Palette palette,
        @FloatRange(from = 0f, to = 1f) float darkAlpha, @FloatRange(from = 0f, to = 1f) float lightAlpha,
        @ColorInt int fallbackColor, boolean bounded) {
    int rippleColor = fallbackColor;
    // try the named swatches in preference order
    if (palette.getVibrantSwatch() != null) {
        rippleColor = ColorUtil.modifyAlpha(palette.getVibrantSwatch().getRgb(), darkAlpha);
    } else if (palette.getLightVibrantSwatch() != null) {
        rippleColor = ColorUtil.modifyAlpha(palette.getLightVibrantSwatch().getRgb(), lightAlpha);
    } else if (palette.getDarkVibrantSwatch() != null) {
        rippleColor = ColorUtil.modifyAlpha(palette.getDarkVibrantSwatch().getRgb(), darkAlpha);
    } else if (palette.getMutedSwatch() != null) {
        rippleColor = ColorUtil.modifyAlpha(palette.getMutedSwatch().getRgb(), darkAlpha);
    } else if (palette.getLightMutedSwatch() != null) {
        rippleColor = ColorUtil.modifyAlpha(palette.getLightMutedSwatch().getRgb(), lightAlpha);
    } else if (palette.getDarkMutedSwatch() != null) {
        rippleColor = ColorUtil.modifyAlpha(palette.getDarkMutedSwatch().getRgb(), darkAlpha);
    }/*from   w w w  .j a v  a2  s . co m*/
    return new RippleDrawable(ColorStateList.valueOf(rippleColor), null,
            bounded ? new ColorDrawable(Color.WHITE) : null);
}

From source file:jp.tkgktyk.xposed.forcetouchdetector.app.util.fab.FloatingActionButtonLollipop.java

@Override
void setBackgroundDrawable(Drawable originalBackground, ColorStateList backgroundTint,
        PorterDuff.Mode backgroundTintMode, int rippleColor, int borderWidth) {
    // Now we need to tint the original background with the tint
    mShapeDrawable = DrawableCompat.wrap(originalBackground.mutate());
    DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
    if (backgroundTintMode != null) {
        DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
    }/*ww  w .j a v a  2  s . c o  m*/

    final Drawable rippleContent;
    if (borderWidth > 0) {
        mBorderDrawable = createBorderDrawable(borderWidth, backgroundTint);
        rippleContent = new LayerDrawable(new Drawable[] { mBorderDrawable, mShapeDrawable });
    } else {
        mBorderDrawable = null;
        rippleContent = mShapeDrawable;
    }

    mRippleDrawable = new RippleDrawable(ColorStateList.valueOf(rippleColor), rippleContent, null);

    mShadowViewDelegate.setBackgroundDrawable(mRippleDrawable);
    mShadowViewDelegate.setShadowPadding(0, 0, 0, 0);
}

From source file:com.justplay1.shoppist.features.lists.ListFragment.java

@Override
public void onResume() {
    super.onResume();
    UiEventBus.instanceOf().filteredObservable(ThemeUpdatedEvent.class);
    uiBusSubscription = UiEventBus.instanceOf().observable().subscribe(o -> {
        actionButton.setBackgroundTintList(ColorStateList.valueOf(preferences.getColorPrimary()));
        ((MainActivity) getActivity()).refreshToolbarColor();
        ((MainActivity) getActivity()).setStatusBarColor();
        adapter.notifyDataSetChanged();//from w w  w  .ja  v  a 2 s.  co  m
    });
}

From source file:xyz.valentin.marineoh.adapters.LineRecyclerViewAdapter.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override//from w ww  . jav  a2  s .c om
public void onBindViewHolder(final ViewHolder holder, int position) {
    holder.mLine = mLines.get(position);

    holder.mLineNameButton.setText(mLines.get(position).getName());
    holder.mLineNameButton
            .setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(mLines.get(position).getColor())));
    holder.mLineNameButton.setTextColor(Color.parseColor(mLines.get(position).getTextColor()));

    holder.mLineNameButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != mListener) {
                mListener.onListFragmentInteraction(holder.mLine);
            }
        }
    });
}