phone book integration

This commit is contained in:
Jehan Monnier 2010-02-12 15:46:01 +01:00
parent 4aac453170
commit d169c9ee2e
16 changed files with 239 additions and 51 deletions

View file

@ -5,7 +5,8 @@
android:versionName="1.0">
<application android:icon="@drawable/linphone2" android:label="@string/app_name">
<activity android:name=".Linphone"
android:label="@string/app_name">
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

View file

@ -1,3 +1,3 @@
APP_PROJECT_PATH := $(call my-dir)/
APP_MODULES :=libspeex libortp libosip2 libeXosip2 libmediastreamer2 libmsandroidsnd liblinphone
APP_MODULES :=libspeex libgsm libortp libosip2 libeXosip2 libmediastreamer2 libmsandroidsnd liblinphone
APP_BUILD_SCRIPT:=$(call my-dir)/../linphone-builder/android/Android.mk

View file

@ -7,7 +7,7 @@
<EditText android:id="@+id/SipUri" android:layout_height="wrap_content" android:hint="sip:" android:layout_width="fill_parent" android:singleLine="true"></EditText>
<TableLayout android:layout_width="fill_parent" android:id="@+id/Dialer" android:layout_height="300dip">
<TableLayout android:layout_width="fill_parent" android:id="@+id/Dialer" android:layout_height="280dip">
<TableRow android:layout_height="fill_parent" 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>
<Button android:id="@+id/Button02" android:text="2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.25"></Button>
@ -35,4 +35,5 @@
</TableLayout>
<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>
</LinearLayout>

View file

@ -36,7 +36,7 @@ enabled=0
[audio_codec_1]
mime=speex
rate=16000
enabled=0
enabled=1
[audio_codec_2]
mime=speex
@ -61,10 +61,10 @@ enabled=1
[audio_codec_6]
mime=PCMU
rate=8000
enabled=0
enabled=1
[audio_codec_7]
mime=PCMA
rate=8000
enabled=0
enabled=1

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="pref_prefix_key">pref_prefix_key</string>
<string name="pref_proxy_key">pref_proxy_key</string>
<string name="pref_domain_key">pref_domain_key</string>
<string name="pref_passwd_key">pref_passwd_key</string>

View file

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="pref_prefix">Prefix</string>
<string name="pref_advanced">Advanced</string>
<string name="menu_settings">Settings</string>
<string name="pref_proxy">Proxy</string>
<string name="pref_domain">Domain*</string>
@ -8,9 +10,13 @@
<string name="hello">Hello World, Linphone!</string>
<string name="app_name">Linphone</string>
<string name="pref_sipaccount">SIP Account</string>
<string name="enter_username">Enter a user name</string>
<string name="enter_passwd">Enter a password</string>
<string name="enter_domain">Enter a domain</string>
<string name="wrong_username">wrong user name</string>
<string name="wrong_passwd">wrong password</string>
<string name="wrong_domain">Wrong domain</string>
<string name="tab_dialer">Dialer</string>
<string name="tab_contact">Contact</string>
<string name="call_error">Cannot call %s</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="config_error">%s, do you want to return to the settings page ?</string>
</resources>

View file

@ -6,4 +6,6 @@
<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

@ -1,6 +1,8 @@
package org.linphone;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneProxyConfig;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
@ -13,6 +15,7 @@ import android.widget.TextView;
public class DialerActivity extends Activity {
private LinphoneCore mLinphoneCore;
private TextView mAddress;
private TextView mStatus;
private ImageButton mCall;
private ImageButton mHangup;
private Button mZero;
@ -30,9 +33,13 @@ public class DialerActivity extends Activity {
private static DialerActivity theDialer;
private String mDisplayName;
/**
*
* @return nul if not ready yet
*/
public static DialerActivity getDialer() {
if (theDialer == null) {
throw new RuntimeException("DialerActivity not instanciated yet");
return null;
} else {
return theDialer;
}
@ -41,6 +48,9 @@ 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);
@ -52,7 +62,12 @@ public class DialerActivity extends Activity {
mCall = (ImageButton) findViewById(R.id.Call);
mCall.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mLinphoneCore.invite(mAddress.getText().toString());
LinphoneProxyConfig lProxy = mLinphoneCore.getDefaultProxyConfig();
String lNormalizedNumber = mAddress.getText().toString();
if (lProxy!=null) {
lNormalizedNumber = lProxy.normalizePhoneNumber(lNormalizedNumber);
}
mLinphoneCore.invite(lNormalizedNumber);
}
});
@ -102,7 +117,7 @@ public class DialerActivity extends Activity {
mHash = (Button) findViewById(R.id.ButtonHash);
mHash.setOnClickListener(new DialKeyListener(mAddress,'#'));
mStatus = (TextView) findViewById(R.id.status_label);
} catch (Exception e) {
Log.e(Linphone.TAG,"Cannot start linphone",e);

View file

@ -33,24 +33,21 @@ import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneCoreListener;
import org.linphone.core.LinphoneProxyConfig;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.provider.Contacts.People;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
public class Linphone extends TabActivity implements LinphoneCoreListener {
@ -67,7 +64,7 @@ public class Linphone extends TabActivity implements LinphoneCoreListener {
Timer mTimer = new Timer("Linphone scheduler");
public static String DIALER_TAB = "dialer";
private Handler mIteratehandler;
static Linphone getLinphone() {
if (theLinphone == null) {
throw new RuntimeException("LinphoneActivity not instanciated yet");
@ -90,16 +87,21 @@ public class Linphone extends TabActivity implements LinphoneCoreListener {
, null);
initFromConf();
mIteratehandler = new Handler() {
public void handleMessage(Message msg) {
//iterate is called inside an Android handler to allow UI interaction within LinphoneCoreListener
mLinphoneCore.iterate();
}
};
TimerTask lTask = new TimerTask() {
@Override
public void run() {
mLinphoneCore.iterate();
mIteratehandler.sendEmptyMessage(0);
}
};
mTimer.scheduleAtFixedRate(lTask, 0, 100);
@ -149,12 +151,17 @@ public class Linphone extends TabActivity implements LinphoneCoreListener {
private void copyAssetsFromPackage() throws IOException {
copyIfNotExist(R.raw.oldphone_mono,RING_SND);
copyIfNotExist(R.raw.ringback,RINGBACK_SND);
copyIfNotExist(R.raw.linphonerc,LINPHONE_FACTORY_RC);
copyFromPackage(R.raw.linphonerc, new File(LINPHONE_FACTORY_RC).getName());
}
private void copyIfNotExist(int ressourceId,String target) throws IOException {
File lFileToCopy = new File(target);
if (!lFileToCopy.exists()) {
FileOutputStream lOutputStream = openFileOutput (lFileToCopy.getName(), 0);
copyFromPackage(ressourceId,lFileToCopy.getName());
}
}
private void copyFromPackage(int ressourceId,String target) throws IOException{
FileOutputStream lOutputStream = openFileOutput (target, 0);
InputStream lInputStream = getResources().openRawResource(ressourceId);
int readByte;
byte[] buff = new byte[8048];
@ -164,7 +171,6 @@ public class Linphone extends TabActivity implements LinphoneCoreListener {
lOutputStream.flush();
lOutputStream.close();
lInputStream.close();
}
}
public void authInfoRequested(LinphoneCore lc, String realm, String username) {
@ -181,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);
}
public void displayWarning(LinphoneCore lc, String message) {
// TODO Auto-generated method stub
@ -191,9 +197,14 @@ public class Linphone extends TabActivity implements LinphoneCoreListener {
Log.i(TAG, "new state ["+state+"]");
switch(state) {
case GSTATE_REG_OK: {
//mLinphoneCore.invite("simon.morlat");
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:
}
}
@ -229,29 +240,25 @@ public class Linphone extends TabActivity implements LinphoneCoreListener {
return false;
}
public void initFromConf() throws LinphoneCoreException {
//1 read proxy config from preferences
String lUserName = mPref.getString(getString(R.string.pref_username_key), null);
if (lUserName == null) {
Toast toast = Toast.makeText(this, getString(R.string.enter_username), Toast.LENGTH_LONG);
toast.show();
startprefActivity();
handleBadConfig(getString(R.string.wrong_username));
return;
}
String lPasswd = mPref.getString(getString(R.string.pref_passwd_key), null);
if (lPasswd == null) {
Toast toast = Toast.makeText(this, this.getString(R.string.enter_passwd), Toast.LENGTH_LONG);
toast.show();
startprefActivity();
handleBadConfig(getString(R.string.wrong_passwd));
return;
}
String lDomain = mPref.getString(getString(R.string.pref_domain_key), null);
if (lDomain == null) {
Toast toast = Toast.makeText(this, this.getString(R.string.enter_domain), Toast.LENGTH_LONG);
toast.show();
startprefActivity();
handleBadConfig(getString(R.string.wrong_domain));
return;
}
@ -284,6 +291,22 @@ public class Linphone extends TabActivity implements LinphoneCoreListener {
}
private void handleBadConfig(String message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(String.format(getString(R.string.config_error),message))
.setCancelable(false)
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startprefActivity();
}
})
.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
builder.create().show();
}
private void startprefActivity() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(Linphone.this, LinphonePreferencesActivity.class);

View file

@ -0,0 +1,37 @@
/*
LinphoneAddress.java
Copyright (C) 2010 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone.core;
public interface LinphoneAddress {
/**
* Human display name
* @return null if not set
*/
public String getDisplayName();
/**
* userinfo
* @return null if not set
*/
public String getUserName();
/**
*
* @return null if not set
*/
public String getDomain();
}

View file

@ -0,0 +1,61 @@
/*
LinphoneAddressImpl.java
Copyright (C) 2010 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone.core;
public class LinphoneAddressImpl implements LinphoneAddress {
protected final long nativePtr;
boolean ownPtr = false;
private native long newLinphoneAddressImpl(String uri,String displayName);
private native void delete(long ptr);
private native String getDisplayName(long ptr);
private native String getUserName(long ptr);
private native String getDomain(long ptr);
protected LinphoneAddressImpl(String username,String domain,String displayName) {
nativePtr = newLinphoneAddressImpl("sip:"+username+"@"+domain, displayName);
}
protected LinphoneAddressImpl(long aNativePtr) {
nativePtr = aNativePtr;
ownPtr=false;
}
protected void finalize() throws Throwable {
if (ownPtr) delete(nativePtr);
}
public String getDisplayName() {
return getDisplayName(nativePtr);
}
public String getDomain() {
return getDomain(nativePtr);
}
public String getUserName() {
return getUserName(nativePtr);
}
public String toString() {
String tmp="";
if (getDisplayName()!=null) {
tmp="<"+getDisplayName()+">";
}
return tmp+"sip:"+getUserName()+"@"+getDomain();
}
}

View file

@ -1,3 +1,21 @@
/*
LinphoneAuthInfoImpl.java
Copyright (C) 2010 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone.core;
class LinphoneAuthInfoImpl implements LinphoneAuthInfo {

View file

@ -89,6 +89,11 @@ public interface LinphoneCore {
public void invite(String uri);
public void terminateCall();
/**
* get the remote address in case of in/out call
* @return null if no call engaged yet
*/
public LinphoneAddress getRemoteAddress();
public void iterate();
}

View file

@ -38,6 +38,7 @@ class LinphoneCoreImpl implements LinphoneCore {
private native void addAuthInfo(long nativePtr,long authInfoNativePtr);
private native void invite(long nativePtr,String uri);
private native void terminateCall(long nativePtr);
private native long getRemoteAddress(long nativePtr);
LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object userdata) throws IOException {
mListener=listener;
@ -87,6 +88,14 @@ class LinphoneCoreImpl implements LinphoneCore {
public void terminateCall() {
terminateCall(nativePtr);
}
public LinphoneAddress getRemoteAddress() {
long ptr = getRemoteAddress(nativePtr);
if (ptr==0) {
return null;
} else {
return new LinphoneAddressImpl(ptr);
}
}
}

View file

@ -45,6 +45,10 @@ public interface LinphoneProxyConfig {
* @throws LinphoneCoreException
*/
public void enableRegister(boolean value) throws LinphoneCoreException;
/**
* normalize a human readable phone number into a basic string. 888-444-222 becomes 888444222
* @param number
* @return
*/
public String normalizePhoneNumber(String number);
}

View file

@ -55,6 +55,8 @@ class LinphoneProxyConfigImpl implements LinphoneProxyConfig {
private native void enableRegister(long ptr,boolean value);
private native String normalizePhoneNumber(long ptr,String number);
public void enableRegister(boolean value) {
enableRegister(nativePtr,value);
}
@ -76,4 +78,7 @@ class LinphoneProxyConfigImpl implements LinphoneProxyConfig {
throw new LinphoneCoreException("Bad proxy address ["+proxyUri+"]");
}
}
public String normalizePhoneNumber(String number) {
return normalizePhoneNumber(nativePtr,number);
}
}