start contact list integration

This commit is contained in:
Jehan Monnier 2010-02-09 18:33:28 +01:00
parent 02c9aa2299
commit 4aac453170
7 changed files with 282 additions and 114 deletions

View file

@ -16,9 +16,20 @@
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
<activity android:name=".DialerActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity android:name=".ContactPickerActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
</manifest>

38
res/layout/dialer.xml Normal file
View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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>
<TableLayout android:layout_width="fill_parent" android:id="@+id/Dialer" android:layout_height="300dip">
<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>
<Button android:id="@+id/Button03" android:text="3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.5"></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>
<Button android:text="5" android:id="@+id/Button05" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.25"></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>
</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>
<Button android:id="@+id/Button08" android:text="8" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.25"></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>
</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>
<Button android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="0+" android:id="@+id/Button00" android:layout_weight="0.25"></Button>
<Button android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/ButtonHash" android:text="#" android:layout_weight="0.5"></Button>
</TableRow><TableRow android:layout_height="fill_parent" android:id="@+id/DialerRow00" android:layout_width="fill_parent" android:layout_weight="1">
<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" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.25"></ImageButton>
</TableRow>
</TableLayout>
</LinearLayout>

View file

@ -1,38 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
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>
<TableLayout android:layout_width="fill_parent" android:id="@+id/Dialer" android:layout_height="300dip">
<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>
<Button android:id="@+id/Button03" android:text="3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.5"></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>
<Button android:text="5" android:id="@+id/Button05" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.25"></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>
</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>
<Button android:id="@+id/Button08" android:text="8" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.25"></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>
</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>
<Button android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="0+" android:id="@+id/Button00" android:layout_weight="0.25"></Button>
<Button android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/ButtonHash" android:text="#" android:layout_weight="0.5"></Button>
</TableRow><TableRow android:layout_height="fill_parent" android:id="@+id/DialerRow00" android:layout_width="fill_parent" android:layout_weight="1">
<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" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.25"></ImageButton>
</TableRow>
</TableLayout>
</LinearLayout>
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>

View file

@ -11,4 +11,6 @@
<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="tab_dialer">Dialer</string>
<string name="tab_contact">Contact</string>
</resources>

View file

@ -0,0 +1,57 @@
package org.linphone;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts;
import android.provider.Contacts.People;
public class ContactPickerActivity extends Activity {
static final int PICK_CONTACT_REQUEST = 0;
static final int PICK_PHONE_NUMBER_REQUEST = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
super.onResume();
startActivityForResult(new Intent(Intent.ACTION_PICK, Contacts.Phones.CONTENT_URI)
,
PICK_CONTACT_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == PICK_CONTACT_REQUEST) {
if (resultCode == RESULT_OK) {
String lColumns[] = new String[] { People.NAME, People.NUMBER };
Cursor lCur = managedQuery(data.getData(), lColumns, // Which columns to return
null, // WHERE clause; which rows to return(all rows)
null, // WHERE clause selection arguments (none)
null // Order-by clause (ascending by name)
);
if (lCur.moveToFirst()) {
String lName = null;
String lPhoneNo = null;
// Get the field values
lName = lCur.getString(lCur.getColumnIndex(People.NAME));
lPhoneNo = lCur.getString(lCur.getColumnIndex(People.NUMBER));
DialerActivity.getDialer().setContactAddress(lPhoneNo, lName);
}
}
Linphone.getLinphone().getTabHost().setCurrentTabByTag(Linphone.DIALER_TAB);
}
}
}

View file

@ -0,0 +1,113 @@
package org.linphone;
import org.linphone.core.LinphoneCore;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
public class DialerActivity extends Activity {
private LinphoneCore mLinphoneCore;
private TextView mAddress;
private ImageButton mCall;
private ImageButton mHangup;
private Button mZero;
private Button mOne;
private Button mTwo;
private Button mThree ;
private Button mFour;
private Button mFive;
private Button mSix;
private Button mSeven;
private Button mEight;
private Button mNine;
private Button mStar;
private Button mHash;
private static DialerActivity theDialer;
private String mDisplayName;
public static DialerActivity getDialer() {
if (theDialer == null) {
throw new RuntimeException("DialerActivity not instanciated yet");
} else {
return theDialer;
}
}
public void setContactAddress(String aContact,String aDisplayName) {
mAddress.setText(aContact);
mDisplayName = aDisplayName;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialer);
try {
theDialer = this;
mLinphoneCore = Linphone.getLinphone().getLinphoneCore();
mAddress = (TextView) findViewById(R.id.SipUri);
mCall = (ImageButton) findViewById(R.id.Call);
mCall.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mLinphoneCore.invite(mAddress.getText().toString());
}
});
mHangup = (ImageButton) findViewById(R.id.HangUp);
mHangup.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mLinphoneCore.terminateCall();
}
});
class DialKeyListener implements OnClickListener {
final String mKeyCode;
final TextView mAddressView;
DialKeyListener(TextView anAddress, char aKeyCode) {
mKeyCode = String.valueOf(aKeyCode);
mAddressView = anAddress;
}
public void onClick(View v) {
mAddressView.append(mKeyCode);
}
};
mZero = (Button) findViewById(R.id.Button00) ;
mZero.setOnClickListener(new DialKeyListener(mAddress,'0'));
mOne = (Button) findViewById(R.id.Button01) ;
mOne.setOnClickListener(new DialKeyListener(mAddress,'1'));
mTwo = (Button) findViewById(R.id.Button02);
mTwo.setOnClickListener(new DialKeyListener(mAddress,'2'));
mThree = (Button) findViewById(R.id.Button03);
mThree.setOnClickListener(new DialKeyListener(mAddress,'3'));
mFour = (Button) findViewById(R.id.Button04);
mFour.setOnClickListener(new DialKeyListener(mAddress,'4'));
mFive = (Button) findViewById(R.id.Button05);
mFive.setOnClickListener(new DialKeyListener(mAddress,'5'));
mSix = (Button) findViewById(R.id.Button06);
mSix.setOnClickListener(new DialKeyListener(mAddress,'6'));
mSeven = (Button) findViewById(R.id.Button07);
mSeven.setOnClickListener(new DialKeyListener(mAddress,'7'));
mEight = (Button) findViewById(R.id.Button08);
mEight.setOnClickListener(new DialKeyListener(mAddress,'8'));
mNine = (Button) findViewById(R.id.Button09);
mNine.setOnClickListener(new DialKeyListener(mAddress,'9'));
mStar = (Button) findViewById(R.id.ButtonStar);
mStar.setOnClickListener(new DialKeyListener(mAddress,'*'));
mHash = (Button) findViewById(R.id.ButtonHash);
mHash.setOnClickListener(new DialKeyListener(mAddress,'#'));
} catch (Exception e) {
Log.e(Linphone.TAG,"Cannot start linphone",e);
}
}
}

View file

@ -34,10 +34,13 @@ import org.linphone.core.LinphoneCoreListener;
import org.linphone.core.LinphoneProxyConfig;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.Contacts.People;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
@ -46,10 +49,11 @@ 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 Activity implements LinphoneCoreListener {
public class Linphone extends TabActivity implements LinphoneCoreListener {
static final public String TAG="Linphone";
/** Called when the activity is first created. */
private static String LINPHONE_FACTORY_RC = "/data/data/org.linphone/files/linphonerc";
@ -61,22 +65,8 @@ public class Linphone extends Activity implements LinphoneCoreListener {
private LinphoneCore mLinphoneCore;
private SharedPreferences mPref;
Timer mTimer = new Timer("Linphone scheduler");
private TextView mAddress;
private ImageButton mCall;
private ImageButton mHangup;
private Button mZero;
private Button mOne;
private Button mTwo;
private Button mThree ;
private Button mFour;
private Button mFive;
private Button mSix;
private Button mSeven;
private Button mEight;
private Button mNine;
private Button mStar;
private Button mHash;
public static String DIALER_TAB = "dialer";
static Linphone getLinphone() {
if (theLinphone == null) {
@ -95,12 +85,12 @@ public class Linphone extends Activity implements LinphoneCoreListener {
copyAssetsFromPackage();
mLinphoneCore = LinphoneCoreFactory.instance().createLinphoneCore( this
, new File(LINPHONE_RC)
, new File(LINPHONE_RC)
, new File(LINPHONE_FACTORY_RC)
, null);
initFromConf();
TimerTask lTask = new TimerTask() {
@Override
@ -110,66 +100,37 @@ public class Linphone extends Activity implements LinphoneCoreListener {
}
};
mTimer.scheduleAtFixedRate(lTask, 0, 100);
mTimer.scheduleAtFixedRate(lTask, 0, 100);
TabHost lTabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
Intent lDialerIntent = new Intent().setClass(this, DialerActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = lTabHost.newTabSpec("dialer").setIndicator(getString(R.string.tab_dialer),
getResources().getDrawable(android.R.drawable.ic_menu_call))
.setContent(lDialerIntent);
lTabHost.addTab(spec);
// Do the same for the other tabs
Intent lContactItent = new Intent().setClass(this, ContactPickerActivity.class);
spec = lTabHost.newTabSpec("contact").setIndicator(getString(R.string.tab_contact),
null)
.setContent(lContactItent);
lTabHost.addTab(spec);
lTabHost.setCurrentTabByTag("dialer");
mAddress = (TextView) findViewById(R.id.SipUri);
mCall = (ImageButton) findViewById(R.id.Call);
mCall.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mLinphoneCore.invite(mAddress.getText().toString());
}
});
mHangup = (ImageButton) findViewById(R.id.HangUp);
mHangup.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mLinphoneCore.terminateCall();
}
});
class DialKeyListener implements OnClickListener {
final String mKeyCode;
final TextView mAddressView;
DialKeyListener(TextView anAddress, char aKeyCode) {
mKeyCode = String.valueOf(aKeyCode);
mAddressView = anAddress;
}
public void onClick(View v) {
mAddressView.append(mKeyCode);
}
};
mZero = (Button) findViewById(R.id.Button00) ;
mZero.setOnClickListener(new DialKeyListener(mAddress,'0'));
mOne = (Button) findViewById(R.id.Button01) ;
mOne.setOnClickListener(new DialKeyListener(mAddress,'1'));
mTwo = (Button) findViewById(R.id.Button02);
mTwo.setOnClickListener(new DialKeyListener(mAddress,'2'));
mThree = (Button) findViewById(R.id.Button03);
mThree.setOnClickListener(new DialKeyListener(mAddress,'3'));
mFour = (Button) findViewById(R.id.Button04);
mFour.setOnClickListener(new DialKeyListener(mAddress,'4'));
mFive = (Button) findViewById(R.id.Button05);
mFive.setOnClickListener(new DialKeyListener(mAddress,'5'));
mSix = (Button) findViewById(R.id.Button06);
mSix.setOnClickListener(new DialKeyListener(mAddress,'6'));
mSeven = (Button) findViewById(R.id.Button07);
mSeven.setOnClickListener(new DialKeyListener(mAddress,'7'));
mEight = (Button) findViewById(R.id.Button08);
mEight.setOnClickListener(new DialKeyListener(mAddress,'8'));
mNine = (Button) findViewById(R.id.Button09);
mNine.setOnClickListener(new DialKeyListener(mAddress,'9'));
mStar = (Button) findViewById(R.id.ButtonStar);
mStar.setOnClickListener(new DialKeyListener(mAddress,'*'));
mHash = (Button) findViewById(R.id.ButtonHash);
mHash.setOnClickListener(new DialKeyListener(mAddress,'#'));
} catch (Exception e) {
Log.e(TAG,"Cannot start linphone",e);
}
@ -272,7 +233,7 @@ public class Linphone extends Activity implements LinphoneCoreListener {
//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, this.getString(R.string.enter_username), Toast.LENGTH_LONG);
Toast toast = Toast.makeText(this, getString(R.string.enter_username), Toast.LENGTH_LONG);
toast.show();
startprefActivity();
return;
@ -328,5 +289,8 @@ public class Linphone extends Activity implements LinphoneCoreListener {
intent.setClass(Linphone.this, LinphonePreferencesActivity.class);
startActivity(intent);
}
protected LinphoneCore getLinphoneCore() {
return mLinphoneCore;
}
}