import { VerticalTextAlignment } from '@nativescript-community/text' ; import { Application , Color , CoreTypes , Utils , ViewBase , profile } from '@nativescript/core' ; let isPostLollipopVar ; export function isPostLollipop ( ) { if ( isPostLollipopVar === undefined ) { isPostLollipopVar = android . os . Build . VERSION . SDK_INT >= 21 ; } return isPostLollipopVar ; } let isPostLollipopMR1Var ; export function isPostLollipopMR1 ( ) { if ( isPostLollipopMR1Var === undefined ) { isPostLollipopMR1Var = android . os . Build . VERSION . SDK_INT >= 22 ; } return isPostLollipopMR1Var ; } let isPostMarshmallowVar ; export function isPostMarshmallow ( ) { if ( isPostMarshmallowVar === undefined ) { isPostMarshmallowVar = android . os . Build . VERSION . SDK_INT >= 23 ; } return isPostMarshmallowVar ; } export const state = { get selected ( ) { return 16842913 ; } , get hovered ( ) { return 16843623 ; } , get focused ( ) { return 16842908 ; } , get enabled ( ) { return 16842910 ; } , get pressed ( ) { return 16842919 ; } , get window_focused ( ) { return 16842909 ; } , get checked ( ) { return 16842912 ; } } ; function createNativeArray ( ... args ) { const result = Array . create ( 'int' , args . length ) ; args . forEach ( ( a , i ) => ( result [ i ] = a ) ) ; return result ; } export const stateSets = { get PRESSED_STATE_SET ( ) { if ( ! this . mPRESSED_STATE_SET ) { this . mPRESSED_STATE_SET = createNativeArray ( state . pressed ) ; } return this . mPRESSED_STATE_SET as number [ ] ; } , get HOVERED_FOCUSED_STATE_SET ( ) { if ( ! this . mHOVERED_FOCUSED_STATE_SET ) { this . mHOVERED_FOCUSED_STATE_SET = createNativeArray ( state . hovered , state . focused ) ; } return this . mPRESSED_STATE_SET as number [ ] ; } , get FOCUSED_STATE_SET ( ) { if ( ! this . mFOCUSED_STATE_SET ) { this . mFOCUSED_STATE_SET = createNativeArray ( state . focused ) ; } return this . mFOCUSED_STATE_SET as number [ ] ; } , get HOVERED_STATE_SET ( ) { if ( ! this . mHOVERED_STATE_SET ) { this . mHOVERED_STATE_SET = createNativeArray ( state . hovered ) ; } return this . mHOVERED_STATE_SET as number [ ] ; } , get SELECTED_PRESSED_STATE_SET ( ) { if ( ! this . mSELECTED_PRESSED_STATE_SET ) { this . mSELECTED_PRESSED_STATE_SET = createNativeArray ( state . enabled , state . pressed ) ; } return this . mSELECTED_PRESSED_STATE_SET as number [ ] ; } , get SELECTED_HOVERED_FOCUSED_STATE_SET ( ) { if ( ! this . mSELECTED_HOVERED_FOCUSED_STATE_SET ) { this . mSELECTED_HOVERED_FOCUSED_STATE_SET = createNativeArray ( state . selected , state . hovered , state . focused ) ; } return this . mSELECTED_HOVERED_FOCUSED_STATE_SET as number [ ] ; } , get SELECTED_FOCUSED_STATE_SET ( ) { if ( ! this . mSELECTED_FOCUSED_STATE_SET ) { this . mSELECTED_FOCUSED_STATE_SET = createNativeArray ( state . selected , state . focused ) ; } return this . mSELECTED_FOCUSED_STATE_SET as number [ ] ; } , get SELECTED_HOVERED_STATE_SET ( ) { if ( ! this . mSELECTED_HOVERED_STATE_SET ) { this . mSELECTED_HOVERED_STATE_SET = createNativeArray ( state . selected , state . hovered ) ; } return this . mSELECTED_HOVERED_STATE_SET as number [ ] ; } , get SELECTED_STATE_SET ( ) { if ( ! this . mSELECTED_STATE_SET ) { this . mSELECTED_STATE_SET = createNativeArray ( state . selected ) ; } return this . mSELECTED_STATE_SET as number [ ] ; } , get BACKGROUND_DEFAULT_STATE_1 ( ) { if ( ! this . mBACKGROUND_DEFAULT_STATE_1 ) { this . mBACKGROUND_DEFAULT_STATE_1 = createNativeArray ( state . window_focused , state . enabled ) ; } return this . mBACKGROUND_DEFAULT_STATE_1 as number [ ] ; } , get BACKGROUND_DEFAULT_STATE_2 ( ) { if ( ! this . mBACKGROUND_DEFAULT_STATE_1_SET ) { this . mBACKGROUND_DEFAULT_STATE_1_SET = createNativeArray ( state . enabled ) ; } return this . mBACKGROUND_DEFAULT_STATE_1_SET as number [ ] ; } , get BACKGROUND_SELECTED_STATE ( ) { if ( ! this . mBACKGROUND_SELECTED_STATE ) { this . mBACKGROUND_SELECTED_STATE = createNativeArray ( state . window_focused , state . enabled , state . pressed ) ; } return this . mBACKGROUND_SELECTED_STATE as number [ ] ; } , get BACKGROUND_CHECKED_STATE ( ) { if ( ! this . mBACKGROUND_CHECKED_STATE ) { this . mBACKGROUND_CHECKED_STATE = createNativeArray ( state . window_focused , state . enabled , state . checked ) ; } return this . mBACKGROUND_CHECKED_STATE as number [ ] ; } , get BACKGROUND_FOCUSED_STATE ( ) { if ( ! this . mBACKGROUND_FOCUSED_STATE ) { this . mBACKGROUND_FOCUSED_STATE = createNativeArray ( state . focused , state . window_focused , state . enabled ) ; } return this . mBACKGROUND_FOCUSED_STATE as number [ ] ; } , get BACKGROUND_DISABLED_STATE ( ) { if ( ! this . mBACKGROUND_DISABLED_STATE ) { this . mBACKGROUND_DISABLED_STATE = createNativeArray ( - state . enabled ) ; } return this . mBACKGROUND_DISABLED_STATE as number [ ] ; } } ; let ColorStateList ; export function getColorStateList ( color ) { if ( ! color ) { return null ; } if ( ! ColorStateList ) { ColorStateList = android . content . res . ColorStateList ; } return ColorStateList . valueOf ( color ) ; } export function getFullColorStateList ( activeColor , inactiveColor = 1627389952 , disabledColor = 1627389952 ) { if ( ! activeColor ) { return null ; } if ( ! NUtils ) { NUtils = ( com as any ) . nativescript . material . core . Utils ; } return NUtils . getFullColorStateList ( activeColor , inactiveColor , disabledColor ) ; } export function getEnabledColorStateList ( color , disabledColor ) { if ( ! color ) { return null ; } if ( ! NUtils ) { NUtils = ( com as any ) . nativescript . material . core . Utils ; } return NUtils . getEnabledColorStateList ( color , disabledColor ) ; } let NUtils ; export const createStateListAnimator = profile ( 'createStateListAnimator' , function ( view , nativeView ) { let elevation = view [ 'elevation' ] ; if ( elevation === undefined || elevation === null ) { elevation = ( view as any ) . getDefaultElevation ( ) ; } elevation = Utils . layout . toDevicePixels ( elevation ) ; let pressedZ = view [ 'dynamicElevationOffset' ] ; if ( pressedZ === undefined || pressedZ === null ) { pressedZ = ( view as any ) . getDefaultDynamicElevationOffset ( ) ; } pressedZ = Utils . layout . toDevicePixels ( pressedZ ) ; if ( ! NUtils ) { NUtils = ( com as any ) . nativescript . material . core . Utils ; } NUtils . createStateListAnimator ( view . _context , nativeView , elevation , pressedZ ) ; } ) ; export function getAttrColor ( context , name ) { const ta = context . obtainStyledAttributes ( [ Utils . android . resources . getId ( ':attr/' + name ) ] ) ; const color = ta . getColor ( 0 , 0 ) ; ta . recycle ( ) ; return color ; } function createForegroundShape ( radius ) { if ( ! NUtils ) { NUtils = ( com as any ) . nativescript . material . core . Utils ; } return NUtils . createForegroundShape ( radius ) ; } export function createRippleDrawable ( rippleColor , radius = 0 ) { if ( ! NUtils ) { NUtils = ( com as any ) . nativescript . material . core . Utils ; } return NUtils . createRippleDrawable ( rippleColor , radius ) ; } export function handleClearFocus ( view ) { if ( ! NUtils ) { NUtils = ( com as any ) . nativescript . material . core . Utils ; } return NUtils . handleClearFocus ( view ) ; } export function setFocusable ( view , focusable ) { view . setFocusable ( focusable ) ; view . setFocusableInTouchMode ( focusable ) ; } export function getLayout ( context , id ) { if ( ! id || ! context ) { return 0 ; } return context . getResources ( ) . getIdentifier ( id , 'layout' , context . getPackageName ( ) ) ; } export function getStyle ( context , id ) { if ( ! id || ! context ) { return 0 ; } return context . getResources ( ) . getIdentifier ( id , 'style' , context . getPackageName ( ) ) ; } export function getAttr ( context , id ) { if ( ! id || ! context ) { return 0 ; } return context . getResources ( ) . getIdentifier ( id , 'attr' , context . getPackageName ( ) ) ; } export function getHorizontalGravity ( textAlignment ) { switch ( textAlignment ) { case 'center' : return 1 ; case 'right' : return 8388613 ; case 'initial' : case 'left' : default : return 8388611 ; } } export function getVerticalGravity ( textAlignment ) { switch ( textAlignment ) { case 'initial' : case 'top' : return 48 ; case 'middle' : case 'center' : return 16 ; case 'bottom' : return 80 ; } }