You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
package org.r3pek.pharmacies.widgets;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import android.hardware.Sensor;
|
|
import android.hardware.SensorEvent;
|
|
import android.hardware.SensorEventListener;
|
|
import android.view.View;
|
|
|
|
public class ImageRotater implements SensorEventListener {
|
|
private LinkedList<ImageOrientationSensor> images = new LinkedList<ImageOrientationSensor>();
|
|
private float lastOrientation = 0;
|
|
|
|
public void addImage(ImageOrientationSensor image) {
|
|
synchronized (images) {
|
|
if (images.contains(image)) return;
|
|
images.add(image);
|
|
}
|
|
}
|
|
|
|
public void delImage(ImageOrientationSensor image) {
|
|
synchronized (images) {
|
|
images.remove(image);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
|
}
|
|
|
|
public float getLastOrientation() {
|
|
return lastOrientation;
|
|
}
|
|
|
|
@Override
|
|
public void onSensorChanged(SensorEvent event) {
|
|
if (event.sensor.getType() != Sensor.TYPE_ORIENTATION) return;
|
|
if (Math.abs(event.values[0] - lastOrientation) < 5) return;
|
|
|
|
lastOrientation = event.values[0];
|
|
synchronized (images) {
|
|
for (ImageOrientationSensor a : images) {
|
|
if (((View)a).isShown())
|
|
a.setOrientation(lastOrientation);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|