package fr.savoca.app.lambertbox;
import android.app.Activity;
import android.hardware.SensorManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.OrientationEventListener;
import android.widget.ImageView;
import android.widget.TextView;
public class LambertBox extends Activity {
TextView textviewOrientation;
MediaPlayer mp;
OrientationEventListener myOrientationEventListener;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView logo = (ImageView)findViewById(R.id.logo);
logo.setImageResource(R.drawable.logo);
mp = MediaPlayer.create(this, R.raw.cl_3);
myOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL){
@Override
public void onOrientationChanged(int arg0) {
boolean flip = false;
synchronized (this) {
if (arg0 > 50 && arg0 < 90) {
if (!mp.isPlaying() && flip == false) {
mp.start();
flip = true;
}
}
else if (arg0 < 50) {
if (!mp.isPlaying() && flip == true) {
mp.start();
flip = false;
}
}
}
}
};
if (myOrientationEventListener.canDetectOrientation()) {
myOrientationEventListener.enable();
}
else{
finish();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
myOrientationEventListener.disable();
}
@Override
protected void onPause() {
super.onDestroy();
myOrientationEventListener.disable();
}
@Override
protected void onStop() {
super.onDestroy();
myOrientationEventListener.disable();
}
}
|