androidx.annotation.ColorInt Java Examples

The following examples show how to use androidx.annotation.ColorInt. 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: SettingsActivity.java    From EdXposedManager with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onColorSelection(@NonNull ColorChooserDialog dialog, @ColorInt int color) {
    int colorFrom = XposedApp.getColor(this);

    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, color);
    colorAnimation.addUpdateListener(animator -> {
        int color1 = (int) animator.getAnimatedValue();

        toolbar.setBackgroundColor(color1);

        int darkenColor = XposedApp.darkenColor(color1, getDarkenFactor());

        getWindow().setStatusBarColor(darkenColor);

        if (navBar != null && navBar.isChecked()) {
            getWindow().setNavigationBarColor(darkenColor);
        }
    });
    colorAnimation.setDuration(750);
    colorAnimation.start();

    if (!dialog.isAccentMode()) {
        XposedApp.getPreferences().edit().putInt("colors", color).apply();
    }
}
 
Example #2
Source File: FastScroller.java    From a with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the color for the scroll handle.
 *
 * @param color The color for the scroll handle
 */
public void setHandleColor(@ColorInt int color) {
    mHandleColor = color;
    if (mHandleImage == null) {
        Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.fastscroll_handle);
        if (drawable != null) {
            mHandleImage = DrawableCompat.wrap(drawable);
        }
    }
    DrawableCompat.setTint(mHandleImage, mHandleColor);
    mHandleView.setImageDrawable(mHandleImage);
}
 
Example #3
Source File: ArcProgressBar.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static Paint createPaint(float width, @ColorInt int color) {
  Paint paint = new Paint();

  paint.setStrokeWidth(width);
  paint.setStyle(Paint.Style.STROKE);
  paint.setAntiAlias(true);
  paint.setColor(color);

  return paint;
}
 
Example #4
Source File: SelectorFactory.java    From monero-wallet-android-app with MIT License 5 votes vote down vote up
public ShapeSelector setDefaultStrokeColor(@ColorInt int color) {
    mDefaultStrokeColor = color;
    if (!hasSetDisabledStrokeColor)
        mDisabledStrokeColor = color;
    if (!hasSetPressedStrokeColor)
        mPressedStrokeColor = color;
    if (!hasSetSelectedStrokeColor)
        mSelectedStrokeColor = color;
    if (!hasSetFocusedStrokeColor)
        mFocusedStrokeColor = color;
    return this;
}
 
Example #5
Source File: TintHelper.java    From a with GNU General Public License v3.0 5 votes vote down vote up
public static void setTint(@NonNull Switch switchView, @ColorInt int color, boolean useDarker) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return;
    if (switchView.getTrackDrawable() != null) {
        switchView.setTrackDrawable(modifySwitchDrawable(switchView.getContext(),
                switchView.getTrackDrawable(), color, false, false, useDarker));
    }
    if (switchView.getThumbDrawable() != null) {
        switchView.setThumbDrawable(modifySwitchDrawable(switchView.getContext(),
                switchView.getThumbDrawable(), color, true, false, useDarker));
    }
}
 
Example #6
Source File: ConfirmPopup.java    From a with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置顶部标题栏标题文字颜色
 */
public void setTitleTextColor(@ColorInt int titleTextColor) {
    if (null != titleView && titleView instanceof TextView) {
        ((TextView) titleView).setTextColor(titleTextColor);
    } else {
        this.titleTextColor = titleTextColor;
    }
}
 
Example #7
Source File: SegmentedButton.java    From SegmentedButton with Apache License 2.0 5 votes vote down vote up
/**
 * Set ripple color used for ripple effect on button press
 *
 * @param color color to set for the ripple effect for this button
 */
public void setRipple(@ColorInt int color)
{
    rippleColor = color;

    if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP)
    {
        rippleDrawableLollipop = new RippleDrawable(ColorStateList.valueOf(rippleColor), null, null);
        // setCallback on Drawable allows animations to be scheduled and the drawable to invalidate the view on
        // animation
        rippleDrawableLollipop.setCallback(this);
        rippleDrawableLollipop.setBounds(0, 0, getWidth(), getHeight());

        // Disable/nullify the pre-lollipop RippleDrawable backport
        rippleDrawable = null;
    }
    else
    {
        rippleDrawable = new codetail.graphics.drawables.RippleDrawable(ColorStateList.valueOf(rippleColor), null,
            null);
        // setCallback on Drawable allows animations to be scheduled and the drawable to invalidate the view on
        // animation
        rippleDrawable.setCallback(this);
        rippleDrawable.setBounds(0, 0, getWidth(), getHeight());

        setOnTouchListener(new DrawableHotspotTouch(rippleDrawable));

        // Disable/nullify the lollipop RippleDrawable
        rippleDrawableLollipop = null;
    }

    invalidate();
}
 
Example #8
Source File: NavigationDrawer.java    From leafpicrevived with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the theme for this Navigation Drawer.
 *
 * @param primaryColor    Color for header background
 * @param backgroundColor Color for drawer background
 * @param textColor       Color for item text
 * @param iconColor       Color for icons
 */
public void setTheme(@ColorInt int primaryColor, @ColorInt int backgroundColor,
                     @ColorInt int textColor, @ColorInt int iconColor) {

    setBackgroundColor(backgroundColor);
    drawerHeader.setBackgroundColor(primaryColor);

    for (NavigationEntry navigationEntry : navigationEntries) {
        navigationEntry.setTextColor(textColor);
        navigationEntry.setIconColor(iconColor);
    }
}
 
Example #9
Source File: SegmentedButtonGroup.java    From SegmentedButton with Apache License 2.0 5 votes vote down vote up
/**
 * Set the background to be a solid color when a button is not selected for each button
 *
 * This will create a ColorDrawable or modify the current background if it is a ColorDrawable.
 *
 * Note: This is a convenience function that sets the background for each individual button.
 *
 * @param color color to set the background to
 */
public void setBackground(@ColorInt int color)
{
    if (backgroundDrawable instanceof ColorDrawable)
    {
        ((ColorDrawable)backgroundDrawable.mutate()).setColor(color);

        // Required to update background for the buttons
        setBackground(backgroundDrawable);
    }
    else
    {
        setBackground(new ColorDrawable(color));
    }
}
 
Example #10
Source File: Utils.java    From bottomsheets with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the {@link Drawable} for the corresponding drawable resource id
 * and applies the specified color to it.
 *
 * @param context the context
 * @param drawableId the drawable resource id
 * @param desiredColor the desired color to be applied to the retrieved drawable
 * @return the retrieved and colored drawable or null.
 */
@Nullable
public static Drawable getColoredDrawable(@NonNull Context context,
                                          @DrawableRes int drawableId,
                                          @ColorInt int desiredColor) {
    Preconditions.nonNull(context);

    final Drawable drawable = ContextCompat.getDrawable(context, drawableId);

    return ((drawable != null) ? getColoredDrawable(drawable, desiredColor) : null);
}
 
Example #11
Source File: NavigationViewUtil.java    From a with GNU General Public License v3.0 5 votes vote down vote up
public static void setItemIconColors(@NonNull NavigationView navigationView, @ColorInt int normalColor, @ColorInt int selectedColor) {
    final ColorStateList iconSl = new ColorStateList(
            new int[][]{
                    new int[]{-android.R.attr.state_checked},
                    new int[]{android.R.attr.state_checked}
            },
            new int[]{
                    normalColor,
                    selectedColor
            });
    navigationView.setItemIconTintList(iconSl);
}
 
Example #12
Source File: IOSDialog.java    From monero-wallet-android-app with MIT License 5 votes vote down vote up
/**
 * 设置底部文字的颜色--------------
 */

public IOSDialog bottomTextColor(@ColorInt int leftColor, @ColorInt int rightColor) {
    mLeftTextColor = leftColor;
    mRightTextColor = rightColor;
    if (mLeftView != null) {
        mLeftView.setTextColor(mLeftTextColor);
    }
    if (mRightView != null) {
        mRightView.setTextColor(mRightTextColor);
    }
    return this;
}
 
Example #13
Source File: ThemeStore.java    From a with GNU General Public License v3.0 5 votes vote down vote up
@CheckResult
@ColorInt
public static int navigationBarColor(@NonNull Context context) {
    if (!coloredNavigationBar(context)) {
        return Color.BLACK;
    }
    return prefs(context).getInt(KEY_NAVIGATION_BAR_COLOR, primaryColor(context));
}
 
Example #14
Source File: MaterialValueHelper.java    From a with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("PrivateResource")
@ColorInt
public static int getSecondaryDisabledTextColor(final Context context, boolean dark) {
    if (dark) {
        return ContextCompat.getColor(context, R.color.secondary_text_disabled_material_light);
    }
    return ContextCompat.getColor(context, R.color.secondary_text_disabled_material_dark);
}
 
Example #15
Source File: Selector.java    From a with GNU General Public License v3.0 5 votes vote down vote up
public ShapeSelector setDefaultBgColor(@ColorInt int color) {
    mDefaultBgColor = color;
    if (!hasSetDisabledBgColor)
        mDisabledBgColor = color;
    if (!hasSetPressedBgColor)
        mPressedBgColor = color;
    if (!hasSetSelectedBgColor)
        mSelectedBgColor = color;
    if (!hasSetFocusedBgColor)
        mFocusedBgColor = color;
    return this;
}
 
Example #16
Source File: ColorUtil.java    From a with GNU General Public License v3.0 5 votes vote down vote up
@ColorInt
public static int adjustAlpha(@ColorInt int color, @FloatRange(from = 0.0, to = 1.0) float factor) {
    int alpha = Math.round(Color.alpha(color) * factor);
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    return Color.argb(alpha, red, green, blue);
}
 
Example #17
Source File: TintHelper.java    From a with GNU General Public License v3.0 5 votes vote down vote up
private static Drawable modifySwitchDrawable(@NonNull Context context, @NonNull Drawable from, @ColorInt int tint, boolean thumb, boolean compatSwitch, boolean useDarker) {
    if (useDarker) {
        tint = ColorUtil.shiftColor(tint, 1.1f);
    }
    tint = ColorUtil.adjustAlpha(tint, (compatSwitch && !thumb) ? 0.5f : 1.0f);
    int disabled;
    int normal;
    if (thumb) {
        disabled = ContextCompat.getColor(context, useDarker ? R.color.ate_switch_thumb_disabled_dark : R.color.ate_switch_thumb_disabled_light);
        normal = ContextCompat.getColor(context, useDarker ? R.color.ate_switch_thumb_normal_dark : R.color.ate_switch_thumb_normal_light);
    } else {
        disabled = ContextCompat.getColor(context, useDarker ? R.color.ate_switch_track_disabled_dark : R.color.ate_switch_track_disabled_light);
        normal = ContextCompat.getColor(context, useDarker ? R.color.ate_switch_track_normal_dark : R.color.ate_switch_track_normal_light);
    }

    // Stock switch includes its own alpha
    if (!compatSwitch) {
        normal = ColorUtil.stripAlpha(normal);
    }

    final ColorStateList sl = new ColorStateList(
            new int[][]{
                    new int[]{-android.R.attr.state_enabled},
                    new int[]{android.R.attr.state_enabled, -android.R.attr.state_activated, -android.R.attr.state_checked},
                    new int[]{android.R.attr.state_enabled, android.R.attr.state_activated},
                    new int[]{android.R.attr.state_enabled, android.R.attr.state_checked}
            },
            new int[]{
                    disabled,
                    normal,
                    tint,
                    tint
            }
    );
    return createTintedDrawable(from, sl);
}
 
Example #18
Source File: FastScroller.java    From a with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the color of the scroll track.
 *
 * @param color The color for the scroll track
 */
public void setTrackColor(@ColorInt int color) {
    @ColorInt int trackColor = color;
    if (mTrackImage == null) {
        Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.fastscroll_track);
        if (drawable != null) {
            mTrackImage = DrawableCompat.wrap(drawable);
        }
    }
    DrawableCompat.setTint(mTrackImage, trackColor);
    mTrackView.setImageDrawable(mTrackImage);
}
 
Example #19
Source File: Utils.java    From android-browser-helper with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether to use dark icons on a background with given color by comparing the
 * contrast ratio (https://www.w3.org/TR/WCAG20/#contrast-ratiodef) to a threshold.
 * This criterion matches the one used by Chrome:
 * https://chromium.googlesource.com/chromium/src/+/90ac05ba6cb9ab5d5df75f0cef62c950be3716c3/chrome/android/java/src/org/chromium/chrome/browser/util/ColorUtils.java#215
 */
private static boolean shouldUseDarkIconsOnBackground(@ColorInt int backgroundColor) {
    float luminance = 0.2126f * luminanceOfColorComponent(Color.red(backgroundColor))
            + 0.7152f * luminanceOfColorComponent(Color.green(backgroundColor))
            + 0.0722f * luminanceOfColorComponent(Color.blue(backgroundColor));
    float contrast = Math.abs((1.05f) / (luminance + 0.05f));
    return contrast < 3;
}
 
Example #20
Source File: ColorUtil.java    From a with GNU General Public License v3.0 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;
    int alpha = Color.alpha(color);
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= by; // value component
    return (alpha << 24) + (0x00ffffff & Color.HSVToColor(hsv));
}
 
Example #21
Source File: SegmentedButtonGroup.java    From SegmentedButton with Apache License 2.0 5 votes vote down vote up
/**
 * Set the border for the perimeter of the button group.
 *
 * @param width     Width of the border in pixels (default value is 0px or no border)
 * @param color     Color of the border (default color is black)
 * @param dashWidth Width of the dash for border, in pixels. Value of 0px means solid line (default is 0px)
 * @param dashGap   Width of the gap for border, in pixels.
 */
public void setBorder(int width, @ColorInt int color, int dashWidth, int dashGap)
{
    borderWidth = width;
    borderColor = color;
    borderDashWidth = dashWidth;
    borderDashGap = dashGap;

    // Border width of 0 indicates to hide borders
    if (width > 0)
    {
        GradientDrawable borderDrawable = new GradientDrawable();
        // Set background color to be transparent so that buttons and everything underneath the border view is
        // still visible. This was an issue on API 16 Android where it would default to a black background
        borderDrawable.setColor(Color.TRANSPARENT);
        // Corner radius is the radius minus half of the border width because the drawable will draw the stroke
        // from the center, so the actual corner radius is reduced
        // If the half border width is left out, the border radius does not follow the curve of the background
        borderDrawable.setCornerRadius(radius - width / 2.0f);
        borderDrawable.setStroke(width, color, dashWidth, dashGap);

        borderView.setBackground(borderDrawable);
    }
    else
    {
        borderView.setBackground(null);
    }
}
 
Example #22
Source File: ThemeStore.java    From a with GNU General Public License v3.0 4 votes vote down vote up
@CheckResult
@ColorInt
public static int textColorPrimary(@NonNull Context context) {
    return prefs(context).getInt(KEY_TEXT_COLOR_PRIMARY, ATHUtil.resolveColor(context, android.R.attr.textColorPrimary));
}
 
Example #23
Source File: StateButton.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
public void setStateStrokeColor(@ColorInt int normal, @ColorInt int pressed, @ColorInt int unable) {
    mNormalStrokeColor = normal;
    mPressedStrokeColor = pressed;
    mUnableStrokeColor = unable;
    setStroke();
}
 
Example #24
Source File: Option.java    From bottomsheets with Apache License 2.0 4 votes vote down vote up
@NonNull
public final Option setIconColor(@ColorInt int iconColor) {
    this.iconColor = iconColor;
    return this;
}
 
Example #25
Source File: DiscreteSlider.java    From DiscreteSlider with MIT License 4 votes vote down vote up
public void setTickMarkInactiveColor(@ColorInt int tickMarkInactiveColor) {
	mTickMarkInactiveColor = tickMarkInactiveColor;
	invalidate();
}
 
Example #26
Source File: ColorableRenderer.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@ColorInt
int getColor();
 
Example #27
Source File: SelectorFactory.java    From monero-wallet-android-app with MIT License 4 votes vote down vote up
public ShapeSelector setFocusedBgColor(@ColorInt int color) {
    mFocusedBgColor = color;
    hasSetPressedBgColor = true;
    return this;
}
 
Example #28
Source File: Selector.java    From a with GNU General Public License v3.0 4 votes vote down vote up
public ShapeSelector setSelectedStrokeColor(@ColorInt int color) {
    mSelectedStrokeColor = color;
    hasSetSelectedStrokeColor = true;
    return this;
}
 
Example #29
Source File: DiscreteSlider.java    From DiscreteSlider with MIT License 4 votes vote down vote up
@ColorInt
public int getTrackColor() {
	return mInactiveTrackColor;
}
 
Example #30
Source File: ConfirmPopup.java    From a with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 设置顶部标题栏下划线颜色
 */
public void setTopLineColor(@ColorInt int topLineColor) {
    this.topLineColor = topLineColor;
}