Initial cut of Contact Options UI.
diff --git a/src/com/android/contacts/ContactOptionsActivity.java b/src/com/android/contacts/ContactOptionsActivity.java
new file mode 100644
index 0000000..83b1062
--- /dev/null
+++ b/src/com/android/contacts/ContactOptionsActivity.java
@@ -0,0 +1,202 @@
+/*
+ * 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.android.contacts;
+
+import android.app.Activity;
+import android.content.ContentValues;
+import android.content.Intent;
+import android.database.Cursor;
+import android.media.Ringtone;
+import android.media.RingtoneManager;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.ContactsContract.Aggregates;
+import android.util.Log;
+import android.view.View;
+import android.widget.CheckBox;
+import android.widget.TextView;
+
+/**
+ * An activity for selecting options for a given contact: custom ringtone and send-to-voicemail.
+ */
+public class ContactOptionsActivity extends Activity implements View.OnClickListener {
+
+    private static final String TAG = "ContactOptionsActivity";
+
+    private static final String[] AGGREGATES_PROJECTION = new String[] {
+            Aggregates.CUSTOM_RINGTONE, Aggregates.SEND_TO_VOICEMAIL
+    };
+
+    private static final int COL_CUSTOM_RINGTONE = 0;
+    private static final int COL_SEND_TO_VOICEMAIL = 1;
+
+    /** The launch code when picking a ringtone */
+    private static final int RINGTONE_PICKED = 3023;
+
+    private String mCustomRingtone;
+    private boolean mSendToVoicemail;
+    private TextView mRingtoneTitle;
+    private CheckBox mSendToVoicemailCheckbox;
+
+    private Uri mAggregateUri;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        mAggregateUri = getIntent().getData();
+
+        setContentView(R.layout.contact_options);
+
+        View ringtoneLayout = findViewById(R.id.ringtone);
+        ringtoneLayout.setOnClickListener(this);
+        TextView label = (TextView)findViewById(R.id.label);
+        label.setText(getString(R.string.label_ringtone));
+
+        mRingtoneTitle = (TextView)ringtoneLayout.findViewById(R.id.data);
+
+        View sendToVoicemailLayout = findViewById(R.id.voicemail);
+        sendToVoicemailLayout.setOnClickListener(this);
+        label = (TextView)sendToVoicemailLayout.findViewById(R.id.label);
+        label.setText(getString(R.string.actionIncomingCall));
+
+        mSendToVoicemailCheckbox = (CheckBox)sendToVoicemailLayout.findViewById(R.id.checkbox);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+
+        if (!loadData()) {
+            finish();
+        }
+
+        updateView();
+    }
+
+    private void updateView() {
+        if (mCustomRingtone == null) {
+            mRingtoneTitle.setText(getString(R.string.default_ringtone));
+        } else {
+            Uri ringtoneUri = Uri.parse(mCustomRingtone);
+            Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri);
+            if (ringtone == null) {
+                Log.w(TAG, "ringtone's URI doesn't resolve to a Ringtone");
+                return;
+            }
+            mRingtoneTitle.setText(ringtone.getTitle(this));
+        }
+
+        mSendToVoicemailCheckbox.setChecked(mSendToVoicemail);
+    }
+
+    public void onClick(View v) {
+        switch (v.getId()) {
+            case R.id.ringtone: {
+                doPickRingtone();
+                break;
+            }
+            case R.id.voicemail: {
+                doToggleSendToVoicemail();
+                break;
+            }
+        }
+    }
+
+    private void doPickRingtone() {
+
+        Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
+        // Allow user to pick 'Default'
+        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
+        // Show only ringtones
+        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
+        // Don't show 'Silent'
+        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
+
+        Uri ringtoneUri;
+        if (mCustomRingtone != null) {
+            ringtoneUri = Uri.parse(mCustomRingtone);
+        } else {
+            // Otherwise pick default ringtone Uri so that something is selected.
+            ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
+        }
+
+        // Put checkmark next to the current ringtone for this contact
+        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtoneUri);
+
+        // Launch!
+        startActivityForResult(intent, RINGTONE_PICKED);
+    }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        if (resultCode != RESULT_OK) {
+            return;
+        }
+
+        switch (requestCode) {
+            case RINGTONE_PICKED: {
+                Uri pickedUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
+                handleRingtonePicked(pickedUri);
+                break;
+            }
+        }
+    }
+
+    private void handleRingtonePicked(Uri pickedUri) {
+        if (pickedUri == null || RingtoneManager.isDefault(pickedUri)) {
+            mCustomRingtone = null;
+        } else {
+            mCustomRingtone = pickedUri.toString();
+        }
+        saveData();
+        updateView();
+    }
+
+    private void doToggleSendToVoicemail() {
+        mSendToVoicemailCheckbox.toggle();
+        mSendToVoicemail = mSendToVoicemailCheckbox.isChecked();
+        saveData();
+        updateView();
+    }
+
+    private boolean loadData() {
+        Cursor c =
+                getContentResolver().query(mAggregateUri, AGGREGATES_PROJECTION, null, null, null);
+        try {
+            if (!c.moveToFirst()) {
+                return false;
+            }
+
+            mCustomRingtone = c.getString(COL_CUSTOM_RINGTONE);
+            mSendToVoicemail = c.getInt(COL_SEND_TO_VOICEMAIL) != 0;
+
+        } finally {
+            c.close();
+        }
+        return true;
+    }
+
+    private void saveData() {
+        ContentValues values = new ContentValues(2);
+        values.put(Aggregates.CUSTOM_RINGTONE, mCustomRingtone);
+        values.put(Aggregates.SEND_TO_VOICEMAIL, mSendToVoicemail);
+        getContentResolver().update(mAggregateUri, values, null, null);
+    }
+}
+
+
diff --git a/src/com/android/contacts/EditContactActivity.java b/src/com/android/contacts/EditContactActivity.java
index 633c180..edcb178 100644
--- a/src/com/android/contacts/EditContactActivity.java
+++ b/src/com/android/contacts/EditContactActivity.java
@@ -46,8 +46,6 @@
 import android.content.res.Resources;
 import android.database.Cursor;
 import android.graphics.Bitmap;
-import android.media.Ringtone;
-import android.media.RingtoneManager;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Parcel;
@@ -57,7 +55,6 @@
 import android.provider.ContactsContract.Aggregates;
 import android.provider.ContactsContract.CommonDataKinds;
 import android.provider.ContactsContract.CommonDataKinds.BaseTypes;
-import android.provider.ContactsContract.CommonDataKinds.CustomRingtone;
 import android.provider.ContactsContract.CommonDataKinds.Email;
 import android.provider.ContactsContract.CommonDataKinds.Im;
 import android.provider.ContactsContract.CommonDataKinds.Note;
@@ -114,9 +111,6 @@
     /** The launch code when picking a photo and the raw data is returned */
     private static final int PHOTO_PICKED_WITH_DATA = 3021;
 
-    /** The launch code when picking a ringtone */
-    private static final int RINGTONE_PICKED = 3023;
-
     // These correspond to the string array in resources for picker "other" items
     final static int OTHER_ORGANIZATION = 0;
     final static int OTHER_NOTE = 1;
@@ -248,12 +242,6 @@
             }
             */
 
-            case R.id.entry_ringtone: {
-                EditEntry entry = findEntryForView(v);
-                doPickRingtone(entry);
-                break;
-            }
-
             case R.id.separator: {
                 // Someone clicked on a section header, so handle add action
                 // TODO: Data addition is still being hashed out.
@@ -554,13 +542,6 @@
                 }
                 break;
             }
-
-            case RINGTONE_PICKED: {
-                Uri pickedUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
-                handleRingtonePicked(pickedUri);
-                mContactChanged = true;
-                break;
-            }
         }
     }
 
@@ -868,62 +849,6 @@
     }
     */
 
-    private void doPickRingtone(EditEntry entry) {
-        Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
-        // Allow user to pick 'Default'
-        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
-        // Show only ringtones
-        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
-        // Don't show 'Silent'
-        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
-
-        Uri ringtoneUri;
-        if (entry.data != null) {
-            ringtoneUri = Uri.parse(entry.data);
-        } else {
-            // Otherwise pick default ringtone Uri so that something is selected.
-            ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
-        }
-
-        // Put checkmark next to the current ringtone for this contact
-        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtoneUri);
-        // Launch!
-        startActivityForResult(intent, RINGTONE_PICKED);
-    }
-
-    private void handleRingtonePicked(Uri pickedUri) {
-        EditEntry entry = getOtherEntry(CustomRingtone.RINGTONE_URI);
-        if (entry == null) {
-            Log.w(TAG, "Ringtone picked but could not find ringtone entry");
-            return;
-        }
-
-        if (pickedUri == null || RingtoneManager.isDefault(pickedUri)) {
-            entry.data = null;
-        } else {
-            entry.data = pickedUri.toString();
-        }
-
-        updateRingtoneView(entry);
-    }
-
-    private void updateRingtoneView(EditEntry entry) {
-        String ringtoneName;
-        if (entry.data == null) {
-            ringtoneName = getString(R.string.default_ringtone);
-        } else {
-            Uri ringtoneUri = Uri.parse(entry.data);
-            Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri);
-            if (ringtone == null) {
-                Log.w(TAG, "ringtone's URI doesn't resolve to a Ringtone");
-                return;
-            }
-            ringtoneName = ringtone.getTitle(this);
-        }
-
-        updateDataView(entry, ringtoneName);
-    }
-
     private void updateDataView(EditEntry entry, String text) {
         TextView dataView = (TextView) entry.view.findViewById(R.id.data);
         dataView.setText(text);
@@ -1159,10 +1084,6 @@
                 } else {
                     /* mResolver.insert(entry.uri, values); */
                 }
-                if (!CustomRingtone.RINGTONE_URI.equals(entry.column) &&
-                        !CustomRingtone.SEND_TO_VOICEMAIL.equals(entry.column)) {
-                    numValues++;
-                }
             } else if (entry.id != 0) {
                 mResolver.delete(entry.uri, null, null);
             }
@@ -1284,10 +1205,6 @@
                     entry.uri = mResolver.insert(
                             Uri.withAppendedPath(contactUri, entry.contentDirectory), values);
                     entry.id = ContentUris.parseId(entry.uri);
-                    if (!People.CUSTOM_RINGTONE.equals(entry.column) &&
-                            !People.SEND_TO_VOICEMAIL.equals(entry.column)) {
-                        numValues++;
-                    }
                 }
             } else {
                 // Update the contact with any straggling data, like notes
@@ -1296,10 +1213,6 @@
                 if (data != null && TextUtils.isGraphic(data)) {
                     values.put(entry.column, data);
                     mResolver.update(contactUri, values, null, null);
-                    if (!People.CUSTOM_RINGTONE.equals(entry.column) &&
-                            !People.SEND_TO_VOICEMAIL.equals(entry.column)) {
-                        numValues++;
-                    }
                 }
             }
         }
@@ -1377,14 +1290,6 @@
                 entry = EditEntry.newNotesEntry(this, aggCursor.getString(DATA_1_COLUMN),
                         uri, id);
                 mNoteEntries.add(entry);
-            } else if (mimetype.equals(CommonDataKinds.CustomRingtone.CONTENT_ITEM_TYPE)) {
-                entry = EditEntry.newRingtoneEntry(this,
-                        aggCursor.getString(DATA_2_COLUMN), uri, id);
-                mOtherEntries.add(entry);
-
-                entry = EditEntry.newSendToVoicemailEntry(this,
-                        aggCursor.getString(DATA_1_COLUMN), uri, id);
-                mOtherEntries.add(entry);
             } else if (mimetype.equals(CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
                     || mimetype.equals(CommonDataKinds.Email.CONTENT_ITEM_TYPE)
                     || mimetype.equals(CommonDataKinds.Postal.CONTENT_ITEM_TYPE)
@@ -1519,14 +1424,6 @@
             entry = EditEntry.newGroupEntry(this, null, mUri, 0);
             mOtherEntries.add(entry);
         }
-
-        // Ringtone
-        entry = EditEntry.newRingtoneEntry(this, null, mUri, 0);
-        mOtherEntries.add(entry);
-
-        // Send to voicemail
-        entry = EditEntry.newSendToVoicemailEntry(this, "0", mUri, 0);
-        mOtherEntries.add(entry);
     }
 
     private void addFromExtras(Bundle extras, Uri phonesUri, Uri methodsUri) {
@@ -1782,21 +1679,12 @@
         // with some additional logic.
         if (entry.mimetype.equals(Organization.CONTENT_ITEM_TYPE)) {
             view = mInflater.inflate(R.layout.edit_contact_entry_org, parent, false);
-        }
         /*
         else if (entry.mimetype.equals(Group.CONTENT_ITEM_TYPE)) {
             view = mInflater.inflate(R.layout.edit_contact_entry_group, parent, false);
             view.setOnFocusChangeListener(this);
         }
         */
-        else if (entry.mimetype.equals(CustomRingtone.CONTENT_ITEM_TYPE)) {
-            if (entry.column.equals(CustomRingtone.RINGTONE_URI)) {
-                view = mInflater.inflate(R.layout.edit_contact_entry_ringtone, parent, false);
-                view.setOnFocusChangeListener(this);
-            } else {
-                view = mInflater.inflate(R.layout.edit_contact_entry_voicemail, parent, false);
-                view.setOnFocusChangeListener(this);
-            }
         } else if (!entry.isStaticLabel) {
             view = mInflater.inflate(R.layout.edit_contact_entry, parent, false);
         } else {
@@ -1830,7 +1718,9 @@
             data2.setText(entry.data2);
         }
         data.setHint(entry.hint);
-        if (data2 != null) data2.setHint(entry.hint2);
+        if (data2 != null) {
+            data2.setHint(entry.hint2);
+        }
         if (entry.lines > 1) {
             data.setLines(entry.lines);
             data.setMaxLines(entry.maxLines);
@@ -1877,15 +1767,14 @@
 
         // Hook up the delete button
         View delete = view.findViewById(R.id.delete);
-        if (delete != null) delete.setOnClickListener(this);
+        if (delete != null) {
+            delete.setOnClickListener(this);
+        }
 
         return view;
     }
 
     private void fillViewData(final EditEntry entry) {
-        if (isOtherEntry(entry, CustomRingtone.RINGTONE_URI)) {
-            updateRingtoneView(entry);
-        }
         /*
         else if (isOtherEntry(entry, GroupMembership.GROUP_ID)) {
             if (entry.data != null) {
@@ -1893,14 +1782,6 @@
             }
         }
         */
-        else if (isOtherEntry(entry, CustomRingtone.SEND_TO_VOICEMAIL)) {
-            CheckBox checkBox = (CheckBox) entry.view.findViewById(R.id.checkbox);
-            boolean sendToVoicemail = false;
-            if (entry.data != null) {
-                sendToVoicemail = (Integer.valueOf(entry.data) == 1);
-            }
-            checkBox.setChecked(sendToVoicemail);
-        }
     }
 
     /**
@@ -2249,42 +2130,6 @@
         */
 
         /**
-         * Create a new ringtone entry with the given data.
-         */
-        public static final EditEntry newRingtoneEntry(EditContactActivity activity,
-                String data, Uri uri, long id) {
-            EditEntry entry = new EditEntry(activity);
-            entry.label = activity.getString(R.string.label_ringtone);
-            entry.data = data;
-            entry.uri = uri;
-            entry.id = id;
-            entry.column = CustomRingtone.RINGTONE_URI;
-            entry.mimetype = CustomRingtone.CONTENT_ITEM_TYPE;
-            entry.isStaticLabel = true;
-            entry.syncDataWithView = false;
-            entry.lines = -1;
-            return entry;
-        }
-
-        /**
-         * Create a new send-to-voicemail entry with the given data.
-         */
-        public static final EditEntry newSendToVoicemailEntry(EditContactActivity activity,
-                String data, Uri uri, long id) {
-            EditEntry entry = new EditEntry(activity);
-            entry.label = activity.getString(R.string.actionIncomingCall);
-            entry.data = data;
-            entry.uri = uri;
-            entry.id = id;
-            entry.column = CustomRingtone.SEND_TO_VOICEMAIL;
-            entry.mimetype = CustomRingtone.CONTENT_ITEM_TYPE;
-            entry.isStaticLabel = true;
-            entry.syncDataWithView = false;
-            entry.lines = -1;
-            return entry;
-        }
-
-        /**
          * Create a new empty email entry
          */
         public static final EditEntry newPhoneEntry(EditContactActivity activity,
diff --git a/src/com/android/contacts/ViewContactActivity.java b/src/com/android/contacts/ViewContactActivity.java
index c6fd7eb..ae5c252 100644
--- a/src/com/android/contacts/ViewContactActivity.java
+++ b/src/com/android/contacts/ViewContactActivity.java
@@ -50,8 +50,6 @@
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.drawable.Drawable;
-import android.media.Ringtone;
-import android.media.RingtoneManager;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
@@ -102,6 +100,7 @@
     public static final int MENU_ITEM_SHOW_BARCODE = 3;
     public static final int MENU_ITEM_SPLIT_AGGREGATE = 4;
     public static final int MENU_ITEM_JOIN_AGGREGATE = 5;
+    public static final int MENU_ITEM_OPTIONS = 6;
 
     private Uri mUri;
     private Uri mAggDataUri;
@@ -308,6 +307,8 @@
                 .setIcon(android.R.drawable.ic_menu_share);
         menu.add(0, MENU_ITEM_JOIN_AGGREGATE, 0, R.string.menu_joinAggregate)
                 .setIcon(android.R.drawable.ic_menu_add);
+        menu.add(0, MENU_ITEM_OPTIONS, 0, R.string.menu_contactOptions)
+                .setIcon(R.drawable.ic_menu_mark);
         return true;
     }
 
@@ -393,6 +394,11 @@
                 return true;
             }
 
+            case MENU_ITEM_OPTIONS: {
+                showOptionsActivity();
+                return true;
+            }
+
             // TODO(emillar) Bring this back.
             /*case MENU_ITEM_SHOW_BARCODE:
                 if (mCursor.moveToFirst()) {
@@ -559,6 +565,12 @@
         mResolver.update(AggregationExceptions.CONTENT_URI, values, null, null);
     }
 
+    private void showOptionsActivity() {
+        final Intent intent = new Intent(this, ContactOptionsActivity.class);
+        intent.setData(mUri);
+        startActivity(intent);
+    }
+
     private ViewEntry getViewEntryForMenuItem(MenuItem item) {
         AdapterView.AdapterContextMenuInfo info;
         try {
@@ -834,35 +846,6 @@
                     }
 
                     mOtherEntries.add(entry);
-                // Build the ringtone and send to voicemail entries
-                } else if (mimetype.equals(CommonDataKinds.CustomRingtone.CONTENT_ITEM_TYPE)) {
-                    final Boolean sendToVoicemail = "1".equals(aggCursor.getString(DATA_1_COLUMN));
-                    final String ringtoneStr = aggCursor.getString(DATA_2_COLUMN);
-
-                    // TODO(emillar) we need to enforce uniqueness of custom ringtone entries on a
-                    // single aggregate. This could be done by checking against the reference ID stored
-                    // in the aggregate.
-
-                    // Build the send directly to voice mail entry
-                    if (sendToVoicemail) {
-                        entry.label = getString(R.string.actionIncomingCall);
-                        entry.data = getString(R.string.detailIncomingCallsGoToVoicemail);
-                        entry.actionIcon = R.drawable.sym_send_to_voicemail;
-                        mOtherEntries.add(entry);
-                    } else if (!TextUtils.isEmpty(ringtoneStr)) {
-                        // Get the URI
-                        Uri ringtoneUri = Uri.parse(ringtoneStr);
-                        if (ringtoneUri != null) {
-                            Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri);
-                            if (ringtone != null) {
-                                entry.label = getString(R.string.label_ringtone);
-                                entry.data = ringtone.getTitle(this);
-                                entry.uri = ringtoneUri;
-                                entry.actionIcon = R.drawable.sym_ringtone;
-                                mOtherEntries.add(entry);
-                            }
-                        }
-                    }
                 // Load the photo
                 } else if (mimetype.equals(CommonDataKinds.Photo.CONTENT_ITEM_TYPE)) {
                     photoBitmap = ContactsUtils.loadContactPhoto(aggCursor, DATA_1_COLUMN, null);