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:ch.berta.fabio.fabprogress.FabProgress.java

private void fadeOut(boolean animate, final boolean reverse) {
    if (animate) {
        animate().setDuration(ICON_CHANGE_ANIM_DURATION).alpha(0).scaleX(0).scaleY(0)
                .setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR).setListener(new AnimatorListenerAdapter() {
                    @Override//www .j a  v a  2 s.c  o  m
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);

                        if (reverse) {
                            setImageDrawable(mFabIcon);
                            setBackgroundTintList(ColorStateList.valueOf(mAccentColor));
                        } else {
                            setImageDrawable(mCompleteIcon);
                            setBackgroundTintList(ColorStateList.valueOf(mArcColor));
                        }

                        fadeIn(reverse);
                    }
                }).start();
    } else if (reverse) {
        setImageDrawable(mFabIcon);
        setBackgroundTintList(ColorStateList.valueOf(mAccentColor));
    } else {
        setImageDrawable(mCompleteIcon);
        setBackgroundTintList(ColorStateList.valueOf(mArcColor));
    }
}

From source file:com.bilibili.magicasakura.utils.ThemeUtils.java

public static ColorStateList getThemeColorStateList(Context context, ColorStateList origin) {
    if (origin == null)
        return null;

    if (origin.isStateful()) {
        TintInfo tintInfo = parseColorStateList(origin);
        if (tintInfo == null || tintInfo.isInvalid()) {
            return origin;
        }// w w  w .  j  ava  2  s  . c o  m

        int[] newColors;
        int[][] newStates;
        int index = 0;
        boolean hasDisableColor = StateSet.stateSetMatches(tintInfo.mTintStates[0], DISABLED_STATE_SET);
        if (!hasDisableColor) {
            newStates = new int[tintInfo.mTintStates.length + 1][];
            newColors = new int[tintInfo.mTintStates.length + 1];
            newStates[index] = DISABLED_STATE_SET;
            newColors[index] = getDisabledThemeAttrColor(context, R.attr.themeColorSecondary);
            index++;
        } else {
            newStates = new int[tintInfo.mTintStates.length][];
            newColors = new int[tintInfo.mTintStates.length];
        }

        for (int i = 0; i < tintInfo.mTintStates.length; i++) {
            newStates[index] = tintInfo.mTintStates[i];
            newColors[index] = replaceColor(context, tintInfo.mTintColors[i]);
            index++;
        }
        return new ColorStateList(newStates, newColors);
    }
    return ColorStateList.valueOf(replaceColor(context, origin.getDefaultColor()));
}

From source file:com.philliphsu.bottomsheetpickers.time.grid.GridTimePickerDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);
    KeyboardListener keyboardListener = new KeyboardListener();
    view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener);

    if (!mThemeSetAtRuntime) {
        mThemeDark = Utils.isDarkTheme(getActivity(), mThemeDark);
    }/*from  ww  w.  ja v  a 2 s. c o  m*/

    final Resources res = getResources();
    final Context ctx = getActivity();
    mHourPickerDescription = res.getString(R.string.hour_picker_description);
    mSelectHours = res.getString(R.string.select_hours);
    mMinutePickerDescription = res.getString(R.string.minute_picker_description);
    mSelectMinutes = res.getString(R.string.select_minutes);
    mSelectedColor = getColor(ctx, android.R.color.white);
    mUnselectedColor = getColor(ctx, R.color.unselected_color);

    mHourView = (TextView) view.findViewById(R.id.hours);
    mHourView.setOnKeyListener(keyboardListener);
    mHourSpaceView = (TextView) view.findViewById(R.id.hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.minutes);
    mMinuteView.setOnKeyListener(keyboardListener);
    mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
    mAmPmTextView.setOnKeyListener(keyboardListener);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    // TODO: Restore
    //        mHapticFeedbackController = new HapticFeedbackController(getActivity());
    mTimePicker = (GridPickerLayout) view.findViewById(R.id.time_picker);
    mTimePicker.setOnValueSelectedListener(this);
    mTimePicker.setOnKeyListener(keyboardListener);
    mTimePicker.initialize(getActivity(), /*mHapticFeedbackController,*/ mInitialHourOfDay, mInitialMinute,
            mIs24HourMode);

    int currentItemShowing = HOUR_INDEX;
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
        currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
    }
    setCurrentItemShowing(currentItemShowing, false, true, true);
    mTimePicker.invalidate();

    mHourView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(HOUR_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mMinuteView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(MINUTE_INDEX, true, false, true);
            tryVibrate();
        }
    });

    mDoneButton = (FloatingActionButton) view.findViewById(R.id.fab);
    mDoneButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInKbMode && isTypedTimeFullyLegal()) {
                finishKbMode(false);
            } else {
                tryVibrate();
            }
            onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes());
        }
    });
    mDoneButton.setOnKeyListener(keyboardListener);

    // TODO: setOnKeyListener?
    mFirstHalfDayToggle = (Button) view.findViewById(R.id.half_day_toggle_1);
    mFirstHalfDayToggle.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            tryToggleHalfDay(HALF_DAY_1);
        }
    });
    // TODO: setOnKeyListener?
    mSecondHalfDayToggle = (Button) view.findViewById(R.id.half_day_toggle_2);
    mSecondHalfDayToggle.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            tryToggleHalfDay(HALF_DAY_2);
        }
    });

    // Enable or disable the AM/PM view.
    mAmPmHitspace = view.findViewById(R.id.ampm_hitspace);
    if (mIs24HourMode) {
        mAmPmTextView.setVisibility(View.GONE);

        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
        TextView separatorView = (TextView) view.findViewById(R.id.separator);
        separatorView.setLayoutParams(paramsSeparator);

        mFirstHalfDayToggle.setText(R.string.hours_00_11);
        mSecondHalfDayToggle.setText(R.string.hours_12_23);
        // We need different drawable resources for each case, not a single one that we
        // just tint differently, because the orientation of each one is different.
        final int icon1 = mThemeDark ? R.drawable.ic_half_day_1_dark_24dp : R.drawable.ic_half_day_1_24dp;
        final int icon2 = mThemeDark ? R.drawable.ic_half_day_2_dark_24dp : R.drawable.ic_half_day_2_24dp;
        mFirstHalfDayToggle.setCompoundDrawablesWithIntrinsicBounds(0, icon1, 0, 0);
        mSecondHalfDayToggle.setCompoundDrawablesWithIntrinsicBounds(0, icon2, 0, 0);
    } else {
        mAmPmTextView.setVisibility(View.VISIBLE);
        mAmPmHitspace.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                tryVibrate();
                int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
                if (amOrPm == HALF_DAY_1) {
                    amOrPm = HALF_DAY_2;
                } else if (amOrPm == HALF_DAY_2) {
                    amOrPm = HALF_DAY_1;
                }
                updateHalfDay(amOrPm);
                mTimePicker.setHalfDay(amOrPm);
            }
        });
        mFirstHalfDayToggle.setText(mAmText);
        mSecondHalfDayToggle.setText(mPmText);
    }

    mAllowAutoAdvance = true;
    setHour(mInitialHourOfDay, true);
    setMinute(mInitialMinute);

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();
    if (mInKbMode) {
        mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
        tryStartingKbMode(-1);
        mHourView.invalidate();
    } else if (mTypedTimes == null) {
        mTypedTimes = new ArrayList<Integer>();
    }

    // Set the theme at the end so that the initialize()s above don't counteract the theme.
    //
    // If you decide to move the FAB and the half day toggles to the GridPickerLayout
    // class, you should remove getApplicationContext(). Otherwise, you would not
    // retrieve the correct accent color.
    mTimePicker.setTheme(getActivity().getApplicationContext(), mThemeDark);
    // Prepare some colors to use.
    final int white = getColor(ctx, android.R.color.white);
    final int darkGray = getColor(ctx, R.color.dark_gray);
    final int lightGray = getColor(ctx, R.color.light_gray);
    final int accentColor = Utils.getThemeAccentColor(getActivity());
    final int sidebarDark = getColor(ctx, R.color.sidebar_color_dark);
    final int sidebarLight = getColor(ctx, R.color.sidebar_color_light);

    // Set the whole view's background color first
    view.setBackgroundColor(mThemeDark ? darkGray : white);
    // Set the colors for each view based on the theme.
    view.findViewById(R.id.time_display_background).setBackgroundColor(mThemeDark ? lightGray : accentColor);
    view.findViewById(R.id.time_display).setBackgroundColor(mThemeDark ? lightGray : accentColor);
    ((TextView) view.findViewById(R.id.separator)).setTextColor(mUnselectedColor);
    ((TextView) view.findViewById(R.id.ampm_label)).setTextColor(mUnselectedColor);
    view.findViewById(R.id.sidebar).setBackgroundColor(mThemeDark ? sidebarDark : sidebarLight);

    // Color in normal state
    mDoneButton.setBackgroundTintList(ColorStateList.valueOf(accentColor));
    //TODO        mDoneButton.setRippleColor();

    mHalfDayToggleSelectedColor = accentColor;
    mHalfDayToggleUnselectedColor = getColor(ctx,
            mThemeDark ? R.color.text_color_primary_dark : R.color.text_color_primary_light);

    Utils.setColorControlHighlight(mFirstHalfDayToggle, accentColor);
    Utils.setColorControlHighlight(mSecondHalfDayToggle, accentColor);

    // Update the half day at the end when the state colors have been initialized
    updateHalfDay(mInitialHourOfDay < 12 ? HALF_DAY_1 : HALF_DAY_2);
    return view;
}

From source file:com.lamcreations.scaffold.common.views.RoundedImageView.java

public void setBorderColor(@ColorInt int color) {
    setBorderColor(ColorStateList.valueOf(color));
}

From source file:com.zertinteractive.wallpaper.activities.DetailActivity.java

private void updateBackground(FloatingActionButton fab, Palette palette) {
    int lightVibrantColor = palette
            .getLightVibrantColor(getResources().getColor(R.color.palette_default_color));
    int vibrantColor = palette.getVibrantColor(getResources().getColor(R.color.accent));
    fab.setRippleColor(lightVibrantColor);
    fab.setBackgroundTintList(ColorStateList.valueOf(vibrantColor));
}

From source file:com.albedinsky.android.ui.widget.SearchView.java

/**
 * Called from one of constructors of this view to perform its initialization.
 * <p>//from w ww . j a  v  a 2 s  .  co m
 * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for
 * this view specific data from it that can be used to configure this new view instance. The
 * specified <var>defStyleAttr</var> and <var>defStyleRes</var> are used to obtain default data
 * from the current theme provided by the specified <var>context</var>.
 */
@SuppressWarnings("ResourceType")
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    this.mContext = context;
    setOrientation(HORIZONTAL);
    setGravity(Gravity.CENTER_VERTICAL);
    this.inflateHierarchy(context, R.layout.ui_search_view);
    this.mProgressBarAnimator = createProgressBarAnimator();
    this.mDefaultRevealAnimationHandler = createRevealAnimationHandler();
    ColorStateList tintList = null;
    PorterDuff.Mode tintMode = PorterDuff.Mode.SRC_IN;
    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_SearchView, defStyleAttr,
            defStyleRes);
    if (typedArray != null) {
        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            final int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_SearchView_android_queryHint) {
                setQueryHint(typedArray.getText(index));
            } else if (index == R.styleable.Ui_SearchView_uiTint) {
                tintList = typedArray.getColorStateList(index);
            } else if (index == R.styleable.Ui_SearchView_uiTintMode) {
                tintMode = TintManager.parseTintMode(typedArray.getInt(R.styleable.Ui_SearchView_uiTintMode, 0),
                        tintList != null ? PorterDuff.Mode.SRC_IN : null);
            } else if (index == R.styleable.Ui_SearchView_uiRevealDuration) {
                mDefaultRevealAnimationHandler.revealDuration = typedArray.getInt(index, 0);
            } else if (index == R.styleable.Ui_SearchView_uiConcealDuration) {
                mDefaultRevealAnimationHandler.concealDuration = typedArray.getInt(index, 0);
            } else if (index == R.styleable.Ui_SearchView_uiRevealInterpolator) {
                final int resId = typedArray.getResourceId(index, 0);
                if (resId != 0) {
                    mDefaultRevealAnimationHandler.interpolator = AnimationUtils.loadInterpolator(context,
                            resId);
                }
            }
        }
        typedArray.recycle();
    }
    if (tintList != null || tintMode != null) {
        this.mTintInfo = new SearchTintInfo();
        this.mTintInfo.tintList = tintList;
        this.mTintInfo.hasTintList = tintList != null;
        this.mTintInfo.tintMode = tintMode;
        this.mTintInfo.hasTintMode = tintMode != null;
    }
    final Resources.Theme theme = context.getTheme();
    final TypedValue typedValue = new TypedValue();
    if (theme.resolveAttribute(R.attr.uiSearchSelectHandleColor, typedValue, true)) {
        if (mTintInfo == null) {
            this.mTintInfo = new SearchTintInfo();
        }
        if (typedValue.resourceId > 0) {
            mTintInfo.textSelectHandleTintList = ResourceUtils.getColorStateList(getResources(),
                    typedValue.resourceId, theme);
        } else {
            mTintInfo.textSelectHandleTintList = ColorStateList.valueOf(typedValue.data);
        }
        mTintInfo.hasTextSelectHandleTintList = mTintInfo.textSelectHandleTintList != null;
    }
    this.applyTint();
    this.mRevealAnimationHandler = mDefaultRevealAnimationHandler;
}

From source file:com.lamcreations.scaffold.common.views.RoundedImageView.java

public void setBorderColor(ColorStateList colors) {
    if (mBorderColor.equals(colors)) {
        return;//from   w  w  w  . j a  v a2s .  c  om
    }

    mBorderColor = (colors != null) ? colors : ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR);
    updateDrawableAttrs();
    updateBackgroundDrawableAttrs(false);
    if (mBorderWidth > 0) {
        invalidate();
    }
}

From source file:org.mariotaku.twidere.activity.support.SignInActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    setupWindow();/* ww  w .j  av a  2 s .c  om*/
    super.onCreate(savedInstanceState);
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
    mResolver = getContentResolver();
    mApplication = TwidereApplication.getInstance(this);
    setContentView(R.layout.activity_sign_in);
    setSupportActionBar((Toolbar) findViewById(R.id.action_bar));

    TwidereActionModeForChildListener actionModeForChildListener = new TwidereActionModeForChildListener(this,
            this, false);
    final TintedStatusNativeActionModeAwareLayout layout = (TintedStatusNativeActionModeAwareLayout) findViewById(
            R.id.main_content);
    layout.setActionModeForChildListener(actionModeForChildListener);

    ThemeUtils.setCompatContentViewOverlay(this, new EmptyDrawable());
    final View actionBarContainer = findViewById(R.id.twidere_action_bar_container);
    ViewCompat.setElevation(actionBarContainer, ThemeUtils.getSupportActionBarElevation(this));
    ViewSupport.setOutlineProvider(actionBarContainer, ViewOutlineProviderCompat.BACKGROUND);
    final View windowOverlay = findViewById(R.id.window_overlay);
    ViewSupport.setBackground(windowOverlay,
            ThemeUtils.getNormalWindowContentOverlay(this, getCurrentThemeResourceId()));

    if (savedInstanceState != null) {
        mAPIUrlFormat = savedInstanceState.getString(Accounts.API_URL_FORMAT);
        mAuthType = savedInstanceState.getInt(Accounts.AUTH_TYPE);
        mSameOAuthSigningUrl = savedInstanceState.getBoolean(Accounts.SAME_OAUTH_SIGNING_URL);
        mConsumerKey = trim(savedInstanceState.getString(Accounts.CONSUMER_KEY));
        mConsumerSecret = trim(savedInstanceState.getString(Accounts.CONSUMER_SECRET));
        mUsername = savedInstanceState.getString(Accounts.SCREEN_NAME);
        mPassword = savedInstanceState.getString(Accounts.PASSWORD);
        mAPIChangeTimestamp = savedInstanceState.getLong(EXTRA_API_LAST_CHANGE);
    }

    mUsernamePasswordContainer
            .setVisibility(mAuthType == ParcelableCredentials.AUTH_TYPE_TWIP_O_MODE ? View.GONE : View.VISIBLE);
    mSignInSignUpContainer
            .setOrientation(mAuthType == ParcelableCredentials.AUTH_TYPE_TWIP_O_MODE ? LinearLayout.VERTICAL
                    : LinearLayout.HORIZONTAL);

    mEditUsername.setText(mUsername);
    mEditUsername.addTextChangedListener(this);
    mEditPassword.setText(mPassword);
    mEditPassword.addTextChangedListener(this);
    final Resources resources = getResources();
    final ColorStateList color = ColorStateList.valueOf(resources.getColor(R.color.material_light_green));
    ViewCompat.setBackgroundTintList(mSignInButton, color);
    setSignInButton();
}

From source file:com.mightyworkouts.seekbar.DiscreteSeekBar.java

/**
 * Sets the color of the seek thumb, as well as the color of the popup indicator.
 *
 * @param thumbColor     The color the seek thumb will be changed to
 * @param indicatorColor The color the popup indicator will be changed to
 *                       The indicator will animate from thumbColor to indicatorColor
 *                       when opening//w w w  .  j  a v  a  2  s .c o  m
 */
public void setThumbColor(int thumbColor, int indicatorColor) {

    mThumb.setColorStateList(ColorStateList.valueOf(thumbColor));
    mIndicator.setColors(indicatorColor, thumbColor);
}

From source file:android.support.designox.widget.TextInputLayout.java

/**
 * Sets the hint text color, size, style from the specified TextAppearance resource.
 *
 * @attr ref android.support.designox.R.styleable#TextInputLayout_hintTextAppearance
 *///from  w w w.  j av  a2  s.  c  o  m
public void setHintTextAppearance(@StyleRes int resId) {
    mCollapsingTextHelper.setCollapsedTextAppearance(resId);
    mFocusedTextColor = ColorStateList.valueOf(mCollapsingTextHelper.getCollapsedTextColor());

    if (mEditText != null) {
        updateLabelState(false);

        // Text size might have changed so update the top margin
        LayoutParams lp = updateEditTextMargin(mEditText.getLayoutParams());
        mEditText.setLayoutParams(lp);
        mEditText.requestLayout();
    }
}