public void AddAction(ActionBarAction actionBarAction)
 {
     ActionList.Add(actionBarAction);
     _stringIds.Add(actionBarAction.PopUpMessage == 0 ? "ERROR" : mContext.Resources.GetString(actionBarAction.PopUpMessage));
 }
예제 #2
0
        /// <summary>
        /// Inflates a View with the given Action.
        /// </summary>
        /// <param name="action">the action to inflate</param>
        /// <returns>a view</returns>
        private View InflateAction(ActionBarAction action)
        {
            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(action.GetDrawable());

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

            if (action.PopUpMessage > 0)
                view.ContentDescription = Resources.GetString(action.PopUpMessage);

            return view;
        }
예제 #3
0
        private View InflateOverflowAction(ActionBarAction action)
        {
            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(action.GetDrawable());

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

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

            _overflowAction.Activity = CurrentActivity;
            return view;
        }
예제 #4
0
        /// <summary>
        /// Remove a action from the action bar.
        /// </summary>
        /// <param name="action">The action to remove</param>
        public void RemoveAction(ActionBarAction action)
        {
            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 ActionBarAction;

                if (actionBarAction == null || !actionBarAction.Equals(action)) continue;

                var menuItemAction = tag as MenuItemActionBarAction;
                if (menuItemAction != null)
                    MenuItemsToHide.Remove(menuItemAction.MenuItemId);

                _actionsView.RemoveView(view);
            }
        }
예제 #5
0
        /// <summary>
        /// Adds a new Action at the specified index.
        /// </summary>
        /// <param name="action">the action to add</param>
        /// <param name="index">the position at which to add the action</param>
        public void AddAction(ActionBarAction action, int index)
        {
            var addActionBar = false;

            var hideAction = false;
            if (!ActionBarUtils.ActionFits(CurrentActivity, index, HasMenuButton, action.ActionType))
            {
                if (!HasMenuButton)
                {
                    addActionBar = _overflowAction.ActionList.Count == 0;
                    _overflowAction.AddAction(action);
                    hideAction = true;
                }
            }
            else
            {
                if (_overflowAction.ActionList.Count != 0)//exists
                    index = _overflowAction.Index;//bring it inside

                hideAction = true;

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

            //simply put it in the menu items to hide if we are a menu item.
            var taskAction = action as MenuItemActionBarAction;
            if (taskAction != null && hideAction)
                MenuItemsToHide.Add(taskAction.MenuItemId);

            if (addActionBar)
                AddOverflowAction(_overflowAction);
        }
예제 #6
0
 /// <summary>
 /// Adds new action in the overflow
 /// </summary>
 /// <param name="action">Action to add.</param>
 public void AddOverflowAction(ActionBarAction action)
 {
     var index = _actionsView.ChildCount;
     _actionsView.AddView(InflateOverflowAction(action), index);
     _overflowAction.Index = index;
 }
예제 #7
0
 /// <summary>
 /// Adds a new Action.
 /// </summary>
 /// <param name="action">Action to add.</param>
 public void AddAction(ActionBarAction action) 
 {
     AddAction(action, _actionsView.ChildCount);
 }
예제 #8
0
        public void SetHomeAction(ActionBarAction action)
        {
            _homeBtn.SetOnClickListener(this);
            _homeBtn.Tag = action;
            _homeBtn.SetImageResource(action.GetDrawable());
            _homeLayout.Visibility = ViewStates.Visible;

            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);
        }