Java Code Examples for android.support.v4.content.ContextCompat#getColor()

The following examples show how to use android.support.v4.content.ContextCompat#getColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CategoryController.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
public static int getBackgroundColour(Context context, @NonNull String categoryName) {
    int colourId = getCategoryResource(context, categoryName, "color", true);
    if (colourId > 0) {
        return ContextCompat.getColor(context, colourId);
    }

    // Seed based on the categoryName, so that each time we try to choose a colour for the same
    // category it will look the same for each different user, and each different session.
    Random random = new Random(categoryName.toLowerCase(Locale.ENGLISH).hashCode());

    float[] hsv = new float[3];
    hsv[0] = random.nextFloat() * 360;
    hsv[1] = 0.4f;
    hsv[2] = 0.5f;
    return Color.HSVToColor(hsv);
}
 
Example 2
Source File: BIGChart.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
protected void setColorLowRes() {
    mTime.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_mTime));
    statusView.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_statusView));
    mRelativeLayout.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_background));
    mSgv.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
    mDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
    mTimestamp.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_Timestamp));
    if (chart != null) {
        highColor = ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor);
        lowColor = ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor);
        midColor = ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor);
        pointSize = 2;
        setupCharts();
    }

}
 
Example 3
Source File: MainActivity.java    From FillDrawable with Apache License 2.0 6 votes vote down vote up
private List<FillDrawable> createDrawables() {

        final Drawable drawable = ContextCompat.getDrawable(this, R.drawable.ic_android);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());

        final int alpha = 125;

        final int rightColor = ContextCompat.getColor(this, R.color.color_3);
        final FillDrawable right = new FillDrawable(FillDrawable.FROM_RIGHT, drawable.mutate())
                .setNormalColor(ColorUtils.applyAlpha(rightColor, alpha))
                .setFillColor(rightColor);

        final int bottomColor = ContextCompat.getColor(this, R.color.color_4);
        final FillDrawable bottom = new FillDrawable(FillDrawable.FROM_BOTTOM, drawable.mutate())
                .setNormalColor(ColorUtils.applyAlpha(bottomColor, alpha))
                .setFillColor(bottomColor);

        return new ArrayList<FillDrawable>() {{
            add(right);
            add(bottom);
        }};
    }
 
Example 4
Source File: NextDoneButton.java    From IntroActivity with Apache License 2.0 6 votes vote down vote up
@SuppressLint("NewApi")
private void initialize(Context context) {
    // Set the background resource
    setBackgroundResource(R.drawable.next_done_button_selector);

    mNextDrawable = ContextCompat.getDrawable(context, getDoneDrawable());
    mDoneDrawable = ContextCompat.getDrawable(context, getNextDrawable());

    if (mColor == 0) {
        mColor = ContextCompat.getColor(context, R.color.next_done_icon_color);
    }

    if (Utils.hasLollipop()) {
        mNextDrawable.setTint(mColor);
        mDoneDrawable.setTint(mColor);
    } else {
        mNextDrawable = DrawableCompat.wrap(mNextDrawable);
        mDoneDrawable = DrawableCompat.wrap(mDoneDrawable);

        DrawableCompat.setTint(mNextDrawable, mColor);
        DrawableCompat.setTint(mDoneDrawable, mColor);
    }

    setImageDrawable(mButtonStyle == STYLE_NEXT ? mNextDrawable : mDoneDrawable);
}
 
Example 5
Source File: AppPreference.java    From good-weather with GNU General Public License v3.0 5 votes vote down vote up
public static int getTextColor(Context context) {
    String theme = getTheme(context);
    if (null == theme) {
        return ContextCompat.getColor(context, R.color.widget_transparentTheme_textColorPrimary);
    } else switch (theme) {
        case "dark":
            return ContextCompat.getColor(context, R.color.widget_darkTheme_textColorPrimary);
        case "light":
            return ContextCompat.getColor(context, R.color.widget_lightTheme_textColorPrimary);
        default:
            return ContextCompat.getColor(context, R.color.widget_transparentTheme_textColorPrimary);
    }
}
 
Example 6
Source File: TickProgressBar.java    From Tick with MIT License 5 votes vote down vote up
private void init(Context context) {
    mColorArc = ContextCompat.getColor(context, R.color.colorStrokeArc);
    mColorCircle = ContextCompat.getColor(context, R.color.colorStrokeCircle);

    setFocusable(false);
    initPainters();
}
 
Example 7
Source File: SpoilerRobotoTextView.java    From Slide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Replaces the blue line produced by <blockquote>s with something more visible
 *
 * @param spannable parsed comment text #fromHtml
 */
private void replaceQuoteSpans(Spannable spannable) {
    QuoteSpan[] quoteSpans = spannable.getSpans(0, spannable.length(), QuoteSpan.class);

    for (QuoteSpan quoteSpan : quoteSpans) {
        final int start = spannable.getSpanStart(quoteSpan);
        final int end = spannable.getSpanEnd(quoteSpan);
        final int flags = spannable.getSpanFlags(quoteSpan);

        spannable.removeSpan(quoteSpan);

        //If the theme is Light or Sepia, use a darker blue; otherwise, use a lighter blue
        final int barColor =
                (SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5)
                        ? ContextCompat.getColor(getContext(), R.color.md_blue_600)
                        : ContextCompat.getColor(getContext(), R.color.md_blue_400);

        final int BAR_WIDTH = 4;
        final int GAP = 5;

        spannable.setSpan(new CustomQuoteSpan(Color.TRANSPARENT, //background color
                        barColor, //bar color
                        BAR_WIDTH, //bar width
                        GAP), //bar + text gap
                start, end, flags);
    }
}
 
Example 8
Source File: IconColorUtils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static int loadSchmeColor(Context context, String type) {

        if (SERVER.equals(type)) {
            return ContextCompat.getColor(context, R.color.item_connection_server);
        } else if (CLIENT.equals(type)) {
            return ContextCompat.getColor(context, R.color.item_connection_client);
        } else {
            return ContextCompat.getColor(context, R.color.item_connection_server);
        }
    }
 
Example 9
Source File: ColorableProgressBar.java    From android-material-stepper with Apache License 2.0 5 votes vote down vote up
public ColorableProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mProgressColor = ContextCompat.getColor(context, R.color.ms_selectedColor);
    mProgressBackgroundColor = ContextCompat.getColor(context, R.color.ms_unselectedColor);
    super.setProgressDrawable(ContextCompat.getDrawable(context, R.drawable.ms_colorable_progress_bar));
    updateProgressDrawable();
}
 
Example 10
Source File: ActivityUtils.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
public ActivityUtils setStatusbarColor(int color, boolean... fromRes) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (fromRes != null && fromRes.length > 0 && fromRes[0]) {
            color = ContextCompat.getColor(_context, color);
        }

        _activity.getWindow().setStatusBarColor(color);
    }
    return this;
}
 
Example 11
Source File: SuntimesActivity.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param context a context used to access resources
 */
private void initColors(Context context)
{
    int[] colorAttrs = { android.R.attr.textColorPrimary };
    TypedArray typedArray = context.obtainStyledAttributes(colorAttrs);
    int def = Color.WHITE;

    color_textTimeDelta = ContextCompat.getColor(context, typedArray.getResourceId(0, def));

    typedArray.recycle();
}
 
Example 12
Source File: Span.java    From Trestle with Apache License 2.0 5 votes vote down vote up
public Builder backgroundColor(Context context, @ColorRes int bgColor) {
    try {
        this.backgroundColor = ContextCompat.getColor(context, bgColor);
    } catch (Resources.NotFoundException e) {
        Log.e("Trestle", "You need to pass in a color resource (e.g. android.R.color.white) for the backgroundColor.");
    }
    return this;
}
 
Example 13
Source File: SearchLiveo.java    From searchliveo with Apache License 2.0 4 votes vote down vote up
private int getColorIconVoice() {
    return ContextCompat.getColor(mContext, mColorIconVoice);
}
 
Example 14
Source File: AmPmCirclesView.java    From date_picker_converter with Apache License 2.0 4 votes vote down vote up
public void initialize(Context context, Locale locale, TimePickerController controller, int amOrPm) {
    if (mIsInitialized) {
        Log.e(TAG, "AmPmCirclesView may only be initialized once.");
        return;
    }

    Resources res = context.getResources();

    if (controller.isThemeDark()) {
        mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_circle_background_dark_theme);
        mAmPmTextColor = ContextCompat.getColor(context, R.color.mdtp_white);
        mAmPmDisabledTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_disabled_dark_theme);
        mSelectedAlpha = SELECTED_ALPHA_THEME_DARK;
    } else {
        mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_white);
        mAmPmTextColor = ContextCompat.getColor(context, R.color.mdtp_ampm_text_color);
        mAmPmDisabledTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_disabled);
        mSelectedAlpha = SELECTED_ALPHA;
    }

    mSelectedColor = controller.getAccentColor();
    mTouchedColor = Utils.darkenColor(mSelectedColor);
    mAmPmSelectedTextColor = ContextCompat.getColor(context, R.color.mdtp_white);

    String typefaceFamily = res.getString(R.string.mdtp_sans_serif);
    Typeface tf = Typeface.create(typefaceFamily, Typeface.NORMAL);
    mPaint.setTypeface(tf);
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Align.CENTER);

    mCircleRadiusMultiplier =
            Float.parseFloat(res.getString(R.string.mdtp_circle_radius_multiplier));
    mAmPmCircleRadiusMultiplier =
            Float.parseFloat(res.getString(R.string.mdtp_ampm_circle_radius_multiplier));
    String[] amPmTexts = new DateFormatSymbols(locale).getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mAmDisabled = controller.isAmDisabled();
    mPmDisabled = controller.isPmDisabled();

    setAmOrPm(amOrPm);
    mAmOrPmPressed = -1;

    mIsInitialized = true;
}
 
Example 15
Source File: ArticleListFragment.java    From tysq-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void initView(View view) {
    super.initView(view);

    unselectColor = ContextCompat.getColor(getContext(), R.color.tip_text_color);
    selectColor = ContextCompat.getColor(getContext(), R.color.select_text_color);

    if (mListener != null) {
        mRecycleView.setListener(mListener);
    }

    mSortList.add(
            new SortVO(
                    Constant.SortType.COMPOSITE,
                    getString(R.string.article_list_composite),
                    true)
    );
    mSortList.add(
            new SortVO(
                    Constant.SortType.NEW,
                    getString(R.string.article_list_new),
                    false)
    );
    mSortList.add(
            new SortVO(
                    Constant.SortType.HOT,
                    getString(R.string.article_list_hot),
                    false)
    );

    handleSort();

    tvComposite.setOnClickListener(this);
    tvHot.setOnClickListener(this);
    tvNew.setOnClickListener(this);
    tvSearch.setOnClickListener(this);

    mRecycleView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

            View firstView = recyclerView.getLayoutManager().getChildAt(0);
            if (firstView == null) {
                return;
            }

            RecyclerView.ViewHolder childViewHolder = recyclerView.getChildViewHolder(firstView);

            if (childViewHolder == null) {
                return;
            }

            if (childViewHolder instanceof ArticleListAdapter.ImageViewHolder
                    || childViewHolder instanceof ArticleListAdapter.VideoViewHolder
                    || childViewHolder instanceof ArticleListAdapter.SortViewHolder
                    || childViewHolder instanceof ArticleListAdapter.TopArticleViewHolder
                    || childViewHolder instanceof ArticleListAdapter.TextViewHolder
                    || childViewHolder instanceof ArticleListAdapter.PageAdvertisementViewHolder) {
                rlSort.setVisibility(View.VISIBLE);
            } else {
                rlSort.setVisibility(View.GONE);
            }
        }
    });

    Log.d(TAG, "mSelSubId"+ mSelSubId);
}
 
Example 16
Source File: SharedPreferencesPropertyBackend.java    From memetastic with GNU General Public License v3.0 4 votes vote down vote up
public int rcolor(@ColorRes int resColorId) {
    return ContextCompat.getColor(_context, resColorId);
}
 
Example 17
Source File: BoxedVertical.java    From BoxedVerticalSeekBar with MIT License 4 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    System.out.println("INIT");
    float density = getResources().getDisplayMetrics().density;

    // Defaults, may need to link this into theme settings
    int progressColor = ContextCompat.getColor(context, R.color.color_progress);
    backgroundColor = ContextCompat.getColor(context, R.color.color_background);
    backgroundColor = ContextCompat.getColor(context, R.color.color_background);

    int textColor = ContextCompat.getColor(context, R.color.color_text);
    mTextSize = (int) (mTextSize * density);
    mDefaultValue = mMax/2;

    if (attrs != null) {
        final TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.BoxedVertical, 0, 0);

        mPoints = a.getInteger(R.styleable.BoxedVertical_points, mPoints);
        mMax = a.getInteger(R.styleable.BoxedVertical_max, mMax);
        mMin = a.getInteger(R.styleable.BoxedVertical_min, mMin);
        mStep = a.getInteger(R.styleable.BoxedVertical_step, mStep);
        mDefaultValue = a.getInteger(R.styleable.BoxedVertical_defaultValue, mDefaultValue);
        mCornerRadius = a.getInteger(R.styleable.BoxedVertical_libCornerRadius, mCornerRadius);
        mtextBottomPadding = a.getInteger(R.styleable.BoxedVertical_textBottomPadding, mtextBottomPadding);
        //Images
        mImageEnabled = a.getBoolean(R.styleable.BoxedVertical_imageEnabled, mImageEnabled);

        if (mImageEnabled){
            Assert.assertNotNull("When images are enabled, defaultImage can not be null. Please assign a drawable in the layout XML file", a.getDrawable(R.styleable.BoxedVertical_defaultImage));
            Assert.assertNotNull("When images are enabled, minImage can not be null. Please assign a drawable in the layout XML file", a.getDrawable(R.styleable.BoxedVertical_minImage));
            Assert.assertNotNull("When images are enabled, maxImage can not be null. Please assign a drawable in the layout XML file", a.getDrawable(R.styleable.BoxedVertical_maxImage));

            mDefaultImage = ((BitmapDrawable) a.getDrawable(R.styleable.BoxedVertical_defaultImage)).getBitmap();
            mMinImage = ((BitmapDrawable) a.getDrawable(R.styleable.BoxedVertical_minImage)).getBitmap();
            mMaxImage = ((BitmapDrawable) a.getDrawable(R.styleable.BoxedVertical_maxImage)).getBitmap();
        }

        progressColor = a.getColor(R.styleable.BoxedVertical_progressColor, progressColor);
        backgroundColor = a.getColor(R.styleable.BoxedVertical_backgroundColor, backgroundColor);

        mTextSize = (int) a.getDimension(R.styleable.BoxedVertical_textSize, mTextSize);
        textColor = a.getColor(R.styleable.BoxedVertical_textColor, textColor);

        mEnabled = a.getBoolean(R.styleable.BoxedVertical_enabled, mEnabled);
        mTouchDisabled = a.getBoolean(R.styleable.BoxedVertical_touchDisabled, mTouchDisabled);
        mtextEnabled = a.getBoolean(R.styleable.BoxedVertical_textEnabled, mtextEnabled);

        mPoints = mDefaultValue;

        a.recycle();
    }

    // range check
    mPoints = (mPoints > mMax) ? mMax : mPoints;
    mPoints = (mPoints < mMin) ? mMin : mPoints;

    mProgressPaint = new Paint();
    mProgressPaint.setColor(progressColor);
    mProgressPaint.setAntiAlias(true);
    mProgressPaint.setStyle(Paint.Style.STROKE);

    mTextPaint = new Paint();
    mTextPaint.setColor(textColor);
    mTextPaint.setAntiAlias(true);
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setTextSize(mTextSize);

    scrHeight = context.getResources().getDisplayMetrics().heightPixels;

}
 
Example 18
Source File: UsersAdapter.java    From mentions with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public UsersAdapter(final Context context) {
    this.context = context;
    final int orange = ContextCompat.getColor(context, R.color.mentions_default_color);
    this.colorSpan = new ForegroundColorSpan(orange);
}
 
Example 19
Source File: SuntimesSettingsActivity.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
private static void initPref_calculator(Context context, final SummaryListPreference calculatorPref, int[] requestedFeatures, String defaultCalculator)
{
    String tagDefault = context.getString(R.string.configLabel_tagDefault);
    String tagPlugin = context.getString(R.string.configLabel_tagPlugin);

    int[] colorAttrs = { R.attr.text_accentColor, R.attr.tagColor_warning };
    TypedArray typedArray = context.obtainStyledAttributes(colorAttrs);
    int colorDefault = ContextCompat.getColor(context, typedArray.getResourceId(0, R.color.text_accent_dark));
    @SuppressLint("ResourceType") int colorPlugin = ContextCompat.getColor(context, typedArray.getResourceId(1, R.color.warningTag_dark));
    typedArray.recycle();

    SuntimesCalculatorDescriptor[] calculators = (requestedFeatures == null ? SuntimesCalculatorDescriptor.values(context)
                                                                            : SuntimesCalculatorDescriptor.values(context, requestedFeatures));
    String[] calculatorEntries = new String[calculators.length];
    String[] calculatorValues = new String[calculators.length];
    CharSequence[] calculatorSummaries = new CharSequence[calculators.length];

    int i = 0;
    for (SuntimesCalculatorDescriptor calculator : calculators)
    {
        calculator.initDisplayStrings(context);
        calculatorEntries[i] = calculatorValues[i] = calculator.getName();

        String displayString = (calculator.getName().equalsIgnoreCase(defaultCalculator))
                             ? context.getString(R.string.configLabel_prefSummaryTagged, calculator.getDisplayString(), tagDefault)
                             : calculator.getDisplayString();

        if (calculator.isPlugin()) {
            displayString = context.getString(R.string.configLabel_prefSummaryTagged, displayString, tagPlugin);
        }

        SpannableString styledSummary = SuntimesUtils.createBoldColorSpan(null, displayString, tagDefault, colorDefault);
        styledSummary = SuntimesUtils.createRelativeSpan(styledSummary, displayString, tagDefault, 1.15f);

        styledSummary = SuntimesUtils.createBoldColorSpan(styledSummary, displayString, tagPlugin, colorPlugin);
        styledSummary = SuntimesUtils.createRelativeSpan(styledSummary, displayString, tagPlugin, 1.15f);

        calculatorSummaries[i] = styledSummary;
        i++;
    }

    calculatorPref.setEntries(calculatorEntries);
    calculatorPref.setEntryValues(calculatorValues);
    calculatorPref.setEntrySummaries(calculatorSummaries);
}
 
Example 20
Source File: DiscountDetailColor.java    From px-android with MIT License 4 votes vote down vote up
@Override
public int getColor(@NonNull final Context context) {
    return ContextCompat.getColor(context, R.color.px_expressCheckoutTextColorDiscount);
}