Exemplo n.º 1
0
 public void OnGestureLearned(GestureRecognitionService source, string gestureName)
 {
     if (source == internalRecognitionService) {
         RunOnUiThread(() => vibrator.Vibrate(100));
     } else if (source == externalRecognitionService) {
         RunOnUiThread(() => Toast.MakeText(this, "Gesture " + gestureName + " learned", ToastLength.Short).Show());
     }
 }
Exemplo n.º 2
0
        // gesture recognition callbacks
        public void OnGestureRecognized(GestureRecognitionService source, Distribution distribution)
        {
            if (source == internalRecognitionService) {
                if (distribution.BestDistance > 8) return;
                RunOnUiThread(() => vibrator.Vibrate(100));
            } else if (source == externalRecognitionService) {
                if (distribution.BestDistance > 8) return;
                RunOnUiThread(() => Toast.MakeText(this, "Gesture " + distribution.BestMatch + " recognized", ToastLength.Short).Show());
            }

            if (distribution.BestMatch == "left") {
                PreviousSlide();
            } else if (distribution.BestMatch == "right") {
                NextSlide();
            } else if (distribution.BestMatch == "pause") {
                SwitchPause();
            }
        }
Exemplo n.º 3
0
        // entry point
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            clientId = GetClientId();

            // gesture recognition
            internalRecognitionService = new GestureRecognitionService(new PhoneSensorSource(this));
            externalRecognitionService = new GestureRecognitionService(new BluetoothSensorSource(this));

            // register callbacks
            internalRecognitionService.RegisterListener(this);
            externalRecognitionService.RegisterListener(this);

            // start detecting gestures
            internalRecognitionService.StartClassificationMode();
            externalRecognitionService.StartClassificationMode();

            // keep light on and screen unlocked
            Window.AddFlags(WindowManagerFlags.KeepScreenOn);

            // get a vibrator service for feedback
            vibrator = (Vibrator) GetSystemService(VibratorService);

            // init screen layout
            SetContentView(Resource.Layout.Main);

            // init server connection
            InitializePresItServiceClient();

            // register button click events
            var authenticateButton = FindViewById<Button>(Resource.Id.AuthenticateButton);
            authenticateButton.Click += async (sender, e) => {
                var scanner = new MobileBarcodeScanner(this);
                var result = await scanner.Scan();
                if (result != null) new Thread(() => service.AuthenticateId(clientId, result.Text)).Start();
            };

            var nextSlideButton = FindViewById<Button>(Resource.Id.NextSlideButton);
            nextSlideButton.Click += (sender, e) => NextSlide();

            var previousSlideButton = FindViewById<Button>(Resource.Id.PreviousSlideButton);
            previousSlideButton.Click += (sender, e) => PreviousSlide();

            var pauseButton = FindViewById<Button>(Resource.Id.PauseButton);
            pauseButton.Click += (sender, e) => SwitchPause();

            var trainingButton = FindViewById<Button>(Resource.Id.TrainingButton);
            trainingButton.Click += (sender, e) => {
                var text = trainingButton.Text;
                SetTraining(internalRecognitionService, ref text);
                trainingButton.Text = text;
            };

            var externalTrainingButton = FindViewById<Button>(Resource.Id.ExternalTrainingButton);
            externalTrainingButton.Click += (sender, e) => {
                var text = externalTrainingButton.Text;
                SetTraining(externalRecognitionService, ref text);
                externalTrainingButton.Text = text;
            };

            var trainingDataSaveButton = FindViewById<Button>(Resource.Id.TrainingDataSaveButton);
            trainingDataSaveButton.Click += (sender, e) => {
                var prefs = PreferenceManager.GetDefaultSharedPreferences(this);
                var editor = prefs.Edit();
                editor.PutString("internalRecognitionService", internalRecognitionService.SerializeTrainingSet());
                editor.PutString("externalRecognitionService", externalRecognitionService.SerializeTrainingSet());
                editor.Commit();
            };

            var trainingDataLoadButton = FindViewById<Button>(Resource.Id.TrainingDataLoadButton);
            trainingDataLoadButton.Click += (sender, e) => {
                var prefs = PreferenceManager.GetDefaultSharedPreferences(this);
                if (!prefs.Contains("internalRecognitionService") || !prefs.Contains("externalRecognitionService")) return;
                internalRecognitionService.DeserializeTrainingSet(prefs.GetString("internalRecognitionService", ""));
                externalRecognitionService.DeserializeTrainingSet(prefs.GetString("externalRecognitionService", ""));
            };
        }
Exemplo n.º 4
0
 public void OnTrainingSetDeleted(GestureRecognitionService source)
 {
 }
Exemplo n.º 5
0
 private void SetTraining(GestureRecognitionService s, ref string buttonText)
 {
     switch (buttonText) {
         case "Start Training Left":
             buttonText = "Start Training Right";
             s.StartLearnMode("left");
             break;
         case "Start Training Right":
             buttonText = "Start Training Pause";
             s.StopLearnMode();
             s.StartLearnMode("right");
             break;
         case "Start Training Pause":
             buttonText = "Stop Training";
             s.StopLearnMode();
             s.StartLearnMode("pause");
             break;
         default:
             buttonText = "Start Training Left";
             s.StopLearnMode();
             break;
     }
 }