<commit_before>package net.kevxu.senselib;

import java.util.ArrayList;
import java.util.List;

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

/**
 * Class for providing orientation information. start() and stop() must be 
 * explicitly called to start and stop the internal thread.
 * 
 * @author <NAME>
 */
public class OrientationService extends SensorService implements SensorEventListener {

	private static final String TAG = "SensorService";

	private Context mContext;
	private SensorManager mSensorManager;
	private List<OrientationServiceListener> mOrientationServiceListeners;

	private Sensor mGravitySensor;
	private Sensor mMagneticFieldSensor;

	private OrientationSensorThread mOrientationSensorThread;

	public interface OrientationServiceListener {
		
		/**
		 * Called when rotation changes.
		 * <p>
		 * Values are defined as following:<br>
		 * values[0]: azimuth, rotation around the Z axis.<br>
		 * values[1]: pitch, rotation around the X axis.<br>
		 * values[2]: roll, rotation around the Y axis.
		 * <p>
		 * The reference coordinate system is defined as following:<br>
		 * X is defined as the vector product Y·Z.<br>
		 * Y is tangential to the ground at the device's current location and 
		 * points towards the magnetic North Pole.<br>
		 * Z points towards the center of the Earth and is perpendicular to the 
		 * ground.
		 * <p>
		 * All three angles above are in radians and positive in the 
		 * counter-clockwise direction.
		 * <p>
		 * Notice that the reference coordinate system is different from the one
		 * used in 
		 * {@link OrientationServiceListener#onRotationMatrixChanged(float[], float[])}.
		 * 
		 * @param values array of float with length 3.
		 */
		public void onOrientationChanged(float[] values);

		/**
		 * Called when rotation changes.
		 * <p>
		 * R is rotation matrix, I is inclination 
		 * matrix. Both matrices transform a vector into world coordinate 
		 * system which defined as following. X is defined as the vector product
		 * Y·Z, Y is tangential to the ground at the device's current location 
		 * and points towards the magnetic North Pole and Z points towards the 
		 * sky and is perpendicular to the ground.
		 * <p>
		 * By definition, <br>
		 * [0 0 g] = R * gravity (g = magnitude of gravity)<br>
		 * [0 m 0] = I * R * geomagnetic (m = magnitude of geomagnetic * field)
		 * <p>
		 * R is the identity matrix when the device is aligned with the world's 
		 * coordinate system, that is, when the device's X axis points toward 
		 * East, the Y axis points to the North Pole and the device is facing 
		 * the sky.
		 * <p>
		 * I is a rotation matrix transforming the geomagnetic vector into the 
		 * same coordinate space as gravity (the world's coordinate space). 
		 * I is a simple rotation around the X axis.
		 * <p>
		 * Notice that the world coordinate system is different from the one 
		 * used in {@link OrientationServiceListener#onOrientationChanged(float[])}.
		 * 
		 * @param R 3 × 3 rotation matrix.
		 * @param I 3 × 3 inclination matrix.
		 */
		public void onRotationMatrixChanged(float[] R, float[] I);

		public void onMagneticFieldChanged(float[] values);

	}

	protected OrientationService(Context context) throws SensorNotAvailableException {
		this(context, null);
	}

	protected OrientationService(Context context, OrientationServiceListener orientationServiceListener) throws SensorNotAvailableException {
		mContext = context;
		mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);

		List<Sensor> gravitySensors = mSensorManager.getSensorList(Sensor.TYPE_GRAVITY);
		List<Sensor> magneticFieldSensor = mSensorManager.getSensorList(Sensor.TYPE_MAGNETIC_FIELD);
		
		int notAvailabelSensors = 0;

		if (gravitySensors.size() == 0) {
			// Gravity sensor not available
			notAvailabelSensors = notAvailabelSensors | Sensor.TYPE_GRAVITY;
		} else {
			// Assume the first in the list is the default sensor
			// Assumption may not be true though
			mGravitySensor = gravitySensors.get(0);<commit_msg>Remove unicode character from OrientationService.<commit_after>package net.kevxu.senselib;

import java.util.ArrayList;
import java.util.List;

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

/**
 * Class for providing orientation information. start() and stop() must be 
 * explicitly called to start and stop the internal thread.
 * 
 * @author <NAME>
 */
public class OrientationService extends SensorService implements SensorEventListener {

	private static final String TAG = "SensorService";

	private Context mContext;
	private SensorManager mSensorManager;
	private List<OrientationServiceListener> mOrientationServiceListeners;

	private Sensor mGravitySensor;
	private Sensor mMagneticFieldSensor;

	private OrientationSensorThread mOrientationSensorThread;

	public interface OrientationServiceListener {
		
		/**
		 * Called when rotation changes.
		 * <p>
		 * Values are defined as following:<br>
		 * values[0]: azimuth, rotation around the Z axis.<br>
		 * values[1]: pitch, rotation around the X axis.<br>
		 * values[2]: roll, rotation around the Y axis.
		 * <p>
		 * The reference coordinate system is defined as following:<br>
		 * X is defined as the vector product Y·Z.<br>
		 * Y is tangential to the ground at the device's current location and 
		 * points towards the magnetic North Pole.<br>
		 * Z points towards the center of the Earth and is perpendicular to the 
		 * ground.
		 * <p>
		 * All three angles above are in radians and positive in the 
		 * counter-clockwise direction.
		 * <p>
		 * Notice that the reference coordinate system is different from the one
		 * used in 
		 * {@link OrientationServiceListener#onRotationMatrixChanged(float[], float[])}.
		 * 
		 * @param values array of float with length 3.
		 */
		public void onOrientationChanged(float[] values);

		/**
		 * Called when rotation changes.
		 * <p>
		 * R is rotation matrix, I is inclination 
		 * matrix. Both matrices transform a vector into world coordinate 
		 * system which defined as following. X is defined as the vector product
		 * Y·Z, Y is tangential to the ground at the device's current location 
		 * and points towards the magnetic North Pole and Z points towards the 
		 * sky and is perpendicular to the ground.
		 * <p>
		 * By definition, <br>
		 * [0 0 g] = R * gravity (g = magnitude of gravity)<br>
		 * [0 m 0] = I * R * geomagnetic (m = magnitude of geomagnetic * field)
		 * <p>
		 * R is the identity matrix when the device is aligned with the world's 
		 * coordinate system, that is, when the device's X axis points toward 
		 * East, the Y axis points to the North Pole and the device is facing 
		 * the sky.
		 * <p>
		 * I is a rotation matrix transforming the geomagnetic vector into the 
		 * same coordinate space as gravity (the world's coordinate space). 
		 * I is a simple rotation around the X axis.
		 * <p>
		 * Notice that the world coordinate system is different from the one 
		 * used in {@link OrientationServiceListener#onOrientationChanged(float[])}.
		 * 
		 * @param R 3 x 3 rotation matrix.
		 * @param I 3 x 3 inclination matrix.
		 */
		public void onRotationMatrixChanged(float[] R, float[] I);

		public void onMagneticFieldChanged(float[] values);

	}

	protected OrientationService(Context context) throws SensorNotAvailableException {
		this(context, null);
	}

	protected OrientationService(Context context, OrientationServiceListener orientationServiceListener) throws SensorNotAvailableException {
		mContext = context;
		mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);

		List<Sensor> gravitySensors = mSensorManager.getSensorList(Sensor.TYPE_GRAVITY);
		List<Sensor> magneticFieldSensor = mSensorManager.getSensorList(Sensor.TYPE_MAGNETIC_FIELD);
		
		int notAvailabelSensors = 0;

		if (gravitySensors.size() == 0) {
			// Gravity sensor not available
			notAvailabelSensors = notAvailabelSensors | Sensor.TYPE_GRAVITY;
		} else {
			// Assume the first in the list is the default sensor
			// Assumption may not be true though
			mGravitySensor = gravitySensors.get(0);
{'fraction_non_alphanumeric': 0.07769631031220435, 'fraction_numerical': 0.003547776726584674, 'mean_word_length': 3.9456140350877194, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, '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': '126211', 'n_tokens_mistral': 2591, 'n_tokens_neox': 2240, 'n_words': 907}