Java Code Examples for androidx.core.graphics.ColorUtils#setAlphaComponent()

The following examples show how to use androidx.core.graphics.ColorUtils#setAlphaComponent() . 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: FlyoutMenuView.java    From FlyoutMenus with MIT License 6 votes vote down vote up
Bitmap createButtonShadowBitmap() {
	int shadowRadius = (int) buttonElevation * 2;
	int bitmapRadius = buttonRadius + (shadowRadius / 2);
	int bitmapSize = bitmapRadius * 2;
	Bitmap shadowBitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap.Config.ARGB_8888);
	shadowBitmap.eraseColor(0x0);

	int colors[] = {
			ColorUtils.setAlphaComponent(SHADOW_COLOR, SHADOW_ALPHA),
			ColorUtils.setAlphaComponent(SHADOW_COLOR, 0)
	};

	float stops[] = {
			(float) (buttonRadius - (shadowRadius / 2)) / (float) bitmapRadius,
			1f
	};

	Paint paint = new Paint();
	paint.setAntiAlias(true);
	paint.setShader(new RadialGradient(bitmapRadius, bitmapRadius, bitmapRadius, colors, stops, Shader.TileMode.CLAMP));

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

	return shadowBitmap;
}
 
Example 2
Source File: ThemedCheckBox.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
static ColorStateList createCheckBoxTintStateList(Context ctx, LiveThemeComponent component) {
    LiveThemeManager lmgr = component.getLiveThemeManager();
    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(ctx, android.R.attr.disabledAlpha, 1.f)));
    return new ColorStateList(new int[][] {
            new int[] { -android.R.attr.state_enabled },
            new int[] { android.R.attr.state_checked },
            new int[] { }
    }, new int[] {
            disabledColor,
            accentColor,
            normalColor
    });
}
 
Example 3
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 4
Source File: ColorImageExample.java    From fresco with MIT License 5 votes vote down vote up
@Override
public CloseableImage decode(
    EncodedImage encodedImage,
    int length,
    QualityInfo qualityInfo,
    ImageDecodeOptions options) {
  try {
    // Read the file as a string
    String text = new String(ByteStreams.toByteArray(encodedImage.getInputStream()));

    // Check if the string matches "<color>#"
    if (!text.startsWith(COLOR_TAG + "#")) {
      return null;
    }

    // Parse the int value between # and <
    int startIndex = COLOR_TAG.length() + 1;
    int endIndex = text.lastIndexOf('<');
    int color = Integer.parseInt(text.substring(startIndex, endIndex), 16);

    // Add the alpha component so that we actually see the color
    color = ColorUtils.setAlphaComponent(color, 255);

    // Return the CloseableImage
    return new CloseableColorImage(color);
  } catch (IOException e) {
    e.printStackTrace();
  }
  // Return nothing if an error occurred
  return null;
}
 
Example 5
Source File: MaterialWeatherView.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public int[] getThemeColors(boolean lightTheme) {
    int color = getBackgroundColor();
    if (!lightTheme) {
        color = getBrighterColor(color);
        return new int[] {color, color, ColorUtils.setAlphaComponent(color, (int) (0.5 * 255))};
    } else {
        return new int[] {color, color, ColorUtils.setAlphaComponent(color, (int) (0.5 * 255))};
    }
}
 
Example 6
Source File: RippleUtils.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/**
 * On API 21+, the framework composites a ripple color onto the display at about 50% opacity.
 * Since we are providing precise ripple colors, cancel that out by doubling the opacity here.
 */
@ColorInt
@TargetApi(VERSION_CODES.LOLLIPOP)
private static int doubleAlpha(@ColorInt int color) {
  int alpha = Math.min(2 * Color.alpha(color), 255);
  return ColorUtils.setAlphaComponent(color, alpha);
}
 
Example 7
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 8
Source File: TrendLinearLayout.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setColor(boolean lightTheme) {
    if (lightTheme) {
        lineColor = ColorUtils.setAlphaComponent(Color.BLACK, (int) (255 * 0.05));
        textColor = ContextCompat.getColor(getContext(), R.color.colorTextSubtitle_light);
    } else {
        lineColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (255 * 0.1));
        textColor = ContextCompat.getColor(getContext(), R.color.colorTextSubtitle_dark);
    }
}
 
Example 9
Source File: TodayWidgetConfigureActivity.java    From ETSMobile-Android2 with Apache License 2.0 5 votes vote down vote up
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    int bgColor = Integer.parseInt(mBgColorSpinner.getSelectedItem().toString());
    int opacity = mOpacitySeekBar.getProgress();
    bgColor = ColorUtils.setAlphaComponent(bgColor, opacity);

    mWidgetPreviewLayout.setBackgroundColor(bgColor);
}
 
Example 10
Source File: ThemedCheckBox.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
static ColorStateList createCheckBoxRippleTintStateList(Context ctx, LiveThemeComponent component) {
    LiveThemeManager lmgr = component.getLiveThemeManager();
    int accentColor = lmgr.getColor(/* R.attr.colorControlActivated */ R.attr.colorAccent);
    int normalColor = StyledAttributesHelper.getColor(ctx, R.attr.colorControlHighlight, 0);
    int accentAlphaColor = ColorUtils.setAlphaComponent(accentColor, (int) (255.f * 0.26f)); // highlight_alpha_material_colored
    return new ColorStateList(new int[][] {
            new int[] { android.R.attr.state_enabled, android.R.attr.state_checked },
            new int[] { }
    }, new int[] {
            accentAlphaColor,
            normalColor
    });
}
 
Example 11
Source File: SelectableRecyclerViewAdapter.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
public SelectableRecyclerViewAdapter(Context context) {
    StyledAttributesHelper ta = StyledAttributesHelper.obtainStyledAttributes(context,
            new int[] { R.attr.selectableItemBackground, R.attr.colorControlHighlight });
    mBackground = ta.getDrawable(R.attr.selectableItemBackground);
    int color = ta.getColor(R.attr.colorControlHighlight, 0);
    color = ColorUtils.setAlphaComponent(color, Color.alpha(color) / 2);
    mSelectedBackground = new ColorDrawable(color);
    ta.recycle();
}
 
Example 12
Source File: ImeContainer.java    From mongol-library with MIT License 5 votes vote down vote up
private void styleCandidatesView() {
    mCandidatesView.setCandidateBackgroundColor(mCurrentKeyboard.getKeyColor());
    mCandidatesView.setBackgroundPressedColor(mCurrentKeyboard.getKeyPressedColor());
    mCandidatesView.setBorderColor(mCurrentKeyboard.getBorderColor());
    mCandidatesView.setBorderWidth(mCurrentKeyboard.getBorderWidth());
    mCandidatesView.setBorderRadius(mCurrentKeyboard.getBorderRadius());

    int textColor = mCurrentKeyboard.getPrimaryTextColor();
    mCandidatesView.setTextColor(textColor);
    int dividerColor = ColorUtils.setAlphaComponent(textColor, DIVIDER_ALPHA);
    mCandidatesView.setDividerColor(dividerColor);
}
 
Example 13
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 14
Source File: VideoPlayerSeekBar.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void setPaintColor(int color, float alpha) {
    if (alpha < 1f) {
        color = ColorUtils.setAlphaComponent(color, (int) (Color.alpha(color) * alpha));
    }
    paint.setColor(color);
}
 
Example 15
Source File: DisplayUtils.java    From GeometricWeather with GNU Lesser General Public License v3.0 4 votes vote down vote up
@ColorInt
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private static int getStatusBarColor21() {
    return ColorUtils.setAlphaComponent(Color.BLACK, (int) (0.1 * 255));
}
 
Example 16
Source File: ShadowRenderer.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
public void setShadowColor(int color) {
  shadowStartColor = ColorUtils.setAlphaComponent(color, COLOR_ALPHA_START);
  shadowMiddleColor = ColorUtils.setAlphaComponent(color, COLOR_ALPHA_MIDDLE);
  shadowEndColor = ColorUtils.setAlphaComponent(color, COLOR_ALPHA_END);
  shadowPaint.setColor(shadowStartColor);
}
 
Example 17
Source File: VideoPlayerSeekBar.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void setPaintColor(int color, float alpha) {
    if (alpha < 1f) {
        color = ColorUtils.setAlphaComponent(color, (int) (Color.alpha(color) * alpha));
    }
    paint.setColor(color);
}
 
Example 18
Source File: ElevationOverlayProvider.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private boolean isThemeSurfaceColor(@ColorInt int color) {
  return ColorUtils.setAlphaComponent(color, 255) == colorSurface;
}
 
Example 19
Source File: MaterialColors.java    From material-components-android with Apache License 2.0 3 votes vote down vote up
/**
 * Calculates a new color by multiplying an additional alpha int value to the alpha channel of a
 * color in integer type.
 *
 * @param originalARGB The original color.
 * @param alpha The additional alpha [0-255].
 * @return The blended color.
 */
@ColorInt
public static int compositeARGBWithAlpha(
    @ColorInt int originalARGB, @IntRange(from = 0, to = 255) int alpha) {
  alpha = Color.alpha(originalARGB) * alpha / 255;
  return ColorUtils.setAlphaComponent(originalARGB, alpha);
}
 
Example 20
Source File: FlyoutMenuView.java    From FlyoutMenus with MIT License 2 votes vote down vote up
/**
 * Set the background fill color for the button
 *
 * @param buttonBackgroundColor the argb color for the background of the button
 */
public void setButtonBackgroundColor(int buttonBackgroundColor) {
	this.buttonBackgroundColor = ColorUtils.setAlphaComponent(buttonBackgroundColor, 255);
	invalidate();
}