Example #1
0
        void LastRefreshFailed_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (ViewModel.LastRefreshFailed.Value && Visible)
            {
                InvokeOnMainThread(() =>
                {
                    FeedbackGenerator = new UINotificationFeedbackGenerator();
                    FeedbackGenerator.NotificationOccurred(UINotificationFeedbackType.Error);

                    View.LayoutIfNeeded();
                    StatusViewHiddenConstraint.Active = false;
                    UIView.Animate(0.3, 0, UIViewAnimationOptions.CurveEaseOut, () => View.LayoutIfNeeded(), null);
                });

                HideOverlayCancellationToken?.Cancel();
                HideOverlayCancellationToken = new CancellationTokenSource();
                Task.Delay(3000, HideOverlayCancellationToken.Token).ContinueWith(t2 =>
                {
                    if (t2.IsCanceled)
                    {
                        return;
                    }
                    InvokeOnMainThread(() =>
                    {
                        View.LayoutIfNeeded();
                        StatusViewHiddenConstraint.Active = true;
                        UIView.Animate(0.3, 0, UIViewAnimationOptions.CurveEaseIn, () => View.LayoutIfNeeded(), null);
                        FeedbackGenerator = null;
                    });
                });
            }
        }
Example #2
0
        private async void PuckUpBarButtonItem_Clicked(object sender, EventArgs e)
        {
            var haptic = new UINotificationFeedbackGenerator();

            haptic.Prepare();

            var pickedUp = await Delivery.MarkAsPickedUp(Delivery, UserId);

            UIAlertController alert = null;

            if (pickedUp)
            {
                haptic.NotificationOccurred(UINotificationFeedbackType.Success);
                alert = UIAlertController.Create("Success", "Delivery set as picked up", UIAlertControllerStyle.Alert);
            }
            else
            {
                haptic.NotificationOccurred(UINotificationFeedbackType.Error);
                alert = UIAlertController.Create("Failure", "Please try agail", UIAlertControllerStyle.Alert);
            }

            alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));

            PresentViewController(alert, true, null);
        }
Example #3
0
        public void HapticFeedbackGenErrorAsync()
        {
            var feedback = new UINotificationFeedbackGenerator();

            feedback.Prepare();
            switch ((UIDevice.CurrentDevice.ValueForKey(new Foundation.NSString("_feedbackSupportLevel")) as Foundation.NSNumber).Int16Value)
            {
            case 1:
                using (var feedbackLow = new UISelectionFeedbackGenerator())
                {
                    feedbackLow.SelectionChanged();
                }
                break;

            case 2:
            {
                feedback.NotificationOccurred(UINotificationFeedbackType.Error);
            }
            break;

            default:
                Vibration.Vibrate(40);
                Task.Delay(20);
                Vibration.Vibrate(40);
                break;
            }
        }
Example #4
0
 public void Before(Session contextEntity)
 {
     if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
     {
         _feedback = new UINotificationFeedbackGenerator();
         _feedback.Prepare();
     }
 }
 public HapticFeedback()
 {
     if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
     {
         // The UINotificationFeedbackGenerator will use the Taptic Engine in newer iPhones
         _feedback = new UINotificationFeedbackGenerator();
         _feedback.Prepare();
     }
 }
Example #6
0
        partial void NotificationAction(Foundation.NSObject sender)
        {
            // Initialize feedback
            var notification = new UINotificationFeedbackGenerator();

            notification.Prepare();

            // Trigger feedback
            notification.NotificationOccurred(UINotificationFeedbackType.Error);
        }
Example #7
0
        private async void BtnBarItemDelever_Clicked(object sender, EventArgs e)
        {
            var haptic = new UINotificationFeedbackGenerator();

            haptic.Prepare();
            bool status = await Delivery.DeliveredPackage(delivery);

            UIAlertController alert = null;

            if (status)
            {
                haptic.NotificationOccurred(UINotificationFeedbackType.Success);
                alert = UIAlertController.Create("Sucess", "Your package is Delivered. Enjoy!", UIAlertControllerStyle.Alert);
            }
            else
            {
                haptic.NotificationOccurred(UINotificationFeedbackType.Error);
                alert = UIAlertController.Create("failed", "Try Again!", UIAlertControllerStyle.Alert);
            }
            alert.AddAction(UIAlertAction.Create("ok", UIAlertActionStyle.Default, null));
            PresentViewController(alert, true, null);
        }
        private async void DeliverBarButtonItem_Clicked(object sender, EventArgs e)
        {
            var haptic = new UINotificationFeedbackGenerator();

            haptic.Prepare();

            bool result = await Delivery.MarkAsDelivered(delivery);

            UIAlertController alert = null;

            if (result)
            {
                haptic.NotificationOccurred(UINotificationFeedbackType.Success);
                alert = UIAlertController.Create("Success", "Delivery has been delivered", UIAlertControllerStyle.Alert);
            }
            else
            {
                haptic.NotificationOccurred(UINotificationFeedbackType.Error);
                alert = UIAlertController.Create("Failure", "Please try again", UIAlertControllerStyle.Alert);
            }

            alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
            PresentViewController(alert, true, null);
        }
Example #9
0
        public void Feedback(HapticEffect effect, EffectMode mode = EffectMode.Default)
        {
            if (mode == EffectMode.Off ||
                effect == HapticEffect.None ||
                !UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
            {
                return;
            }
            if (mode == EffectMode.Default && Forms9Patch.Settings.HapticEffectMode == EffectMode.Off)
            {
                return;
            }
            switch (effect)
            {
            case HapticEffect.Selection:
            {
                using (var selection = new UISelectionFeedbackGenerator())
                {
                    selection.Prepare();
                    selection.SelectionChanged();
                }
            }
            break;

            case HapticEffect.LightImpact:
            {
                using (var impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Light))
                {
                    impact.Prepare();
                    impact.ImpactOccurred();
                }
            }
            break;

            case HapticEffect.MediumImpact:
            {
                using (var impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Medium))
                {
                    impact.Prepare();
                    impact.ImpactOccurred();
                }
            }
            break;

            case HapticEffect.HeavyImpact:
            {
                using (var impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Heavy))
                {
                    impact.Prepare();
                    impact.ImpactOccurred();
                }
            }
            break;

            case HapticEffect.ErrorNotification:
            {
                // Initialize feedback
                using (var notification = new UINotificationFeedbackGenerator())
                {
                    notification.Prepare();
                    notification.NotificationOccurred(UINotificationFeedbackType.Error);
                }
            }
            break;

            case HapticEffect.WarningNotification:
            {
                // Initialize feedback
                using (var notification = new UINotificationFeedbackGenerator())
                {
                    notification.Prepare();
                    notification.NotificationOccurred(UINotificationFeedbackType.Warning);
                }
            }
            break;

            case HapticEffect.SuccessNotification:
            {
                // Initialize feedback
                using (var notification = new UINotificationFeedbackGenerator())
                {
                    notification.Prepare();
                    notification.NotificationOccurred(UINotificationFeedbackType.Success);
                }
            }
            break;
            }
        }
Example #10
0
        private async void DoCamera()
        {
            if (CrossMedia.Current == null)
            {
                await CrossMedia.Current.Initialize();
            }

            if (!CrossMedia.Current.IsCameraAvailable ||
                !CrossMedia.Current.IsTakePhotoSupported || !CrossMedia.Current.IsPickPhotoSupported)
            {
                UserDialogs.Instance.Alert("No camera found.", null, "OK");
                return;
            }

            var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
            {
            });

            if (file == null)
            {
                UserDialogs.Instance.Alert("You didn't take a photo.", null, "OK");
                return;
            }

            Stream s = file.GetStream();

            byte[] result = null;
            var    buffer = new byte[16 * 1024];

            using (MemoryStream ms = new MemoryStream())
            {
                int read;
                while ((read = s.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                result = ms.ToArray();
            }

            //show and tell shit, then Run ML
            SEEFOOD.Hidden             = true;
            stat.Hidden                = false;
            selectCamRollButton.Hidden = true;
            takePhotoButton.Hidden     = true;
            image.Hidden               = false;
            spinnyboy.Hidden           = false;
            this.hotdogLbl.Hidden      = true;
            this.ramenLbl.Hidden       = true;
            this.ramenOrHotdog.Hidden  = true;
            spinnyboy.StartAnimating();
            returnToMenu.Hidden  = false;
            this.stat.Text       = "Analyzing...";
            this.stat.TextColor  = UIKit.UIColor.Black;
            showDebugInfo.Hidden = false;
            var data = NSData.FromArray(result);

            image.Image = UIImage.LoadFromData(data);
            await Task.Delay(1000);

            //ML

            Console.WriteLine("Selected: " + ViewController.Type.ToString());

            //First we check what type of thing we have here
            if (ViewController.Type.Equals("Hotdog"))
            {
                var     assetPath             = NSBundle.MainBundle.GetUrlForResource("model", "mlmodel");
                var     transform             = MLModel.CompileModel(assetPath, out NSError compErr);
                MLModel model                 = MLModel.Create(transform, out NSError fucl);
                var     vnModel               = VNCoreMLModel.FromMLModel(model, out NSError rror);
                var     ciImage               = new CIImage(image.Image);
                var     classificationRequest = new VNCoreMLRequest(vnModel);

                //just do it
                var handler = new VNImageRequestHandler(ciImage, ImageIO.CGImagePropertyOrientation.Up, new VNImageOptions());
                handler.Perform(new[] { classificationRequest }, out NSError perfError);
                var results = classificationRequest.GetResults <VNClassificationObservation>();
                var thing   = results[0];
                Console.WriteLine("Hotdog OUT " + thing.Identifier);
                switch (thing.Identifier)
                {
                case "hotdog":
                    if (thing.Confidence > 0.85f)
                    {
                        this.stat.Text          = "✅ Hotdog";
                        this.stat.TextColor     = UIKit.UIColor.Green;
                        this.stat.TextAlignment = UITextAlignment.Center;
                        spinnyboy.Hidden        = true;
                        spinnyboy.StopAnimating();
                    }
                    else
                    {
                        this.stat.Text          = "❌ Not Hotdog";
                        this.stat.TextColor     = UIKit.UIColor.Red;
                        this.stat.TextAlignment = UITextAlignment.Center;
                        spinnyboy.Hidden        = true;
                        spinnyboy.StopAnimating();
                    }

                    break;

                case "nothotdog":
                    this.stat.Text          = "❌ Not Hotdog";
                    this.stat.TextColor     = UIKit.UIColor.Red;
                    this.stat.TextAlignment = UITextAlignment.Center;
                    spinnyboy.Hidden        = true;
                    spinnyboy.StopAnimating();
                    break;
                }
                this.confidence = thing.Confidence;
                // cache the instance
                var haptic = new UINotificationFeedbackGenerator();

                // Do this in advance so it is ready to be called on-demand without delay...
                haptic.Prepare();

                // produce the feedback as many times as needed
                haptic.NotificationOccurred(UINotificationFeedbackType.Success);

                // when done all done, clean up
                haptic.Dispose();
            }
            else
            {
                NSUrl modelPath = NSBundle.MainBundle.GetUrlForResource("Ramen", "mlmodel");
                if (modelPath == null)
                {
                    Console.WriteLine("peeepee");
                }
                var     transform             = MLModel.CompileModel(modelPath, out NSError compErr);
                MLModel model                 = MLModel.Create(transform, out NSError fucl);
                var     vnModel               = VNCoreMLModel.FromMLModel(model, out NSError rror);
                var     ciImage               = new CIImage(image.Image);
                var     classificationRequest = new VNCoreMLRequest(vnModel);

                //just do it
                var handler = new VNImageRequestHandler(ciImage, ImageIO.CGImagePropertyOrientation.Up, new VNImageOptions());
                handler.Perform(new[] { classificationRequest }, out NSError perfError);
                var results = classificationRequest.GetResults <VNClassificationObservation>();
                var thing   = results[0];
                Console.WriteLine("Ramen OUT " + thing.Identifier);
                switch (thing.Identifier)
                {
                case "ramen":
                    if (thing.Confidence > 0.85f)
                    {
                        this.stat.Text          = "✅ Ramen";
                        this.stat.TextColor     = UIKit.UIColor.Green;
                        this.stat.TextAlignment = UITextAlignment.Center;
                        spinnyboy.Hidden        = true;
                        spinnyboy.StopAnimating();
                    }
                    else
                    {
                        this.stat.Text          = "❌ Not Ramen";
                        this.stat.TextColor     = UIKit.UIColor.Red;
                        this.stat.TextAlignment = UITextAlignment.Center;
                        spinnyboy.Hidden        = true;
                        spinnyboy.StopAnimating();
                    }

                    break;

                case "notramen":
                    this.stat.Text          = "❌ Not Ramen";
                    this.stat.TextColor     = UIKit.UIColor.Red;
                    this.stat.TextAlignment = UITextAlignment.Center;
                    spinnyboy.Hidden        = true;
                    spinnyboy.StopAnimating();
                    break;
                }
                this.confidence = thing.Confidence;
                var haptic = new UINotificationFeedbackGenerator();

                // Do this in advance so it is ready to be called on-demand without delay...
                haptic.Prepare();

                // produce the feedback as many times as needed
                haptic.NotificationOccurred(UINotificationFeedbackType.Success);

                // when done all done, clean up
                haptic.Dispose();
            }
        }