import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.media.AudioManager;
public class InCallScreen extends Activity
{
private SensorManager manager = null;
private SensorEventListener listener = null;
private Sensor sensor = null;
private void initSensor() {
listener = new SensorEventListener() {
public void onAccuracyChanged(Sensor s, int accuracy) {
}
public void onSensorChanged(SensorEvent event) {
float x = event.values[SensorManager.DATA_X];
float y = event.values[SensorManager.DATA_Y];
float z = event.values[SensorManager.DATA_Z];
final boolean hasRingingCall = mCM.hasActiveRingingCall();
Phone.State state = mCM.getState();
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if(state == Phone.State.RINGING)
{
if (z < -10)
{
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
}
else
{
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
}
};
manager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE);
sensor = manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
}
@Override
protected void onCreate(Bundle icicle) {
Log.i(LOG_TAG, "onCreate()... this = " + this);
super.onCreate(icicle);
mCM = PhoneApp.getInstance().mCM;
initInCallScreen();
}
@Override
protected void onResume() {
if (DBG) log("onResume()...");
super.onResume();
manager.registerListener(listener, sensor, SensorManager.SENSOR_DELAY_GAME);
}
@Override
protected void onPause() {
if (DBG) log("onPause()...");
super.onPause();
manager.unregisterListener(listener);
}
}