package pt.isep.mei.simov.droneappcontroller;

import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;

import org.jivesoftware.smack.packet.Message;

/**
 * Created by João on 30-12-2014.
 */
public class ExpertMode extends Activity implements SensorEventListener {


        private SensorManager sensorManager;

        TextView x_tilt;
        TextView y_tilt;



        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_expert_mode);

        x_tilt=(TextView)findViewById(R.id.x_tilt);
        y_tilt=(TextView)findViewById(R.id.y_tilt);

        sensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);

        // add listener. The listener will be HelloAndroid (this) class
        sensorManager.registerListener(this,
                sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                SensorManager.SENSOR_DELAY_GAME);
    }


        @Override
        public void onSensorChanged(SensorEvent event) {

        if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){

            // assign directions
            float x=event.values[0];
            float y=event.values[1];

            
            if(x > 1){
                x_tilt.setText("Trás");
            } else if(x < -1) {
                x_tilt.setText("Frente");
            }

            if(y > 1){
                y_tilt.setText("Direita");
            }else if(y < -1){
                y_tilt.setText("Esquerda");
            }



        }

    }
    public void senMessage(String message) {
        Message msg = new Message(to, Message.Type.chat);

        msg.setBody(message);
        if (connection != null) {
            connection.sendPacket(msg);
            messages.add(connection.getUser() + ":");
            messages.add(message);
        }
    }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {

    }
}
