类androidx.annotation.ColorInt源码实例Demo

下面列出了怎么用androidx.annotation.ColorInt的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: EdXposedManager   文件: SettingsActivity.java
@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();
    }
}
 
源代码2 项目: a   文件: ColorUtil.java
@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));
}
 
源代码3 项目: mollyim-android   文件: ArcProgressBar.java
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;
}
 
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;
}
 
源代码5 项目: a   文件: TintHelper.java
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));
    }
}
 
源代码6 项目: a   文件: ConfirmPopup.java
/**
 * 设置顶部标题栏标题文字颜色
 */
public void setTitleTextColor(@ColorInt int titleTextColor) {
    if (null != titleView && titleView instanceof TextView) {
        ((TextView) titleView).setTextColor(titleTextColor);
    } else {
        this.titleTextColor = titleTextColor;
    }
}
 
源代码7 项目: SegmentedButton   文件: SegmentedButton.java
/**
 * 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();
}
 
源代码8 项目: leafpicrevived   文件: NavigationDrawer.java
/**
 * 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);
    }
}
 
源代码9 项目: SegmentedButton   文件: SegmentedButtonGroup.java
/**
 * 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));
    }
}
 
源代码10 项目: bottomsheets   文件: Utils.java
/**
 * 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);
}
 
源代码11 项目: a   文件: NavigationViewUtil.java
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);
}
 
源代码12 项目: SegmentedButton   文件: SegmentedButtonGroup.java
/**
 * 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);
    }
}
 
源代码13 项目: monero-wallet-android-app   文件: IOSDialog.java
/**
 * 设置底部文字的颜色--------------
 */

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;
}
 
源代码14 项目: a   文件: ThemeStore.java
@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));
}
 
源代码15 项目: a   文件: MaterialValueHelper.java
@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);
}
 
源代码16 项目: a   文件: Selector.java
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;
}
 
源代码17 项目: a   文件: ColorUtil.java
@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);
}
 
源代码18 项目: a   文件: TintHelper.java
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);
}
 
源代码19 项目: a   文件: FastScroller.java
/**
 * 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);
}
 
源代码20 项目: android-browser-helper   文件: Utils.java
/**
 * 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;
}
 
源代码21 项目: a   文件: FastScroller.java
/**
 * 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);
}
 
源代码22 项目: a   文件: ThemeStore.java
@CheckResult
@ColorInt
public static int textColorPrimary(@NonNull Context context) {
    return prefs(context).getInt(KEY_TEXT_COLOR_PRIMARY, ATHUtil.resolveColor(context, android.R.attr.textColorPrimary));
}
 
源代码23 项目: OneText_For_Android   文件: NiceImageView.java
public void setMaskColor(@ColorInt int maskColor) {
    this.maskColor = maskColor;
    invalidate();
}
 
源代码24 项目: mollyim-android   文件: AttachmentManager.java
public static void selectGif(Activity activity, int requestCode, boolean isForMms, @ColorInt int color) {
  Intent intent = new Intent(activity, GiphyActivity.class);
  intent.putExtra(GiphyActivity.EXTRA_IS_MMS, isForMms);
  intent.putExtra(GiphyActivity.EXTRA_COLOR, color);
  activity.startActivityForResult(intent, requestCode);
}
 
public ShapeSelector setFocusedBgColor(@ColorInt int color) {
    mFocusedBgColor = color;
    hasSetPressedBgColor = true;
    return this;
}
 
源代码26 项目: mollyim-android   文件: ColorableRenderer.java
@ColorInt
int getColor();
 
源代码27 项目: bcm-android   文件: StateButton.java
public void setPressedBackgroundColor(@ColorInt int pressedBackgroundColor) {
    this.mPressedBackgroundColor = pressedBackgroundColor;
    mPressedBackground.setColor(mPressedBackgroundColor);
}
 
源代码28 项目: a   文件: ThemeStore.java
@CheckResult
@ColorInt
public static int accentColor(@NonNull Context context) {
    return prefs(context).getInt(KEY_ACCENT_COLOR, ATHUtil.resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238")));
}
 
源代码29 项目: bcm-android   文件: StateButton.java
public void setUnableTextColor(@ColorInt int unableTextColor) {
    this.mUnableTextColor = unableTextColor;
    setTextColor();
}
 
源代码30 项目: a   文件: ThemeStore.java
@CheckResult
@ColorInt
public static int backgroundColor(@NonNull Context context) {
    return prefs(context).getInt(KEY_BACKGROUND_COLOR, ATHUtil.resolveColor(context, android.R.attr.colorBackground));
}