public FeelingsSecondPage() { progressBar = DependencyService.Get<IProgressBar>(); NavigationPage.SetHasNavigationBar(this, false); masterLayout = new CustomLayout(); masterLayout.BackgroundColor = Color.FromRgb(244, 244, 244); //deviceSpec = DependencyService.Get<IDeviceSpec>(); AddEventsSituationsOrThoughts.feelingSecondPage = this; this.Appearing += FeelingsSecondPage_Appearing; actionPreviewListSource = new ObservableCollection<PreviewItem>(); mainTitleBar = new PurposeColorTitleBar(Color.FromRgb(8, 135, 224), "Purpose Color", Color.Black, "back", true); mainTitleBar.imageAreaTapGestureRecognizer.Tapped += imageAreaTapGestureRecognizer_Tapped; subTitleBar = new PurposeColorSubTitleBar(Constants.SUB_TITLE_BG_COLOR, "Emotional Awareness"); subTitleBar.BackButtonTapRecognizer.Tapped += OnBackButtonTapRecognizerTapped; subTitleBar.NextButtonTapRecognizer.Tapped += NextButtonTapRecognizer_Tapped; screenHeight = App.screenHeight; screenWidth = App.screenWidth; aePicker = null; actionlist = null; Label firstLine = new Label(); firstLine.Text = "Does being"; firstLine.FontFamily = Constants.HELVERTICA_NEUE_LT_STD; firstLine.TextColor = Color.FromRgb(40, 47, 50); firstLine.HeightRequest = screenHeight * 15 / 100; firstLine.HorizontalOptions = LayoutOptions.Center; firstLine.WidthRequest = screenWidth; firstLine.XAlign = TextAlignment.Center; Label secondLine = new Label(); secondLine.Text = App.SelectedEmotion; secondLine.FontFamily = Constants.HELVERTICA_NEUE_LT_STD; secondLine.FontAttributes = FontAttributes.Italic; secondLine.TextColor = Constants.BLUE_BG_COLOR;//Color.FromRgb(40, 47, 50); secondLine.HeightRequest = screenHeight * 15 / 100; secondLine.HorizontalOptions = LayoutOptions.Center; secondLine.WidthRequest = screenWidth; secondLine.XAlign = TextAlignment.Center; Label thirdLine = new Label(); thirdLine.Text = "support your goals and dreams?"; thirdLine.FontFamily = Constants.HELVERTICA_NEUE_LT_STD; thirdLine.TextColor = Color.FromRgb(40, 50, 50); thirdLine.HeightRequest = screenHeight * 11 / 100; thirdLine.HorizontalOptions = LayoutOptions.Center; thirdLine.WidthRequest = screenWidth; thirdLine.XAlign = TextAlignment.Center; goalsAndDreamsPickerButton = new PurposeColor.interfaces.CustomImageButton(); goalsAndDreamsPickerButton.ImageName = Device.OnPlatform("select_box_whitebg.png", "select_box_whitebg.png", @"/Assets/select_box_whitebg.png"); goalsAndDreamsPickerButton.Text = "Goals & Dreams"; goalsAndDreamsPickerButton.FontFamily = Constants.HELVERTICA_NEUE_LT_STD; goalsAndDreamsPickerButton.TextOrientation = interfaces.TextOrientation.Left; goalsAndDreamsPickerButton.FontSize = 17; goalsAndDreamsPickerButton.TextColor = Color.Gray; goalsAndDreamsPickerButton.WidthRequest = screenWidth * 90 / 100; goalsAndDreamsPickerButton.Clicked += OnGoalsPickerButtonClicked; actionPickerButton = new CustomImageButton(); actionPickerButton.IsVisible = false; actionPickerButton.BackgroundColor = Color.FromRgb(30, 126, 210); actionPickerButton.Text = "Add Supporting Actions"; actionPickerButton.TextColor = Color.White; actionPickerButton.TextOrientation = TextOrientation.Middle; actionPickerButton.FontFamily = Constants.HELVERTICA_NEUE_LT_STD; // actionPickerButton.TextOrientation = interfaces.TextOrientation.Left; actionPickerButton.WidthRequest = screenWidth * 90 / 100; actionPickerButton.Clicked += OnActionPickerButtonClicked; if (App.screenDensity > 1.5) { firstLine.FontSize = Device.OnPlatform(20, 20, 30); secondLine.FontSize = Device.OnPlatform(20, 22, 30); thirdLine.FontSize = Device.OnPlatform(20, 20, 30); actionPickerButton.FontSize = 17; actionPickerButton.HeightRequest = screenHeight * 6 / 100; goalsAndDreamsPickerButton.HeightRequest = screenHeight * 6 / 100; } else { firstLine.FontSize = Device.OnPlatform(16, 18, 26); secondLine.FontSize = Device.OnPlatform(16, 20, 26); thirdLine.FontSize = Device.OnPlatform(16, 18, 26); actionPickerButton.FontSize = 15; actionPickerButton.HeightRequest = screenHeight * 9 / 100; goalsAndDreamsPickerButton.HeightRequest = screenHeight * 9 / 100; } slider = new CustomSlider { Minimum = -2, Maximum = 2, WidthRequest = screenWidth * 90 / 100 }; slider.StopGesture = GetstopGetsture; //Image sliderDivider1 = new Image(); //sliderDivider1.Source = "drag_sepeate.png"; //Image sliderDivider2 = new Image(); //sliderDivider2.Source = "drag_sepeate.png"; //Image sliderDivider3 = new Image(); //sliderDivider3.Source = "drag_sepeate.png"; //Image sliderBG = new Image(); //sliderBG.Source = "drag_bg.png"; this.Appearing += FeelingNowPage_Appearing; masterLayout.AddChildToLayout(mainTitleBar, 0, 0); masterLayout.AddChildToLayout(subTitleBar, 0, Device.OnPlatform(9, 10, 9)); masterLayout.AddChildToLayout(firstLine, 0, 20); masterLayout.AddChildToLayout(secondLine, 0, 25); masterLayout.AddChildToLayout(thirdLine, 0, 30); //masterLayout.AddChildToLayout(sliderBG, 7, 45); masterLayout.AddChildToLayout(slider, 5, Device.OnPlatform(37, 35, 34)); /* masterLayout.AddChildToLayout(sliderDivider1, 30, 45.5f); masterLayout.AddChildToLayout(sliderDivider2, 50, 45.5f); masterLayout.AddChildToLayout(sliderDivider3, 70, 45.5f);*/ masterLayout.AddChildToLayout(goalsAndDreamsPickerButton, 5, Device.OnPlatform(50, 50, 45)); masterLayout.AddChildToLayout(actionPickerButton, 5, Device.OnPlatform(65, 65, 55)); listContainer = new StackLayout(); listContainer.BackgroundColor = Constants.PAGE_BG_COLOR_LIGHT_GRAY; listContainer.WidthRequest = screenWidth * 90 / 100; listContainer.HeightRequest = screenHeight * 20 / 100; listContainer.ClassId = "preview"; actionPreviewListView = new ListView(); actionPreviewListView.BackgroundColor = Constants.PAGE_BG_COLOR_LIGHT_GRAY; actionPreviewListView.ItemTemplate = new DataTemplate(typeof(ActionPreviewCellItem)); ActionPreviewCellItem.mainPage = this; actionPreviewListView.SeparatorVisibility = SeparatorVisibility.None; actionPreviewListView.Opacity = 1; actionPreviewListView.ItemsSource = actionPreviewListSource; listContainer.Children.Add(actionPreviewListView); masterLayout.AddChildToLayout(listContainer, 5, Device.OnPlatform(73, 73, 64)); Content = masterLayout; }
public async void OnGoalsPickerButtonClicked(object sender, System.EventArgs e) { try { await goalsAndDreamsPickerButton.ScaleTo(1.5, 100, Easing.Linear); await goalsAndDreamsPickerButton.ScaleTo(1, 100, Easing.Linear); CustomPicker ePicker = new CustomPicker(masterLayout, App.GetGoalsList(), 35, Constants.ADD_GOALS, true, true); ePicker.WidthRequest = screenWidth; ePicker.HeightRequest = screenHeight; ePicker.ClassId = "ePicker"; ePicker.feelingSecondPage = this; ePicker.listView.ItemSelected += OnGoalsPickerItemSelected; masterLayout.AddLayout(ePicker, 0, 0); //double yPos = 60 * screenHeight / 100; //ePicker.TranslateTo(0, yPos, 250, Easing.BounceIn); // ePicker.FadeTo(1, 750, Easing.Linear); } catch (System.Exception ex) { var test = ex.Message; } }
async void OnActionPickerButtonClicked(object sender, System.EventArgs e) { try { await actionPickerButton.ScaleTo(1.5, 100, Easing.Linear); await actionPickerButton.ScaleTo(1, 100, Easing.Linear); if(aePicker == null) { aePicker = new CustomPicker(masterLayout, actionlist, 35, Constants.ADD_ACTIONS, true, true, true); aePicker.WidthRequest = screenWidth; aePicker.HeightRequest = screenHeight; aePicker.ClassId = "ePicker"; aePicker.listView.ItemSelected += OnActionPickerItemSelected; } masterLayout.AddLayout(aePicker, 0, 0); } catch (System.Exception ex) { var test = ex.Message; //DisplayAlert(Constants.ALERT_TITLE, "please try again", Constants.ALERT_OK); } }
async void OnVideoButtonClicked(object sender, EventArgs e) { try { IProgressBar progres = DependencyService.Get<IProgressBar>(); if (Device.OS != TargetPlatform.iOS) progres.ShowProgressbar("Preparing media.."); if ((sender as CustomImageButton).ClassId == "camera") { try { if (Device.OS == TargetPlatform.WinPhone) { PurposeColor.interfaces.ICameraCapture camera = DependencyService.Get<PurposeColor.interfaces.ICameraCapture>(); camera.RecodeVideo(); } else if (Media.Plugin.CrossMedia.Current.IsCameraAvailable) { if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakeVideoSupported) { progres.HideProgressbar(); return; } string fileName = string.Format("Video{0}.mp4", System.DateTime.Now.ToString("yyyyMMddHHmmss")); StoreVideoOptions videoOptions = new StoreVideoOptions(); videoOptions.Name = fileName; videoOptions.Directory = "DefaultVideos"; videoOptions.DesiredLength = TimeSpan.FromMinutes(5); videoOptions.Quality = VideoQuality.Low; if( Device.OS == TargetPlatform.Android ) { IVideoCompressor compress = DependencyService.Get<IVideoCompressor>(); Size camSize = compress.GetCameraSize(); if( camSize.Width > 5000 ) videoOptions.Quality = VideoQuality.Low; else videoOptions.Quality = VideoQuality.Medium; } var file = await CrossMedia.Current.TakeVideoAsync( videoOptions ); // MasterObject.ShowAlert( "test", null ); await Task.Delay( TimeSpan.FromSeconds( 2 ) ); //progres.ShowProgressbar( "video is compressing..." ); if (file == null) { progres.HideProgressbar(); return; } string videoFilename = Path.GetFileName( file.Path ); MemoryStream ms = new MemoryStream(); /*file.GetStream().CopyTo(ms);*/ if( Device.OS == TargetPlatform.Android ) { IVideoCompressor compressor = DependencyService.Get<IVideoCompressor>(); ms = compressor.CompressVideo( file.Path, App.DownloadsPath + videoFilename, false ); ms.Position = 0; } else if( Device.OS == TargetPlatform.iOS ) { file.GetStream().CopyTo(ms); } if( ms == null ) { MasterObject.DisplayAlert("Error in adding video."); return; } if (ms.Length > 15728640) { MasterObject.DisplayAlert("Can not add video, Maximum file size limied to 15 MB"); progres.HideProgressbar(); ms = null; file = null; GC.Collect(); return; } if( Device.OS == TargetPlatform.Android ) { MasterObject.AddFileToMediaArray(ms, App.DownloadsPath + videoFilename, PurposeColor.Constants.MediaType.Video); } else if( Device.OS == TargetPlatform.iOS ) { MasterObject.AddFileToMediaArray(ms, file.Path, PurposeColor.Constants.MediaType.Video); } } } catch (Exception ex) { var test = ex.Message; } progres.HideProgressbar(); } else if ((sender as CustomImageButton).ClassId == "gallery") { try { if (Device.OS == TargetPlatform.WinPhone) { //https://social.msdn.microsoft.com/Forums/windowsapps/en-US/7e4492dc-d8f3-4dc5-8055-625352aaa8b6/fileopenpicker-class-on-wp8 // We do not currently support choosing files other than photos or choosing files from other Store apps // list the video folder content in a list view. // http://www.c-sharpcorner.com/UploadFile/2b876a/how-to-use-folders-and-files-in-windows-phone-8/ PurposeColor.interfaces.IFileBrowser fileBrowser = DependencyService.Get<PurposeColor.interfaces.IFileBrowser>(); List<String> files = await fileBrowser.GetVideoFileList(); //fileBrowser = null; // so the the memory can be released. if (files == null || files.Count < 1) { //progres.HideProgressbar(); // should hide the DataTemplateSelector so don't return from here.' MasterObject.DisplayAlert("Video files not accessible"); } else { // display the file names in custom picker, and get the file once the user taps on any of the file name. View fileView = PageContainer.Children.FirstOrDefault(pick => pick.ClassId == "filePicker"); if (fileView != null) { PageContainer.Children.Remove(fileView); fileView = null; } List<CustomListViewItem> customList = new List<CustomListViewItem>(); foreach (var item in files) { customList.Add(new CustomListViewItem { Name = item }); } CustomPicker filePicker = new CustomPicker(PageContainer, customList, 65, "Select file", true, false); //customList = null; filePicker.WidthRequest = App.screenWidth; filePicker.HeightRequest = App.screenHeight; filePicker.ClassId = "filePicker"; PageContainer.AddChildToLayout(filePicker, 0, 0); filePicker.listView.ItemSelected += async (s, eve) => { CustomListViewItem item = eve.SelectedItem as CustomListViewItem; MemoryStream videoFileMS = await fileBrowser.GetVideostream(item.Name); if (videoFileMS != null) { MasterObject.AddFileToMediaArray(videoFileMS, item.Name, Constants.MediaType.Video); } else { MasterObject.DisplayAlert("File read error"); } View filepickView = PageContainer.Children.FirstOrDefault(pick => pick.ClassId == "filePicker"); if (filepickView != null) { PageContainer.Children.Remove(filepickView); fileView = null; } //videoFileMS = null; }; //fileBrowser = null; } } else if (CrossMedia.Current.IsPickVideoSupported) { var file = await CrossMedia.Current.PickVideoAsync(); if (file == null) { progres.HideProgressbar(); return; } MemoryStream ms = new MemoryStream(); /* file.GetStream().CopyTo(ms); ms.Position = 0;*/ if( Device.OS == TargetPlatform.Android ) { string videoFilename = Path.GetFileName( file.Path ); IVideoCompressor compressor = DependencyService.Get<IVideoCompressor>(); ms = compressor.CompressVideo( file.Path, App.DownloadsPath + videoFilename, false ); ms.Position = 0; } else if( Device.OS == TargetPlatform.iOS ) { string videoFilename = Path.GetFileName( file.Path ); IVideoCompressor compressor = DependencyService.Get<IVideoCompressor>(); ms = compressor.CompressVideo( file.Path, App.DownloadsPath + videoFilename, false ); } if (ms.Length > 15728640) { MasterObject.DisplayAlert("Can not add video, Maximum file size limied to 15 MB"); progres.HideProgressbar(); ms = null; file = null; GC.Collect(); return; } if( Device.OS == TargetPlatform.Android ) { MasterObject.AddFileToMediaArray(ms, file.Path, PurposeColor.Constants.MediaType.Video); } else if( Device.OS == TargetPlatform.iOS ) { string fileName = Path.GetFileNameWithoutExtension( file.Path ) + ".mp4"; string downloadFilePath = Path.Combine(App.DownloadsPath, fileName ); MasterObject.AddFileToMediaArray(ms, downloadFilePath, PurposeColor.Constants.MediaType.Video); } } else { progres.HideProgressbar(); MasterObject.DisplayAlert("Video library not available"); return; } } catch (Exception ex) { var test = ex.Message; } progres.HideProgressbar(); } View pickView = PageContainer.Children.FirstOrDefault(pick => pick.ClassId == "mediachooser"); PageContainer.Children.Remove(pickView); pickView = null; progres.HideProgressbar(); GC.Collect(); } catch (Exception ex) { var test = ex.Message; } }
async void LocationInputTapRecognizer_Tapped(object sender, EventArgs e) { await ApplyAnimation ( locationInputStack ); App.nearByLocationsSource.Clear(); IProgressBar progress = DependencyService.Get<IProgressBar>(); try { var locator = CrossGeolocator.Current; //locator.AllowsBackgroundUpdates = true; locator.DesiredAccuracy = 50; if (!locator.IsGeolocationEnabled) { DisplayAlert("Purpose Color", "Please turn ON location services", "Ok"); return; } progress.ShowProgressbar("Getting Location.."); locator.StartListening(1, 100); var position = await locator.GetPositionAsync(timeoutMilliseconds: 10000); if (position == null) { return; } App.Lattitude = position.Latitude; App.Longitude = position.Longitude; lattitude = position.Latitude.ToString() != null ? position.Latitude.ToString() : string.Empty; longitude = position.Longitude.ToString() != null ? position.Longitude.ToString() : string.Empty; locator.StopListening(); ILocation loc = DependencyService.Get<ILocation>(); try { await ServiceHelper.GetCurrentAddressToList(App.Lattitude, App.Longitude); await ServiceHelper.GetNearByLocations( App.Lattitude, App.Longitude ); progress.HideProgressbar(); List<CustomListViewItem> pickerSource = App.nearByLocationsSource; CustomPicker ePicker = new CustomPicker(masterLayout, pickerSource, Device.OnPlatform(65, 65, 55),"Nearby Places", true, false);// 65 ePicker.WidthRequest = screenWidth; ePicker.HeightRequest = screenHeight; ePicker.ClassId = "ePicker"; ePicker.listView.ItemSelected += OnLocationListViewItemSelected; masterLayout.AddChildToLayout(ePicker, 0, 0); } catch (Exception) { DisplayAlert("Location error", "Address could not be retrived", "OK"); } } catch (Exception ex) { DisplayAlert(Constants.ALERT_TITLE, "Location service failed.", Constants.ALERT_OK); progress.HideProgressbar(); } }
public async void OnEventPickerButtonClicked(object sender, System.EventArgs e) { try { eventsDisplaying = true; this.eventPickerButton.Clicked -= OnEventPickerButtonClicked; await eventPickerButton.ScaleTo(1.5, 100, Easing.Linear); await eventPickerButton.ScaleTo(1, 100, Easing.Linear); CustomPicker ePicker = new CustomPicker(masterLayout, App.GetEventsList(), 45, Constants.ADD_EVENTS, true, true); ePicker.FeelingsPage = this; ePicker.WidthRequest = screenWidth; ePicker.HeightRequest = screenHeight; ePicker.ClassId = "ePicker"; ePicker.listView.ItemSelected += OnEventPickerItemSelected; masterLayout.AddLayout(ePicker, 0, 0); } catch (System.Exception ex) { DisplayAlert(Constants.ALERT_TITLE, "Please try again", Constants.ALERT_OK); } this.eventPickerButton.Clicked += OnEventPickerButtonClicked; eventsDisplaying = false; }
public async void OnEmotionalPickerButtonClicked(object sender, System.EventArgs e) { if (slider.CurrentValue == 0) { progressBar.ShowToast("Slider is in neutral."); return; } try { this.emotionalPickerButton.Clicked -= OnEmotionalPickerButtonClicked; emotionsDisplaying = true; await emotionalPickerButton.ScaleTo(1.5, 100, Easing.Linear); await emotionalPickerButton.ScaleTo(1, 100, Easing.Linear); List<CustomListViewItem> pickerSource = App.emotionsListSource.Where(toAdd => toAdd.SliderValue == slider.CurrentValue).ToList(); CustomPicker ePicker = new CustomPicker(masterLayout, pickerSource, Device.OnPlatform(65, 65, 55), Constants.SELECT_EMOTIONS, true, true);// 65 ePicker.WidthRequest = screenWidth; ePicker.HeightRequest = screenHeight; ePicker.ClassId = "ePicker"; ePicker.FeelingsPage = this; ePicker.listView.ItemSelected += OnEmotionalPickerItemSelected; masterLayout.AddLayout(ePicker, 0, Device.OnPlatform(0, 0, 0)); } catch (System.Exception) { DisplayAlert(Constants.ALERT_TITLE, "Please try again", Constants.ALERT_OK); } this.emotionalPickerButton.Clicked += OnEmotionalPickerButtonClicked; emotionsDisplaying = false; }