use of android.graphics.LinearGradient in project CustomShapeImageView by MostafaGazar.
the class SVGHandlerTest method testParseLinearGradient_xlink.
@Test
public void testParseLinearGradient_xlink() throws Exception {
//given
when(picture.beginRecording(anyInt(), anyInt())).thenReturn(canvas);
SVGParser.SVGHandler parserHandler = spy(this.parserHandler);
LinearGradient gr1 = mock(LinearGradient.class);
PowerMockito.whenNew(LinearGradient.class).withArguments(eq(10.1f), eq(4.1f), eq(11.1f), eq(0.0f), eq(new int[0]), eq(new float[0]), eq(Shader.TileMode.CLAMP)).thenReturn(gr1);
LinearGradient gr2 = mock(LinearGradient.class);
PowerMockito.whenNew(LinearGradient.class).withArguments(eq(5.1f), eq(1.1f), eq(20.1f), eq(25.0f), eq(new int[0]), eq(new float[0]), eq(Shader.TileMode.CLAMP)).thenReturn(gr2);
//when
startSVG(parserHandler);
//parent
startElement(parserHandler, attributes(attr("id", "gr1"), attr("x1", "10.1"), attr("y1", "4.1"), attr("x2", "11.1"), attr("gradientTransform", "matrix(0.2883 0 0 0.2865 153.3307 265.0264)")), "linearGradient");
endElement(parserHandler, "linearGradient");
//child
startElement(parserHandler, attributes(attr("id", "gr2"), attr("x1", "5.1"), attr("y1", "1.1"), attr("x2", "20.1"), attr("y2", "25.0"), attr("href", "#gr1")), "linearGradient");
endElement(parserHandler, "linearGradient");
endSVG(parserHandler);
//then
verify(gr2).setLocalMatrix(matrix);
}
use of android.graphics.LinearGradient in project remusic by aa112901.
the class CustomTextView method onSizeChanged.
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if (mWidth == 0) {
Log.e(TAG, "*********************");
mWidth = getMeasuredWidth();
paint2 = getPaint();
//颜色渐变器
gradient = new LinearGradient(0, 0, mWidth, 0, new int[] { Color.GRAY, Color.WHITE, Color.GRAY }, new float[] { 0.3f, 0.5f, 1.0f }, Shader.TileMode.CLAMP);
paint2.setShader(gradient);
matrix = new Matrix();
}
}
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 KeepScore by nolanlawson.
the class TopDownGradientSpan method updateDrawState.
@Override
public void updateDrawState(TextPaint ds) {
Shader shader = new LinearGradient(0, mStartY, 0, mEndY, new int[] { mStartColor, mEndColor }, null, TileMode.CLAMP);
ds.setShader(shader);
}
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;
}
Aggregations