android.graphics.LinearGradient Java Examples

The following examples show how to use android.graphics.LinearGradient. 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: SVBar.java    From PhotoEdit with Apache License 2.0 6 votes vote down vote up
/**
 * Set the bar color. <br>
 * <br>
 * Its discouraged to use this method.
 *
 * @param color
 */
public void setColor(int color) {
    int x1, y1;
    if(mOrientation) {
        x1 = (mBarLength + mBarPointerHaloRadius);
        y1 = mBarThickness;
    }        else {
        x1 = mBarThickness;
        y1 = (mBarLength + mBarPointerHaloRadius);
    }

    Color.colorToHSV(color, mHSVColor);
    shader = new LinearGradient(mBarPointerHaloRadius, 0,
            x1, y1, new int[] {Color.WHITE, color, Color.BLACK}, null,
            Shader.TileMode.CLAMP);
    mBarPaint.setShader(shader);
    calculateColor(mBarPointerPosition);
    mBarPointerPaint.setColor(mColor);
    if (mPicker != null) {
        mPicker.setNewCenterColor(mColor);
        if(mPicker.hasOpacityBar())
            mPicker.changeOpacityBarColor(mColor);
    }
    invalidate();
}
 
Example #2
Source File: GradientLine.java    From WidgetCase with Apache License 2.0 6 votes vote down vote up
private void downLgMoreCofig(Canvas canvas){
    // 设置渐变曲线配置
    float y0 = control1.y;
    LinearGradient lg = new LinearGradient(mRadius * 2, y0, mView_W / 2, control2.y + DensityUtil.dp2px(2),
            Color.rgb(88, 181, 250), Color.rgb(101, 226, 175), Shader.TileMode.CLAMP);
    mPaint.setShader(lg);

    // 画虚线
    canvas.drawLine(mRadius + mPointPaint.getStrokeWidth(), mRadius * 2 + mPointPaint.getStrokeWidth(),
            mRadius + mPointPaint.getStrokeWidth(), mView_H - mRadius * 2 - mPointPaint.getStrokeWidth(), mImaPaint);

    // 画圆点
    mPointPaint.setShader(lg);
    canvas.drawCircle(mRadius + mPointPaint.getStrokeWidth(), control1.y, mRadius, mPointPaint);
    canvas.drawCircle(mView_W - mRadius - mPointPaint.getStrokeWidth(), control2.y, mRadius, mPointPaint);
}
 
Example #3
Source File: TimeLineDrawing.java    From InteractiveChart with Apache License 2.0 6 votes vote down vote up
@Override public void onInit(CandleRender render, AbsChartModule chartModule) {
  super.onInit(render, chartModule);
  attribute = render.getAttribute();

  borderPaint.setStyle(Paint.Style.STROKE);
  borderPaint.setStrokeWidth(attribute.borderWidth);
  borderPaint.setColor(attribute.borderColor);

  timelinePaint.setStrokeWidth(attribute.timeLineWidth);
  timelinePaint.setColor(attribute.timeLineColor);
  timelinePaint.setStyle(Paint.Style.STROKE);

  timeShaderPaint.setShader(
      new LinearGradient(0, viewRect.top, 0, viewRect.bottom,
          new int[] { attribute.timeLineShaderColorBegin, attribute.timeLineShaderColorEnd },
          null, Shader.TileMode.REPEAT));

  space = (attribute.candleSpace / attribute.candleWidth) / 2;
}
 
Example #4
Source File: HueBackgroundView.java    From thunderboard-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    float width = getWidth();
    float height = getHeight();

    if (isEnabled()) {
        LinearGradient grad = new LinearGradient(height / 2, 0.0f,
                width - height / 2, 0.0f,
                spectrumColors, null, Shader.TileMode.CLAMP);
        brush.setShader(grad);
        canvas.drawRect(height / 2, (height - lineHeight) / 2,
                width - height / 2, (height + lineHeight) / 2,
                brush);
    }

}
 
Example #5
Source File: VolumeView.java    From zone-sdk with MIT License 6 votes vote down vote up
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    mWidth = getWidth();
    mRectHeight = getHeight();
    mRectWidth = (int) (mWidth * 0.6 / mRectCount);
    mLinearGradient = new LinearGradient(
            0,
            0,
            mRectWidth,
            mRectHeight,
            Color.YELLOW,
            Color.BLUE,
            Shader.TileMode.CLAMP);
    mPaint.setShader(mLinearGradient);
}
 
Example #6
Source File: ValueBar.java    From PhotoEdit with Apache License 2.0 6 votes vote down vote up
/**
 * Set the bar color. <br>
 * <br>
 * Its discouraged to use this method.
 *
 * @param color
 */
public void setColor(int color) {
    int x1, y1;
    if(mOrientation == ORIENTATION_HORIZONTAL) {
        x1 = (mBarLength + mBarPointerHaloRadius);
        y1 = mBarThickness;
    }
    else {
        x1 = mBarThickness;
        y1 = (mBarLength + mBarPointerHaloRadius);
    }

    Color.colorToHSV(color, mHSVColor);
    shader = new LinearGradient(mBarPointerHaloRadius, 0,
            x1, y1, new int[] {
            color, Color.BLACK }, null, Shader.TileMode.CLAMP);
    mBarPaint.setShader(shader);
    calculateColor(mBarPointerPosition);
    mBarPointerPaint.setColor(mColor);
    if (mPicker != null) {
        mPicker.setNewCenterColor(mColor);
        if(mPicker.hasOpacityBar())
            mPicker.changeOpacityBarColor(mColor);
    }
    invalidate();
}
 
Example #7
Source File: ImageUtils.java    From ViewPager with Apache License 2.0 6 votes vote down vote up
public static Bitmap getReverseBitmapById(Context context, int resId, float percent) {
    // get the source bitmap
    Bitmap srcBitmap=BitmapFactory.decodeResource(context.getResources(), resId);
    // get the tow third segment of the reverse bitmap
    Matrix matrix=new Matrix();
    matrix.setScale(1, -1);
    Bitmap rvsBitmap=Bitmap.createBitmap(srcBitmap, 0, (int) (srcBitmap.getHeight()*(1-percent)),
            srcBitmap.getWidth(), (int) (srcBitmap.getHeight()*percent), matrix, false);
    // combine the source bitmap and the reverse bitmap
    Bitmap comBitmap=Bitmap.createBitmap(srcBitmap.getWidth(),
            srcBitmap.getHeight()+rvsBitmap.getHeight()+20, srcBitmap.getConfig());
    Canvas gCanvas=new Canvas(comBitmap);
    gCanvas.drawBitmap(srcBitmap, 0, 0, null);
    gCanvas.drawBitmap(rvsBitmap, 0, srcBitmap.getHeight()+20, null);
    Paint paint=new Paint();
    LinearGradient shader=new LinearGradient(0, srcBitmap.getHeight()+20, 0, comBitmap.getHeight(),
            Color.BLACK, Color.TRANSPARENT, Shader.TileMode.CLAMP);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    gCanvas.drawRect(0, srcBitmap.getHeight()+20, srcBitmap.getWidth(), comBitmap.getHeight(), paint);
    return comBitmap;
}
 
Example #8
Source File: SyncPlayFragment.java    From Musync with MIT License 6 votes vote down vote up
public Bitmap addGradient(Bitmap originalBitmap){

        int width = originalBitmap.getWidth();
        int height = originalBitmap.getHeight();
        Bitmap updatedBitmap = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(updatedBitmap);
        canvas.drawBitmap(originalBitmap,0,0,null);
        Paint paint = new Paint();
        LinearGradient shader = new LinearGradient(0,0,0,height,getResources().getColor(R.color.colorAccent),getResources().getColor(R.color.colorAccent1), Shader.TileMode.CLAMP);
        paint.setShader(shader);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawRect(0,0,width,height,paint);

        return updatedBitmap;

    }
 
Example #9
Source File: ScanWindowView.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
/**
 * 绘制扫描线
 */
private void drawLaserScanner(Canvas canvas) {
    paint.setColor(lineColor);
    //线性渐变
    LinearGradient linearGradient = new LinearGradient(
            0, scannerStart,
            0, scannerStart + SCANNER_LINE_HEIGHT,
            shadeColor(lineColor),
            lineColor,
            Shader.TileMode.MIRROR);

    paint.setShader(linearGradient);
    if (scannerStart <= scannerEnd) {
        //椭圆
        RectF rectF = new RectF(2 * SCANNER_LINE_HEIGHT, scannerStart, width - 2 * SCANNER_LINE_HEIGHT, scannerStart + SCANNER_LINE_HEIGHT);
        canvas.drawOval(rectF, paint);
        scannerStart += SCANNER_LINE_MOVE_DISTANCE;
    } else {
        scannerStart = 0;
    }
    paint.setShader(null);
}
 
Example #10
Source File: ReflectionActivity.java    From AndroidDemo with Apache License 2.0 6 votes vote down vote up
private Bitmap createReflection(Bitmap original, float percentage, int gap) {

		final int reflectionHeight = (int) (original.getHeight() * percentage);
		Bitmap bitmapWithReflection = Bitmap.createBitmap(original.getWidth(), (original.getHeight() + reflectionHeight + gap), Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(bitmapWithReflection);

		// original image
		canvas.drawBitmap(original, 0, 0, null);
		// gap drawing
		final Paint transparentPaint = new Paint();
		transparentPaint.setARGB(0, 255, 255, 255);
		canvas.drawRect(0, original.getHeight(), original.getWidth(), original.getHeight() + gap, transparentPaint);
		// reflection
		final Matrix matrix = new Matrix();
		matrix.preScale(1, -1);
		canvas.drawBitmap(Bitmap.createBitmap(original, 0, original.getHeight() - reflectionHeight, original.getWidth(), reflectionHeight, matrix, false), 0, original.getHeight() + gap, null);
		// reflection shading
		final Paint fadePaint = new Paint();
		fadePaint.setShader(new LinearGradient(0, original.getHeight(), 0, original.getHeight() + reflectionHeight + gap, 0x70ffffff, 0x00ffffff, Shader.TileMode.CLAMP));
		fadePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
		canvas.drawRect(0, original.getHeight(), original.getWidth(), bitmapWithReflection.getHeight() + gap, fadePaint);

		original.recycle();
		return bitmapWithReflection;
	}
 
Example #11
Source File: Ariana.java    From Ariana with Apache License 2.0 6 votes vote down vote up
public static Drawable drawable(final int[] colorBoxes, final float[] position, final GradientAngle gradientAngle) {
    ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            AngleCoordinate ac = AngleCoordinate.getAngleCoordinate(gradientAngle, width, height);
            LinearGradient linearGradient = new LinearGradient(ac.x1, ac.y1, ac.x2, ac.y2,
                    colorBoxes,
                    position,
                    Shader.TileMode.REPEAT);
            return linearGradient;
        }
    };
    PaintDrawable paint = new PaintDrawable();
    paint.setShape(new RectShape());
    paint.setShaderFactory(shaderFactory);
    return paint;
}
 
Example #12
Source File: SplashScreen.java    From Musync with MIT License 6 votes vote down vote up
public Bitmap addGradient(Bitmap originalBitmap){

        int width = originalBitmap.getWidth();
        int height = originalBitmap.getHeight();
        Bitmap updatedBitmap = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(updatedBitmap);
        canvas.drawBitmap(originalBitmap,0,0,null);
        Paint paint = new Paint();
        LinearGradient shader = new LinearGradient(0,0,0,height,getResources().getColor(R.color.colorAccent),getResources().getColor(R.color.colorAccent1), Shader.TileMode.CLAMP);
        paint.setShader(shader);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawRect(0,0,width,height,paint);

        return updatedBitmap;

    }
 
Example #13
Source File: OpacityBar.java    From memoir with Apache License 2.0 6 votes vote down vote up
/**
 * Set the bar color. <br>
 * <br>
 * Its discouraged to use this method.
 *
 * @param color
 */
public void setColor(int color) {
    int x1, y1;
    if (mOrientation == ORIENTATION_HORIZONTAL) {
        x1 = (mBarLength + mBarPointerHaloRadius);
        y1 = mBarThickness;
    } else {
        x1 = mBarThickness;
        y1 = (mBarLength + mBarPointerHaloRadius);
    }

    Color.colorToHSV(color, mHSVColor);
    shader = new LinearGradient(mBarPointerHaloRadius, 0,
            x1, y1, new int[]{
            Color.HSVToColor(0x00, mHSVColor), color}, null,
            Shader.TileMode.CLAMP);
    mBarPaint.setShader(shader);
    calculateColor(mBarPointerPosition);
    mBarPointerPaint.setColor(mColor);
    if (mPicker != null) {
        mPicker.setNewCenterColor(mColor);
    }
    invalidate();
}
 
Example #14
Source File: SVBar.java    From HoloColorPicker with Apache License 2.0 6 votes vote down vote up
/**
 * Set the bar color. <br>
 * <br>
 * Its discouraged to use this method.
 * 
 * @param color
 */
public void setColor(int color) {
	int x1, y1;
	if(mOrientation) {
		x1 = (mBarLength + mBarPointerHaloRadius);
		y1 = mBarThickness;
	}        else {
		x1 = mBarThickness;
		y1 = (mBarLength + mBarPointerHaloRadius);
	}
	
	Color.colorToHSV(color, mHSVColor);
	shader = new LinearGradient(mBarPointerHaloRadius, 0,
			x1, y1, new int[] {Color.WHITE, color, Color.BLACK}, null,
			Shader.TileMode.CLAMP);
	mBarPaint.setShader(shader);
    calculateColor(mBarPointerPosition);
	mBarPointerPaint.setColor(mColor);
	if (mPicker != null) {
		mPicker.setNewCenterColor(mColor);
		if(mPicker.hasOpacityBar())
			mPicker.changeOpacityBarColor(mColor);
	}
	invalidate();
}
 
Example #15
Source File: HueDrawable.java    From spline with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    Rect b = getBounds();

    Paint huePaint = new Paint();
    huePaint.setShader(new LinearGradient(0, 0, b.width(), 0,
            new int[]{
                    0xFFFF0000,
                    0xFFFFFF00,
                    0xFF00FF00,
                    0xFF00FFFF,
                    0xFF0000FF,
                    0xFFFF00FF,
                    0xFFFF0000
            },
            null,
            Shader.TileMode.REPEAT)
    );
    canvas.drawRect(b, huePaint);
}
 
Example #16
Source File: ArcProgress.java    From GeometricWeather with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void ensureShadowShader() {
    shaderColors[0] = shaderColor;
    shaderColors[1] = Color.TRANSPARENT;

    if (shaderWrapper.isDifferent(
            getMeasuredWidth(), getMeasuredHeight(), false, shaderColors)) {
        shaderWrapper.setShader(
                new LinearGradient(
                        0, rectF.top,
                        0, rectF.bottom,
                        shaderColors[0], shaderColors[1],
                        Shader.TileMode.CLAMP
                ),
                getMeasuredWidth(), getMeasuredHeight(),
                false,
                shaderColors
        );
    }
}
 
Example #17
Source File: BarWavesView.java    From Musicoco with Apache License 2.0 6 votes vote down vote up
private void drawWaves(Canvas canvas) {

        for (int i = 0; i < mWaveNumber; i++) {
            float left = mWaveWidth * i + mWaveInterval * i;
            float right = left + mWaveWidth;

            float bottom = getHeight() - mBarHeight;
            float fs = mWaveHeight[i];
            float top;
            top = bottom - mWaveMinHeight - (fs * mWaveRange);
            LinearGradient lg = new LinearGradient(
                    left, bottom,
                    right, top,
                    mWaveColors[i],
                    null,
                    Shader.TileMode.CLAMP
            );
            mPaint.setAlpha(255);
            mPaint.setShader(lg);
            canvas.drawRoundRect(left, top, right, bottom + 2, 20, 20, mPaint);
        }

    }
 
Example #18
Source File: ColorPicker.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private Bitmap createColorWheelBitmap(int width, int height) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    LinearGradient gradientShader = new LinearGradient(0, 0, width, 0, new int[]{Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN, Color.BLUE, Color.MAGENTA, Color.RED}, null, Shader.TileMode.CLAMP);
    LinearGradient alphaShader = new LinearGradient(0, (height / 3), 0, height, new int[]{Color.WHITE, Color.TRANSPARENT}, null, Shader.TileMode.CLAMP);
    ComposeShader composeShader = new ComposeShader(alphaShader, gradientShader, PorterDuff.Mode.MULTIPLY);

    colorWheelPaint.setShader(composeShader);

    Canvas canvas = new Canvas(bitmap);
    canvas.drawRect(0, 0, width, height, colorWheelPaint);

    return bitmap;
}
 
Example #19
Source File: Config.java    From Oblique with Apache License 2.0 5 votes vote down vote up
public Shader getLinearGradient(GradientAngle gradientAngle, float width, float height) {
    float x1 = 0, x2 = 0, y1 = 0, y2 = 0;
    switch (gradientAngle) {
        case LEFT_TO_RIGHT:
            x2 = width;
            break;
        case RIGHT_TO_LEFT:
            x1 = width;
            break;
        case TOP_TO_BOTTOM:
            y2 = height;
            break;
        case BOTTOM_TO_TOP:
            y1 = height;
            break;
        case LEFT_TOP_TO_RIGHT_BOTTOM:
            x2 = width;
            y2 = height;
            break;
        case RIGHT_BOTTOM_TO_LEFT_TOP:
            x1 = width;
            y1 = height;
            break;
        case LEFT_BOTTOM_TO_RIGHT_TOP:
            x2 = width;
            y1 = height;
            break;
        case RIGHT_TOP_TO_LEFT_BOTTOM:
            x1 = width;
            y2 = height;
            break;
    }
    return new LinearGradient(x1, y1, x2, y2, startColor, endColor, Shader.TileMode.CLAMP);
}
 
Example #20
Source File: ImageLoader.java    From Audinaut with GNU General Public License v3.0 5 votes vote down vote up
private Bitmap createUnknownImage(int size, int primaryColor, String topText, String bottomText) {
    Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Paint color = new Paint();
    color.setColor(primaryColor);
    canvas.drawRect(0, 0, size, size * 2.0f / 3.0f, color);

    color.setShader(new LinearGradient(0, 0, 0, size / 3.0f, Color.rgb(82, 82, 82), Color.BLACK, Shader.TileMode.MIRROR));
    canvas.drawRect(0, size * 2.0f / 3.0f, size, size, color);

    if (topText != null || bottomText != null) {
        Paint font = new Paint();
        font.setFlags(Paint.ANTI_ALIAS_FLAG);
        font.setColor(Color.WHITE);
        font.setTextSize(3.0f + size * 0.07f);

        if (topText != null) {
            canvas.drawText(topText, size * 0.05f, size * 0.6f, font);
        }

        if (bottomText != null) {
            canvas.drawText(bottomText, size * 0.05f, size * 0.8f, font);
        }
    }

    return bitmap;
}
 
Example #21
Source File: ReflectionImageProcessor.java    From sketch with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public Bitmap onProcess(@NonNull Sketch sketch, @NonNull Bitmap bitmap, @Nullable Resize resize, boolean lowQualityImage) {
    if (bitmap.isRecycled()) {
        return bitmap;
    }

    int srcHeight = bitmap.getHeight();
    int reflectionHeight = (int) (srcHeight * reflectionScale);
    int reflectionTop = srcHeight + reflectionSpacing;

    Bitmap.Config config = lowQualityImage ? Bitmap.Config.ARGB_4444 : Bitmap.Config.ARGB_8888;
    BitmapPool bitmapPool = sketch.getConfiguration().getBitmapPool();

    Bitmap reflectionBitmap = bitmapPool.getOrMake(bitmap.getWidth(), reflectionTop + reflectionHeight, config);

    // 在上半部分绘制原图
    Canvas canvas = new Canvas(reflectionBitmap);
    canvas.drawBitmap(bitmap, 0, 0, null);

    // 在下半部分绘制倒影
    Matrix matrix = new Matrix();
    matrix.postScale(1, -1);
    matrix.postTranslate(0, srcHeight + reflectionTop);
    canvas.drawBitmap(bitmap, matrix, null);

    // 在倒影部分绘制半透明遮罩,让倒影部分产生半透明渐变的效果
    Paint paint = new Paint();
    paint.setShader(new LinearGradient(0, reflectionTop, 0, reflectionBitmap.getHeight(), 0x70ffffff, 0x00ffffff, TileMode.CLAMP));
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    canvas.drawRect(0, reflectionTop, reflectionBitmap.getWidth(), reflectionBitmap.getHeight(), paint);

    return reflectionBitmap;
}
 
Example #22
Source File: SectionProBar.java    From WidgetCase with Apache License 2.0 5 votes vote down vote up
/**
 * 绘制进度条背景
 *
 * @param canvas
 * @param reachedEndX
 */
private void drawProgressBg(Canvas canvas, float reachedEndX) {
    mBgPaint.setStrokeWidth(mUnReachedHeight);
    if (mBgGradientColor == null) { // 默认
        mBgPaint.setColor(mUnReachedColor);
        canvas.drawLine(0, 0, mMaxUnReachedEndX, 0, mBgPaint);
    } else { // 渐变
        mBgPaint.setShader(new LinearGradient(mMaxUnReachedEndX - reachedEndX, 0, mMaxUnReachedEndX, 0,
                mBgGradientColor.getStartColor(), mBgGradientColor.getEndColor(),
                Shader.TileMode.CLAMP));
        canvas.drawLine(0, 0, mMaxUnReachedEndX, 0, mBgPaint);
    }
}
 
Example #23
Source File: PictureProgressBar.java    From AlbumCameraRecorder with MIT License 5 votes vote down vote up
private void init() {
    //初始化画笔
    paintBackGround = new Paint();
    paintBackGround.setColor(backGroundColor);

    paintBar = new Paint();
    paintBar.setColor(barColor);

        //在PreDraw时获取View属性,因为在初始化的时候View还没进行Measure
        getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                getViewTreeObserver().removeOnPreDrawListener(this);
                if (barDrawableId != 0 && backgroundDrawableId != 0)
                try {
                    setBarDrawableId(barDrawableId);
                    setBarBackgroundDrawableId(backgroundDrawableId);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                //是否需要渐变器
                if (isGradient) {
                    if (barDrawable == null) {
                        linearGradient = new LinearGradient(0, progressHeight / 2, progressWidth, progressHeight / 2, gradientStartColor, gradientEndColor, Shader.TileMode.CLAMP);
                        paintBar.setShader(linearGradient);
                    }
                }
                return false;
            }
        });



}
 
Example #24
Source File: GradientLine.java    From WidgetCase with Apache License 2.0 5 votes vote down vote up
private void upLgMoreConfig(Canvas canvas){
    LinearGradient lg = new LinearGradient(mRadius * 2, control1.y, mView_W / 2, control2.y + DensityUtil.dp2px(2),
            Color.rgb(255, 196, 0), Color.rgb(255, 105, 83), Shader.TileMode.CLAMP);
    mPaint.setShader(lg);

    // 画虚线
    canvas.drawLine(mView_W - mRadius - mPointPaint.getStrokeWidth(), mRadius * 2 + mPointPaint.getStrokeWidth(),
            mView_W - mRadius - mPointPaint.getStrokeWidth(), mView_H - mRadius * 2 - mPointPaint.getStrokeWidth(), mImaPaint);

    // 画圆点
    mPointPaint.setShader(lg);
    canvas.drawCircle(mRadius + mPointPaint.getStrokeWidth(), mView_H - mRadius - mPointPaint.getStrokeWidth(), mRadius, mPointPaint);
    canvas.drawCircle(mView_W - mRadius - mPointPaint.getStrokeWidth(), control2.y + DensityUtil.dp2px(2), mRadius, mPointPaint);
}
 
Example #25
Source File: ImageUtils.java    From wakao-app with MIT License 5 votes vote down vote up
/**
 * 获得带倒影的图片方法
 * 
 * @param bitmap
 * @return
 */
public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) {
	final int reflectionGap = 4;
	int width = bitmap.getWidth();
	int height = bitmap.getHeight();

	Matrix matrix = new Matrix();
	matrix.preScale(1, -1);

	Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2,
			width, height / 2, matrix, false);

	Bitmap bitmapWithReflection = Bitmap.createBitmap(width,
			(height + height / 2), Config.ARGB_8888);

	Canvas canvas = new Canvas(bitmapWithReflection);
	canvas.drawBitmap(bitmap, 0, 0, null);
	Paint deafalutPaint = new Paint();
	canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);

	canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);

	Paint paint = new Paint();
	LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
			bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff,
			0x00ffffff, TileMode.CLAMP);
	paint.setShader(shader);
	// Set the Transfer mode to be porter duff and destination in
	paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
	// Draw a rectangle using the paint with our linear gradient
	canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
			+ reflectionGap, paint);

	return bitmapWithReflection;
}
 
Example #26
Source File: ChevronRegionView.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
private void updatePath()
{
	float radius = getWidth() / 20;
	float arrowHeight = getHeight() / 4;

	Rect rect = new Rect(2, 2, this.getWidth() - 4, this.getHeight() - 4);

	mPath = new Path();
	mPath.moveTo(rect.left + radius, rect.top);
	mPath.lineTo(rect.right, rect.top);
	mPath.lineTo(rect.right, rect.bottom - arrowHeight);
	mPath.lineTo(rect.exactCenterX(), rect.bottom);
	mPath.lineTo(rect.left, rect.bottom - arrowHeight);
	mPath.lineTo(rect.left, rect.top);
	mPath.close();

	int color = this.getContext().getResources().getColor(R.color.tag_unselected_outline);
	if (mIsActive)
		color = this.getContext().getResources().getColor(R.color.tag_selected_outline);

	mPaint = new Paint();
	mPaint.setAntiAlias(true);
	mPaint.setColor(color);
	mPaint.setStyle(Paint.Style.FILL);
	mPaint.setStrokeWidth(0);
	mPaint.setStrokeJoin(Paint.Join.ROUND); // set the join to round you
											// want
	mPaint.setStrokeCap(Paint.Cap.ROUND); // set the paint cap to round too
	mPaint.setPathEffect(new CornerPathEffect(radius)); // set the path
														// effect when they

	color = this.getContext().getResources().getColor(R.color.tag_unselected);
	if (mIsActive)
		color = this.getContext().getResources().getColor(R.color.tag_selected);
	mShader = new LinearGradient(0, 0, 0, getHeight(), color, color, Shader.TileMode.CLAMP);
}
 
Example #27
Source File: CoverMaskImageView.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void setPaintStyle() {
    double deltaX;
    double deltaY;
    if (gradientAngle == 90 || gradientAngle == 270) {
        deltaX = 0;
    } else {
        deltaX = 0.5 * getMeasuredHeight() / Math.tan(gradientAngle * Math.PI / 180.0);
        deltaX = Math.min(deltaX, getMeasuredWidth() * 0.5);
        deltaX = Math.max(deltaX, getMeasuredWidth() * -0.5);
    }
    if (gradientAngle == 90) {
        deltaY = 0.5 * getMeasuredHeight();
    } else if (gradientAngle == 270) {
        deltaY = -0.5 * getMeasuredHeight();
    } else {
        deltaY = 0.5 * getMeasuredWidth() * Math.tan(gradientAngle * Math.PI / 180.0);
        deltaY = Math.min(deltaY, getMeasuredHeight() * 0.5);
        deltaY = Math.max(deltaY, getMeasuredHeight() * -0.5);
    }

    double cX = getMeasuredWidth() * 0.5;
    double cY = getMeasuredHeight() * 0.5;
    paint.setShader(
            new LinearGradient(
                (float) (cX + deltaX), (float) (cY - deltaY),
                (float) (cX - deltaX), (float) (cY + deltaY),
                new int[]{
                        ColorUtils.setAlphaComponent(maskColor, (int) (255 * toAlpha)),
                        ColorUtils.setAlphaComponent(maskColor, (int) (255 * fromAlpha))
                },
                null,
                Shader.TileMode.CLAMP
            )
    );
}
 
Example #28
Source File: OBGradientLayer.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
public void draw(Canvas canvas)
{
    Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
    PointF ps = OB_Maths.locationForRect(startx,starty,bounds());
    PointF pe = OB_Maths.locationForRect(endx,endy,bounds());
    LinearGradient lg = new LinearGradient(ps.x,ps.y,pe.x,pe.y,colours,locations, Shader.TileMode.CLAMP);
    p.setShader(lg);
    canvas.drawRect(bounds(),p);
}
 
Example #29
Source File: VerticalSlideColorPicker.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  super.onSizeChanged(w, h, oldw, oldh);

  viewWidth  = w;
  viewHeight = h;

  if (viewWidth <= 0 || viewHeight <= 0) return;

  int barWidth = (int) (viewWidth * INDICATOR_TO_BAR_WIDTH_RATIO);

  centerX           = viewWidth / 2;
  indicatorRadius   = (viewWidth / 2) - borderWidth;
  colorPickerRadius = (barWidth / 2) - borderWidth;

  colorPickerBody   = new RectF(centerX - colorPickerRadius,
                                borderWidth + colorPickerRadius + indicatorRadius,
                                centerX + colorPickerRadius,
                                viewHeight - (borderWidth + colorPickerRadius + indicatorRadius));

  LinearGradient gradient = new LinearGradient(0, colorPickerBody.top, 0, colorPickerBody.bottom, colors, null, Shader.TileMode.CLAMP);
  paint.setShader(gradient);

  if (bitmap != null) {
    bitmap.recycle();
  }

  bitmap       = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888);
  bitmapCanvas = new Canvas(bitmap);
}
 
Example #30
Source File: BitmapUtils.java    From XKnife-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Get reflection image from bitmap
 *
 * @param bitmap
 * @return
 */
public static Bitmap getReflectionImageWithBitmap(Bitmap bitmap) {
    if (bitmap != null) {
        final int reflectionGap = 4;
        int w = bitmap.getWidth();
        int h = bitmap.getHeight();
        Matrix matrix = new Matrix();
        matrix.preScale(1, -1);
        Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, h / 2, w,
                h / 2, matrix, false);

        Bitmap bitmapWithReflection = Bitmap.createBitmap(w, (h + h / 2),
                Bitmap.Config.ARGB_8888);

        Canvas canvas = new Canvas(bitmapWithReflection);
        canvas.drawBitmap(bitmap, 0, 0, null);
        Paint deafalutPaint = new Paint();
        canvas.drawRect(0, h, w, h + reflectionGap, deafalutPaint);

        canvas.drawBitmap(reflectionImage, 0, h + reflectionGap, null);

        Paint paint = new Paint();
        LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
                bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff,
                0x00ffffff, Shader.TileMode.CLAMP);
        paint.setShader(shader);
        // Set the Transfer mode to be porter duff and destination in
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
        // Draw a rectangle using the paint with our linear gradient
        canvas.drawRect(0, h, w, bitmapWithReflection.getHeight()
                + reflectionGap, paint);
        return bitmapWithReflection;
    } else {
        return null;
    }
}