package com.example.Maps013;


import android.app.Activity;
import android.content.Context;
import android.hardware.*;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

// Sensor.TYPE_STEP_COUNTER
// http://www.edumobile.org/android/stepcounter-app-with-android-kitkat-4-4/

// https://jayeshcp.wordpress.com/2013/05/01/how-to-use-accelerometer-sensor-in-android/

// https://github.com/bagilevi/android-pedometer/blob/master/src/name/bagi/levente/pedometer/StepService.java

// http://www.gadgetsaint.com/android/create-pedometer-step-counter-android/#.WRXeLdykJ7O

//https://github.com/itkovian/StepCounter/tree/master/src/be/ugent/csl/StepCounter

// https://examples.javacodegeeks.com/android/core/hardware/sensor/android-accelerometer-example/

//https://androidstream.wordpress.com/2013/01/16/android-collecting-and-plotting-accelerometer-data/

// http://stackoverflow.com/questions/26782028/step-detector-using-android-accelerometer

public class podometre01 extends Activity implements SensorEventListener 
{

	private SensorManager sensorManager;
	private TextView count;
	boolean activityRunning;

	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.podometre_layout);
		count = (TextView) findViewById(R.id.count);
	
		sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
	}

	@Override
	protected void onResume() 
	{
		super.onResume();
		activityRunning = true;
		
		Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
		
		if (countSensor != null) 
		{
			sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
		} 
		else 
		{
			Toast.makeText(this, "Count sensor not available!", Toast.LENGTH_LONG).show();
		}

	}

	@Override
	protected void onPause()
	{
		super.onPause();
		activityRunning = false;
		//if you unregister the last listener, the hardware will stop detecting step events
		//sensorManager.unregisterListener(this);
	}
	
	@Override
	public void onSensorChanged(SensorEvent event) 
	{
		if (activityRunning) 
		{
			count.setText(String.valueOf(event.values[0]));
		}
	
	}
	
	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy)
	{
	}
}