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

The following examples show how to use android.support.v4.content.res.ResourcesCompat#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: MainActivity.java    From android-docs-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final Resources resources = getResources();
    final Resources.Theme theme = getTheme();
    mColorHearing = ResourcesCompat.getColor(resources, R.color.status_hearing, theme);
    mColorNotHearing = ResourcesCompat.getColor(resources, R.color.status_not_hearing, theme);

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    mStatus = (TextView) findViewById(R.id.status);
    mText = (TextView) findViewById(R.id.text);

    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    final ArrayList<String> results = savedInstanceState == null ? null :
            savedInstanceState.getStringArrayList(STATE_RESULTS);
    mAdapter = new ResultAdapter(results);
    mRecyclerView.setAdapter(mAdapter);
}
 
Example 2
Source File: PolygonOverlayActivity.java    From android-map-sdk with Apache License 2.0 6 votes vote down vote up
@Override
public void onMapReady(@NonNull NaverMap naverMap) {
    int color = ResourcesCompat.getColor(getResources(), R.color.primary, getTheme());

    PolygonOverlay polygon = new PolygonOverlay();
    polygon.setCoords(COORDS_1);
    polygon.setColor(ColorUtils.setAlphaComponent(color, 31));
    polygon.setOutlineColor(color);
    polygon.setOutlineWidth(getResources().getDimensionPixelSize(R.dimen.overlay_line_width));
    polygon.setMap(naverMap);

    PolygonOverlay polygonWithHole = new PolygonOverlay();
    polygonWithHole.setCoords(COORDS_2);
    polygonWithHole.setHoles(HOLES);
    polygonWithHole.setColor(
        ColorUtils.setAlphaComponent(ResourcesCompat.getColor(getResources(), R.color.gray, getTheme()), 127));
    polygonWithHole.setMap(naverMap);
}
 
Example 3
Source File: SocialMentionAutoComplete.java    From SocialMentionAutoComplete with Apache License 2.0 6 votes vote down vote up
public CharSequence terminateToken(CharSequence text) {

            int i = text.length();

            while (i > 0 && text.charAt(i - 1) == ' ') {
                i--;
            }

            if (i > 0 && text.charAt(i - 1) == ' ') {
                return text;
            } else {
                // Returns colored text for selected token
                SpannableString sp = new SpannableString(String.format(formattedOfString, text));
                int textColor = ResourcesCompat.getColor(getResources(), R.color.colorPrimary, null);
                sp.setSpan(new ForegroundColorSpan(textColor), 0, text.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                return sp;
            }
        }
 
Example 4
Source File: ContactAdapter.java    From UnifiedContactPicker with Apache License 2.0 6 votes vote down vote up
public ContactAdapter(Context context, List<Contact> contacts, ContactSelectionListener listener, String selectedIconHex, byte[] selectedDrawable) {
    super(contacts);
    this.mMaterialColors = context.getResources().getIntArray(R.array.colors);
    this.mContacts = contacts;
    this.mSelection = new ArrayList<>();
    this.selectedColor = ResourcesCompat.getColor(context.getResources(), R.color.color_7,null);
    this.subtitleColor= ResourcesCompat.getColor(context.getResources(), R.color.subtitle,null);
    this.mListener = listener;

    if(selectedIconHex == null)
        this.selectedIconColor = ResourcesCompat.getColor(context.getResources(),R.color.materialGreen, null);
    else
        this.selectedIconColor = Color.parseColor(selectedIconHex);

    if(selectedDrawable != null)
        this.selectedDrawable = PickerUtils.extractDrawable(selectedDrawable);
    else
        this.selectedDrawable = PickerUtils.extractDrawable(PickerUtils.sendDrawable(context.getResources(),R.drawable.ic_done));
}
 
Example 5
Source File: CheckRadioView.java    From AlbumCameraRecorder with MIT License 5 votes vote down vote up
private void init() {
    mSelectedColor = ResourcesCompat.getColor(
            getResources(), R.color.blue_item_checkCircle_backgroundColor,
            getContext().getTheme());
    mUnSelectUdColor = ResourcesCompat.getColor(
            getResources(), R.color.blue_check_original_radio_disable,
            getContext().getTheme());
    setChecked(false);
}
 
Example 6
Source File: CircularRevealDrawable.java    From WIFIADB with Apache License 2.0 5 votes vote down vote up
public CircularRevealDrawable() {
    super();
    mPaint = new Paint();

    mResources = MyApp.getContext().getResources();
    mDefaultColor = ResourcesCompat.getColor(mResources,android.R.color.white,null);

    mColorMap = new SparseArrayCompat<>();
    mCurrentColor = EOF_COLOR;
    mNextColor = EOF_COLOR;
}
 
Example 7
Source File: CircleOverlayActivity.java    From android-map-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public void onMapReady(@NonNull NaverMap naverMap) {
    int color = ResourcesCompat.getColor(getResources(), R.color.primary, getTheme());

    CircleOverlay circleOverlay = new CircleOverlay();
    circleOverlay.setCenter(new LatLng(37.5666102, 126.9783881));
    circleOverlay.setRadius(500);
    circleOverlay.setColor(ColorUtils.setAlphaComponent(color, 31));
    circleOverlay.setOutlineColor(color);
    circleOverlay.setOutlineWidth(getResources().getDimensionPixelSize(R.dimen.overlay_line_width));
    circleOverlay.setMap(naverMap);
}
 
Example 8
Source File: MainActivity.java    From welcome-coordinator with Apache License 2.0 5 votes vote down vote up
private void initializeBackgroundTransitions() {
    final Resources resources = getResources();
    final int colorPage1 = ResourcesCompat.getColor(resources, R.color.page1, getTheme());
    final int colorPage2 = ResourcesCompat.getColor(resources, R.color.page2, getTheme());
    final int colorPage3 = ResourcesCompat.getColor(resources, R.color.page3, getTheme());
    final int colorPage4 = ResourcesCompat.getColor(resources, R.color.page4, getTheme());
    backgroundAnimator = ValueAnimator
            .ofObject(new ArgbEvaluator(), colorPage1, colorPage2, colorPage3, colorPage4);
    backgroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            coordinatorLayout.setBackgroundColor((int) animation.getAnimatedValue());
        }
    });
}
 
Example 9
Source File: SocialMentionTextView.java    From SocialMentionAutoComplete with Apache License 2.0 5 votes vote down vote up
private void init() {

        int textColor = ResourcesCompat.getColor(getResources(), R.color.colorPrimary, null);
        setLinkTextColor(textColor);
        setLinksClickable(true);
        setMovementMethod(LinkMovementMethod.getInstance());
        setFocusable(false);
    }
 
Example 10
Source File: SwingCoordinatorLayout.java    From swipe-maker with Apache License 2.0 5 votes vote down vote up
public ColorFilter getColor(Context context) {
    if (color == null) {
        color = new PorterDuffColorFilter(
                ResourcesCompat.getColor(context.getResources(), resId, context.getTheme()), PorterDuff.Mode.MULTIPLY);
    }
    return color;
}
 
Example 11
Source File: SentimentFragment.java    From android-docs-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Resources resources = getResources();
    final Resources.Theme theme = getActivity().getTheme();
    mColorPositive = ResourcesCompat.getColor(resources, R.color.score_positive, theme);
    mColorNeutral = ResourcesCompat.getColor(resources, R.color.score_neutral, theme);
    mColorNegative = ResourcesCompat.getColor(resources, R.color.score_negative, theme);
}
 
Example 12
Source File: GraphFragment.java    From CryptoBuddy with GNU Affero General Public License v3.0 5 votes vote down vote up
public void setColors(float percentChange) {
    if (percentChange >= 0) {
        chartFillColor = ResourcesCompat.getColor(getActivity().getResources(), R.color.materialLightGreen, null);
        chartBorderColor = ResourcesCompat.getColor(getActivity().getResources(), R.color.darkGreen, null);
        percentageColor = ResourcesCompat.getColor(getActivity().getResources(), R.color.percentPositiveGreen, null);
    }
    else {
        chartFillColor = ResourcesCompat.getColor(getActivity().getResources(), R.color.materialLightRed, null);
        chartBorderColor = ResourcesCompat.getColor(getActivity().getResources(), R.color.darkRed, null);
        percentageColor = ResourcesCompat.getColor(getActivity().getResources(), R.color.percentNegativeRed, null);
    }
}
 
Example 13
Source File: CircularRevealDrawable.java    From WIFIADB with Apache License 2.0 4 votes vote down vote up
public void putColor(int index,@ColorRes int colorRes){
    final int color = ResourcesCompat.getColor(mResources,colorRes,null);
    mColorMap.put(index,color);
}
 
Example 14
Source File: BottomSheetBuilder.java    From BottomSheetBuilder with Apache License 2.0 4 votes vote down vote up
public BottomSheetBuilder setTitleTextColorResource(@ColorRes int color) {
    mTitleTextColor = ResourcesCompat.getColor(mContext.getResources(), color,
            mContext.getTheme());
    return this;
}
 
Example 15
Source File: BottomDialog.java    From BottomDialogs with Apache License 2.0 4 votes vote down vote up
public Builder setPositiveTextColorResource(@ColorRes int textColorRes) {
    this.btn_colorPositive = ResourcesCompat.getColor(context.getResources(), textColorRes, null);
    return this;
}
 
Example 16
Source File: BottomDialog.java    From BottomDialogs with Apache License 2.0 4 votes vote down vote up
public Builder setPositiveBackgroundColorResource(@ColorRes int buttonColorRes) {
    this.btn_colorPositiveBackground = ResourcesCompat.getColor(context.getResources(), buttonColorRes, null);
    return this;
}
 
Example 17
Source File: BottomSheetBuilder.java    From BottomSheetBuilder with Apache License 2.0 4 votes vote down vote up
public BottomSheetBuilder setBackgroundColorResource(@ColorRes int background) {
    mBackgroundColor = ResourcesCompat.getColor(mContext.getResources(), background,
            mContext.getTheme());
    return this;
}
 
Example 18
Source File: EntityWidgetProvider.java    From homeassist with Apache License 2.0 4 votes vote down vote up
public static void updateEntityWidget(Context context, Widget widget) {
    Log.d("YouQi", "Widget updateEntityWidget: " + CommonUtil.deflate(widget));
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

    String iconText = widget.getMdiIcon(); //MDIFont.getIcon("mdi:weather-hail");
    int iconColor = ResourcesCompat.getColor(context.getResources(), (widget.isToggleable() && !widget.isCurrentStateActive()) ? R.color.md_grey_500 : R.color.xiaomiPrimaryTextSelected, null);

    Bitmap myBitmap = Bitmap.createBitmap(160, 160, Bitmap.Config.ARGB_8888);
    myBitmap.eraseColor(Color.TRANSPARENT);

    Typeface typeface = ResourcesCompat.getFont(context, R.font.mdi);
    Paint paint = new Paint();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setAntiAlias(true);
    paint.setTypeface(typeface);
    paint.setColor(iconColor);
    paint.setTextSize(160);
    //paint.setStrokeWidth(24); // Text Size
    //setTextSizeForWidth(paint, 48, iconText);
    //paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // Text Overlapping Pattern

    Canvas canvas = new Canvas(myBitmap);
    int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2));
    int xPos = (canvas.getWidth() - yPos) / 2;//(canvas.getWidth() / 2);
    canvas.drawText(iconText, 0, yPos, paint);

    RemoteViews remoteViews = new RemoteViews("com.axzae.homeassistant", R.layout.widget_entity);
    remoteViews.setImageViewBitmap(R.id.image_icon, myBitmap);
    remoteViews.setTextViewText(R.id.text_state, widget.getFriendlyStateRow());
    remoteViews.setTextColor(R.id.text_state, iconColor);
    remoteViews.setTextViewText(R.id.text_group, widget.getFriendlyName());

    //https://stackoverflow.com/questions/21311917/onreceive-will-always-receive-the-last-appwidgetid-even-different-instance-widg
    Intent newIntent = new Intent(context, EntityWidgetProvider.class);
    newIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    newIntent.putExtra("appWidgetId", widget.appWidgetId);
    newIntent.putExtra("widget", CommonUtil.deflate(widget));
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, widget.appWidgetId, newIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.item, pendingIntent);
    appWidgetManager.updateAppWidget(widget.appWidgetId, remoteViews);
    Log.d("YouQi", "appWidgetManager updating (" + widget.appWidgetId + "): " + widget.getFriendlyState());
}
 
Example 19
Source File: ClickOrLongButton.java    From AlbumCameraRecorder with MIT License 4 votes vote down vote up
private void init() {
    touchable = recordable = true;
    BOUNDING_BOX_SIZE = DisplayMetricsUtils.dip2px(100.0F); // 整块
    OUT_CIRCLE_WIDTH = DisplayMetricsUtils.dip2px(2.3F);// 外线宽度
    OUTER_CIRCLE_WIDTH_INC = DisplayMetricsUtils.dip2px(4.3F);
    INNER_CIRCLE_RADIUS = DisplayMetricsUtils.dip2px(32.0F);

    // 调取样式中的颜色
    TypedArray arrayRoundBorder = getContext().getTheme().obtainStyledAttributes(new int[]{R.attr.click_long_button_round_border});
    int defaultRoundBorderColor = ResourcesCompat.getColor(
            getResources(), R.color.click_long_button_round_border,
            getContext().getTheme());
    TypedArray arrayInnerCircleInOperation = getContext().getTheme().obtainStyledAttributes(new int[]{ R.attr.click_long_button_inner_circle_in_operation });
    int defaultInnerCircleInOperationColor = ResourcesCompat.getColor(
            getResources(), R.color.click_long_button_inner_circle_in_operation,
            getContext().getTheme());
    TypedArray arrayInnerCircleNoOperation = getContext().getTheme().obtainStyledAttributes(new int[]{ R.attr.click_long_button_inner_circle_no_operation });
    int defaultInnerCircleNoOperationColor = ResourcesCompat.getColor(
            getResources(), R.color.click_long_button_inner_circle_no_operation,
            getContext().getTheme());

    colorRecord = arrayInnerCircleInOperation.getColor(0, defaultInnerCircleInOperationColor);
    colorRoundBorder = arrayRoundBorder.getColor(0, defaultRoundBorderColor);
    colorWhiteP60 = arrayInnerCircleNoOperation.getColor(0, defaultInnerCircleNoOperationColor);
    int colorBlackP40 = getResources().getColor(R.color.black_forty_percent);
    int colorBlackP80 = getResources().getColor(R.color.black_eighty_percent);
    int colorTranslucent = getResources().getColor(R.color.circle_shallow_translucent_bg);
    // 内圈操作中样式
    processBarPaint = new Paint();
    processBarPaint.setColor(colorRecord);
    processBarPaint.setAntiAlias(true);
    processBarPaint.setStrokeWidth(OUT_CIRCLE_WIDTH);
    processBarPaint.setStyle(Style.STROKE);
    processBarPaint.setStrokeCap(Cap.ROUND);
    // 外圈样式
    outMostWhiteCirclePaint = new Paint();
    outMostWhiteCirclePaint.setColor(colorRoundBorder);
    outMostWhiteCirclePaint.setAntiAlias(true);
    outMostWhiteCirclePaint.setStrokeWidth(OUT_CIRCLE_WIDTH);
    outMostWhiteCirclePaint.setStyle(Style.STROKE);
    // 内圈未操作中样式
    centerCirclePaint = new Paint();
    centerCirclePaint.setColor(colorWhiteP60);
    centerCirclePaint.setAntiAlias(true);
    centerCirclePaint.setStyle(Style.FILL_AND_STROKE);
    outBlackCirclePaint = new Paint();
    outBlackCirclePaint.setColor(colorBlackP40);
    outBlackCirclePaint.setAntiAlias(true);
    outBlackCirclePaint.setStyle(Style.STROKE);
    outBlackCirclePaint.setStrokeWidth(1.0F);
    outMostBlackCirclePaint = new Paint();
    outMostBlackCirclePaint.setColor(colorBlackP80);
    outMostBlackCirclePaint.setAntiAlias(true);
    outMostBlackCirclePaint.setStyle(Style.STROKE);
    outMostBlackCirclePaint.setStrokeWidth(1.0F);
    translucentPaint = new Paint();
    translucentPaint.setColor(colorTranslucent);
    translucentPaint.setAntiAlias(true);
    translucentPaint.setStyle(Style.FILL_AND_STROKE);
    centerX = (BOUNDING_BOX_SIZE / 2);
    centerY = (BOUNDING_BOX_SIZE / 2);
    outMostCircleRadius = DisplayMetricsUtils.dip2px(37.0F);
    outBlackCircleRadiusInc = DisplayMetricsUtils.dip2px(7.0F);
    innerCircleRadiusWhenRecord = DisplayMetricsUtils.dip2px(35.0F);
    innerCircleRadiusToDraw = INNER_CIRCLE_RADIUS;
    outBlackCircleRadius = (outMostCircleRadius - OUT_CIRCLE_WIDTH / 2.0F);
    outMostBlackCircleRadius = (outMostCircleRadius + OUT_CIRCLE_WIDTH / 2.0F);
    startAngle270 = 270.0F;
    percentInDegree = 0.0F;
    outMostCircleRect = new RectF(centerX - outMostCircleRadius, centerY - outMostCircleRadius, centerX + outMostCircleRadius, centerY + outMostCircleRadius);
    touchTimeHandler = new TouchTimeHandler(Looper.getMainLooper(), updateUITask);
    mButtonState = BUTTON_STATE_BOTH;   // 状态为两者都可以
}
 
Example 20
Source File: XOutdatedUtils.java    From XFrame with Apache License 2.0 2 votes vote down vote up
/**
 * getColor过时方法处理
 *
 * @param id 资源id
 * @param theme 指定主题
 * @return
 */
public static int getColor(@ColorRes int id, @Nullable Resources.Theme theme) {
    return ResourcesCompat.getColor(XFrame.getResources(), id, theme);
}