androidx.core.graphics.ColorUtils Java Examples

The following examples show how to use androidx.core.graphics.ColorUtils. 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: HomeActivityDelegate.java    From Taskbar with Apache License 2.0 6 votes vote down vote up
private void enterIconArrangeMode() {
    try {
        SharedPreferences pref = U.getSharedPreferences(this);
        JSONArray jsonIcons = new JSONArray(pref.getString(PREF_DESKTOP_ICONS, "[]"));

        if(jsonIcons.length() == 0) {
            U.showToast(this, R.string.tb_no_icons_to_arrange);
            return;
        }

        fab.view.setBackgroundTintList(
                ColorStateList.valueOf(ColorUtils.setAlphaComponent(U.getAccentColor(this), 255)));

        iconArrangeMode = true;
        fab.show();
    } catch (JSONException e) { /* Gracefully fail */ }
}
 
Example #2
Source File: ThemedEditText.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
public static void setBackgroundActiveColor(View editText, LiveThemeComponent component) {
    LiveThemeManager lmgr = component.getLiveThemeManager();
    if (editText.getBackground() == null || lmgr == null)
        return;
    int accentColor = lmgr.getColor(/* R.attr.colorControlActivated */ R.attr.colorAccent);
    int normalColor = lmgr.getColor(/* R.attr.colorControlNormal */ android.R.attr.textColorSecondary);
    int disabledColor = ColorUtils.setAlphaComponent(normalColor, (int) (255.f *
            StyledAttributesHelper.getFloat(editText.getContext(), android.R.attr.disabledAlpha, 1.f)));
    int[][] states = new int[][]{
            new int[]{-android.R.attr.state_enabled},
            new int[]{-android.R.attr.state_pressed, -android.R.attr.state_focused},
            new int[]{}
    };
    int[] colors = new int[]{
            disabledColor,
            normalColor,
            accentColor
    };
    ColorStateList list = new ColorStateList(states, colors);
    editText.setBackground(new ColorFilterWorkaroundDrawable(editText.getBackground()));
    ViewCompat.setBackgroundTintList(editText, list);
}
 
Example #3
Source File: InterfaceSettingsFragment.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void bind(CheckBoxSetting entry) {
    super.bind(entry);
    int[] overrideColors = ((ThemeOptionSetting) entry).overrideColors;
    int bgColor = StyledAttributesHelper.getColor(mCheckBox.getContext(),
            android.R.attr.colorBackground, 0);
    boolean darkBg = ColorUtils.calculateLuminance(bgColor) < 0.4;
    int overrideColor = overrideColors[0];
    for (int c : overrideColors) {
        if ((!darkBg && ColorUtils.calculateLuminance(c) < 0.75)
                || (darkBg && ColorUtils.calculateLuminance(c) > 0.25)) {
            overrideColor = c;
            break;
        }
    }
    if (overrideColor != 0)
        CompoundButtonCompat.setButtonTintList(mCheckBox,
                ColorStateList.valueOf(overrideColor));
    else
        CompoundButtonCompat.setButtonTintList(mCheckBox, mDefaultButtonTintList);
}
 
Example #4
Source File: DrawerMenuListAdapter.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
public DrawerMenuListAdapter(Context context, LockableDrawerLayout drawerLayout,
                             boolean alwaysShowServer) {
    mContext = context;
    mDrawerLayout = drawerLayout;
    mAlwaysShowServer = alwaysShowServer;
    notifyServerListChanged();

    StyledAttributesHelper ta = StyledAttributesHelper.obtainStyledAttributes(context,
            new int[] { R.attr.colorAccent, R.attr.selectableItemBackground, R.attr.colorControlHighlight, android.R.attr.textColorPrimary });
    mChannelBackground = ta.getDrawable(R.attr.selectableItemBackground);
    int color = ta.getColor(R.attr.colorControlHighlight, 0);
    color = ColorUtils.setAlphaComponent(color, Color.alpha(color) / 2);
    mChannelSelectedBackground = new ColorDrawable(color);
    mSelectedForegroundColor = ta.getColor(R.attr.colorAccent, 0);
    mDefaultForegroundColor = ta.getColor(android.R.attr.textColorPrimary, 0);
    ta.recycle();
}
 
Example #5
Source File: SkyTubeApp.java    From SkyTube with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(26)
private void initChannels(Context context) {

	if(BuildCompat.isAtLeastR()) {
		return;
	}
	NotificationManager notificationManager =
			(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

	String channelId = NEW_VIDEOS_NOTIFICATION_CHANNEL;
	CharSequence channelName = context.getString(R.string.notification_channel_feed_title);
	int importance = NotificationManager.IMPORTANCE_LOW;
	NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance);
	notificationChannel.enableLights(true);
	notificationChannel.setLightColor(ColorUtils.compositeColors(0xFFFF0000, 0xFFFF0000));
	notificationChannel.enableVibration(false);
	notificationManager.createNotificationChannel(notificationChannel);
}
 
Example #6
Source File: CropOverlayView.java    From cloudinary_android with MIT License 6 votes vote down vote up
private void init() {
    gestureDetector = new CropOverlayGestureDetector(overlay, this);

    dottedPaint.setColor(Color.WHITE);
    dottedPaint.setStyle(Paint.Style.STROKE);
    dottedPaint.setStrokeWidth(5);
    dottedPaint.setPathEffect(new DashPathEffect(new float[]{5, 10}, 0));

    guidelinesPaint.setColor(Color.WHITE);
    guidelinesPaint.setStyle(Paint.Style.STROKE);

    handlePaint.setColor(Color.WHITE);
    handlePaint.setStyle(Paint.Style.FILL);

    dimBackgroundPaint.setColor(ColorUtils.setAlphaComponent(Color.BLACK, 125));
    dimBackgroundPaint.setStyle(Paint.Style.FILL);

    setVisibility(INVISIBLE);
}
 
Example #7
Source File: FlyoutMenuView.java    From FlyoutMenus with MIT License 6 votes vote down vote up
Bitmap createMenuShadowBitmap() {
	menuShadowRadius = (int) flyoutMenuView.menuElevation * 2;
	menuShadowInset = menuShadowRadius / 2;
	int size = 2 * menuShadowRadius + 1;
	Bitmap shadowBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
	shadowBitmap.eraseColor(0x0); // clear

	Paint paint = new Paint();
	paint.setAntiAlias(true);
	paint.setShader(new RadialGradient(
			menuShadowRadius + 1,
			menuShadowRadius + 1,
			menuShadowRadius,
			ColorUtils.setAlphaComponent(SHADOW_COLOR, SHADOW_ALPHA),
			ColorUtils.setAlphaComponent(SHADOW_COLOR, 0),
			Shader.TileMode.CLAMP));

	Canvas canvas = new Canvas(shadowBitmap);
	canvas.drawRect(0, 0, size, size, paint);

	return shadowBitmap;
}
 
Example #8
Source File: StroageUsageView.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void invalidate() {
    super.invalidate();
    progressView.invalidate();

    if (lastProgressColor != Theme.getColor(Theme.key_player_progress)){
        lastProgressColor = Theme.getColor(Theme.key_player_progress);

        telegramCacheTextView.setCompoundDrawablesWithIntrinsicBounds(Theme.createCircleDrawable(AndroidUtilities.dp(10), lastProgressColor), null, null, null);
        telegramCacheTextView.setCompoundDrawablePadding(AndroidUtilities.dp(6));

        telegramDatabaseTextView.setCompoundDrawablesWithIntrinsicBounds(Theme.createCircleDrawable(AndroidUtilities.dp(10), lastProgressColor), null, null, null);
        telegramDatabaseTextView.setCompoundDrawablePadding(AndroidUtilities.dp(6));

        freeSizeTextView.setCompoundDrawablesWithIntrinsicBounds(Theme.createCircleDrawable(AndroidUtilities.dp(10), ColorUtils.setAlphaComponent(lastProgressColor,64)), null, null, null);
        freeSizeTextView.setCompoundDrawablePadding(AndroidUtilities.dp(6));

        totlaSizeTextView.setCompoundDrawablesWithIntrinsicBounds(Theme.createCircleDrawable(AndroidUtilities.dp(10), ColorUtils.setAlphaComponent(lastProgressColor,127)), null, null, null);
        totlaSizeTextView.setCompoundDrawablePadding(AndroidUtilities.dp(6));
    }

    textSettingsCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    divider.setBackgroundColor(Theme.getColor(Theme.key_divider));
}
 
Example #9
Source File: TaskbarController.java    From Taskbar with Apache License 2.0 6 votes vote down vote up
@SuppressLint("SetTextI18n")
@Override
public void onReceive(Context context, Intent intent) {
    int count = intent.getIntExtra("count", 0);
    if(count > 0) {
        int color = ColorUtils.setAlphaComponent(U.getBackgroundTint(context), 255);
        notificationCountText.setTextColor(color);

        Drawable drawable = ContextCompat.getDrawable(context, R.drawable.tb_circle);
        drawable.setTint(U.getAccentColor(context));

        notificationCountCircle.setImageDrawable(drawable);
        notificationCountText.setText(Integer.toString(count));
    } else {
        notificationCountCircle.setImageDrawable(null);
        notificationCountText.setText(null);
    }
}
 
Example #10
Source File: ViewButtonColor.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
void setColor(Integer color) {
    if (color == null)
        color = Color.TRANSPARENT;
    this.color = color;

    GradientDrawable background = new GradientDrawable();
    background.setColor(color);
    background.setStroke(
            Helper.dp2pixels(getContext(), 1),
            Helper.resolveColor(getContext(), R.attr.colorSeparator));
    setBackground(background);

    if (color == Color.TRANSPARENT)
        setTextColor(Helper.resolveColor(getContext(), android.R.attr.textColorPrimary));
    else {
        double lum = ColorUtils.calculateLuminance(color);
        setTextColor(lum < 0.5 ? Color.WHITE : Color.BLACK);
    }
}
 
Example #11
Source File: NotificationPreferenceView.java    From zephyr with MIT License 6 votes vote down vote up
private void setColors(@ColorInt int color) {
    ZephyrExecutors.getMainThreadExecutor().execute(() -> {
        topView.setBackground(createBackground(color, false));
        bottomView.setBackground(createBackground(ColorUtils.blendARGB(color, Color.BLACK, 0.2f), true));

        ColorStateList buttonStates = new ColorStateList(
                new int[][]{
                        new int[]{-android.R.attr.state_enabled},
                        new int[]{android.R.attr.state_checked},
                        new int[]{}
                },
                new int[]{
                        Color.GRAY,
                        ColorUtils.blendARGB(color, Color.BLACK, 0.4f),
                        ColorUtils.blendARGB(color, Color.BLACK, 0.2f)
                }
        );
        prefSwitch.getThumbDrawable().setTintList(buttonStates);
        prefSwitch.getTrackDrawable().setTintList(buttonStates);
    });
}
 
Example #12
Source File: ImageHelper.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
static Bitmap generateLetterIcon(String letter, float h, int size, Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    float s = prefs.getInt("saturation", 100) / 100f;
    float v = prefs.getInt("brightness", 100) / 100f;
    float t = prefs.getInt("threshold", 50) / 100f;

    int bg = Color.HSVToColor(new float[]{h, s, v});
    double lum = ColorUtils.calculateLuminance(bg);

    Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawColor(bg);

    Paint paint = new Paint();
    paint.setColor(lum < t ? Color.WHITE : Color.BLACK);
    paint.setTextSize(size / 2f);
    paint.setTypeface(Typeface.DEFAULT_BOLD);

    canvas.drawText(letter,
            size / 2f - paint.measureText(letter) / 2,
            size / 2f - (paint.descent() + paint.ascent()) / 2, paint);

    return bitmap;
}
 
Example #13
Source File: FilterTabsView.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setValue(FilterTabsView object, float value) {
    animationValue = value;

    int color1 = Theme.getColor(tabLineColorKey);
    int color2 = Theme.getColor(aTabLineColorKey);
    selectorDrawable.setColor(ColorUtils.blendARGB(color1, color2, value));

    if (aBackgroundColorKey != null) {
        color1 = Theme.getColor(backgroundColorKey);
        color2 = Theme.getColor(aBackgroundColorKey);
        object.setBackgroundColor(ColorUtils.blendARGB(color1, color2, value));
    }

    listView.invalidateViews();
    listView.invalidate();
    object.invalidate();
}
 
Example #14
Source File: StroageUsageView.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void invalidate() {
    super.invalidate();
    progressView.invalidate();

    if (lastProgressColor != Theme.getColor(Theme.key_player_progress)){
        lastProgressColor = Theme.getColor(Theme.key_player_progress);

        telegramCacheTextView.setCompoundDrawablesWithIntrinsicBounds(Theme.createCircleDrawable(AndroidUtilities.dp(10), lastProgressColor), null, null, null);
        telegramCacheTextView.setCompoundDrawablePadding(AndroidUtilities.dp(6));

        telegramDatabaseTextView.setCompoundDrawablesWithIntrinsicBounds(Theme.createCircleDrawable(AndroidUtilities.dp(10), lastProgressColor), null, null, null);
        telegramDatabaseTextView.setCompoundDrawablePadding(AndroidUtilities.dp(6));

        freeSizeTextView.setCompoundDrawablesWithIntrinsicBounds(Theme.createCircleDrawable(AndroidUtilities.dp(10), ColorUtils.setAlphaComponent(lastProgressColor,64)), null, null, null);
        freeSizeTextView.setCompoundDrawablePadding(AndroidUtilities.dp(6));

        totlaSizeTextView.setCompoundDrawablesWithIntrinsicBounds(Theme.createCircleDrawable(AndroidUtilities.dp(10), ColorUtils.setAlphaComponent(lastProgressColor,127)), null, null, null);
        totlaSizeTextView.setCompoundDrawablePadding(AndroidUtilities.dp(6));
    }

    textSettingsCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    divider.setBackgroundColor(Theme.getColor(Theme.key_divider));
}
 
Example #15
Source File: AirQualityHolder.java    From GeometricWeather with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressLint("SetTextI18n")
@Override
public void onBindView(DailyWeatherAdapter.ViewModel model, int position) {
    AirQuality airQuality = ((DailyAirQuality) model).getAirQuality();

    int aqi = airQuality.getAqiIndex();
    int color = airQuality.getAqiColor(itemView.getContext());

    progress.setMax(400);
    progress.setProgress(aqi);
    progress.setProgressColor(color);
    progress.setProgressBackgroundColor(
            ColorUtils.setAlphaComponent(color, (int) (255 * 0.1))
    );

    content.setText(aqi + " / " + airQuality.getAqiText());
}
 
Example #16
Source File: ImmersionBar.java    From a with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 初始化android 5.0以上状态栏和导航栏
 *
 * @param uiFlags the ui flags
 * @return the int
 */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private int initBarAboveLOLLIPOP(int uiFlags) {
    uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;  //Activity全屏显示,但状态栏不会被隐藏覆盖,状态栏依然可见,Activity顶端布局部分会被状态栏遮住。
    if (mBarParams.fullScreen && mBarParams.navigationBarEnable) {
        uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; //Activity全屏显示,但导航栏不会被隐藏覆盖,导航栏依然可见,Activity底部布局部分会被导航栏遮住。
    }
    mWindow.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    if (mConfig.hasNavigtionBar()) {  //判断是否存在导航栏
        mWindow.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }
    mWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);  //需要设置这个才能设置状态栏颜色
    if (mBarParams.statusBarFlag)
        mWindow.setStatusBarColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
                mBarParams.statusBarColorTransform, mBarParams.statusBarAlpha));  //设置状态栏颜色
    else
        mWindow.setStatusBarColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
                Color.TRANSPARENT, mBarParams.statusBarAlpha));  //设置状态栏颜色
    if (mBarParams.navigationBarEnable) {
        mWindow.setNavigationBarColor(ColorUtils.blendARGB(mBarParams.navigationBarColor,
                mBarParams.navigationBarColorTransform, mBarParams.navigationBarAlpha));  //设置导航栏颜色
        if (Build.VERSION.SDK_INT >= 28 && !mBarParams.navigationBarDivider)
                mWindow.setNavigationBarDividerColor(Color.TRANSPARENT);
    }
    return uiFlags;
}
 
Example #17
Source File: CloudImplementor.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void draw(@Size(2) int[] canvasSizes, Canvas canvas,
                 float displayRate, float scrollRate, float rotation2D, float rotation3D) {
    if (displayRate >=1) {
        canvas.drawColor(backgroundColor);
    } else {
        canvas.drawColor(
                ColorUtils.setAlphaComponent(
                        backgroundColor,
                        (int) (displayRate * 255)));
    }

    if (scrollRate < 1) {
        if (thunder != null) {
            canvas.drawColor(
                    Color.argb(
                            (int) (displayRate * (1 - scrollRate) * thunder.alpha * 255),
                            thunder.r,
                            thunder.g,
                            thunder.b));
        }
        for (Star s : stars) {
            paint.setColor(s.color);
            paint.setAlpha((int) (displayRate * (1 - scrollRate) * s.alpha * 255));
            canvas.drawCircle(s.centerX, s.centerY, s.radius, paint);
        }
        for (Cloud c : clouds) {
            paint.setColor(c.color);
            paint.setAlpha((int) (displayRate * (1 - scrollRate) * c.alpha * 255));
            canvas.drawCircle(c.centerX, c.centerY, c.radius, paint);
        }
    }
}
 
Example #18
Source File: TodayWidgetConfigureActivity.java    From ETSMobile-Android2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    int bgColor = Integer.parseInt(mBgColorSpinner.getSelectedItem().toString());
    bgColor = ColorUtils.setAlphaComponent(bgColor, progress);

    mWidgetPreviewLayout.setBackgroundColor(bgColor);
}
 
Example #19
Source File: MaterialColors.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates a color that represents the layering of the {@code overlayColor} (with {@code
 * overlayAlpha} applied) on top of the {@code backgroundColor}.
 */
@ColorInt
public static int layer(
    @ColorInt int backgroundColor,
    @ColorInt int overlayColor,
    @FloatRange(from = 0.0, to = 1.0) float overlayAlpha) {
  int computedAlpha = Math.round(Color.alpha(overlayColor) * overlayAlpha);
  int computedOverlayColor = ColorUtils.setAlphaComponent(overlayColor, computedAlpha);
  return layer(backgroundColor, computedOverlayColor);
}
 
Example #20
Source File: ChatAttachAlert.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Keep
public void setCheckedState(float state) {
    checkedState = state;
    imageView.setScaleX(1.0f - 0.06f * state);
    imageView.setScaleY(1.0f - 0.06f * state);
    textView.setTextColor(ColorUtils.blendARGB(Theme.getColor(Theme.key_dialogTextGray2), Theme.getColor(textKey), checkedState));
    invalidate();
}
 
Example #21
Source File: HailImplementor.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void draw(@Size(2) int[] canvasSizes, Canvas canvas,
                 float displayRate, float scrollRate, float rotation2D, float rotation3D) {

    if (displayRate >= 1) {
        canvas.drawColor(backgroundColor);
    } else {
        canvas.drawColor(
                ColorUtils.setAlphaComponent(
                        backgroundColor,
                        (int) (displayRate * 255)));
    }

    if (scrollRate < 1) {
        canvas.rotate(
                rotation2D,
                canvasSizes[0] * 0.5F,
                canvasSizes[1] * 0.5F);

        for (Hail h : hails) {
            path.reset();
            path.moveTo(h.centerX - h.size, h.centerY);
            path.lineTo(h.centerX, h.centerY - h.size);
            path.lineTo(h.centerX + h.size, h.centerY);
            path.lineTo(h.centerX, h.centerY + h.size);
            path.close();
            paint.setColor(h.color);
            if (displayRate < lastDisplayRate) {
                paint.setAlpha((int) (displayRate * (1 - scrollRate) * 255));
            } else {
                paint.setAlpha(255);
            }
            canvas.drawPath(path, paint);
        }
    }

    lastDisplayRate = displayRate;
}
 
Example #22
Source File: PullForegroundDrawable.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void setOutProgress(float value) {
    outProgress = value;
    int color = ColorUtils.blendARGB(Theme.getNonAnimatedColor(avatarBackgroundColorKey), Theme.getNonAnimatedColor(backgroundActiveColorKey), 1f - outProgress);
    paintBackgroundAccent.setColor(color);
    if (changeAvatarColor && isDraw()) {
        Theme.dialogs_archiveAvatarDrawable.beginApplyLayerColors();
        Theme.dialogs_archiveAvatarDrawable.setLayerColor("Arrow1.**", color);
        Theme.dialogs_archiveAvatarDrawable.setLayerColor("Arrow2.**", color);
        Theme.dialogs_archiveAvatarDrawable.commitApplyLayerColors();
    }
}
 
Example #23
Source File: PullForegroundDrawable.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void updateColors() {
    int primaryColor = Color.WHITE;
    int backgroundColor = Theme.getColor(backgroundColorKey);

    tooltipTextPaint.setColor(primaryColor);
    paintWhite.setColor(primaryColor);
    paintSecondary.setColor(ColorUtils.setAlphaComponent(primaryColor, 100));
    backgroundPaint.setColor(backgroundColor);
    arrowDrawable.setColor(backgroundColor);
    paintBackgroundAccent.setColor(Theme.getColor(avatarBackgroundColorKey));
}
 
Example #24
Source File: PullForegroundDrawable.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void updateColors() {
    int primaryColor = Color.WHITE;
    int backgroundColor = Theme.getColor(backgroundColorKey);

    tooltipTextPaint.setColor(primaryColor);
    paintWhite.setColor(primaryColor);
    paintSecondary.setColor(ColorUtils.setAlphaComponent(primaryColor, 100));
    backgroundPaint.setColor(backgroundColor);
    arrowDrawable.setColor(backgroundColor);
    paintBackgroundAccent.setColor(Theme.getColor(avatarBackgroundColorKey));
}
 
Example #25
Source File: SnowImplementor.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void draw(@Size(2) int[] canvasSizes, Canvas canvas,
                 float displayRate, float scrollRate, float rotation2D, float rotation3D) {

    if (displayRate >= 1) {
        canvas.drawColor(backgroundColor);
    } else {
        canvas.drawColor(
                ColorUtils.setAlphaComponent(
                        backgroundColor,
                        (int) (displayRate * 255)));
    }

    if (scrollRate < 1) {
        canvas.rotate(
                rotation2D,
                canvasSizes[0] * 0.5F,
                canvasSizes[1] * 0.5F);
        for (Snow s : snows) {
            paint.setColor(s.color);
            if (displayRate < lastDisplayRate) {
                paint.setAlpha((int) (displayRate * (1 - scrollRate) * 255));
            } else {
                paint.setAlpha((int) ((1 - scrollRate) * 255));
            }
            canvas.drawCircle(s.centerX, s.centerY, s.radius, paint);
        }
    }

    lastDisplayRate = displayRate;
}
 
Example #26
Source File: DisplayUtils.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@ColorInt
@RequiresApi(Build.VERSION_CODES.M)
private static int getStatusBarColor23(Context context, boolean light, boolean miniAlpha) {
    if (miniAlpha) {
        return light
                ? ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.2 * 255))
                : ColorUtils.setAlphaComponent(Color.BLACK, (int) (0.1 * 255));
    }
    return ColorUtils.setAlphaComponent(
            ContextCompat.getColor(context, light ? R.color.colorRoot_light : R.color.colorRoot_dark),
            (int) (0.8 * 255)
    );
}
 
Example #27
Source File: TrendingStickersAlert.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);

    final float fraction = getFraction();

    canvas.save();
    canvas.translate(0, layout.getTranslationY() + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0) - topOffset);

    // top icon
    final int w = AndroidUtilities.dp(36);
    final int h = AndroidUtilities.dp(4);
    final int offset = (int) (h * 2f * (1f - fraction));
    shapeDrawable.setCornerRadius(AndroidUtilities.dp(2));
    final int sheetScrollUpColor = Theme.getColor(Theme.key_sheet_scrollUp);
    shapeDrawable.setColor(ColorUtils.setAlphaComponent(sheetScrollUpColor, (int) (Color.alpha(sheetScrollUpColor) * fraction)));
    shapeDrawable.setBounds((getWidth() - w) / 2, scrollOffsetY + AndroidUtilities.dp(10) + offset, (getWidth() + w) / 2, scrollOffsetY + AndroidUtilities.dp(10) + offset + h);
    shapeDrawable.draw(canvas);

    canvas.restore();

    // status bar
    setStatusBarVisible(fraction == 0f && Build.VERSION.SDK_INT >= 21 && !isDismissed(), !gluedToTop);
    if (statusBarAlpha > 0f) {
        final int color = Theme.getColor(Theme.key_dialogBackground);
        paint.setColor(Color.argb((int) (0xff * statusBarAlpha), (int) (Color.red(color) * 0.8f), (int) (Color.green(color) * 0.8f), (int) (Color.blue(color) * 0.8f)));
        canvas.drawRect(backgroundPaddingLeft, 0, getMeasuredWidth() - backgroundPaddingLeft, AndroidUtilities.statusBarHeight, paint);
    }
}
 
Example #28
Source File: LineViewData.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void updateColors() {
    if (line.colorKey != null && Theme.hasThemeKey(line.colorKey)) {
        lineColor = Theme.getColor(line.colorKey);
    } else {
        int color = Theme.getColor(Theme.key_windowBackgroundWhite);
        boolean darkBackground = ColorUtils.calculateLuminance(color) < 0.5f;
        lineColor = darkBackground ? line.colorDark : line.color;
    }
    paint.setColor(lineColor);
    bottomLinePaint.setColor(lineColor);
    selectionPaint.setColor(lineColor);
}
 
Example #29
Source File: ChatAttachAlert.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Keep
public void setCheckedState(float state) {
    checkedState = state;
    imageView.setScaleX(1.0f - 0.06f * state);
    imageView.setScaleY(1.0f - 0.06f * state);
    textView.setTextColor(ColorUtils.blendARGB(Theme.getColor(Theme.key_dialogTextGray2), Theme.getColor(textKey), checkedState));
    invalidate();
}
 
Example #30
Source File: ColorHelper.java    From hipda with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isTextColorReadable(String color) {
    float delta = HiSettingsHelper.getInstance().isNightMode() ? 0.35f : 0.1f;
    float[] textHslColor = new float[3], refHslColor = new float[3];
    ColorUtils.colorToHSL(Color.parseColor(color), textHslColor);
    ColorUtils.colorToHSL(HiSettingsHelper.getInstance().isNightMode() ? NIGHT_REF_COLOR : DAY_REF_COLOR, refHslColor);
    return Math.abs(textHslColor[2] - refHslColor[2]) >= delta;
}