public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Create a TrayManager to handle a collection of "palette"
            // trays. It will automatically close any open tray when
            // another tray in this collection is opened.
            trayManager = new ACTrayManager();

            // Automatically close the left tray when any tray
            // in the manager's collection is opened
            trayManager.TrayOpened += (tray) => {
                // Animate the tray being closed
                leftTray.CloseTray(true);

                // Are we on an iPhone?
                if (UserInterfaceIdiomIsPhone)
                {
                    // Yes, close the right tray too
                    rightTray.CloseTray(true);
                }
            };

            // Wireup the left side tray created in the .xib file and style
            // it to be a drag out tray.
            if (leftTray != null)
            {
                // Set tray type
                leftTray.orientation = ACTrayOrientation.Left;
                leftTray.tabLocation = ACTrayTabLocation.BottomOrRight;
                leftTray.frameType   = ACTrayFrameType.EdgeOnly;
                leftTray.tabType     = ACTrayTabType.IconAndTitle;

                // Style tray
                leftTray.appearance.background = UIColor.DarkGray;
                leftTray.icon  = UIImage.FromFile("Images/icon_calendar.png");
                leftTray.title = "Events";
                leftTray.appearance.tabAlpha = 0.8f;
                leftTray.CloseTray(false);

                // Respond to the tray being touched
                leftTray.Touched += (tray) => {
                    // Are we on an iPhone?
                    if (UserInterfaceIdiomIsPhone)
                    {
                        //Yes, close this tray and aminate the closing
                        rightTray.CloseTray(true);
                    }

                    // Tell any open palette trays to close
                    trayManager.CloseAllTrays();

                    // Close document tray
                    if (documentTray != null)
                    {
                        documentTray.CloseTray(true);
                    }
                };
            }

            // Wireup the right tray created in the .xib file and style it
            // to be a popup tray. Touch it's dragTab to open and close it.
            if (rightTray != null)
            {
                // Are we on an iPhone?
                if (UserInterfaceIdiomIsPhone)
                {
                    // Move the subview into view and attach it to the master view
                    rightTray.MoveTo(new CGPoint(320f - rightTray.Frame.Width, 0f));
                    View.AddSubview(rightTray);

                    // iPhone specific settings
                    rightTray.tabLocation = ACTrayTabLocation.BottomOrRight;
                }

                // Set tray type
                rightTray.trayType            = ACTrayType.Popup;
                rightTray.orientation         = ACTrayOrientation.Right;
                rightTray.bringToFrontOnTouch = true;
                if (UserInterfaceIdiomIsPhone)
                {
                    rightTray.CloseTray(false);
                }

                // Respond to the tray being opened
                rightTray.Opened += (tray) => {
                    //Are we on an iPhone?
                    if (UserInterfaceIdiomIsPhone)
                    {
                        //Yes, close this tray and aminate the closing
                        leftTray.CloseTray(true);
                    }

                    // Tell any open palette trays to close
                    trayManager.CloseAllTrays();

                    // Close document tray
                    if (documentTray != null)
                    {
                        documentTray.CloseTray(true);
                    }
                };
            }

            // Wireup the document tray created in the .xib file and style it
            // to be an auto closing popup. When the user selects something
            // from it's content area, it is automatically closed.
            if (documentTray != null)
            {
                // Set tray type
                documentTray.trayType    = ACTrayType.AutoClosingPopup;
                documentTray.orientation = ACTrayOrientation.Bottom;
                documentTray.tabType     = ACTrayTabType.GripAndTitle;

                // Style tray
                documentTray.tabWidth = 125f;
                documentTray.title    = "Documents";
                documentTray.CloseTray(false);

                // Respond to the tray being opened
                documentTray.Opened += (tray) => {
                    // Close left and right trays
                    leftTray.CloseTray(true);
                    rightTray.CloseTray(true);
                };
            }

            // Palette 1
            // Wireup the 1st palette from the .xib file and style it
            // to be an auto closing popup. When the user selects something
            // from it's content area, it is automatically closed.
            if (paletteTray != null)
            {
                // Are we on an iPhone?
                if (UserInterfaceIdiomIsPhone)
                {
                    // Move the subview into view and attach it to the master view
                    paletteTray.MoveTo(new CGPoint(0, 0));
                    View.AddSubview(paletteTray);

                    // Adjust tab location
                    paletteTray.tabLocation = ACTrayTabLocation.Custom;
                    paletteTray.tabOffset   = 55f;

                    //iPhone specific settings
                    paletteTray.orientation = ACTrayOrientation.Right;
                }
                else
                {
                    // iPad specific settings
                    paletteTray.tabLocation = ACTrayTabLocation.TopOrLeft;
                    paletteTray.orientation = ACTrayOrientation.Top;
                }

                // Set tray type
                paletteTray.trayType = ACTrayType.AutoClosingPopup;
                paletteTray.tabType  = ACTrayTabType.IconAndTitle;
                paletteTray.CloseTray(false);

                // Style tray
                paletteTray.tabWidth = 125f;
                paletteTray.icon     = UIImage.FromFile("Images/icon_palette.png");
                paletteTray.title    = "Palette";

                // Add this tray to the manager's collection
                trayManager.AddTray(paletteTray);
            }

            // Palette 2
            // Wireup the 2nd palette from the .xib file and style it
            // to be a popup tray. Touch it's dragTab to open and close it.
            if (propertyTray != null)
            {
                // Are we on an iPhone?
                if (UserInterfaceIdiomIsPhone)
                {
                    // Move subview into view and attach it to the master view
                    propertyTray.MoveTo(new CGPoint(0, 170));
                    View.AddSubview(propertyTray);

                    // iPhone specific settings
                    propertyTray.orientation = ACTrayOrientation.Right;
                }
                else
                {
                    // iPad specific settings
                    propertyTray.orientation = ACTrayOrientation.Top;
                }

                // Set tray type
                propertyTray.trayType    = ACTrayType.Popup;
                propertyTray.tabLocation = ACTrayTabLocation.TopOrLeft;
                propertyTray.tabType     = ACTrayTabType.IconAndTitle;
                propertyTray.CloseTray(false);

                // Style tray
                propertyTray.tabWidth = 125f;
                propertyTray.icon     = UIImage.FromFile("Images/icon_measures.png");
                propertyTray.title    = "Properties";

                // Add this tray to the manager's collection
                trayManager.AddTray(propertyTray);
            }

            // Palette 3
            // Wireup the 3rd palette from the .xib file and style it
            // to be an auto closing popup. When the user selects something
            // from it's content area, it is automatically closed.
            if (toolsTray != null)
            {
                // Are we on an iPhone?
                if (UserInterfaceIdiomIsPhone)
                {
                    // Move the subview into view and attach it to the master view
                    toolsTray.MoveTo(new CGPoint(0, 0));
                    View.AddSubview(toolsTray);

                    // Adjust tab location
                    toolsTray.tabLocation = ACTrayTabLocation.Custom;
                    toolsTray.tabOffset   = 5f;

                    // iPhone specific settings
                    toolsTray.orientation = ACTrayOrientation.Right;
                }
                else
                {
                    // iPad specific settings
                    toolsTray.orientation = ACTrayOrientation.Top;
                }

                // Set tray type
                toolsTray.trayType = ACTrayType.AutoClosingPopup;
                toolsTray.tabType  = ACTrayTabType.IconOnly;
                toolsTray.tabType  = ACTrayTabType.CustomDrawn;
                toolsTray.CloseTray(false);

                // Style tray
                toolsTray.tabWidth = 50f;
                toolsTray.appearance.background = UIColor.FromRGB(38, 38, 38);

                // Custom draw the tray's drag tab
                toolsTray.CustomDrawDragTab += (tray, rect) => {
                    // Mix background color
                    UIColor tabColor;

                    if (tray.frameType == ACTrayFrameType.None)
                    {
                        tabColor = tray.appearance.background.ColorWithAlpha(tray.appearance.tabAlpha);
                    }
                    else
                    {
                        tabColor = tray.appearance.frame.ColorWithAlpha(tray.appearance.tabAlpha);
                    }

                    // Save current context
                    var context = UIGraphics.GetCurrentContext();

                    // Draw tab in the given bounds
                    var bodyPath = UIBezierPath.FromRect(rect);
                    tabColor.SetFill();
                    bodyPath.Fill();

                    // Draw icon
                    var icon        = UIImage.FromFile("Images/icon_pencil.png");
                    var y           = rect.GetMinY() + 5f;
                    var tabIconRect = new CGRect(rect.GetMinX() + 1, y, 30, 30);
                    var tabIconPath = UIBezierPath.FromRect(tabIconRect);
                    context.SaveState();
                    tabIconPath.AddClip();
                    icon.Draw(new CGRect((float)Math.Floor(tabIconRect.GetMinX() + 1f), (float)Math.Floor(y + 0.5f), icon.Size.Width, icon.Size.Height), CGBlendMode.Normal, tray.appearance.tabAlpha);
                    context.RestoreState();
                };

                // Add this tray to the manager's collection
                trayManager.AddTray(toolsTray);
            }
        }
Ejemplo n.º 2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Gain Access to all views and controls in our layout
            leftTray     = FindViewById <ACTray> (Resource.Id.trayLeft);
            rightTray    = FindViewById <ACTray> (Resource.Id.trayRight);
            toolsTray    = FindViewById <ACTray> (Resource.Id.trayTools);
            propertyTray = FindViewById <ACTray> (Resource.Id.trayProperty);
            paletteTray  = FindViewById <ACTray> (Resource.Id.trayPalette);
            documentTray = FindViewById <ACTray> (Resource.Id.trayDocuments);

            // Create a TrayManager to handle a collection of "palette"
            // trays. It will automatically close any open tray when
            // another tray in this collection is opened.
            trayManager = new ACTrayManager();

            // Automatically close the left and right trays when any tray
            // in the manager's collection is opened
            trayManager.TrayOpened += (tray) => {
                // Animate the trays being closed
                leftTray.CloseTray(true);
                rightTray.CloseTray(true);
            };

            // Setup the left side tray
            leftTray.trayType            = ACTrayType.Draggable;
            leftTray.orientation         = ACTrayOrientation.Left;
            leftTray.tabLocation         = ACTrayTabLocation.BottomOrRight;
            leftTray.frameType           = ACTrayFrameType.EdgeOnly;
            leftTray.tabType             = ACTrayTabType.IconAndTitle;
            leftTray.bringToFrontOnTouch = true;

            // Style tray
            leftTray.appearance.background = Color.Gray;
            leftTray.appearance.border     = Color.Red;
            leftTray.icon  = Resource.Drawable.icon_calendar;
            leftTray.title = "Events";
            leftTray.appearance.tabAlpha = 100;
            leftTray.CloseTray(false);

            // Respond to the left tray being touched
            leftTray.Touched += (tray) => {
                //Yes, close this tray and aminate the closing
                rightTray.CloseTray(true);

                // Tell any open palette trays to close
                trayManager.CloseAllTrays();

                // Close document tray
                documentTray.CloseTray(true);
            };

            // Setup the right side tray
            rightTray.trayType            = ACTrayType.Popup;
            rightTray.orientation         = ACTrayOrientation.Right;
            rightTray.bringToFrontOnTouch = true;
            rightTray.CloseTray(false);

            // Respond to the tray being opened
            rightTray.Opened += (tray) => {
                //Close this tray and aminate the closing
                leftTray.CloseTray(true);

                // Tell any open palette trays to close
                trayManager.CloseAllTrays();

                // Close document tray
                documentTray.CloseTray(true);
            };

            // Set tray type
            documentTray.trayType            = ACTrayType.AutoClosingPopup;
            documentTray.orientation         = ACTrayOrientation.Bottom;
            documentTray.tabType             = ACTrayTabType.GripAndTitle;
            documentTray.bringToFrontOnTouch = true;

            // Style tray
            documentTray.tabWidth = 125;
            documentTray.appearance.background = Color.Gray;
            documentTray.title = "Documents";
            documentTray.CloseTray(false);

            // Respond to the tray being opened
            documentTray.Opened += (tray) => {
                // Close left and right trays
                leftTray.CloseTray(true);
                rightTray.CloseTray(true);
            };

            //--------------------------------------------------------------------------------------
            // Create three action tray's and use them as a collection via an ActionTrayManager
            //--------------------------------------------------------------------------------------

            //--------------------------------------------------------------------------------------
            // Palette 1
            // Set tray type
            paletteTray.trayType    = ACTrayType.AutoClosingPopup;
            paletteTray.orientation = ACTrayOrientation.Top;
            paletteTray.tabLocation = ACTrayTabLocation.TopOrLeft;
            paletteTray.tabType     = ACTrayTabType.IconAndTitle;
            paletteTray.CloseTray(false);

            // Style tray
            paletteTray.tabWidth = 125;
            paletteTray.appearance.background = Color.Gray;
            paletteTray.icon  = Resource.Drawable.icon_palette;
            paletteTray.title = "Palette";

            // Add this tray to the manager's collection
            trayManager.AddTray(paletteTray);

            //--------------------------------------------------------------------------------------
            // Palette 2
            // Setup property tray type
            propertyTray.trayType    = ACTrayType.Popup;
            propertyTray.orientation = ACTrayOrientation.Top;
            propertyTray.tabLocation = ACTrayTabLocation.TopOrLeft;
            propertyTray.tabType     = ACTrayTabType.IconAndTitle;
            propertyTray.CloseTray(false);

            // Style tray
            propertyTray.tabWidth = 125;
            propertyTray.appearance.background = Color.Rgb(38, 38, 38);
            propertyTray.icon  = Resource.Drawable.icon_measures;
            propertyTray.title = "Properties";

            // Add this tray to the manager's collection
            trayManager.AddTray(propertyTray);

            //--------------------------------------------------------------------------------------
            // Palette 3
            // Setup tools tray type
            toolsTray.trayType    = ACTrayType.AutoClosingPopup;
            toolsTray.orientation = ACTrayOrientation.Top;
            toolsTray.tabType     = ACTrayTabType.IconOnly;
            toolsTray.CloseTray(false);

            // Style tools tray
            toolsTray.tabWidth              = 50;
            toolsTray.tabLocation           = ACTrayTabLocation.BottomOrRight;
            toolsTray.appearance.background = Color.Rgb(38, 38, 38);
            toolsTray.tabType = ACTrayTabType.CustomDrawn;
            toolsTray.icon    = Resource.Drawable.icon_pencil;

            // Custom draw this tab
            toolsTray.CustomDrawDragTab += (tray, canvas, rect) => {
                //Draw background
                var body = new ShapeDrawable(new RectShape());
                body.Paint.Color = tray.appearance.background;
                body.SetBounds(rect.Left, rect.Top, rect.Right, rect.Bottom);
                body.Draw(canvas);

                //Define icon paint
                var iPaint = new Paint();
                iPaint.Alpha = tray.appearance.tabAlpha;

                //Load bitmap
                var bitmap = BitmapFactory.DecodeResource(Resources, tray.icon);

                //Draw image
                canvas.DrawBitmap(bitmap, rect.Left + 1, rect.Top + 5, iPaint);
            };

            // Add this tray to the manager's collection
            trayManager.AddTray(toolsTray);
        }