import { getRippleColor , rippleColorProperty , themer } from '@nativescript-community/ui-material-core' ; import { Background , Color , backgroundInternalProperty } from '@nativescript/core' ; import { createRippleDrawable , getAttrColor , getColorStateList , isPostLollipopMR1 , isPostMarshmallow } from '@nativescript-community/ui-material-core/android/utils' ; import { RippleBase } from './ripple-common' ; let MDStackLayout ; const DEFAULT_STROKE_VALUE = - 1 ; function initMDStackLayout ( ) { if ( ! MDStackLayout ) { if ( isPostLollipopMR1 ( ) ) { MDStackLayout = org . nativescript . widgets . StackLayout ; } else { initializePreLollipopStackLayout ( ) ; MDStackLayout = PreLollipopStackLayout as any ; } } } interface PreLollipopStackLayout extends org . nativescript . widgets . StackLayout { new ( context ) : PreLollipopStackLayout ; } let PreLollipopStackLayout ; function initializePreLollipopStackLayout ( ) { if ( PreLollipopStackLayout ) { return ; } @ NativeClass class PreLollipopStackLayoutImpl extends org . nativescript . widgets . StackLayout { constructor ( context ) { super ( context ) ; return global . __native ( this ) ; } private mForeground ; private mSelfBounds = new android . graphics . Rect ( ) ; private mOverlayBounds = new android . graphics . Rect ( ) ; private mForegroundGravity = android . view . Gravity . FILL ; protected mForegroundInPadding = true ; mForegroundBoundsChanged = false ; return see getForegroundGravity ( ) { return this . mForegroundGravity ; } param foregroundGravity See  android . view . Gravity see setForegroundGravity ( foregroundGravity ) { if ( this . mForegroundGravity !== foregroundGravity ) { if ( ( foregroundGravity & android . view . Gravity . RELATIVE_HORIZONTAL_GRAVITY_MASK ) === 0 ) { foregroundGravity |= android . view . Gravity . START ; } if ( ( foregroundGravity & android . view . Gravity . VERTICAL_GRAVITY_MASK ) === 0 ) { foregroundGravity |= android . view . Gravity . TOP ; } this . mForegroundGravity = foregroundGravity ; if ( this . mForegroundGravity === android . view . Gravity . FILL && this . mForeground != null ) { const padding = new android . graphics . Rect ( ) ; this . mForeground . getPadding ( padding ) ; } this . requestLayout ( ) ; } } verifyDrawable ( who ) { return super . verifyDrawable ( who ) || who === this . mForeground ; } jumpDrawablesToCurrentState ( ) { super . jumpDrawablesToCurrentState ( ) ; if ( this . mForeground != null ) { this . mForeground . jumpToCurrentState ( ) ; } } drawableStateChanged ( ) { super . drawableStateChanged ( ) ; if ( this . mForeground != null && this . mForeground . isStateful ( ) ) { this . mForeground . setState ( this . getDrawableState ( ) ) ; } } param drawable setForeground ( drawable ) { if ( this . mForeground !== drawable ) { if ( this . mForeground != null ) { this . mForeground . setCallback ( null ) ; this . unscheduleDrawable ( this . mForeground ) ; } this . mForeground = drawable ; if ( drawable != null ) { this . setWillNotDraw ( false ) ; drawable . setCallback ( this ) ; if ( drawable . isStateful ( ) ) { drawable . setState ( this . getDrawableState ( ) ) ; } if ( this . mForegroundGravity === android . view . Gravity . FILL ) { const padding = new android . graphics . Rect ( ) ; drawable . getPadding ( padding ) ; } } else { this . setWillNotDraw ( true ) ; } this . requestLayout ( ) ; this . invalidate ( ) ; } } return getForeground ( ) { return this . mForeground ; } onLayout ( changed , left , top , right , bottom ) { super . onLayout ( changed , left , top , right , bottom ) ; this . mForegroundBoundsChanged = this . mForegroundBoundsChanged || changed ; } onSizeChanged ( w , h , oldw , oldh ) { super . onSizeChanged ( w , h , oldw , oldh ) ; this . mForegroundBoundsChanged = true ; } draw ( canvas ) { super . draw ( canvas ) ; if ( this . mForeground != null ) { const foreground = this . mForeground ; if ( this . mForegroundBoundsChanged ) { this . mForegroundBoundsChanged = false ; const selfBounds = this . mSelfBounds ; const overlayBounds = this . mOverlayBounds ; const w = this . getRight ( ) - this . getLeft ( ) ; const h = this . getBottom ( ) - this . getTop ( ) ; if ( this . mForegroundInPadding ) { selfBounds . set ( 0 , 0 , w , h ) ; } else { selfBounds . set ( this . getPaddingLeft ( ) , this . getPaddingTop ( ) , w - this . getPaddingRight ( ) , h - this . getPaddingBottom ( ) ) ; } android . view . Gravity . apply ( this . mForegroundGravity , foreground . getIntrinsicWidth ( ) , foreground . getIntrinsicHeight ( ) , selfBounds , overlayBounds ) ; foreground . setBounds ( overlayBounds ) ; } foreground . draw ( canvas ) ; } } drawableHotspotChanged ( x , y ) { super . drawableHotspotChanged ( x , y ) ; if ( this . mForeground != null ) { this . mForeground . setHotspot ( x , y ) ; } } } PreLollipopStackLayout = PreLollipopStackLayoutImpl as any ; } export class Ripple extends RippleBase { nativeViewProtected : android . view . View ; ripple : android . graphics . drawable . RippleDrawable ; public createNativeView ( ) { const view = super . createNativeView ( ) as android . view . View ; this . setRippleDrawable ( view ) ; return view ; } rippleDrawable : android . graphics . drawable . Drawable ; getRippleColor ( ) { if ( this . rippleColor ) { return getRippleColor ( this . rippleColor ) ; } return getRippleColor ( themer . getAccentColor ( ) ) ; } setRippleDrawable ( view , radius = 0 ) { if ( ! this . rippleDrawable ) { this . rippleDrawable = createRippleDrawable ( this . getRippleColor ( ) , radius ) ; if ( isPostMarshmallow ( ) ) { view . setForeground ( this . rippleDrawable ) ; } } } [ rippleColorProperty . setNative ] ( color ) { if ( ! this . rippleDrawable ) { this . setRippleDrawable ( this . nativeViewProtected ) ; } else { if ( isPostLollipopMR1 ( ) ) { ( this . rippleDrawable as android . graphics . drawable . RippleDrawable ) . setColor ( getColorStateList ( color . android ) ) ; } else { ( this . rippleDrawable as any ) . rippleShape . getPaint ( ) . setColor ( getRippleColor ( color ) ) ; } } } [ backgroundInternalProperty . setNative ] ( value ) { super [ backgroundInternalProperty . setNative ] ( value ) ; if ( this . nativeViewProtected ) { if ( value instanceof android . graphics . drawable . Drawable ) { } else { this . rippleDrawable = null ; this . setRippleDrawable ( this . nativeViewProtected , value . borderTopLeftRadius ) ; } } } }