Пример #1
0
        internal static void UpdateTitle()
        {
            if (Instance?.ActionBar == null)
            {
                return;
            }

            FragmentHistoryStack.SetHomeUp(Pane.Popover);

            var style = Stack.CurrentLayer == null ? iApp.Instance.Style : Stack.CurrentLayer.LayerStyle;

            ((PopoverActivity)Instance).UpdateHeader(style.HeaderColor);

            var popoverView = Stack.CurrentView as IView;
            var title       = popoverView == null ? iApp.Instance.Title : popoverView.Title;

            Instance.ActionBar.Title = title;
        }
Пример #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            var splash = DroidFactory.MainActivity as SplashActivity;

            if (splash != null)
            {
                DroidFactory.Instance.ViewOutputting -= splash.OnViewOutputting;
            }
            DroidFactory.MainActivity = this;
            base.OnCreate(savedInstanceState);

            if (DroidFactory.TheApp == null)
            {
                Device.Log.Warn($"The app has not been set. Please set {nameof(TargetFactory)}.{nameof(TargetFactory.TheApp)} to this to your app instance.");
                SetContentView(Resource.Layout.main);
            }
            else
            {
                SetContentView(DroidFactory.TheApp.FormFactor != FormFactor.Fullscreen ? Resource.Layout.main : Resource.Layout.fullscreen);
            }

            if (FindViewById(Resource.Id.master_fragment) == null)
            {
                var layoutName = DroidFactory.TheApp.FormFactor != FormFactor.Fullscreen
                    ? nameof(Resource.Layout.main)
                    : nameof(Resource.Layout.fullscreen);
                Device.Log.Fatal($"Master view id @+id/master_fragment not found in layout resource: {layoutName}");
            }

            if (PaneManager.Instance.Any())
            {
                if (DroidFactory.Tabs == null)
                {
                    (PaneManager.Instance.FromNavContext(Pane.Master, 0) as FragmentHistoryStack)?.Align(NavigationType.Tab);
                }
                else
                {
                    DroidFactory.Tabs.Render();
                }

                (PaneManager.Instance.FromNavContext(Pane.Detail, 0) as FragmentHistoryStack)?.Align(NavigationType.Tab);
                var popover = PaneManager.Instance.FromNavContext(Pane.Popover, 0) as FragmentHistoryStack;
                if (popover != null && popover.Views.Any(v => !(v is VanityFragment)))
                {
                    popover.Align(NavigationType.Tab);
                }
            }
            else
            {
                PaneManager.Instance.AddStack(new FragmentHistoryStack(Pane.Master, 0), new iApp.AppNavigationContext {
                    ActivePane = Pane.Master,
                });

                var detail = FindViewById <FrameLayout>(Resource.Id.detail_fragment);
                if (detail != null)
                {
                    var detailStack = new FragmentHistoryStack(Pane.Detail, 0);
                    detailStack.PushView(new VanityFragment {
                        OutputPane = Pane.Detail,
                    });
                    PaneManager.Instance.AddStack(detailStack, detailStack.Context);
                }

                PaneManager.Instance.AddStack(new FragmentHistoryStack(Pane.Popover, 0), new iApp.AppNavigationContext {
                    ActivePane = Pane.Popover,
                });
            }

            if (!iApp.Session.ContainsKey(InitKey))
            {
                return;
            }
            var view = iApp.Session[InitKey] as IMXView;

            iApp.Session.SafeKeys.Remove(InitKey);
            iApp.Session.Remove(InitKey);
            if (view == null)
            {
                return;
            }
            PaneManager.Instance.DisplayView(view);
            var entry = view as IHistoryEntry;

            if (entry != null)
            {
                var stack = (FragmentHistoryStack)PaneManager.Instance.FindStack(view);
                entry.OutputPane = stack.Context.ActivePane;
            }
            Events.RaiseEvent(DroidFactory.Instance, nameof(iApp.Factory.ViewOutputted), new ViewOutputEventArgs(null, view));
        }
Пример #3
0
        internal static void RefreshTitles()
        {
            var actionBar = MainActivity.ActionBar;

            if (actionBar == null)
            {
                return;
            }

            Device.Thread.ExecuteOnMainThread(() => { FragmentHistoryStack.SetHomeUp(Pane.Master); });
            var master     = PaneManager.Instance.FromNavContext(Pane.Master, 0);
            var detail     = PaneManager.Instance.FromNavContext(Pane.Detail, 0);
            var masterView = master?.CurrentView as IView;
            var detailView = detail?.CurrentView as IView;

            var title    = masterView == null ? iApp.Instance?.Title : masterView.Title;
            var subtitle = detailView?.Title;

            if (string.IsNullOrWhiteSpace(subtitle))
            {
                subtitle = null;
            }

            actionBar.NavigationMode = ActionBarNavigationMode.Standard;

            var view = detail ?? master;

            Device.Thread.ExecuteOnMainThread(() =>
            {
                var c = (view?.CurrentView as IView)?.TitleColor;
                if (!c.HasValue || c.Value.IsDefaultColor)
                {
                    actionBar.Title    = title;
                    actionBar.Subtitle = subtitle;
                }
                else
                {
                    if (title == null)
                    {
                        actionBar.TitleFormatted = null;
                    }
                    else
                    {
                        ISpannable text = new SpannableString(title);
                        text.SetSpan(new ForegroundColorSpan(c.Value.ToColor()), 0, text.Length(), SpanTypes.InclusiveInclusive);
                        actionBar.TitleFormatted = text;
                    }

                    if (subtitle == null)
                    {
                        actionBar.SubtitleFormatted = null;
                    }
                    else
                    {
                        ISpannable text = new SpannableString(subtitle);
                        text.SetSpan(new ForegroundColorSpan(c.Value.ToColor()), 0, text.Length(), SpanTypes.InclusiveInclusive);
                        actionBar.SubtitleFormatted = text;
                    }
                }
            });

            UI.Color headerColor;

            if (view?.CurrentLayer != null)
            {
                headerColor = view.CurrentLayer.LayerStyle.HeaderColor;
            }
            else if (view?.CurrentView is IView)
            {
                headerColor = ((IView)view.CurrentView).HeaderColor;
            }
            else if (iApp.Instance != null)
            {
                headerColor = iApp.Instance.Style.HeaderColor;
            }
            else
            {
                return;
            }

            var baseActivity = MainActivity as BaseActivity;

            if (baseActivity != null)
            {
                baseActivity.UpdateHeader(headerColor);
            }
            else
            {
                actionBar.SetBackgroundDrawable(headerColor.ToColorDrawable());
            }
        }