use of android.graphics.LinearGradient in project SmoothProgressBar by castorflex.
the class SmoothProgressDrawable method drawGradient.
private void drawGradient(Canvas canvas) {
float xSectionWidth = 1f / mSectionsCount;
int currentIndexColor = mColorsIndex;
mLinearGradientPositions[0] = 0f;
mLinearGradientPositions[mLinearGradientPositions.length - 1] = 1f;
int firstColorIndex = currentIndexColor - 1;
if (firstColorIndex < 0)
firstColorIndex += mColors.length;
mLinearGradientColors[0] = mColors[firstColorIndex];
for (int i = 0; i < mSectionsCount; ++i) {
float position = mInterpolator.getInterpolation(i * xSectionWidth + mCurrentOffset);
mLinearGradientPositions[i + 1] = position;
mLinearGradientColors[i + 1] = mColors[currentIndexColor];
currentIndexColor = (currentIndexColor + 1) % mColors.length;
}
mLinearGradientColors[mLinearGradientColors.length - 1] = mColors[currentIndexColor];
float left = mReversed ? (mMirrorMode ? Math.abs(mBounds.left - mBounds.right) / 2 : mBounds.left) : mBounds.left;
float right = mMirrorMode ? (mReversed ? mBounds.left : Math.abs(mBounds.left - mBounds.right) / 2) : mBounds.right;
float top = mBounds.centerY() - mStrokeWidth / 2;
float bottom = mBounds.centerY() + mStrokeWidth / 2;
LinearGradient linearGradient = new LinearGradient(left, top, right, bottom, mLinearGradientColors, mLinearGradientPositions, mMirrorMode ? Shader.TileMode.MIRROR : Shader.TileMode.CLAMP);
mPaint.setShader(linearGradient);
}
use of android.graphics.LinearGradient in project Signal-Android by WhisperSystems.
the class VerticalSlideColorPicker method onSizeChanged.
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
viewWidth = w;
viewHeight = h;
centerX = viewWidth / 2;
colorPickerRadius = (viewWidth / 2) - borderWidth;
colorPickerBody = new RectF(centerX - colorPickerRadius, borderWidth + colorPickerRadius, centerX + colorPickerRadius, viewHeight - (borderWidth + colorPickerRadius));
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);
resetToDefault();
}
use of android.graphics.LinearGradient in project android_frameworks_base by ParanoidAndroid.
the class RecentsScrollViewPerformanceHelper method drawCallback.
public void drawCallback(Canvas canvas, int left, int right, int top, int bottom, int scrollX, int scrollY, float topFadingEdgeStrength, float bottomFadingEdgeStrength, float leftFadingEdgeStrength, float rightFadingEdgeStrength, int mPaddingTop) {
if ((mSoftwareRendered && OPTIMIZE_SW_RENDERED_RECENTS) || USE_DARK_FADE_IN_HW_ACCELERATED_MODE) {
if (mFadePaint == null) {
mFadePaint = new Paint();
mFadeMatrix = new Matrix();
// use use a height of 1, and then wack the matrix each time we
// actually use it.
mFade = new LinearGradient(0, 0, 0, 1, 0xCC000000, 0, Shader.TileMode.CLAMP);
// PULL OUT THIS CONSTANT
mFadePaint.setShader(mFade);
}
// draw the fade effect
boolean drawTop = false;
boolean drawBottom = false;
boolean drawLeft = false;
boolean drawRight = false;
float topFadeStrength = 0.0f;
float bottomFadeStrength = 0.0f;
float leftFadeStrength = 0.0f;
float rightFadeStrength = 0.0f;
final float fadeHeight = mFadingEdgeLength;
int length = (int) fadeHeight;
// overlapping fades produce odd-looking artifacts
if (mIsVertical && (top + length > bottom - length)) {
length = (bottom - top) / 2;
}
// also clip horizontal fades if necessary
if (!mIsVertical && (left + length > right - length)) {
length = (right - left) / 2;
}
if (mIsVertical) {
topFadeStrength = Math.max(0.0f, Math.min(1.0f, topFadingEdgeStrength));
drawTop = topFadeStrength * fadeHeight > 1.0f;
bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, bottomFadingEdgeStrength));
drawBottom = bottomFadeStrength * fadeHeight > 1.0f;
}
if (!mIsVertical) {
leftFadeStrength = Math.max(0.0f, Math.min(1.0f, leftFadingEdgeStrength));
drawLeft = leftFadeStrength * fadeHeight > 1.0f;
rightFadeStrength = Math.max(0.0f, Math.min(1.0f, rightFadingEdgeStrength));
drawRight = rightFadeStrength * fadeHeight > 1.0f;
}
if (drawTop) {
mFadeMatrix.setScale(1, fadeHeight * topFadeStrength);
mFadeMatrix.postTranslate(left, top);
mFade.setLocalMatrix(mFadeMatrix);
canvas.drawRect(left, top, right, top + length, mFadePaint);
if (mBlackPaint == null) {
// Draw under the status bar at the top
mBlackPaint = new Paint();
mBlackPaint.setColor(0xFF000000);
}
canvas.drawRect(left, top - mPaddingTop, right, top, mBlackPaint);
}
if (drawBottom) {
mFadeMatrix.setScale(1, fadeHeight * bottomFadeStrength);
mFadeMatrix.postRotate(180);
mFadeMatrix.postTranslate(left, bottom);
mFade.setLocalMatrix(mFadeMatrix);
canvas.drawRect(left, bottom - length, right, bottom, mFadePaint);
}
if (drawLeft) {
mFadeMatrix.setScale(1, fadeHeight * leftFadeStrength);
mFadeMatrix.postRotate(-90);
mFadeMatrix.postTranslate(left, top);
mFade.setLocalMatrix(mFadeMatrix);
canvas.drawRect(left, top, left + length, bottom, mFadePaint);
}
if (drawRight) {
mFadeMatrix.setScale(1, fadeHeight * rightFadeStrength);
mFadeMatrix.postRotate(90);
mFadeMatrix.postTranslate(right, top);
mFade.setLocalMatrix(mFadeMatrix);
canvas.drawRect(right - length, top, right, bottom, mFadePaint);
}
}
}
use of android.graphics.LinearGradient in project UltimateAndroid by cymcsg.
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.
* <p/>
* 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 UltimateAndroid by cymcsg.
the class HomeDiagram method drawBrokenLine.
/**
* 绘制折线
*
* @param c
*/
public void drawBrokenLine(Canvas c) {
int index = 0;
float temp_x = 0;
float temp_y = 0;
float base = (getHeight() - tb * 3.0f) / (Collections.max(milliliter) - Collections.min(milliliter));
Shader mShader = new LinearGradient(0, 0, 0, getHeight(), new int[] { Color.argb(100, 0, 255, 255), Color.argb(45, 0, 255, 255), Color.argb(10, 0, 255, 255) }, null, Shader.TileMode.CLAMP);
framPanint.setShader(mShader);
for (int i = 0; i < milliliter.size() - 1; i++) {
float x1 = interval_left_right * i;
float y1 = getHeight() - tb * 1.5f - (base * milliliter.get(i));
float x2 = interval_left_right * (i + 1);
float y2 = getHeight() - tb * 1.5f - (base * milliliter.get(i + 1));
if ((int) (base * milliliter.get(i + 1)) == 0 && index == 0) {
index++;
temp_x = x1;
temp_y = y1;
}
if ((int) (base * milliliter.get(i + 1)) != 0 && index != 0) {
index = 0;
x1 = temp_x;
y1 = temp_y;
}
if (index == 0) {
c.drawLine(x1, y1, x2, y2, paint_brokenLine);
path.lineTo(x1, y1);
if (i != 0)
c.drawBitmap(bitmap_point, x1 - bitmap_point.getWidth() / 2, y1 - bitmap_point.getHeight() / 2, null);
if (i == milliliter.size() - 2) {
path.lineTo(x2, y2);
path.lineTo(x2, getHeight());
path.lineTo(0, getHeight());
path.close();
c.drawPath(path, framPanint);
c.drawBitmap(bitmap_point, x2 - bitmap_point.getWidth() / 2, y2 - bitmap_point.getHeight() / 2, null);
}
}
}
paint_dottedline.setColor(orangeLineColor);
Path path = new Path();
path.moveTo(0, getHeight() - tb * 6.5f);
path.lineTo(getWidth(), getHeight() - tb * 6.5f);
PathEffect effects = new DashPathEffect(new float[] { tb * 0.3f, tb * 0.3f, tb * 0.3f, tb * 0.3f }, tb * 0.1f);
paint_dottedline.setPathEffect(effects);
c.drawPath(path, paint_dottedline);
}
Aggregations