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:cat.terrones.devops.radiofx.ui.MediaItemViewHolder.java

private static void initializeColorStateLists(Context ctx) {
    sColorStateNotPlaying = ColorStateList
            .valueOf(ctx.getResources().getColor(R.color.media_item_icon_not_playing));
    sColorStatePlaying = ColorStateList.valueOf(ctx.getResources().getColor(R.color.media_item_icon_playing));
}

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

@Override
void setRippleColor(int rippleColor) {
    if (mRippleDrawable instanceof RippleDrawable) {
        ((RippleDrawable) mRippleDrawable).setColor(ColorStateList.valueOf(rippleColor));
    } else {//from www. j  a v a2s  . c  o  m
        super.setRippleColor(rippleColor);
    }
}

From source file:com.freshdigitable.udonroad.ffab.IndicatableFFAB.java

public IndicatableFFAB(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    final View v = View.inflate(context, R.layout.view_indicatable_ffab, this);
    indicator = (ActionIndicatorView) v.findViewById(R.id.iffab_indicator);
    ffab = (FlingableFAB) v.findViewById(R.id.iffab_ffab);
    ViewCompat.setElevation(indicator, ffab.getCompatElevation());

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IndicatableFFAB, defStyleAttr,
            R.style.Widget_FFAB_IndicatableFFAB);
    try {//from  w ww.  j  a  v  a  2 s  .c  om
        final Drawable fabIcon = a.getDrawable(R.styleable.IndicatableFFAB_fabIcon);
        ffab.setImageDrawable(fabIcon);
        final int fabTint = a.getColor(R.styleable.IndicatableFFAB_fabTint, NO_ID);
        if (fabTint != NO_ID) {
            ViewCompat.setBackgroundTintList(ffab, ColorStateList.valueOf(fabTint));
        }
        final int indicatorTint = a.getColor(R.styleable.IndicatableFFAB_indicatorTint, 0);
        indicator.setBackgroundColor(indicatorTint);
        indicatorMargin = a.getDimensionPixelSize(R.styleable.IndicatableFFAB_marginFabToIndicator, 0);
    } finally {
        a.recycle();
    }

    ffab.setOnTouchListener(new OnTouchListener() {
        private MotionEvent old;

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            final int action = motionEvent.getAction();
            if (action == MotionEvent.ACTION_DOWN) {
                old = MotionEvent.obtain(motionEvent);
                onStart();
                return false;
            }
            final Direction direction = Direction.getDirection(old, motionEvent);
            if (action == MotionEvent.ACTION_MOVE) {
                onMoving(direction);
            } else if (action == MotionEvent.ACTION_UP) {
                old.recycle();
                onFling(view.getHandler());
            }
            return false;
        }

        private Direction prevSelected = Direction.UNDEFINED;

        public void onStart() {
            indicator.onActionLeave(prevSelected);
            prevSelected = Direction.UNDEFINED;
            indicator.setVisibility(View.VISIBLE);
        }

        public void onMoving(Direction direction) {
            if (prevSelected == direction) {
                return;
            }
            indicator.onActionLeave(prevSelected);
            if (isDirectionEnabled(direction)) {
                indicator.onActionSelected(direction);
            }
            prevSelected = direction;
        }

        private boolean isDirectionEnabled(Direction direction) {
            for (Direction d : enableDirections) {
                if (d == direction) {
                    return true;
                }
            }
            return false;
        }

        public void onFling(Handler handler) {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    indicator.setVisibility(View.INVISIBLE);
                }
            }, 200);
        }
    });

    if (isInEditMode()) {
        indicator.setVisibility(VISIBLE);
    }
}

From source file:com.yanzhenjie.recyclerview.swipe.SwipeMenuItem.java

public SwipeMenuItem setTextColor(@ColorInt int titleColor) {
    this.titleColor = ColorStateList.valueOf(titleColor);
    return this;
}

From source file:org.telegram.ui.ActionBar.ActionBarMenu.java

public ActionBarMenuItem addItem(int id, int icon, int backgroundColor, Drawable drawable, int width) {
    ActionBarMenuItem menuItem = new ActionBarMenuItem(getContext(), this, backgroundColor);
    menuItem.setTag(id);//ww  w  . j a  va 2s.c  om
    if (drawable != null) {
        menuItem.iconView.setImageDrawable(drawable);
    } else {
        menuItem.iconView.setImageResource(icon);
        if (icon == R.drawable.ic_ab_reply || icon == R.drawable.ic_ab_fwd_copy
                || icon == R.drawable.ic_ab_fwd_forward || icon == R.drawable.ic_ab_fwd_delete) {
            menuItem.iconView.setImageTintList(
                    ColorStateList.valueOf(ContextCompat.getColor(getContext(), R.color.secondary_text)));
        }
    }
    addView(menuItem);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) menuItem.getLayoutParams();
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.width = width;
    menuItem.setLayoutParams(layoutParams);
    menuItem.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            ActionBarMenuItem item = (ActionBarMenuItem) view;
            if (item.hasSubMenu()) {
                if (parentActionBar.actionBarMenuOnItemClick.canOpenMenu()) {
                    item.toggleSubMenu();
                }
            } else if (item.isSearchField()) {
                parentActionBar.onSearchFieldVisibilityChanged(item.toggleSearch(true));
            } else {
                onItemClick((Integer) view.getTag());
            }
        }
    });
    return menuItem;
}

From source file:rocks.stalin.android.app.ui.MediaItemViewHolder.java

private static void initializeColorStateLists(Context ctx) {
    sColorStateNotPlaying = ColorStateList
            .valueOf(ContextCompat.getColor(ctx, R.color.media_item_icon_not_playing));
    sColorStatePlaying = ColorStateList.valueOf(ContextCompat.getColor(ctx, R.color.media_item_icon_playing));
}

From source file:im.ene.ribbon.MiscUtils.java

static void setDrawableColor(@NonNull final Drawable drawable, final int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && drawable instanceof RippleDrawable) {
        ((RippleDrawable) drawable).setColor(ColorStateList.valueOf(color));
    } else {//  www .  j  a va 2  s.  c o  m
        DrawableCompat.setTint(drawable, color);
    }
}

From source file:com.auth0.android.lock.views.ActionButton.java

private Drawable generateStateBackground(Theme lockTheme) {
    int normalColor = lockTheme.getPrimaryColor(getContext());
    int pressedColor = lockTheme.getDarkPrimaryColor(getContext());
    int disabledColor = ContextCompat.getColor(getContext(), R.color.com_auth0_lock_submit_disabled);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        return new RippleDrawable(ColorStateList.valueOf(pressedColor), new ColorDrawable(normalColor), null);
    } else {// w  w w  . j  ava  2  s.  c om
        StateListDrawable states = new StateListDrawable();
        states.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed },
                new ColorDrawable(pressedColor));
        states.addState(new int[] { android.R.attr.state_enabled }, new ColorDrawable(normalColor));
        states.addState(new int[] {}, new ColorDrawable(disabledColor));
        return states;
    }
}

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

@Override
void setRippleColor(int rippleColor) {
    mRippleDrawable.setColor(ColorStateList.valueOf(rippleColor));
}

From source file:net.qiujuer.genius.ui.widget.GeniusBalloonMarker.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public GeniusBalloonMarker(Context context, AttributeSet attrs, int defStyleAttr, String maxValue) {
    super(context, attrs, defStyleAttr);

    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    int padding = (int) (PADDING_DP * displayMetrics.density) * 2;
    mNumber = new TextView(context);
    //Add some padding to this textView so the bubble has some space to breath
    mNumber.setPadding(padding, 0, padding, 0);
    mNumber.setGravity(Gravity.CENTER);// w  w w.ja va  2s. com
    mNumber.setText(maxValue);
    mNumber.setMaxLines(1);
    mNumber.setSingleLine(true);
    GeniusCompat.setTextDirection(mNumber, TEXT_DIRECTION_LOCALE);
    mNumber.setVisibility(View.INVISIBLE);

    //add some padding for the elevation shadow not to be clipped
    //I'm sure there are better ways of doing this...
    setPadding(padding, padding, padding, padding);

    resetSizes(maxValue);

    mSeparation = (int) (SEPARATION_DP * displayMetrics.density);

    mBalloonMarkerDrawable = new BalloonMarkerDrawable(ColorStateList.valueOf(Color.TRANSPARENT), 0);
    mBalloonMarkerDrawable.setCallback(this);
    mBalloonMarkerDrawable.setMarkerListener(this);
    mBalloonMarkerDrawable.setExternalOffset(padding);

    GeniusCompat.setOutlineProvider(this, mBalloonMarkerDrawable);

    if (attrs != null) {

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GeniusBalloonMarker,
                R.attr.GeniusBalloonMarkerStyle, R.style.DefaultBalloonMarkerStyle);
        int textAppearanceId = a.getResourceId(R.styleable.GeniusBalloonMarker_g_markerTextAppearance,
                R.style.DefaultBalloonMarkerTextAppearanceStyle);

        setTextAppearance(textAppearanceId);

        ColorStateList color = a.getColorStateList(R.styleable.GeniusBalloonMarker_g_markerBackgroundColor);
        setBackgroundColor(color);

        //Elevation for android 5+
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            float elevation = a.getDimension(R.styleable.GeniusBalloonMarker_g_markerElevation,
                    ELEVATION_DP * displayMetrics.density);
            ViewCompat.setElevation(this, elevation);
        }
        a.recycle();
    }
}