Exemplo n.º 1
0
        public async void TakePhoto()
        {
            //Checking for camera permissions
            var cameraPermission = await PermissionHandler.CheckForCameraPermission();

            if (!cameraPermission)
            {
                await CrossPermissions.Current.RequestPermissionsAsync(Permission.Camera);
            }

            //Checking for storage permissions
            var storagePermission = await PermissionHandler.CheckForCameraPermission();

            if (!storagePermission)
            {
                await CrossPermissions.Current.RequestPermissionsAsync(Permission.Storage);
            }

            //Taking photo and storing it in MediaFile variable 'takenPhoto'
            try
            {
                takenPhoto = await TakingPhotoHandler.TakePhoto();
            }

            catch (ManagerException photoNotTakenException)
            {
                ToastUtil.ShowToast(photoNotTakenException.ErrorCode);
            }
        }
Exemplo n.º 2
0
        public async void NavigateToHistoryPage()
        {
            UserDialogs.Instance.ShowLoading("Loading", MaskType.Black);

            try
            {
                var historyList = await _restService.GetHistoryById(User.Id);

                var displayHistoryList = new List <DisplayHistoryModel>();

                foreach (var element in historyList)
                {
                    var target = await _restService.GetUserById(element.TargetId);

                    displayHistoryList.Add(new DisplayHistoryModel()
                    {
                        Status    = element.Status,
                        ImageUri  = target.ImageContentUri,
                        FirstName = target.PersonFirstName,
                    });
                }

                UserDialogs.Instance.HideLoading();

                await Application.Current.MainPage.Navigation.PushAsync(new HistoryPage(new HistoryPageViewModel(displayHistoryList)));
            }

            catch (ManagerException managerException) when(managerException.ErrorCode == Constants.HistoryElementNotFoundError)
            {
                ToastUtil.ShowToast(Constants.HistoryElementNotFoundError);
            }
        }
Exemplo n.º 3
0
        //CommandBar处理
        private async void AppBarClick(object sender, RoutedEventArgs e)
        {
            string id             = (DefaultViewModel["Item"] as SampleDataItem).UniqueId;
            var    resourceLoader = ResourceLoader.GetForCurrentView("Resources");

            switch ((sender as AppBarButton).Tag as string)
            {
            case "AddFav":
                ReadListUtil.AddFavId(id);
                //Lock Screen Badge
                Global.Current.Notifications.UpdateBadgeWithNumber(1);
                //Toast Notification
                ToastUtil.ShowToast(resourceLoader.GetString("HubTitleText"), resourceLoader.GetString("AddFavSuccessText"));
                this.AddFav.Visibility    = Visibility.Collapsed;
                this.RemoveFav.Visibility = Visibility.Visible;
                break;

            case "RemoveFav":
                ReadListUtil.RemoveFavId(id);
                //Lock Screen Badge
                Global.Current.Notifications.UpdateBadgeWithNumber(2);
                //Toast Notification
                ToastUtil.ShowToast(resourceLoader.GetString("HubTitleText"), resourceLoader.GetString("RemoveFavSuccessText"));
                this.AddFav.Visibility    = Visibility.Visible;
                this.RemoveFav.Visibility = Visibility.Collapsed;
                break;

            case "Share":
                (DefaultViewModel["Item"] as SampleDataItem).Title.RegisterForShare(resourceLoader.GetString("ShareTitle"), resourceLoader.GetString("ShareDesc"));
                break;

            case "Save":
            {
                //检测是否有sd卡,如果没有,就弹出toast提示
                if (!await FileEx.IsAvailableRemoveDevice("SD"))
                {
                    ToastUtil.ShowToast(resourceLoader.GetString("HubTitleText"), resourceLoader.GetString("NoSD"));
                    return;
                }
                //保存文件到sd卡
                string fileName = string.Empty;
                foreach (StorageTarget item in Enum.GetValues(typeof(StorageTarget)))
                {
                    if (item.ToString() == "SD")
                    {
                        await resourceLoader.GetString("HTMLContent").Save("NewsSample", "saved.html", item);

                        ToastUtil.ShowToast(resourceLoader.GetString("HubTitleText"), resourceLoader.GetString("SaveSDSuccessText"));
                    }
                }
            }

            break;

            default:
                break;
            }
        }
Exemplo n.º 4
0
        public async void SavePerson()
        {
            if (!FieldsAreFilled())
            {
                ToastUtil.ShowToast("All fields must be filled!");

                return;
            }

            PersonObject.ImageName = PersonObject.PersonFirstName + PersonObject.PersonLastName + ".jpg";
            PersonObject.Score     = 0;

            await CloudStorageService.SaveBlockBlob(takenPhoto, PersonObject.ImageName);

            PersonObject.ImageContentUri = CloudStorageService.GetImageUri(_personObject.ImageName);

            try
            {
                UserDialogs.Instance.ShowLoading("Loading", MaskType.Black);

                PersonObject = await _restService.CreateImageObject(PersonObject);
            }

            catch (ManagerException creationException)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast(creationException.ErrorCode);

                return;
            }

            try
            {
                var status = await _restService.InsertUserIntoRecognition(PersonObject);

                var features = await _restService.GetFaceFeatures(PersonObject);

                var insertedFeatures = await _restService.InsertFaceFeatures(features);
            }

            catch (ManagerException recognitionException)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast(recognitionException.ErrorCode);

                return;
            }

            SaveProperties();

            UserDialogs.Instance.HideLoading();

            NavigateToHomePage();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Shows photo of target as a hint only one time for one target
        /// </summary>
        public async void GetHint()
        {
            if (!IsHintAvailable)
            {
                ToastUtil.ShowToast("You already used your hint!");

                return;
            }

            var result = await UserDialogs.Instance.ConfirmAsync(new ConfirmConfig
            {
                Message    = "Do you want to use up your hint?",
                OkText     = "Yes please",
                CancelText = "Nah"
            });

            if (!result)
            {
                return;
            }

            var checkTargetStatus = await CheckForTarget();

            if (checkTargetStatus)
            {
                var fetchedTarget = await _restService.GetUserById(Target.PreyPersonId);

                TargetImageUri = fetchedTarget.ImageContentUri;
                OnPropertyChanged("TargetImageUri");

                await PopupNavigation.Instance.PushAsync(new HintPopUp(this));

                IsHintAvailable = false;

                await Task.Delay(7000);

                if (PopupNavigation.Instance.PopupStack.Any(p => p is HintPopUp))
                {
                    await PopupNavigation.Instance.PopAsync();
                }

                TargetImageUri = "";
                OnPropertyChanged("TargetImageUri");

                return;
            }

            ToastUtil.ShowToast("You don't have a target!");
        }
Exemplo n.º 6
0
        /// <summary>
        /// Assigns random target after checking if it is already assigned
        /// </summary>
        public async void GetTarget()
        {
            IsDescriptionAvailable = true;
            OnPropertyChanged("IsDescriptionAvailable");

            DisplayMessage = "";
            OnPropertyChanged("DisplayMessage");

            DisplayStatus = "";
            OnPropertyChanged("DisplayStatus");

            UserDialogs.Instance.ShowLoading("Loading", MaskType.Black);

            var checkTargetStatus = await CheckForTarget();

            if (checkTargetStatus)
            {
                var fetchedTarget = await _restService.GetUserById(Target.PreyPersonId);

                TargetDescriptionSentence = fetchedTarget.DescriptiveSentence;

                OnPropertyChanged("TargetDescriptionSentence");

                var fetchedFeatures = await _restService.GetFaceFeatures(fetchedTarget);

                DisplayAge    = "Age: " + fetchedFeatures.Age.ToString();
                DisplayGender = "Gender: " + fetchedFeatures.Gender;

                OnPropertyChanged("DisplayAge");
                OnPropertyChanged("DisplayGender");

                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast(Constants.TargetAlreadyAssignedError);

                return;
            }

            try
            {
                DisplayMessage = "";
                OnPropertyChanged("DisplayMessage");

                DisplayStatus = "";
                OnPropertyChanged("DisplayStatus");

                var targetId = await _restService.GetRandomTarget(User.Id);

                var fetchedTarget = await _restService.GetUserById(targetId);

                TargetDescriptionSentence = fetchedTarget.DescriptiveSentence;

                OnPropertyChanged("TargetDescriptionSentence");

                var result = _restService.InsertHistoryModel(new HistoryModel()
                {
                    UserId   = User.Id,
                    TargetId = targetId,
                    Status   = Constants.TargetNotHuntedHistory
                });

                var fetchedFeatures = await _restService.GetFaceFeatures(fetchedTarget);

                DisplayAge    = "Age: " + fetchedFeatures.Age.ToString();
                DisplayGender = "Gender: " + fetchedFeatures.Gender;

                OnPropertyChanged("DisplayAge");
                OnPropertyChanged("DisplayGender");

                IsHintAvailable = true;

                UserDialogs.Instance.HideLoading();

                //Initiate popup
                await PopupNavigation.Instance.PushAsync(new TargetPopUp(this));

                return;
            }

            catch (ManagerException getTargetException) when(getTargetException.ErrorCode == Constants.TargetAlreadyAssignedError)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast(getTargetException.ErrorCode);
            }

            catch (ManagerException noPlayersException) when(noPlayersException.ErrorCode == Constants.ThereAreNoPlayersError)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast(noPlayersException.ErrorCode);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Checks for permissions, takes photo and checks whether target was hit
        /// </summary>
        public async void TakePhoto()
        {
            var cameraPermission = await PermissionHandler.CheckForCameraPermission();

            if (!cameraPermission)
            {
                await CrossPermissions.Current.RequestPermissionsAsync(Permission.Camera);
            }

            var storagePermission = await PermissionHandler.CheckForCameraPermission();

            if (!storagePermission)
            {
                await CrossPermissions.Current.RequestPermissionsAsync(Permission.Storage);
            }
            try
            {
                var takenPhoto = await TakingPhotoHandler.TakePhoto();

                UserDialogs.Instance.ShowLoading("Loading", MaskType.Black);

                var saveImage = User.Id + ".jpg";
                await CloudStorageService.SaveBlockBlob(takenPhoto, saveImage);
            }

            catch (ManagerException photoNotTakenException)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast(photoNotTakenException.ErrorCode);

                return;
            }

            try
            {
                var imageName          = User.Id + ".jpg";
                var recognitionMessage = await _restService.Identify(imageName);

                var isTargetDead = await _restService.IsPreyHunted(User.Id, Convert.ToInt32(recognitionMessage));

                if (isTargetDead)
                {
                    DisplayMessage = "It's a direct hit!";
                    OnPropertyChanged("DisplayMessage");

                    var hitResult = await _restService.GetUserById(Convert.ToInt32(recognitionMessage));

                    var historyResult = await _restService.UpdateHistoryModel(User.Id, hitResult.Id);

                    UserDialogs.Instance.HideLoading();

                    //Initiate popup
                    await PopupNavigation.Instance.PushAsync(new ShootPopUp(this));

                    DisplayStatus = "Name: " + hitResult.PersonFirstName;
                    OnPropertyChanged("DisplayStatus");

                    User = await _restService.UpdateUserScore(User.Id);

                    Name = "Your score is: " + User.Score.ToString();
                    OnPropertyChanged("Name");
                }
            }

            catch (ManagerException noFacesFoundException) when(noFacesFoundException.ErrorCode == Constants.NoFacesIdentifiedError)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast(noFacesFoundException.ErrorCode);
            }

            catch (ManagerException noOneIdentifiedException) when(noOneIdentifiedException.ErrorCode == Constants.NoMatchFoundError)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast(noOneIdentifiedException.ErrorCode);
            }

            catch (ManagerException targetNotFoundException) when(targetNotFoundException.ErrorCode == Constants.TargetNotFoundError)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast(targetNotFoundException.ErrorCode);
            }

            catch (ManagerException userNotFoundException) when(userNotFoundException.ErrorCode == Constants.UserDoesNotExistError)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast("Something went wrong");
            }

            //This catch is just for testing purposes
            catch (ManagerException)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast("Something went wrong");
            }
        }