add support for mute/speaker

This commit is contained in:
Jehan Monnier 2010-03-15 18:04:58 +01:00
parent 0c1705227d
commit 8f94e5f38b
13 changed files with 157 additions and 71 deletions

BIN
res/drawable/mic_active.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
res/drawable/mic_muted.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 615 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 569 B

View file

@ -3,9 +3,9 @@
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:id="@+id/SipUri" android:layout_height="wrap_content"
android:hint="sip:" android:layout_width="fill_parent"
android:singleLine="true"></EditText>
<LinearLayout android:id="@+id/LinearLayout02" android:layout_height="wrap_content" android:layout_width="fill_parent"><EditText android:id="@+id/SipUri" android:layout_height="wrap_content" android:hint="sip:" android:layout_width="fill_parent" android:lines="1" android:layout_weight="0.8"></EditText>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Erase" android:text=" &lt;- "></Button>
</LinearLayout>
<TableLayout android:layout_width="fill_parent" android:id="@+id/Dialer"
android:layout_height="fill_parent">
@ -13,77 +13,81 @@
android:layout_weight="1" android:id="@+id/DialerRow01"
android:layout_width="fill_parent">
<Button android:id="@+id/Button01" android:text="1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="0.25"></Button>
android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.33"></Button>
<Button android:id="@+id/Button02" android:text="2"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="0.25"></Button>
android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.33"></Button>
<Button android:id="@+id/Button03" android:text="3"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="0.5"></Button>
android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.33"></Button>
</TableRow>
<TableRow android:layout_height="fill_parent"
android:layout_weight="1" android:id="@+id/DialerRow02"
android:layout_width="fill_parent">
<Button android:id="@+id/Button04" android:text="4"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="0.25"></Button>
android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.33"></Button>
<Button android:text="5" android:id="@+id/Button05"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="0.25"></Button>
android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.33"></Button>
<Button android:id="@+id/Button06" android:text="6"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="0.5"></Button>
android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.33"></Button>
</TableRow>
<TableRow android:layout_weight="1" android:layout_height="fill_parent"
android:id="@+id/DialerRow03" android:layout_width="fill_parent">
<Button android:text="7" android:id="@+id/Button07"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="0.25"></Button>
android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.33"></Button>
<Button android:id="@+id/Button08" android:text="8"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="0.25"></Button>
android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.33"></Button>
<Button android:text="9" android:id="@+id/Button09"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="0.5"></Button>
android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.33"></Button>
</TableRow>
<TableRow android:layout_weight="1" android:layout_height="fill_parent"
android:id="@+id/DialerRow04" android:layout_width="fill_parent">
<Button android:layout_width="fill_parent"
android:layout_height="fill_parent" android:text="*"
android:layout_weight="0.25" android:id="@+id/ButtonStar"></Button>
android:id="@+id/ButtonStar" android:layout_weight="0.33"></Button>
<Button android:layout_width="fill_parent"
android:layout_height="fill_parent" android:text="0+" android:id="@+id/Button00"
android:layout_weight="0.25"></Button>
android:layout_height="fill_parent" android:text="0+" android:id="@+id/Button00" android:layout_weight="0.33"></Button>
<Button android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/ButtonHash"
android:text="#" android:layout_weight="0.5"></Button>
android:text="#" android:layout_weight="0.33"></Button>
</TableRow>
<TableRow android:layout_height="fill_parent"
android:layout_width="fill_parent" android:layout_weight="1"
android:id="@+id/DialerRow05">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout android:layout_height="fill_parent"
android:layout_width="fill_parent" android:id="@+id/IncallControlRow">
<ToggleButton android:id="@+id/mic_mute_button"
android:textOn="" android:textOff=""
android:layout_weight="0.25" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:drawableTop="@drawable/mic_active" android:checked="true"></ToggleButton>
<ImageButton android:src="@drawable/red"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_weight="0.25" android:id="@+id/HangUp"></ImageButton>
<ToggleButton android:id="@+id/speaker_button"
android:textOn="" android:textOff=""
android:layout_weight="0.25" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:drawableTop="@drawable/speaker_32_on"></ToggleButton>
</LinearLayout>
<LinearLayout android:layout_height="fill_parent"
android:layout_width="fill_parent" android:id="@+id/CallControlRow">
<ImageButton android:id="@+id/Call"
android:layout_height="fill_parent" android:src="@drawable/green"
android:layout_width="fill_parent" android:layout_weight="0.25">
</ImageButton>
<ImageButton android:id="@+id/HangUp" android:src="@drawable/red"
<ImageButton android:src="@drawable/red"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_weight="0.25"></ImageButton>
</TableRow>
<EditText android:layout_width="fill_parent" android:id="@+id/status_label"
android:clickable="false" android:focusable="false"
android:cursorVisible="false" android:textSize="12sp" android:height="15sp"
android:layout_height="wrap_content"></EditText>
android:layout_weight="0.25" android:id="@+id/Decline"></ImageButton>
</LinearLayout>
</LinearLayout>
<EditText android:layout_width="fill_parent" android:id="@+id/status_label"
android:clickable="false" android:focusable="false"
android:cursorVisible="false" android:textSize="12sp" android:height="15sp"
android:layout_height="wrap_content" android:background="@android:color/transparent"
android:textColor="@android:color/white"></EditText>
</TableLayout>
</LinearLayout>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="pref_audio">Audio</string>
<string name="menu_exit">Exit</string>
<string name="pref_prefix">Prefix</string>
<string name="pref_advanced">Advanced</string>

View file

@ -1,11 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/pref_sipaccount"><EditTextPreference android:title="@string/pref_username" android:key="@string/pref_username_key"></EditTextPreference>
<EditTextPreference android:title="@string/pref_passwd" android:key="@string/pref_passwd_key"></EditTextPreference>
<EditTextPreference android:title="@string/pref_domain" android:key="@string/pref_domain_key"></EditTextPreference>
<EditTextPreference android:title="@string/pref_proxy" android:key="@string/pref_proxy_key"></EditTextPreference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_advanced"><EditTextPreference android:title="@string/pref_prefix" android:key="@string/pref_prefix_key"></EditTextPreference>
</PreferenceCategory>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/pref_sipaccount">
<EditTextPreference android:title="@string/pref_username"
android:key="@string/pref_username_key"></EditTextPreference>
<EditTextPreference android:title="@string/pref_passwd"
android:key="@string/pref_passwd_key"></EditTextPreference>
<EditTextPreference android:title="@string/pref_domain"
android:key="@string/pref_domain_key"></EditTextPreference>
<EditTextPreference android:title="@string/pref_proxy"
android:key="@string/pref_proxy_key"></EditTextPreference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_advanced">
<EditTextPreference android:title="@string/pref_prefix"
android:key="@string/pref_prefix_key"></EditTextPreference>
</PreferenceCategory>
</PreferenceScreen>

View file

@ -36,6 +36,8 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
@ -44,6 +46,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
private TextView mAddress;
private TextView mStatus;
private ImageButton mCall;
private ImageButton mDecline;
private ImageButton mHangup;
private Button mZero;
private Button mOne;
@ -57,6 +60,10 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
private Button mNine;
private Button mStar;
private Button mHash;
private LinearLayout mCallControlRow;
private LinearLayout mInCallControlRow;
private static DialerActivity theDialer;
private String mDisplayName;
@ -120,16 +127,19 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
}
});
mDecline= (ImageButton) findViewById(R.id.Decline);
mHangup = (ImageButton) findViewById(R.id.HangUp);
mHangup.setEnabled(false);
mHangup.setOnClickListener(new OnClickListener() {
OnClickListener lHangupListener = new OnClickListener() {
public void onClick(View v) {
LinphoneCore lLinphoneCore = LinphoneService.instance().getLinphoneCore();
lLinphoneCore.terminateCall();
}
});
};
mHangup.setOnClickListener(lHangupListener);
mDecline.setOnClickListener(lHangupListener);
class DialKeyListener implements OnClickListener {
final String mKeyCode;
@ -143,7 +153,18 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
}
};
mCallControlRow = (LinearLayout) findViewById(R.id.CallControlRow);
mInCallControlRow = (LinearLayout) findViewById(R.id.IncallControlRow);
mInCallControlRow.setVisibility(View.GONE);
if (LinphoneService.isready()) {
if (LinphoneService.instance().getLinphoneCore().isIncall()) {
mCall.setEnabled(false);
mHangup.setEnabled(!mCall.isEnabled());
mCallControlRow.setVisibility(View.GONE);
mInCallControlRow.setVisibility(View.VISIBLE);
}
}
mZero = (Button) findViewById(R.id.Button00) ;
if (mZero != null) {
@ -172,6 +193,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
mHash = (Button) findViewById(R.id.ButtonHash);
mHash.setOnClickListener(new DialKeyListener(mAddress,'#'));
}
mStatus = (TextView) findViewById(R.id.status_label);
theDialer = this;
@ -180,6 +202,11 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
}
}
@Override
protected void onResume() {
super.onResume();
}
public void authInfoRequested(LinphoneCore lc, String realm, String username) {
// TODO Auto-generated method stub
@ -202,12 +229,18 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
public void generalState(LinphoneCore lc, GeneralState state) {
switch(state) {
case GSTATE_POWER_ON:
mCall.setEnabled(!LinphoneService.instance().getLinphoneCore().isIncall());
mHangup.setEnabled(!mCall.isEnabled());
break;
case GSTATE_REG_OK: {
break;
}
case GSTATE_CALL_OUT_INVITE: {
//de-activate green button
mCall.setEnabled(false);
mCallControlRow.setVisibility(View.GONE);
mInCallControlRow.setVisibility(View.VISIBLE);
}
case GSTATE_CALL_IN_INVITE: {
// activate red button
@ -256,6 +289,8 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
}
private void exitCallMode() {
mCallControlRow.setVisibility(View.VISIBLE);
mInCallControlRow.setVisibility(View.GONE);
mCall.setEnabled(true);
mHangup.setEnabled(false);
setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);

View file

@ -97,7 +97,7 @@ public class HistoryActivity extends ListActivity {
lView = mInflater.inflate(R.layout.history_cell, parent,false);
}
LinphoneCallLog lLog = mLogs.get(mLogs.size()-position-1);
LinphoneCallLog lLog = mLogs.get(position);
LinphoneAddress lAddress;
TextView lFirstLineView = (TextView) lView.findViewById(R.id.history_cell_first_line);
TextView lSecondLineView = (TextView) lView.findViewById(R.id.history_cell_second_line);

View file

@ -61,6 +61,11 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
theLinphoneActivity = this;
// start linphone as background
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(this, LinphoneService.class);
startService(intent);
mMainFrame = (FrameLayout) findViewById(R.id.main_frame);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
@ -70,7 +75,7 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
}
mAudioManager = ((AudioManager)getSystemService(Context.AUDIO_SERVICE));
TabHost lTabHost = getTabHost(); // The activity TabHost
TabHost lTabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
@ -100,17 +105,16 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
lTabHost.addTab(spec);
lTabHost.setCurrentTabByTag("dialer");
// start linphone as background
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(this, LinphoneService.class);
startService(intent);
}
@Override
protected void onDestroy() {
super.onDestroy();
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
if (isFinishing()) {
//restaure audio settings
//restaure audio settings
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) {
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setRouting(AudioManager.MODE_NORMAL,
@ -121,8 +125,21 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(this, LinphoneService.class);
stopService(intent);
theLinphoneActivity = null;
}
theLinphoneActivity = null;
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@ -182,15 +199,15 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
}
public void onAccuracyChanged(Sensor sensor, int accuracy) {
//nop
//nop
}
public void onSensorChanged(SensorEvent event) {
WindowManager.LayoutParams lAttrs =getWindow().getAttributes();
if (event.values[0] == 0) {
if (LinphoneService.instance().getLinphoneCore().isIncall() && event.values[0] == 0) {
lAttrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
mMainFrame.setVisibility(View.INVISIBLE);
} else if (event.values[0] == 1) {
} else if (mMainFrame.getVisibility() != View.VISIBLE && event.values[0] == 1) {
lAttrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
mMainFrame.setVisibility(View.VISIBLE);
}

View file

@ -60,7 +60,9 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
Timer mTimer = new Timer("Linphone scheduler");
private Handler mHandler = new Handler() ;
static boolean isready() {
return (theLinphone!=null);
}
static LinphoneService instance() {
if (theLinphone == null) {
throw new RuntimeException("LinphoneActivity not instanciated yet");
@ -83,6 +85,7 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
, new File(LINPHONE_FACTORY_RC)
, null);
mLinphoneCore.setSoftPlayLevel(3);
initFromConf();
TimerTask lTask = new TimerTask() {

View file

@ -136,5 +136,15 @@ public interface LinphoneCore {
* destroy linphone core and free all underlying resources
*/
public void destroy();
/**
* Allow to control play level before entering sound card:
* @param level in db
*/
public void setSoftPlayLevel(float gain);
/**
* get play level before entering sound card:
* @return level in db
*/
public float getSoftPlayLevel();
}

View file

@ -51,7 +51,9 @@ class LinphoneCoreImpl implements LinphoneCore {
private native long getCallLog(long nativePtr,int position);
private native int getNumberOfCallLogs(long nativePtr);
private native void delete(long nativePtr);
private native void setNetworkStateReachable(long nativePtr,boolean isReachable);
private native void setNetworkStateReachable(long nativePtr,boolean isReachable);
private native void setSoftPlayLevel(long nativeptr, float gain);
private native float getSoftPlayLevel(long nativeptr);
LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object userdata) throws IOException {
@ -159,4 +161,11 @@ class LinphoneCoreImpl implements LinphoneCore {
public void setNetworkStateReachable(boolean isReachable) {
setNetworkStateReachable(nativePtr,isReachable);
}
public void setSoftPlayLevel(float gain) {
setSoftPlayLevel(nativePtr,gain);
}
public float getSoftPlayLevel() {
return getSoftPlayLevel(nativePtr);
}
}