mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Revert "Revert "feat(android): added ability to create background linear gradients. (#116)" (#122)" (#123)
This reverts commit 3170b8696f.
This commit is contained in:
committed by
GitHub
parent
e2003aa9b1
commit
7c0bdd8435
@@ -6,6 +6,7 @@ import android.graphics.Bitmap;
|
|||||||
import android.graphics.BitmapShader;
|
import android.graphics.BitmapShader;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.graphics.LinearGradient;
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Path;
|
import android.graphics.Path;
|
||||||
@@ -49,6 +50,7 @@ public class BorderDrawable extends ColorDrawable implements BitmapOwner {
|
|||||||
private int backgroundColor;
|
private int backgroundColor;
|
||||||
private String backgroundImage;
|
private String backgroundImage;
|
||||||
private Bitmap backgroundBitmap;
|
private Bitmap backgroundBitmap;
|
||||||
|
private LinearGradientDefinition backgroundGradient;
|
||||||
private String backgroundRepeat;
|
private String backgroundRepeat;
|
||||||
private String backgroundPosition;
|
private String backgroundPosition;
|
||||||
private CSSValue[] backgroundPositionParsedCSSValues;
|
private CSSValue[] backgroundPositionParsedCSSValues;
|
||||||
@@ -149,6 +151,8 @@ public class BorderDrawable extends ColorDrawable implements BitmapOwner {
|
|||||||
return backgroundBitmap;
|
return backgroundBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LinearGradientDefinition getBackgroundGradient() { return backgroundGradient; }
|
||||||
|
|
||||||
public String getBackgroundRepeat() {
|
public String getBackgroundRepeat() {
|
||||||
return backgroundRepeat;
|
return backgroundRepeat;
|
||||||
}
|
}
|
||||||
@@ -223,6 +227,7 @@ public class BorderDrawable extends ColorDrawable implements BitmapOwner {
|
|||||||
int backgroundColor,
|
int backgroundColor,
|
||||||
String backgroundImageUri,
|
String backgroundImageUri,
|
||||||
Bitmap backgroundBitmap,
|
Bitmap backgroundBitmap,
|
||||||
|
LinearGradientDefinition backgroundGradient,
|
||||||
Context context,
|
Context context,
|
||||||
String backgroundRepeat,
|
String backgroundRepeat,
|
||||||
String backgroundPosition,
|
String backgroundPosition,
|
||||||
@@ -250,6 +255,7 @@ public class BorderDrawable extends ColorDrawable implements BitmapOwner {
|
|||||||
this.backgroundColor = backgroundColor;
|
this.backgroundColor = backgroundColor;
|
||||||
this.backgroundImage = backgroundImageUri;
|
this.backgroundImage = backgroundImageUri;
|
||||||
this.backgroundBitmap = backgroundBitmap;
|
this.backgroundBitmap = backgroundBitmap;
|
||||||
|
this.backgroundGradient = backgroundGradient;
|
||||||
this.backgroundRepeat = backgroundRepeat;
|
this.backgroundRepeat = backgroundRepeat;
|
||||||
this.backgroundPosition = backgroundPosition;
|
this.backgroundPosition = backgroundPosition;
|
||||||
this.backgroundPositionParsedCSSValues = backgroundPositionParsedCSSValues;
|
this.backgroundPositionParsedCSSValues = backgroundPositionParsedCSSValues;
|
||||||
@@ -361,6 +367,24 @@ public class BorderDrawable extends ColorDrawable implements BitmapOwner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.backgroundGradient != null) {
|
||||||
|
LinearGradientDefinition def = this.backgroundGradient;
|
||||||
|
Paint backgroundGradientPaint = new Paint();
|
||||||
|
LinearGradient shader = new LinearGradient(
|
||||||
|
def.getStartX() * width, def.getStartY() * height,
|
||||||
|
def.getEndX() * width, def.getEndY() * height,
|
||||||
|
def.getColors(), def.getStops(), Shader.TileMode.MIRROR);
|
||||||
|
backgroundGradientPaint.setAntiAlias(true);
|
||||||
|
backgroundGradientPaint.setFilterBitmap(true);
|
||||||
|
backgroundGradientPaint.setShader(shader);
|
||||||
|
|
||||||
|
if (this.clipPath != null && !this.clipPath.isEmpty()) {
|
||||||
|
drawClipPath(this.clipPath, canvas, backgroundGradientPaint, backgroundBoundsF, this.density);
|
||||||
|
} else {
|
||||||
|
canvas.drawPath(backgroundPath, backgroundGradientPaint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// draw border
|
// draw border
|
||||||
if (this.clipPath != null && !this.clipPath.isEmpty()) {
|
if (this.clipPath != null && !this.clipPath.isEmpty()) {
|
||||||
float borderWidth = this.getUniformBorderWidth();
|
float borderWidth = this.getUniformBorderWidth();
|
||||||
@@ -386,7 +410,7 @@ public class BorderDrawable extends ColorDrawable implements BitmapOwner {
|
|||||||
float[] borderOuterRadii = {
|
float[] borderOuterRadii = {
|
||||||
borderTopLeftRadius, borderTopLeftRadius,
|
borderTopLeftRadius, borderTopLeftRadius,
|
||||||
borderTopRightRadius, borderTopRightRadius,
|
borderTopRightRadius, borderTopRightRadius,
|
||||||
borderBottomRightRadius, borderBottomRightRadius,
|
borderBottomRightRadius, borderBottomRightRadius,
|
||||||
borderBottomLeftRadius, borderBottomLeftRadius
|
borderBottomLeftRadius, borderBottomLeftRadius
|
||||||
};
|
};
|
||||||
borderPath.addRoundRect(borderOuterRect, borderOuterRadii, Path.Direction.CW);
|
borderPath.addRoundRect(borderOuterRect, borderOuterRadii, Path.Direction.CW);
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package org.nativescript.widgets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Vultix on 3/12/2018.
|
||||||
|
*/
|
||||||
|
public class LinearGradientDefinition {
|
||||||
|
private float startX;
|
||||||
|
private float startY;
|
||||||
|
private float endX;
|
||||||
|
private float endY;
|
||||||
|
private int[] colors;
|
||||||
|
private float[] stops;
|
||||||
|
|
||||||
|
public float getStartX() { return startX; }
|
||||||
|
public float getStartY() { return startY; }
|
||||||
|
public float getEndX() { return endX; }
|
||||||
|
public float getEndY() { return endY; }
|
||||||
|
public int[] getColors() { return colors; }
|
||||||
|
public float[] getStops() { return stops; }
|
||||||
|
|
||||||
|
public LinearGradientDefinition(float startX, float startY, float endX, float endY, int[] colors, float[] stops) {
|
||||||
|
this.startX = startX;
|
||||||
|
this.startY = startY;
|
||||||
|
this.endX = endX;
|
||||||
|
this.endY = endY;
|
||||||
|
this.colors = colors;
|
||||||
|
this.stops = stops;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user