EmbedSample.Android.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #if __ANDROID__ || ANDROID
  2. using System;
  3. using System.IO;
  4. using System.Diagnostics;
  5. using Android.Views;
  6. using Android.Webkit;
  7. using Avalonia.Controls.Platform;
  8. using Avalonia.Platform;
  9. namespace NativeEmbedSample;
  10. public partial class EmbedSample
  11. {
  12. private IPlatformHandle CreateAndroid(IPlatformHandle parent)
  13. {
  14. var button = new Android.Widget.Button(Android.App.Application.Context) { Text = "Android button" };
  15. return new AndroidViewHandle(button);
  16. }
  17. private void DestroyAndroid(IPlatformHandle control)
  18. {
  19. base.DestroyNativeControlCore(control);
  20. }
  21. }
  22. internal sealed class AndroidViewHandle : INativeControlHostDestroyableControlHandle
  23. {
  24. private View _view;
  25. public AndroidViewHandle(View view)
  26. {
  27. _view = view;
  28. }
  29. public IntPtr Handle => _view?.Handle ?? IntPtr.Zero;
  30. public string HandleDescriptor => "JavaHandle";
  31. public void Destroy()
  32. {
  33. _view?.Dispose();
  34. _view = null;
  35. }
  36. ~AndroidViewHandle()
  37. {
  38. Destroy();
  39. }
  40. }
  41. #endif