Пример #1
0
        /// <summary>
        /// Inflates a View with the given Action.
        /// </summary>
        /// <param name="legacyBarAction">the legacyBarAction to inflate</param>
        /// <returns>a view</returns>
        private View InflateAction(LegacyBarAction legacyBarAction)
        {
            var view = _inflater.Inflate(Resource.Layout.actionbar_item, _actionsView, false);

            if (null != ItemBackgroundDrawable)
            {
                view.SetBackgroundDrawable(ItemBackgroundDrawable.GetConstantState().NewDrawable());
            }
            else if (ItemBackgroundDrawableRaw > 0)
            {
                view.SetBackgroundResource(ItemBackgroundDrawableRaw);
            }

            var labelView =
                view.FindViewById <ImageButton>(Resource.Id.actionbar_item);

            labelView.SetImageResource(legacyBarAction.GetDrawable());

            view.Tag = legacyBarAction;
            view.SetOnClickListener(this);
            view.SetOnLongClickListener(this);

            if (legacyBarAction.PopUpMessage > 0)
            {
                view.ContentDescription = Resources.GetString(legacyBarAction.PopUpMessage);
            }

            return(view);
        }
Пример #2
0
        private View InflateOverflowAction(LegacyBarAction legacyBarAction)
        {
            var view = _inflater.Inflate(Resource.Layout.overflowactionbar_item, _actionsView, false);


            var labelView =
                view.FindViewById <ImageButton>(Resource.Id.actionbar_item);


            if (null != ItemBackgroundDrawable)
            {
                labelView.SetBackgroundDrawable(ItemBackgroundDrawable.GetConstantState().NewDrawable());
            }
            else if (ItemBackgroundDrawableRaw > 0)
            {
                labelView.SetBackgroundResource(ItemBackgroundDrawableRaw);
            }

            labelView.SetImageResource(legacyBarAction.GetDrawable());

            var spinner = view.FindViewById <Spinner>(Resource.Id.overflow_spinner);

            _overflowLegacyBarAction.OverflowSpinner = spinner;

            labelView.Tag = legacyBarAction;
            labelView.SetOnClickListener(this);
            //view.SetOnLongClickListener(this);

            return(view);
        }
Пример #3
0
        /// <summary>
        /// Remove a legacyBarAction from the legacyBarAction bar.
        /// </summary>
        /// <param name="legacyBarAction">The legacyBarAction to remove</param>
        public void RemoveAction(LegacyBarAction legacyBarAction)
        {
            for (var i = 0; i < _actionsView.ChildCount; i++)
            {
                var view = _actionsView.GetChildAt(i);

                if (view == null)
                {
                    continue;
                }

                var tag             = view.Tag;
                var actionBarAction = tag as LegacyBarAction;

                if (actionBarAction == null || !actionBarAction.Equals(legacyBarAction))
                {
                    continue;
                }

                var menuItemAction = tag as MenuItemLegacyBarAction;
                if (menuItemAction != null)
                {
                    MenuItemsToHide.Remove(menuItemAction.MenuItemId);
                }

                _actionsView.RemoveView(view);
            }
        }
Пример #4
0
        /// <summary>
        /// Adds new legacyBarAction in the overflow
        /// </summary>
        /// <param name="legacyBarAction">Action to add.</param>
        public void AddOverflowAction(LegacyBarAction legacyBarAction)
        {
            var index = _actionsView.ChildCount;

            _actionsView.AddView(InflateOverflowAction(legacyBarAction), index);
            _overflowLegacyBarAction.Index = index;
        }
Пример #5
0
        public void SetHomeAction(LegacyBarAction legacyBarAction)
        {
            _homeBtn.SetOnClickListener(this);
            _homeBtn.Tag = legacyBarAction;
            _homeBtn.SetImageResource(legacyBarAction.GetDrawable());
            _homeLayout.Visibility = ViewStates.Visible;
            _backIndicator.SetBackgroundResource(LightIcons ? Resource.Drawable.actionbar_back_indicator : Resource.Drawable.actionbar_back_indicator_dark);


            if (null != ItemBackgroundDrawable)
            {
                _homeBtn.SetBackgroundDrawable(ItemBackgroundDrawable.GetConstantState().NewDrawable());
            }
            else if (ItemBackgroundDrawableRaw > 0)
            {
                _homeBtn.SetBackgroundResource(ItemBackgroundDrawableRaw);
            }


            ((LayoutParams)_titleLayout.LayoutParameters).AddRule(LayoutRules.RightOf, Resource.Id.actionbar_home_bg);
        }
Пример #6
0
        /// <summary>
        /// Adds a new Action at the specified index.
        /// </summary>
        /// <param name="legacyBarAction">the legacyBarAction to add</param>
        /// <param name="index">the position at which to add the legacyBarAction</param>
        public void AddAction(LegacyBarAction legacyBarAction, int index)
        {
            var addActionBar = false;

            var hideAction = false;

            if (!LegacyBarUtils.ActionFits(Context.Resources.DisplayMetrics.WidthPixels, Context.Resources.DisplayMetrics.Density, index, HasMenuButton, legacyBarAction.ActionType))
            {
                if (!HasMenuButton)
                {
                    addActionBar = _overflowLegacyBarAction.ActionList.Count == 0;
                    _overflowLegacyBarAction.AddAction(legacyBarAction);
                    hideAction = true;
                }
            }
            else
            {
                if (_overflowLegacyBarAction.ActionList.Count != 0) //exists
                {
                    index = _overflowLegacyBarAction.Index;         //bring it inside
                }
                hideAction = true;

                _actionsView.AddView(InflateAction(legacyBarAction), index);
            }

            //simply put it in the menu items to hide if we are a menu item.
            var taskAction = legacyBarAction as MenuItemLegacyBarAction;

            if (taskAction != null && hideAction)
            {
                MenuItemsToHide.Add(taskAction.MenuItemId);
            }

            if (addActionBar)
            {
                AddOverflowAction(_overflowLegacyBarAction);
            }
        }
Пример #7
0
 /// <summary>
 /// Adds a new Action.
 /// </summary>
 /// <param name="legacyBarAction">Action to add.</param>
 public void AddAction(LegacyBarAction legacyBarAction)
 {
     AddAction(legacyBarAction, _actionsView.ChildCount);
 }