Skip to content

Commit 559a7c8

Browse files
committed
Implement the BorderDrawable class used in background.android.ts in Java
Resolves NativeScript#2318
1 parent 81288df commit 559a7c8

File tree

8 files changed

+100
-238
lines changed

8 files changed

+100
-238
lines changed

tests/app/ui/button/button-tests-native.android.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export function getNativeColor(button: buttonModule.Button): colorModule.Color {
2323

2424
export function getNativeBackgroundColor(button: buttonModule.Button): colorModule.Color {
2525
var bkg = <any>button.android.getBackground();
26-
if (bkg instanceof background.ad.BorderDrawable) {
27-
return (<background.ad.BorderDrawable>bkg).background.color;
26+
if (bkg instanceof org.nativescript.widgets.BorderDrawable) {
27+
return new colorModule.Color((<org.nativescript.widgets.BorderDrawable>bkg).getBackgroundColor());
2828
}
2929
else {
3030
return new colorModule.Color(bkg.backgroundColor)

tests/app/ui/label/label-tests-native.android.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export function getNativeTextAlignment(label: labelModule.Label): string {
2323

2424
export function getNativeBackgroundColor(label: labelModule.Label): colorModule.Color {
2525
var bkg = <any>label.android.getBackground();
26-
if (bkg instanceof background.ad.BorderDrawable) {
27-
return (<background.ad.BorderDrawable>bkg).background.color;
26+
if (bkg instanceof org.nativescript.widgets.BorderDrawable) {
27+
return new colorModule.Color((<org.nativescript.widgets.BorderDrawable>bkg).getBackgroundColor());
2828
}
2929
else {
3030
return new colorModule.Color(bkg.backgroundColor)

tests/app/ui/label/label-tests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
261261
normalColor = actualColors.getDefaultColor()
262262
TKUnit.assert(normalColor, "Expected: " + expColor + ", Actual: " + normalColor);
263263

264-
var bkg = (<background.ad.BorderDrawable>testLabel.android.getBackground());
265-
actualBackgroundColor = bkg.background.color.android;
264+
var bkg = (<org.nativescript.widgets.BorderDrawable>testLabel.android.getBackground());
265+
actualBackgroundColor = bkg.getBackgroundColor();
266266
expBackgroundColor = android.graphics.Color.parseColor(backgroundColor);
267267
TKUnit.assertEqual(actualBackgroundColor, expBackgroundColor);
268268
}

tests/app/ui/text-field/text-field-tests-native.android.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export function getNativeColor(textField: textFieldModule.TextField): colorModul
2828

2929
export function getNativeBackgroundColor(textField: textFieldModule.TextField): colorModule.Color {
3030
var bkg = <any>textField.android.getBackground();
31-
if (bkg instanceof background.ad.BorderDrawable) {
32-
return (<background.ad.BorderDrawable>bkg).background.color;
31+
if (bkg instanceof org.nativescript.widgets.BorderDrawable) {
32+
return new colorModule.Color((<org.nativescript.widgets.BorderDrawable>bkg).getBackgroundColor());
3333
}
3434
else {
3535
return new colorModule.Color(bkg.backgroundColor)

tests/app/ui/text-view/text-view-tests-native.android.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export function getNativeColor(textView: textViewModule.TextView): colorModule.C
3232

3333
export function getNativeBackgroundColor(textView: textViewModule.TextView): colorModule.Color {
3434
var bkg = <any>textView.android.getBackground();
35-
if (bkg instanceof background.ad.BorderDrawable) {
36-
return (<background.ad.BorderDrawable>bkg).background.color;
35+
if (bkg instanceof org.nativescript.widgets.BorderDrawable) {
36+
return new colorModule.Color((<org.nativescript.widgets.BorderDrawable>bkg).getBackgroundColor());
3737
}
3838
else {
3939
return new colorModule.Color(bkg.backgroundColor)

tests/app/ui/view/view-tests.android.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,33 +269,33 @@ export var test_StylePropertiesDefaultValuesCache = function () {
269269
}
270270

271271
export function getNativeBorderWidth(v: view.View): number {
272-
var bkg = <any>(<android.view.View>v.android).getBackground();
272+
var bkg = <org.nativescript.widgets.BorderDrawable>v.android.getBackground();
273273

274-
return bkg ? bkg.borderWidth : -1;
274+
return bkg ? bkg.getBorderWidth() : -1;
275275
}
276276

277277
export function getNativeCornerRadius(v: view.View): number {
278-
var bkg = <any>(<android.view.View>v.android).getBackground();
278+
var bkg = <org.nativescript.widgets.BorderDrawable>v.android.getBackground();
279279

280-
return bkg ? bkg.cornerRadius : -1;
280+
return bkg ? bkg.getBorderRadius() : -1;
281281
}
282282

283283
export function checkNativeBorderColor(v: view.View): boolean {
284-
var bkg = <background.ad.BorderDrawable>(<android.view.View>v.android).getBackground();
284+
var bkg = <org.nativescript.widgets.BorderDrawable>(<android.view.View>v.android).getBackground();
285285

286-
return v.borderColor && bkg && bkg.borderColor === v.borderColor.android;
286+
return v.borderColor && bkg && bkg.getBorderColor() === v.borderColor.android;
287287
}
288288

289289
export function checkNativeBackgroundColor(v: view.View): boolean {
290-
var bkg = <background.ad.BorderDrawable>(<android.view.View>v.android).getBackground();
290+
var bkg = <org.nativescript.widgets.BorderDrawable>(<android.view.View>v.android).getBackground();
291291

292-
return v.backgroundColor && bkg && bkg.background && bkg.background.color.equals(v.backgroundColor);
292+
return v.backgroundColor && bkg && bkg.getBackgroundColor() === v.backgroundColor.android;
293293
}
294294

295295
export function checkNativeBackgroundImage(v: view.View): boolean {
296-
var bkg = <background.ad.BorderDrawable>(<android.view.View>v.android).getBackground();
296+
var bkg = <org.nativescript.widgets.BorderDrawable>(<android.view.View>v.android).getBackground();
297297

298-
return bkg && bkg.background && !types.isNullOrUndefined(bkg.background.image);
298+
return bkg && !types.isNullOrUndefined(bkg.getBackgroundImage());
299299
}
300300

301301
let SDK: number;

tns-core-modules/org.nativescript.widgets.d.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,44 @@
11
declare module org {
22
module nativescript {
33
module widgets {
4+
export class BorderDrawable extends android.graphics.drawable.ColorDrawable {
5+
constructor(density: number);
6+
public refresh(
7+
borderWidth: number,
8+
borderColor: number,
9+
borderRadius: number,
10+
clipPath: string,
11+
backgroundColor: number,
12+
backgroundImage: android.graphics.Bitmap,
13+
backgroundImageWidth: number,
14+
backgroundImageHeight: number,
15+
backgroundRepeat: string,
16+
backgroundPosition: string,
17+
backgroundPositionParsedCSSValues: native.Array<CSSValue>,
18+
backgroundSize: string,
19+
backgroundSizeParsedCSSValues: native.Array<CSSValue>
20+
);
21+
public getBorderWidth(): number;
22+
public getBorderColor(): number;
23+
public getBorderRadius(): number;
24+
public getClipPath(): string;
25+
public getBackgroundColor(): number;
26+
public getBackgroundImage(): android.graphics.Bitmap;
27+
public getBackgroundImageWidth(): number;
28+
public getBackgroundImageHeight(): number;
29+
public getBackgroundRepeat(): string;
30+
public getBackgroundPosition(): string;
31+
public getBackgroundSize(): string;
32+
}
33+
34+
export class CSSValue {
35+
constructor(type: string, str: string, unit: string, value: number);
36+
public getType(): string;
37+
public getString(): string;
38+
public getUnit(): string;
39+
public getValue(): number;
40+
}
41+
442
export class CommonLayoutParams extends android.widget.FrameLayout.LayoutParams {
543
constructor();
644

0 commit comments

Comments
 (0)