Java Code Examples for android.graphics.Color.argb()

The following are Jave code examples for showing how to use argb() of the android.graphics.Color class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: True-Weather   File: Const.java   Source Code and License Vote up 9 votes
public static int getAIColor() {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    int cHour = cal.get(Calendar.HOUR_OF_DAY);

    int color = Color.argb(119, 94, 94, 94);

    switch (cHour) {
        case 0:
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
            color = Color.argb(184, 1, 7, 61);
            break;
    }

    return color;
}
 
Example 2
Project: PlusGram   File: ColorPicker.java   Source Code and License Vote up 6 votes
private int interpolateColors(int leftColor, int rightColor, float factor) {
    factor = Math.min(Math.max(factor, 0.0f), 1.0f);

    int r1 = Color.red(leftColor);
    int r2 = Color.red(rightColor);

    int g1 = Color.green(leftColor);
    int g2 = Color.green(rightColor);

    int b1 = Color.blue(leftColor);
    int b2 = Color.blue(rightColor);

    int r = Math.min(255, (int) (r1 + (r2 - r1) * factor));
    int g = Math.min(255, (int) (g1 + (g2 - g1) * factor));
    int b = Math.min(255, (int) (b1 + (b2 - b1) * factor));

    return Color.argb(255, r, g, b);
}
 
Example 3
Project: garras   File: CollectionAdapter.java   Source Code and License Vote up 6 votes
private int computeCardBackgroundColor(String color) {
    if (TextUtils.isEmpty(color)
            || (!Pattern.compile("^#[a-fA-F0-9]{6}").matcher(color).matches()
            && !Pattern.compile("^[a-fA-F0-9]{6}").matcher(color).matches())) {
        return Color.argb(0, 0, 0, 0);
    } else {
        if (Pattern.compile("^[a-fA-F0-9]{6}").matcher(color).matches()) {
            color = "#" + color;
        }
        int backgroundColor = Color.parseColor(color);
        int red = ((backgroundColor & 0x00FF0000) >> 16);
        int green = ((backgroundColor & 0x0000FF00) >> 8);
        int blue = (backgroundColor & 0x000000FF);
        return Color.rgb(
                (int) (red + (255 - red) * 0.7),
                (int) (green + (255 - green) * 0.7),
                (int) (blue + (255 - blue) * 0.7));
    }
}
 
Example 4
Project: Quran   File: QuranPageLayout.java   Source Code and License Vote up 6 votes
@Override
public void updateView(@NonNull QuranSettings quranSettings) {
  super.updateView(quranSettings);
  boolean nightMode = quranSettings.isNightMode();
  int lineColor = Color.BLACK;
  final int nightModeTextBrightness = nightMode ?
      quranSettings.getNightModeTextBrightness() : Constants.DEFAULT_NIGHT_MODE_TEXT_BRIGHTNESS;
  if (nightMode) {
    lineColor = Color.argb(nightModeTextBrightness, 255, 255, 255);
  }

  if (pageNumber % 2 == 0) {
    leftBorder = nightMode ? BorderMode.DARK : BorderMode.LIGHT;
    rightBorder = BorderMode.HIDDEN;
  } else {
    rightBorder = nightMode ? BorderMode.DARK : BorderMode.LIGHT;
    if (QuranPageLayout.lineColor != lineColor) {
      QuranPageLayout.lineColor = lineColor;
      lineDrawable.getPaint().setColor(lineColor);
    }
    leftBorder = BorderMode.LINE;
  }

  updateBackground(nightMode, quranSettings);
}
 
Example 5
Project: garras   File: PhotoAdapter.java   Source Code and License Vote up 6 votes
private int computeCardBackgroundColor(String color) {
    if (TextUtils.isEmpty(color)
            || (!Pattern.compile("^#[a-fA-F0-9]{6}").matcher(color).matches()
            && !Pattern.compile("^[a-fA-F0-9]{6}").matcher(color).matches())) {
        return Color.argb(0, 0, 0, 0);
    } else {
        if (Pattern.compile("^[a-fA-F0-9]{6}").matcher(color).matches()) {
            color = "#" + color;
        }
        int backgroundColor = Color.parseColor(color);
        int red = ((backgroundColor & 0x00FF0000) >> 16);
        int green = ((backgroundColor & 0x0000FF00) >> 8);
        int blue = (backgroundColor & 0x000000FF);
        return Color.rgb(
                (int) (red + (255 - red) * 0.7),
                (int) (green + (255 - green) * 0.7),
                (int) (blue + (255 - blue) * 0.7));
    }
}
 
Example 6
Project: FakeWeather   File: ThemeUtil.java   Source Code and License Vote up 5 votes
public static int changeAlpha(int color, float fraction) {
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    int alpha = (int) (Color.alpha(color) * fraction);
    return Color.argb(alpha, red, green, blue);
}
 
Example 7
Project: phonk   File: AndroidUtils.java   Source Code and License Vote up 5 votes
public static int darkenColor(int color, float factor) {

        int a = Color.alpha( color );
        int r = Color.red( color );
        int g = Color.green( color );
        int b = Color.blue( color );

        return Color.argb( a,
                Math.max( (int)(r * factor), 0 ),
                Math.max( (int)(g * factor), 0 ),
                Math.max( (int)(b * factor), 0 ) );
    }
 
Example 8
Project: QMUI_Android   File: QMUICollapsingTextHelper.java   Source Code and License Vote up 5 votes
/**
 * Blend {@code color1} and {@code color2} using the given ratio.
 *
 * @param ratio of which to blend. 0.0 will return {@code color1}, 0.5 will give an even blend,
 *              1.0 will return {@code color2}.
 */
private static int blendColors(int color1, int color2, float ratio) {
    final float inverseRatio = 1f - ratio;
    float a = (Color.alpha(color1) * inverseRatio) + (Color.alpha(color2) * ratio);
    float r = (Color.red(color1) * inverseRatio) + (Color.red(color2) * ratio);
    float g = (Color.green(color1) * inverseRatio) + (Color.green(color2) * ratio);
    float b = (Color.blue(color1) * inverseRatio) + (Color.blue(color2) * ratio);
    return Color.argb((int) a, (int) r, (int) g, (int) b);
}
 
Example 9
Project: AndroidDigIn   File: Utils.java   Source Code and License Vote up 5 votes
/**
 * 从颜色得到另一个对比度高的颜色,其实就是给出黑白两种色,
 * 不过传入的颜色如果较暗,那就是白色,如果较亮那就是黑色
 * @param color
 * @return
 */
public static int getComplimentColor(@ColorInt int color) {
    // get existing colors
    int alpha = Color.alpha(color);
    int red = Color.red(color);
    int blue = Color.blue(color);
    int green = Color.green(color);

    // find compliments
    red = (~red) & 0xff;
    blue = (~blue) & 0xff;
    green = (~green) & 0xff;

    return Color.argb(alpha, red, green, blue);
}
 
Example 10
Project: blockvote   File: HistoryView.java   Source Code and License Vote up 5 votes
private static Paint makePaint(Option option, Interval interval, int strokeWidth) {
	Paint paint = new Paint();
	paint.setStyle(Paint.Style.STROKE);
	paint.setAntiAlias(true);

	// 1d and 7d invisible until a nice way to display/configure is found
	int   alpha;
	switch (interval) {
		case D1:
			alpha = 0;
			break;
		case D7:
			alpha = 0;
			break;
		case D30:
			alpha = 200;
			break;
		default:
			throw new IllegalArgumentException();
	}
	paint.setStrokeWidth(strokeWidth);

	int color;
	switch (option) {
		case SW:
			color = Color.argb(alpha, 255, 0, 0);
			break;
		case BU:
			color = Color.argb(alpha, 0, 0, 255);
			break;
		default:
			throw new IllegalArgumentException();
	}
	paint.setColor(color);

	return paint;
}
 
Example 11
Project: Blockly   File: CategoryView.java   Source Code and License Vote up 5 votes
protected void updateCategoryColors(BlocklyCategory curCategory) {
    Integer maybeColor = curCategory == null ? null : curCategory.getColor();
    int bgColor = DEFAULT_CATEGORIES_BACKGROUND_COLOR;
    if (maybeColor != null) {
        bgColor = getBackgroundColor(maybeColor);
    }

    int alphaBgColor = Color.argb(
            mCloseable ? DEFAULT_CATEGORIES_BACKGROUND_ALPHA : ColorUtils.ALPHA_OPAQUE,
            Color.red(bgColor), Color.green(bgColor), Color.blue(bgColor));
    this.setBackgroundColor(alphaBgColor);
}
 
Example 12
Project: CoolApk-Console   File: BezelImageView.java   Source Code and License Vote up 5 votes
public BezelImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Attribute initialization
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView, defStyle, R.style.BezelImageView);

    mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_biv_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }

    mDrawCircularShadow = a.getBoolean(R.styleable.BezelImageView_biv_drawCircularShadow, true);

    mSelectorColor = a.getColor(R.styleable.BezelImageView_biv_selectorOnPress, 0);

    a.recycle();

    // Other initialization
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    // Create a desaturate color filter for pressed state.
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    mDesaturateColorFilter = new ColorMatrixColorFilter(cm);

    //create a selectorFilter if we already have a color
    if (mSelectorColor != 0) {
        this.mSelectorFilter = new PorterDuffColorFilter(Color.argb(mSelectorAlpha, Color.red(mSelectorColor), Color.green(mSelectorColor), Color.blue(mSelectorColor)), PorterDuff.Mode.SRC_ATOP);
    }
}
 
Example 13
Project: easyfilemanager   File: ColorUtils.java   Source Code and License Vote up 5 votes
/**
 * Composite two potentially translucent colors over each other and returns the result.
 */
public static int compositeColors(int fg, int bg) {
    final float alpha1 = Color.alpha(fg) / 255f;
    final float alpha2 = Color.alpha(bg) / 255f;

    float a = (alpha1 + alpha2) * (1f - alpha1);
    float r = (Color.red(fg) * alpha1) + (Color.red(bg) * alpha2 * (1f - alpha1));
    float g = (Color.green(fg) * alpha1) + (Color.green(bg) * alpha2 * (1f - alpha1));
    float b = (Color.blue(fg) * alpha1) + (Color.blue(bg) * alpha2 * (1f - alpha1));

    return Color.argb((int) a, (int) r, (int) g, (int) b);
}
 
Example 14
Project: ZhaZhaShop   File: FragmentMovieMain.java   Source Code and License Vote up 4 votes
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    if (positionOffset == 0 && positionOffsetPixels == 0) {
        onPageSelected(position);
        return;
    }

    boolean lessThanHalf = positionOffset < 0.5;

    // alpha变化范围:-255~255
    float alpha = (1 - positionOffset * 2) * 255;
    int alphaWhite = Color.argb((int) alpha, 255, 255, 255); // 白渐变到透明
    int alphaBlue = Color.argb((int) alpha, 0, 153, 204); // 蓝渐变到透明

    int alphaWhiteReverse = Color.argb((int) -alpha, 255, 255, 255); // 白渐变到透明
    int alphaBlueReverse = Color.argb((int) -alpha, 0, 153, 204); // 蓝渐变到透明

    //获取滑块的Layout
    mParams = (FrameLayout.LayoutParams) mViewIndicator.getLayoutParams();
    //判断滑动的距离
    if (positionOffset == 0) { // 停止滚动
        mParams.setMargins(mViewIndicator.getWidth() * position, 0, 0, 0);
    } else {
        mParams.setMargins((int) (mViewIndicator.getWidth() * (position + positionOffset)), 0, 0, 0);
    }
    //通过LayoutParams设置滑块的位置
    mViewIndicator.setLayoutParams(mParams);

    switch (position) {
        case 0:
            if (lessThanHalf) {
                mTvHotMovie.setTextColor(alphaBlue);
                mTvWaitMovie.setTextColor(alphaWhite);
            } else {
                mTvHotMovie.setTextColor(alphaWhiteReverse);
                mTvWaitMovie.setTextColor(alphaBlueReverse);
            }
            break;
        case 1:
            if (lessThanHalf) {
                mTvWaitMovie.setTextColor(alphaBlue);
                mTvFindMovie.setTextColor(alphaWhite);
            } else {
                mTvWaitMovie.setTextColor(alphaWhiteReverse);
                mTvFindMovie.setTextColor(alphaBlueReverse);
            }
            break;
    }
}
 
Example 15
Project: AssistantBySDK   File: DatePickerDialog.java   Source Code and License Vote up 4 votes
/**
 * Set the text color of the OK button
 * @param color the color you want
 */
@SuppressWarnings("unused")
public void setOkColor(@ColorInt int color) {
    mOkColor = Color.argb(255, Color.red(color), Color.green(color), Color.blue(color));
}
 
Example 16
Project: AssistantBySDK   File: TimePickerDialog.java   Source Code and License Vote up 4 votes
/**
 * Set the text color of the OK button
 * @param color the color you want
 */
@SuppressWarnings("unused")
public void setOkColor(@ColorInt int color) {
    mOkColor = Color.argb(255, Color.red(color), Color.green(color), Color.blue(color));
}
 
Example 17
Project: iosched-reader   File: SlidingTabStrip.java   Source Code and License Vote up 4 votes
/**
 * Set the alpha value of the {@code color} to be the given {@code alpha} value.
 */
private static int setColorAlpha(int color, byte alpha) {
    return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color));
}
 
Example 18
Project: buildAPKsApps   File: JavaScriptSurfaceInterface.java   Source Code and License Vote up 4 votes
@JavascriptInterface
public void setColor(int r, int g, int b)
{
    int c = Color.argb(255, r, g, b);
    mPaint.setColor(c);
}
 
Example 19
Project: LaunchTime   File: Theme.java   Source Code and License Vote up 4 votes
private void initBuiltinIconThemes() {
    builtinThemes.put(IconsHandler.DEFAULT_PACK, new DefaultTheme(IconsHandler.DEFAULT_PACK, ctx.getString(R.string.icons_pack_default_name)));

    int [] ucolors = {Color.argb(127,50,50,50), Color.argb(127,10,10,160), Color.argb(127,170,10,10)};
    int [] ubcolors = {Color.BLACK, Color.argb(127,0,0,60), Color.argb(127,60,0,6)};
    for (int i=1; i<=3; i++) {
        BuiltinTheme u = new MonochromeTheme("user" + i, ctx.getString(R.string.user_theme, i))
                .setColor(Thing.Mask, Color.TRANSPARENT)
                .setColor(Thing.Text, Color.argb(255,220,220,220))
                .setColor(Thing.AltText, Color.WHITE)
                .setColor(Thing.Background, ubcolors[i-1])
                .setColor(Thing.AltBackground, ucolors[i-1]);

        builtinThemes.put(u.getPackKey(), u);
    }

    BuiltinTheme bwicon = new MonochromeTheme("bwicon", ctx.getString(R.string.theme_bw))
            .setColor(Thing.Mask, Color.WHITE)
            .setColor(Thing.Text, Color.argb(255,220,220,220))
            .setColor(Thing.AltText, Color.WHITE)
            .setColor(Thing.Background, Color.BLACK)
            .setColor(Thing.AltBackground, Color.parseColor("#ff222222"));

    builtinThemes.put(bwicon.getPackKey(), bwicon);


    BuiltinTheme termcap = new MonochromeTheme("termcap", ctx.getString(R.string.theme_termcap))
            .setColor(Thing.Mask, Color.parseColor("#dd22ff22"))
            .setColor(Thing.Text, Color.parseColor("#dd22ff22"))
            .setColor(Thing.AltText, Color.parseColor("#dd22ff22"))
            .setColor(Thing.Background, Color.BLACK)
            .setColor(Thing.AltBackground, Color.parseColor("#dd112211"));

    builtinThemes.put(termcap.getPackKey(), termcap);


    BuiltinTheme coolblue = new MonochromeTheme("coolblue", ctx.getString(R.string.theme_coolblue))
            .setColor(Thing.Mask, Color.parseColor("#ff1111ff"))
            .setColor(Thing.Text, Color.parseColor("#eeffffff"))
            .setColor(Thing.AltText, Color.parseColor("#eeffffff"))
            .setColor(Thing.Background, Color.parseColor("#88000077"))
            .setColor(Thing.AltBackground, Color.parseColor("#881111ff"));

    builtinThemes.put(coolblue.getPackKey(), coolblue);

    BuiltinTheme redplanet = new MonochromeTheme("redplanet", ctx.getString(R.string.theme_redplanet))
            .setColor(Thing.Mask, Color.parseColor("#ffff2222"))
            .setColor(Thing.Text, Color.parseColor("#eeff2222"))
            .setColor(Thing.AltText, Color.parseColor("#eeff2222"))
            .setColor(Thing.Background, Color.parseColor("#77550000"))
            .setColor(Thing.AltBackground, Color.parseColor("#22121111"));

    builtinThemes.put(redplanet.getPackKey(), redplanet);

    BuiltinTheme ladypink = new MonochromeTheme("ladypink", ctx.getString(R.string.theme_ladypink))
            .setColor(Thing.Mask, Color.parseColor("#ffff1493"))
            .setColor(Thing.Text, Color.parseColor("#eeffffff"))
            .setColor(Thing.AltText, Color.parseColor("#eeffc0cb"))
            .setColor(Thing.Background, Color.parseColor("#ffff69b4"))
            .setColor(Thing.AltBackground, Color.parseColor("#ffff1493"));

    builtinThemes.put(ladypink.getPackKey(), ladypink);
}
 
Example 20
Project: CoolApk-Console   File: BezelImageView.java   Source Code and License Vote up 2 votes
/**
 * Sets the color of the selector to be draw over the
 * CircularImageView. Be sure to provide some opacity.
 *
 * @param selectorColor The color (including alpha) to set for the selector overlay.
 */
public void setSelectorColor(int selectorColor) {
    this.mSelectorColor = selectorColor;
    this.mSelectorFilter = new PorterDuffColorFilter(Color.argb(mSelectorAlpha, Color.red(mSelectorColor), Color.green(mSelectorColor), Color.blue(mSelectorColor)), PorterDuff.Mode.SRC_ATOP);
    this.invalidate();
}