+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.svn/pristine/08/08ff16b157a13ef87c307eb415a5ec84dc171674.svn-base b/.svn/pristine/08/08ff16b157a13ef87c307eb415a5ec84dc171674.svn-base
new file mode 100644
index 0000000..2fd4aa0
Binary files /dev/null and b/.svn/pristine/08/08ff16b157a13ef87c307eb415a5ec84dc171674.svn-base differ
diff --git a/.svn/pristine/0e/0e3fab556ab6fa51b8feffc9de483803294984bc.svn-base b/.svn/pristine/0e/0e3fab556ab6fa51b8feffc9de483803294984bc.svn-base
new file mode 100644
index 0000000..cbb07a2
Binary files /dev/null and b/.svn/pristine/0e/0e3fab556ab6fa51b8feffc9de483803294984bc.svn-base differ
diff --git a/.svn/pristine/2e/2e7d8b3ed39531e245b37a0028e060e7b56090cf.svn-base b/.svn/pristine/2e/2e7d8b3ed39531e245b37a0028e060e7b56090cf.svn-base
new file mode 100644
index 0000000..534dd68
Binary files /dev/null and b/.svn/pristine/2e/2e7d8b3ed39531e245b37a0028e060e7b56090cf.svn-base differ
diff --git a/.svn/pristine/37/3758d0f7048beec99cd6b2a6f648da2381f6f46b.svn-base b/.svn/pristine/37/3758d0f7048beec99cd6b2a6f648da2381f6f46b.svn-base
new file mode 100644
index 0000000..4fc0faf
Binary files /dev/null and b/.svn/pristine/37/3758d0f7048beec99cd6b2a6f648da2381f6f46b.svn-base differ
diff --git a/.svn/pristine/37/37baec7b524d5e5497a4cdf69f5e73f70f156fd1.svn-base b/.svn/pristine/37/37baec7b524d5e5497a4cdf69f5e73f70f156fd1.svn-base
new file mode 100644
index 0000000..0d5175c
--- /dev/null
+++ b/.svn/pristine/37/37baec7b524d5e5497a4cdf69f5e73f70f156fd1.svn-base
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.svn/pristine/3a/3a2b0e4618a40bfb0e9ef4ca224ca3850c2b4356.svn-base b/.svn/pristine/3a/3a2b0e4618a40bfb0e9ef4ca224ca3850c2b4356.svn-base
new file mode 100644
index 0000000..db0112b
--- /dev/null
+++ b/.svn/pristine/3a/3a2b0e4618a40bfb0e9ef4ca224ca3850c2b4356.svn-base
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/.svn/pristine/3e/3e2dd0148436b18eb35a858bd9bf8c160544cbcc.svn-base b/.svn/pristine/3e/3e2dd0148436b18eb35a858bd9bf8c160544cbcc.svn-base
new file mode 100644
index 0000000..8fe18c5
--- /dev/null
+++ b/.svn/pristine/3e/3e2dd0148436b18eb35a858bd9bf8c160544cbcc.svn-base
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
diff --git a/.svn/pristine/43/435552f6f42cbe5209e6f981b0174db512f0b822.svn-base b/.svn/pristine/43/435552f6f42cbe5209e6f981b0174db512f0b822.svn-base
new file mode 100644
index 0000000..0591501
Binary files /dev/null and b/.svn/pristine/43/435552f6f42cbe5209e6f981b0174db512f0b822.svn-base differ
diff --git a/.svn/pristine/46/462f1fc4cf268c8c42bad38ff3259d72b95f294d.svn-base b/.svn/pristine/46/462f1fc4cf268c8c42bad38ff3259d72b95f294d.svn-base
new file mode 100644
index 0000000..8708bb6
Binary files /dev/null and b/.svn/pristine/46/462f1fc4cf268c8c42bad38ff3259d72b95f294d.svn-base differ
diff --git a/.svn/pristine/49/495c027ed046563e0e5202cae7042c07f3b18985.svn-base b/.svn/pristine/49/495c027ed046563e0e5202cae7042c07f3b18985.svn-base
new file mode 100644
index 0000000..7c62b52
--- /dev/null
+++ b/.svn/pristine/49/495c027ed046563e0e5202cae7042c07f3b18985.svn-base
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/.svn/pristine/4d/4dc5cd7f28f14dfa82af4e7846c17bc3e51cf917.svn-base b/.svn/pristine/4d/4dc5cd7f28f14dfa82af4e7846c17bc3e51cf917.svn-base
new file mode 100644
index 0000000..d407271
Binary files /dev/null and b/.svn/pristine/4d/4dc5cd7f28f14dfa82af4e7846c17bc3e51cf917.svn-base differ
diff --git a/.svn/pristine/50/5004c007d4bd4322454ca806f9ed5920aa713687.svn-base b/.svn/pristine/50/5004c007d4bd4322454ca806f9ed5920aa713687.svn-base
new file mode 100644
index 0000000..4f3020f
Binary files /dev/null and b/.svn/pristine/50/5004c007d4bd4322454ca806f9ed5920aa713687.svn-base differ
diff --git a/.svn/pristine/51/5109083fef635bc94bc638bf8e02233d80450f9e.svn-base b/.svn/pristine/51/5109083fef635bc94bc638bf8e02233d80450f9e.svn-base
new file mode 100644
index 0000000..0f6e0b5
--- /dev/null
+++ b/.svn/pristine/51/5109083fef635bc94bc638bf8e02233d80450f9e.svn-base
@@ -0,0 +1 @@
+ContactManager
\ No newline at end of file
diff --git a/.svn/pristine/56/563fea87193c89cf05134fe44fa137be0449e261.svn-base b/.svn/pristine/56/563fea87193c89cf05134fe44fa137be0449e261.svn-base
new file mode 100644
index 0000000..882eb14
Binary files /dev/null and b/.svn/pristine/56/563fea87193c89cf05134fe44fa137be0449e261.svn-base differ
diff --git a/.svn/pristine/5d/5df49e7a8c8ecf11e78651658157fb60f7139ea1.svn-base b/.svn/pristine/5d/5df49e7a8c8ecf11e78651658157fb60f7139ea1.svn-base
new file mode 100644
index 0000000..d2d96f2
--- /dev/null
+++ b/.svn/pristine/5d/5df49e7a8c8ecf11e78651658157fb60f7139ea1.svn-base
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/.svn/pristine/6a/6a5c56ceb8e199a647a6b54973a4e8af04ccdc3a.svn-base b/.svn/pristine/6a/6a5c56ceb8e199a647a6b54973a4e8af04ccdc3a.svn-base
new file mode 100644
index 0000000..f7c9dab
Binary files /dev/null and b/.svn/pristine/6a/6a5c56ceb8e199a647a6b54973a4e8af04ccdc3a.svn-base differ
diff --git a/.svn/pristine/6e/6e443b2222559b13d5cc22028fc6c1d94a497377.svn-base b/.svn/pristine/6e/6e443b2222559b13d5cc22028fc6c1d94a497377.svn-base
new file mode 100644
index 0000000..85f0c77
Binary files /dev/null and b/.svn/pristine/6e/6e443b2222559b13d5cc22028fc6c1d94a497377.svn-base differ
diff --git a/.svn/pristine/71/71240041115d1920a4f8f20d1eb61a9442b8bc25.svn-base b/.svn/pristine/71/71240041115d1920a4f8f20d1eb61a9442b8bc25.svn-base
new file mode 100644
index 0000000..c7a65b4
--- /dev/null
+++ b/.svn/pristine/71/71240041115d1920a4f8f20d1eb61a9442b8bc25.svn-base
@@ -0,0 +1,33 @@
+
+
+
+
+ Account
+ Add Contact
+ Add Contact
+ All Accounts
+ Contact Manager
+ Contact creation failed, check logs.
+ Contact Email
+ Contact Name
+ Contact Phone
+ Save
+ Select
+ Select label
+ Show Invisible Contacts (Only)
+ Target Account
+ (Undefined)
+
diff --git a/.svn/pristine/73/73c51b4e53b06c6881ea5165eb29278a993c07a4.svn-base b/.svn/pristine/73/73c51b4e53b06c6881ea5165eb29278a993c07a4.svn-base
new file mode 100644
index 0000000..01e8c07
--- /dev/null
+++ b/.svn/pristine/73/73c51b4e53b06c6881ea5165eb29278a993c07a4.svn-base
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.svn/pristine/76/76f91a118c25d2b372dac0205655780dc3e4dff6.svn-base b/.svn/pristine/76/76f91a118c25d2b372dac0205655780dc3e4dff6.svn-base
new file mode 100644
index 0000000..92c29f8
--- /dev/null
+++ b/.svn/pristine/76/76f91a118c25d2b372dac0205655780dc3e4dff6.svn-base
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.contactmanager;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.ContactsContract;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.CompoundButton.OnCheckedChangeListener;
+import android.widget.ListView;
+import android.widget.SimpleCursorAdapter;
+
+public final class ContactManager extends Activity
+{
+
+ public static final String TAG = "ContactManager";
+
+ private Button mAddAccountButton;
+ private ListView mContactList;
+ private boolean mShowInvisible;
+ private CheckBox mShowInvisibleControl;
+
+ /**
+ * Called when the activity is first created. Responsible for initializing the UI.
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ Log.v(TAG, "Activity State: onCreate()");
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.contact_manager);
+
+ // Obtain handles to UI objects
+ mAddAccountButton = (Button) findViewById(R.id.addContactButton);
+ mContactList = (ListView) findViewById(R.id.contactList);
+ mShowInvisibleControl = (CheckBox) findViewById(R.id.showInvisible);
+
+ // Initialize class properties
+ mShowInvisible = false;
+ mShowInvisibleControl.setChecked(mShowInvisible);
+
+ // Register handler for UI elements
+ mAddAccountButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ Log.d(TAG, "mAddAccountButton clicked");
+ launchContactAdder();
+ }
+ });
+ mShowInvisibleControl.setOnCheckedChangeListener(new OnCheckedChangeListener() {
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ Log.d(TAG, "mShowInvisibleControl changed: " + isChecked);
+ mShowInvisible = isChecked;
+ populateContactList();
+ }
+ });
+
+ // Populate the contact list
+ populateContactList();
+ }
+
+ /**
+ * Populate the contact list based on account currently selected in the account spinner.
+ */
+ private void populateContactList() {
+ // Build adapter with contact entries
+ Cursor cursor = getContacts();
+ String[] fields = new String[] {
+ ContactsContract.Data.DISPLAY_NAME
+ };
+ SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contact_entry, cursor,
+ fields, new int[] {R.id.contactEntryText});
+ mContactList.setAdapter(adapter);
+ }
+
+ /**
+ * Obtains the contact list for the currently selected account.
+ *
+ * @return A cursor for for accessing the contact list.
+ */
+ private Cursor getContacts()
+ {
+ // Run query
+ Uri uri = ContactsContract.Contacts.CONTENT_URI;
+ String[] projection = new String[] {
+ ContactsContract.Contacts._ID,
+ ContactsContract.Contacts.DISPLAY_NAME
+ };
+ String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" +
+ (mShowInvisible ? "0" : "1") + "'";
+ String[] selectionArgs = null;
+ String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
+
+ return managedQuery(uri, projection, selection, selectionArgs, sortOrder);
+ }
+
+ /**
+ * Launches the ContactAdder activity to add a new contact to the selected accont.
+ */
+ protected void launchContactAdder() {
+ Intent i = new Intent(this, ContactAdder.class);
+ startActivity(i);
+ }
+}
diff --git a/.svn/pristine/7c/7cbb0a80689da95c9758ccbb9b8632edc6630476.svn-base b/.svn/pristine/7c/7cbb0a80689da95c9758ccbb9b8632edc6630476.svn-base
new file mode 100644
index 0000000..a07c69f
Binary files /dev/null and b/.svn/pristine/7c/7cbb0a80689da95c9758ccbb9b8632edc6630476.svn-base differ
diff --git a/.svn/pristine/7d/7d7532163543a55e0db0f51804aeaaa505b89e75.svn-base b/.svn/pristine/7d/7d7532163543a55e0db0f51804aeaaa505b89e75.svn-base
new file mode 100644
index 0000000..9a4e197
--- /dev/null
+++ b/.svn/pristine/7d/7d7532163543a55e0db0f51804aeaaa505b89e75.svn-base
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
diff --git a/.svn/pristine/7e/7e57c710103595a80d9383152fe7bbb5b724e8ee.svn-base b/.svn/pristine/7e/7e57c710103595a80d9383152fe7bbb5b724e8ee.svn-base
new file mode 100644
index 0000000..7f4e211
--- /dev/null
+++ b/.svn/pristine/7e/7e57c710103595a80d9383152fe7bbb5b724e8ee.svn-base
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ http://www.w3.org/1999/xhtml
+
+
+
+
+
+
+
diff --git a/.svn/pristine/85/851ab337ebe980e360378ba1dfa6a6351eb551bc.svn-base b/.svn/pristine/85/851ab337ebe980e360378ba1dfa6a6351eb551bc.svn-base
new file mode 100644
index 0000000..0e7e802
Binary files /dev/null and b/.svn/pristine/85/851ab337ebe980e360378ba1dfa6a6351eb551bc.svn-base differ
diff --git a/.svn/pristine/8b/8bbbf16a8b28892fbd1f3281ed9808b1731844b6.svn-base b/.svn/pristine/8b/8bbbf16a8b28892fbd1f3281ed9808b1731844b6.svn-base
new file mode 100644
index 0000000..18689f6
Binary files /dev/null and b/.svn/pristine/8b/8bbbf16a8b28892fbd1f3281ed9808b1731844b6.svn-base differ
diff --git a/.svn/pristine/8c/8ca339cc6cff7f96a4ee2e6d53bdece6669fa43f.svn-base b/.svn/pristine/8c/8ca339cc6cff7f96a4ee2e6d53bdece6669fa43f.svn-base
new file mode 100644
index 0000000..267dcb6
Binary files /dev/null and b/.svn/pristine/8c/8ca339cc6cff7f96a4ee2e6d53bdece6669fa43f.svn-base differ
diff --git a/.svn/pristine/91/91c0eed42bb6ffbb3e720f4309d06edaa5ab81b1.svn-base b/.svn/pristine/91/91c0eed42bb6ffbb3e720f4309d06edaa5ab81b1.svn-base
new file mode 100644
index 0000000..8074c4c
Binary files /dev/null and b/.svn/pristine/91/91c0eed42bb6ffbb3e720f4309d06edaa5ab81b1.svn-base differ
diff --git a/.svn/pristine/91/91d88622a6df7c21ff026322899023f17a3040b0.svn-base b/.svn/pristine/91/91d88622a6df7c21ff026322899023f17a3040b0.svn-base
new file mode 100644
index 0000000..1275f59
Binary files /dev/null and b/.svn/pristine/91/91d88622a6df7c21ff026322899023f17a3040b0.svn-base differ
diff --git a/.svn/pristine/91/91f3fdc057bca0ffad3258c6a0c8287d1472570c.svn-base b/.svn/pristine/91/91f3fdc057bca0ffad3258c6a0c8287d1472570c.svn-base
new file mode 100644
index 0000000..c80ba20
Binary files /dev/null and b/.svn/pristine/91/91f3fdc057bca0ffad3258c6a0c8287d1472570c.svn-base differ
diff --git a/.svn/pristine/a3/a3184c1ff880c2b0926f70b714f989cfd90caca6.svn-base b/.svn/pristine/a3/a3184c1ff880c2b0926f70b714f989cfd90caca6.svn-base
new file mode 100644
index 0000000..b385f01
--- /dev/null
+++ b/.svn/pristine/a3/a3184c1ff880c2b0926f70b714f989cfd90caca6.svn-base
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.svn/pristine/a9/a9eca4ce5d432b06bbf0d6bf8c8a21eeee74af09.svn-base b/.svn/pristine/a9/a9eca4ce5d432b06bbf0d6bf8c8a21eeee74af09.svn-base
new file mode 100644
index 0000000..eb49704
--- /dev/null
+++ b/.svn/pristine/a9/a9eca4ce5d432b06bbf0d6bf8c8a21eeee74af09.svn-base
@@ -0,0 +1,55 @@
+/* AUTO-GENERATED FILE. DO NOT MODIFY.
+ *
+ * This class was automatically generated by the
+ * aapt tool from the resource data it found. It
+ * should not be modified by hand.
+ */
+
+package com.example.android.contactmanager;
+
+public final class R {
+ public static final class attr {
+ }
+ public static final class drawable {
+ public static final int icon=0x7f020000;
+ }
+ public static final class id {
+ public static final int accountIcon=0x7f050000;
+ public static final int accountSpinner=0x7f050003;
+ public static final int addContactButton=0x7f05000d;
+ public static final int contactEmailEditText=0x7f050007;
+ public static final int contactEmailTypeSpinner=0x7f050008;
+ public static final int contactEntryText=0x7f05000a;
+ public static final int contactList=0x7f05000b;
+ public static final int contactNameEditText=0x7f050004;
+ public static final int contactPhoneEditText=0x7f050005;
+ public static final int contactPhoneTypeSpinner=0x7f050006;
+ public static final int contactSaveButton=0x7f050009;
+ public static final int firstAccountLine=0x7f050002;
+ public static final int secondAccountLine=0x7f050001;
+ public static final int showInvisible=0x7f05000c;
+ }
+ public static final class layout {
+ public static final int account_entry=0x7f030000;
+ public static final int contact_adder=0x7f030001;
+ public static final int contact_entry=0x7f030002;
+ public static final int contact_manager=0x7f030003;
+ }
+ public static final class string {
+ public static final int accountSpinnerLabel=0x7f040000;
+ public static final int addContactButtonLabel=0x7f040001;
+ public static final int addContactTitle=0x7f040002;
+ public static final int allAccounts=0x7f040003;
+ public static final int app_name=0x7f040004;
+ public static final int contactCreationFailure=0x7f040005;
+ public static final int contactEmailLabel=0x7f040006;
+ public static final int contactNameLabel=0x7f040007;
+ public static final int contactPhoneLabel=0x7f040008;
+ public static final int save=0x7f040009;
+ public static final int selectAccountLabel=0x7f04000a;
+ public static final int selectLabel=0x7f04000b;
+ public static final int showInvisible=0x7f04000c;
+ public static final int targetAccountLabel=0x7f04000d;
+ public static final int undefinedTypeLabel=0x7f04000e;
+ }
+}
diff --git a/.svn/pristine/ab/ab32b734e537300732d838a361a782bbd0afbc31.svn-base b/.svn/pristine/ab/ab32b734e537300732d838a361a782bbd0afbc31.svn-base
new file mode 100644
index 0000000..ae60713
Binary files /dev/null and b/.svn/pristine/ab/ab32b734e537300732d838a361a782bbd0afbc31.svn-base differ
diff --git a/.svn/pristine/bb/bb9fcc4cc6918a9e252c82def593b80f8054d76b.svn-base b/.svn/pristine/bb/bb9fcc4cc6918a9e252c82def593b80f8054d76b.svn-base
new file mode 100644
index 0000000..3adeaab
--- /dev/null
+++ b/.svn/pristine/bb/bb9fcc4cc6918a9e252c82def593b80f8054d76b.svn-base
@@ -0,0 +1,390 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.contactmanager;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.accounts.AuthenticatorDescription;
+import android.accounts.OnAccountsUpdateListener;
+import android.app.Activity;
+import android.content.ContentProviderOperation;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.provider.ContactsContract;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.Spinner;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.widget.AdapterView.OnItemSelectedListener;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+public final class ContactAdder extends Activity implements OnAccountsUpdateListener
+{
+ public static final String TAG = "ContactsAdder";
+ public static final String ACCOUNT_NAME =
+ "com.example.android.contactmanager.ContactsAdder.ACCOUNT_NAME";
+ public static final String ACCOUNT_TYPE =
+ "com.example.android.contactmanager.ContactsAdder.ACCOUNT_TYPE";
+
+ private ArrayList mAccounts;
+ private AccountAdapter mAccountAdapter;
+ private Spinner mAccountSpinner;
+ private EditText mContactEmailEditText;
+ private ArrayList mContactEmailTypes;
+ private Spinner mContactEmailTypeSpinner;
+ private EditText mContactNameEditText;
+ private EditText mContactPhoneEditText;
+ private ArrayList mContactPhoneTypes;
+ private Spinner mContactPhoneTypeSpinner;
+ private Button mContactSaveButton;
+ private AccountData mSelectedAccount;
+
+ /**
+ * Called when the activity is first created. Responsible for initializing the UI.
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ Log.v(TAG, "Activity State: onCreate()");
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.contact_adder);
+
+ // Obtain handles to UI objects
+ mAccountSpinner = (Spinner) findViewById(R.id.accountSpinner);
+ mContactNameEditText = (EditText) findViewById(R.id.contactNameEditText);
+ mContactPhoneEditText = (EditText) findViewById(R.id.contactPhoneEditText);
+ mContactEmailEditText = (EditText) findViewById(R.id.contactEmailEditText);
+ mContactPhoneTypeSpinner = (Spinner) findViewById(R.id.contactPhoneTypeSpinner);
+ mContactEmailTypeSpinner = (Spinner) findViewById(R.id.contactEmailTypeSpinner);
+ mContactSaveButton = (Button) findViewById(R.id.contactSaveButton);
+
+ // Prepare list of supported account types
+ // Note: Other types are available in ContactsContract.CommonDataKinds
+ // Also, be aware that type IDs differ between Phone and Email, and MUST be computed
+ // separately.
+ mContactPhoneTypes = new ArrayList();
+ mContactPhoneTypes.add(ContactsContract.CommonDataKinds.Phone.TYPE_HOME);
+ mContactPhoneTypes.add(ContactsContract.CommonDataKinds.Phone.TYPE_WORK);
+ mContactPhoneTypes.add(ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE);
+ mContactPhoneTypes.add(ContactsContract.CommonDataKinds.Phone.TYPE_OTHER);
+ mContactEmailTypes = new ArrayList();
+ mContactEmailTypes.add(ContactsContract.CommonDataKinds.Email.TYPE_HOME);
+ mContactEmailTypes.add(ContactsContract.CommonDataKinds.Email.TYPE_WORK);
+ mContactEmailTypes.add(ContactsContract.CommonDataKinds.Email.TYPE_MOBILE);
+ mContactEmailTypes.add(ContactsContract.CommonDataKinds.Email.TYPE_OTHER);
+
+ // Prepare model for account spinner
+ mAccounts = new ArrayList();
+ mAccountAdapter = new AccountAdapter(this, mAccounts);
+ mAccountSpinner.setAdapter(mAccountAdapter);
+
+ // Populate list of account types for phone
+ ArrayAdapter adapter;
+ adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item);
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ Iterator iter;
+ iter = mContactPhoneTypes.iterator();
+ while (iter.hasNext()) {
+ adapter.add(ContactsContract.CommonDataKinds.Phone.getTypeLabel(
+ this.getResources(),
+ iter.next(),
+ getString(R.string.undefinedTypeLabel)).toString());
+ }
+ mContactPhoneTypeSpinner.setAdapter(adapter);
+ mContactPhoneTypeSpinner.setPrompt(getString(R.string.selectLabel));
+
+ // Populate list of account types for email
+ adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item);
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ iter = mContactEmailTypes.iterator();
+ while (iter.hasNext()) {
+ adapter.add(ContactsContract.CommonDataKinds.Email.getTypeLabel(
+ this.getResources(),
+ iter.next(),
+ getString(R.string.undefinedTypeLabel)).toString());
+ }
+ mContactEmailTypeSpinner.setAdapter(adapter);
+ mContactEmailTypeSpinner.setPrompt(getString(R.string.selectLabel));
+
+ // Prepare the system account manager. On registering the listener below, we also ask for
+ // an initial callback to pre-populate the account list.
+ AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true);
+
+ // Register handlers for UI elements
+ mAccountSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
+ public void onItemSelected(AdapterView> parent, View view, int position, long i) {
+ updateAccountSelection();
+ }
+
+ public void onNothingSelected(AdapterView> parent) {
+ // We don't need to worry about nothing being selected, since Spinners don't allow
+ // this.
+ }
+ });
+ mContactSaveButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ onSaveButtonClicked();
+ }
+ });
+ }
+
+ /**
+ * Actions for when the Save button is clicked. Creates a contact entry and terminates the
+ * activity.
+ */
+ private void onSaveButtonClicked() {
+ Log.v(TAG, "Save button clicked");
+ createContactEntry();
+ finish();
+ }
+
+ /**
+ * Creates a contact entry from the current UI values in the account named by mSelectedAccount.
+ */
+ protected void createContactEntry() {
+ // Get values from UI
+ String name = mContactNameEditText.getText().toString();
+ String phone = mContactPhoneEditText.getText().toString();
+ String email = mContactEmailEditText.getText().toString();
+ int phoneType = mContactPhoneTypes.get(
+ mContactPhoneTypeSpinner.getSelectedItemPosition());
+ int emailType = mContactEmailTypes.get(
+ mContactEmailTypeSpinner.getSelectedItemPosition());;
+
+ // Prepare contact creation request
+ //
+ // Note: We use RawContacts because this data must be associated with a particular account.
+ // The system will aggregate this with any other data for this contact and create a
+ // coresponding entry in the ContactsContract.Contacts provider for us.
+ ArrayList ops = new ArrayList();
+ ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
+ .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, mSelectedAccount.getType())
+ .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, mSelectedAccount.getName())
+ .build());
+ ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
+ .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
+ .withValue(ContactsContract.Data.MIMETYPE,
+ ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
+ .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name)
+ .build());
+ ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
+ .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
+ .withValue(ContactsContract.Data.MIMETYPE,
+ ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
+ .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phone)
+ .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, phoneType)
+ .build());
+ ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
+ .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
+ .withValue(ContactsContract.Data.MIMETYPE,
+ ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
+ .withValue(ContactsContract.CommonDataKinds.Email.DATA, email)
+ .withValue(ContactsContract.CommonDataKinds.Email.TYPE, emailType)
+ .build());
+
+ // Ask the Contact provider to create a new contact
+ Log.i(TAG,"Selected account: " + mSelectedAccount.getName() + " (" +
+ mSelectedAccount.getType() + ")");
+ Log.i(TAG,"Creating contact: " + name);
+ try {
+ getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
+ } catch (Exception e) {
+ // Display warning
+ Context ctx = getApplicationContext();
+ CharSequence txt = getString(R.string.contactCreationFailure);
+ int duration = Toast.LENGTH_SHORT;
+ Toast toast = Toast.makeText(ctx, txt, duration);
+ toast.show();
+
+ // Log exception
+ Log.e(TAG, "Exceptoin encoutered while inserting contact: " + e);
+ }
+ }
+
+ /**
+ * Called when this activity is about to be destroyed by the system.
+ */
+ @Override
+ public void onDestroy() {
+ // Remove AccountManager callback
+ AccountManager.get(this).removeOnAccountsUpdatedListener(this);
+ super.onDestroy();
+ }
+
+ /**
+ * Updates account list spinner when the list of Accounts on the system changes. Satisfies
+ * OnAccountsUpdateListener implementation.
+ */
+ public void onAccountsUpdated(Account[] a) {
+ Log.i(TAG, "Account list update detected");
+ // Clear out any old data to prevent duplicates
+ mAccounts.clear();
+
+ // Get account data from system
+ AuthenticatorDescription[] accountTypes = AccountManager.get(this).getAuthenticatorTypes();
+
+ // Populate tables
+ for (int i = 0; i < a.length; i++) {
+ // The user may have multiple accounts with the same name, so we need to construct a
+ // meaningful display name for each.
+ String systemAccountType = a[i].type;
+ AuthenticatorDescription ad = getAuthenticatorDescription(systemAccountType,
+ accountTypes);
+ AccountData data = new AccountData(a[i].name, ad);
+ mAccounts.add(data);
+ }
+
+ // Update the account spinner
+ mAccountAdapter.notifyDataSetChanged();
+ }
+
+ /**
+ * Obtain the AuthenticatorDescription for a given account type.
+ * @param type The account type to locate.
+ * @param dictionary An array of AuthenticatorDescriptions, as returned by AccountManager.
+ * @return The description for the specified account type.
+ */
+ private static AuthenticatorDescription getAuthenticatorDescription(String type,
+ AuthenticatorDescription[] dictionary) {
+ for (int i = 0; i < dictionary.length; i++) {
+ if (dictionary[i].type.equals(type)) {
+ return dictionary[i];
+ }
+ }
+ // No match found
+ throw new RuntimeException("Unable to find matching authenticator");
+ }
+
+ /**
+ * Update account selection. If NO_ACCOUNT is selected, then we prohibit inserting new contacts.
+ */
+ private void updateAccountSelection() {
+ // Read current account selection
+ mSelectedAccount = (AccountData) mAccountSpinner.getSelectedItem();
+ }
+
+ /**
+ * A container class used to repreresent all known information about an account.
+ */
+ private class AccountData {
+ private String mName;
+ private String mType;
+ private CharSequence mTypeLabel;
+ private Drawable mIcon;
+
+ /**
+ * @param name The name of the account. This is usually the user's email address or
+ * username.
+ * @param description The description for this account. This will be dictated by the
+ * type of account returned, and can be obtained from the system AccountManager.
+ */
+ public AccountData(String name, AuthenticatorDescription description) {
+ mName = name;
+ if (description != null) {
+ mType = description.type;
+
+ // The type string is stored in a resource, so we need to convert it into something
+ // human readable.
+ String packageName = description.packageName;
+ PackageManager pm = getPackageManager();
+
+ if (description.labelId != 0) {
+ mTypeLabel = pm.getText(packageName, description.labelId, null);
+ if (mTypeLabel == null) {
+ throw new IllegalArgumentException("LabelID provided, but label not found");
+ }
+ } else {
+ mTypeLabel = "";
+ }
+
+ if (description.iconId != 0) {
+ mIcon = pm.getDrawable(packageName, description.iconId, null);
+ if (mIcon == null) {
+ throw new IllegalArgumentException("IconID provided, but drawable not " +
+ "found");
+ }
+ } else {
+ mIcon = getResources().getDrawable(android.R.drawable.sym_def_app_icon);
+ }
+ }
+ }
+
+ public String getName() {
+ return mName;
+ }
+
+ public String getType() {
+ return mType;
+ }
+
+ public CharSequence getTypeLabel() {
+ return mTypeLabel;
+ }
+
+ public Drawable getIcon() {
+ return mIcon;
+ }
+
+ public String toString() {
+ return mName;
+ }
+ }
+
+ /**
+ * Custom adapter used to display account icons and descriptions in the account spinner.
+ */
+ private class AccountAdapter extends ArrayAdapter {
+ public AccountAdapter(Context context, ArrayList accountData) {
+ super(context, android.R.layout.simple_spinner_item, accountData);
+ setDropDownViewResource(R.layout.account_entry);
+ }
+
+ public View getDropDownView(int position, View convertView, ViewGroup parent) {
+ // Inflate a view template
+ if (convertView == null) {
+ LayoutInflater layoutInflater = getLayoutInflater();
+ convertView = layoutInflater.inflate(R.layout.account_entry, parent, false);
+ }
+ TextView firstAccountLine = (TextView) convertView.findViewById(R.id.firstAccountLine);
+ TextView secondAccountLine = (TextView) convertView.findViewById(R.id.secondAccountLine);
+ ImageView accountIcon = (ImageView) convertView.findViewById(R.id.accountIcon);
+
+ // Populate template
+ AccountData data = getItem(position);
+ firstAccountLine.setText(data.getName());
+ secondAccountLine.setText(data.getTypeLabel());
+ Drawable icon = data.getIcon();
+ if (icon == null) {
+ icon = getResources().getDrawable(android.R.drawable.ic_menu_search);
+ }
+ accountIcon.setImageDrawable(icon);
+ return convertView;
+ }
+ }
+}
diff --git a/.svn/pristine/d7/d7c6173f3c8989b05b8522328e5b5f204d6d89eb.svn-base b/.svn/pristine/d7/d7c6173f3c8989b05b8522328e5b5f204d6d89eb.svn-base
new file mode 100644
index 0000000..3eaf474
--- /dev/null
+++ b/.svn/pristine/d7/d7c6173f3c8989b05b8522328e5b5f204d6d89eb.svn-base
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/.svn/pristine/da/dab9122f41b8f635738ab44b288f12412bbdf3ce.svn-base b/.svn/pristine/da/dab9122f41b8f635738ab44b288f12412bbdf3ce.svn-base
new file mode 100644
index 0000000..1095584
Binary files /dev/null and b/.svn/pristine/da/dab9122f41b8f635738ab44b288f12412bbdf3ce.svn-base differ
diff --git a/.svn/pristine/e4/e4c41a40ff72f397e0d8610df1609d83acd74200.svn-base b/.svn/pristine/e4/e4c41a40ff72f397e0d8610df1609d83acd74200.svn-base
new file mode 100644
index 0000000..f00625d
--- /dev/null
+++ b/.svn/pristine/e4/e4c41a40ff72f397e0d8610df1609d83acd74200.svn-base
@@ -0,0 +1,732 @@
+
+
+
+