Java Code Examples for android.content.Context#getColor()

The following examples show how to use android.content.Context#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: TextBadge.java    From Badger with Apache License 2.0 6 votes vote down vote up
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
static int badgeTextColor(Context context) {
    Resources.Theme theme = context.getTheme();
    TypedValue typedValue = new TypedValue();
    if (theme.resolveAttribute(R.attr.badgeTextColor, typedValue, true)) {
        return typedValue.data;
    }
    if (theme.resolveAttribute(R.attr.titleTextColor, typedValue, true)) {
        return typedValue.data;
    }
    if (WMATE) {
        return context.getResources().getColor(R.color.badgeTextColor);
    }
    if (theme.resolveAttribute(android.R.attr.titleTextColor, typedValue, true)) {
        return typedValue.data;
    }
    return context.getColor(R.color.badgeTextColor);
}
 
Example 2
Source File: SwitchBar.java    From EnhancedScreenshotNotification with GNU General Public License v3.0 6 votes vote down vote up
public SwitchBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    LayoutInflater.from(context).inflate(R.layout.switch_bar_content, this, true);
    mTextView = findViewById(android.R.id.text1);
    mSwitch = findViewById(android.R.id.checkbox);

    mDisabledBackgroundColor = context.getColor(R.color.material_grey_600);
    mEnabledBackgroundColor = ResourcesUtils.resolveColorAttr(context, android.R.attr.colorAccent);

    mDisabledText = context.getString(R.string.switch_bar_disabled);
    mEnabledText = context.getString(R.string.switch_bar_enabled);

    setOnClickListener(v -> toggle());

    updateViewStates();
}
 
Example 3
Source File: PreviewActionForegroundDrawable.java    From EnhancedScreenshotNotification with GNU General Public License v3.0 6 votes vote down vote up
public PreviewActionForegroundDrawable(@NonNull Context context) {
    mBackgroundColor = context.getColor(R.color.material_blue_500);

    mBackgroundPaint = new Paint();
    mBackgroundPaint.setColor(mBackgroundColor);
    mBackgroundPaint.setStyle(Paint.Style.FILL);
    mBackgroundPaint.setAntiAlias(true);

    mIconArcPaint = new Paint();
    mIconArcPaint.setColor(Color.WHITE);
    mIconArcPaint.setStyle(Paint.Style.STROKE);
    mIconArcPaint.setStrokeWidth(context.getResources().getDimension(R.dimen.view_icon_arc_stroke_width));
    mIconArcPaint.setAntiAlias(true);

    mIconDrawable = context.getDrawable(R.drawable.ic_open_in_browser_white_24dp);
    mArrowDrawable = context.getDrawable(R.drawable.ic_keyboard_arrow_up_white_24dp);
    mIconSize = context.getResources().getDimensionPixelSize(R.dimen.view_icon_size);
    mIconMinMargin = context.getResources().getDimensionPixelSize(R.dimen.view_icon_min_margin);
    mIconArcRadiusOffset = context.getResources().getDimensionPixelSize(R.dimen.view_icon_arc_radius_offset);
}
 
Example 4
Source File: SendScreen.java    From smartcoins-wallet with MIT License 5 votes vote down vote up
public static int getColorWrapper(Context context, int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return context.getColor(id);
    } else {
        return context.getResources().getColor(id);
    }
}
 
Example 5
Source File: ResourceUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
/** Returns the @colorInt associated with a particular resource ID {@code colorResId}. */
@ColorInt
public static int getColor(@ColorRes int colorResId, Context context) {
  // Resources.getColor(int) is deprecated M onwards and
  // Context.getColor(int) is added from M onwards.
  return context.getColor(colorResId);
}
 
Example 6
Source File: ShapeLoadingView.java    From android-shapeLoadingView with Apache License 2.0 5 votes vote down vote up
private int getColor(Context context, int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return context.getColor(id);
    } else {
        return context.getResources().getColor(id);
    }
}
 
Example 7
Source File: AddEditContacts.java    From smartcoins-wallet with MIT License 5 votes vote down vote up
public static int getColorWrapper(Context context, int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return context.getColor(id);
    } else {
        return context.getResources().getColor(id);
    }
}
 
Example 8
Source File: CompatUtils.java    From drip-steps with Apache License 2.0 5 votes vote down vote up
static public int getColor(Context context, int resourceId) {
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
		return context.getColor(resourceId);
	} else {
		//noinspection deprecation
		return context.getResources().getColor(resourceId);
	}
}
 
Example 9
Source File: ColorUtils.java    From Musicoco with Apache License 2.0 5 votes vote down vote up
public static int[] get2ToolbarTextColors(Context context) {
    int[] colors = new int[2];
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        colors[0] = context.getColor(R.color.white_d);
        colors[1] = context.getColor(R.color.white_d_d);
    } else {
        colors[0] = context.getResources().getColor(R.color.white_d);
        colors[1] = context.getResources().getColor(R.color.white_d_d);
    }

    return colors;
}
 
Example 10
Source File: ColorUtils.java    From Musicoco with Apache License 2.0 5 votes vote down vote up
/**
 * 0 主字体颜色
 * 1 辅字体颜色
 */
public static int[] get2DarkThemeTextColor(Context context) {
    int[] colors = new int[2];

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        colors[0] = context.getColor(R.color.theme_dark_main_text); //主字体色
        colors[1] = context.getColor(R.color.theme_dark_vic_text); // 辅字体色
    } else {
        colors[0] = context.getResources().getColor(R.color.theme_dark_main_text);
        colors[1] = context.getResources().getColor(R.color.theme_dark_vic_text);
    }
    return colors;
}
 
Example 11
Source File: ColorUtils.java    From Musicoco with Apache License 2.0 5 votes vote down vote up
/**
 * 0 主字体颜色
 * 1 辅字体颜色
 */
public static int[] get2WhiteThemeTextColor(Context context) {
    int[] colors = new int[2];

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        colors[0] = context.getColor(R.color.theme_white_main_text); //主字体色
        colors[1] = context.getColor(R.color.theme_white_vic_text); // 辅字体色
    } else {
        colors[0] = context.getResources().getColor(R.color.theme_white_main_text);
        colors[1] = context.getResources().getColor(R.color.theme_white_vic_text);
    }

    return colors;
}
 
Example 12
Source File: ColorUtils.java    From Musicoco with Apache License 2.0 5 votes vote down vote up
/**
 * 0 状态栏背景色<br>
 * 1 标题栏背景色<br>
 * 2 控件首选色<br>
 * 3 主背景色<br>
 * 4 辅背景色<br>
 * 5 主字体色<br>
 * 6 辅字体色<br>
 * 7 底部导航背景色<br>
 * 8 标题栏主字体色<br>
 * 9 标题栏辅字体色<br>
 */
public static int[] get10WhiteThemeColors(Context context) {
    int[] colors = new int[10];
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        colors[0] = context.getColor(R.color.theme_white_primary);
        colors[1] = context.getColor(R.color.theme_white_primary_dark);
        colors[2] = context.getColor(R.color.theme_white_accent);
        colors[3] = context.getColor(R.color.theme_white_main_bg);
        colors[4] = context.getColor(R.color.theme_white_vic_bg);
        colors[5] = context.getColor(R.color.theme_white_main_text);
        colors[6] = context.getColor(R.color.theme_white_vic_text);
        colors[7] = context.getColor(R.color.theme_white_nav);
        colors[8] = context.getColor(R.color.theme_white_toolbar_main_text);
        colors[9] = context.getColor(R.color.theme_white_toolbar_vic_text);
    } else {
        colors[0] = context.getResources().getColor(R.color.theme_white_primary);
        colors[1] = context.getResources().getColor(R.color.theme_white_primary_dark);
        colors[2] = context.getResources().getColor(R.color.theme_white_accent);
        colors[3] = context.getResources().getColor(R.color.theme_white_main_bg);
        colors[4] = context.getResources().getColor(R.color.theme_white_vic_bg);
        colors[5] = context.getResources().getColor(R.color.theme_white_main_text);
        colors[6] = context.getResources().getColor(R.color.theme_white_vic_text);
        colors[7] = context.getResources().getColor(R.color.theme_white_nav);
        colors[8] = context.getResources().getColor(R.color.theme_white_toolbar_main_text);
        colors[9] = context.getResources().getColor(R.color.theme_white_toolbar_vic_text);
    }

    AppPreference preference = new AppPreference(context);
    colors[2] = preference.getAccentColor();

    return colors;
}
 
Example 13
Source File: AlbumPictureController.java    From Musicoco with Apache License 2.0 5 votes vote down vote up
public AlbumPictureController(Context context, final ImageSwitcher view, int size) {
    this.view = view;
    this.size = size;
    this.context = context;
    this.cache = new BitmapCache(context, BitmapCache.CACHE_ALBUM_VISUALIZER_IMAGE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        defaultColor = context.getColor(R.color.default_play_bg_color);
        defaultTextColor = context.getColor(R.color.default_play_text_color);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        defaultColor = context.getResources().getColor(R.color.default_play_bg_color, null);
        defaultTextColor = context.getResources().getColor(R.color.default_play_text_color, null);
    } else {
        defaultColor = context.getResources().getColor(R.color.default_play_bg_color);
        defaultTextColor = context.getResources().getColor(R.color.default_play_text_color);
    }

    this.bitmapProducer = new BitmapProducer(context);

    colors = new int[]{
            defaultColor,
            defaultTextColor,
            defaultColor,
            defaultTextColor
    };

    rotateAnim = ObjectAnimator.ofFloat(0, 360);
    rotateAnim.setDuration(45 * 1000);
    rotateAnim.setRepeatMode(ValueAnimator.RESTART);
    rotateAnim.setRepeatCount(ValueAnimator.INFINITE);
    rotateAnim.setInterpolator(new LinearInterpolator());
    rotateAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            view.getCurrentView().setRotation(value);
        }
    });
}
 
Example 14
Source File: ResourcesHelper.java    From AndroidCommons with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static int getColor(@NonNull Context context, @ColorRes int colorResId) {
    if (Build.VERSION.SDK_INT < 23) {
        return context.getResources().getColor(colorResId);
    } else {
        return context.getColor(colorResId);
    }
}
 
Example 15
Source File: Compat.java    From geopaparazzi with GNU General Public License v3.0 5 votes vote down vote up
public static int getColor(Context context, int id) {
    int color = 0;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        color = context.getColor(id);
    } else {
        color = context.getResources().getColor(id);
    }
    return color;
}
 
Example 16
Source File: ScreenUtils.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
public static int getColor(@NonNull Context context, @ColorRes int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return context.getColor(id);
    } else {
        return context.getResources().getColor(id);
    }
}
 
Example 17
Source File: DataSourceList.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
DataSourceListAdapter(Context context) {
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mAccentColor = context.getColor(R.color.colorAccentLight);
    mDisabledColor = context.getColor(R.color.colorPrimary);
}
 
Example 18
Source File: CustomKeyboardView.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
public CustomKeyboardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    LayoutInflater inflate =
            (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    int previewLayout = 0;
    int keyTextSize = 0;
    mKeyBackground = context.getDrawable(R.drawable.keyboard_key_background);
    mKeyCapStartBackground = context.getDrawable(R.drawable.keyboard_key_background);
    mVerticalCorrection = 0;
    previewLayout = 0;
    mPreviewOffset = 0;
    mPreviewHeight = 80;
    mKeyTextSize = context.getResources().getDimensionPixelSize(R.dimen.keyboard_key_text_size);
    mKeyTextColor = 0xFFFFFFFF;
    mLabelTextSize = context.getResources().getDimensionPixelSize(R.dimen.keyboard_key_longtext_size);
    mPopupLayout = R.layout.keyboard;
    mShadowColor = 0;
    mShadowRadius = 0;
    mBackgroundDimAmount = 0.5f;
    clearHover();

    mPreviewPopup = new PopupWindow(context);
    if (previewLayout != 0) {
        mPreviewText = (TextView) inflate.inflate(previewLayout, null);
        mPreviewTextSizeLarge = (int) mPreviewText.getTextSize();
        mPreviewPopup.setContentView(mPreviewText);
        mPreviewPopup.setBackgroundDrawable(null);
    } else {
        mShowPreview = false;
    }

    mPreviewPopup.setTouchable(false);

    mPopupKeyboard = new PopupWindow(context);
    mPopupKeyboard.setBackgroundDrawable(null);
    //mPopupKeyboard.setClippingEnabled(false);

    mPopupParent = this;
    //mPredicting = true;

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(keyTextSize);
    mPaint.setTextAlign(Align.CENTER);
    mPaint.setAlpha(255);
    mPaint.setTypeface(Typeface.create("sans-serif",Typeface.NORMAL));

    mPadding = new Rect(0, 0, 0, 0);
    mMiniKeyboardCache = new HashMap<>();
    mKeyBackground.getPadding(mPadding);
    mKeyboardHoveredPadding = getResources().getDimensionPixelSize(R.dimen.keyboard_key_hovered_padding);
    mKeyboardPressedPadding = getResources().getDimensionPixelSize(R.dimen.keyboard_key_pressed_padding);

    mSwipeThreshold = (int) (500 * getResources().getDisplayMetrics().density);
    mDisambiguateSwipe = false;

    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    resetMultiTap();

    mForegroundColor = context.getColor(R.color.asphalt);
    mSelectedForegroundColor = context.getColor(R.color.fog);
}
 
Example 19
Source File: Utils.java    From PasscodeView with Apache License 2.0 4 votes vote down vote up
@ColorInt
public static int getColorCompat(@NonNull Context context, @ColorRes int colorRes) {
    return Build.VERSION.SDK_INT < Build.VERSION_CODES.M ?
            context.getResources().getColor(colorRes) : context.getColor(colorRes);
}
 
Example 20
Source File: ThemeHelper.java    From NewsMe with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a color associated with a particular resource ID
 * <p/>
 * Starting in {@link Build.VERSION_CODES#M}, the returned
 * color will be styled for the specified Context's theme.
 *
 * @param colorId The desired resource identifier, as generated by the aapt
 *                tool. This integer encodes the package, type, and resource
 *                entry. The value 0 is an invalid identifier.
 * @return A single color value in the form 0xAARRGGBB.
 */
public static int getColor(Context context, @ColorRes int colorId) {
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
        //noinspection deprecation
        return context.getResources().getColor(colorId);
    } else {
        return context.getColor(colorId);
    }
}