@ -32,9 +32,6 @@ namespace Avalonia.Android.Platform.SkiaPlatform
{
class TopLevelImpl : IAndroidView , ITopLevelImpl , EglGlPlatformSurface . IEglWindowGlPlatformSurfaceInfoWithWaitPolicy
{
private readonly IGlPlatformSurface _ gl ;
private readonly IFramebufferPlatformSurface _f ramebuffer ;
private readonly AndroidKeyboardEventsHelper < TopLevelImpl > _ keyboardHelper ;
private readonly AndroidMotionEventsHelper _ pointerHelper ;
private readonly AndroidInputMethod < ViewImpl > _ textInputMethod ;
@ -59,13 +56,9 @@ namespace Avalonia.Android.Platform.SkiaPlatform
_ textInputMethod = new AndroidInputMethod < ViewImpl > ( _ view ) ;
_ keyboardHelper = new AndroidKeyboardEventsHelper < TopLevelImpl > ( this ) ;
_ pointerHelper = new AndroidMotionEventsHelper ( this ) ;
_ gl = new EglGlPlatformSurface ( this ) ;
_f ramebuffer = new FramebufferManager ( this ) ;
_ clipboard = new ClipboardImpl ( avaloniaView . Context . GetSystemService ( Context . ClipboardService ) . JavaCast < ClipboardManager > ( ) ) ;
_ screens = new AndroidScreens ( avaloniaView . Context ) ;
RenderScaling = _ view . Scaling ;
if ( avaloniaView . Context is Activity mainActivity )
{
_ insetsManager = new AndroidInsetsManager ( mainActivity , this ) ;
@ -78,15 +71,16 @@ namespace Avalonia.Android.Platform.SkiaPlatform
_ systemNavigationManager = new AndroidSystemNavigationManagerImpl ( avaloniaView . Context as IActivityNavigationService ) ;
Surfaces = new object [ ] { _ gl , _f ramebuffer , _ view } ;
var gl = new EglGlPlatformSurface ( this ) ;
var framebuffer = new FramebufferManager ( this ) ;
Surfaces = [ gl , framebuffer , _ view ] ;
Handle = new AndroidViewControlHandle ( _ view ) ;
}
public IInputRoot ? InputRoot { get ; private set ; }
public virtual Size ClientSize = > _ view . Size . ToSize ( RenderScaling ) ;
public Size ? FrameSize = > null ;
public Size ClientSize = > _ view . Size . ToSize ( RenderScaling ) ;
public double RenderScaling = > _ view . Scaling ;
public Action ? Closed { get ; set ; }
@ -110,16 +104,6 @@ namespace Avalonia.Android.Platform.SkiaPlatform
public Compositor Compositor = > AndroidPlatform . Compositor ? ?
throw new InvalidOperationException ( "Android backend wasn't initialized. Make sure .UseAndroid() was executed." ) ;
public virtual void Hide ( )
{
_ view . Visibility = ViewStates . Invisible ;
}
public void Invalidate ( Rect rect )
{
if ( _ view . Holder ? . Surface ? . IsValid = = true ) _ view . Invalidate ( ) ;
}
public Point PointToClient ( PixelPoint point )
{
return point . ToPoint ( RenderScaling ) ;
@ -140,18 +124,6 @@ namespace Avalonia.Android.Platform.SkiaPlatform
InputRoot = inputRoot ;
}
public virtual void Show ( )
{
_ view . Visibility = ViewStates . Visible ;
}
public double RenderScaling { get ; }
void Draw ( )
{
Paint ? . Invoke ( new Rect ( new Point ( 0 , 0 ) , ClientSize ) ) ;
}
public virtual void Dispose ( )
{
_ systemNavigationManager . Dispose ( ) ;
@ -159,7 +131,7 @@ namespace Avalonia.Android.Platform.SkiaPlatform
_ view = null ! ;
}
protected virtual v oid OnResized ( Size size )
protected void OnResized ( Size size )
{
Resized ? . Invoke ( size , WindowResizeReason . Unspecified ) ;
}
@ -169,10 +141,11 @@ namespace Avalonia.Android.Platform.SkiaPlatform
Resized ? . Invoke ( size , WindowResizeReason . Layout ) ;
}
class ViewImpl : InvalidationAwareSurfaceView , ISurfaceHolderCallback , IInitEditorInfo
sealed class ViewImpl : InvalidationAwareSurfaceView , IInitEditorInfo
{
private readonly TopLevelImpl _ tl ;
private Size _ oldSize ;
private double _ oldScaling ;
public ViewImpl ( Context context , TopLevelImpl tl , bool placeOnTop ) : base ( context )
{
@ -181,13 +154,6 @@ namespace Avalonia.Android.Platform.SkiaPlatform
SetZOrderOnTop ( true ) ;
}
public TopLevelImpl TopLevelImpl = > _ tl ;
protected override void Draw ( )
{
_ tl . Draw ( ) ;
}
protected override void DispatchDraw ( global :: Android . Graphics . Canvas canvas )
{
// Workaround issue #9230 on where screen remains gray after splash screen.
@ -234,20 +200,40 @@ namespace Avalonia.Android.Platform.SkiaPlatform
return res ? ? baseResult ;
}
void ISurfaceHolderCallback . SurfaceChanged ( ISurfaceHolder holder , Format format , int width , int height )
public override void SurfaceChanged ( ISurfaceHolder holder , Format format , int width , int height )
{
var newSize = new PixelSize ( width , height ) . ToSize ( _ tl . RenderScaling ) ;
base . SurfaceChanged ( holder , format , width , height ) ;
var newSize = Size . ToSize ( Scaling ) ;
var newScaling = Scaling ;
if ( newSize ! = _ oldSize )
{
_ oldSize = newSize ;
_ tl . OnResized ( newSize ) ;
}
// ReSharper disable once CompareOfFloatsByEqualityOperator
if ( newScaling ! = _ oldScaling )
{
_ oldScaling = newScaling ;
_ tl . ScalingChanged ? . Invoke ( newScaling ) ;
}
}
base . SurfaceChanged ( holder , format , width , height ) ;
public override void SurfaceRedrawNeeded ( ISurfaceHolder holder )
{
// Compositor Renderer handles Paint event in-sync, which is perfect for sync SurfaceRedrawNeeded
_ tl . Paint ? . Invoke ( new Rect ( new Point ( ) , Size . ToSize ( Scaling ) ) ) ;
base . SurfaceRedrawNeeded ( holder ) ;
}
public override void SurfaceRedrawNeededAsync ( ISurfaceHolder holder , IRunnable drawingFinished )
{
_ tl . Compositor . RequestCompositionUpdate ( drawingFinished . Run ) ;
base . SurfaceRedrawNeededAsync ( holder , drawingFinished ) ;
}
public sealed override bool OnCheckIsTextEditor ( )
public override bool OnCheckIsTextEditor ( )
{
return true ;
}
@ -259,11 +245,10 @@ namespace Avalonia.Android.Platform.SkiaPlatform
_ initEditorInfo = init ;
}
public sealed override IInputConnection OnCreateInputConnection ( EditorInfo ? outAttrs )
public override IInputConnection OnCreateInputConnection ( EditorInfo ? outAttrs )
{
return _ initEditorInfo ? . Invoke ( _ tl , outAttrs ! ) ! ;
}
}
public IPopupImpl ? CreatePopup ( ) = > null ;
@ -303,10 +288,8 @@ namespace Avalonia.Android.Platform.SkiaPlatform
IntPtr EglGlPlatformSurface . IEglWindowGlPlatformSurfaceInfo . Handle = > ( ( IPlatformHandle ) _ view ) . Handle ;
bool EglGlPlatformSurface . IEglWindowGlPlatformSurfaceInfoWithWaitPolicy . SkipWaits = > true ;
public PixelSize Size = > _ view . Size ;
public double Scaling = > RenderScaling ;
PixelSize EglGlPlatformSurface . IEglWindowGlPlatformSurfaceInfo . Size = > _ view . Size ;
double EglGlPlatformSurface . IEglWindowGlPlatformSurfaceInfo . Scaling = > _ view . Scaling ;
public void SetTransparencyLevelHint ( IReadOnlyList < WindowTransparencyLevel > transparencyLevels )
{