void BindHeaderView(HeaderViewHolder holder)
        {
            var section = holder.RowInfo.Section;
            var view    = holder.ItemView;

            //judging cell height
            int cellHeight       = (int)_context.ToPixels(44);
            var individualHeight = section.HeaderHeight;

            if (individualHeight > 0d)
            {
                cellHeight = (int)_context.ToPixels(individualHeight);
            }
            else if (_settingsView.HeaderHeight > -1)
            {
                cellHeight = (int)_context.ToPixels(_settingsView.HeaderHeight);
            }
            else
            {
                cellHeight = -1; // Height Auto
            }

            if (cellHeight >= 0)
            {
                view.SetMinimumHeight(cellHeight);
                view.LayoutParameters.Height = cellHeight;
            }

            //textview setting
            holder.TextView.SetPadding(
                (int)view.Context.ToPixels(_settingsView.HeaderPadding.Left),
                (int)view.Context.ToPixels(_settingsView.HeaderPadding.Top),
                (int)view.Context.ToPixels(_settingsView.HeaderPadding.Right),
                (int)view.Context.ToPixels(_settingsView.HeaderPadding.Bottom)
                );

            holder.TextView.Gravity       = _settingsView.HeaderTextVerticalAlign.ToNativeVertical() | GravityFlags.Left;
            holder.TextView.TextAlignment = Android.Views.TextAlignment.Gravity;
            holder.TextView.Typeface      = FontUtility.CreateTypeface(_settingsView.HeaderFontFamily, _settingsView.HeaderFontAttributes);
            holder.TextView.SetTextSize(Android.Util.ComplexUnitType.Sp, (float)_settingsView.HeaderFontSize);
            holder.TextView.SetBackgroundColor(_settingsView.HeaderBackgroundColor.ToAndroid());

            // Single line was done away with.
            //holder.TextView.SetMaxLines(1);
            //holder.TextView.SetMinLines(1);
            //holder.TextView.Ellipsize = TextUtils.TruncateAt.End;

            if (_settingsView.HeaderTextColor != Xamarin.Forms.Color.Default)
            {
                holder.TextView.SetTextColor(_settingsView.HeaderTextColor.ToAndroid());
            }

            //update text
            holder.TextView.Text = section.Title;
        }
Example #2
0
        void BindHeaderView(HeaderViewHolder holder, TextCell formsCell)
        {
            var view = holder.ItemView;

            //judging cell height
            int cellHeight       = (int)_context.ToPixels(44);
            var individualHeight = formsCell.Height;

            if (individualHeight > 0d)
            {
                cellHeight = (int)_context.ToPixels(individualHeight);
            }
            else if (_settingsView.HeaderHeight > -1)
            {
                cellHeight = (int)_context.ToPixels(_settingsView.HeaderHeight);
            }

            view.SetMinimumHeight(cellHeight);
            view.LayoutParameters.Height = cellHeight;

            //textview setting
            holder.TextView.SetPadding(
                (int)view.Context.ToPixels(_settingsView.HeaderPadding.Left),
                (int)view.Context.ToPixels(_settingsView.HeaderPadding.Top),
                (int)view.Context.ToPixels(_settingsView.HeaderPadding.Right),
                (int)view.Context.ToPixels(_settingsView.HeaderPadding.Bottom)
                );

            holder.TextView.Gravity       = _settingsView.HeaderTextVerticalAlign.ToNativeVertical() | GravityFlags.Left;
            holder.TextView.TextAlignment = Android.Views.TextAlignment.Gravity;
            holder.TextView.SetTextSize(Android.Util.ComplexUnitType.Sp, (float)_settingsView.HeaderFontSize);
            holder.TextView.SetBackgroundColor(_settingsView.HeaderBackgroundColor.ToAndroid());
            holder.TextView.SetMaxLines(1);
            holder.TextView.SetMinLines(1);
            holder.TextView.Ellipsize = TextUtils.TruncateAt.End;

            if (_settingsView.HeaderTextColor != Xamarin.Forms.Color.Default)
            {
                holder.TextView.SetTextColor(_settingsView.HeaderTextColor.ToAndroid());
            }

            //border setting
            if (_settingsView.ShowSectionTopBottomBorder)
            {
                holder.Border.SetBackgroundColor(_settingsView.SeparatorColor.ToAndroid());
            }
            else
            {
                holder.Border.SetBackgroundColor(Android.Graphics.Color.Transparent);
            }

            //update text
            holder.TextView.Text = formsCell.Text;
        }
        /// <summary>
        /// Ons the create view holder.
        /// </summary>
        /// <returns>The create view holder.</returns>
        /// <param name="parent">Parent.</param>
        /// <param name="viewType">View type.</param>
        public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
        {
            ViewHolder viewHolder;

            var inflater = LayoutInflater.FromContext(_context);

            switch ((ViewType)viewType)
            {
            case ViewType.TextHeader:
                viewHolder = new HeaderViewHolder(inflater.Inflate(Resource.Layout.HeaderCell, parent, false));
                break;

            case ViewType.TextFooter:
                viewHolder = new FooterViewHolder(inflater.Inflate(Resource.Layout.FooterCell, parent, false));
                break;

            case ViewType.CustomHeader:
                var hContainer = new HeaderFooterContainer(_context);
                viewHolder = new CustomHeaderViewHolder(hContainer);
                break;

            case ViewType.CustomFooter:
                var fContainer = new HeaderFooterContainer(_context);
                viewHolder = new CustomFooterViewHolder(fContainer);
                break;

            default:
                viewHolder = new ContentBodyViewHolder(inflater.Inflate(Resource.Layout.ContentCell, parent, false));
                viewHolder.ItemView.SetOnClickListener(this);
                viewHolder.ItemView.SetOnLongClickListener(this);
                break;
            }

            _viewHolders.Add(viewHolder);

            inflater.Dispose();

            return(viewHolder);
        }
Example #4
0
        /// <summary>
        /// Ons the create view holder.
        /// </summary>
        /// <returns>The create view holder.</returns>
        /// <param name="parent">Parent.</param>
        /// <param name="viewType">View type.</param>
        public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
        {
            ViewHolder viewHolder;

            switch (viewType)
            {
            case ViewTypeHeader:
                viewHolder = new HeaderViewHolder(LayoutInflater.FromContext(_context).Inflate(Resource.Layout.HeaderCell, parent, false), _settingsView);
                break;

            case ViewTypeFooter:
                viewHolder = new FooterViewHolder(LayoutInflater.FromContext(_context).Inflate(Resource.Layout.FooterCell, parent, false), _settingsView);
                break;

            default:
                viewHolder = new ContentViewHolder(LayoutInflater.FromContext(_context).Inflate(Resource.Layout.ContentCell, parent, false));
                viewHolder.ItemView.SetOnClickListener(this);
                break;
            }

            _viewHolders.Add(viewHolder);

            return(viewHolder);
        }