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:org.floens.chan.ui.controller.ThemeSettingsController.java

@Override
public void onCreate() {
    super.onCreate();

    navigationItem.setTitle(R.string.settings_screen_theme);
    navigationItem.swipeable = false;//from www .  j a  v  a  2 s. c o  m
    view = inflateRes(R.layout.controller_theme);

    themeHelper = ThemeHelper.getInstance();
    themes = themeHelper.getThemes();

    pager = (ViewPager) view.findViewById(R.id.pager);
    done = (FloatingActionButton) view.findViewById(R.id.add);
    done.setOnClickListener(this);

    textView = (TextView) view.findViewById(R.id.text);

    SpannableString changeAccentColor = new SpannableString(getString(R.string.setting_theme_accent));
    changeAccentColor.setSpan(new ClickableSpan() {
        @Override
        public void onClick(View widget) {
            showAccentColorPicker();
        }
    }, 0, changeAccentColor.length(), 0);

    textView.setText(TextUtils.concat(getString(R.string.setting_theme_explanation), changeAccentColor));
    textView.setMovementMethod(LinkMovementMethod.getInstance());

    adapter = new Adapter();
    pager.setAdapter(adapter);

    ChanSettings.ThemeColor currentSettingsTheme = ChanSettings.getThemeAndColor();
    for (int i = 0; i < themeHelper.getThemes().size(); i++) {
        Theme theme = themeHelper.getThemes().get(i);
        ThemeHelper.PrimaryColor primaryColor = theme.primaryColor;

        if (theme.name.equals(currentSettingsTheme.theme)) {
            // Current theme
            pager.setCurrentItem(i, false);
        }
        selectedPrimaryColors.add(primaryColor);
    }
    selectedAccentColor = themeHelper.getTheme().accentColor;
    done.setBackgroundTintList(ColorStateList.valueOf(selectedAccentColor.color));
}

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

public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundedImageView, defStyle, 0);

    int index = a.getInt(R.styleable.RoundedImageView_android_scaleType, -1);
    if (index >= 0) {
        setScaleType(SCALE_TYPES[index]);
    } else {/*from  www.j  a v a 2  s .c  o m*/
        // default scaletype to FIT_CENTER
        setScaleType(ScaleType.FIT_CENTER);
    }

    float cornerRadiusOverride = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius, -1);

    mCornerRadii[Corner.TOP_LEFT] = a
            .getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_left, -1);
    mCornerRadii[Corner.TOP_RIGHT] = a
            .getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_right, -1);
    mCornerRadii[Corner.BOTTOM_RIGHT] = a
            .getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_right, -1);
    mCornerRadii[Corner.BOTTOM_LEFT] = a
            .getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_left, -1);

    boolean any = false;
    for (int i = 0, len = mCornerRadii.length; i < len; i++) {
        if (mCornerRadii[i] < 0) {
            mCornerRadii[i] = 0f;
        } else {
            any = true;
        }
    }

    if (!any) {
        if (cornerRadiusOverride < 0) {
            cornerRadiusOverride = DEFAULT_RADIUS;
        }
        for (int i = 0, len = mCornerRadii.length; i < len; i++) {
            mCornerRadii[i] = cornerRadiusOverride;
        }
    }

    mBorderWidth = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_border_width, -1);
    if (mBorderWidth < 0) {
        mBorderWidth = DEFAULT_BORDER_WIDTH;
    }

    mBorderColor = a.getColorStateList(R.styleable.RoundedImageView_riv_border_color);
    if (mBorderColor == null) {
        mBorderColor = ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR);
    }

    mMutateBackground = a.getBoolean(R.styleable.RoundedImageView_riv_mutate_background, false);
    mIsOval = a.getBoolean(R.styleable.RoundedImageView_riv_oval, false);

    final int tileMode = a.getInt(R.styleable.RoundedImageView_riv_tile_mode, TILE_MODE_UNDEFINED);
    if (tileMode != TILE_MODE_UNDEFINED) {
        setTileModeX(parseTileMode(tileMode));
        setTileModeY(parseTileMode(tileMode));
    }

    final int tileModeX = a.getInt(R.styleable.RoundedImageView_riv_tile_mode_x, TILE_MODE_UNDEFINED);
    if (tileModeX != TILE_MODE_UNDEFINED) {
        setTileModeX(parseTileMode(tileModeX));
    }

    final int tileModeY = a.getInt(R.styleable.RoundedImageView_riv_tile_mode_y, TILE_MODE_UNDEFINED);
    if (tileModeY != TILE_MODE_UNDEFINED) {
        setTileModeY(parseTileMode(tileModeY));
    }

    updateDrawableAttrs();
    updateBackgroundDrawableAttrs(true);

    a.recycle();
}

From source file:cc.wudoumi.framework.views.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    tabBackgroundResId = R.drawable.background_tab;
    setFillViewport(true);//  w w  w . j a  v  a2s .co  m
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    //tabTextColor = a.getColor(1, tabTextColor);
    textColor = a.getColorStateList(1);
    if (textColor == null) {
        textColor = ColorStateList.valueOf(tabTextColor);
    }
    a.recycle();

    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    selecttabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsSelectTextSize,
            tabTextSize);
    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }

    tabTextSizeChange = tabTextSize != selecttabTextSize;
}

From source file:kr.selfcontrol.selflocklauncher.picker.HorizontalPicker.java

public HorizontalPicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // create the selector wheel paint
    TextPaint paint = new TextPaint();
    paint.setAntiAlias(true);/*from  w  ww . j  a v  a  2s  . c  o  m*/
    mTextPaint = paint;

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HorizontalPicker, defStyle, 0);

    CharSequence[] values;
    int ellipsize = 3; // END default value
    int sideItems = mSideItems;

    try {
        mTextColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor);
        if (mTextColor == null) {
            mTextColor = ColorStateList.valueOf(0xFF000000);
        }

        values = a.getTextArray(R.styleable.HorizontalPicker_values);
        ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize);
        mMarqueeRepeatLimit = a.getInt(R.styleable.HorizontalPicker_android_marqueeRepeatLimit,
                mMarqueeRepeatLimit);
        mDividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, mDividerSize);
        sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems);

        float textSize = a.getDimension(R.styleable.HorizontalPicker_android_textSize, -1);
        if (textSize > -1) {
            setTextSize(textSize);
        }
    } finally {
        a.recycle();
    }

    switch (ellipsize) {
    case 1:
        setEllipsize(TextUtils.TruncateAt.START);
        break;
    case 2:
        setEllipsize(TextUtils.TruncateAt.MIDDLE);
        break;
    case 3:
        setEllipsize(TextUtils.TruncateAt.END);
        break;
    case 4:
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
        break;
    }

    Paint.FontMetricsInt fontMetricsInt = mTextPaint.getFontMetricsInt();
    mBoringMetrics = new BoringLayout.Metrics();
    mBoringMetrics.ascent = fontMetricsInt.ascent;
    mBoringMetrics.bottom = fontMetricsInt.bottom;
    mBoringMetrics.descent = fontMetricsInt.descent;
    mBoringMetrics.leading = fontMetricsInt.leading;
    mBoringMetrics.top = fontMetricsInt.top;
    mBoringMetrics.width = mItemWidth;

    setWillNotDraw(false);

    mFlingScrollerX = new OverScroller(context);
    mAdjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f));

    // initialize constants
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity()
            / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
    mOverscrollDistance = configuration.getScaledOverscrollDistance();

    mPreviousScrollerX = Integer.MIN_VALUE;

    setValues(values);
    setSideItems(sideItems);

    mTouchHelper = new PickerTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);

}

From source file:com.lab47billion.appchooser.HorizontalPicker.java

public HorizontalPicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    _context = context;/*ww w  .j  a  v a  2  s. com*/

    // create the selector wheel paint
    TextPaint paint = new TextPaint();
    paint.setAntiAlias(true);
    mTextPaint = paint;

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HorizontalPicker, defStyle, 0);

    CharSequence[] values;
    int ellipsize = 3; // END default value
    int sideItems = mSideItems;

    try {
        mTextColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor);
        if (mTextColor == null) {
            mTextColor = ColorStateList.valueOf(0xFF000000);
        }

        values = a.getTextArray(R.styleable.HorizontalPicker_values);
        ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize);
        mDividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, mDividerSize);
        mNormalTextSize = a.getDimension(R.styleable.HorizontalPicker_normalTextSize, 20);
        mSelectedTextSize = a.getDimension(R.styleable.HorizontalPicker_selectedTextSize, -1);
        sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems);

        if (mNormalTextSize > -1) {
            setTextSize(mNormalTextSize);
        }
        if (mSelectedTextSize == -1) {
            mSelectedTextSize = mNormalTextSize;
        }

    } finally {
        a.recycle();
    }

    switch (ellipsize) {
    case 1:
        setEllipsize(TextUtils.TruncateAt.START);
        break;
    case 2:
        setEllipsize(TextUtils.TruncateAt.MIDDLE);
        break;
    case 3:
        setEllipsize(TextUtils.TruncateAt.END);
        break;
    case 4:
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
        break;
    }

    Paint.FontMetricsInt fontMetricsInt = mTextPaint.getFontMetricsInt();
    mBoringMetrics = new BoringLayout.Metrics();
    mBoringMetrics.ascent = fontMetricsInt.ascent;
    mBoringMetrics.bottom = fontMetricsInt.bottom;
    mBoringMetrics.descent = fontMetricsInt.descent;
    mBoringMetrics.leading = fontMetricsInt.leading;
    mBoringMetrics.top = fontMetricsInt.top;
    mBoringMetrics.width = mItemWidth;

    setWillNotDraw(false);

    mFlingScrollerX = new OverScroller(context);
    mAdjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f));

    // initialize constants
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity()
            / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
    mOverscrollDistance = configuration.getScaledOverscrollDistance();

    mPreviousScrollerX = Integer.MIN_VALUE;

    setValues(values);
    setSideItems(sideItems);

    /*mTouchHelper = new PickerTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);*/

}

From source file:spit.matrix2017.Activities.EventDetails.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_event_details);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*www .j a va 2  s .c o  m*/
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("");

    final AppCompatTextView textViews[] = { (AppCompatTextView) findViewById(R.id.tv_event_description),
            (AppCompatTextView) findViewById(R.id.tv_event_venue_time),
            (AppCompatTextView) findViewById(R.id.tv_event_registration),
            (AppCompatTextView) findViewById(R.id.tv_event_prizes),
            (AppCompatTextView) findViewById(R.id.tv_event_organizers) };

    collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsingToolbar_event);
    organizers_card = (CardView) findViewById(R.id.organizers_card);
    prizes_card = (CardView) findViewById(R.id.prizes_card);
    registration_card = (CardView) findViewById(R.id.registration_card);

    visitedCalendar = false;
    isFirstLaunch = true;

    //get intent from eventlist adapter
    if (getIntent().getStringExtra("name") != null && getSupportActionBar() != null) {
        event_name = getIntent().getStringExtra("name");
        this.setTitle(event_name);
    } else
        this.setTitle("Some event");

    setDescription(getIntent().getStringExtra("description"));
    setVenueAndTime(getIntent().getStringExtra("venue"), getIntent().getStringExtra("time"));
    setRegistration(getIntent().getStringExtra("registration"));
    setPrizes(getIntent().getStringExtra("prizes"));
    setContacts(getIntent().getStringExtra("contact1name"), getIntent().getStringExtra("contact1no"),
            getIntent().getStringExtra("contact2name"), getIntent().getStringExtra("contact2no"));

    isFavouriteEvent = getIntent().getIntExtra("favorite", 0) == 1;
    isReminderSet = getIntent().getIntExtra("reminder", 0) == 1;

    mainImageView = (ImageView) findViewById(R.id.main_imageView);
    assert mainImageView != null;
    mainImageView.setImageResource(getIntent().getIntExtra("image", R.drawable.event_vsm));

    fab = (FloatingActionButton) findViewById(R.id.fab);
    assert fab != null;
    if (isFavouriteEvent)
        fab.setImageResource(R.drawable.svg_favorite_white_48px);

    Bitmap bitmap = ((BitmapDrawable) mainImageView.getDrawable()).getBitmap();

    Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
        @Override
        public void onGenerated(Palette palette) {
            Palette.Swatch swatch = palette.getVibrantSwatch();
            if (swatch == null)
                swatch = palette.getMutedSwatch();
            if (swatch != null) {
                int color = swatch.getRgb();
                if (Color.red(color) + Color.green(color) + Color.green(color) > 420)
                    color = Color.rgb((int) (Color.red(color) * 0.8), (int) (Color.green(color) * 0.8),
                            (int) (Color.blue(color) * 0.8));

                fab.setBackgroundTintList(ColorStateList.valueOf(color));
                fab.setRippleColor(swatch.getTitleTextColor());
                collapsingToolbarLayout.setContentScrimColor(color);
                collapsingToolbarLayout.setBackgroundColor(color);
                collapsingToolbarLayout.setStatusBarScrimColor(color);

                if (Build.VERSION.SDK_INT >= 21) {
                    getWindow().setStatusBarColor(color);
                }

                for (AppCompatTextView textView : textViews)
                    textView.setTextColor(color);
            }
        }
    });

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            isFavouriteEvent = !isFavouriteEvent;
            ContentResolver contentResolver = getContentResolver();
            Uri uri = Uri.parse("content://spit.matrix2017.provider");
            String selection = "name = ?";
            String[] selectionArgs = { getIntent().getStringExtra("name") };
            ContentValues cv = new ContentValues();

            if (isFavouriteEvent) {
                cv.put("favorite", 1);
                contentResolver.update(uri, cv, selection, selectionArgs);
                Toast.makeText(EventDetails.this, "Added to favorites", Toast.LENGTH_SHORT).show();
                fab.setImageResource(R.drawable.svg_favorite_white_48px);
            } else {
                cv.put("favorite", 0);
                contentResolver.update(uri, cv, selection, selectionArgs);
                fab.setImageResource(R.drawable.svg_favorite_border_white_48px);
            }
        }
    });
}

From source file:com.freshdigitable.udonroad.UserInfoView.java

private void bindFollowingStatus(@StringRes int status, @ColorRes int color) {
    followingStatus.setText(status);/*  ww  w.j a v a 2 s. co  m*/
    ViewCompat.setBackgroundTintList(followingStatus,
            ColorStateList.valueOf(ContextCompat.getColor(getContext(), color)));
    followingStatus.setVisibility(VISIBLE);
}

From source file:com.facebook.react.views.slider.ReactSlider.java

@TargetApi(21)
public void setThumbColor(Integer value) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setThumbTintList(ColorStateList.valueOf(value));
    } else {/*from  ww w . j  av a 2s. c  o  m*/
        DrawableCompat.setTintList(getThumb().mutate(), ColorStateList.valueOf(value));
    }
}

From source file:us.bridgeses.minder_tasks.viewtranslators.TaskActivity.java

@Override
public void applyTheme(@NonNull Theme theme) {
    mainFrame.setBackgroundColor(theme.getBackgroundColor());
    header.setBackgroundColor(theme.getPrimaryColor());
    newButton.setBackgroundTintList(ColorStateList.valueOf(theme.getHighlightColor()));
    title.setText(theme.getTitle());// w  w w  .  j a  va  2  s  .  c  o  m
    title.setTextSize(theme.getHeadlineSize());
    title.setTextColor(theme.getHighlightFontColor());
    caption.setText(theme.getCaption());
    caption.setTextSize(theme.getTextSize());
    caption.setTextColor(theme.getHighlightFontColor());

}

From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static Drawable createButtonRippleBg(Context context, int colorButtonNormal,
        int colorControlHighlight) {
    return new RippleDrawable(ColorStateList.valueOf(colorControlHighlight), null,
            createButtonShape(context, colorButtonNormal));
}