using System;
using System.Collections.Generic;
using System.Text;
#if ANDROID
using Android.Hardware;
using Android.App;
#endif

namespace ShootingHero.Utilities
{
#if ANDROID
	public class Accelerometer : Java.Lang.Object, ISensorEventListener
	{
		Activity activity;
		float x, y, z;

		public float X { get { return x; } set { x = value; } }
		public float Y { get { return y; } set { y = value; } }
		public float Z { get { return z; } set { z = value; } }

		public Accelerometer ( Activity activity )
		{
			this.activity = activity;
			SensorManager sensorManager = activity.GetSystemService ( Activity.SensorService ) as SensorManager;
			sensorManager.RegisterListener ( this, sensorManager.GetDefaultSensor ( SensorType.Accelerometer ), SensorDelay.Game );
		}

		public new void Dispose ()
		{
			SensorManager sensorManager = activity.GetSystemService ( Activity.SensorService ) as SensorManager;
			sensorManager.UnregisterListener ( this );
			base.Dispose ();
		}

		public void OnAccuracyChanged ( Sensor sensor, SensorStatus accuracy )
		{

		}

		public void OnSensorChanged ( SensorEvent e )
		{
			x = e.Values [ 0 ];
			y = e.Values [ 1 ];
			z = e.Values [ 2 ];
		}
	}
#endif
}
