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

The following examples show how to use android.graphics.Color#argb() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
public void setLetterDashed(int letteridx,boolean dashed)
{
    List<OBPath>pathList = (List)groupList.get(letteridx).members;
    int col = dashed?Color.argb(255,230,230,230) :Color.BLACK;
    float lw = dashed?lineWidth * 0.5f:lineWidth;
    lockScreen();
    for(OBPath p : pathList)
    {
        if(dashed)
            p.setLineDashPattern(Arrays.asList((dashlen0) ,(dashlen1)));
        else
            p.setLineDashPattern(null);
        p.setStrokeColor(col);
        p.setLineWidth(lw);
    }
    unlockScreen();
}
 
Example 2
public void onRadioButtonClicked(int id) {
    // Check which radio button was clicked
    handlingFillColor = id == R.id.doFillRadioButton;

    int fill;
    int alpha;
    if (handlingFillColor) {
        fill = mCurrentColorStrokeObject.fillColor;
        alpha = mCurrentColorStrokeObject.fillAlpha;
    } else {
        fill = mCurrentColorStrokeObject.strokeColor;
        alpha = mCurrentColorStrokeObject.strokeAlpha;
    }
    int red = Color.red(fill);
    int green = Color.green(fill);
    int blue = Color.blue(fill);
    int argb = Color.argb(red, green, blue, alpha);
    mColorView.setBackgroundColor(argb);
    mAlphaSeekBar.setProgress(alpha);
    mRedSeekBar.setProgress(red);
    mGreenSeekBar.setProgress(green);
    mBlueSeekBar.setProgress(blue);
}
 
Example 3
Source Project: AndroidDemo   File: ScanView.java    License: MIT License 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    Paint mPaint = new Paint();
    mPaint.setAntiAlias(true);
    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    Rect rectd = new Rect((viewSize / 10) * 4, (viewSize / 10) * 4, viewSize - (viewSize / 10) * 4, viewSize - (viewSize / 10) * 4);
    canvas.drawBitmap(bitmap, rect, rectd, mPaint);

    circlePaint = new Paint();
    circlePaint.setStyle(Paint.Style.STROKE);
    circlePaint.setAntiAlias(true);
    circlePaint.setStrokeWidth((viewSize / 10));

    circlePaint.setColor(Color.parseColor(circlrColor1));
    canvas.drawCircle(viewSize / 2, viewSize / 2, (viewSize / 10) * 2.5f, circlePaint);

    circlePaint.setColor(Color.parseColor(circlrColor2));
    canvas.drawCircle(viewSize / 2, viewSize / 2, (viewSize / 10) * 3.5f, circlePaint);

    circlePaint.setColor(Color.parseColor(circlrColor3));
    canvas.drawCircle(viewSize / 2, viewSize / 2, (viewSize / 10) * 4.5f, circlePaint);

    sectorPaint = new Paint();
    sectorPaint.setAntiAlias(true);
    sectorPaint.setStyle(Paint.Style.STROKE);
    sectorPaint.setStrokeWidth((viewSize / 10) * 3);
    Shader sectorShader = new SweepGradient(viewSize / 2, viewSize / 2,
            new int[]{Color.TRANSPARENT, Color.argb(0,Color.red(accentColor),Color.green(accentColor),Color.blue(accentColor)),
                    Color.argb(255,Color.red(accentColor),Color.green(accentColor),Color.blue(accentColor))},
            new float[]{0, 0.875f, 1f});
    sectorPaint.setShader(sectorShader);

    if (threadFlag) {
        canvas.concat(matrix);
        canvas.drawCircle(viewSize / 2, viewSize / 2, (viewSize / 10) * 3.5f, sectorPaint);
    }
}
 
Example 4
Source Project: droidddle   File: UiUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static int scaleColor(int color, float factor, boolean scaleAlpha) {
    return Color
            .argb(scaleAlpha ? (Math.round(Color.alpha(color) * factor)) : Color.alpha(color),
                    Math.round(Color.red(color) * factor),
                    Math.round(Color.green(color) * factor),
                    Math.round(Color.blue(color) * factor));
}
 
Example 5
Source Project: TextFieldBoxes   File: TextFieldBoxes.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * return a lighter color
 *
 * @param factor percentage of light applied
 */
protected static int lighter(int color, float factor) {

    int red = (int) ((Color.red(color) * (1 - factor) / 255 + factor) * 255);
    int green = (int) ((Color.green(color) * (1 - factor) / 255 + factor) * 255);
    int blue = (int) ((Color.blue(color) * (1 - factor) / 255 + factor) * 255);
    return Color.argb(Color.alpha(color), red, green, blue);
}
 
Example 6
Source Project: HoldingButton   File: ColorHelper.java    License: Apache License 2.0 5 votes vote down vote up
static int blend(int from, int to, float ratio) {
    float inverseRatio = 1f - ratio;

    float a = Color.alpha(to) * ratio + Color.alpha(from) * inverseRatio;
    float r = Color.red(to) * ratio + Color.red(from) * inverseRatio;
    float g = Color.green(to) * ratio + Color.green(from) * inverseRatio;
    float b = Color.blue(to) * ratio + Color.blue(from) * inverseRatio;

    return Color.argb((int) a, (int) r, (int) g, (int) b);
}
 
Example 7
Source Project: sealrtc-android   File: MarkerDrawable.java    License: MIT License 5 votes vote down vote up
private static int blendColors(int color1, int color2, float factor) {
    final float inverseFactor = 1f - factor;
    float a = (Color.alpha(color1) * factor) + (Color.alpha(color2) * inverseFactor);
    float r = (Color.red(color1) * factor) + (Color.red(color2) * inverseFactor);
    float g = (Color.green(color1) * factor) + (Color.green(color2) * inverseFactor);
    float b = (Color.blue(color1) * factor) + (Color.blue(color2) * inverseFactor);
    return Color.argb((int) a, (int) r, (int) g, (int) b);
}
 
Example 8
Source Project: APlayer   File: ColorUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 调整颜色透明度
 */
@ColorInt
public static int adjustAlpha(@ColorInt int paramInt,
    @FloatRange(from = 0.0D, to = 1.0D) float paramFloat) {
  return Color.argb(Math.round(Color.alpha(paramInt) * paramFloat), Color.red(paramInt),
      Color.green(paramInt), Color.blue(paramInt));
}
 
Example 9
Source Project: MaterialDesignLibrary   File: Switch.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Make a dark color to press effect
 * 
 * @return
 */
protected int makePressColor() {
	int r = (this.backgroundColor >> 16) & 0xFF;
	int g = (this.backgroundColor >> 8) & 0xFF;
	int b = (this.backgroundColor >> 0) & 0xFF;
	r = (r - 30 < 0) ? 0 : r - 30;
	g = (g - 30 < 0) ? 0 : g - 30;
	b = (b - 30 < 0) ? 0 : b - 30;
	return Color.argb(70, r, g, b);
}
 
Example 10
Source Project: Noyze   File: ColorPreference.java    License: Apache License 2.0 5 votes vote down vote up
protected void setValue(int color) {
    final int alpha = getAlpha();
    final int value;
    if (alpha == 255) {
        value = color;
    } else if (alpha == 0) {
        value = Color.TRANSPARENT;
    } else {
        value = Color.argb(getAlpha(), Color.red(color),
                Color.green(color), Color.blue(color));
    }
    mPreference.setValue(value);
}
 
Example 11
public int darker(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 12
Source Project: WCViewPager   File: SampleActivity.java    License: MIT License 5 votes vote down vote up
@Override
public Object instantiateItemObject(ViewGroup container, int position) {
    View view = View.inflate(container.getContext(), android.R.layout.test_list_item, null);
    ((TextView)view.findViewById(android.R.id.text1)).setText(strings.get(position));
    container.addView(view);

    // set Random background
    Random rnd = new Random();
    int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
    view.setBackgroundColor(color);

    return view;
}
 
Example 13
Source Project: Snake   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
public static int changeAlpha(@ColorInt int color,int alpha) {
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);

    return Color.argb(alpha,red,green,blue);
}
 
Example 14
Source Project: ReadMark   File: WaveLoadingView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *
 * 为后面的wave设置透明度
 * @param waveColor
 * @param factor
 * @return
 */
private int setBackWaveColor(int waveColor, float factor){
    int alpha = Math.round(Color.alpha(waveColor) * factor);
    int red = Color.red(waveColor);
    int green = Color.green(waveColor);
    int blue = Color.blue(waveColor);
    return Color.argb(alpha, red, green, blue);
}
 
Example 15
Source Project: DMusic   File: ViewHelper.java    License: Apache License 2.0 4 votes vote down vote up
public static ColorFilter setImageViewTintColor(ImageView imageView, @ColorInt int tintColor) {
    LightingColorFilter colorFilter = new LightingColorFilter(Color.argb(255, 0, 0, 0), tintColor);
    imageView.setColorFilter(colorFilter);
    return colorFilter;
}
 
Example 16
Source Project: Painter   File: RandomColorAdapter.java    License: MIT License 4 votes vote down vote up
@Override
public Integer getItem(int position) {
    return Color.argb(255, mRandom.nextInt(256), mRandom.nextInt(256), mRandom.nextInt(256));
}
 
Example 17
Source Project: XFrame   File: XBitmapUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 模糊效果处理
 * @return 模糊效果处理后的图片
 */
public Bitmap blur(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);

    int pixColor = 0;

    int newR = 0;
    int newG = 0;
    int newB = 0;

    int newColor = 0;

    int[][] colors = new int[9][3];
    for (int i = 1, length = width - 1; i < length; i++) {
        for (int k = 1, len = height - 1; k < len; k++) {
            for (int m = 0; m < 9; m++) {
                int s = 0;
                int p = 0;
                switch (m) {
                    case 0:
                        s = i - 1;
                        p = k - 1;
                        break;
                    case 1:
                        s = i;
                        p = k - 1;
                        break;
                    case 2:
                        s = i + 1;
                        p = k - 1;
                        break;
                    case 3:
                        s = i + 1;
                        p = k;
                        break;
                    case 4:
                        s = i + 1;
                        p = k + 1;
                        break;
                    case 5:
                        s = i;
                        p = k + 1;
                        break;
                    case 6:
                        s = i - 1;
                        p = k + 1;
                        break;
                    case 7:
                        s = i - 1;
                        p = k;
                        break;
                    case 8:
                        s = i;
                        p = k;
                }
                pixColor = bitmap.getPixel(s, p);
                colors[m][0] = Color.red(pixColor);
                colors[m][1] = Color.green(pixColor);
                colors[m][2] = Color.blue(pixColor);
            }

            for (int m = 0; m < 9; m++) {
                newR += colors[m][0];
                newG += colors[m][1];
                newB += colors[m][2];
            }

            newR = (int) (newR / 9F);
            newG = (int) (newG / 9F);
            newB = (int) (newB / 9F);

            newR = Math.min(255, Math.max(0, newR));
            newG = Math.min(255, Math.max(0, newG));
            newB = Math.min(255, Math.max(0, newB));

            newColor = Color.argb(255, newR, newG, newB);
            newBitmap.setPixel(i, k, newColor);

            newR = 0;
            newG = 0;
            newB = 0;
        }
    }
    return newBitmap;
}
 
Example 18
Source Project: droidddle   File: SlidingTabStrip.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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 19
/**
 * @return color with alpha value
 */
public int getColorWithAlpha() {
    return Color.argb(mAlpha, mRed, mGreen, mBlue);
}
 
Example 20
Source Project: Noyze   File: ColorHelper.java    License: Apache License 2.0 4 votes vote down vote up
public static int noAlpha(final int color) {
    return Color.argb(255, Color.red(color), Color.green(color), Color.blue(color));
}