AndroidPlatform.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.IO;
  3. using Avalonia.Android.Platform;
  4. using Avalonia.Android.Platform.Input;
  5. using Avalonia.Android.Platform.SkiaPlatform;
  6. using Avalonia.Controls;
  7. using Avalonia.Controls.Platform;
  8. using Avalonia.Input;
  9. using Avalonia.Input.Platform;
  10. using Avalonia.Platform;
  11. using Avalonia.Shared.PlatformSupport;
  12. using Avalonia.Skia;
  13. namespace Avalonia
  14. {
  15. public static class AndroidApplicationExtensions
  16. {
  17. public static T UseAndroid<T>(this T builder) where T : AppBuilderBase<T>, new()
  18. {
  19. builder.UseWindowingSubsystem(Android.AndroidPlatform.Initialize, "Android");
  20. return builder;
  21. }
  22. }
  23. }
  24. namespace Avalonia.Android
  25. {
  26. public class AndroidPlatform : IPlatformSettings, IWindowingPlatform, IPlatformIconLoader
  27. {
  28. public static readonly AndroidPlatform Instance = new AndroidPlatform();
  29. public Size DoubleClickSize => new Size(4, 4);
  30. public TimeSpan DoubleClickTime => TimeSpan.FromMilliseconds(200);
  31. public double RenderScalingFactor => _scalingFactor;
  32. public double LayoutScalingFactor => _scalingFactor;
  33. private readonly double _scalingFactor = 1;
  34. public AndroidPlatform()
  35. {
  36. _scalingFactor = global::Android.App.Application.Context.Resources.DisplayMetrics.ScaledDensity;
  37. }
  38. public static void Initialize()
  39. {
  40. AvaloniaLocator.CurrentMutable
  41. .Bind<IClipboard>().ToTransient<ClipboardImpl>()
  42. .Bind<IStandardCursorFactory>().ToTransient<CursorFactory>()
  43. .Bind<IKeyboardDevice>().ToSingleton<AndroidKeyboardDevice>()
  44. .Bind<IMouseDevice>().ToSingleton<AndroidMouseDevice>()
  45. .Bind<IPlatformSettings>().ToConstant(Instance)
  46. .Bind<IPlatformThreadingInterface>().ToConstant(new AndroidThreadingInterface())
  47. .Bind<ISystemDialogImpl>().ToTransient<SystemDialogImpl>()
  48. .Bind<IWindowingPlatform>().ToConstant(Instance);
  49. SkiaPlatform.Initialize();
  50. }
  51. public void Init(Type applicationType)
  52. {
  53. StandardRuntimePlatformServices.Register(applicationType.Assembly);
  54. }
  55. public IWindowImpl CreateWindow()
  56. {
  57. return new WindowImpl();
  58. }
  59. public IEmbeddableWindowImpl CreateEmbeddableWindow()
  60. {
  61. throw new NotImplementedException();
  62. }
  63. public IPopupImpl CreatePopup()
  64. {
  65. throw new NotImplementedException();
  66. }
  67. public IWindowIconImpl LoadIcon(string fileName)
  68. {
  69. return null;
  70. }
  71. public IWindowIconImpl LoadIcon(Stream stream)
  72. {
  73. return null;
  74. }
  75. public IWindowIconImpl LoadIcon(IBitmapImpl bitmap)
  76. {
  77. return null;
  78. }
  79. }
  80. }