@@ -5,11 +5,11 @@ import {
5
5
Color ,
6
6
Length ,
7
7
PercentLength ,
8
+ Utils ,
8
9
View ,
9
10
androidDynamicElevationOffsetProperty ,
10
11
androidElevationProperty ,
11
- backgroundInternalProperty ,
12
- profile
12
+ backgroundInternalProperty
13
13
} from '@nativescript/core' ;
14
14
import { createRippleDrawable , createStateListAnimator , getAttrColor , getColorStateList , handleClearFocus , isPostLollipop , isPostLollipopMR1 , isPostMarshmallow } from './android/utils' ;
15
15
import { CornerFamily , applyMixins } from './index.common' ;
@@ -29,6 +29,14 @@ function cornerTreat(cornerFamily: CornerFamily): com.google.android.material.sh
29
29
}
30
30
}
31
31
32
+ let context : android . content . Context ;
33
+ function getContext ( ) {
34
+ if ( ! context ) {
35
+ context = Utils . ad . getApplicationContext ( ) ;
36
+ }
37
+ return context ;
38
+ }
39
+
32
40
// stub class as we don't use this on android
33
41
export class Themer {
34
42
primaryColor : string | Color ;
@@ -53,7 +61,7 @@ export class Themer {
53
61
}
54
62
getPrimaryColor ( ) : string | Color {
55
63
if ( ! this . primaryColor ) {
56
- this . primaryColor = new Color ( getAttrColor ( Application . android . startActivity , 'colorPrimary' ) ) ;
64
+ this . primaryColor = new Color ( getAttrColor ( getContext ( ) , 'colorPrimary' ) ) ;
57
65
}
58
66
return this . primaryColor ;
59
67
}
@@ -63,14 +71,14 @@ export class Themer {
63
71
}
64
72
getOnPrimaryColor ( ) {
65
73
if ( ! this . onPrimaryColor ) {
66
- this . onPrimaryColor = new Color ( getAttrColor ( Application . android . startActivity , 'colorOnPrimary' ) ) ;
74
+ this . onPrimaryColor = new Color ( getAttrColor ( getContext ( ) , 'colorOnPrimary' ) ) ;
67
75
}
68
76
return this . onPrimaryColor ;
69
77
}
70
78
71
79
setAccentColor ( value : string | Color ) {
72
80
if ( ! this . accentColor ) {
73
- this . accentColor = new Color ( getAttrColor ( Application . android . startActivity , 'colorAccent' ) ) ;
81
+ this . accentColor = new Color ( getAttrColor ( getContext ( ) , 'colorAccent' ) ) ;
74
82
}
75
83
this . accentColor = value ;
76
84
}
@@ -95,7 +103,7 @@ export class Themer {
95
103
}
96
104
getPrimaryColorVariant ( ) : string | Color {
97
105
if ( ! this . primaryColorVariant ) {
98
- this . primaryColorVariant = new Color ( getAttrColor ( Application . android . context , 'colorSecondary' ) ) ;
106
+ this . primaryColorVariant = new Color ( getAttrColor ( getContext ( ) , 'colorSecondary' ) ) ;
99
107
}
100
108
return this . primaryColorVariant ;
101
109
}
@@ -109,7 +117,7 @@ export class Themer {
109
117
controlHighlightColor : Color ;
110
118
getControlHighlightColor ( ) : Color {
111
119
if ( ! this . controlHighlightColor ) {
112
- this . controlHighlightColor = new Color ( getAttrColor ( Application . android . context , 'colorControlHighlight' ) ) ;
120
+ this . controlHighlightColor = new Color ( getAttrColor ( getContext ( ) , 'colorControlHighlight' ) ) ;
113
121
}
114
122
return this . controlHighlightColor ;
115
123
}
0 commit comments