예제 #1
0
        public void MenuItemSelectedEvent(CustomMenuItem selection, List <ImageView> icons, List <TextView> titleTextView)
        {
            int index = selection.Id;

            currentTabIndex = index;

            SetUpMenu();

            myTabbedPage.RaiseTappedIndex(currentTabIndex);

            myTabbedPage.CurrentPage  = myTabbedPage.Children[selection.Id];
            myTabbedPage.SelectedItem = myTabbedPage.Children[selection.Id];
        }
예제 #2
0
        /**
         * Display your menu. Not we require a view from the parent.  This is so we can get
         * a window token.  It doesn't matter which view on the parent is passed in.
         * @param View v
         * @return void
         */
        public void Show(View v, GravityFlags screenLocation, bool enableSelectedIndicator)
        {
            if (table != null && table.Visibility == ViewStates.Gone)
            {
                Reshow();
                return;
            }

            if (mIsShowing)
            {
                return;
            }

            int itemCount = mMenuItems.Count;

            if (itemCount < 1)
            {
                return;
            }

            if (imageViewList.Count > 0)
            {
                imageViewList.Clear();
            }
            if (badgeTextViewList.Count > 0)
            {
                badgeTextViewList.Clear();
            }
            if (titleViewList.Count > 0)
            {
                titleViewList.Clear();
            }
            if (indicatorList.Count > 0)
            {
                indicatorList.Clear();
            }

            mView       = mLayoutInflater.Inflate(UIHelper.GetResource(UIHelper.Layout, "custom_menu"), null);
            tableParent = mView.FindViewById(UIHelper.GetResource(UIHelper.Id, "table_parent")) as LinearLayout;

            if (mView == null)
            {
                return;
            }

            var tableId = UIHelper.GetResource(UIHelper.Id, "custom_menu_table");

            table = (TableLayout)mView.FindViewById(tableId);
            if (table == null)
            {
                return;
            }

            var windowManager = (mContext as Activity).WindowManager;

            table.RemoveAllViews();

            TableRow row     = null;
            TextView tv      = null;
            TextView tvBadge = null;
            TextView selected_item_indicator = null;

            ImageView iv = null;

            row = new TableRow(mContext);
            row.LayoutParameters = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MatchParent, RelativeLayout.LayoutParams.WrapContent);
            for (int j = 0; j < mItemsCount; j++)
            {
                if (j >= itemCount)
                {
                    break;
                }

                CustomMenuItem cmi        = mMenuItems.ElementAt(j);
                View           itemLayout = mLayoutInflater.Inflate(UIHelper.GetLayoutResource("custom_menu_item"), null);
                tv = (TextView)itemLayout.FindViewById(UIHelper.GetId("custom_menu_item_caption"));
                tv.SetTextColor(this.textColor);

                if (String.IsNullOrEmpty(cmi.Caption))
                {
                    tv.Visibility = ViewStates.Gone;
                }
                else
                {
                    tv.Text       = cmi.Caption;
                    tv.Visibility = ViewStates.Visible;
                }
                titleViewList.Add(tv);

                iv = (ImageView)itemLayout.FindViewById(UIHelper.GetId("custom_menu_item_icon"));

                if (cmi.ImageResourceId > 0)
                {
                    iv.SetImageResource(cmi.ImageResourceId);
                }

                iv.Tag = cmi.Id;
                imageViewList.Add(iv);

                selected_item_indicator = itemLayout.FindViewById(UIHelper.GetId("selected_item_indicator")) as TextView;
                if (enableSelectedIndicator)
                {
                    selected_item_indicator.Visibility = ViewStates.Visible;
                }

                indicatorList.Add(selected_item_indicator);

                tvBadge = itemLayout.FindViewById(UIHelper.GetId("custom_badge")) as TextView;

                if (String.IsNullOrEmpty(cmi.Badge))
                {
                    tvBadge.Visibility = ViewStates.Gone;
                }
                else
                {
                    int badgeCount = int.Parse(cmi.Badge);
                    if (badgeCount > 0)
                    {
                        tvBadge.Text = badgeCount.ToString();
                        //tvBadge.SetBackgroundDrawable(drawbg(tvBadge));
                        tvBadge.Visibility = ViewStates.Visible;

                        //if (Build.VERSION.SdkInt <= Android.OS.BuildVersionCodes.JellyBean)
                        //{
                        //    //TODO: Fix x location of badge
                        //    tvBadge.SetX(iv.GetX() + iv.Drawable.IntrinsicWidth);
                        //}
                    }
                }
                badgeTextViewList.Add(tvBadge);

                itemLayout.Click += delegate(object sender, EventArgs e)
                {
                    if (EnableClickingTab)
                    {
                        selectedIndex = cmi.Id;
                        mListener.MenuItemSelectedEvent(cmi, imageViewList, titleViewList);
                    }
                };

                row.AddView(itemLayout);
            }

            if (selectedIndex >= 0)
            {
                if (mMenuItems.ElementAt(selectedIndex).ActiveImageId > 0)
                {
                    imageViewList.ElementAt(selectedIndex).SetImageResource(mMenuItems.ElementAt(selectedIndex).ActiveImageId);
                }

                titleViewList.ElementAt(selectedIndex).SetTextColor(selectedTextColor);
                indicatorList.ElementAt(selectedIndex).SetBackgroundColor(selectedTextColor);

                //var ivParent = (RelativeLayout)imageViewList[selectedIndex].Parent.Parent;
                //ivParent.Background = mContext.Resources.GetDrawable(UIHelper.GetDrawableResource("my_menu_item_pressed"));
            }

            table.AddView(row);

            mIsShowing = true;
        }
예제 #3
0
        private void ActionBarTabsSetup(ActionBar actionBar)
        {
            if (actionBar.TabCount == 0)
            {
                return;
            }

            if (menuItems.Count > 0)
            {
                menuItems.Clear();
            }

            mMenu.SetTextColor(myTabbedPage.TextColor.ToAndroid(), myTabbedPage.SelectedTextColor.ToAndroid());

            int ctr = 0;

            foreach (var page in myTabbedPage.Children)
            {
                try
                {
                    var cmi = new CustomMenuItem();
                    cmi.Id      = ctr;
                    cmi.Caption = (myTabbedPage.TextVisible) ? page.Title : "";

                    if (myTabbedPage.ActiveIcons.Count > 0)
                    {
                        cmi.ActiveImageId = UIHelper.GetDrawableResource(myTabbedPage.ActiveIcons.ElementAt(ctr));
                    }

                    if (page.Icon != null && page.Icon.File != null)
                    {
                        cmi.ImageResourceId = UIHelper.GetDrawableResource(page.Icon);
                    }

                    if (cmi.Id == myTabbedPage.BadgeLocation)
                    {
                        cmi.Badge = myTabbedPage.BadgeCount.ToString();
                    }

                    menuItems.Add(cmi);

                    if (!mMenu.IsShowing())
                    {
                        try
                        {
                            mMenu.SetMenuItems(menuItems);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }

                    ctr++;
                }
                catch (Exception)
                {
                    continue;
                }

                _isFirstDesign = false;
            }

            mMenu.SetSelectedIndex(currentTabIndex);

            if (mMenu.IsShowing())
            {
                return;
            }

            if (myTabbedPage.TabScreenLocation == TabGravity.Bottom)
            {
                myTabbedPage.Padding = new Thickness(0, 0, 0, originalPadding);
            }
            else
            {
                myTabbedPage.Padding = new Thickness(0, originalPadding, 0, 0);
            }

            ShowCustomMenu();

            mMenu.UpdateBadgeCount(myTabbedPage.BadgeCount);
        }