private bool DisplayVoices(AccelerometerPosition accBefore, AccelerometerPosition accNow, MediaPlayer mp, AccelerometerReader accelerometerReader)
 {
     if (Math.Abs(accBefore.accX - accNow.accX) > 0.3 || Math.Abs(accBefore.accY - accNow.accY) > 0.3 || Math.Abs(accBefore.accZ - accNow.accZ) > 0.3)
     {
         MainThread.BeginInvokeOnMainThread(() =>
         {
             accelerometerReader.PlayInclinedSongs(shakeDetector);
         });
         return(true);
     }
     else if (cpt == 10 || cpt == 20)
     {
         MainThread.BeginInvokeOnMainThread(() =>
         {
             accelerometerReader.PlayStableSongs(shakeDetector);
         });
     }
     return(false);
 }
 private void SetAccPosition(AccelerometerPosition accPos, AccelerometerReader accelerometerReader)
 {
     accPos.accX = accelerometerReader.AccX;
     accPos.accY = accelerometerReader.AccY;
     accPos.accZ = accelerometerReader.AccZ;
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            Button buttonVoix1   = FindViewById <Button>(Resource.Id.buttonVoix1);
            Button buttonVoix2   = FindViewById <Button>(Resource.Id.buttonVoix2);
            Button buttonVoixOff = FindViewById <Button>(Resource.Id.buttonVoixoff);

            button1 = 1;
            button2 = 2;
            cpt     = 0;

            accelerometerReader = new AccelerometerReader();
            shakeDetector       = new ShakeDetector();
            accStart            = new AccelerometerPosition();
            accBefore           = new AccelerometerPosition();
            accNow = new AccelerometerPosition();

            buttonVoix1.Click += (sender, e) =>
            {
                Setvoices(button1);
                SetAccPosition(accStart, accelerometerReader);
                shakeDetector.ResetShakePlayer();
                accelerometerReader.ResetAccPlayer();
                cpt = 0;
                if (player2 != null)
                {
                    player2.Reset();
                }
                StartTimer(accelerometerReader, player1);
                if (!Accelerometer.IsMonitoring)
                {
                    Accelerometer.Start(SensorSpeed.Game);
                }
                player1.Start();
            };

            buttonVoix2.Click += (sender, e) =>
            {
                Setvoices(button2);
                SetAccPosition(accStart, accelerometerReader);
                shakeDetector.ResetShakePlayer();
                accelerometerReader.ResetAccPlayer();
                cpt = 0;
                if (player1 != null)
                {
                    player1.Reset();
                }
                StartTimer(accelerometerReader, player2);
                if (!Accelerometer.IsMonitoring)
                {
                    Accelerometer.Start(SensorSpeed.Game);
                }
                player2.Start();
            };

            buttonVoixOff.Click += (sender, e) =>
            {
                if (Accelerometer.IsMonitoring)
                {
                    Accelerometer.Stop();
                }
                accelerometerReader.Start = false;
                shakeDetector.Start       = false;
            };
        }