コード例 #1
0
        static void SetupInit(CoreApplication application, InitializationOptions options = null)
        {
            Context = application;

            if (!IsInitialized)
            {
                Internals.Log.Listeners.Add(new XamarinLogListener());
                if (System.Threading.SynchronizationContext.Current == null)
                {
                    TizenSynchronizationContext.Initialize();
                }

                Elementary.Initialize();
                Elementary.ThemeOverlay();
                Utility.AppendGlobalFontPath(@"/usr/share/fonts");
            }

            Device.PlatformServices = new TizenPlatformServices();
            if (Device.info != null)
            {
                ((TizenDeviceInfo)Device.info).Dispose();
                Device.info = null;
            }

            Device.Info = new Forms.TizenDeviceInfo();
            Device.SetFlags(s_flags);

            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);
            }

            if (!Forms.IsInitialized)
            {
                if (options != null)
                {
                    s_platformType       = options.PlatformType;
                    s_useMessagingCenter = options.UseMessagingCenter;

                    if (options.Assemblies != null && options.Assemblies.Length > 0)
                    {
                        TizenPlatformServices.AppDomain.CurrentDomain.AddAssemblies(options.Assemblies);
                    }

                    // renderers
                    if (options.Handlers != null)
                    {
                        Registrar.RegisterRenderers(options.Handlers);
                    }
                    else
                    {
                        // Add Xamarin.Forms.Core assembly by default to apply the styles.
                        TizenPlatformServices.AppDomain.CurrentDomain.AddAssembly(Assembly.GetAssembly(typeof(Xamarin.Forms.View)));

                        // static registrar
                        if (options.StaticRegistarStrategy != StaticRegistrarStrategy.None)
                        {
                            s_staticRegistrarStrategy = options.StaticRegistarStrategy;
                            StaticRegistrar.RegisterHandlers(options.CustomHandlers);

                            if (options.StaticRegistarStrategy == StaticRegistrarStrategy.All)
                            {
                                Registrar.RegisterAll(new Type[]
                                {
                                    typeof(ExportRendererAttribute),
                                    typeof(ExportImageSourceHandlerAttribute),
                                    typeof(ExportCellAttribute),
                                    typeof(ExportHandlerAttribute),
                                    typeof(ExportFontAttribute)
                                });
                            }
                        }
                        else
                        {
                            Registrar.RegisterAll(new Type[]
                            {
                                typeof(ExportRendererAttribute),
                                typeof(ExportImageSourceHandlerAttribute),
                                typeof(ExportCellAttribute),
                                typeof(ExportHandlerAttribute),
                                typeof(ExportFontAttribute)
                            });
                        }
                    }

                    // 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
                    Registrar.RegisterStylesheets(options.Flags);
                }
                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),
                        typeof(ExportFontAttribute)
                    });
                }
            }

            Color.SetAccent(GetAccentColor(profile));
            ExpressionSearch.Default = new TizenExpressionSearch();

            if (application is WatchApplication)
            {
                s_platformType = PlatformType.Lightweight;
            }

            IsInitialized = true;
        }
コード例 #2
0
ファイル: Forms.cs プロジェクト: wmhang/Xamarin.Forms
        static void SetupInit(
            Context activity,
            Assembly resourceAssembly,
            ActivationOptions?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("new AndroidDeviceInfo(activity)");
            Device.Info = new AndroidDeviceInfo(activity);
            Device.SetFlags(s_flags);

            Profile.FramePartition("AndroidTicker");

            var ticker = Ticker.Default as AndroidTicker;
            if (ticker != null)
            {
                ticker.Dispose();
            }
            Ticker.SetDefault(new AndroidTicker());

            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 & ActivationFlags.NoCss) != 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 (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBeanMr1)
            {
                Device.SetFlowDirection(activity.Resources.Configuration.LayoutDirection.ToFlowDirection());
            }

            if (ExpressionSearch.Default == null)
            {
                ExpressionSearch.Default = new AndroidExpressionSearch();
            }

            IsInitialized = true;
            Profile.FrameEnd();
        }
コード例 #3
0
ファイル: Forms.cs プロジェクト: RomanKhabarov/Maui
        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();
        }
コード例 #4
0
ファイル: Forms.cs プロジェクト: zdanovs/Xamarin.Forms
        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;
        }