Java Code Examples for android.support.v4.graphics.ColorUtils#setAlphaComponent()

The following examples show how to use android.support.v4.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: IntroActivity.java    From Puff-Android with MIT License 6 votes vote down vote up
private void updateTaskDescription() {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
        String title = getTitle().toString();
        Drawable iconDrawable = getApplicationInfo().loadIcon(getPackageManager());
        Bitmap icon = iconDrawable instanceof BitmapDrawable ? ((BitmapDrawable) iconDrawable).getBitmap() : null;
        int colorPrimary;
        if (position < getCount()) {
            try {
                colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackgroundDark(position));
            } catch (Resources.NotFoundException e) {
                colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackground(position));
            }
        }
        else {
            TypedValue typedValue = new TypedValue();
            TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary});
            colorPrimary = a.getColor(0, 0);
            a.recycle();
        }
        colorPrimary = ColorUtils.setAlphaComponent(colorPrimary, 0xFF);

        setTaskDescription(new ActivityManager.TaskDescription(title, icon, colorPrimary));
    }
}
 
Example 2
Source File: WorldMapView.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
public void themeViews(Context context, SuntimesTheme theme)
{
    options.backgroundColor = theme.getMapBackgroundColor();
    options.sunShadowColor = theme.getMapShadowColor();
    options.moonLightColor = theme.getMapHighlightColor();
    options.gridXColor = options.moonLightColor;
    options.gridYColor = options.moonLightColor;
    options.latitudeColors[0] = ColorUtils.setAlphaComponent(options.sunShadowColor, 255);
    options.latitudeColors[1] = ColorUtils.setAlphaComponent(options.moonLightColor, 255);
    options.latitudeColors[2] = ColorUtils.setAlphaComponent(options.moonLightColor, 255);
    options.locationFillColor = theme.getActionColor();
    options.sunFillColor = theme.getNoonIconColor();
    options.sunStrokeColor = theme.getNoonIconStrokeColor();
    options.moonFillColor = theme.getMoonFullColor();
    options.moonStrokeColor = theme.getMoonWaningColor();

    foregroundColor = theme.getMapForegroundColor();
    setMapMode(context, mode);    // options.foregroundColor is assigned with the mapMode
}
 
Example 3
Source File: WelcomeActivity.java    From andela-crypto-app with Apache License 2.0 6 votes vote down vote up
private void updateTaskDescription(int position) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        String title = getTitle().toString();
        Drawable iconDrawable = getApplicationInfo().loadIcon(getPackageManager());
        Bitmap icon = iconDrawable instanceof BitmapDrawable
                ? ((BitmapDrawable) iconDrawable).getBitmap()
                : null;
        int colorPrimary;
        if (position < slidesAdapter.getCount()) {
            colorPrimary = ContextCompat.getColor(this,
                    slidesAdapter.slides.get(position).backgroundColor);
        } else {
            TypedValue typedValue = new TypedValue();
            TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary});
            colorPrimary = a.getColor(0, 0);
            a.recycle();
        }
        colorPrimary = ColorUtils.setAlphaComponent(colorPrimary, 0xFF);
        setTaskDescription(new ActivityManager.TaskDescription(title, icon, colorPrimary));
    }
}
 
Example 4
Source File: ExtractedColors.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The hotseat's color is defined as follows:
 * - 12% black for super light wallpaper
 * - 18% white for super dark
 * - 25% white otherwise
 */
void updateHotseatPalette(Palette hotseatPalette) {
    int hotseatColor;
    int vibrantColor;

    if (hotseatPalette != null) {

        int extractedVibrantColor = hotseatPalette.getVibrantColor(ExtractedColors.DEFAULT_COLOR);
        if (ExtractionUtils.isSuperLight(hotseatPalette)) {
            hotseatColor = ColorUtils.setAlphaComponent(Color.BLACK, (int) (0.12f * 255));
            vibrantColor = ColorUtils.setAlphaComponent(extractedVibrantColor, (int) (0.12f * 255));

        } else if (ExtractionUtils.isSuperDark(hotseatPalette)) {
            hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.18f * 255));
            vibrantColor = ColorUtils.setAlphaComponent(extractedVibrantColor, (int) (0.18f * 255));
        } else {
            hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.25f * 255));
            vibrantColor = ColorUtils.setAlphaComponent(extractedVibrantColor, (int) (0.25f * 255));
        }
        setColorAtIndex(HOTSEAT_INDEX, hotseatColor);
        setColorAtIndex(VIBRANT_INDEX, vibrantColor);
    }
}
 
Example 5
Source File: IntroActivity.java    From Prodigal with Apache License 2.0 6 votes vote down vote up
private void updateTaskDescription() {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
        String title = getTitle().toString();
        Drawable iconDrawable = getApplicationInfo().loadIcon(getPackageManager());
        Bitmap icon = iconDrawable instanceof BitmapDrawable ? ((BitmapDrawable) iconDrawable).getBitmap() : null;
        int colorPrimary;
        if (position < getCount()) {
            try {
                colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackgroundDark(position));
            } catch (Resources.NotFoundException e) {
                colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackground(position));
            }
        }
        else {
            TypedValue typedValue = new TypedValue();
            TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary});
            colorPrimary = a.getColor(0, 0);
            a.recycle();
        }
        colorPrimary = ColorUtils.setAlphaComponent(colorPrimary, 0xFF);

        setTaskDescription(new ActivityManager.TaskDescription(title, icon, colorPrimary));
    }
}
 
Example 6
Source File: Picker.java    From MultiImagePicker with MIT License 6 votes vote down vote up
private void init() {
    final TypedValue typedValue = new TypedValue();
    initUsingColorAccent(typedValue);

    mImageBackgroundColor = getColor(R.color.alter_unchecked_image_background);
    mImageCheckColor = getColor(R.color.alter_image_check_color);
    mCheckedImageOverlayColor = getColor(R.color.alter_checked_photo_overlay);
    mAlbumBackgroundColor = getColor(R.color.alter_album_background);
    mAlbumNameTextColor = getColor(R.color.alter_album_name_text_color);
    mAlbumImagesCountTextColor = getColor(R.color.alter_album_images_count_text_color);
    mFabBackgroundColorWhenPressed = ColorUtils.setAlphaComponent(mFabBackgroundColor, (int) (android.graphics.Color.alpha(mFabBackgroundColor) * 0.8f));
    mPickMode = PickMode.MULTIPLE_IMAGES;

    mPopupThemeResId = Util.getDefaultPopupTheme(mContext);
    mCaptureItemIconTintColor = mDoneFabIconTintColor = Util.getDefaultIconTintColor(mContext);

    mShouldShowCaptureMenuItem = true;

    mCheckIconTintColor = Color.WHITE;
    mVideosEnabled = false;
    mVideoLengthLimit = 0; // No limit

    mVideoThumbnailOverlayColor = getColor(R.color.alter_video_thumbnail_overlay);
    mVideoIconTintColor = Color.WHITE;
}
 
Example 7
Source File: AllAngleExpandableButton.java    From AllAngleExpandableButton with Apache License 2.0 5 votes vote down vote up
private Bitmap getButtonShadowBitmap(ButtonData buttonData) {
    if (buttonData.isMainButton()) {
        if (mainShadowBitmap != null) {
            return mainShadowBitmap;
        }
    } else {
        if (subShadowBitmap != null) {
            return subShadowBitmap;
        }
    }

    int buttonSizePx = buttonData.isMainButton() ? mainButtonSizePx : subButtonSizePx;
    int buttonRadius = buttonSizePx / 2;
    int bitmapRadius = buttonRadius + buttonElevationPx;
    int bitmapSize = bitmapRadius * 2;
    Bitmap bitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap.Config.ARGB_8888);
    bitmap.eraseColor(0x0);
    int colors[] = {ColorUtils.setAlphaComponent(BUTTON_SHADOW_COLOR, BUTTON_SHADOW_ALPHA),
            ColorUtils.setAlphaComponent(BUTTON_SHADOW_COLOR, 0)};
    float stops[] = {(float) (buttonRadius - buttonElevationPx) / (float) bitmapRadius, 1};
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new RadialGradient(bitmapRadius, bitmapRadius, bitmapRadius, colors, stops, Shader.TileMode.CLAMP));
    Canvas canvas = new Canvas(bitmap);
    canvas.drawRect(0, 0, bitmapSize, bitmapSize, paint);
    if (buttonData.isMainButton()) {
        mainShadowBitmap = bitmap;
        return mainShadowBitmap;
    } else {
        subShadowBitmap = bitmap;
        return subShadowBitmap;
    }
}
 
Example 8
Source File: SampleLinkedTableAdapter.java    From AdaptiveTableLayout with MIT License 5 votes vote down vote up
@Override
public void onBindHeaderColumnViewHolder(@NonNull ViewHolderImpl viewHolder, int column) {
    int color = COLORS[column % COLORS.length];
    TestHeaderColumnViewHolder vh = (TestHeaderColumnViewHolder) viewHolder;
    vh.tvText.setText(mTableDataSource.getColumnHeaderData(column));  // skip left top header
    GradientDrawable gd = new GradientDrawable(
            mIsRtl ? GradientDrawable.Orientation.RIGHT_LEFT : GradientDrawable.Orientation.LEFT_RIGHT,
            new int[]{ColorUtils.setAlphaComponent(color, 50), 0x00000000});
    gd.setCornerRadius(0f);
    vh.vGradient.setBackground(gd);
    vh.vLine.setBackgroundColor(color);
}
 
Example 9
Source File: Hotseat.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
public Hotseat(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mLauncher = Launcher.getLauncher(context);
    mHasVerticalHotseat = mLauncher.getDeviceProfile().isVerticalBarLayout();
    mBackgroundColor = ColorUtils.setAlphaComponent(
            ThemeUtils.getAttrColor(context, android.R.attr.colorPrimary), 0);
    mBackground = new ColorDrawable(mBackgroundColor);
    setBackground(mBackground);
}
 
Example 10
Source File: MoonApsisView.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("ResourceType")
public void initTheme(Context context)
{
    int[] colorAttrs = { android.R.attr.textColorPrimary, R.attr.buttonPressColor, R.attr.text_disabledColor, R.attr.colorBackgroundFloating, R.attr.text_accentColor };
    TypedArray typedArray = context.obtainStyledAttributes(colorAttrs);
    int def = R.color.transparent;
    colorEnabled = ContextCompat.getColor(context, typedArray.getResourceId(0, def));
    colorPressed = ContextCompat.getColor(context, typedArray.getResourceId(1, def));
    colorDisabled = ContextCompat.getColor(context, typedArray.getResourceId(2, def));
    colorBackground = ColorUtils.setAlphaComponent(ContextCompat.getColor(context, typedArray.getResourceId(3, def)), (int)(9d * (254d / 10d)));
    colorAccent = ContextCompat.getColor(context, typedArray.getResourceId(4, def));
    typedArray.recycle();
    themeDrawables();
}
 
Example 11
Source File: GradientDrawableInflateImpl.java    From MagicaSakura with Apache License 2.0 4 votes vote down vote up
int getAlphaColor(int baseColor, float alpha) {
    return alpha != 1.0f
            ? ColorUtils.setAlphaComponent(baseColor, Math.round(Color.alpha(baseColor) * alpha))
            : baseColor;
}
 
Example 12
Source File: SkinCompatThemeUtils.java    From Android-skin-support with MIT License 4 votes vote down vote up
static int getThemeAttrColor(Context context, int attr, float alpha) {
    final int color = getThemeAttrColor(context, attr);
    final int originalAlpha = Color.alpha(color);
    return ColorUtils.setAlphaComponent(color, Math.round(originalAlpha * alpha));
}
 
Example 13
Source File: ColorPalette.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
public static int getTransparentColor(int color, int alpha){
    return  ColorUtils.setAlphaComponent(color, alpha);
}
 
Example 14
Source File: ColorPalette.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
public static int getTransparentColor(int color, int alpha){
    return  ColorUtils.setAlphaComponent(color, alpha);
}
 
Example 15
Source File: ColorPalette.java    From Android-AudioRecorder-App with Apache License 2.0 4 votes vote down vote up
public static int getTransparentColor(int color, int alpha) {
  return ColorUtils.setAlphaComponent(color, alpha);
}
 
Example 16
Source File: PhonographColorUtil.java    From Orin with GNU General Public License v3.0 4 votes vote down vote up
public static int setTransparency(int color, int transparancy) {
    return ColorUtils.setAlphaComponent(color, transparancy);
}
 
Example 17
Source File: FolderIcon.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
public void drawBackground(Context context, Canvas canvas) {
    mPaint.setStyle(Paint.Style.FILL);

    int alpha = (int) Math.min(MAX_BG_OPACITY, BG_OPACITY * mColorMultiplier);

    //set the theme attributes to the folder preview circle (stroke and inner bg)
    int accent = ThemeUtils.getColorAccent(context);
    int defaultColor = PreferencesState.isDarkThemeEnabled(context)? Color.argb(alpha, BG_INTENSITY_DARK, BG_INTENSITY_DARK, BG_INTENSITY_DARK) : Color.argb(alpha, BG_INTENSITY, BG_INTENSITY, BG_INTENSITY);
    int color = PreferencesState.areColoredFoldersEnabled(context)? ColorUtils.setAlphaComponent(accent, alpha) : defaultColor;

    mPaint.setColor(color);

    drawCircle(canvas, 0 /* deltaRadius */);

    // Draw shadow.
    if (mShadowShader == null) {
        return;
    }
    float radius = getScaledRadius();
    float shadowRadius = radius + mStrokeWidth;
    mPaint.setColor(Color.BLACK);
    int offsetX = getOffsetX();
    int offsetY = getOffsetY();
    final int saveCount;
    if (canvas.isHardwareAccelerated()) {
        saveCount = canvas.saveLayer(offsetX - mStrokeWidth, offsetY,
                offsetX + radius + shadowRadius, offsetY + shadowRadius + shadowRadius,
                null, Canvas.CLIP_TO_LAYER_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);

    } else {
        saveCount = canvas.save(Canvas.CLIP_SAVE_FLAG);
        clipCanvasSoftware(canvas, Region.Op.DIFFERENCE);
    }

    mShaderMatrix.setScale(shadowRadius, shadowRadius);
    mShaderMatrix.postTranslate(radius + offsetX, shadowRadius + offsetY);
    mShadowShader.setLocalMatrix(mShaderMatrix);
    mPaint.setShader(mShadowShader);
    canvas.drawPaint(mPaint);
    mPaint.setShader(null);

    if (canvas.isHardwareAccelerated()) {
        mPaint.setXfermode(mShadowPorterDuffXfermode);
        canvas.drawCircle(radius + offsetX, radius + offsetY, radius, mPaint);
        mPaint.setXfermode(null);
    }

    canvas.restoreToCount(saveCount);
}
 
Example 18
Source File: ThemeUtils.java    From MagicaSakura with Apache License 2.0 4 votes vote down vote up
static int getThemeAttrColor(Context context, @AttrRes int attr, float alpha) {
    final int color = getThemeAttrColor(context, attr);
    final int originalAlpha = Color.alpha(color);

    return ColorUtils.setAlphaComponent(color, Math.round(originalAlpha * alpha));
}
 
Example 19
Source File: ThemeUtils.java    From timecat with Apache License 2.0 4 votes vote down vote up
static int getThemeAttrColor(Context context, @AttrRes int attr, float alpha) {
    final int color = getThemeAttrColor(context, attr);
    final int originalAlpha = Color.alpha(color);

    return ColorUtils.setAlphaComponent(color, Math.round(originalAlpha * alpha));
}
 
Example 20
Source File: ColorMixer.java    From GankMeizhi with Apache License 2.0 3 votes vote down vote up
/**
 * 将两个颜色叠加起来
 *
 * @param background 背景色
 * @param foreground 前景色
 * @param ratio      调节前景色的透明度比例
 * @return 混合后的颜色
 */
public static int mix(@ColorInt int background, @ColorInt int foreground, float ratio) {
    int alpha = Color.alpha(foreground);
    alpha = (int) Math.floor((float) alpha * ratio);
    foreground = ColorUtils.setAlphaComponent(foreground, alpha);
    return ColorUtils.compositeColors(foreground, background);
}