public override bool Load(IModuleContext context)
        {
            var mediatorFactory = AndroidToolkitExtensions.MediatorFactory;

            AndroidToolkitExtensions.MediatorFactory = (o, dataContext, arg3) =>
            {
                return(AndroidToolkitExtensions.MvvmActivityMediatorDefaultFactory(o, dataContext, arg3) ?? mediatorFactory?.Invoke(o, dataContext, arg3));
            };
            AndroidToolkitExtensions.LayoutInflaterFactory = (c, dataContext, factory, inflater) =>
            {
                if (inflater == null)
                {
                    Tracer.Error("The bindable inflater cannot be created without the original inflater");
                    return(null);
                }
                LayoutInflaterFactoryWrapper.SetFactory(inflater, factory);
                return(inflater);
            };
            AndroidToolkitExtensions.MenuInflaterFactory = (c, baseMenuInflater, ctx) => new BindableMenuInflater(c)
            {
                NestedMenuInflater = baseMenuInflater
            };
            AndroidToolkitExtensions.GetContentView = AndroidToolkitExtensions.GetContentViewDefault;
            AndroidToolkitExtensions.AddContentViewManager(new ViewContentViewManager());

            BindNavigationService(context, context.IocContainer);
            BindViewFactory(context, context.IocContainer);

            return(base.Load(context));
        }
        private void SetIndicator(TabHost.TabSpec tabSpec, object item)
        {
            (item as IViewModel)?.Settings.Metadata.AddOrUpdate(ViewModelConstants.StateNotNeeded, true);
            var templateId = _itemTemplateProvider.GetTemplateId();
            var selector   = _itemTemplateProvider.GetDataTemplateSelector();

            if (templateId == null && selector == null)
            {
                selector = EmptyTemplateSelector.Instance;
            }
            object content = AndroidToolkitExtensions.GetContentView(TabHost, TabHost.Context, item, templateId, selector);

            if (content == EmptyTemplateSelector.EmptyView)
            {
                content = null;
                if (item is IHasDisplayName)
                {
                    BindingServiceProvider.BindingProvider.CreateBindingsFromString(tabSpec, "Title DisplayName", null);
                }
                else
                {
                    tabSpec.SetIndicator(item.ToStringSafe("(null)"));
                }
            }
            var view = content as View;

            if (view == null)
            {
                tabSpec.SetIndicator(content.ToStringSafe("(null)"));
            }
            else
            {
                tabSpec.SetIndicator(view);
            }
        }
 public void OnActivityDestroyed(Activity activity)
 {
     if (IsAlive() && !(activity is IActivityView))
     {
         AndroidToolkitExtensions.SetCurrentActivity(activity, true);
     }
 }
Beispiel #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            var content = _viewId.HasValue
                ? LayoutInflater.Inflate(_viewId.Value, null)
                : CreateDefaultView();

            if (content != null)
            {
                SetContentView(content);
            }

            if (Interlocked.Exchange(ref _state, StartedState) == DefaultState)
            {
                AndroidToolkitExtensions.SetCurrentActivity(this, false);
                if (AndroidBootstrapperBase.Current != null && AndroidBootstrapperBase.Current.IsInitialized)
                {
                    StartBootstrapperCallback(this);
                }
                else
                {
                    ThreadPool.QueueUserWorkItem(StartBootstrapperCallback, this);
                }
            }
        }
Beispiel #5
0
        public void Apply(IMenu menu, Context context, object parent)
        {
            AndroidToolkitExtensions.ValidateTemplate(ItemsSource, Items);
            var setter = new XmlPropertySetter(menu, context);

            menu.SetBindingMemberValue(AttachedMembers.Object.Parent, parent);
            setter.SetBinding(nameof(DataContext), DataContext, false);
            setter.SetBoolProperty(nameof(IsVisible), IsVisible);
            setter.SetBoolProperty(nameof(IsEnabled), IsEnabled);
            if (!string.IsNullOrEmpty(Bind))
            {
                setter.Bind(menu, Bind);
            }
            if (string.IsNullOrEmpty(ItemsSource))
            {
                if (Items != null)
                {
                    for (int index = 0; index < Items.Count; index++)
                    {
                        Items[index].Apply(menu, context, index, index);
                    }
                }
            }
            else
            {
                menu.SetBindingMemberValue(AttachedMembers.Menu.ItemsSourceGenerator, new MenuItemsSourceGenerator(menu, context, ItemTemplate));
                setter.SetBinding(nameof(ItemsSource), ItemsSource, true);
            }
            setter.Apply();
        }
Beispiel #6
0
 public virtual MenuInflater GetMenuInflater(MenuInflater baseMenuInflater)
 {
     if (_menuInflater == null)
     {
         _menuInflater = AndroidToolkitExtensions.MenuInflaterFactory(Target, baseMenuInflater, MugenMvvmToolkit.Models.DataContext.Empty);
     }
     return(_menuInflater ?? baseMenuInflater);
 }
Beispiel #7
0
 public virtual void OnViewCreated(View view, Bundle savedInstanceState, Action <View, Bundle> baseOnViewCreated)
 {
     if (!(Target is DialogFragment))
     {
         AndroidToolkitExtensions.NotifyActivityAttached(Target.Activity, view);
     }
     baseOnViewCreated(view, savedInstanceState);
 }
Beispiel #8
0
 public void OnActivityDestroyed(Activity activity)
 {
     Interlocked.Decrement(ref _activityCounter);
     if (IsAlive() && !(activity is IActivityView))
     {
         AndroidToolkitExtensions.SetCurrentActivity(activity, true);
     }
 }
 private void RaiseNew(Activity activity)
 {
     if (IsAlive() && !(activity is IActivityView) && _service.CurrentContent != activity)
     {
         AndroidToolkitExtensions.SetCurrentActivity(activity, false);
         _service.RaiseNavigated(activity, NavigationMode.New, null, null);
     }
 }
Beispiel #10
0
        private static void ActionBarUpdateItemsSource(ActionBar actionBar)
        {
            switch (actionBar.GetNavigationMode())
            {
            case ActionBarNavigationMode.List:
#if APPCOMPAT
                IItemsSourceAdapter sourceAdapter = actionBar.GetBindingMemberValue(AttachedMembersCompat.ActionBar.ItemsSourceAdapter);
#else
                IItemsSourceAdapter sourceAdapter = actionBar.GetBindingMemberValue(AttachedMembers.ActionBar.ItemsSourceAdapter);
#endif
                if (sourceAdapter == null)
                {
                    sourceAdapter = AndroidToolkitExtensions.ItemsSourceAdapterFactory(actionBar, actionBar.ThemedContext, DataContext.Empty);
#if APPCOMPAT
                    actionBar.SetBindingMemberValue(AttachedMembersCompat.ActionBar.ItemsSourceAdapter, sourceAdapter);
#else
                    actionBar.SetBindingMemberValue(AttachedMembers.ActionBar.ItemsSourceAdapter, sourceAdapter);
#endif
                    actionBar.SetListNavigationCallbacks(sourceAdapter, new ActionBarNavigationListener(actionBar));
                }
#if APPCOMPAT
                sourceAdapter.ItemsSource = actionBar.GetBindingMemberValue(AttachedMembersCompat.ActionBar.ItemsSource);
#else
                sourceAdapter.ItemsSource = actionBar.GetBindingMemberValue(AttachedMembers.ActionBar.ItemsSource);
#endif
                break;

            case ActionBarNavigationMode.Standard:
#if APPCOMPAT
                actionBar.SetBindingMemberValue(AttachedMembersCompat.ActionBar.SelectedItem, BindingExtensions.NullValue);
#else
                actionBar.SetBindingMemberValue(AttachedMembers.ActionBar.SelectedItem, BindingExtensions.NullValue);
#endif

                actionBar.SetListNavigationCallbacks(null, null);
#if APPCOMPAT
                actionBar.GetBindingMemberValue(AttachedMembersCompat.ActionBar.ItemsSourceGenerator)?.SetItemsSource(null);
                var adapter = actionBar.GetBindingMemberValue(AttachedMembersCompat.ActionBar.ItemsSourceAdapter);
#else
                actionBar.GetBindingMemberValue(AttachedMembers.ActionBar.ItemsSourceGenerator)?.SetItemsSource(null);
                var adapter = actionBar.GetBindingMemberValue(AttachedMembers.ActionBar.ItemsSourceAdapter);
#endif
                if (adapter != null)
                {
                    adapter.ItemsSource = null;
                }
                break;

            case ActionBarNavigationMode.Tabs:
#if APPCOMPAT
                actionBar.GetBindingMemberValue(AttachedMembersCompat.ActionBar.ItemsSourceGenerator)?.SetItemsSource(actionBar.GetBindingMemberValue(AttachedMembersCompat.ActionBar.ItemsSource));
#else
                actionBar.GetBindingMemberValue(AttachedMembers.ActionBar.ItemsSourceGenerator)?.SetItemsSource(actionBar.GetBindingMemberValue(AttachedMembers.ActionBar.ItemsSource));
#endif

                break;
            }
        }
Beispiel #11
0
 private void ClearView()
 {
     if (_view != null)
     {
         _view.ClearBindingsRecursively(true, true, AndroidToolkitExtensions.AggressiveViewCleanup);
         _view = null;
         AndroidToolkitExtensions.CleanupWeakReferences(false);
     }
 }
Beispiel #12
0
 internal ViewGroupItemsSourceGenerator([NotNull] ViewGroup viewGroup)
 {
     Should.NotBeNull(viewGroup, nameof(viewGroup));
     _viewGroup = viewGroup;
     _adapter   = AndroidToolkitExtensions.ItemsSourceAdapterFactory(viewGroup, viewGroup.Context, Context);
     _collectionViewManagerMember = BindingServiceProvider
                                    .MemberProvider
                                    .GetBindingMember(viewGroup.GetType(), AttachedMembers.ViewGroup.CollectionViewManager, false, false);
     TryListenActivity(viewGroup.Context);
 }
Beispiel #13
0
 public LayoutInflater GetLayoutInflater(LayoutInflater baseLayoutInflater)
 {
     if (!_isCreated)
     {
         return(baseLayoutInflater);
     }
     if (_layoutInflater == null)
     {
         _layoutInflater = AndroidToolkitExtensions.LayoutInflaterFactory(Target, null, null, baseLayoutInflater);
     }
     return(_layoutInflater ?? baseLayoutInflater);
 }
Beispiel #14
0
        public virtual void OnStart(Action baseOnStart)
        {
            if (!_isStarted)
            {
                AndroidToolkitExtensions.NotifyActivityAttached(Target, _view);
                _isStarted = true;
            }
            baseOnStart();

            var service = Get <INavigationService>();

            service.OnStartActivity(Target, NavigationContext);
            Started?.Invoke(Target, EventArgs.Empty);
        }
        public object Convert(object value, Type targetType = null, object parameter = null, CultureInfo culture = null)
#endif

        {
            try
            {
                var ctx = (parameter as DataContext).ToNonReadOnly();
                if (!string.IsNullOrEmpty(ViewName))
                {
                    ctx.AddOrUpdate(NavigationConstants.ViewName, ViewName);
                }
#if ANDROID
                return(AndroidToolkitExtensions.GetOrCreateView((IViewModel)value, AlwaysCreateNewView, ctx));
#else
                return(ToolkitServiceProvider.ViewManager.GetOrCreateView((IViewModel)value, AlwaysCreateNewView, ctx));
#endif
            }
            catch (Exception exception) when(!ThrowOnError)
            {
                Tracer.Error(exception.Flatten(true));
#if ANDROID
                var txt = new TextView(parameter as Context ?? Application.Context)
                {
                    Text = exception.Flatten(true)
                };
                txt.SetTextColor(Color.Red);
                return(txt);
#elif TOUCH
                return(new UITextView(new RectangleF(10, 10, 300, 30))
                {
                    TextColor = UIColor.Red, Editable = false, DataDetectorTypes = UIDataDetectorType.None, Text = exception.Flatten(true)
                });
#elif XAMARIN_FORMS
                return(new Label {
                    TextColor = Color.Red, Text = exception.Flatten(true)
                });
#else
                return(new TextBox
                {
                    Text = exception.Flatten(true),
#if WINFORMS
                    ReadOnly = true,
                    WordWrap = true,
                    ForeColor = Color.Red
#else
                    IsReadOnly = true,
                    TextWrapping = TextWrapping.Wrap,
                    Foreground = new SolidColorBrush(Colors.Red)
#endif
                });
Beispiel #16
0
        public override void OnDestroy(Action baseOnDestroy)
        {
            if (Tracer.TraceInformation)
            {
                Tracer.Info($"OnDestroy activity({Target})");
            }
            ServiceProvider.EventAggregator.Unsubscribe(this);
            Destroyed?.Invoke(Target, EventArgs.Empty);
            _view.ClearBindingsRecursively(true, true, AndroidToolkitExtensions.AggressiveViewCleanup);
            _view = null;

            if (_metadata != null)
            {
                _metadata.Clear();
                _metadata = null;
            }

            MenuTemplate.Clear(_menu);
            _menu = null;

            if (_menuInflater != null)
            {
                _menuInflater.Dispose();
                _menuInflater = null;
            }
            if (_layoutInflater != null)
            {
                _layoutInflater.Dispose();
                _layoutInflater = null;
            }
            ServiceProvider.Get <INavigationService>().OnDestroyActivity(Target, NavigationContext);
            base.OnDestroy(baseOnDestroy);
            ThreadPool.QueueUserWorkItem(state => AndroidToolkitExtensions.CleanupWeakReferences(true));
            AndroidToolkitExtensions.SetCurrentActivity(Target, true);
            Target.ClearBindings(false, true);
            OptionsItemSelected  = null;
            ActivityResult       = null;
            ConfigurationChanged = null;
            PostCreate           = null;
            BackPressing         = null;
            Created           = null;
            Started           = null;
            Paused            = null;
            SaveInstanceState = null;
            Stoped            = null;
            Restarted         = null;
            Resume            = null;
            Destroyed         = null;
        }
Beispiel #17
0
        private void ApplyInternal(IMenu menu, Context context, int id, int order, object dataContext, bool useContext)
        {
            AndroidToolkitExtensions.ValidateTemplate(ItemsSource, Items);
            bool isSubMenu = !string.IsNullOrEmpty(ItemsSource) || Items != null && Items.Count > 0;
            XmlPropertySetter setter;
            int groupId;

            int.TryParse(Group, out groupId);
            if (isSubMenu)
            {
                ISubMenu subMenu = menu.AddSubMenu(groupId, id, order, string.Empty);
                setter = new XmlPropertySetter(subMenu.Item, context);
                subMenu.SetBindingMemberValue(AttachedMembers.Object.Parent, menu);
                subMenu.Item.SetBindingMemberValue(AttachedMembers.Object.Parent, subMenu);
                SetDataContext(subMenu, setter, dataContext, useContext);
                ApplySelf(subMenu.Item, setter);

                if (string.IsNullOrEmpty(ItemsSource))
                {
                    for (int index = 0; index < Items.Count; index++)
                    {
                        Items[index].Apply(subMenu, context, index, index);
                    }
                }
                else
                {
                    subMenu.SetBindingMemberValue(AttachedMembers.Menu.ItemsSourceGenerator,
                                                  new MenuItemsSourceGenerator(subMenu, context, ItemTemplate ?? this));
                    XmlPropertySetter.AddBinding(setter, subMenu, AttachedMemberConstants.ItemsSource, ItemsSource, true);
                }
            }
            else
            {
                var menuItem = menu.Add(groupId, id, order, string.Empty);
                setter = new XmlPropertySetter(menuItem, context);
                menuItem.SetBindingMemberValue(AttachedMembers.Object.Parent, menu);
                SetDataContext(menuItem, setter, dataContext, useContext);
                ApplySelf(menuItem, setter);
            }
            setter.Apply();
        }
        public void OnResumeActivity(Activity activity, IDataContext context)
        {
            Should.NotBeNull(activity, nameof(activity));
            SetBackground(false, context);
            var prevContent = CurrentContent;

            if ((_newContext == null || IsFinishing(activity) || !_newContext.GetData(NavigationProvider.BringToFront)) && ReferenceEquals(activity, prevContent))
            {
                return;
            }
            var viewModel = activity.DataContext() as IViewModel;

            viewModel?.Settings.Metadata.Remove(NavigationProvider.BringToFront);
            AndroidToolkitExtensions.SetCurrentActivity(activity, false);
            var bundle = GetState(activity);

            if (bundle.ContainsKey(IsOpenedKey))
            {
                NavigationMode mode;
                IDataContext   ctx = _backContext;
                if (ctx != null || prevContent != null && IsFinishing(prevContent))
                {
                    mode         = NavigationMode.Back;
                    _backContext = null;
                }
                else
                {
                    ctx         = _newContext;
                    _newContext = null;
                    mode        = NavigationMode.Refresh;
                }
                RaiseNavigated(activity, mode, GetParameterFromIntent(activity.Intent), MergeContext(ctx, context));
            }
            else
            {
                bundle.PutBoolean(IsOpenedKey, true);
                var newContext = _newContext;
                _newContext = null;
                RaiseNavigated(activity, NavigationMode.New, GetParameterFromIntent(activity.Intent), MergeContext(newContext, context));
            }
        }
        public bool Load(IModuleContext context)
        {
#if !APPCOMPAT
            if (!AndroidToolkitExtensions.IsApiGreaterThanOrEqualTo17)
            {
                return(false);
            }
#endif
            var isActionBar        = AndroidToolkitExtensions.IsActionBar;
            var isFragment         = AndroidToolkitExtensions.IsFragment;
            var tabChangedDelegate = TabHostItemsSourceGenerator.TabChangedDelegate;
            var removeTabDelegate  = TabHostItemsSourceGenerator.RemoveTabDelegate;

            AndroidToolkitExtensions.IsActionBar = o => isActionBar(o) || o is ActionBar;
            AndroidToolkitExtensions.IsFragment  = o => isFragment(o) || o is Fragment;
            AndroidToolkitExtensions.AddContentViewManager(new FragmentContentViewManager());

            TabHostItemsSourceGenerator.RemoveTabDelegate  = (generator, info) => OnRemoveTab(removeTabDelegate, generator, info);
            TabHostItemsSourceGenerator.TabChangedDelegate = (generator, o, arg3, arg4, arg5) => OnTabChanged(tabChangedDelegate, generator, o, arg3, arg4, arg5);
            return(true);
        }
        public bool Load(IModuleContext context)
        {
            IViewModelPresenter service;

#if APPCOMPAT
            if (!context.IocContainer.TryGet(out service))
            {
                return(false);
            }
#else
            if (!AndroidToolkitExtensions.IsApiGreaterThanOrEqualTo17 || !context.IocContainer.TryGet(out service))
            {
                return(false);
            }
#endif
            var mediatorFactory = AndroidToolkitExtensions.MediatorFactory;
            AndroidToolkitExtensions.MediatorFactory = (o, dataContext, arg3) =>
            {
#if APPCOMPAT
                return(FragmentExtensions.MvvmFragmentMediatorDefaultFactory(o, dataContext, arg3) ?? mediatorFactory?.Invoke(o, dataContext, arg3));
#else
                return(AndroidToolkitExtensions.MvvmFragmentMediatorDefaultFactory(o, dataContext, arg3) ?? mediatorFactory?.Invoke(o, dataContext, arg3));
#endif
            };


            var windowPresenter = service.DynamicPresenters.OfType <DynamicViewModelWindowPresenter>().FirstOrDefault();
            if (windowPresenter == null)
            {
                windowPresenter = context.IocContainer.Get <DynamicViewModelWindowPresenter>();
                service.DynamicPresenters.Add(windowPresenter);
            }
#if APPCOMPAT
            windowPresenter.RegisterMediatorFactory <Infrastructure.Mediators.WindowViewMediator, Interfaces.Views.IWindowView>();
#else
            windowPresenter.RegisterMediatorFactory <WindowViewMediator, IWindowView>();
#endif
            return(true);
        }
        public void OnResumeActivity(Activity activity, IDataContext context)
        {
            Should.NotBeNull(activity, nameof(activity));
            SetBackground(false, context);
            var prevContent = CurrentContent;

            if (ReferenceEquals(activity, prevContent))
            {
                return;
            }
            AndroidToolkitExtensions.SetCurrentActivity(activity, false);
            var bundle = GetState(activity);

            if (bundle.ContainsKey(IsOpenedKey))
            {
                NavigationMode mode;
                IDataContext   ctx = _backContext;
                if (ctx != null || prevContent != null && GetState(prevContent).ContainsKey(IsBackKey))
                {
                    mode         = NavigationMode.Back;
                    _backContext = null;
                }
                else
                {
                    ctx         = _newContext;
                    _newContext = null;
                    mode        = NavigationMode.Refresh;
                }
                RaiseNavigated(activity, mode, GetParameterFromIntent(activity.Intent), MergeContext(ctx, context));
            }
            else
            {
                bundle.PutBoolean(IsOpenedKey, true);
                var newContext = _newContext;
                _newContext = null;
                RaiseNavigated(activity, NavigationMode.New, GetParameterFromIntent(activity.Intent), MergeContext(newContext, context));
            }
        }
Beispiel #22
0
        private static void StartBootstrapperCallback(object state)
        {
            var       activityBase = (SplashScreenActivityBase)state;
            Exception exception    = null;
            AndroidBootstrapperBase bootstrapper = null;

            try
            {
                bootstrapper = AndroidBootstrapperBase.GetOrCreateBootstrapper(activityBase.CreateBootstrapper);
                bootstrapper.Start();
            }
            catch (Exception e)
            {
                Tracer.Error(e.Flatten(true));
                exception = e;
            }
            finally
            {
                activityBase.OnBootstrapperStarted(bootstrapper, exception);
                AndroidToolkitExtensions.SetCurrentActivity(activityBase, true);
                _state = DefaultState;
            }
        }
        internal static void SetContentView([NotNull] this ViewGroup frameLayout, [NotNull] object content,
                                            [NotNull] FragmentTransaction transaction,
                                            [NotNull] Action <ViewGroup, Fragment, FragmentTransaction> updateAction)
        {
            Should.NotBeNull(frameLayout, nameof(frameLayout));
            var view = content as View;

            if (view == null)
            {
                var fragment = (Fragment)content;
                AndroidToolkitExtensions.ValidateViewIdFragment(frameLayout, fragment);
                updateAction(frameLayout, fragment, transaction);
            }
            else
            {
                if (frameLayout.ChildCount == 1 && frameLayout.GetChildAt(0) == view)
                {
                    return;
                }
                frameLayout.RemoveAllViews();
                frameLayout.AddView(view);
            }
        }
 private object GetContent(object item)
 {
     return(AndroidToolkitExtensions.GetContentView(TabHost, TabHost.Context,
                                                    item, _contentTemplateProvider.GetTemplateId(), _contentTemplateProvider.GetDataTemplateSelector()));
 }
        public bool SetContent(object view, object content)
        {
            var targetView = view as ViewGroup;

            if (targetView == null)
            {
                return(false);
            }
            if (content == null)
            {
                FragmentManager fragmentManager = targetView.GetFragmentManager();
                Fragment        oldFragment     = fragmentManager?.FindFragmentById(targetView.Id);
                if (oldFragment != null && !fragmentManager.IsDestroyed)
                {
                    BeginTransaction(fragmentManager, targetView, null)
                    .Remove(oldFragment)
                    .CommitAllowingStateLoss();
                    fragmentManager.ExecutePendingTransactions();
                    return(true);
                }
                return(false);
            }
            var fragment = content as Fragment;

            if (fragment == null)
            {
                return(false);
            }
            AndroidToolkitExtensions.ValidateViewIdFragment(targetView, fragment);
            FragmentManager manager = targetView.GetFragmentManager();

            if (manager == null)
            {
                return(false);
            }
            FragmentTransaction transaction = BeginTransaction(manager, targetView, fragment);
            var addToBackStack = targetView.GetBindingMemberValue(AttachedMembers.ViewGroup.AddToBackStack);

            if (addToBackStack && fragment.Arguments != null)
            {
                addToBackStack = !fragment.Arguments.GetBoolean(AddedToBackStackKey);
            }

            if (fragment.IsDetached)
            {
                transaction.Attach(fragment);
            }
            else
            {
                if (addToBackStack)
                {
                    if (fragment.Arguments == null)
                    {
                        fragment.Arguments = new Bundle();
                    }
                    fragment.Arguments.PutBoolean(AddedToBackStackKey, true);
                }
                transaction.Replace(targetView.Id, fragment);
            }
            if (addToBackStack)
            {
                transaction.AddToBackStack(null);
            }

            transaction.Commit();
            manager.ExecutePendingTransactions();
            return(true);
        }
 private bool IsSpinner()
 {
     return(Container is Spinner || AndroidToolkitExtensions.IsActionBar(Container));
 }
Beispiel #27
0
 protected virtual Object InstantiateItemInternal(ViewGroup container, object item)
 {
     return((Object)AndroidToolkitExtensions
            .GetContentView(container, container.Context, item, _itemTemplateProvider.GetTemplateId(), _itemTemplateProvider.GetDataTemplateSelector()));
 }
 protected AndroidBootstrapperBase(bool isDesignMode = false, PlatformInfo platform = null)
     : base(isDesignMode)
 {
     _platform = platform ?? AndroidToolkitExtensions.GetPlatformInfo();
 }
        public void Apply(Activity activity)
        {
            AndroidToolkitExtensions.ValidateTemplate(ItemsSource, Items);
            var actionBar = activity.GetActionBar();

            var setter = new XmlPropertySetter(actionBar, activity);

            setter.SetEnumProperty <ActionBarNavigationMode>(nameof(NavigationMode), NavigationMode);
            setter.SetProperty(nameof(DataContext), DataContext);

            if (!string.IsNullOrEmpty(Bind))
            {
                setter.Bind(actionBar, Bind);
            }
            setter.SetProperty(nameof(ContextActionBarTemplate), ContextActionBarTemplate);
            setter.SetBinding(nameof(ContextActionBarVisible), ContextActionBarVisible, false);
            setter.SetProperty(nameof(BackgroundDrawable), BackgroundDrawable);
            setter.SetProperty(nameof(CustomView), CustomView);
            setter.SetEnumProperty <ActionBarDisplayOptions>(nameof(DisplayOptions), DisplayOptions);
            setter.SetBoolProperty(nameof(DisplayHomeAsUpEnabled), DisplayHomeAsUpEnabled);
            setter.SetBoolProperty(nameof(DisplayShowCustomEnabled), DisplayShowCustomEnabled);
            setter.SetBoolProperty(nameof(DisplayShowHomeEnabled), DisplayShowHomeEnabled);
            setter.SetBoolProperty(nameof(DisplayShowTitleEnabled), DisplayShowTitleEnabled);
            setter.SetBoolProperty(nameof(DisplayUseLogoEnabled), DisplayUseLogoEnabled);
            setter.SetBoolProperty(nameof(HomeButtonEnabled), HomeButtonEnabled);
            setter.SetProperty(nameof(Icon), Icon);
            setter.SetProperty(nameof(Logo), Logo);
            setter.SetProperty(nameof(SplitBackgroundDrawable), SplitBackgroundDrawable);
            setter.SetProperty(nameof(StackedBackgroundDrawable), StackedBackgroundDrawable);
            setter.SetBoolProperty(nameof(IsShowing), IsShowing);
            setter.SetStringProperty(nameof(Subtitle), Subtitle);
            setter.SetStringProperty(nameof(Title), Title);
            setter.SetBoolProperty(nameof(Visible), Visible);
            setter.SetBinding(AttachedMembers.ActionBar.HomeButtonClick, HomeButtonClick, false);

            if (string.IsNullOrEmpty(ItemsSource))
            {
                if (Items != null)
                {
                    ActionBar.Tab firstTab = null;
                    for (int index = 0; index < Items.Count; index++)
                    {
                        var tab = Items[index].CreateTab(actionBar);
                        if (firstTab == null)
                        {
                            firstTab = tab;
                        }
                        actionBar.AddTab(tab);
                    }
                    TryRestoreSelectedIndex(activity, actionBar);
                }
            }
            else
            {
#if APPCOMPAT
                actionBar.SetBindingMemberValue(AttachedMembersCompat.ActionBar.ItemsSourceGenerator, new ActionBarTabItemsSourceGenerator(actionBar, TabTemplate));
#else
                actionBar.SetBindingMemberValue(AttachedMembers.ActionBar.ItemsSourceGenerator, new ActionBarTabItemsSourceGenerator(actionBar, TabTemplate));
#endif
                setter.SetBinding(nameof(ItemsSource), ItemsSource, false);
            }
            setter.SetBinding(nameof(SelectedItem), SelectedItem, false);
            setter.Apply();
        }
            private void SetContent(ActionBar.Tab tab, FragmentTransaction ft, int?placeHolder, Activity activity, ActionBar bar)
            {
                if (placeHolder == null)
                {
                    Tracer.Error("The placeholder for tab {0} was not found.", tab);
                    return;
                }
                var layout = activity.FindViewById <ViewGroup>(placeHolder.Value);

                if (layout == null)
                {
                    Tracer.Warn("The ActionBarTabContentId with id = {0} is not found in activity {1}",
                                placeHolder.Value,
                                activity);
                    return;
                }
                if (_content == null)
                {
#if APPCOMPAT
                    _content = tab.GetBindingMemberValue(AttachedMembersCompat.ActionBarTab.Content);
#else
                    _content = tab.GetBindingMemberValue(AttachedMembers.ActionBarTab.Content);
#endif

                    var viewModel = _content as IViewModel;
                    if (viewModel == null)
                    {
                        var fragmentClass = _content as string;
                        //If content is a string, trying to create a fragment.
                        if (!string.IsNullOrEmpty(fragmentClass))
                        {
                            var type = TypeCache <Fragment> .Instance.GetTypeByName(fragmentClass, true, false);

                            if (type != null)
                            {
                                var fragment = Fragment.Instantiate(bar.ThemedContext, Java.Lang.Class.FromType(type).Name);
                                _content = fragment;
                            }
                        }
                        else if (_content is int)
                        {
                            _content = activity.GetBindableLayoutInflater().Inflate((int)_content, null);
                        }
                    }
                    else
                    {
                        viewModel.Settings.Metadata.AddOrUpdate(ViewModelConstants.StateNotNeeded, true);
                    }
                    _content = AndroidToolkitExtensions.GetContentView(layout, layout.Context, _content,
                                                                       _contentTemplateProvider.GetTemplateId(), _contentTemplateProvider.GetDataTemplateSelector());
                    if (BindingServiceProvider.BindingManager.GetBindings(tab, AttachedMembers.Object.DataContext).Any())
                    {
                        _content.SetBindingMemberValue(AttachedMembers.Object.Parent, tab);
                    }
                    layout.SetContentView(_content, ft, (@group, fragment, arg3) =>
                    {
                        if (fragment.IsDetached)
                        {
                            arg3.Attach(fragment);
                        }
                        else
                        {
                            arg3.Replace(@group.Id, fragment);
                        }
                    });
                }
                else
                {
                    layout.SetContentView(_content, ft, (@group, fragment, arg3) => arg3.Attach(fragment));
                }
            }