static void SetupInit( IMauiContext mauiContext, UI.Xaml.Window mainWindow, IEnumerable <Assembly> rendererAssemblies = null, InitializationOptions?maybeOptions = null) { MauiContext = mauiContext; Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim); var accent = (WSolidColorBrush)Microsoft.UI.Xaml.Application.Current.Resources["SystemColorControlAccentBrush"]; KnownColor.SetAccent(accent.ToColor()); ExpressionSearch.Default = new WindowsExpressionSearch(); Registrar.ExtraAssemblies = rendererAssemblies?.ToArray(); Device.DefaultRendererAssembly = typeof(Forms).Assembly; if (mainWindow != null) { MainWindow = mainWindow; //if (mainWindow is WindowsBasePage windowsPage) //{ // windowsPage.LoadApplication(windowsPage.CreateApplication()); // windowsPage.Activate(); //} } IsInitialized = true; }
static void SetupInit( IMauiContext mauiContext, UI.Xaml.Window mainWindow, IEnumerable <Assembly> rendererAssemblies = null, InitializationOptions?maybeOptions = null) { MauiContext = mauiContext; Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim); var accent = (WSolidColorBrush)Microsoft.UI.Xaml.Application.Current.Resources["SystemColorControlAccentBrush"]; KnownColor.SetAccent(accent.ToColor()); Device.SetIdiom(TargetIdiom.Tablet); Device.SetFlowDirection(mauiContext.GetFlowDirection()); //TODO WINUI3 //switch (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily) //{ // case "Windows.Desktop": // if (Windows.UI.ViewManagement.UIViewSettings.GetForCurrentView().UserInteractionMode == // Windows.UI.ViewManagement.UserInteractionMode.Touch) // Device.SetIdiom(TargetIdiom.Tablet); // else // Device.SetIdiom(TargetIdiom.Desktop); // break; // case "Windows.Mobile": // Device.SetIdiom(TargetIdiom.Phone); // break; // case "Windows.Xbox": // Device.SetIdiom(TargetIdiom.TV); // break; // default: // Device.SetIdiom(TargetIdiom.Unsupported); // break; //} ExpressionSearch.Default = new WindowsExpressionSearch(); Registrar.ExtraAssemblies = rendererAssemblies?.ToArray(); var platformServices = new WindowsPlatformServices(); Device.PlatformServices = platformServices; Device.PlatformInvalidator = platformServices; if (mainWindow != null) { MainWindow = mainWindow; //if (mainWindow is WindowsBasePage windowsPage) //{ // windowsPage.LoadApplication(windowsPage.CreateApplication()); // windowsPage.Activate(); //} } IsInitialized = true; }
static void SetupInit( IMauiContext context, Assembly resourceAssembly, InitializationOptions?maybeOptions = null ) { var activity = context.Context; Profile.FrameBegin(); Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim); // Allow this multiple times to support the app and then the activity ApplicationContext = activity.ApplicationContext; MauiContext = context; if (!IsInitialized) { // Only need to do this once Profile.FramePartition("ResourceManager.Init"); ResourceManager.Init(resourceAssembly); } Profile.FramePartition("Color.SetAccent()"); // We want this to be updated when we have a new activity (e.g. on a configuration change) // This could change if the UI mode changes (e.g., if night mode is enabled) Application.AccentColor = GetAccentColor(activity); _ColorButtonNormalSet = false; // We want this to be updated when we have a new activity (e.g. on a configuration change) // because AndroidPlatformServices needs a current activity to launch URIs from Profile.FramePartition("Device.PlatformServices"); var androidServices = new AndroidPlatformServices(activity); Device.PlatformServices = androidServices; Profile.FramePartition("RegisterAll"); if (maybeOptions?.Flags.HasFlag(InitializationFlags.SkipRenderers) != true) { RegisterCompatRenderers(context, maybeOptions); } Profile.FramePartition("Epilog"); Device.SetFlowDirection(activity.Resources.Configuration.LayoutDirection.ToFlowDirection()); if (ExpressionSearch.Default == null) { ExpressionSearch.Default = new AndroidExpressionSearch(); } IsInitialized = true; Profile.FrameEnd(); }
public static void Init(IMauiContext context, InitializationOptions?options = null) { Assembly resourceAssembly; Profile.FrameBegin("Assembly.GetCallingAssembly"); resourceAssembly = Assembly.GetCallingAssembly(); Profile.FrameEnd("Assembly.GetCallingAssembly"); Profile.FrameBegin(); SetupInit(context, resourceAssembly, options); Profile.FrameEnd(); }
static void SetupInit(IMauiContext context, InitializationOptions?maybeOptions = null) { MauiContext = context; Microsoft.Maui.Controls.Internals.Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim); Application.AccentColor = Color.FromRgba(50, 79, 133, 255); #if __MOBILE__ Device.SetIdiom(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? TargetIdiom.Tablet : TargetIdiom.Phone); Device.SetFlowDirection(UIApplication.SharedApplication.UserInterfaceLayoutDirection.ToFlowDirection()); #else if (!IsInitialized) { // Only need to do this once // Subscribe to notifications in OS Theme changes NSDistributedNotificationCenter.GetDefaultCenter().AddObserver((NSString)"AppleInterfaceThemeChangedNotification", (n) => { var interfaceStyle = NSUserDefaults.StandardUserDefaults.StringForKey("AppleInterfaceStyle"); var aquaAppearance = NSAppearance.GetAppearance(interfaceStyle == "Dark" ? NSAppearance.NameDarkAqua : NSAppearance.NameAqua); NSApplication.SharedApplication.Appearance = aquaAppearance; Application.Current?.TriggerThemeChanged(new AppThemeChangedEventArgs(interfaceStyle == "Dark" ? OSAppTheme.Dark : OSAppTheme.Light)); }); } Device.SetIdiom(TargetIdiom.Desktop); Device.SetFlowDirection(NSApplication.SharedApplication.UserInterfaceLayoutDirection.ToFlowDirection()); if (IsMojaveOrNewer) { var interfaceStyle = NSUserDefaults.StandardUserDefaults.StringForKey("AppleInterfaceStyle"); var aquaAppearance = NSAppearance.GetAppearance(interfaceStyle == "Dark" ? NSAppearance.NameDarkAqua : NSAppearance.NameAqua); NSApplication.SharedApplication.Appearance = aquaAppearance; } #endif var platformServices = new IOSPlatformServices(); Device.PlatformServices = platformServices; #if __MOBILE__ Device.PlatformInvalidator = platformServices; #endif if (maybeOptions?.Flags.HasFlag(InitializationFlags.SkipRenderers) != true) { RegisterCompatRenderers(); } ExpressionSearch.Default = new iOSExpressionSearch(); IsInitialized = true; }
internal static void RegisterCompatRenderers(IMauiContext context, InitializationOptions?maybeOptions) { if (!IsInitializedRenderers) { IsInitializedRenderers = true; if (maybeOptions.HasValue) { var options = maybeOptions.Value; var handlers = options.Handlers; var flags = options.Flags; var effectScopes = options.EffectScopes; //TODO: ExportCell? //TODO: ExportFont // renderers Registrar.RegisterRenderers(handlers); // effects if (effectScopes != null) { for (var i = 0; i < effectScopes.Length; i++) { var effectScope = effectScopes[0]; Registrar.RegisterEffects(effectScope.Name, effectScope.Effects); } } // css Registrar.RegisterStylesheets(flags); } else { // Only need to do this once Registrar.RegisterAll(new[] { typeof(ExportRendererAttribute), typeof(ExportCellAttribute), typeof(ExportImageSourceHandlerAttribute), typeof(ExportFontAttribute) }, context?.Services?.GetService <IFontRegistrar>()); } } }
static void SetupInit(IMauiContext context, InitializationOptions?maybeOptions = null) { MauiContext = context; Microsoft.Maui.Controls.Internals.Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim); Application.AccentColor = Color.FromRgba(50, 79, 133, 255); Device.DefaultRendererAssembly = typeof(Forms).Assembly; if (maybeOptions?.Flags.HasFlag(InitializationFlags.SkipRenderers) != true) { RegisterCompatRenderers(context); } ExpressionSearch.Default = new iOSExpressionSearch(); IsInitialized = true; }
public static void Init(IActivationState activationState, InitializationOptions?options = null) => Init(activationState.Context, options);
static void SetupInit( Context activity, Assembly resourceAssembly, InitializationOptions?maybeOptions = null ) { Profile.FrameBegin(); Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim); if (!IsInitialized) { // Only need to get this once; it won't change ApplicationContext = activity.ApplicationContext; } #pragma warning disable 618 // Still have to set this up so obsolete code can function Context = activity; #pragma warning restore 618 if (!IsInitialized) { // Only need to do this once Profile.FramePartition("ResourceManager.Init"); ResourceManager.Init(resourceAssembly); } Profile.FramePartition("Color.SetAccent()"); // We want this to be updated when we have a new activity (e.g. on a configuration change) // This could change if the UI mode changes (e.g., if night mode is enabled) Color.SetAccent(GetAccentColor(activity)); _ColorButtonNormalSet = false; if (!IsInitialized) { // Only need to do this once Profile.FramePartition("Log.Listeners"); Internals.Log.Listeners.Add(new DelegateLogListener((c, m) => Trace.WriteLine(m, c))); } // We want this to be updated when we have a new activity (e.g. on a configuration change) // because AndroidPlatformServices needs a current activity to launch URIs from Profile.FramePartition("Device.PlatformServices"); var androidServices = new AndroidPlatformServices(activity); Device.PlatformServices = androidServices; Device.PlatformInvalidator = androidServices; // use field and not property to avoid exception in getter if (Device.info != null) { ((AndroidDeviceInfo)Device.info).Dispose(); Device.info = null; } // We want this to be updated when we have a new activity (e.g. on a configuration change) // because Device.Info watches for orientation changes and we need a current activity for that Profile.FramePartition("create AndroidDeviceInfo"); Device.Info = new AndroidDeviceInfo(activity); Profile.FramePartition("setFlags"); Device.SetFlags(s_flags); Profile.FramePartition("AndroidTicker"); Ticker.SetDefault(null); Profile.FramePartition("RegisterAll"); if (!IsInitialized) { if (maybeOptions.HasValue) { var options = maybeOptions.Value; var handlers = options.Handlers; var flags = options.Flags; var effectScopes = options.EffectScopes; //TODO: ExportCell? //TODO: ExportFont // renderers Registrar.RegisterRenderers(handlers); // effects if (effectScopes != null) { for (var i = 0; i < effectScopes.Length; i++) { var effectScope = effectScopes[0]; Registrar.RegisterEffects(effectScope.Name, effectScope.Effects); } } // css Registrar.RegisterStylesheets(flags); } else { // Only need to do this once Registrar.RegisterAll(new[] { typeof(ExportRendererAttribute), typeof(ExportCellAttribute), typeof(ExportImageSourceHandlerAttribute), typeof(ExportFontAttribute) }); } } Profile.FramePartition("Epilog"); var currentIdiom = TargetIdiom.Unsupported; // First try UIModeManager using (var uiModeManager = UiModeManager.FromContext(ApplicationContext)) { try { var uiMode = uiModeManager?.CurrentModeType ?? UiMode.TypeUndefined; currentIdiom = DetectIdiom(uiMode); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Unable to detect using UiModeManager: {ex.Message}"); } } // Then try Configuration if (TargetIdiom.Unsupported == currentIdiom) { var configuration = activity.Resources.Configuration; if (configuration != null) { var minWidth = configuration.SmallestScreenWidthDp; var isWide = minWidth >= TabletCrossover; currentIdiom = isWide ? TargetIdiom.Tablet : TargetIdiom.Phone; } else { // Start clutching at straws var metrics = activity.Resources?.DisplayMetrics; if (metrics != null) { var minSize = Math.Min(metrics.WidthPixels, metrics.HeightPixels); var isWide = minSize * metrics.Density >= TabletCrossover; currentIdiom = isWide ? TargetIdiom.Tablet : TargetIdiom.Phone; } } } Device.SetIdiom(currentIdiom); if (SdkInt >= BuildVersionCodes.JellyBeanMr1) { Device.SetFlowDirection(activity.Resources.Configuration.LayoutDirection.ToFlowDirection()); } if (ExpressionSearch.Default == null) { ExpressionSearch.Default = new AndroidExpressionSearch(); } IsInitialized = true; Profile.FrameEnd(); }
static void SetupInit( Context activity, Assembly resourceAssembly, InitializationOptions?maybeOptions = null ) { Profile.FrameBegin(); if (!IsInitialized) { // Only need to get this once; it won't change ApplicationContext = activity.ApplicationContext; } #pragma warning disable 618 // Still have to set this up so obsolete code can function Context = activity; #pragma warning restore 618 if (!IsInitialized) { // Only need to do this once Profile.FramePartition("ResourceManager.Init"); ResourceManager.Init(resourceAssembly); } Profile.FramePartition("Color.SetAccent()"); // We want this to be updated when we have a new activity (e.g. on a configuration change) // This could change if the UI mode changes (e.g., if night mode is enabled) Color.SetAccent(GetAccentColor(activity)); _ColorButtonNormalSet = false; if (!IsInitialized) { // Only need to do this once Profile.FramePartition("Log.Listeners"); Internals.Log.Listeners.Add(new DelegateLogListener((c, m) => Trace.WriteLine(m, c))); } // We want this to be updated when we have a new activity (e.g. on a configuration change) // because AndroidPlatformServices needs a current activity to launch URIs from Profile.FramePartition("Device.PlatformServices"); Device.PlatformServices = new AndroidPlatformServices(activity); // use field and not property to avoid exception in getter if (Device.info != null) { ((AndroidDeviceInfo)Device.info).Dispose(); Device.info = null; } // We want this to be updated when we have a new activity (e.g. on a configuration change) // because Device.Info watches for orientation changes and we need a current activity for that Profile.FramePartition("create AndroidDeviceInfo"); Device.Info = new AndroidDeviceInfo(activity); Profile.FramePartition("setFlags"); Device.SetFlags(s_flags); Profile.FramePartition("AndroidTicker"); Ticker.SetDefault(null); Profile.FramePartition("RegisterAll"); if (!IsInitialized) { if (maybeOptions.HasValue) { var options = maybeOptions.Value; var handlers = options.Handlers; var flags = options.Flags; var effectScopes = options.EffectScopes; // renderers Registrar.RegisterRenderers(handlers); // effects if (effectScopes != null) { for (var i = 0; i < effectScopes.Length; i++) { var effectScope = effectScopes[0]; Registrar.RegisterEffects(effectScope.Name, effectScope.Effects); } } // css var noCss = (flags & InitializationFlags.DisableCss) != 0; if (!noCss) { Registrar.RegisterStylesheets(); } } else { // Only need to do this once Registrar.RegisterAll(new[] { typeof(ExportRendererAttribute), typeof(ExportCellAttribute), typeof(ExportImageSourceHandlerAttribute) }); } } Profile.FramePartition("Epilog"); // This could change as a result of a config change, so we need to check it every time int minWidthDp = activity.Resources.Configuration.SmallestScreenWidthDp; Device.SetIdiom(minWidthDp >= TabletCrossover ? TargetIdiom.Tablet : TargetIdiom.Phone); if (SdkInt >= BuildVersionCodes.JellyBeanMr1) { Device.SetFlowDirection(activity.Resources.Configuration.LayoutDirection.ToFlowDirection()); } if (ExpressionSearch.Default == null) { ExpressionSearch.Default = new AndroidExpressionSearch(); } IsInitialized = true; Profile.FrameEnd(); }
static void SetupInit( IMauiContext mauiContext, UI.Xaml.LaunchActivatedEventArgs launchActivatedEventArgs, WindowsBasePage mainWindow, IEnumerable <Assembly> rendererAssemblies = null, InitializationOptions?maybeOptions = null) { MauiContext = mauiContext; Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim); var accent = (WSolidColorBrush)Microsoft.UI.Xaml.Application.Current.Resources["SystemColorControlAccentBrush"]; KnownColor.SetAccent(accent.ToFormsColor()); if (!IsInitialized) { #if !UWP_16299 Log.Listeners.Add(new DelegateLogListener((c, m) => Debug.WriteLine(LogFormat, c, m))); #else Log.Listeners.Add(new DelegateLogListener((c, m) => Trace.WriteLine(m, c))); #endif } if (!UI.Xaml.Application.Current.Resources.ContainsKey("RootContainerStyle")) { UI.Xaml.Application.Current.Resources.MergedDictionaries.Add(GetTabletResources()); } try { UI.Xaml.Application.Current.Resources.MergedDictionaries.Add(new UI.Xaml.Controls.XamlControlsResources()); } catch { Log.Warning("Resources", "Unable to load WinUI resources. Try adding Microsoft.Maui.Controls.Compatibility nuget to UWP project"); } Device.SetIdiom(TargetIdiom.Tablet); Device.SetFlowDirection(GetFlowDirection()); Device.SetFlags(s_flags); //TODO WINUI3 //// use field and not property to avoid exception in getter //if (Device.info != null) //{ // Device.info.Dispose(); // Device.info = null; //} //Device.Info = new WindowsDeviceInfo(); //TODO WINUI3 //switch (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily) //{ // case "Windows.Desktop": // if (Windows.UI.ViewManagement.UIViewSettings.GetForCurrentView().UserInteractionMode == // Windows.UI.ViewManagement.UserInteractionMode.Touch) // Device.SetIdiom(TargetIdiom.Tablet); // else // Device.SetIdiom(TargetIdiom.Desktop); // break; // case "Windows.Mobile": // Device.SetIdiom(TargetIdiom.Phone); // break; // case "Windows.Xbox": // Device.SetIdiom(TargetIdiom.TV); // break; // default: // Device.SetIdiom(TargetIdiom.Unsupported); // break; //} ExpressionSearch.Default = new WindowsExpressionSearch(); Registrar.ExtraAssemblies = rendererAssemblies?.ToArray(); s_state = launchActivatedEventArgs.UWPLaunchActivatedEventArgs.PreviousExecutionState; var dispatcher = mainWindow?.DispatcherQueue ?? System.DispatcherQueue.GetForCurrentThread(); var platformServices = new WindowsPlatformServices(dispatcher); Device.PlatformServices = platformServices; Device.PlatformInvalidator = platformServices; if (maybeOptions?.Flags.HasFlag(InitializationFlags.SkipRenderers) != true) { RegisterCompatRenderers(); } if (mainWindow != null) { MainWindow = mainWindow; //TODO WINUI3 Platform.UWP.Platform.SubscribeAlertsAndActionSheets(); mainWindow.LoadApplication(mainWindow.CreateApplication()); mainWindow.Activate(); } IsInitialized = true; }
public static void Init(IActivationState state, InitializationOptions?options = null) { SetupInit(state.Context, state.Context.GetOptionalPlatformWindow(), maybeOptions: options); }
static void SetupInit(CoreApplication application, InitializationOptions?maybeOptions = null) { Context = application; if (!IsInitialized) { Internals.Log.Listeners.Add(new XamarinLogListener()); if (System.Threading.SynchronizationContext.Current == null) { TizenSynchronizationContext.Initialize(); } Elementary.Initialize(); Elementary.ThemeOverlay(); } Device.PlatformServices = new TizenPlatformServices(); if (Device.info != null) { ((TizenDeviceInfo)Device.info).Dispose(); Device.info = null; } Device.Info = new Forms.TizenDeviceInfo(); Device.SetFlags(s_flags); if (!Forms.IsInitialized) { if (maybeOptions.HasValue) { var options = maybeOptions.Value; _useDeviceIndependentPixel = options.UseDeviceIndependentPixel; if (options.Assemblies != null) { TizenPlatformServices.AppDomain.CurrentDomain.AddAssemblies(options.Assemblies); } // renderers if (options.Handlers != null) { Registrar.RegisterRenderers(options.Handlers); } else { Registrar.RegisterAll(new Type[] { typeof(ExportRendererAttribute), typeof(ExportImageSourceHandlerAttribute), typeof(ExportCellAttribute), typeof(ExportHandlerAttribute) }); } // effects var effectScopes = options.EffectScopes; if (effectScopes != null) { for (var i = 0; i < effectScopes.Length; i++) { var effectScope = effectScopes[0]; Registrar.RegisterEffects(effectScope.Name, effectScope.Effects); } } // css var flags = options.Flags; var noCss = (flags & InitializationFlags.DisableCss) != 0; if (!noCss) { Registrar.RegisterStylesheets(); } } else { // In .NETCore, AppDomain feature is not supported. // The list of assemblies returned by AppDomain.GetAssemblies() method should be registered manually. // The assembly of the executing application and referenced assemblies of it are added into the list here. TizenPlatformServices.AppDomain.CurrentDomain.RegisterAssemblyRecursively(application.GetType().GetTypeInfo().Assembly); Registrar.RegisterAll(new Type[] { typeof(ExportRendererAttribute), typeof(ExportImageSourceHandlerAttribute), typeof(ExportCellAttribute), typeof(ExportHandlerAttribute) }); } } string profile = ((TizenDeviceInfo)Device.Info).Profile; if (profile == "mobile") { Device.SetIdiom(TargetIdiom.Phone); } else if (profile == "tv") { Device.SetIdiom(TargetIdiom.TV); } else if (profile == "desktop") { Device.SetIdiom(TargetIdiom.Desktop); } else if (profile == "wearable") { Device.SetIdiom(TargetIdiom.Watch); } else { Device.SetIdiom(TargetIdiom.Unsupported); } Color.SetAccent(GetAccentColor(profile)); ExpressionSearch.Default = new TizenExpressionSearch(); IsInitialized = true; }
static void SetupInit( IMauiContext context, Assembly resourceAssembly, InitializationOptions?maybeOptions = null ) { var activity = context.Context; Profile.FrameBegin(); Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim); // Allow this multiple times to support the app and then the activity ApplicationContext = activity.ApplicationContext; MauiContext = context; if (!IsInitialized) { // Only need to do this once Profile.FramePartition("ResourceManager.Init"); ResourceManager.Init(resourceAssembly); } Profile.FramePartition("Color.SetAccent()"); // We want this to be updated when we have a new activity (e.g. on a configuration change) // This could change if the UI mode changes (e.g., if night mode is enabled) Application.AccentColor = GetAccentColor(activity); _ColorButtonNormalSet = false; if (!IsInitialized) { // Only need to do this once Profile.FramePartition("Log.Listeners"); Internals.Log.Listeners.Add(new DelegateLogListener((c, m) => Trace.WriteLine(m, c))); } // We want this to be updated when we have a new activity (e.g. on a configuration change) // because AndroidPlatformServices needs a current activity to launch URIs from Profile.FramePartition("Device.PlatformServices"); var androidServices = new AndroidPlatformServices(activity); Device.PlatformServices = androidServices; Device.PlatformInvalidator = androidServices; // use field and not property to avoid exception in getter if (Device.info != null) { ((AndroidDeviceInfo)Device.info).Dispose(); Device.info = null; } // We want this to be updated when we have a new activity (e.g. on a configuration change) // because Device.Info watches for orientation changes and we need a current activity for that Profile.FramePartition("create AndroidDeviceInfo"); Device.Info = new AndroidDeviceInfo(activity); Profile.FramePartition("setFlags"); Device.SetFlags(s_flags); Profile.FramePartition("AndroidTicker"); Ticker.SetDefault(null); Profile.FramePartition("RegisterAll"); if (maybeOptions?.Flags.HasFlag(InitializationFlags.SkipRenderers) != true) { RegisterCompatRenderers(maybeOptions); } Profile.FramePartition("Epilog"); var currentIdiom = TargetIdiom.Unsupported; // First try UIModeManager using (var uiModeManager = UiModeManager.FromContext(ApplicationContext)) { try { var uiMode = uiModeManager?.CurrentModeType ?? UiMode.TypeUndefined; currentIdiom = DetectIdiom(uiMode); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Unable to detect using UiModeManager: {ex.Message}"); } } // Then try Configuration if (TargetIdiom.Unsupported == currentIdiom) { var configuration = activity.Resources.Configuration; if (configuration != null) { var minWidth = configuration.SmallestScreenWidthDp; var isWide = minWidth >= TabletCrossover; currentIdiom = isWide ? TargetIdiom.Tablet : TargetIdiom.Phone; } else { // Start clutching at straws var metrics = activity.Resources?.DisplayMetrics; if (metrics != null) { var minSize = Math.Min(metrics.WidthPixels, metrics.HeightPixels); var isWide = minSize * metrics.Density >= TabletCrossover; currentIdiom = isWide ? TargetIdiom.Tablet : TargetIdiom.Phone; } } } Device.SetIdiom(currentIdiom); if (SdkInt >= BuildVersionCodes.JellyBeanMr1) { Device.SetFlowDirection(activity.Resources.Configuration.LayoutDirection.ToFlowDirection()); } if (ExpressionSearch.Default == null) { ExpressionSearch.Default = new AndroidExpressionSearch(); } IsInitialized = true; Profile.FrameEnd(); }
public static void Init(IActivationState state, InitializationOptions?options = null) { SetupInit(state.Context, null, maybeOptions: options); }
static void SetupInit( IMauiContext mauiContext, UI.Xaml.Window mainWindow, IEnumerable <Assembly> rendererAssemblies = null, InitializationOptions?maybeOptions = null) { MauiContext = mauiContext; Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim); var accent = (WSolidColorBrush)Microsoft.UI.Xaml.Application.Current.Resources["SystemColorControlAccentBrush"]; KnownColor.SetAccent(accent.ToColor()); if (!IsInitialized) { Log.Listeners.Add(new DelegateLogListener((c, m) => Debug.WriteLine(LogFormat, c, m))); } Device.SetIdiom(TargetIdiom.Tablet); Device.SetFlowDirection(mauiContext.GetFlowDirection()); Device.SetFlags(s_flags); Device.Info = new WindowsDeviceInfo(); //TODO WINUI3 //// use field and not property to avoid exception in getter //if (Device.info != null) //{ // Device.info.Dispose(); // Device.info = null; //} //Device.Info = new WindowsDeviceInfo(); //TODO WINUI3 //switch (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily) //{ // case "Windows.Desktop": // if (Windows.UI.ViewManagement.UIViewSettings.GetForCurrentView().UserInteractionMode == // Windows.UI.ViewManagement.UserInteractionMode.Touch) // Device.SetIdiom(TargetIdiom.Tablet); // else // Device.SetIdiom(TargetIdiom.Desktop); // break; // case "Windows.Mobile": // Device.SetIdiom(TargetIdiom.Phone); // break; // case "Windows.Xbox": // Device.SetIdiom(TargetIdiom.TV); // break; // default: // Device.SetIdiom(TargetIdiom.Unsupported); // break; //} ExpressionSearch.Default = new WindowsExpressionSearch(); Registrar.ExtraAssemblies = rendererAssemblies?.ToArray(); var dispatcher = mainWindow?.DispatcherQueue ?? UI.Dispatching.DispatcherQueue.GetForCurrentThread(); var platformServices = new WindowsPlatformServices(dispatcher); Device.PlatformServices = platformServices; Device.PlatformInvalidator = platformServices; if (mainWindow != null) { MainWindow = mainWindow; //if (mainWindow is WindowsBasePage windowsPage) //{ // windowsPage.LoadApplication(windowsPage.CreateApplication()); // windowsPage.Activate(); //} } IsInitialized = true; }