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

The following examples show how to use android.graphics.Color#rgb() . 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: SweepGradientRadarView.java    From AndroidDigIn with Apache License 2.0 6 votes vote down vote up
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    mCx = w / 2;
    mCy = h / 2;
    mSweepGradient = new SweepGradient(mCx, mCy,
            new int[]{Color.argb(25, 0, 255, 0),
                    Color.argb(80, 0, 255, 0),
                    Color.argb(200, 0, 255, 0)},
            new float[]{0, 0.95f, 1.0f});
    mPaint = new Paint();
    mPaint.setShader(mSweepGradient);
    mDividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCircleDividerColor = Color.BLACK;
    mCrossDividerColor = Color.WHITE;
    mRadarBgColor = Color.rgb(154, 154, 154);
    mDividerPaint.setColor(mCircleDividerColor);
    mDividerPaint.setStrokeWidth(3);
    mDividerPaint.setStyle(Paint.Style.STROKE);
}
 
Example 2
Source File: ColorPickerView.java    From YCCustomText with Apache License 2.0 6 votes vote down vote up
public int[] createDefaultColorTable() {

//        int[] cs = {
//                Color.rgb(0, 0, 0),//白色
//                Color.rgb(255, 0, 0),//红色
//                Color.rgb(0, 255, 0),//绿色
//                Color.rgb(0, 255, 255),//青色
//                Color.rgb(0, 0, 255),//蓝色
//                Color.rgb(255, 0, 255),//紫色
//                Color.rgb(255, 255, 255)//黑色
//        };
        int[] cs = {
                Color.rgb(0, 0, 0),
                Color.rgb(255, 0, 0),//红色
                Color.rgb(255, 255, 0),
                Color.rgb(0, 255, 0),//绿色
                Color.rgb(0, 255, 255),//青色
                Color.rgb(0, 0, 255),//蓝色
                Color.rgb(255, 0, 255),
                Color.rgb(255, 0, 0)//红色
        };
        return cs;
    }
 
Example 3
Source File: HailImplementor.java    From GeometricWeather with GNU Lesser General Public License v3.0 6 votes vote down vote up
@ColorInt
public static int getThemeColor(Context context, @TypeRule int type) {
    switch (type) {
        case TYPE_HAIL_DAY:
            return Color.rgb(80, 116, 193);

        case TYPE_HAIL_NIGHT:
            return Color.rgb(42, 52, 69);
    }
    return ContextCompat.getColor(context, R.color.colorPrimary);
}
 
Example 4
Source File: MainActivity.java    From AndroidDatabaseLibraryComparison with MIT License 6 votes vote down vote up
private int getFrameworkColor(String framework) {
    // using the 300 line colors from http://www.google.com/design/spec/style/color.html#color-color-palette
    switch (framework) {
        case DBFlowTester.FRAMEWORK_NAME:
            return Color.rgb(0xE5,0x73,0x73); // red
        case AATester.FRAMEWORK_NAME:
            return Color.rgb(0xF0, 0x62, 0x92); // pink
        case OllieTester.FRAMEWORK_NAME:
            return Color.rgb(0xFF, 0xA5, 0x00); // orange
        case GreenDaoTester.FRAMEWORK_NAME:
            return Color.rgb(0xBA, 0x68, 0xC8); // purple
        case OrmLiteTester.FRAMEWORK_NAME:
            return Color.rgb(0x4D, 0xB6, 0xAC); // teal
        case SprinklesTester.FRAMEWORK_NAME:
            return Color.rgb(0x79, 0x86, 0xCB); // indigo
        case SugarTester.FRAMEWORK_NAME:
            return Color.rgb(0x64, 0xB5, 0XF6); // blue
        case RealmTester.FRAMEWORK_NAME:
            return Color.rgb(0xAE, 0xD5, 0X81); // light green
        default:
            return Color.WHITE;
    }
}
 
Example 5
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 5 votes vote down vote up
private void addBoatTrip(GraphicsOverlay graphicOverlay) {
  //define a polyline for the boat trip
  Polyline boatRoute = getBoatTripGeometry();
  //define a line symbol
  SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.DASH, Color.rgb(128, 0, 128), 4);
  //create the graphic
  Graphic boatTripGraphic = new Graphic(boatRoute, lineSymbol);
  //add to the graphic overlay
  graphicOverlay.getGraphics().add(boatTripGraphic);
}
 
Example 6
Source File: BarrageSurfaceView.java    From NIM_Android_UIKit with MIT License 5 votes vote down vote up
private BarrageTextTask buildBarrageTextTask(String text, int line) {
    if (TextUtils.isEmpty(text)) {
        return null;
    }

    // text size, length
    int size = config.getMinTextSizeSp() + random.nextInt(config.getMaxTextSizeSp() - config.getMinTextSizeSp() + 1);
    size = ScreenUtil.sp2px(size);

    // text color
    int color;
    if (config.getColors() != null && !config.getColors().isEmpty()) {
        color = config.getColors().get(random.nextInt(config.getColors().size()));
    } else {
        color = Color.rgb(random.nextInt(256), random.nextInt(256), random.nextInt(256));
    }

    // duration
    int duration = config.getDuration() + random.nextInt() % 500;

    // start position
    float x = getWidth();
    float y = size + line * lineHeight;

    // speed
    float deltaX = (1.0f * getWidth() / duration) * TIME_INTERVAL;

    // log
    StringBuilder log = new StringBuilder();
    log.append("build text barrage task")
            .append(", line=").append(line)
            .append(", text=").append(text)
            .append(", speed=").append(deltaX);
    log(log.toString());

    return new BarrageTextTask(text, line, color, size, duration, x, y, deltaX);
}
 
Example 7
Source File: ProgressWebView.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
private int changeColor(int rgb) {
    int red = rgb >> 16 & 0xFF;
    int green = rgb >> 8 & 0xFF;
    int blue = rgb & 0xFF;
    red = (int) Math.floor(red * (1 - 0.2));
    green = (int) Math.floor(green * (1 - 0.2));
    blue = (int) Math.floor(blue * (1 - 0.2));
    return Color.rgb(red, green, blue);
}
 
Example 8
Source File: LoadToastView.java    From RxAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
private int fetchPrimaryColor() {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
        TypedValue typedValue = new TypedValue();

        TypedArray a = getContext().obtainStyledAttributes(typedValue.data, new int[] { android.R.attr.colorAccent });
        int color = a.getColor(0, 0);

        a.recycle();

        return color;
    }
    return Color.rgb(155, 155, 155);
}
 
Example 9
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 5 votes vote down vote up
private void overrideRenderer() {

    // create a new simple renderer for the line feature layer
    SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.rgb(0, 0, 255), 2);
    SimpleRenderer simpleRenderer = new SimpleRenderer(lineSymbol);

    // override the current renderer with the new renderer defined above
    mFeatureLayer.setRenderer(simpleRenderer);
  }
 
Example 10
Source File: SlidingTabStrip.java    From Trivia-Knowledge with Apache License 2.0 5 votes vote down vote up
/**
 * Blend {@code color1} and {@code color2} using the given ratio.
 *
 * @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend,
 *              0.0 will return {@code color2}.
 */
private static int blendColors(int color1, int color2, float ratio) {
    final float inverseRation = 1f - ratio;
    float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
    float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
    float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
    return Color.rgb((int) r, (int) g, (int) b);
}
 
Example 11
Source File: PayChart.java    From quickmark with MIT License 5 votes vote down vote up
private int getRandomColor() {// �ֱ����RBG��ֵ
	Random random = new Random();
	int R = random.nextInt(255);
	int G = random.nextInt(255);
	int B = random.nextInt(255);
	return Color.rgb(R, G, B);
}
 
Example 12
Source File: Blockies.java    From Lunary-Ethereum-Wallet with GNU General Public License v3.0 5 votes vote down vote up
private static int toRGB(float h, float s, float l) {
    h = h % 360.0f;
    h /= 360f;
    s /= 100f;
    l /= 100f;

    float q = 0;

    if (l < 0.5)
        q = l * (1 + s);
    else
        q = (l + s) - (s * l);

    float p = 2 * l - q;

    float r = Math.max(0, HueToRGB(p, q, h + (1.0f / 3.0f)));
    float g = Math.max(0, HueToRGB(p, q, h));
    float b = Math.max(0, HueToRGB(p, q, h - (1.0f / 3.0f)));

    r = Math.min(r, 1.0f);
    g = Math.min(g, 1.0f);
    b = Math.min(b, 1.0f);

    int red = (int) (r * 255);
    int green = (int) (g * 255);
    int blue = (int) (b * 255);
    return Color.rgb(red, green, blue);
}
 
Example 13
Source File: MainActivity.java    From PickerUI with Apache License 2.0 5 votes vote down vote up
private int getRandomColor() {
    // generate the random integers for r, g and b value
    Random rand = new Random();
    int r = rand.nextInt(255);
    int g = rand.nextInt(255);
    int b = rand.nextInt(255);
    return Color.rgb(r, g, b);
}
 
Example 14
Source File: WebPEncoder.java    From APNG4Android with Apache License 2.0 4 votes vote down vote up
private void loadGif(Loader loader) {
    try {
        GifReader reader = new GifReader(loader.obtain());
        List<Block> blocks = GifParser.parse(reader);
        ColorTable globalColorTable = null;
        List<GifFrame> frames = new ArrayList<>();
        GraphicControlExtension graphicControlExtension = null;
        int bgColorIndex = -1;
        for (Block block : blocks) {
            if (block instanceof LogicalScreenDescriptor) {
                width = ((LogicalScreenDescriptor) block).screenWidth;
                height = ((LogicalScreenDescriptor) block).screenHeight;
                if (((LogicalScreenDescriptor) block).gColorTableFlag()) {
                    bgColorIndex = ((LogicalScreenDescriptor) block).bgColorIndex & 0xff;
                }
            } else if (block instanceof ColorTable) {
                globalColorTable = (ColorTable) block;
            } else if (block instanceof GraphicControlExtension) {
                graphicControlExtension = (GraphicControlExtension) block;
            } else if (block instanceof ImageDescriptor) {
                GifFrame gifFrame = new GifFrame(reader, globalColorTable, graphicControlExtension, (ImageDescriptor) block);
                frames.add(gifFrame);
            } else if (block instanceof ApplicationExtension && "NETSCAPE2.0".equals(((ApplicationExtension) block).identifier)) {
                loopCount = ((ApplicationExtension) block).loopCount;
            }
        }
        if (globalColorTable != null && bgColorIndex > 0) {
            int abgr = globalColorTable.getColorTable()[bgColorIndex];
            this.bgColor = Color.rgb(abgr & 0xff, (abgr >> 8) & 0xff, (abgr >> 16) & 0xff);
        }
        GifWriter writer = new GifWriter();
        for (GifFrame frame : frames) {
            writer.reset(frame.frameWidth * frame.frameHeight);
            int[] pixels = writer.asIntArray();
            frame.encode(pixels, 1);
            Bitmap bitmap = Bitmap.createBitmap(frame.frameWidth, frame.frameHeight, Bitmap.Config.ARGB_8888);
            bitmap.copyPixelsFromBuffer(writer.asBuffer().rewind());
            FrameBuilder frameBuilder = new FrameBuilder();
            boolean disposal = false, blending = false;
            switch (frame.disposalMethod) {
                case 0:
                case 1:
                    disposal = false;
                    blending = true;
                    break;
                case 2:
                    disposal = true;
                    blending = true;
                    break;
                case 3:
                    disposal = true;
                    blending = true;
                    break;
            }
            frameBuilder
                    .bitmap(bitmap)
                    .duration(frame.frameDuration)
                    .offsetX(frame.frameX)
                    .offsetY(frame.frameY)
                    .disposal(disposal)
                    .blending(blending);
            frameInfoList.add(frameBuilder.build());
        }

    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 15
Source File: KeyButtonRipple.java    From GravityBox with Apache License 2.0 4 votes vote down vote up
public void setGlowColor(int color) {
    int rgb = Color.rgb(Color.red(color), Color.green(color), Color.blue(color));
    getRipplePaint().setColor(rgb);
    mGlowAlphaMax = Color.alpha(color) / 255f;
}
 
Example 16
Source File: FlatCheckBox.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    super.draw(canvas);


    float textTranslation = 0f;

    if (progress <= 0.5f) {
        float checkProgress = textTranslation = progress / 0.5f;
        int rD = (int) ((Color.red(colorInactive) - Color.red(colorActive)) * checkProgress);
        int gD = (int) ((Color.green(colorInactive) - Color.green(colorActive)) * checkProgress);
        int bD = (int) ((Color.blue(colorInactive) - Color.blue(colorActive)) * checkProgress);
        int c = Color.rgb(Color.red(colorActive) + rD, Color.green(colorActive) + gD, Color.blue(colorActive) + bD);

        fillPaint.setColor(c);

        rD = (int) ((Color.red(colorTextActive) - Color.red(colorInactive)) * checkProgress);
        gD = (int) ((Color.green(colorTextActive) - Color.green(colorInactive)) * checkProgress);
        bD = (int) ((Color.blue(colorTextActive) - Color.blue(colorInactive)) * checkProgress);
        c = Color.rgb(Color.red(colorInactive) + rD, Color.green(colorInactive) + gD, Color.blue(colorInactive) + bD);

        textPaint.setColor(c);
    } else {
        textTranslation = 1f;
        textPaint.setColor(colorTextActive);
        fillPaint.setColor(colorInactive);
    }


    int heightHalf = (getMeasuredHeight() >> 1);

    outLinePaint.setColor(colorInactive);
    canvas.drawRoundRect(rectF, HEIGHT / 2f, HEIGHT / 2f, fillPaint);
    canvas.drawRoundRect(rectF, HEIGHT / 2f, HEIGHT / 2f, outLinePaint);
    if (text != null) {
        canvas.drawText(text,
                (getMeasuredWidth() >> 1) + (textTranslation * TRANSLETE_TEXT),
                heightHalf + (textPaint.getTextSize() * 0.35f),
                textPaint
        );
    }

    float bounceProgress = 2.0f - progress / 0.5f;
    canvas.save();
    canvas.scale(0.9f, 0.9f, AndroidUtilities.dpf2(7f), heightHalf);
    canvas.translate(AndroidUtilities.dp(12), heightHalf - AndroidUtilities.dp(9));

    if (progress > 0.5f) {
        checkPaint.setColor(colorTextActive);
        int endX = (int) (AndroidUtilities.dpf2(7f) - AndroidUtilities.dp(4) * (1.0f - bounceProgress));
        int endY = (int) (AndroidUtilities.dpf2(13f) - AndroidUtilities.dp(4) * (1.0f - bounceProgress));
        canvas.drawLine(AndroidUtilities.dpf2(7f), (int) AndroidUtilities.dpf2(13f), endX, endY, checkPaint);
        endX = (int) (AndroidUtilities.dpf2(7f) + AndroidUtilities.dp(8) * (1.0f - bounceProgress));
        endY = (int) (AndroidUtilities.dpf2(13f) - AndroidUtilities.dp(8) * (1.0f - bounceProgress));
        canvas.drawLine((int) AndroidUtilities.dpf2(7f), (int) AndroidUtilities.dpf2(13f), endX, endY, checkPaint);
    }
    canvas.restore();


}
 
Example 17
Source File: ColorSelector.java    From meiShi with Apache License 2.0 4 votes vote down vote up
@Override
public void onValueChanged(int value) {
	color = Color.rgb(red.getValue(), green.getValue(), blue.getValue());
	colorView.setBackgroundColor(color);
}
 
Example 18
Source File: RadioButton.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    if (bitmap == null || bitmap.getWidth() != getMeasuredWidth()) {
        if (bitmap != null) {
            bitmap.recycle();
            bitmap = null;
        }
        try {
            bitmap = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config.ARGB_8888);
            bitmapCanvas = new Canvas(bitmap);
        } catch (Throwable e) {
            FileLog.e(e);
        }
    }
    float circleProgress;
    float innerRad;
    if (progress <= 0.5f) {
        paint.setColor(color);
        checkedPaint.setColor(color);
        circleProgress = progress / 0.5f;
    } else {
        circleProgress = 2.0f - progress / 0.5f;
        int r1 = Color.red(color);
        int rD = (int) ((Color.red(checkedColor) - r1) * (1.0f - circleProgress));
        int g1 = Color.green(color);
        int gD = (int) ((Color.green(checkedColor) - g1) * (1.0f - circleProgress));
        int b1 = Color.blue(color);
        int bD = (int) ((Color.blue(checkedColor) - b1) * (1.0f - circleProgress));
        int c = Color.rgb(r1 + rD, g1 + gD, b1 + bD);
        paint.setColor(c);
        checkedPaint.setColor(c);
    }
    if (bitmap != null) {
        bitmap.eraseColor(0);
        float rad = size / 2 - (1 + circleProgress) * AndroidUtilities.density;
        bitmapCanvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, rad, paint);
        if (progress <= 0.5f) {
            bitmapCanvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, (rad - AndroidUtilities.dp(1)), checkedPaint);
            bitmapCanvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, (rad - AndroidUtilities.dp(1)) * (1.0f - circleProgress), eraser);
        } else {
            bitmapCanvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, size / 4 + (rad - AndroidUtilities.dp(1) - size / 4) * circleProgress, checkedPaint);
        }

        canvas.drawBitmap(bitmap, 0, 0, null);
    }
}
 
Example 19
Source File: ColorsUtils.java    From mvvm-template with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Calculate the value for different color.
 *
 * @param baseColor
 *         Value of base color.
 * @param emptyColor
 *         Value of empty color
 * @param level
 *         Level.
 * @return The value for the level of the base color.
 */
public static int calculateLevelColor(int baseColor, int emptyColor, int level) {
    if (level == 0) {
        return emptyColor;
    }
    return Color.rgb(
            calculateR(Color.red(baseColor), level),
            calculateG(Color.green(baseColor), level),
            calculateB(Color.blue(baseColor), level));
}
 
Example 20
Source File: ColorUtils.java    From BigApp_Discuz_Android with Apache License 2.0 2 votes vote down vote up
public static int toColor(int r, int g, int b) {

        return Color.rgb(r, g, b);

    }