Browse Source
* add tv support to form factor * Resolve comments and add chromium book * Add some documentation --------- Co-authored-by: Max Katz <maxkatz6@outlook.com>pull/14226/head
committed by
GitHub
10 changed files with 137 additions and 8 deletions
@ -0,0 +1,52 @@ |
|||
using System; |
|||
using Android.Content.PM; |
|||
using Android.Content; |
|||
using Avalonia.Platform; |
|||
using App = Android.App.Application; |
|||
using System.Reflection; |
|||
|
|||
namespace Avalonia |
|||
{ |
|||
internal static class AndroidRuntimePlatformServices |
|||
{ |
|||
public static AppBuilder UseAndroidRuntimePlatformSubsystem(this AppBuilder builder) |
|||
{ |
|||
builder.UseRuntimePlatformSubsystem(() => Register(builder.ApplicationType?.Assembly), nameof(AndroidRuntimePlatform)); |
|||
return builder; |
|||
} |
|||
|
|||
public static void Register(Assembly? assembly = null) |
|||
{ |
|||
AssetLoader.RegisterResUriParsers(); |
|||
AvaloniaLocator.CurrentMutable |
|||
.Bind<IRuntimePlatform>().ToSingleton<AndroidRuntimePlatform>() |
|||
.Bind<IAssetLoader>().ToConstant(new StandardAssetLoader(assembly)); |
|||
} |
|||
} |
|||
|
|||
|
|||
internal class AndroidRuntimePlatform : StandardRuntimePlatform |
|||
{ |
|||
private static readonly Lazy<RuntimePlatformInfo> Info = new(() => |
|||
{ |
|||
var isDesktop = IsRunningOnDesktop(App.Context); |
|||
var isTv = IsRunningOnTv(App.Context); |
|||
|
|||
return new RuntimePlatformInfo |
|||
{ |
|||
IsDesktop = isDesktop, |
|||
IsMobile = !isTv && !isDesktop, |
|||
IsTV = isTv |
|||
}; |
|||
}); |
|||
|
|||
private static bool IsRunningOnDesktop(Context context) => |
|||
context.PackageManager.HasSystemFeature("org.chromium.arc") || |
|||
context.PackageManager.HasSystemFeature("org.chromium.arc.device_management"); |
|||
|
|||
private static bool IsRunningOnTv(Context context) => |
|||
context.PackageManager.HasSystemFeature(PackageManager.FeatureLeanback); |
|||
|
|||
public override RuntimePlatformInfo GetRuntimeInfo() => Info.Value; |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
using System.Reflection; |
|||
using Avalonia.Platform; |
|||
|
|||
namespace Avalonia.Tizen; |
|||
|
|||
internal static class TizenRuntimePlatformServices |
|||
{ |
|||
public static AppBuilder UseTizenRuntimePlatformSubsystem(this AppBuilder builder) |
|||
{ |
|||
builder.UseRuntimePlatformSubsystem(() => Register(builder.ApplicationType?.Assembly), nameof(TizenRuntimePlatform)); |
|||
return builder; |
|||
} |
|||
|
|||
public static void Register(Assembly? assembly = null) |
|||
{ |
|||
AssetLoader.RegisterResUriParsers(); |
|||
AvaloniaLocator.CurrentMutable |
|||
.Bind<IRuntimePlatform>().ToSingleton<TizenRuntimePlatform>() |
|||
.Bind<IAssetLoader>().ToConstant(new StandardAssetLoader(assembly)); |
|||
} |
|||
} |
|||
|
|||
internal class TizenRuntimePlatform : StandardRuntimePlatform |
|||
{ |
|||
private static readonly Lazy<RuntimePlatformInfo> Info = new(() => |
|||
{ |
|||
global::Tizen.System.Information.TryGetValue("http://tizen.org/feature/profile", out string profile); |
|||
|
|||
return new RuntimePlatformInfo |
|||
{ |
|||
IsMobile = profile.Equals("mobile", StringComparison.OrdinalIgnoreCase), |
|||
IsTV = profile.Equals("tv", StringComparison.OrdinalIgnoreCase), |
|||
IsDesktop = false |
|||
}; |
|||
}); |
|||
|
|||
public override RuntimePlatformInfo GetRuntimeInfo() => Info.Value; |
|||
} |
|||
Loading…
Reference in new issue