Java Code Examples for android.support.annotation.ColorInt

The following are top voted examples for showing how to use android.support.annotation.ColorInt. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: mapbox-plugins-android   File: LocationLayer.java   View source code 7 votes vote down vote up
private void styleAccuracy(float accuracyAlpha, @ColorInt int accuracyColor) {
  layerMap.get(ACCURACY_LAYER).setProperties(
    circleColor(accuracyColor),
    circleOpacity(accuracyAlpha),
    circlePitchAlignment(Property.CIRCLE_PITCH_ALIGNMENT_MAP),
    circleStrokeWidth(0.5f),
    circleStrokeColor(accuracyColor)
  );
}
 
Example 2
Project: FastAndroid   File: UIStatusBarController.java   View source code 6 votes vote down vote up
/**
 * 设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColor(Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
        View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
        if (fakeStatusBarView != null) {
            if (fakeStatusBarView.getVisibility() == View.GONE) {
                fakeStatusBarView.setVisibility(View.VISIBLE);
            }
            fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        } else {
            decorView.addView(createStatusBarView(activity, color, statusBarAlpha));
        }
        setRootView(activity);
    }
}
 
Example 3
Project: qmui   File: QMUIDrawableHelper.java   View source code 6 votes vote down vote up
/**
 * 动态创建带上分隔线或下分隔线的Drawable
 *
 * @param separatorColor
 * @param bgColor
 * @param top
 * @return
 */
public static LayerDrawable createItemSeparatorBg(@ColorInt int separatorColor, @ColorInt int bgColor, int separatorHeight, boolean top) {

    ShapeDrawable separator = new ShapeDrawable();
    separator.getPaint().setStyle(Paint.Style.FILL);
    separator.getPaint().setColor(separatorColor);

    ShapeDrawable bg = new ShapeDrawable();
    bg.getPaint().setStyle(Paint.Style.FILL);
    bg.getPaint().setColor(bgColor);

    Drawable[] layers = {separator, bg};
    LayerDrawable layerDrawable = new LayerDrawable(layers);

    layerDrawable.setLayerInset(1, 0, top ? separatorHeight : 0, 0, top ? 0 : separatorHeight);
    return layerDrawable;
}
 
Example 4
Project: RLibrary   File: SnackbarUtils.java   View source code 6 votes vote down vote up
/**
 * 设置snackbar文字和背景颜色
 *
 * @param parent          父视图(CoordinatorLayout或者DecorView)
 * @param text            文本
 * @param duration        显示时长
 * @param textColor       文本颜色
 * @param bgColor         背景色
 * @param actionText      事件文本
 * @param actionTextColor 事件文本颜色
 * @param listener        监听器
 */
private static void showSnackbar(View parent, CharSequence text, int duration, @ColorInt int textColor, @ColorInt int bgColor,
                                 CharSequence actionText, int actionTextColor, View.OnClickListener listener) {
    switch (duration) {
        default:
        case Snackbar.LENGTH_SHORT:
        case Snackbar.LENGTH_LONG:
            snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, text, duration));
            break;
        case Snackbar.LENGTH_INDEFINITE:
            snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, text, Snackbar.LENGTH_INDEFINITE).setDuration(duration));
    }
    View view = snackbarWeakReference.get().getView();
    ((TextView) view.findViewById(R.id.snackbar_text)).setTextColor(textColor);
    view.setBackgroundColor(bgColor);
    if (actionText != null && actionText.length() > 0 && listener != null) {
        snackbarWeakReference.get().setActionTextColor(actionTextColor);
        snackbarWeakReference.get().setAction(actionText, listener);
    }
    snackbarWeakReference.get().show();
}
 
Example 5
Project: GitHub   File: StatusBarUtil.java   View source code 6 votes vote down vote up
/**
 * 设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */

public static void setColor(Activity activity, @ColorInt int color, int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
        int count = decorView.getChildCount();
        if (count > 0 && decorView.getChildAt(count - 1) instanceof StatusBarView) {
            decorView.getChildAt(count - 1).setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        } else {
            StatusBarView statusView = createStatusBarView(activity, color, statusBarAlpha);
            decorView.addView(statusView);
        }
        setRootView(activity);
    }
}
 
Example 6
Project: SubwayTooter   File: ColorPickerDialog.java   View source code 6 votes vote down vote up
private int[] getColorShades(@ColorInt int color) {
  return new int[]{
      shadeColor(color, 0.9),
      shadeColor(color, 0.7),
      shadeColor(color, 0.5),
      shadeColor(color, 0.333),
      shadeColor(color, 0.166),
      shadeColor(color, -0.125),
      shadeColor(color, -0.25),
      shadeColor(color, -0.375),
      shadeColor(color, -0.5),
      shadeColor(color, -0.675),
      shadeColor(color, -0.7),
      shadeColor(color, -0.775),
  };
}
 
Example 7
Project: EmoticonGIFKeyboard   File: EmoticonGifImageView.java   View source code 5 votes vote down vote up
/**
 * Get the dark color.
 *
 * @param color Original color.
 * @return Dark color.
 */
@ColorInt
private static int getDarkColor(final int color) {
    final float factor = 0.6f;

    final int a = Color.alpha(color);
    final int r = Math.round(Color.red(color) * factor);
    final int g = Math.round(Color.green(color) * factor);
    final int b = Math.round(Color.blue(color) * factor);
    return Color.argb(a,
            Math.min(r, 255),
            Math.min(g, 255),
            Math.min(b, 255));
}
 
Example 8
Project: chips-input-layout   File: CircleImageView.java   View source code 5 votes vote down vote up
/**
 * Set a color to be drawn behind the circle-shaped drawable. Note that
 * this has no effect if the drawable is opaque or no drawable is set.
 *
 * @param fillColor The color to be drawn behind the drawable
 *
 * @deprecated Fill color support is going to be removed in the future
 */
@Deprecated
public void setFillColor(@ColorInt int fillColor) {
    if (fillColor == mFillColor) {
        return;
    }

    mFillColor = fillColor;
    mFillPaint.setColor(fillColor);
    invalidate();
}
 
Example 9
Project: minion-android   File: IniSyntaxHighlighter.java   View source code 5 votes vote down vote up
private void applySpan(Spannable spannable, @ColorInt int color, int start, int end) {
    spannable.setSpan(
            new ForegroundColorSpan(color),
            start,
            end,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
Example 10
Project: MainCalendar   File: CompatUtils.java   View source code 5 votes vote down vote up
/**
 * Gets color.
 *
 * @param context  the context
 * @param colorRes the color res
 * @return the color
 */
@ColorInt
public static int getColor(Context context, @ColorRes int colorRes) {
    if (Build.VERSION.SDK_INT < 21) {
        //noinspection deprecation
        return context.getResources().getColor(colorRes);
    } else {
        return context.getResources().getColor(colorRes, null);
    }
}
 
Example 11
Project: GitHub   File: ColorUtils.java   View source code 5 votes vote down vote up
/**
 * Returns the luminance of a color as a float between {@code 0.0} and {@code 1.0}.
 * <p>Defined as the Y component in the XYZ representation of {@code color}.</p>
 */
@FloatRange(from = 0.0, to = 1.0)
public static double calculateLuminance(@ColorInt int color) {
    final double[] result = getTempDouble3Array();
    colorToXYZ(color, result);
    // Luminance is the Y component
    return result[1] / 100;
}
 
Example 12
Project: IslamicLibraryAndroid   File: Util.java   View source code 5 votes vote down vote up
@ColorInt
public static int getColorFromAttr(Context context, int attr, @ColorInt int defaultColor) {
    TypedArray a = context.obtainStyledAttributes(new TypedValue().data, new int[]{attr});
    int intColor = a.getColor(0, defaultColor);
    a.recycle();
    return intColor;
}
 
Example 13
Project: XERUNG   File: CircleImageView.java   View source code 5 votes vote down vote up
public void setFillColor(@ColorInt int fillColor) {
    if (fillColor == mFillColor) {
        return;
    }

    mFillColor = fillColor;
    mFillPaint.setColor(fillColor);
    invalidate();
}
 
Example 14
Project: MusicX-music-player   File: Helper.java   View source code 5 votes vote down vote up
@ColorInt
public static int setColorAlpha(@ColorInt int color, @FloatRange(from = 0.0D, to = 1.0D) float alpha) {
    int alpha2 = Math.round((float) Color.alpha(color) * alpha);
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    return Color.argb(alpha2, red, green, blue);
}
 
Example 15
Project: cwac-crossport   File: DrawerArrowDrawable.java   View source code 5 votes vote down vote up
/**
 * Sets the color of the drawable.
 */
public void setColor(@ColorInt int color) {
  if (color != mPaint.getColor()) {
    mPaint.setColor(color);
    invalidateSelf();
  }
}
 
Example 16
Project: AndroidDigIn   File: TouchDelegateViewGroup.java   View source code 5 votes vote down vote up
public void setDelegateAreaColor(@ColorInt int color, Rect rect) {
    paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(color);
    this.rect = rect;
    invalidate();
}
 
Example 17
Project: GitHub   File: BarUtils.java   View source code 5 votes vote down vote up
/**
 * 设置状态栏颜色
 *
 * @param fakeStatusBar 伪造状态栏
 * @param color         状态栏颜色值
 * @param alpha         状态栏透明度,此透明度并非颜色中的透明度
 */
public static void setStatusBarColor(@NonNull final View fakeStatusBar,
                                     @ColorInt final int color,
                                     @IntRange(from = 0, to = 255) final int alpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
    fakeStatusBar.setVisibility(View.VISIBLE);
    transparentStatusBar((Activity) fakeStatusBar.getContext());
    ViewGroup.LayoutParams layoutParams = fakeStatusBar.getLayoutParams();
    layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    layoutParams.height = BarUtils.getStatusBarHeight();
    fakeStatusBar.setBackgroundColor(getStatusBarColor(color, alpha));
}
 
Example 18
Project: MusicX-music-player   File: ATEUtil.java   View source code 5 votes vote down vote up
@ColorInt
public static int shiftColor(@ColorInt int color, @FloatRange(from = 0.0f, to = 2.0f) float by) {
    if (by == 1f) return color;
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= by; // value component
    return Color.HSVToColor(hsv);
}
 
Example 19
Project: TakeRest   File: FragmentUtils.java   View source code 5 votes vote down vote up
/**
 * 设置背景色
 *
 * @param fragment fragment
 * @param color    背景色
 */
public static void setBackgroundColor(@NonNull Fragment fragment, @ColorInt int color) {
    View view = fragment.getView();
    if (view != null) {
        view.setBackgroundColor(color);
    }
}
 
Example 20
Project: IslamicLibraryAndroid   File: Highlight.java   View source code 5 votes vote down vote up
@ColorInt
public static int getHighlightColor(String className) {
    Matcher matcher = HIGHLIGHT_CLASS_PATTERN.matcher(className);
    int classNumber = 0;
    if (matcher.matches()) {
        classNumber = Integer.parseInt(matcher.group(1));
    }
    return highlightColorMap.get(classNumber);
}
 
Example 21
Project: GitHub   File: StatusBarUtil.java   View source code 5 votes vote down vote up
/**
 * 生成一个和状态栏大小相同的彩色矩形条
 *
 * @param activity 需要设置的 activity
 * @param color    状态栏颜色值
 * @return 状态栏矩形条
 */
private static StatusBarView createStatusBarView(Activity activity, @ColorInt int color) {
    // 绘制一个和状态栏一样高的矩形
    StatusBarView statusBarView = new StatusBarView(activity);
    LinearLayout.LayoutParams params =
            new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
    statusBarView.setLayoutParams(params);
    statusBarView.setBackgroundColor(color);
    return statusBarView;
}
 
Example 22
Project: DebugOverlay-Android   File: CpuUsageViewModule.java   View source code 5 votes vote down vote up
@Override
public View createView(ViewGroup root, @ColorInt int textColor, float textSize, float textAlpha) {
    View view = LayoutInflater.from(root.getContext()).inflate(layoutResId, root, false);
    cpuUsageTextView = view.findViewById(R.id.debugoverlay_overlay_text);
    cpuUsageTextView.setTextColor(textColor);
    cpuUsageTextView.setTextSize(textSize);
    cpuUsageTextView.setAlpha(textAlpha);
    return view;
}
 
Example 23
Project: emptyview   File: EmptyView.java   View source code 5 votes vote down vote up
private void setText(@Nullable CharSequence text, @ColorInt int color) {
    if (TextUtils.isEmpty(text)) {
        textView.setVisibility(GONE);
    } else {
        textView.setVisibility(VISIBLE);
        textView.setText(fromHtml(text.toString()));
        textView.setTextColor(color);
    }
}
 
Example 24
Project: Discover   File: CircleImageView.java   View source code 5 votes vote down vote up
public void setBorderColor(@ColorInt int borderColor) {
    if (borderColor == mBorderColor) {
        return;
    }

    mBorderColor = borderColor;
    mBorderPaint.setColor(mBorderColor);
    invalidate();
}
 
Example 25
Project: CXJPadProject   File: WheelPicker.java   View source code 5 votes vote down vote up
/**
 * 设置分隔阴影颜色及透明度
 */
public void setShadowColor(@ColorInt int color, @IntRange(from = 1, to = 255) int alpha) {
    if (null == dividerConfig) {
        dividerConfig = new WheelView.DividerConfig();
    }
    dividerConfig.setShadowColor(color);
    dividerConfig.setShadowAlpha(alpha);
}
 
Example 26
Project: MusicX-music-player   File: Config.java   View source code 5 votes vote down vote up
@CheckResult
@ColorInt
public static int navigationViewSelectedBg(@NonNull Context context, @Nullable String key, boolean darkTheme) {
    final int defaultColor = ContextCompat.getColor(context, darkTheme ?
            R.color.ate_navigation_drawer_selected_dark : R.color.ate_navigation_drawer_selected_light);
    return prefs(context, key).getInt(KEY_NAVIGATIONVIEW_SELECTED_BG, defaultColor);
}
 
Example 27
Project: CFAlertDialog   File: CFAlertDialog.java   View source code 5 votes vote down vote up
public CFAlertActionButton(Context context, String buttonText, @ColorInt int textColor, @ColorInt int backgroundColor, CFAlertActionStyle style, CFAlertActionAlignment alignment, OnClickListener onClickListener) {
    this.context = context;
    this.buttonText = buttonText;
    this.textColor = textColor;
    this.backgroundColor = backgroundColor;
    this.style = style;
    this.backgroundDrawableId = getBackgroundDrawable(style);
    this.alignment = alignment;
    this.onClickListener = onClickListener;

    // default textColor
    if (textColor == -1) {
        this.textColor = getTextColor(style);
    }
}
 
Example 28
Project: AnimatedArcProgressView   File: ArcLoadingView.java   View source code 5 votes vote down vote up
/**
 * Setup primary color for the arcs.
 * Basically initializes {@code mColorList} with provided color.
 *
 * @param color  A {@link ColorInt}.
 */
protected void setPrimaryColor(@ColorInt int color) {
    // clear color list and make it null, so it's ignored when drawing and primary color will be used instead
    setColorList(null);

    if (mPrimaryColor != color) {
        mPrimaryColor = color;
    }
}
 
Example 29
Project: fluentAppBar   File: MenuSecondaryItemsAdapter.java   View source code 5 votes vote down vote up
MenuSecondaryItemsAdapter(Context context, @MenuRes int secondaryMenuId, View.OnClickListener onClickListener,
                                 @ColorInt int foregroundColour) {
    this.context = context;
    this.onClickListener = onClickListener;
    this.foregroundColour = foregroundColour;
    this.itemss = new ArrayList<>();

    MenuParserHelper.parseMenu(context, secondaryMenuId, itemss);
}
 
Example 30
Project: Readhub-Android   File: ResUtils.java   View source code 5 votes vote down vote up
@ColorInt
public static int getThemeAttrColor(@NonNull Context context, @AttrRes int attr) {
    TypedArray a = context.obtainStyledAttributes(null, new int[]{attr});
    try {
        return a.getColor(0, 0);
    } finally {
        a.recycle();
    }
}
 
Example 31
Project: Recognize-it   File: AlbumUtils.java   View source code 5 votes vote down vote up
/**
 * Return a color-int from alpha, red, green, blue components.
 *
 * @param color color.
 * @param alpha alpha, alpha component [0..255] of the color.
 */
@ColorInt
public static int getAlphaColor(@ColorInt int color, @IntRange(from = 0, to = 255) int alpha) {
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    return Color.argb(alpha, red, green, blue);
}
 
Example 32
Project: FastLib   File: FastLoadMoreView.java   View source code 5 votes vote down vote up
/**
 * 设置所有TextView 文本颜色
 *
 * @param mLoadTextColor
 * @return
 */
public Builder setLoadTextColor(@ColorInt int mLoadTextColor) {
    setLoadingTextColor(mLoadTextColor);
    setLoadFailTextColor(mLoadTextColor);
    setLoadEndTextColor(mLoadTextColor);
    return this;
}
 
Example 33
Project: SystemUITuner2   File: SetupActivity.java   View source code 5 votes vote down vote up
public static NoRoot newInstance(String title, String description, @SuppressWarnings("SameParameterValue") @DrawableRes int drawable, @ColorInt int color) {
    NoRoot fragment = new NoRoot();
    Bundle args = new Bundle();
    args.putString(ARG_TITLE, title);
    args.putString(ARG_DESC, description);
    args.putInt(ARG_DRAWABLE, drawable);
    args.putInt(ARG_BG_COLOR, color);
    fragment.setArguments(args);
    return fragment;
}
 
Example 34
Project: GitHub   File: SpaceTabLayout.java   View source code 4 votes vote down vote up
public void setTabOneTextColor(@ColorInt int tabOneTextColor) {
    if (!iconOnly) tabOneTextView.setTextColor(tabOneTextColor);
    else throw new IllegalArgumentException("You selected icons only.");
}
 
Example 35
Project: CXJPadProject   File: ConfirmPopup.java   View source code 4 votes vote down vote up
/**
 * 设置顶部标题栏背景颜色
 */
public void setTopBackgroundColor(@ColorInt int topBackgroundColor) {
    this.topBackgroundColor = topBackgroundColor;
}
 
Example 36
Project: javaide   File: DrawableUtils.java   View source code 4 votes vote down vote up
public static Drawable tintDrawable(Drawable d, @ColorInt int color) {
    Drawable wd = DrawableCompat.wrap(d);
    DrawableCompat.setTint(wd, color);
    return wd;
}
 
Example 37
Project: ParticlesDrawable   File: ParticlesDrawable.java   View source code 4 votes vote down vote up
@Override
public void fillCircle(final float cx, final float cy, final float radius,
        @ColorInt final int color) {
    mCanvasParticlesView.fillCircle(cx, cy, radius, color);
}
 
Example 38
Project: GitHub   File: SpaceTabLayout.java   View source code 4 votes vote down vote up
public void setTabThreeTextColor(@ColorInt int tabThreeTextColor) {
    if (!iconOnly) tabThreeTextView.setTextColor(tabThreeTextColor);
    else throw new IllegalArgumentException("You selected icons only.");
}
 
Example 39
Project: android-paypal-example   File: BadgeStyle.java   View source code 4 votes vote down vote up
public BadgeStyle setColorPressed(@ColorInt int colorPressed) {
    this.colorPressed = colorPressed;
    return this;
}
 
Example 40
Project: proSwipeButton   File: ProSwipeButton.java   View source code 4 votes vote down vote up
@ColorInt
public int getTextColor() {
    return this.textColorInt;
}