use of android.graphics.LinearGradient in project LoadingDrawable by dinuscxj.
the class CollisionLoadingRenderer method setupPaint.
private void setupPaint() {
mPaint.setStyle(Paint.Style.FILL);
mPaint.setShader(new LinearGradient(mBallSideOffsets, 0, mWidth - mBallSideOffsets, 0, mColors, mPositions, Shader.TileMode.CLAMP));
}
use of android.graphics.LinearGradient in project ActivityAnimationLib by dkmeteor.
the class BaseFoldingLayout method prepareFold.
/**
* This method is called in order to update the fold's orientation, anchor
* point and number of folds. This creates the necessary setup in order to
* prepare the layout for a fold with the specified parameters. Some of the
* dimensions required for the folding transformation are also acquired
* here.
*
* After this method is called, it will be in a completely unfolded state by
* default.
*/
private void prepareFold(Orientation orientation, float anchorFactor, int numberOfFolds) {
mSrc = new float[NUM_OF_POLY_POINTS];
mDst = new float[NUM_OF_POLY_POINTS];
mDstRect = new Rect();
mFoldFactor = 0;
mPreviousFoldFactor = 0;
mIsFoldPrepared = false;
mSolidShadow = new Paint();
mGradientShadow = new Paint();
mOrientation = orientation;
mIsHorizontal = (orientation == Orientation.HORIZONTAL);
if (mIsHorizontal) {
mShadowLinearGradient = new LinearGradient(0, 0, SHADING_FACTOR, 0, Color.BLACK, Color.TRANSPARENT, TileMode.CLAMP);
} else {
mShadowLinearGradient = new LinearGradient(0, 0, 0, SHADING_FACTOR, Color.BLACK, Color.TRANSPARENT, TileMode.CLAMP);
}
mGradientShadow.setStyle(Style.FILL);
mGradientShadow.setShader(mShadowLinearGradient);
mShadowGradientMatrix = new Matrix();
mAnchorFactor = anchorFactor;
mNumberOfFolds = numberOfFolds;
mOriginalWidth = getMeasuredWidth();
mOriginalHeight = getMeasuredHeight();
mFoldRectArray = new Rect[mNumberOfFolds];
mMatrix = new Matrix[mNumberOfFolds];
for (int x = 0; x < mNumberOfFolds; x++) {
mMatrix[x] = new Matrix();
}
int h = mOriginalHeight;
int w = mOriginalWidth;
if (Util.IS_JBMR2 && h != 0 && w != 0) {
mFullBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(mFullBitmap);
getChildAt(0).draw(canvas);
}
int delta = Math.round(mIsHorizontal ? ((float) w) / ((float) mNumberOfFolds) : ((float) h) / ((float) mNumberOfFolds));
/*
* Loops through the number of folds and segments the full layout into a
* number of smaller equal components. If the number of folds is odd,
* then one of the components will be smaller than all the rest. Note
* that deltap below handles the calculation for an odd number of folds.
*/
for (int x = 0; x < mNumberOfFolds; x++) {
if (mIsHorizontal) {
int deltap = (x + 1) * delta > w ? w - x * delta : delta;
mFoldRectArray[x] = new Rect(x * delta, 0, x * delta + deltap, h);
} else {
int deltap = (x + 1) * delta > h ? h - x * delta : delta;
mFoldRectArray[x] = new Rect(0, x * delta, w, x * delta + deltap);
}
}
if (mIsHorizontal) {
mFoldMaxHeight = h;
mFoldMaxWidth = delta;
} else {
mFoldMaxHeight = delta;
mFoldMaxWidth = w;
}
mIsFoldPrepared = true;
}
use of android.graphics.LinearGradient in project FBReaderJ by geometer.
the class AmbilWarnaKotak method onDraw.
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (paint == null) {
paint = new Paint();
luar = new LinearGradient(0.f, 0.f, 0.f, this.getMeasuredHeight(), 0xffffffff, 0xff000000, TileMode.CLAMP);
}
int rgb = Color.HSVToColor(color);
Shader dalam = new LinearGradient(0.f, 0.f, this.getMeasuredWidth(), 0.f, 0xffffffff, rgb, TileMode.CLAMP);
ComposeShader shader = new ComposeShader(luar, dalam, PorterDuff.Mode.MULTIPLY);
paint.setShader(shader);
canvas.drawRect(0.f, 0.f, this.getMeasuredWidth(), this.getMeasuredHeight(), paint);
}
use of android.graphics.LinearGradient in project HTextView by hanks-zyh.
the class RainBowText method animatePrepare.
@Override
protected void animatePrepare(CharSequence text) {
mTextWidth = (int) mPaint.measureText(mText, 0, mText.length());
mTextWidth = Math.max(DisplayUtils.dp2Px(100), mTextWidth);
if (mTextWidth > 0) {
mLinearGradient = new LinearGradient(0, 0, mTextWidth, 0, colors, null, Shader.TileMode.MIRROR);
mPaint.setShader(mLinearGradient);
}
}
use of android.graphics.LinearGradient in project material-components-android by material-components.
the class CircularBorderDrawable method createGradientShader.
/**
* Creates a vertical {@link LinearGradient}
*
* @return
*/
private Shader createGradientShader() {
final Rect rect = mRect;
copyBounds(rect);
final float borderRatio = mBorderWidth / rect.height();
final int[] colors = new int[6];
colors[0] = ColorUtils.compositeColors(mTopOuterStrokeColor, mCurrentBorderTintColor);
colors[1] = ColorUtils.compositeColors(mTopInnerStrokeColor, mCurrentBorderTintColor);
colors[2] = ColorUtils.compositeColors(ColorUtils.setAlphaComponent(mTopInnerStrokeColor, 0), mCurrentBorderTintColor);
colors[3] = ColorUtils.compositeColors(ColorUtils.setAlphaComponent(mBottomInnerStrokeColor, 0), mCurrentBorderTintColor);
colors[4] = ColorUtils.compositeColors(mBottomInnerStrokeColor, mCurrentBorderTintColor);
colors[5] = ColorUtils.compositeColors(mBottomOuterStrokeColor, mCurrentBorderTintColor);
final float[] positions = new float[6];
positions[0] = 0f;
positions[1] = borderRatio;
positions[2] = 0.5f;
positions[3] = 0.5f;
positions[4] = 1f - borderRatio;
positions[5] = 1f;
return new LinearGradient(0, rect.top, 0, rect.bottom, colors, positions, Shader.TileMode.CLAMP);
}
Aggregations