public MediaSourceChooser(AddEventsSituationsOrThoughts masterObject, CustomLayout pageContainer, string type) { MasterObject = masterObject; CustomLayout masterLayout = new CustomLayout(); masterLayout.BackgroundColor = Color.Transparent; //IDeviceSpec deviceSpec = DependencyService.Get<IDeviceSpec>(); double screenWidth = App.screenWidth; double screenHeight = App.screenHeight; PageContainer = pageContainer; StackLayout layout = new StackLayout(); layout.BackgroundColor = Color.Black; layout.Opacity = .6; layout.WidthRequest = screenWidth; layout.HeightRequest = screenHeight; TapGestureRecognizer emptyAreaTapGestureRecognizer = new TapGestureRecognizer(); emptyAreaTapGestureRecognizer.Tapped += (s, e) => { View pickView = PageContainer.Children.FirstOrDefault(pick => pick.ClassId == "mediachooser"); PageContainer.Children.Remove(pickView); pickView = null; }; layout.GestureRecognizers.Add(emptyAreaTapGestureRecognizer); CustomImageButton imageButton = new CustomImageButton(); imageButton.ImageName = Device.OnPlatform("image.png", "image.png", @"/Assets/image.png"); imageButton.WidthRequest = screenWidth * 20 / 100; imageButton.HeightRequest = screenHeight * 10 / 100; imageButton.ClassId = type; imageButton.Clicked += OnImageButtonClicked; CustomImageButton videoButton = new CustomImageButton(); videoButton.ImageName = Device.OnPlatform("video.png", "video.png", @"/Assets/video.png"); videoButton.WidthRequest = screenWidth * 20 / 100; videoButton.HeightRequest = screenHeight * 10 / 100; videoButton.ClassId = type; videoButton.Clicked += OnVideoButtonClicked; masterLayout.AddChildToLayout(layout, 0, 0); masterLayout.AddChildToLayout(imageButton, 40, 40); masterLayout.AddChildToLayout(videoButton, 40, 60); this.BackgroundColor = Color.Transparent; Content = masterLayout; }
void OnAddButtonClicked(object sender, EventArgs e) { try { if (pageTitle == Constants.SELECT_EMOTIONS) { CustomEntry emotionsEntry = new CustomEntry(); emotionsEntry.BackgroundColor = Color.White; emotionsEntry.Placeholder = "Enter emotion"; emotionsEntry.WidthRequest = screenWidth * 75 / 100; emotionsEntry.TextColor = Color.Black; listTitle.IsVisible = false; addButton.IsVisible = false; emotionsEntry.TextChanged += EmotionsEntry_TextChanged; addEmotionButton = new Image(); addEmotionButton.Source = (FileImageSource)ImageSource.FromFile(Device.OnPlatform("tick_with_bg.png", "tick_with_bg.png", "//Assets//tick_with_bg.png")); addEmotionButton.WidthRequest = Device.OnPlatform(25, 25, 30); addEmotionButton.HeightRequest = Device.OnPlatform(25, 25, 30); StackLayout addEmotionButtonLayout = new StackLayout(); addEmotionButtonLayout.HeightRequest = 50; addEmotionButtonLayout.WidthRequest = 50; addEmotionButtonLayout.BackgroundColor = Color.Transparent; TapGestureRecognizer addEmotionButtonLayoutTapGestureRecognizer = new TapGestureRecognizer(); addEmotionButtonLayoutTapGestureRecognizer.Tapped += async ( object addsender, EventArgs adde) => { IProgressBar progressBar = DependencyService.Get<IProgressBar>(); progressBar.ShowProgressbar("sending new emotion"); //User user = App.Settings.GetUser(); listTitle.IsVisible = true; addButton.IsVisible = true; addEmotionButton.IsVisible = false; emotionsEntry.IsVisible = false; addEmotionButtonLayout.IsVisible = false; if (emotionsEntry.Text == null) { progressBar.ShowToast("emotion is empty"); progressBar.HideProgressbar(); return; } if (emotionsEntry.Text != null && emotionsEntry.Text.Trim().Length == 0) { progressBar.ShowToast("emotion is empty"); progressBar.HideProgressbar(); return; } User user = App.Settings.GetUser(); if (user == null) { return; } var addService = await ServiceHelper.AddEmotion(FeelingNowPage.sliderValue.ToString(), emotionsEntry.Text, user.UserId); await FeelingsPage.DownloadAllEmotions(); View pickView = pageContainedLayout.Children.FirstOrDefault(pick => pick.ClassId == "ePicker"); pageContainedLayout.Children.Remove(pickView); pickView = null; progressBar.HideProgressbar(); if(listView.SelectedItem != null) { listView.SelectedItem = null; } //await Task.Delay( TimeSpan.FromSeconds( 1 ) ); CustomListViewItem newEmotionItem = new CustomListViewItem(); newEmotionItem.EmotionID = App.emotionsListSource.First().EmotionID; newEmotionItem.Name = App.emotionsListSource.First().Name; newEmotionItem.SliderValue = App.emotionsListSource.First().SliderValue; SelectedItemChangedEventArgs newEmotionEvent = new SelectedItemChangedEventArgs( newEmotionItem ); FeelingsPage.OnEmotionalPickerItemSelected( this, newEmotionEvent ); }; addEmotionButtonLayout.GestureRecognizers.Add(addEmotionButtonLayoutTapGestureRecognizer); masterLayout.AddChildToLayout(addEmotionButton, 85, (100 - topYPos - 2) - 6); masterLayout.AddChildToLayout(emotionsEntry, 7, (100 - topYPos - 2) - Device.OnPlatform(7, 7, 9)); masterLayout.AddChildToLayout(addEmotionButtonLayout, Device.OnPlatform(80, 80, 83), Device.OnPlatform((100 - topYPos - 1) - 9, (100 - topYPos - 1) - 9, (100 - topYPos - 1) - 8)); } else { //Navigation.PushAsync(new AddEventsSituationsOrThoughts(pageTitle)); AddEventsSituationsOrThoughts addUtitlty = new AddEventsSituationsOrThoughts(pageTitle); /*addUtitlty.feelingsPage = FeelingsPage; addUtitlty.feelingSecondPage = feelingSecondPage;*/ Navigation.PushAsync( addUtitlty ); View pickView = pageContainedLayout.Children.FirstOrDefault(pick => pick.ClassId == "ePicker"); pageContainedLayout.Children.Remove(pickView); pickView = null; } } catch (Exception ex) { var test = ex.Message; } }