From 4aac453170e8557e31d5eab80a067194f591d705 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Tue, 9 Feb 2010 18:33:28 +0100 Subject: [PATCH] start contact list integration --- AndroidManifest.xml | 13 ++- res/layout/dialer.xml | 38 +++++++ res/layout/main.xml | 55 ++++----- res/values/strings.xml | 2 + src/org/linphone/ContactPickerActivity.java | 57 ++++++++++ src/org/linphone/DialerActivity.java | 113 +++++++++++++++++++ src/org/linphone/Linphone.java | 118 +++++++------------- 7 files changed, 282 insertions(+), 114 deletions(-) create mode 100644 res/layout/dialer.xml create mode 100644 src/org/linphone/ContactPickerActivity.java create mode 100644 src/org/linphone/DialerActivity.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 6d4730203..755e9b0f6 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -16,9 +16,20 @@ - + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/dialer.xml b/res/layout/dialer.xml new file mode 100644 index 000000000..51da56e53 --- /dev/null +++ b/res/layout/dialer.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/layout/main.xml b/res/layout/main.xml index 51da56e53..1d0e21b7d 100644 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -1,38 +1,21 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="fill_parent"> + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 250dc8b7e..3c661852a 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -11,4 +11,6 @@ Enter a user name Enter a password Enter a domain +Dialer +Contact diff --git a/src/org/linphone/ContactPickerActivity.java b/src/org/linphone/ContactPickerActivity.java new file mode 100644 index 000000000..a20342c84 --- /dev/null +++ b/src/org/linphone/ContactPickerActivity.java @@ -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); + } + } +} diff --git a/src/org/linphone/DialerActivity.java b/src/org/linphone/DialerActivity.java new file mode 100644 index 000000000..6dfa95932 --- /dev/null +++ b/src/org/linphone/DialerActivity.java @@ -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); + } + + } + +} diff --git a/src/org/linphone/Linphone.java b/src/org/linphone/Linphone.java index 8a79f54dd..4bd7da127 100644 --- a/src/org/linphone/Linphone.java +++ b/src/org/linphone/Linphone.java @@ -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; + } } \ No newline at end of file