fix sip uri presentation in History

fix landscape mode
This commit is contained in:
Jehan Monnier 2010-03-16 12:37:05 +01:00
parent 8f94e5f38b
commit b983a3a071
9 changed files with 197 additions and 59 deletions

View file

@ -3,34 +3,66 @@
android:orientation="vertical" android:layout_width="fill_parent" android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<LinearLayout android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/Addresslayout">
<EditText android:id="@+id/SipUri" android:layout_height="wrap_content" <EditText android:id="@+id/SipUri" android:layout_height="wrap_content"
android:hint="sip:" android:layout_width="fill_parent" android:hint="sip:" android:layout_width="fill_parent"
android:singleLine="true"></EditText> android:lines="1" android:layout_weight="0.2"></EditText>
<Button android:layout_height="wrap_content" android:id="@+id/Erase"
<TableLayout android:layout_width="fill_parent" android:id="@+id/Dialer" android:layout_height="fill_parent"> android:layout_width="fill_parent" android:text="&lt;-"
android:layout_weight="0.8"></Button>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/IncallAddressLayout">
<EditText android:text="@+id/EditText01"
android:layout_height="wrap_content" android:lines="1"
android:id="@+id/DisplayNameView" android:clickable="false"
android:cursorVisible="false" android:gravity="center"
android:layout_width="fill_parent"></EditText>
</LinearLayout>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout01"
<TableRow android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1" android:id="@+id/DialerRow05"> android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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" <ImageButton android:id="@+id/Call"
android:layout_height="fill_parent" android:src="@drawable/green" android:layout_height="fill_parent" android:src="@drawable/green"
android:layout_width="fill_parent" android:layout_weight="0.25"> android:layout_width="fill_parent" android:layout_weight="0.25">
</ImageButton> </ImageButton>
<ImageButton android:src="@drawable/red"
<ImageButton android:id="@+id/HangUp" android:src="@drawable/red"
android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_weight="0.25"></ImageButton> android:layout_weight="0.25" android:id="@+id/Decline"></ImageButton>
</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:background="@android:color/transparent" android:textColor="@android:color/white"
android:lines="1" android:layout_height="wrap_content"></EditText>
</LinearLayout>
</TableRow><TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/DialerRow06"></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></TableLayout>
</LinearLayout> </LinearLayout>

View file

@ -3,8 +3,20 @@
android:orientation="vertical" android:layout_width="fill_parent" android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
<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> <LinearLayout android:id="@+id/LinearLayout02"
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Erase" android:text=" &lt;- "></Button> android:layout_height="wrap_content" android:layout_width="fill_parent">
<LinearLayout android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/Addresslayout">
<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.2"></EditText>
<Button android:layout_height="wrap_content" android:id="@+id/Erase"
android:layout_width="fill_parent" android:text="&lt;-" android:layout_weight="0.8"></Button>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/IncallAddressLayout"><EditText android:text="@+id/EditText01" android:layout_height="wrap_content" android:lines="1" android:id="@+id/DisplayNameView" android:clickable="false" android:cursorVisible="false" android:gravity="center" android:layout_width="fill_parent"></EditText>
</LinearLayout>
</LinearLayout> </LinearLayout>
<TableLayout android:layout_width="fill_parent" android:id="@+id/Dialer" <TableLayout android:layout_width="fill_parent" android:id="@+id/Dialer"

View file

@ -4,4 +4,5 @@
<item android:title="@string/menu_settings" android:id="@+id/menu_settings"> <item android:title="@string/menu_settings" android:id="@+id/menu_settings">
</item> </item>
<item android:title="@string/menu_exit" android:id="@+id/menu_exit"></item> <item android:title="@string/menu_exit" android:id="@+id/menu_exit"></item>
<item android:id="@+id/menu_about" android:title="@string/menu_about"></item>
</menu> </menu>

View file

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

View file

@ -27,7 +27,6 @@ import org.linphone.core.LinphoneCore.GeneralState;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration;
import android.media.AudioManager; import android.media.AudioManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -35,19 +34,25 @@ import android.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TableRow;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class DialerActivity extends Activity implements LinphoneCoreListener { public class DialerActivity extends Activity implements LinphoneCoreListener {
private TextView mAddress; private TextView mAddress;
private TextView mDisplayNameView;
private TextView mStatus; private TextView mStatus;
private ImageButton mCall; private ImageButton mCall;
private ImageButton mDecline; private ImageButton mDecline;
private ImageButton mHangup; private ImageButton mHangup;
private Button mErase;
private Button mZero; private Button mZero;
private Button mOne; private Button mOne;
private Button mTwo; private Button mTwo;
@ -61,8 +66,13 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
private Button mStar; private Button mStar;
private Button mHash; private Button mHash;
private ToggleButton mMute;
private ToggleButton mSpeaker;
private LinearLayout mCallControlRow; private LinearLayout mCallControlRow;
private LinearLayout mInCallControlRow; private LinearLayout mInCallControlRow;
private LinearLayout mAddressLayout;
private LinearLayout mInCallAddressLayout;
private static DialerActivity theDialer; private static DialerActivity theDialer;
@ -92,6 +102,14 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
mAddress = (TextView) findViewById(R.id.SipUri); mAddress = (TextView) findViewById(R.id.SipUri);
mDisplayNameView = (TextView) findViewById(R.id.DisplayNameView);
mErase = (Button)findViewById(R.id.Erase);
mErase.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mAddress.getEditableText().delete(mAddress.getEditableText().length()-1, mAddress.getEditableText().length());
}
});
mCall = (ImageButton) findViewById(R.id.Call); mCall = (ImageButton) findViewById(R.id.Call);
mCall.setOnClickListener(new OnClickListener() { mCall.setOnClickListener(new OnClickListener() {
@ -150,12 +168,17 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
} }
public void onClick(View v) { public void onClick(View v) {
mAddressView.append(mKeyCode); mAddressView.append(mKeyCode);
mDisplayName="";
} }
}; };
mCallControlRow = (LinearLayout) findViewById(R.id.CallControlRow); mCallControlRow = (LinearLayout) findViewById(R.id.CallControlRow);
mInCallControlRow = (LinearLayout) findViewById(R.id.IncallControlRow); mInCallControlRow = (LinearLayout) findViewById(R.id.IncallControlRow);
mAddressLayout = (LinearLayout) findViewById(R.id.Addresslayout);
mInCallAddressLayout = (LinearLayout) findViewById(R.id.IncallAddressLayout);
mInCallControlRow.setVisibility(View.GONE); mInCallControlRow.setVisibility(View.GONE);
mInCallAddressLayout.setVisibility(View.GONE);
if (LinphoneService.isready()) { if (LinphoneService.isready()) {
if (LinphoneService.instance().getLinphoneCore().isIncall()) { if (LinphoneService.instance().getLinphoneCore().isIncall()) {
@ -163,9 +186,43 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
mHangup.setEnabled(!mCall.isEnabled()); mHangup.setEnabled(!mCall.isEnabled());
mCallControlRow.setVisibility(View.GONE); mCallControlRow.setVisibility(View.GONE);
mInCallControlRow.setVisibility(View.VISIBLE); mInCallControlRow.setVisibility(View.VISIBLE);
mAddressLayout.setVisibility(View.GONE);
mInCallAddressLayout.setVisibility(View.VISIBLE);
} }
} }
mMute = (ToggleButton)findViewById(R.id.mic_mute_button);
mMute.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
LinphoneCore lc = LinphoneService.instance().getLinphoneCore();
if (isChecked) {
lc.muteMic(false);
mMute.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.mic_active, 0, 0);
} else {
lc.muteMic(true);
mMute.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.mic_muted, 0, 0);
}
}
});
mSpeaker = (ToggleButton)findViewById(R.id.speaker_button);
mSpeaker.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
routeAudioToSpeaker();
} else {
routeAudioToReceiver();
}
}
});
mZero = (Button) findViewById(R.id.Button00) ; mZero = (Button) findViewById(R.id.Button00) ;
if (mZero != null) { if (mZero != null) {
@ -199,6 +256,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
} catch (Exception e) { } catch (Exception e) {
Log.e(LinphoneService.TAG,"Cannot start linphone",e); Log.e(LinphoneService.TAG,"Cannot start linphone",e);
finish();
} }
} }
@ -230,39 +288,22 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
switch(state) { switch(state) {
case GSTATE_POWER_ON: case GSTATE_POWER_ON:
mCall.setEnabled(!LinphoneService.instance().getLinphoneCore().isIncall()); mCall.setEnabled(!lc.isIncall());
mHangup.setEnabled(!mCall.isEnabled()); mHangup.setEnabled(!mCall.isEnabled());
break; break;
case GSTATE_REG_OK: { case GSTATE_REG_OK: {
break; break;
} }
case GSTATE_CALL_OUT_INVITE: { 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: { case GSTATE_CALL_IN_INVITE: {
// activate red button enterIncalMode(lc);
mHangup.setEnabled(true); routeAudioToSpeaker();
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) {
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setRouting(AudioManager.MODE_NORMAL,
AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
} else {
mAudioManager.setSpeakerphoneOn(true);
}
break; break;
} }
case GSTATE_CALL_IN_CONNECTED: case GSTATE_CALL_IN_CONNECTED:
case GSTATE_CALL_OUT_CONNECTED: { case GSTATE_CALL_OUT_CONNECTED: {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) { routeAudioToReceiver();
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setRouting(AudioManager.MODE_NORMAL,
AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
} else {
mAudioManager.setSpeakerphoneOn(false);
}
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL); setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
break; break;
} }
@ -288,12 +329,47 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
} }
private void enterIncalMode(LinphoneCore lc) {
mCallControlRow.setVisibility(View.GONE);
mInCallControlRow.setVisibility(View.VISIBLE);
mAddressLayout.setVisibility(View.GONE);
mInCallAddressLayout.setVisibility(View.VISIBLE);
mCall.setEnabled(false);
mHangup.setEnabled(true);
String DisplayName = lc.getRemoteAddress().getDisplayName();
if (DisplayName!=null) {
mDisplayNameView.setText(DisplayName);
} else {
mDisplayNameView.setText(lc.getRemoteAddress().getUserName());
}
}
private void exitCallMode() { private void exitCallMode() {
mCallControlRow.setVisibility(View.VISIBLE); mCallControlRow.setVisibility(View.VISIBLE);
mInCallControlRow.setVisibility(View.GONE); mInCallControlRow.setVisibility(View.GONE);
mAddressLayout.setVisibility(View.VISIBLE);
mInCallAddressLayout.setVisibility(View.GONE);
mCall.setEnabled(true); mCall.setEnabled(true);
mHangup.setEnabled(false); mHangup.setEnabled(false);
setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE); setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);
} }
private void routeAudioToSpeaker() {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) {
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setRouting(AudioManager.MODE_NORMAL,
AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
} else {
mAudioManager.setSpeakerphoneOn(true);
}
}
private void routeAudioToReceiver() {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) {
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setRouting(AudioManager.MODE_NORMAL,
AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
} else {
mAudioManager.setSpeakerphoneOn(false);
}
}
} }

View file

@ -24,6 +24,8 @@ import java.util.List;
import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCallLog; import org.linphone.core.LinphoneCallLog;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.LinphoneCallLog.CallDirection; import org.linphone.core.LinphoneCallLog.CallDirection;
import android.app.ListActivity; import android.app.ListActivity;
@ -70,10 +72,8 @@ public class HistoryActivity extends ListActivity {
class CallHistoryAdapter extends BaseAdapter { class CallHistoryAdapter extends BaseAdapter {
private final Context mContext;
final List<LinphoneCallLog> mLogs; final List<LinphoneCallLog> mLogs;
CallHistoryAdapter(Context aContext) { CallHistoryAdapter(Context aContext) {
mContext = aContext;
mLogs = LinphoneService.instance().getLinphoneCore().getCallLogs(); mLogs = LinphoneService.instance().getLinphoneCore().getCallLogs();
} }
public int getCount() { public int getCount() {
@ -114,13 +114,22 @@ public class HistoryActivity extends ListActivity {
lDirectionImageIn.setVisibility(View.GONE); lDirectionImageIn.setVisibility(View.GONE);
lDirectionImageOut.setVisibility(View.VISIBLE); lDirectionImageOut.setVisibility(View.VISIBLE);
} }
LinphoneCore lc = LinphoneService.instance().getLinphoneCore();
LinphoneProxyConfig lProxyConfig = lc.getDefaultProxyConfig();
String lDetailedName=null;
String lDisplayName = lAddress.getDisplayName();
if (lAddress.getDisplayName() == null) { if (lProxyConfig != null && lProxyConfig.getDomain().equals(lAddress.getDomain())) {
lFirstLineView.setText(lAddress.getUserName()); lDetailedName = lAddress.getUserName();
} else {
lDetailedName = lAddress.toUri();
}
if (lDisplayName == null) {
lFirstLineView.setText(lDetailedName);
lSecondLineView.setVisibility(View.GONE); lSecondLineView.setVisibility(View.GONE);
} else { } else {
lFirstLineView.setText(lAddress.getDisplayName()); lFirstLineView.setText(lDisplayName);
lSecondLineView.setText(lAddress.getUserName()); lSecondLineView.setText(lDetailedName);
lSecondLineView.setVisibility(View.VISIBLE); lSecondLineView.setVisibility(View.VISIBLE);
} }

View file

@ -146,5 +146,11 @@ public interface LinphoneCore {
* @return level in db * @return level in db
*/ */
public float getSoftPlayLevel(); public float getSoftPlayLevel();
/**
* Mutes or unmutes the local microphone.
* @param isMuted
*/
public void muteMic(boolean isMuted);
} }

View file

@ -23,14 +23,11 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.linphone.LinphoneService;
import android.util.Log;
class LinphoneCoreImpl implements LinphoneCore { class LinphoneCoreImpl implements LinphoneCore {
private final LinphoneCoreListener mListener; @SuppressWarnings("unused")
private final LinphoneCoreListener mListener; //to make sure to keep a reference on this object
private long nativePtr = 0; private long nativePtr = 0;
private native long newLinphoneCore(LinphoneCoreListener listener,String userConfig,String factoryConfig,Object userdata); private native long newLinphoneCore(LinphoneCoreListener listener,String userConfig,String factoryConfig,Object userdata);
private native void iterate(long nativePtr); private native void iterate(long nativePtr);
@ -54,6 +51,7 @@ class LinphoneCoreImpl implements LinphoneCore {
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 void setSoftPlayLevel(long nativeptr, float gain);
private native float getSoftPlayLevel(long nativeptr); private native float getSoftPlayLevel(long nativeptr);
private native void muteMic(long nativePtr,boolean isMuted);
LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object userdata) throws IOException { LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object userdata) throws IOException {
@ -168,4 +166,7 @@ class LinphoneCoreImpl implements LinphoneCore {
public float getSoftPlayLevel() { public float getSoftPlayLevel() {
return getSoftPlayLevel(nativePtr); return getSoftPlayLevel(nativePtr);
} }
public void muteMic(boolean isMuted) {
muteMic(nativePtr,isMuted);
}
} }

View file

@ -42,8 +42,8 @@ class LinphoneProxyConfigImpl implements LinphoneProxyConfig {
ownPtr=false; ownPtr=false;
} }
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
Log.e(LinphoneService.TAG,"fixme, should release underlying proxy config"); //Log.e(LinphoneService.TAG,"fixme, should release underlying proxy config");
// FIXME if (ownPtr) delete(nativePtr); if (ownPtr) delete(nativePtr);
} }
private native long newLinphoneProxyConfig(); private native long newLinphoneProxyConfig();
private native void delete(long ptr); private native void delete(long ptr);