Esempio n. 1
0
        /// <summary>
        /// Fires when a button is clicked
        /// If hold not true, then play the video path. If vid not found then...
        /// If hold true, then open the button maintenace screen for the selected button.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        public void ButtonClickPlayVid(object sender, EventArgs e)
        {
            //convert sender to custom button type so can access properties
            CustomButton btn = sender as CustomButton;

            if (btn != null)
            {
                if (Hold == false) //if hold button not pressed down
                {
                    Debug.WriteLine("Button {0} Pressed", btn.ID);
                    Debug.WriteLine("Playing vid: {0}", btn.VidPath);

                    //sets the movie player url to the buttons vid path, and plays the vid in fullscreen
                    VideoPlayer.MoviePlayer.ContentUrl = NSUrl.FromFilename(btn.VidPath);
                    VideoPlayer.MoviePlayer.SetFullscreen(true, false);
                    VideoPlayer.MoviePlayer.Play();
                }
                else //if the hold button is held down / hold is true
                {
                    Debug.WriteLine("open button maintenance");
                    this.PresentModalViewController(ButtonMaintenanceScreen.Screen, false); //open the button maintenace screen modal
                    Hold = false;                                                           //reset hold to false otherwise hold stays true after opening button maintenance screen

                    // set button maintenance obj to sender!
                    //create a new button data obj that will be passed to the button mainteance screen
                    //*fixed issure where button maintenance values are changed, but not saved. But it still saved those values because of ref type
                    //set the button data properties to the sender's (button clicked) properties
                    ButtonData buttonData = new ButtonData();
                    buttonData.ID = btn.ID;

                    buttonData.BorderColour = new BorderColourData()
                    {
                        Red = (float)btn.BorderColour.Components[0], Green = (float)btn.BorderColour.Components[1], Blue = (float)btn.BorderColour.Components[2]
                    };

                    buttonData.ImgPath = btn.ImgPath;
                    buttonData.VidPath = btn.VidPath;
                    //set button maintenance screen button to the button data obj
                    ButtonMaintenanceScreen.Button = buttonData;

                    //set button border width on button maintenace screen
                    ButtonMaintenanceScreen.ButtonBorderWidth = AppData.BorderWidth;
                    ButtonMaintenanceScreen.UpdateBorders(); //update border sizes

                    //set sliders - so it matches the colours of the button clicked
                    ButtonMaintenanceScreen.RedSlider.Value   = (float)btn.BorderColour.Components[0];
                    ButtonMaintenanceScreen.GreenSlider.Value = (float)btn.BorderColour.Components[1];
                    ButtonMaintenanceScreen.BlueSlider.Value  = (float)btn.BorderColour.Components[2];

                    //set colour and image box
                    ButtonMaintenanceScreen.SetColourBox(); //change to on change
                    ButtonMaintenanceScreen.SetImageBox();

                    //set the video box (thumbnail)
                    //set the movie player url property to the sender's(button clicked) vidpath
                    //so it can display the videos thumbnail in the video box
                    ButtonMaintenanceScreen.MoviePlayer.ContentUrl = NSUrl.FromFilename(btn.VidPath);
                    ButtonMaintenanceScreen.SetVideoBox();

                    //pass some of the app datas values to the button maintenance screen class
                    ButtonMaintenanceScreen.ButtonsPerPage = (int)AppData.ButtonsPerPage;
                    ButtonMaintenanceScreen.NumberOfPages  = (int)AppData.NumberOfPages;
                }
            }
        }
Esempio n. 2
0
        public UIButton ResetButton; //resets the button to the default settings

        public ButtonMaintenanceScreen()
        {
            GeneralMaintenanceScreen.Saved += SaveGeneral; //

            //create screen
            Screen = new UIViewController();
            Screen.View.BackgroundColor = UIColor.White;

            //create button
            Button = new ButtonData();

            //create media picker
            MediaPicker = new UIImagePickerController();
            //MediaPicker.VideoExportPreset = AVAssetExportSessionPreset.HighestQuality.ToString();
            //System.Diagnostics.Debug.WriteLine(MediaPicker.VideoExportPreset);
            MediaPicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
            MediaPicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary);
            //MediaPicker.ImageExportPreset = UIImagePickerControllerImageUrlExportPreset.Current;
            MediaPicker.VideoExportPreset     = AVAssetExportSessionPreset.Passthrough.GetConstant().ToString();
            MediaPicker.FinishedPickingMedia += Handle_FinishedPickingMedia;
            MediaPicker.Canceled             += Handle_Canceled;

            //1. create views
            //create reset button
            ResetButton = new UIButton();
            ResetButton.BackgroundColor = UIColor.Green;
            ResetButton.SetTitle("Reset button\nsettings", UIControlState.Normal);
            ResetButton.SetTitleColor(UIColor.Black, UIControlState.Normal);

            //when video button clicked - open the media picker native interface
            ResetButton.TouchUpInside += ResetButtonData;

            ResetButton.Layer.BorderColor   = ButtonBorderColour.CGColor;
            ResetButton.Layer.BorderWidth   = ButtonBorderWidth;
            ResetButton.BackgroundColor     = ButtonBackgroundColour;
            ResetButton.LineBreakMode       = UILineBreakMode.WordWrap;//allow multiple lines for text inside video button
            ResetButton.VerticalAlignment   = UIControlContentVerticalAlignment.Center;
            ResetButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
            ResetButton.Layer.CornerRadius  = ButtonCornerRadius;

            //create video button
            VideoButton = new UIButton();
            VideoButton.BackgroundColor = UIColor.Green;
            VideoButton.SetTitle("Choose a video for\nthe button \nto play", UIControlState.Normal);
            VideoButton.SetTitleColor(UIColor.Black, UIControlState.Normal);

            //when video button clicked - open the media picker native interface
            VideoButton.TouchUpInside += (s, e) =>
            {
                try
                {
                    //set the media picker to show only videos
                    MediaPicker.MediaTypes = new string[] { UTType.Movie, UTType.Video }; //vids?
                    Screen.PresentViewControllerAsync(MediaPicker, true);
                }
                catch (Exception ex)
                {
                    //if the device doesn't have any videos, pop up an alert box with a message
                    Console.WriteLine(ex.Message);
                    UIAlertView alert = new UIAlertView()
                    {
                        Title   = "No Videos Alert",
                        Message = "You don't have any videos to select. To download or record vids..."
                    };

                    alert.AddButton("OK");
                    alert.Show();
                }
            };

            VideoButton.Layer.BorderColor = ButtonBorderColour.CGColor;
            VideoButton.Layer.BorderWidth = ButtonBorderWidth;
            VideoButton.BackgroundColor   = ButtonBackgroundColour;
            VideoButton.LineBreakMode     = UILineBreakMode.WordWrap;//allow multiple lines for text inside video button
            //VideoButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center; //center text
            VideoButton.VerticalAlignment   = UIControlContentVerticalAlignment.Center;
            VideoButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
            VideoButton.Layer.CornerRadius  = ButtonCornerRadius;

            //create image button
            ImageButton = new UIButton();
            ImageButton.BackgroundColor = UIColor.Green;
            ImageButton.SetTitle("Choose an image for\nthe button thumbnail", UIControlState.Normal);
            ImageButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
            //when image button clicked - open the media picker native interface
            ImageButton.TouchUpInside += (s, e) =>
            {
                try
                {
                    //set the media picker to show only images
                    MediaPicker.MediaTypes = new string[] { UTType.Image };
                    Screen.PresentViewControllerAsync(MediaPicker, true);
                }
                catch (Exception ex)
                {
                    //if the device doesn't have any images, pop up an alert box with a message
                    Console.WriteLine(ex.Message);
                    UIAlertView alert = new UIAlertView()
                    {
                        Title   = "No Images Alert",
                        Message = "You don't have any images to select. To download or take photos..."
                    };

                    alert.AddButton("OK");
                    alert.Show();
                }
            };
            ImageButton.Layer.BorderColor   = ButtonBorderColour.CGColor;
            ImageButton.Layer.BorderWidth   = ButtonBorderWidth;
            ImageButton.BackgroundColor     = ButtonBackgroundColour;
            ImageButton.LineBreakMode       = UILineBreakMode.WordWrap;                   //allow multiple lines for text inside video button
            ImageButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center; //center text
            ImageButton.Layer.CornerRadius  = ButtonCornerRadius;

            //create image box
            ImageBox = new UIImageView();
            ImageBox.Layer.BorderWidth  = ButtonBorderWidth;
            ImageBox.Layer.CornerRadius = ButtonCornerRadius;
            ImageBox.ClipsToBounds      = true;
            ImageBox.Layer.BorderColor  = UIColor.Gray.CGColor;


            //create video box
            VideoBox = new UIImageView();
            VideoBox.Layer.BorderWidth  = ButtonBorderWidth;
            VideoBox.Layer.CornerRadius = ButtonCornerRadius;
            VideoBox.ClipsToBounds      = true;
            VideoBox.Layer.BorderColor  = UIColor.Gray.CGColor;

            //create back button
            BackButton = new UIButton();
            BackButton.TouchUpInside += CloseScreen;
            BackButton.SetTitle("Back", UIControlState.Normal);
            BackButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
            Screen.Add(BackButton); //add back button to screen
            BackButton.Layer.BorderColor  = ButtonBorderColour.CGColor;
            BackButton.Layer.BorderWidth  = ButtonBorderWidth;
            BackButton.BackgroundColor    = ButtonBackgroundColour;
            BackButton.Layer.CornerRadius = ButtonCornerRadius;

            //create save button
            SaveButton = new UIButton();
            SaveButton.BackgroundColor = UIColor.Red;
            SaveButton.TouchUpInside  += Save;
            SaveButton.SetTitle("Save", UIControlState.Normal);
            SaveButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
            Screen.Add(SaveButton); //add save button to screen
            SaveButton.Layer.BorderColor  = ButtonBorderColour.CGColor;
            SaveButton.Layer.BorderWidth  = ButtonBorderWidth;
            SaveButton.BackgroundColor    = ButtonBackgroundColour;
            SaveButton.Layer.CornerRadius = ButtonCornerRadius;

            //create colour box
            ColourBox = new UIView();
            ColourBox.Layer.BorderWidth  = ButtonBorderWidth;
            ColourBox.Layer.CornerRadius = ButtonCornerRadius;
            ColourBox.Layer.BorderColor  = UIColor.Gray.CGColor;

            //create general button
            GeneralButton = new UIButton();
            GeneralButton.BackgroundColor = UIColor.Green;
            //open the general settings modal.
            //pass some app data
            GeneralButton.TouchUpInside += (o, s) =>
            {
                //remove?
                //GeneralMaintenanceScreen.ButtonsPerPage = ButtonsPerPage;
                //GeneralMaintenanceScreen.NumberOfPages = NumberOfPages;
                Screen.PresentModalViewController(GeneralMaintenanceScreen.Screen, false); //

                GeneralMaintenanceScreen.NumberOfPages    = this.NumberOfPages;
                GeneralMaintenanceScreen.ButtonsPerPage   = this.ButtonsPerPage;
                GeneralMaintenanceScreen.BordersThickness = this.ButtonBorderWidth;
                GeneralMaintenanceScreen.SetDropDowns();
                //ImageBox.Layer.BorderColor = UIColor.Clear.CGColor;
            };
            GeneralButton.SetTitle("JustButtons\nSettings", UIControlState.Normal);
            GeneralButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
            GeneralButton.Layer.BorderColor   = ButtonBorderColour.CGColor;
            GeneralButton.Layer.BorderWidth   = ButtonBorderWidth;
            GeneralButton.BackgroundColor     = ButtonBackgroundColour;
            GeneralButton.Layer.CornerRadius  = ButtonCornerRadius;
            GeneralButton.LineBreakMode       = UILineBreakMode.WordWrap;                   //allow multiple lines for text inside video button
            GeneralButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center; //center text

            //color sliders
            RedSlider = new UISlider();
            RedSlider.ValueChanged += UpdateBorderColor;

            GreenSlider = new UISlider();
            GreenSlider.ValueChanged += UpdateBorderColor;

            BlueSlider = new UISlider();
            BlueSlider.ValueChanged += UpdateBorderColor;

            //create labels
            VideoButtonTitle               = new UILabel();
            VideoButtonTitle.Text          = "Click below to change the video played:";
            VideoButtonTitle.TextColor     = UIColor.Black;
            VideoButtonTitle.TextAlignment = UITextAlignment.Left;
            VideoButtonTitle.LineBreakMode = UILineBreakMode.WordWrap;
            VideoButtonTitle.Lines         = 2;

            ImageButtonTitle               = new UILabel();
            ImageButtonTitle.Text          = "Click below to change the button's image:";
            ImageButtonTitle.TextColor     = UIColor.Black;
            ImageButtonTitle.TextAlignment = UITextAlignment.Left;
            ImageButtonTitle.LineBreakMode = UILineBreakMode.WordWrap;
            ImageButtonTitle.Lines         = 2;

            ColourBoxTitle               = new UILabel();
            ColourBoxTitle.Text          = "Adjust the sliders to change the border colour:";
            ColourBoxTitle.TextColor     = UIColor.Black;
            ColourBoxTitle.TextAlignment = UITextAlignment.Left;
            ColourBoxTitle.LineBreakMode = UILineBreakMode.WordWrap;
            ColourBoxTitle.Lines         = 2;

            SettingsButtonTitle               = new UILabel();
            SettingsButtonTitle.Text          = "Click below to change the number of pages and buttons, and border thickness:";
            SettingsButtonTitle.TextColor     = UIColor.Black;
            SettingsButtonTitle.TextAlignment = UITextAlignment.Left;
            SettingsButtonTitle.LineBreakMode = UILineBreakMode.WordWrap;
            SettingsButtonTitle.Lines         = 2;

            //2. add views to parent view
            Screen.View.Add(VideoButton);
            Screen.View.Add(ImageButton);
            Screen.View.Add(ImageBox);
            Screen.View.Add(VideoBox);
            Screen.View.Add(BackButton);
            Screen.View.Add(SaveButton);
            Screen.Add(ColourBox);
            Screen.Add(GeneralButton);
            Screen.Add(RedSlider);
            Screen.Add(GreenSlider);
            Screen.Add(BlueSlider);
            Screen.Add(ImageButtonTitle);
            Screen.Add(VideoButtonTitle);
            Screen.Add(ColourBoxTitle);
            Screen.Add(SettingsButtonTitle);
            Screen.Add(ResetButton);

            //3. call method on parent view
            Screen.View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();

            //4. add constraints
            Screen.View.AddConstraints(
                VideoButton.AtTopOf(Screen.View, UIApplication.SharedApplication.StatusBarFrame.Height + 75),
                VideoButton.AtLeftOf(Screen.View, 70),
                VideoButton.WithRelativeWidth(Screen.View, 0.19f),
                VideoButton.Height().EqualTo(100),

                ImageButton.Below(VideoButton, 80),
                ImageButton.WithSameLeft(VideoButton),
                ImageButton.WithSameWidth(VideoButton),
                ImageButton.WithSameHeight(VideoButton),

                VideoBox.WithSameTop(VideoButton),
                VideoBox.Left().EqualTo().RightOf(VideoButton).Plus(35),
                VideoBox.WithRelativeWidth(Screen.View, 0.17f),
                VideoBox.Height().EqualTo(100),

                ImageBox.WithSameTop(ImageButton),
                ImageBox.WithSameLeft(VideoBox),
                ImageBox.WithSameWidth(VideoBox),
                ImageBox.WithSameHeight(VideoBox),

                BackButton.WithSameTop(VideoButton),
                BackButton.AtRightOf(Screen.View, 70),
                BackButton.WithSameWidth(VideoButton),
                BackButton.WithSameHeight(VideoButton),

                SaveButton.WithSameTop(ImageButton),
                SaveButton.AtRightOf(Screen.View, 70),
                SaveButton.WithSameWidth(VideoButton),
                SaveButton.WithSameHeight(VideoButton),

                ColourBox.Below(ImageButton, 80),
                ColourBox.WithSameLeft(VideoButton),
                ColourBox.WithSameWidth(VideoButton),
                ColourBox.WithSameHeight(VideoBox),

                GeneralButton.Below(ColourBox, 80),
                GeneralButton.WithSameLeft(VideoButton),
                GeneralButton.WithSameWidth(VideoButton),
                GeneralButton.WithSameHeight(VideoButton),

                RedSlider.WithSameTop(ColourBox),
                RedSlider.Left().EqualTo().RightOf(ColourBox).Plus(35),
                RedSlider.WithRelativeWidth(Screen.View, 0.11f),
                RedSlider.WithSameHeight(ColourBox),

                GreenSlider.WithSameTop(ColourBox),
                GreenSlider.Left().EqualTo().RightOf(RedSlider).Plus(30),
                GreenSlider.WithSameWidth(RedSlider),
                GreenSlider.WithSameHeight(ColourBox),

                BlueSlider.WithSameTop(ColourBox),
                BlueSlider.Left().EqualTo().RightOf(GreenSlider).Plus(30),
                BlueSlider.WithSameWidth(RedSlider),
                BlueSlider.WithSameHeight(ColourBox),

                VideoButtonTitle.Above(VideoButton, 5),
                VideoButtonTitle.WithSameLeft(VideoButton),
                VideoButtonTitle.WithRelativeWidth(VideoButton, 3.1f),
                VideoButtonTitle.Height().EqualTo(80),

                ImageButtonTitle.Above(ImageButton, 5),
                ImageButtonTitle.WithSameLeft(VideoButtonTitle),
                ImageButtonTitle.WithSameWidth(VideoButtonTitle),
                ImageButtonTitle.WithSameHeight(VideoButtonTitle),

                ColourBoxTitle.Above(ColourBox, 5),
                ColourBoxTitle.WithSameLeft(VideoButtonTitle),
                ColourBoxTitle.WithSameWidth(VideoButtonTitle),
                ColourBoxTitle.WithSameHeight(VideoButtonTitle),

                SettingsButtonTitle.Above(GeneralButton, 5),
                SettingsButtonTitle.WithSameLeft(VideoButtonTitle),
                SettingsButtonTitle.WithSameWidth(VideoButtonTitle),
                SettingsButtonTitle.WithSameHeight(VideoButtonTitle),

                ResetButton.WithSameTop(GeneralButton),
                ResetButton.AtRightOf(Screen.View, 70),
                ResetButton.WithSameWidth(VideoButton),
                ResetButton.WithSameHeight(VideoButton)
                );
        }
Esempio n. 3
0
        /// <summary>
        /// Creates the cells and adds them to grid.
        /// Creates the buttons and adds them to cell.
        /// Creates the image from img path and adds them to button.
        /// </summary>
        public void CreateCells()
        {
            //gets the starting index for button ids using page and number of buttons per page
            nint btnIdCounter = (PageNum - 1) * AppData.ButtonsPerPage;

            for (int c = 0; c < Cols; c++)
            {
                for (int r = 0; r < Rows; r++)
                {
                    //create cell
                    CGRect cellFrame          = new CGRect(c * CellW, r * CellH, CellW, CellH);
                    UICollectionViewCell cell = new UICollectionViewCell(cellFrame);
                    Grid.AddSubview(cell); //add cell to grid

                    //create button and button data
                    ButtonData   theButtonData;
                    CustomButton theButton = new CustomButton();
                    CGRect       btnFrame  = new CGRect(0 + (ButtonPadding / 2), 0 + (ButtonPadding / 2), CellW - (ButtonPadding), CellH - (ButtonPadding));

                    //retrives button data obj from list of buttons using id
                    //returns null if no match
                    theButtonData = AppData.Buttons.Find((x) =>
                    {
                        return(x.ID == btnIdCounter);
                    });

                    //if no button data obj existed with the button id
                    if (theButtonData == null) //create default button data
                    {
                        //set the button data default values
                        theButtonData              = new ButtonData();
                        theButtonData.ID           = (int)btnIdCounter;
                        theButtonData.BorderColour = new BorderColourData()
                        {
                            Red = 0, Green = 0, Blue = 105
                        };
                        theButtonData.VidPath = "babyshark.m4v";
                        //theButtonData.ImgPath = "shark.jpg";
                        theButtonData.ImgPath = "defaultbuttonimg.png";
                    }

                    //fill the button with the button data properties
                    theButton.ID           = (int)theButtonData.ID;
                    theButton.BorderColour = UIColor.FromRGB(theButtonData.BorderColour.Red, theButtonData.BorderColour.Green, theButtonData.BorderColour.Blue).CGColor;
                    theButton.VidPath      = theButtonData.VidPath;
                    theButton.ImgPath      = theButtonData.ImgPath;
                    //set the button styling and settings
                    theButton.Layer.BorderColor = theButton.BorderColour;

                    //set constant properties for every button
                    theButton.Frame = btnFrame;
                    //theButton.Layer.BorderWidth = ButtonBorderW;
                    theButton.Layer.BorderWidth  = AppData.BorderWidth;
                    theButton.Layer.CornerRadius = ButtonCornerRadius;

                    //
                    var maskingShapeLayer = new CAShapeLayer()
                    {
                        Path = UIBezierPath.FromRoundedRect(theButton.Bounds, UIRectCorner.AllCorners, new CGSize(26, 26)).CGPath
                    };
                    theButton.Layer.Mask = maskingShapeLayer;

                    //add play vid function to button click
                    theButton.TouchUpInside -= ButtonClickPlayVid; //fixes a saved button playing multiple times!
                    theButton.TouchUpInside += ButtonClickPlayVid;

                    //add button to cell
                    cell.AddSubview(theButton);

                    //create img
                    CGRect      imgFrame = new CGRect(0, 0, theButton.Bounds.Width, theButton.Bounds.Height);
                    UIImageView img      = new UIImageView(imgFrame);
                    img.Image = new UIImage(theButton.ImgPath); //set the image to the button img path
                    img.UserInteractionEnabled = false;         //So user can still click the button
                    img.Layer.CornerRadius     = ButtonCornerRadius;
                    img.ClipsToBounds          = true;          //enables corner radius on img

                    //add img to button
                    theButton.AddSubview(img);

                    btnIdCounter++; //increments the button id counter for the next button
                }
            }
        }