Esempio n. 1
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ItemsSourceAdapter" /> class.
 /// </summary>
 public ItemsSourceAdapter([NotNull] object container, Context context, bool listenCollectionChanges, string dropDownItemTemplateSelectorName = AttachedMemberNames.DropDownItemTemplateSelector,
                           string itemTemplateSelectorName = AttachedMemberConstants.ItemTemplateSelector, string dropDownItemTemplateIdName = AttachedMemberNames.DropDownItemTemplate,
                           string itemTemplateIdName       = AttachedMemberConstants.ItemTemplate)
 {
     Should.NotBeNull(container, "container");
     _container                = container;
     _itemTemplateProvider     = new DataTemplateProvider(container, itemTemplateIdName, itemTemplateSelectorName);
     _dropDownTemplateProvider = new DataTemplateProvider(container, dropDownItemTemplateIdName,
                                                          dropDownItemTemplateSelectorName);
     _layoutInflater = LayoutInflater.From(context);
     if (listenCollectionChanges)
     {
         _weakHandler = ReflectionExtensions.MakeWeakCollectionChangedHandler(this, (adapter, o, arg3) => adapter.OnCollectionChanged(o, arg3));
     }
 }
Esempio n. 2
0
 private TabHostItemsSourceGenerator([NotNull] TabHost tabHost)
 {
     Should.NotBeNull(tabHost, "tabHost");
     _tabHost = tabHost;
     _tabHost.Setup();
     _tabToContent         = new Dictionary <string, TabInfo>();
     _tabFactory           = new TabFactory(this);
     _itemTemplateProvider = new DataTemplateProvider(tabHost, AttachedMemberConstants.ItemTemplate,
                                                      AttachedMemberConstants.ItemTemplateSelector);
     _contentTemplateProvider = new DataTemplateProvider(tabHost, AttachedMemberConstants.ContentTemplate,
                                                         AttachedMemberConstants.ContentTemplateSelector);
     _selectedItemMember = BindingServiceProvider
                           .MemberProvider
                           .GetBindingMember(tabHost.GetType(), AttachedMemberConstants.SelectedItem, false, false);
     TryListenActivity(tabHost.Context);
     _tabHost.TabChanged += TabHostOnTabChanged;
 }
Esempio n. 3
0
        protected virtual View CreateView(object value, View convertView, ViewGroup parent, DataTemplateProvider templateProvider, int defaultTemplate)
        {
            var valueView = value as View;

            if (valueView != null)
            {
                return(valueView);
            }

            int?   templateId = null;
            object template;

            if (templateProvider.TrySelectTemplate(value, out template))
            {
                if (template != null)
                {
                    valueView = template as View;
                    if (valueView != null)
                    {
                        BindingServiceProvider.ContextManager
                        .GetBindingContext(valueView)
                        .Value = value;
                        return(valueView);
                    }
                    if (template is int)
                    {
                        templateId = (int)template;
                    }
                    else
                    {
                        value = template;
                    }
                }
            }
            else
            {
                templateId = templateProvider.GetTemplateId();
            }
            if (templateId == null)
            {
                if (!(convertView is TextView))
                {
                    convertView = LayoutInflater.Inflate(defaultTemplate, null);
                }
                var textView = convertView as TextView;
                if (textView != null)
                {
                    textView.Text = value == null ? "(null)" : value.ToString();
                }
                return(textView);
            }
            var itemView = convertView as ListItem;

            if (itemView == null || itemView.TemplateId != templateId)
            {
                convertView = CreateView(value, parent, templateId.Value);
            }
            BindingServiceProvider.ContextManager.GetBindingContext(convertView).Value = value;
            return(convertView);
        }