Files
vtm/vtm-android/src/org/oscim/android/Compass.java
Hannes Janetzek 67a3cbadf7 package/naming reorganization:
- RenderLayer -> LayerRenderer
  as this LayerRenderer just the rendering implementation of a Layer
  - not a 'layer' itself
- move renderer.sublayer.*Renderer into their respective *Layer classes
- move layers.labeling to layers.tile.vector.labeling
  (until there is a common labeling framework)
- remove layers.overlay
  - move Marker stuff to layers.marker
- merge TileRenderer into TileRenderLayer

- rename renderer.sublayers to renderer.elements
- move layers.tile.* to tiling package
- move tilesource.* to tiling.source

- rename oscim.view -> oscim.map
2013-11-23 21:09:30 +01:00

69 lines
1.9 KiB
Java

/*
* Copyright 2012 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.android;
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;
public class Compass {
private final SensorEventListener mListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
if (Math.abs(event.values[0] - mAngle) > 0.25) {
mAngle = event.values[0];
if (mMap != null) {
mMap.getViewport().setRotation(-mAngle);
mMap.updateMap(true);
}
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
/* package */float mAngle = 0;
/* package */Map mMap;
private final SensorManager mSensorManager;
private final Sensor mSensor;
public Compass(MapActivity mapActivity, Map map) {
mMap = map;
mSensorManager = (SensorManager) mapActivity
.getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
}
public void enable() {
mSensorManager.registerListener(mListener, mSensor,
SensorManager.SENSOR_DELAY_UI);
}
public void disable() {
mSensorManager.unregisterListener(mListener);
mMap.getViewport().setRotation(0);
}
}