Merge branch 'master' of git.linphone.org:linphone-android
This commit is contained in:
commit
9986dded32
2 changed files with 50 additions and 25 deletions
|
@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
package org.linphone;
|
package org.linphone;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.linphone.component.ToggleImageButton;
|
import org.linphone.component.ToggleImageButton;
|
||||||
import org.linphone.component.ToggleImageButton.OnCheckedChangeListener;
|
import org.linphone.component.ToggleImageButton.OnCheckedChangeListener;
|
||||||
import org.linphone.core.AndroidCameraRecordManager;
|
import org.linphone.core.AndroidCameraRecordManager;
|
||||||
|
@ -37,6 +39,10 @@ import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
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.AudioManager;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.media.RingtoneManager;
|
import android.media.RingtoneManager;
|
||||||
|
@ -110,6 +116,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
||||||
MediaPlayer mRingerPlayer;
|
MediaPlayer mRingerPlayer;
|
||||||
LinphoneCall.State mCurrentCallState;
|
LinphoneCall.State mCurrentCallState;
|
||||||
Vibrator mVibrator;
|
Vibrator mVibrator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return null if not ready yet
|
* @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");
|
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK|PowerManager.ON_AFTER_RELEASE,"Linphone");
|
||||||
mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
@ -444,7 +452,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
||||||
if (mCurrentCallState == LinphoneCall.State.IncomingReceived) {
|
if (mCurrentCallState == LinphoneCall.State.IncomingReceived) {
|
||||||
//previous state was ringing, so stop ringing
|
//previous state was ringing, so stop ringing
|
||||||
stoptRinging();
|
stoptRinging();
|
||||||
routeAudioToReceiver();
|
//routeAudioToReceiver();
|
||||||
}
|
}
|
||||||
if (state == LinphoneCall.State.OutgoingInit) {
|
if (state == LinphoneCall.State.OutgoingInit) {
|
||||||
mWakeLock.acquire();
|
mWakeLock.acquire();
|
||||||
|
@ -506,6 +514,8 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
||||||
routeAudioToReceiver();
|
routeAudioToReceiver();
|
||||||
}
|
}
|
||||||
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
|
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
|
||||||
|
LinphoneActivity.instance().startProxymitySensor();
|
||||||
|
|
||||||
}
|
}
|
||||||
private void configureMuteAndSpeakerButtons() {
|
private void configureMuteAndSpeakerButtons() {
|
||||||
mMute.setChecked(LinphoneService.instance().getLinphoneCore().isMicMuted());
|
mMute.setChecked(LinphoneService.instance().getLinphoneCore().isMicMuted());
|
||||||
|
@ -540,6 +550,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
||||||
routeAudioToReceiver();
|
routeAudioToReceiver();
|
||||||
BandwidthManager.getInstance().setUserRestriction(false);
|
BandwidthManager.getInstance().setUserRestriction(false);
|
||||||
resetCameraFromPreferences();
|
resetCameraFromPreferences();
|
||||||
|
LinphoneActivity.instance().stopProxymitySensor();
|
||||||
}
|
}
|
||||||
private void routeAudioToSpeaker() {
|
private void routeAudioToSpeaker() {
|
||||||
if (Integer.parseInt(Build.VERSION.SDK) <= 4 /*<donut*/) {
|
if (Integer.parseInt(Build.VERSION.SDK) <= 4 /*<donut*/) {
|
||||||
|
@ -560,7 +571,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
||||||
}
|
}
|
||||||
private void callPending(LinphoneCall call) {
|
private void callPending(LinphoneCall call) {
|
||||||
mDecline.setEnabled(true);
|
mDecline.setEnabled(true);
|
||||||
routeAudioToSpeaker();
|
//routeAudioToSpeaker();
|
||||||
|
|
||||||
// Privacy setting to not share the user camera by default
|
// Privacy setting to not share the user camera by default
|
||||||
boolean prefVideoEnable = mPref.getBoolean(getString(R.string.pref_video_enable_key), false);
|
boolean prefVideoEnable = mPref.getBoolean(getString(R.string.pref_video_enable_key), false);
|
||||||
|
@ -713,4 +724,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
||||||
private AndroidCameraRecordManager getVideoManager() {
|
private AndroidCameraRecordManager getVideoManager() {
|
||||||
return AndroidCameraRecordManager.getInstance();
|
return AndroidCameraRecordManager.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,14 +42,17 @@ import android.view.WindowManager;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.TabHost;
|
import android.widget.TabHost;
|
||||||
|
|
||||||
public class LinphoneActivity extends TabActivity implements SensorEventListener {
|
public class LinphoneActivity extends TabActivity {
|
||||||
public static String DIALER_TAB = "dialer";
|
public static String DIALER_TAB = "dialer";
|
||||||
private AudioManager mAudioManager;
|
private AudioManager mAudioManager;
|
||||||
private static LinphoneActivity theLinphoneActivity;
|
private static LinphoneActivity theLinphoneActivity;
|
||||||
private SensorManager mSensorManager;
|
|
||||||
private FrameLayout mMainFrame;
|
private FrameLayout mMainFrame;
|
||||||
|
private SensorManager mSensorManager;
|
||||||
|
private SensorEventListener mSensorEventListener;
|
||||||
|
|
||||||
private static String SCREEN_IS_HIDDEN ="screen_is_hidden";
|
private static String SCREEN_IS_HIDDEN ="screen_is_hidden";
|
||||||
|
|
||||||
protected static LinphoneActivity instance()
|
protected static LinphoneActivity instance()
|
||||||
{
|
{
|
||||||
if (theLinphoneActivity == null) {
|
if (theLinphoneActivity == null) {
|
||||||
|
@ -70,6 +73,7 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
|
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
||||||
|
|
||||||
theLinphoneActivity = this;
|
theLinphoneActivity = this;
|
||||||
// start linphone as background
|
// start linphone as background
|
||||||
|
@ -79,12 +83,6 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
|
||||||
|
|
||||||
mMainFrame = (FrameLayout) findViewById(R.id.main_frame);
|
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));
|
mAudioManager = ((AudioManager)getSystemService(Context.AUDIO_SERVICE));
|
||||||
|
|
||||||
TabHost lTabHost = getTabHost(); // The activity TabHost
|
TabHost lTabHost = getTabHost(); // The activity TabHost
|
||||||
|
@ -162,9 +160,7 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
if (isFinishing()) {
|
|
||||||
if (mSensorManager!=null) mSensorManager.unregisterListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -233,18 +229,8 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
|
||||||
//nop
|
//nop
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSensorChanged(SensorEvent event) {
|
|
||||||
//Log.d(LinphoneService.TAG, "Proximity sensor report ["+event.values[0]+"] , for max range ["+event.sensor.getMaximumRange()+"]");
|
protected void hideScreen(boolean isHidden) {
|
||||||
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) {
|
|
||||||
WindowManager.LayoutParams lAttrs =getWindow().getAttributes();
|
WindowManager.LayoutParams lAttrs =getWindow().getAttributes();
|
||||||
if (isHidden) {
|
if (isHidden) {
|
||||||
lAttrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
lAttrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
||||||
|
@ -255,5 +241,30 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
|
||||||
}
|
}
|
||||||
getWindow().setAttributes(lAttrs);
|
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