more jni functions implemented
This commit is contained in:
parent
d169c9ee2e
commit
d4ef1c0957
7 changed files with 104 additions and 28 deletions
|
@ -1,7 +1,11 @@
|
||||||
package org.linphone;
|
package org.linphone;
|
||||||
|
|
||||||
|
import org.linphone.core.LinphoneAddress;
|
||||||
import org.linphone.core.LinphoneCore;
|
import org.linphone.core.LinphoneCore;
|
||||||
|
import org.linphone.core.LinphoneCoreFactory;
|
||||||
|
import org.linphone.core.LinphoneCoreListener;
|
||||||
import org.linphone.core.LinphoneProxyConfig;
|
import org.linphone.core.LinphoneProxyConfig;
|
||||||
|
import org.linphone.core.LinphoneCore.GeneralState;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -11,8 +15,9 @@ import android.view.View.OnClickListener;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class DialerActivity extends Activity {
|
public class DialerActivity extends Activity implements LinphoneCoreListener {
|
||||||
private LinphoneCore mLinphoneCore;
|
private LinphoneCore mLinphoneCore;
|
||||||
private TextView mAddress;
|
private TextView mAddress;
|
||||||
private TextView mStatus;
|
private TextView mStatus;
|
||||||
|
@ -48,9 +53,6 @@ public class DialerActivity extends Activity {
|
||||||
mAddress.setText(aContact);
|
mAddress.setText(aContact);
|
||||||
mDisplayName = aDisplayName;
|
mDisplayName = aDisplayName;
|
||||||
}
|
}
|
||||||
public void displayStatus(String status) {
|
|
||||||
mStatus.setText(status);
|
|
||||||
}
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.dialer);
|
setContentView(R.layout.dialer);
|
||||||
|
@ -62,12 +64,24 @@ public class DialerActivity extends Activity {
|
||||||
mCall = (ImageButton) findViewById(R.id.Call);
|
mCall = (ImageButton) findViewById(R.id.Call);
|
||||||
mCall.setOnClickListener(new OnClickListener() {
|
mCall.setOnClickListener(new OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
String lRawAddress = mAddress.getText().toString();
|
||||||
|
String lCallingUri=null;
|
||||||
|
if (lRawAddress.startsWith("sip:")) {
|
||||||
|
lCallingUri=lRawAddress;
|
||||||
|
} else {
|
||||||
LinphoneProxyConfig lProxy = mLinphoneCore.getDefaultProxyConfig();
|
LinphoneProxyConfig lProxy = mLinphoneCore.getDefaultProxyConfig();
|
||||||
String lNormalizedNumber = mAddress.getText().toString();
|
String lDomain=null;
|
||||||
if (lProxy!=null) {
|
String lNormalizedNumber=null;
|
||||||
lNormalizedNumber = lProxy.normalizePhoneNumber(lNormalizedNumber);
|
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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ public class Linphone extends TabActivity implements LinphoneCoreListener {
|
||||||
public static String DIALER_TAB = "dialer";
|
public static String DIALER_TAB = "dialer";
|
||||||
|
|
||||||
private Handler mIteratehandler;
|
private Handler mIteratehandler;
|
||||||
|
|
||||||
static Linphone getLinphone() {
|
static Linphone getLinphone() {
|
||||||
if (theLinphone == null) {
|
if (theLinphone == null) {
|
||||||
throw new RuntimeException("LinphoneActivity not instanciated yet");
|
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) {
|
public void authInfoRequested(LinphoneCore lc, String realm, String username) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public void byeReceived(LinphoneCore lc, String from) {
|
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) {
|
public void displayStatus(LinphoneCore lc, String message) {
|
||||||
Log.i(TAG, 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) {
|
public void displayWarning(LinphoneCore lc, String message) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
@ -195,18 +195,7 @@ public class Linphone extends TabActivity implements LinphoneCoreListener {
|
||||||
}
|
}
|
||||||
public void generalState(LinphoneCore lc, LinphoneCore.GeneralState state) {
|
public void generalState(LinphoneCore lc, LinphoneCore.GeneralState state) {
|
||||||
Log.i(TAG, "new state ["+state+"]");
|
Log.i(TAG, "new state ["+state+"]");
|
||||||
|
if (DialerActivity.getDialer()!=null) DialerActivity.getDialer().generalState(lc,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:
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public void inviteReceived(LinphoneCore lc, String from) {
|
public void inviteReceived(LinphoneCore lc, String from) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
@ -287,7 +276,13 @@ public class Linphone extends TabActivity implements LinphoneCoreListener {
|
||||||
lDefaultProxyConfig.enableRegister(true);
|
lDefaultProxyConfig.enableRegister(true);
|
||||||
lDefaultProxyConfig.done();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,4 +34,9 @@ public interface LinphoneAddress {
|
||||||
* @return null if not set
|
* @return null if not set
|
||||||
*/
|
*/
|
||||||
public String getDomain();
|
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class LinphoneAddressImpl implements LinphoneAddress {
|
||||||
private native String getDisplayName(long ptr);
|
private native String getDisplayName(long ptr);
|
||||||
private native String getUserName(long ptr);
|
private native String getUserName(long ptr);
|
||||||
private native String getDomain(long ptr);
|
private native String getDomain(long ptr);
|
||||||
|
private native String toUri(long ptr);
|
||||||
|
|
||||||
protected LinphoneAddressImpl(String username,String domain,String displayName) {
|
protected LinphoneAddressImpl(String username,String domain,String displayName) {
|
||||||
nativePtr = newLinphoneAddressImpl("sip:"+username+"@"+domain, displayName);
|
nativePtr = newLinphoneAddressImpl("sip:"+username+"@"+domain, displayName);
|
||||||
|
@ -51,11 +51,10 @@ public class LinphoneAddressImpl implements LinphoneAddress {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String tmp="";
|
return toUri();
|
||||||
if (getDisplayName()!=null) {
|
}
|
||||||
tmp="<"+getDisplayName()+">";
|
public String toUri() {
|
||||||
}
|
return toUri(nativePtr);
|
||||||
return tmp+"sip:"+getUserName()+"@"+getDomain();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,9 @@ public class LinphoneCoreFactory {
|
||||||
return new LinphoneCoreImpl(listener,userConfig,factoryConfig,userdata);
|
return new LinphoneCoreImpl(listener,userConfig,factoryConfig,userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LinphoneAddress createLinphoneAddress(String username,String domain,String displayName) {
|
||||||
|
return new LinphoneAddressImpl(username,domain,displayName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,4 +51,15 @@ public interface LinphoneProxyConfig {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String normalizePhoneNumber(String number);
|
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,8 +55,12 @@ class LinphoneProxyConfigImpl implements LinphoneProxyConfig {
|
||||||
|
|
||||||
private native void enableRegister(long ptr,boolean value);
|
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 normalizePhoneNumber(long ptr,String number);
|
||||||
|
|
||||||
|
private native String getDomain(long ptr);
|
||||||
|
|
||||||
public void enableRegister(boolean value) {
|
public void enableRegister(boolean value) {
|
||||||
enableRegister(nativePtr,value);
|
enableRegister(nativePtr,value);
|
||||||
}
|
}
|
||||||
|
@ -81,4 +85,10 @@ class LinphoneProxyConfigImpl implements LinphoneProxyConfig {
|
||||||
public String normalizePhoneNumber(String number) {
|
public String normalizePhoneNumber(String number) {
|
||||||
return normalizePhoneNumber(nativePtr,number);
|
return normalizePhoneNumber(nativePtr,number);
|
||||||
}
|
}
|
||||||
|
public void setDialPrefix(String prefix) {
|
||||||
|
setDialPrefix(nativePtr, prefix);
|
||||||
|
}
|
||||||
|
public String getDomain() {
|
||||||
|
return getDomain(nativePtr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue