@@ -5,11 +5,11 @@ import {
55 Color ,
66 Length ,
77 PercentLength ,
8+ Utils ,
89 View ,
910 androidDynamicElevationOffsetProperty ,
1011 androidElevationProperty ,
11- backgroundInternalProperty ,
12- profile
12+ backgroundInternalProperty
1313} from '@nativescript/core' ;
1414import { createRippleDrawable , createStateListAnimator , getAttrColor , getColorStateList , handleClearFocus , isPostLollipop , isPostLollipopMR1 , isPostMarshmallow } from './android/utils' ;
1515import { CornerFamily , applyMixins } from './index.common' ;
@@ -29,6 +29,14 @@ function cornerTreat(cornerFamily: CornerFamily): com.google.android.material.sh
2929 }
3030}
3131
32+ let context : android . content . Context ;
33+ function getContext ( ) {
34+ if ( ! context ) {
35+ context = Utils . ad . getApplicationContext ( ) ;
36+ }
37+ return context ;
38+ }
39+
3240// stub class as we don't use this on android
3341export class Themer {
3442 primaryColor : string | Color ;
@@ -53,7 +61,7 @@ export class Themer {
5361 }
5462 getPrimaryColor ( ) : string | Color {
5563 if ( ! this . primaryColor ) {
56- this . primaryColor = new Color ( getAttrColor ( Application . android . startActivity , 'colorPrimary' ) ) ;
64+ this . primaryColor = new Color ( getAttrColor ( getContext ( ) , 'colorPrimary' ) ) ;
5765 }
5866 return this . primaryColor ;
5967 }
@@ -63,14 +71,14 @@ export class Themer {
6371 }
6472 getOnPrimaryColor ( ) {
6573 if ( ! this . onPrimaryColor ) {
66- this . onPrimaryColor = new Color ( getAttrColor ( Application . android . startActivity , 'colorOnPrimary' ) ) ;
74+ this . onPrimaryColor = new Color ( getAttrColor ( getContext ( ) , 'colorOnPrimary' ) ) ;
6775 }
6876 return this . onPrimaryColor ;
6977 }
7078
7179 setAccentColor ( value : string | Color ) {
7280 if ( ! this . accentColor ) {
73- this . accentColor = new Color ( getAttrColor ( Application . android . startActivity , 'colorAccent' ) ) ;
81+ this . accentColor = new Color ( getAttrColor ( getContext ( ) , 'colorAccent' ) ) ;
7482 }
7583 this . accentColor = value ;
7684 }
@@ -95,7 +103,7 @@ export class Themer {
95103 }
96104 getPrimaryColorVariant ( ) : string | Color {
97105 if ( ! this . primaryColorVariant ) {
98- this . primaryColorVariant = new Color ( getAttrColor ( Application . android . context , 'colorSecondary' ) ) ;
106+ this . primaryColorVariant = new Color ( getAttrColor ( getContext ( ) , 'colorSecondary' ) ) ;
99107 }
100108 return this . primaryColorVariant ;
101109 }
@@ -109,7 +117,7 @@ export class Themer {
109117 controlHighlightColor : Color ;
110118 getControlHighlightColor ( ) : Color {
111119 if ( ! this . controlHighlightColor ) {
112- this . controlHighlightColor = new Color ( getAttrColor ( Application . android . context , 'colorControlHighlight' ) ) ;
120+ this . controlHighlightColor = new Color ( getAttrColor ( getContext ( ) , 'colorControlHighlight' ) ) ;
113121 }
114122 return this . controlHighlightColor ;
115123 }
0 commit comments