forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathborder.android.ts
More file actions
51 lines (42 loc) · 1.99 KB
/
border.android.ts
File metadata and controls
51 lines (42 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import borderCommon = require("ui/border/border-common");
import proxy = require("ui/core/proxy");
import dependencyObservable = require("ui/core/dependency-observable");
import utils = require("utils/utils");
// merge the exports of the common file with the exports of this file
declare var exports;
require("utils/module-merge").merge(borderCommon, exports);
function onBorderPropertyChanged(data: dependencyObservable.PropertyChangeData) {
var border = <Border>data.object;
border._updateAndroidBorder();
}
(<proxy.PropertyMetadata>borderCommon.Border.cornerRadiusProperty.metadata).onSetNativeValue = onBorderPropertyChanged;
(<proxy.PropertyMetadata>borderCommon.Border.borderWidthProperty.metadata).onSetNativeValue = onBorderPropertyChanged;
(<proxy.PropertyMetadata>borderCommon.Border.borderColorProperty.metadata).onSetNativeValue = onBorderPropertyChanged;
export class Border extends borderCommon.Border {
public _updateAndroidBorder() {
if (!this._nativeView) {
return;
}
var nativeView = <android.view.ViewGroup>this._nativeView;
var backgroundDrawable = nativeView.getBackground();
if (!(backgroundDrawable instanceof android.graphics.drawable.GradientDrawable)) {
backgroundDrawable = new android.graphics.drawable.GradientDrawable();
nativeView.setBackgroundDrawable(backgroundDrawable);
}
var gd = <android.graphics.drawable.GradientDrawable>backgroundDrawable;
var density = utils.layout.getDisplayDensity();
gd.setCornerRadius(this.cornerRadius * density);
if (this.borderColor) {
gd.setStroke(this.borderWidth * density, this.borderColor.android);
}
else {
gd.setStroke(this.borderWidth * density, android.graphics.Color.TRANSPARENT);
}
if (this.backgroundColor) {
gd.setColor(this.backgroundColor.android);
}
else {
gd.setColor(android.graphics.Color.TRANSPARENT);
}
}
}