more jni functions implemented

This commit is contained in:
jehan monnier 2010-02-14 09:52:18 +01:00
parent d169c9ee2e
commit d4ef1c0957
7 changed files with 104 additions and 28 deletions

View file

@ -1,7 +1,11 @@
package org.linphone;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneCoreListener;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.LinphoneCore.GeneralState;
import android.app.Activity;
import android.os.Bundle;
@ -11,8 +15,9 @@ import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
public class DialerActivity extends Activity {
public class DialerActivity extends Activity implements LinphoneCoreListener {
private LinphoneCore mLinphoneCore;
private TextView mAddress;
private TextView mStatus;
@ -48,9 +53,6 @@ public class DialerActivity extends Activity {
mAddress.setText(aContact);
mDisplayName = aDisplayName;
}
public void displayStatus(String status) {
mStatus.setText(status);
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialer);
@ -62,12 +64,24 @@ public class DialerActivity extends Activity {
mCall = (ImageButton) findViewById(R.id.Call);
mCall.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String lRawAddress = mAddress.getText().toString();
String lCallingUri=null;
if (lRawAddress.startsWith("sip:")) {
lCallingUri=lRawAddress;
} else {
LinphoneProxyConfig lProxy = mLinphoneCore.getDefaultProxyConfig();
String lNormalizedNumber = mAddress.getText().toString();
if (lProxy!=null) {
lNormalizedNumber = lProxy.normalizePhoneNumber(lNormalizedNumber);
String lDomain=null;
String lNormalizedNumber=null;
if (lProxy!=null) {
lNormalizedNumber = lProxy.normalizePhoneNumber(lNormalizedNumber);
lDomain = lProxy.getDomain();
}
LinphoneAddress lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(lNormalizedNumber
, lDomain
, mDisplayName);
lCallingUri = lAddress.toUri();
}
mLinphoneCore.invite(lNormalizedNumber);
mLinphoneCore.invite(lCallingUri);
}
});
@ -124,5 +138,44 @@ public class DialerActivity extends Activity {
}
}
public void authInfoRequested(LinphoneCore lc, String realm, String username) {
// TODO Auto-generated method stub
}
public void byeReceived(LinphoneCore lc, String from) {
// TODO Auto-generated method stub
}
public void displayMessage(LinphoneCore lc, String message) {
// TODO Auto-generated method stub
}
public void displayStatus(LinphoneCore lc, String message) {
mStatus.setText(message);
}
public void displayWarning(LinphoneCore lc, String message) {
// TODO Auto-generated method stub
}
public void generalState(LinphoneCore lc, GeneralState state) {
switch(state) {
case GSTATE_CALL_ERROR: {
Toast toast = Toast.makeText(this
,String.format(getString(R.string.call_error),lc.getRemoteAddress())
, Toast.LENGTH_LONG);
toast.show();
}
case GSTATE_REG_OK:
}
}
public void inviteReceived(LinphoneCore lc, String from) {
// TODO Auto-generated method stub
}
public void show(LinphoneCore lc) {
// TODO Auto-generated method stub
}
}

View file

@ -65,6 +65,7 @@ public class Linphone extends TabActivity implements LinphoneCoreListener {
public static String DIALER_TAB = "dialer";
private Handler mIteratehandler;
static Linphone getLinphone() {
if (theLinphone == null) {
throw new RuntimeException("LinphoneActivity not instanciated yet");
@ -174,7 +175,6 @@ public class Linphone extends TabActivity implements LinphoneCoreListener {
}
public void authInfoRequested(LinphoneCore lc, String realm, String username) {
// TODO Auto-generated method stub
}
public void byeReceived(LinphoneCore lc, String from) {
@ -187,7 +187,7 @@ public class Linphone extends TabActivity implements LinphoneCoreListener {
}
public void displayStatus(LinphoneCore lc, String message) {
Log.i(TAG, message);
if (DialerActivity.getDialer()!=null) DialerActivity.getDialer().displayStatus(message);
if (DialerActivity.getDialer()!=null) DialerActivity.getDialer().displayStatus(lc,message);
}
public void displayWarning(LinphoneCore lc, String message) {
// TODO Auto-generated method stub
@ -195,18 +195,7 @@ public class Linphone extends TabActivity implements LinphoneCoreListener {
}
public void generalState(LinphoneCore lc, LinphoneCore.GeneralState state) {
Log.i(TAG, "new state ["+state+"]");
switch(state) {
case GSTATE_CALL_ERROR: {
Toast toast = Toast.makeText(this
,String.format(getString(R.string.call_error),mLinphoneCore.getRemoteAddress())
, Toast.LENGTH_LONG);
toast.show();
}
case GSTATE_REG_OK:
}
if (DialerActivity.getDialer()!=null) DialerActivity.getDialer().generalState(lc,state);
}
public void inviteReceived(LinphoneCore lc, String from) {
// TODO Auto-generated method stub
@ -287,7 +276,13 @@ public class Linphone extends TabActivity implements LinphoneCoreListener {
lDefaultProxyConfig.enableRegister(true);
lDefaultProxyConfig.done();
}
lDefaultProxyConfig = mLinphoneCore.getDefaultProxyConfig();
//prefix
String lPrefix = mPref.getString(getString(R.string.pref_prefix_key), null);
if (lPrefix != null && lDefaultProxyConfig !=null) {
lDefaultProxyConfig.setDialPrefix(lPrefix);
}
}

View file

@ -34,4 +34,9 @@ public interface LinphoneAddress {
* @return null if not set
*/
public String getDomain();
/**
* @return an URI version of the address that can be used to place a call using {@link LinphoneCore#invite(String)}
*/
public String toUri();
}

View file

@ -28,7 +28,7 @@ public class LinphoneAddressImpl implements LinphoneAddress {
private native String getDisplayName(long ptr);
private native String getUserName(long ptr);
private native String getDomain(long ptr);
private native String toUri(long ptr);
protected LinphoneAddressImpl(String username,String domain,String displayName) {
nativePtr = newLinphoneAddressImpl("sip:"+username+"@"+domain, displayName);
@ -51,11 +51,10 @@ public class LinphoneAddressImpl implements LinphoneAddress {
}
public String toString() {
String tmp="";
if (getDisplayName()!=null) {
tmp="<"+getDisplayName()+">";
}
return tmp+"sip:"+getUserName()+"@"+getDomain();
return toUri();
}
public String toUri() {
return toUri(nativePtr);
}
}

View file

@ -39,6 +39,9 @@ public class LinphoneCoreFactory {
return new LinphoneCoreImpl(listener,userConfig,factoryConfig,userdata);
}
public LinphoneAddress createLinphoneAddress(String username,String domain,String displayName) {
return new LinphoneAddressImpl(username,domain,displayName);
}
}

View file

@ -51,4 +51,15 @@ public interface LinphoneProxyConfig {
* @return
*/
public String normalizePhoneNumber(String number);
/**
* usefull function to automatically add internationnal prefix to e164 phone numbers
* @param prefix
*/
public void setDialPrefix(String prefix);
/**
* rget domain host name or ip
* @return may be null
*/
public String getDomain();
}

View file

@ -55,8 +55,12 @@ class LinphoneProxyConfigImpl implements LinphoneProxyConfig {
private native void enableRegister(long ptr,boolean value);
private native void setDialPrefix(long ptr, String prefix);
private native String normalizePhoneNumber(long ptr,String number);
private native String getDomain(long ptr);
public void enableRegister(boolean value) {
enableRegister(nativePtr,value);
}
@ -81,4 +85,10 @@ class LinphoneProxyConfigImpl implements LinphoneProxyConfig {
public String normalizePhoneNumber(String number) {
return normalizePhoneNumber(nativePtr,number);
}
public void setDialPrefix(String prefix) {
setDialPrefix(nativePtr, prefix);
}
public String getDomain() {
return getDomain(nativePtr);
}
}