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