FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(android): implement BorderDrawable outline · NativeScript/NativeScript@ec07a99 · GitHub

Commit ec07a99

Browse files
committed
feat(android): implement BorderDrawable outline
1 parent 20a45a8 commit ec07a99

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

  • tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets

‎tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/BorderDrawable.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.graphics.Color;
99
import android.graphics.LinearGradient;
1010
import android.graphics.Matrix;
11+
import android.graphics.Outline;
1112
import android.graphics.Paint;
1213
import android.graphics.Path;
1314
import android.graphics.PointF;
@@ -16,6 +17,7 @@
1617
import android.graphics.drawable.ColorDrawable;
1718
import android.graphics.drawable.Drawable;
1819
import android.graphics.Shader;
20+
import android.support.annotation.NonNull;
1921

2022
import org.nativescript.widgets.image.BitmapOwner;
2123
import org.nativescript.widgets.image.Fetcher;
@@ -804,6 +806,23 @@ public Drawable getDrawable() {
804806
return drawable;
805807
}
806808

809+
@Override
810+
public void getOutline(@NonNull Outline outline) {
811+
if (android.os.Build.VERSION.SDK_INT >= 21) {
812+
Path backgroundPath = new Path();
813+
float[] backgroundRadii = {
814+
Math.max(0, borderTopLeftRadius), Math.max(0, borderTopLeftRadius),
815+
Math.max(0, borderTopRightRadius), Math.max(0, borderTopRightRadius),
816+
Math.max(0, borderBottomRightRadius), Math.max(0, borderBottomRightRadius),
817+
Math.max(0, borderBottomLeftRadius), Math.max(0, borderBottomLeftRadius)
818+
};
819+
backgroundPath.addRoundRect(new RectF(getBounds()), backgroundRadii, Path.Direction.CW);
820+
outline.setConvexPath(backgroundPath);
821+
} else {
822+
throw new IllegalStateException("Method supported on API 21 or higher");
823+
}
824+
}
825+
807826
private class BackgroundDrawParams {
808827
private boolean repeatX = true;
809828
private boolean repeatY = true;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL