// Path: src/org/oscim/app/App.java
// public class App extends Application {
// 
// 	public final static Logger log = LoggerFactory.getLogger(App.class);
// 
// 	public static Map map;
// 	public static MapView view;
// 	public static Resources res;
// 	public static TileMap activity;
// 
// 	public static POISearch poiSearch;
// 	public static RouteSearch routeSearch;
// 
// 	@Override
// 	public void onCreate() {
// 		super.onCreate();
// 		res = getResources();
// 	}
// 
// 	public static void lockOrientation(Activity activity) {
// 		Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
// 		int rotation = display.getRotation();
// 		int tempOrientation = activity.getResources().getConfiguration().orientation;
// 		int orientation = 0;
// 		switch (tempOrientation)
// 		{
// 			case Configuration.ORIENTATION_LANDSCAPE:
// 				if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90)
// 					orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
// 				else
// 					orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
// 				break;
// 			case Configuration.ORIENTATION_PORTRAIT:
// 				if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270)
// 					orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
// 				else
// 					orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
// 		}
// 		activity.setRequestedOrientation(orientation);
// 	}
// }


import android.widget.ImageView;
import org.oscim.app.App;
import org.oscim.app.R;
import org.oscim.core.MapPosition;
import org.oscim.event.Event;
import org.oscim.layers.Layer;
import org.oscim.map.Map;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
/*
 * Copyright 2013 Ahmad Saleem
 * Copyright 2013 Hannes Janetzek
 *
 * This program is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */

package org.oscim.app.location;



@SuppressWarnings("deprecation")
public class Compass extends Layer implements SensorEventListener,
        Map.UpdateListener {

	// final static Logger log = LoggerFactory.getLogger(Compass.class);

	public enum Mode {
		OFF, C2D, C3D,
	}

	private final SensorManager mSensorManager;
	private final ImageView mArrowView;

	// private final float[] mRotationM = new float[9];
	private final float[] mRotationV = new float[3];

	// private float[] mAccelV = new float[3];
	// private float[] mMagnetV = new float[3];
	// private boolean mLastAccelerometerSet;
	// private boolean mLastMagnetometerSet;

	private float mCurRotation;
	private float mCurTilt;

	private boolean mControlOrientation;

	private Mode mMode = Mode.OFF;
	private int mListeners;

	@Override
	public void onMapEvent(Event e, MapPosition mapPosition) {
		if (!mControlOrientation) {
			float rotation = -mapPosition.bearing;
			adjustArrow(rotation, rotation);
		}
	}

	public Compass(Context context, Map map) {
		super(map);

		mSensorManager = (SensorManager) context
		    .getSystemService(Context.SENSOR_SERVICE);

		// List<Sensor> s = mSensorManager.getSensorList(Sensor.TYPE_ALL);
		// for (Sensor sensor : s)
		// log.debug(sensor.toString());

// Path: src/org/oscim/app/App.java
// public class App extends Application {
// 
// 	public final static Logger log = LoggerFactory.getLogger(App.class);
// 
// 	public static Map map;
// 	public static MapView view;
// 	public static Resources res;
// 	public static TileMap activity;
// 
// 	public static POISearch poiSearch;
// 	public static RouteSearch routeSearch;
// 
// 	@Override
// 	public void onCreate() {
// 		super.onCreate();
// 		res = getResources();
// 	}
// 
// 	public static void lockOrientation(Activity activity) {
// 		Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
// 		int rotation = display.getRotation();
// 		int tempOrientation = activity.getResources().getConfiguration().orientation;
// 		int orientation = 0;
// 		switch (tempOrientation)
// 		{
// 			case Configuration.ORIENTATION_LANDSCAPE:
// 				if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90)
// 					orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
// 				else
// 					orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
// 				break;
// 			case Configuration.ORIENTATION_PORTRAIT:
// 				if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270)
// 					orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
// 				else
// 					orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
// 		}
// 		activity.setRequestedOrientation(orientation);
// 	}
// }


// Path: src/org/oscim/app/location/Compass.java
import android.widget.ImageView;
import org.oscim.app.App;
import org.oscim.app.R;
import org.oscim.core.MapPosition;
import org.oscim.event.Event;
import org.oscim.layers.Layer;
import org.oscim.map.Map;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;

/*
 * Copyright 2013 Ahmad Saleem
 * Copyright 2013 Hannes Janetzek
 *
 * This program is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */

package org.oscim.app.location;



@SuppressWarnings("deprecation")
public class Compass extends Layer implements SensorEventListener,
        Map.UpdateListener {

	// final static Logger log = LoggerFactory.getLogger(Compass.class);

	public enum Mode {
		OFF, C2D, C3D,
	}

	private final SensorManager mSensorManager;
	private final ImageView mArrowView;

	// private final float[] mRotationM = new float[9];
	private final float[] mRotationV = new float[3];

	// private float[] mAccelV = new float[3];
	// private float[] mMagnetV = new float[3];
	// private boolean mLastAccelerometerSet;
	// private boolean mLastMagnetometerSet;

	private float mCurRotation;
	private float mCurTilt;

	private boolean mControlOrientation;

	private Mode mMode = Mode.OFF;
	private int mListeners;

	@Override
	public void onMapEvent(Event e, MapPosition mapPosition) {
		if (!mControlOrientation) {
			float rotation = -mapPosition.bearing;
			adjustArrow(rotation, rotation);
		}
	}

	public Compass(Context context, Map map) {
		super(map);

		mSensorManager = (SensorManager) context
		    .getSystemService(Context.SENSOR_SERVICE);

		// List<Sensor> s = mSensorManager.getSensorList(Sensor.TYPE_ALL);
		// for (Sensor sensor : s)
		// log.debug(sensor.toString());

		mArrowView = (ImageView) App.activity.findViewById(R.id.compass);