android.graphics.Shader.TileMode Java Examples

The following examples show how to use android.graphics.Shader.TileMode. 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: PXLinearGradient.java    From pixate-freestyle-android with Apache License 2.0 6 votes vote down vote up
private LinearGradient getGradient(PointF point1, PointF point2) {
    adjustGradientColors();
    int[] colors = new int[this.colors.size()];
    for (int i = 0; i < colors.length; i++) {
        colors[i] = this.colors.get(i);
    }
    float[] positions = null;
    if (!offsets.isEmpty()) {
        positions = new float[this.offsets.size()];
        for (int i = 0; i < positions.length; i++) {
            positions[i] = this.offsets.get(i);
        }
    }
    try {
        LinearGradient gradient = new LinearGradient(point1.x, point1.y, point2.x, point2.y,
                colors, positions, TileMode.CLAMP);
        return gradient;
    } catch (Exception e) {
        if (PXLog.isLogging()) {
            PXLog.e(TAG, e, "Error while instantiating a LinearGradient");
        }
        return null;
    }
}
 
Example #2
Source File: ObjectGraphicInProminentMode.java    From mlkit-material-android with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Canvas canvas) {
  RectF rect = overlay.translateRect(object.getBoundingBox());

  // Draws the dark background scrim and leaves the object area clear.
  canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint);
  canvas.drawRoundRect(rect, boxCornerRadius, boxCornerRadius, eraserPaint);

  // Draws the bounding box with a gradient border color at vertical.
  boxPaint.setShader(
      confirmationController.isConfirmed()
          ? null
          : new LinearGradient(
              rect.left,
              rect.top,
              rect.left,
              rect.bottom,
              boxGradientStartColor,
              boxGradientEndColor,
              TileMode.CLAMP));
  canvas.drawRoundRect(rect, boxCornerRadius, boxCornerRadius, boxPaint);
}
 
Example #3
Source File: AmbilWarnaKotak.java    From callmeter with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onDraw(final Canvas canvas) {
    super.onDraw(canvas);

    if (this.paint == null) {
        this.paint = new Paint();
        this.luar = new LinearGradient(0.f, 0.f, 0.f, this.ukuranUiPx, 0xffffffff, 0xff000000,
                TileMode.CLAMP);
    }

    this.tmp00[1] = this.tmp00[2] = 1.f;
    this.tmp00[0] = this.hue;
    int rgb = Color.HSVToColor(this.tmp00);

    this.dalam = new LinearGradient(0.f, 0.f, this.ukuranUiPx, 0.f, 0xffffffff, rgb,
            TileMode.CLAMP);
    ComposeShader shader = new ComposeShader(this.luar, this.dalam, PorterDuff.Mode.MULTIPLY);

    this.paint.setShader(shader);

    canvas.drawRect(0.f, 0.f, this.ukuranUiPx, this.ukuranUiPx, this.paint);
}
 
Example #4
Source File: ColorPicker.java    From SystemBarTint with Apache License 2.0 6 votes vote down vote up
private Bitmap createColorWheelBitmap(int width, int height) {

        Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[] { 0f, 1f, 1f };
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
 
Example #5
Source File: ColorPicker.java    From px-android with MIT License 6 votes vote down vote up
private Bitmap createColorWheelBitmap(int width, int height) {

        Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = { 0f, 1f, 1f };
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient =
            new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;
    }
 
Example #6
Source File: CircularRevealHelper.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
public void buildCircularRevealCache() {
  if (STRATEGY == BITMAP_SHADER) {
    buildingCircularRevealCache = true;
    hasCircularRevealCache = false;

    view.buildDrawingCache();
    Bitmap bitmap = view.getDrawingCache();

    if (bitmap == null && view.getWidth() != 0 && view.getHeight() != 0) {
      bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Config.ARGB_8888);
      Canvas canvas = new Canvas(bitmap);
      view.draw(canvas);
    }

    if (bitmap != null) {
      revealPaint.setShader(new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP));
    }

    buildingCircularRevealCache = false;
    hasCircularRevealCache = true;
  }
}
 
Example #7
Source File: MultiColorPicker.java    From Android-Color-Picker with Apache License 2.0 6 votes vote down vote up
private Bitmap createColorWheelBitmap(int width, int height) {

        Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[] { 0f, 1f, 1f };
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
 
Example #8
Source File: ReflectView.java    From TvLauncher with Apache License 2.0 6 votes vote down vote up
/**
 * Set the bitmap reflection
 *
 * @param bitmap
 * @return
 */
public static Bitmap createReflectedImage(Bitmap bitmap, int reflectHeight) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (height <= reflectHeight) {
        return null;
    }
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height
            - reflectHeight, width, reflectHeight, matrix, true);
    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, reflectHeight,
            Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(reflectionImage, 0, 0, null);
    LinearGradient shader = new LinearGradient(0, 0, 0,
            bitmapWithReflection.getHeight(), 0x80ffffff, 0x00ffffff,
            TileMode.CLAMP);
    Paint paint = new Paint();
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    canvas.drawRect(0, 0, width, bitmapWithReflection.getHeight(), paint);
    return bitmapWithReflection;
}
 
Example #9
Source File: RoundImageView.java    From umeng_community_android with MIT License 6 votes vote down vote up
/**
 * 初始化BitmapShader
 */
private void setUpShader() {
    Drawable drawable = getDrawable();
    Bitmap bmp = drawableToBitamp(drawable);
    if (drawable == null || bmp == null) {
        return;
    }

    // 将bmp作为着色器,就是在指定区域内绘制bmp
    mBitmapShader = new BitmapShader(bmp, TileMode.CLAMP, TileMode.CLAMP);
    float scale = 1.0f;
    // 拿到bitmap宽或高的小值
    int bSize = Math.min(bmp.getWidth(), bmp.getHeight());
    scale = mWidth * 1.0f / bSize;

    // shader的变换矩阵,我们这里主要用于放大或者缩小
    mMatrix.setScale(scale, scale);
    // 设置变换矩阵
    mBitmapShader.setLocalMatrix(mMatrix);
    // 设置shader
    mBitmapPaint.setShader(mBitmapShader);
}
 
Example #10
Source File: CircleImageView.java    From the-tech-frontier-app with MIT License 6 votes vote down vote up
/**
 * 初始化BitmapShader
 */
private void setUpShader() {
    Drawable drawable = getDrawable();
    if (drawable == null) {
        return;
    }

    Bitmap bmp = drawableToBitamp(drawable);
    // 将bmp作为着色器,就是在指定区域内绘制bmp
    mBitmapShader = new BitmapShader(bmp, TileMode.CLAMP, TileMode.CLAMP);
    float scale = 1.0f;
    // 拿到bitmap宽或高的小值
    int bSize = Math.min(bmp.getWidth(), bmp.getHeight());
    scale = mWidth * 1.0f / bSize;

    // shader的变换矩阵,我们这里主要用于放大或者缩小
    mMatrix.setScale(scale, scale);
    // 设置变换矩阵
    mBitmapShader.setLocalMatrix(mMatrix);
    // 设置shader
    mBitmapPaint.setShader(mBitmapShader);
}
 
Example #11
Source File: ColorPicker.java    From Mi-Band with GNU General Public License v2.0 6 votes vote down vote up
private Bitmap createColorWheelBitmap(int width, int height) {

        Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[]{0f, 1f, 1f};
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
 
Example #12
Source File: LinearGradientFillBitmapTextureAtlasSourceDecorator.java    From tilt-game-android with MIT License 6 votes vote down vote up
public LinearGradientFillBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int[] pColors, final float[] pPositions, final LinearGradientDirection pLinearGradientDirection, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
	super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pTextureAtlasSourceDecoratorOptions);
	this.mColors = pColors;
	this.mPositions = pPositions;
	this.mLinearGradientDirection = pLinearGradientDirection;

	this.mPaint.setStyle(Style.FILL);

	final int right = pBitmapTextureAtlasSource.getTextureWidth() - 1;
	final int bottom = pBitmapTextureAtlasSource.getTextureHeight() - 1;

	final float fromX = pLinearGradientDirection.getFromX(right);
	final float fromY = pLinearGradientDirection.getFromY(bottom);
	final float toX = pLinearGradientDirection.getToX(right);
	final float toY = pLinearGradientDirection.getToY(bottom);

	this.mPaint.setShader(new LinearGradient(fromX, fromY, toX, toY, pColors, pPositions, TileMode.CLAMP));
}
 
Example #13
Source File: RadialGradientFillBitmapTextureAtlasSourceDecorator.java    From tilt-game-android with MIT License 6 votes vote down vote up
public RadialGradientFillBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int[] pColors, final float[] pPositions, final RadialGradientDirection pRadialGradientDirection, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
	super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pTextureAtlasSourceDecoratorOptions);
	this.mColors = pColors;
	this.mPositions = pPositions;
	this.mRadialGradientDirection = pRadialGradientDirection;

	this.mPaint.setStyle(Style.FILL);

	final int width = pBitmapTextureAtlasSource.getTextureWidth();
	final int height = pBitmapTextureAtlasSource.getTextureHeight();

	final float centerX = width * 0.5f;
	final float centerY = height * 0.5f;

	final float radius = Math.max(centerX, centerY);

	switch (pRadialGradientDirection) {
		case INSIDE_OUT:
			this.mPaint.setShader(new RadialGradient(centerX, centerY, radius, pColors, pPositions, TileMode.CLAMP));
			break;
		case OUTSIDE_IN:
			ArrayUtils.reverse(pColors);
			this.mPaint.setShader(new RadialGradient(centerX, centerY, radius, pColors, pPositions, TileMode.CLAMP));
			break;
	}
}
 
Example #14
Source File: ColorPicker.java    From redalert-android with Apache License 2.0 6 votes vote down vote up
private Bitmap createColorWheelBitmap(int width, int height) {

        Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[]{0f, 1f, 1f};
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
 
Example #15
Source File: LinearGradientFillBitmapTextureAtlasSourceDecorator.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
public LinearGradientFillBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int[] pColors, final float[] pPositions, final LinearGradientDirection pLinearGradientDirection, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
	super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pTextureAtlasSourceDecoratorOptions);
	this.mColors = pColors;
	this.mPositions = pPositions;
	this.mLinearGradientDirection = pLinearGradientDirection;

	this.mPaint.setStyle(Style.FILL);

	final int right = pBitmapTextureAtlasSource.getTextureWidth() - 1;
	final int bottom = pBitmapTextureAtlasSource.getTextureHeight() - 1;

	final float fromX = pLinearGradientDirection.getFromX(right);
	final float fromY = pLinearGradientDirection.getFromY(bottom);
	final float toX = pLinearGradientDirection.getToX(right);
	final float toY = pLinearGradientDirection.getToY(bottom);

	this.mPaint.setShader(new LinearGradient(fromX, fromY, toX, toY, pColors, pPositions, TileMode.CLAMP));
}
 
Example #16
Source File: RadialGradientFillBitmapTextureAtlasSourceDecorator.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
public RadialGradientFillBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int[] pColors, final float[] pPositions, final RadialGradientDirection pRadialGradientDirection, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
	super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pTextureAtlasSourceDecoratorOptions);
	this.mColors = pColors;
	this.mPositions = pPositions;
	this.mRadialGradientDirection = pRadialGradientDirection;

	this.mPaint.setStyle(Style.FILL);

	final int width = pBitmapTextureAtlasSource.getTextureWidth();
	final int height = pBitmapTextureAtlasSource.getTextureHeight();

	final float centerX = width * 0.5f;
	final float centerY = height * 0.5f;

	final float radius = Math.max(centerX, centerY);

	switch(pRadialGradientDirection) {
		case INSIDE_OUT:
			this.mPaint.setShader(new RadialGradient(centerX, centerY, radius, pColors, pPositions, TileMode.CLAMP));
			break;
		case OUTSIDE_IN:
			ArrayUtils.reverse(pColors);
			this.mPaint.setShader(new RadialGradient(centerX, centerY, radius, pColors, pPositions, TileMode.CLAMP));
			break;
	}
}
 
Example #17
Source File: CircleImageView.java    From GestureViews with Apache License 2.0 6 votes vote down vote up
private void setup() {
    init();

    Bitmap bitmap = isCircle ? getBitmapFromDrawable(getDrawable()) : null;

    if (bitmap != null) {
        BitmapShader bitmapShader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
        tmpMatrix.set(getImageMatrix());
        tmpMatrix.postTranslate(getPaddingLeft(), getPaddingTop());
        bitmapShader.setLocalMatrix(tmpMatrix);
        bitmapPaint.setShader(bitmapShader);
    } else {
        bitmapPaint.setShader(null);
    }

    invalidate();
}
 
Example #18
Source File: RoundedBitmapBuilder.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
public RoundedBitmapBuilder tileMode(TileMode titleModeX,TileMode titleModeY){
	if(titleModeX!=null)
	    this.mTileModeX = titleModeX;
	if(titleModeY!=null)
	    this.mTileModeY = titleModeY;
	return this;
}
 
Example #19
Source File: FloatingActionButton.java    From TestChat with Apache License 2.0 5 votes vote down vote up
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
        if (!mStrokeVisible) {
                return new ColorDrawable(Color.TRANSPARENT);
        }

        ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());

        final int bottomStrokeColor = darkenColor(color);
        final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
        final int topStrokeColor = lightenColor(color);
        final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);

        final Paint paint = shapeDrawable.getPaint();
        paint.setAntiAlias(true);
        paint.setStrokeWidth(strokeWidth);
        paint.setStyle(Style.STROKE);
        shapeDrawable.setShaderFactory(new ShaderFactory() {
                @Override
                public Shader resize(int width, int height) {
                        return new LinearGradient(width / 2, 0, width / 2, height,
                                new int[]{topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor},
                                new float[]{0f, 0.2f, 0.5f, 0.8f, 1f},
                                TileMode.CLAMP
                        );
                }
        });

        return shapeDrawable;
}
 
Example #20
Source File: SlideView.java    From SpecialAlarmClock with Apache License 2.0 5 votes vote down vote up
public SlideView(Context context, AttributeSet attrs) {
    super(context, attrs);
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaxVelocity = configuration.getScaledMaximumFlingVelocity();
    mInterpolator = new AccelerateDecelerateInterpolator();
    mDensity = getResources().getDisplayMetrics().density;
    setClickable(true);
    setFocusable(true);
    setFocusableInTouchMode(true);

    TypedArray typeArray = context.obtainStyledAttributes(attrs, R.styleable.SlideView);
    mText = typeArray.getString(R.styleable.SlideView_maskText);
    mTextSize = typeArray.getDimensionPixelSize(R.styleable.SlideView_maskTextSize, R.dimen.mask_text_size);
    mTextLeft = typeArray.getDimensionPixelSize(R.styleable.SlideView_maskTextMarginLeft, R.dimen.mask_text_margin_left);
    mTextTop = typeArray.getDimensionPixelSize(R.styleable.SlideView_maskTextMarginTop, R.dimen.mask_text_margin_top);

    mSlider = typeArray.getResourceId(R.styleable.SlideView_slider, R.mipmap.app_icon);
    mSliderLeft = typeArray.getDimensionPixelSize(R.styleable.SlideView_sliderMarginLeft, R.dimen.slider_margin_left);
    mSliderTop = typeArray.getDimensionPixelSize(R.styleable.SlideView_sliderMarginTop, R.dimen.slider_margin_top);
    mSliderBitmap = BitmapFactory.decodeResource(getResources(), mSlider);
    mSliderRect = new Rect(mSliderLeft, mSliderTop, mSliderLeft + mSliderBitmap.getWidth(), mSliderTop + mSliderBitmap.getHeight());

    mSlidableLength = typeArray.getDimensionPixelSize(R.styleable.SlideView_slidableLength, R.dimen.slidable_length);
    mEffectiveLength = typeArray.getDimensionPixelSize(R.styleable.SlideView_effectiveLength,
            R.dimen.effective_length);
    mEffectiveVelocity = typeArray.getDimensionPixelSize(R.styleable.SlideView_effectiveVelocity,
            R.dimen.effective_velocity);
    typeArray.recycle();

    mGradientColors = new int[]{Color.argb(255, 120, 120, 120), Color.argb(255, 120, 120, 120), Color.argb(255, 255, 255, 255)};
    mGradient = new LinearGradient(0, 0, 100 * mDensity, 0, mGradientColors, new float[]{0, 0.7f, 1}, TileMode.MIRROR);
    mGradientIndex = 0;
    mPaint = new Paint();
    mMatrix = new Matrix();
    mPaint.setTextSize(mTextSize);
    mHandler.sendEmptyMessageDelayed(MSG_REDRAW, DRAW_INTERVAL);
}
 
Example #21
Source File: RoundedVignetteBitmapDisplayer.java    From letv with Apache License 2.0 5 votes vote down vote up
protected void onBoundsChange(Rect bounds) {
    super.onBoundsChange(bounds);
    RadialGradient vignette = new RadialGradient(this.mRect.centerX(), (this.mRect.centerY() * 1.0f) / 0.7f, this.mRect.centerX() * 1.3f, new int[]{0, 0, 2130706432}, new float[]{0.0f, 0.7f, 1.0f}, TileMode.CLAMP);
    Matrix oval = new Matrix();
    oval.setScale(1.0f, 0.7f);
    vignette.setLocalMatrix(oval);
    this.paint.setShader(new ComposeShader(this.bitmapShader, vignette, Mode.SRC_OVER));
}
 
Example #22
Source File: ReflectView.java    From TvLauncher with Apache License 2.0 5 votes vote down vote up
public static Bitmap createCutReflectedImage(Bitmap bitmap, int cutHeight) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int totalHeight = mReflectImageHeight + cutHeight;
    if (height <= totalHeight) {
        return null;
    }
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height
                    - mReflectImageHeight - cutHeight, width, mReflectImageHeight,
            matrix, true);
    Bitmap bitmapWithReflection = Bitmap.createBitmap(width,
            mReflectImageHeight, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(reflectionImage, 0, 0, null);
    LinearGradient shader = new LinearGradient(0, 0, 0,
            bitmapWithReflection.getHeight(), 0x80ffffff, 0x00ffffff,
            TileMode.CLAMP);
    Paint paint = new Paint();
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    canvas.drawRect(0, 0, width, bitmapWithReflection.getHeight(), paint);
    if (!reflectionImage.isRecycled()) {
        reflectionImage.recycle();
    }
    System.gc();

    return bitmapWithReflection;
}
 
Example #23
Source File: RoundedPagerDrawable.java    From letv with Apache License 2.0 5 votes vote down vote up
public void draw(Canvas canvas) {
    if (this.mRebuildShader) {
        BitmapShader bitmapShader = new BitmapShader(this.mBitmap, this.mTileModeX, this.mTileModeY);
        if (this.mTileModeX == TileMode.CLAMP && this.mTileModeY == TileMode.CLAMP) {
            bitmapShader.setLocalMatrix(this.mShaderMatrix);
        }
        this.mBitmapPaint.setShader(bitmapShader);
        this.mRebuildShader = false;
    }
    if (this.mOval) {
        if (this.mBorderWidth > 0.0f) {
            canvas.drawOval(this.mDrawableRect, this.mBitmapPaint);
            canvas.drawOval(this.mBorderRect, this.mBorderPaint);
            return;
        }
        canvas.drawOval(this.mDrawableRect, this.mBitmapPaint);
    } else if (any(this.mCornersRounded)) {
        float radius = this.mCornerRadius;
        if (this.mBorderWidth > 0.0f) {
            canvas.drawRoundRect(this.mDrawableRect, radius, radius, this.mBitmapPaint);
            canvas.drawRoundRect(this.mBorderRect, radius, radius, this.mBorderPaint);
            redrawBitmapForSquareCorners(canvas);
            redrawBorderForSquareCorners(canvas);
            return;
        }
        canvas.drawRoundRect(this.mDrawableRect, radius, radius, this.mBitmapPaint);
        redrawBitmapForSquareCorners(canvas);
    } else {
        canvas.drawRect(this.mDrawableRect, this.mBitmapPaint);
        if (this.mBorderWidth > 0.0f) {
            canvas.drawRect(this.mBorderRect, this.mBorderPaint);
        }
    }
}
 
Example #24
Source File: ObjectGraphicInMultiMode.java    From mlkit-material-android with Apache License 2.0 5 votes vote down vote up
ObjectGraphicInMultiMode(
    GraphicOverlay overlay,
    DetectedObject object,
    ObjectConfirmationController confirmationController) {
  super(overlay);

  this.object = object;
  this.confirmationController = confirmationController;

  Resources resources = context.getResources();
  boxPaint = new Paint();
  boxPaint.setStyle(Style.STROKE);
  boxPaint.setStrokeWidth(
      resources.getDimensionPixelOffset(
          confirmationController.isConfirmed()
              ? R.dimen.bounding_box_confirmed_stroke_width
              : R.dimen.bounding_box_stroke_width));
  boxPaint.setColor(Color.WHITE);

  boxGradientStartColor = ContextCompat.getColor(context, R.color.bounding_box_gradient_start);
  boxGradientEndColor = ContextCompat.getColor(context, R.color.bounding_box_gradient_end);
  boxCornerRadius = resources.getDimensionPixelOffset(R.dimen.bounding_box_corner_radius);

  scrimPaint = new Paint();
  scrimPaint.setShader(
      new LinearGradient(
          0,
          0,
          overlay.getWidth(),
          overlay.getHeight(),
          ContextCompat.getColor(context, R.color.object_confirmed_bg_gradient_start),
          ContextCompat.getColor(context, R.color.object_confirmed_bg_gradient_end),
          TileMode.MIRROR));

  eraserPaint = new Paint();
  eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

  minBoxLen =
      resources.getDimensionPixelOffset(R.dimen.object_reticle_outer_ring_stroke_radius) * 2;
}
 
Example #25
Source File: RoundImageView.java    From orz with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化BitmapShader
 */
private void setUpShader() {
    Drawable drawable = getDrawable();
    if (drawable == null) {
        return;
    }

    Bitmap bmp = drawableToBitmap(drawable);
    // 将bmp作为着色器,就是在指定区域内绘制bmp
    mBitmapShader = new BitmapShader(bmp, TileMode.CLAMP, TileMode.CLAMP);
    float scale = 1.0f;
    if (mType == TYPE_CIRCLE) {
        // 拿到bitmap宽或高的小值
        int bSize = Math.min(bmp.getWidth(), bmp.getHeight());
        scale = mWidth * 1.0f / bSize;

    } else if (mType == TYPE_ROUND) {
        // 如果图片的宽或者高与view的宽高不匹配,计算出需要缩放的比例;缩放后的图片的宽高,一定要大于我们view的宽高;所以我们这里取大值;
        scale = Math.max(getWidth() * 1.0f / bmp.getWidth(), getHeight() * 1.0f / bmp.getHeight());
    }
    // shader的变换矩阵,我们这里主要用于放大或者缩小
    mMatrix.setScale(scale, scale);
    // 设置变换矩阵
    mBitmapShader.setLocalMatrix(mMatrix);
    // 设置shader
    mBitmapPaint.setShader(mBitmapShader);
}
 
Example #26
Source File: BitmapUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 获得带倒影的图片方法
 *
 * @param bitmap 源Bitmap
 * @return 带倒影的Bitmap
 */
public static Bitmap createReflectionBitmap(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 #27
Source File: CircleGestureImageView.java    From GestureViews with Apache License 2.0 5 votes vote down vote up
private void setup() {
    Bitmap bitmap = isCircle ? getBitmapFromDrawable(getDrawable()) : null;
    if (bitmap != null) {
        bitmapPaint.setShader(new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP));
        updateShaderMatrix();
    } else {
        bitmapPaint.setShader(null);
    }

    invalidate();
}
 
Example #28
Source File: RoundedPagerDrawable.java    From letv with Apache License 2.0 5 votes vote down vote up
public RoundedPagerDrawable setTileModeX(TileMode tileModeX) {
    if (this.mTileModeX != tileModeX) {
        this.mTileModeX = tileModeX;
        this.mRebuildShader = true;
        invalidateSelf();
    }
    return this;
}
 
Example #29
Source File: FloatingActionButton.java    From android-chat-ui with Apache License 2.0 5 votes vote down vote up
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
  if (!mStrokeVisible) {
    return new ColorDrawable(Color.TRANSPARENT);
  }

  ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());

  final int bottomStrokeColor = darkenColor(color);
  final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
  final int topStrokeColor = lightenColor(color);
  final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);

  final Paint paint = shapeDrawable.getPaint();
  paint.setAntiAlias(true);
  paint.setStrokeWidth(strokeWidth);
  paint.setStyle(Style.STROKE);
  shapeDrawable.setShaderFactory(new ShaderFactory() {
    @Override
    public Shader resize(int width, int height) {
      return new LinearGradient(width / 2, 0, width / 2, height,
          new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor },
          new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f },
          TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
 
Example #30
Source File: ClockFaceView.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private RadialGradient getGradientForTextView(RectF selectorBox, RectF tvBox) {
  if (!RectF.intersects(selectorBox, tvBox)) {
    return null;
  }

  return new RadialGradient(
      (selectorBox.centerX() - scratch.left),
      (selectorBox.centerY() - scratch.top),
      selectorBox.width() * .5f,
      gradientColors,
      gradientPositions,
      TileMode.CLAMP);
}