<commit_before>package com.gps.capstone.traceroute.sensors.listeners;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.util.Log;

import com.gps.capstone.traceroute.Utils.SensorUtil.EventType;
import com.gps.capstone.traceroute.sensors.events.NewDataEvent;

/**
 * Created by saryana on 5/3/15.
 */
public class DirectionTestClass extends MySensorListener implements SensorEventListener {

    private Sensor mMagnetic;
    private Sensor mGravity;
    private float[] mGravValues;
    private float[] mMagneticValues;
    private String mCurrentDir;

    /**
     * Dummy class for direction that will use the compass and put the restriction on users
     * to be holding their phone so we have the proper heading.
     */
    public DirectionTestClass(Context context) {
        super(context);
        mGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        mMagnetic = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
        mGravValues = null;
        mMagneticValues = null;
        mCurrentDir = "";
    }

    @Override
    public void register() {
        mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_NORMAL);
        mSensorManager.registerListener(this, mMagnetic, SensorManager.SENSOR_DELAY_GAME);
    }

    @Override
    public void unregister() {
        mSensorManager.unregisterListener(this);
    }

    @Override
    public void onSensorChanged(SensorEvent event) {
        if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
            mMagneticValues = event.values;
        } else {
            mGravValues = event.values;
            if (mMagneticValues != null) {
                float[] rotationMatrix = new float[9];
                float[] R = new float[9];
                SensorManager.getRotationMatrix(rotationMatrix, null, mGravValues, mMagneticValues);

                float[] orientation = new float[3];
                SensorManager.getOrientation(rotationMatrix, orientation);
                // Posting the radian value we are getting
                mBus.post(new NewDataEvent(new float[]{orientation[0]}, EventType.DIRECTION_CHANGE));

//                // TODO NOTE TO KEITH: It may not be an idea to sector it up since the data readings still
//                // jump around a bit we can have a pretty small sector size, but i'm not sure if that
//                // actually helps anything
//                mBus.post(new NewDataEvent(new float[]{heading}, EventType.DIRECTION_CHANGE));
            }
        }
    }

    private String headingToDir(float heading) {
        String dir;<commit_msg>confusion<commit_after>package com.gps.capstone.traceroute.sensors.listeners;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.util.Log;

import com.gps.capstone.traceroute.Utils.SensorUtil.EventType;
import com.gps.capstone.traceroute.sensors.events.NewDataEvent;

/**
 * Created by saryana on 5/3/15.
 */
public class DirectionTestClass extends MySensorListener implements SensorEventListener {

    private Sensor mMagnetic;
    private Sensor mGravity;
    private float[] mGravValues;
    private float[] mMagneticValues;
    private String mCurrentDir;

    /**
     * Dummy class for direction that will use the compass and put the restriction on users
     * to be holding their phone so we have the proper heading.
     */
    public DirectionTestClass(Context context) {
        super(context);
        mGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        mMagnetic = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
        mGravValues = null;
        mMagneticValues = null;
        mCurrentDir = "";
    }

    @Override
    public void register() {
        mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_NORMAL);
        mSensorManager.registerListener(this, mMagnetic, SensorManager.SENSOR_DELAY_GAME);
    }

    @Override
    public void unregister() {
        mSensorManager.unregisterListener(this);
    }

    @Override
    public void onSensorChanged(SensorEvent event) {
        if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
            mMagneticValues = event.values;
        } else {
            mGravValues = event.values;
            if (mMagneticValues != null) {
                float[] rotationMatrix = new float[9];
                SensorManager.getRotationMatrix(rotationMatrix, null, mGravValues, mMagneticValues);

                float[] orientation = new float[3];
                SensorManager.getOrientation(rotationMatrix, orientation);
                Log.d("DIRECTION", "" + orientation[2]);
                // Posting the radian value we are getting
                mBus.post(new NewDataEvent(new float[]{orientation[0], orientation[2]}, EventType.DIRECTION_CHANGE));

//                // TODO NOTE TO KEITH: It may not be an idea to sector it up since the data readings still
//                // jump around a bit we can have a pretty small sector size, but i'm not sure if that
//                // actually helps anything
//                mBus.post(new NewDataEvent(new float[]{heading}, EventType.DIRECTION_CHANGE));
            }
        }
    }

    private String headingToDir(float heading) {
        String dir;
{'fraction_non_alphanumeric': 0.08499550763701708, 'fraction_numerical': 0.003054806828391734, 'mean_word_length': 2.786394557823129, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1897046', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1515, 'n_words': 386}