fix proximity sensor issue
This commit is contained in:
parent
6619599beb
commit
72107897cb
2 changed files with 50 additions and 24 deletions
|
@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
*/
|
||||
package org.linphone;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.linphone.component.ToggleImageButton;
|
||||
import org.linphone.component.ToggleImageButton.OnCheckedChangeListener;
|
||||
import org.linphone.core.AndroidCameraRecordManager;
|
||||
|
@ -37,6 +39,10 @@ import android.content.Context;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.RingtoneManager;
|
||||
|
@ -110,6 +116,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
|||
MediaPlayer mRingerPlayer;
|
||||
LinphoneCall.State mCurrentCallState;
|
||||
Vibrator mVibrator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return null if not ready yet
|
||||
|
@ -135,6 +142,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
|||
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK|PowerManager.ON_AFTER_RELEASE,"Linphone");
|
||||
mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
|
||||
|
||||
try {
|
||||
|
||||
|
||||
|
@ -444,6 +452,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
|||
if (mCurrentCallState == LinphoneCall.State.IncomingReceived) {
|
||||
//previous state was ringing, so stop ringing
|
||||
stoptRinging();
|
||||
//routeAudioToReceiver();
|
||||
}
|
||||
if (state == LinphoneCall.State.OutgoingInit) {
|
||||
mWakeLock.acquire();
|
||||
|
@ -505,6 +514,8 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
|||
routeAudioToReceiver();
|
||||
}
|
||||
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
|
||||
LinphoneActivity.instance().startProxymitySensor();
|
||||
|
||||
}
|
||||
private void configureMuteAndSpeakerButtons() {
|
||||
mMute.setChecked(LinphoneService.instance().getLinphoneCore().isMicMuted());
|
||||
|
@ -539,6 +550,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
|||
routeAudioToReceiver();
|
||||
BandwidthManager.getInstance().setUserRestriction(false);
|
||||
resetCameraFromPreferences();
|
||||
LinphoneActivity.instance().stopProxymitySensor();
|
||||
}
|
||||
private void routeAudioToSpeaker() {
|
||||
if (Integer.parseInt(Build.VERSION.SDK) <= 4 /*<donut*/) {
|
||||
|
@ -559,7 +571,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
|||
}
|
||||
private void callPending() {
|
||||
mDecline.setEnabled(true);
|
||||
routeAudioToSpeaker();
|
||||
//routeAudioToSpeaker();
|
||||
|
||||
// Privacy setting to not share the user camera by default
|
||||
boolean prefVideoEnable = mPref.getBoolean(getString(R.string.pref_video_enable_key), false);
|
||||
|
@ -711,5 +723,8 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
|||
private AndroidCameraRecordManager getVideoManager() {
|
||||
return AndroidCameraRecordManager.getInstance();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -42,14 +42,17 @@ import android.view.WindowManager;
|
|||
import android.widget.FrameLayout;
|
||||
import android.widget.TabHost;
|
||||
|
||||
public class LinphoneActivity extends TabActivity implements SensorEventListener {
|
||||
public class LinphoneActivity extends TabActivity {
|
||||
public static String DIALER_TAB = "dialer";
|
||||
private AudioManager mAudioManager;
|
||||
private static LinphoneActivity theLinphoneActivity;
|
||||
private SensorManager mSensorManager;
|
||||
|
||||
private FrameLayout mMainFrame;
|
||||
private SensorManager mSensorManager;
|
||||
private SensorEventListener mSensorEventListener;
|
||||
|
||||
private static String SCREEN_IS_HIDDEN ="screen_is_hidden";
|
||||
|
||||
protected static LinphoneActivity instance()
|
||||
{
|
||||
if (theLinphoneActivity == null) {
|
||||
|
@ -70,6 +73,7 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
||||
|
||||
theLinphoneActivity = this;
|
||||
// start linphone as background
|
||||
|
@ -79,12 +83,6 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
|
|||
|
||||
mMainFrame = (FrameLayout) findViewById(R.id.main_frame);
|
||||
|
||||
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
||||
List<Sensor> lSensorList = mSensorManager.getSensorList(Sensor.TYPE_PROXIMITY);
|
||||
if (lSensorList.size() >0) {
|
||||
mSensorManager.registerListener(this,lSensorList.get(0),SensorManager.SENSOR_DELAY_UI);
|
||||
Log.i(LinphoneService.TAG, "Proximity sensor detected, registering");
|
||||
}
|
||||
mAudioManager = ((AudioManager)getSystemService(Context.AUDIO_SERVICE));
|
||||
|
||||
TabHost lTabHost = getTabHost(); // The activity TabHost
|
||||
|
@ -162,9 +160,7 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
|
|||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (isFinishing()) {
|
||||
if (mSensorManager!=null) mSensorManager.unregisterListener(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@Override
|
||||
|
@ -233,18 +229,8 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
|
|||
//nop
|
||||
}
|
||||
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
//Log.d(LinphoneService.TAG, "Proximity sensor report ["+event.values[0]+"] , for max range ["+event.sensor.getMaximumRange()+"]");
|
||||
if (LinphoneService.isready() == false) return; //nop nothing to do
|
||||
|
||||
if (LinphoneService.instance().getLinphoneCore().isIncall()
|
||||
&& event.values[0] != event.sensor.getMaximumRange() ) {
|
||||
hideScreen(true);
|
||||
} else {
|
||||
hideScreen(false);
|
||||
}
|
||||
}
|
||||
private void hideScreen(boolean isHidden) {
|
||||
|
||||
protected void hideScreen(boolean isHidden) {
|
||||
WindowManager.LayoutParams lAttrs =getWindow().getAttributes();
|
||||
if (isHidden) {
|
||||
lAttrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
||||
|
@ -255,5 +241,30 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
|
|||
}
|
||||
getWindow().setAttributes(lAttrs);
|
||||
}
|
||||
protected void startProxymitySensor() {
|
||||
List<Sensor> lSensorList = mSensorManager.getSensorList(Sensor.TYPE_PROXIMITY);
|
||||
mSensorEventListener = new SensorEventListener() {
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
if (event.timestamp == 0) return; //just ignoring for nexus 1
|
||||
//Log.d(LinphoneService.TAG, "Proximity sensor report ["+event.values[0]+"] , for max range ["+event.sensor.getMaximumRange()+"]");
|
||||
|
||||
if (event.values[0] != event.sensor.getMaximumRange() ) {
|
||||
LinphoneActivity.instance().hideScreen(true);
|
||||
} else {
|
||||
LinphoneActivity.instance().hideScreen(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
||||
};
|
||||
if (lSensorList.size() >0) {
|
||||
mSensorManager.registerListener(mSensorEventListener,lSensorList.get(0),SensorManager.SENSOR_DELAY_UI);
|
||||
Log.i(LinphoneService.TAG, "Proximity sensor detected, registering");
|
||||
}
|
||||
}
|
||||
protected void stopProxymitySensor() {
|
||||
if (mSensorManager!=null) mSensorManager.unregisterListener(mSensorEventListener);
|
||||
hideScreen(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue