auto import from //branches/cupcake/...@125939
diff --git a/src/com/android/contacts/ContactEntryAdapter.java b/src/com/android/contacts/ContactEntryAdapter.java
index 981b4bc..c5b7ccf 100644
--- a/src/com/android/contacts/ContactEntryAdapter.java
+++ b/src/com/android/contacts/ContactEntryAdapter.java
@@ -40,6 +40,7 @@
         People.STARRED, // 5
         People.CUSTOM_RINGTONE, // 6
         People.SEND_TO_VOICEMAIL, // 7
+        People.PHONETIC_NAME, // 8
     };
     public static final int CONTACT_ID_COLUMN = 0;
     public static final int CONTACT_NAME_COLUMN = 1;
@@ -49,6 +50,7 @@
     public static final int CONTACT_STARRED_COLUMN = 5;
     public static final int CONTACT_CUSTOM_RINGTONE_COLUMN = 6;
     public static final int CONTACT_SEND_TO_VOICEMAIL_COLUMN = 7;
+    public static final int CONTACT_PHONETIC_NAME_COLUMN = 8;
 
     public static final String[] PHONES_PROJECTION = new String[] {
         People.Phones._ID, // 0
diff --git a/src/com/android/contacts/ContactsListActivity.java b/src/com/android/contacts/ContactsListActivity.java
index 5e1fd63..5a83090 100644
--- a/src/com/android/contacts/ContactsListActivity.java
+++ b/src/com/android/contacts/ContactsListActivity.java
@@ -633,7 +633,7 @@
         Intent syncIntent = new Intent(Intent.ACTION_VIEW);
         syncIntent.setClass(this, ContactsGroupSyncSelector.class);
         menu.add(0, 0, 0, R.string.syncGroupPreference)
-                .setIcon(R.drawable.ic_menu_refresh)
+                .setIcon(android.R.drawable.ic_menu_refresh)
                 .setIntent(syncIntent);
         
         // SIM import
@@ -815,7 +815,6 @@
                     .setMessage(R.string.deleteConfirmation)
                     .setNegativeButton(android.R.string.cancel, null)
                     .setPositiveButton(android.R.string.ok, new DeleteClickListener(uri))
-                    .setCancelable(false)
                     .show();
                 return true;
             }
diff --git a/src/com/android/contacts/DialtactsActivity.java b/src/com/android/contacts/DialtactsActivity.java
index 00df1c1..1933c4c 100644
--- a/src/com/android/contacts/DialtactsActivity.java
+++ b/src/com/android/contacts/DialtactsActivity.java
@@ -16,6 +16,7 @@
 
 package com.android.contacts;
 
+import android.app.Activity;
 import android.app.TabActivity;
 import android.content.Intent;
 import android.graphics.drawable.Drawable;
@@ -37,7 +38,7 @@
  * and another tab with recent calls in it. This is the container and the tabs
  * are embedded using intents.
  */
-public class DialtactsActivity extends TabActivity {
+public class DialtactsActivity extends TabActivity implements TabHost.OnTabChangeListener {
     private static final String TAG = "Dailtacts";
 
     public static final String EXTRA_IGNORE_STATE = "ignore-state";
@@ -66,6 +67,7 @@
         setContentView(R.layout.dialer_activity);
 
         mTabHost = getTabHost();
+        mTabHost.setOnTabChangedListener(this);
 
         // Setup the tabs
         setupDialerTab();
@@ -286,4 +288,16 @@
         
         return super.onKeyDown(keyCode, event);
     }
+
+    /** {@inheritDoc} */
+    public void onTabChanged(String tabId) {
+        // Because we're using Activities as our tab children, we trigger
+        // onWindowFocusChanged() to let them know when they're active.  This may
+        // seem to duplicate the purpose of onResume(), but it's needed because
+        // onResume() can't reliably check if a keyguard is active.
+        Activity activity = getLocalActivityManager().getActivity(tabId);
+        if (activity != null) {
+            activity.onWindowFocusChanged(true);
+        }
+    }
 }
diff --git a/src/com/android/contacts/EditContactActivity.java b/src/com/android/contacts/EditContactActivity.java
index 3a7610d..2994ce4 100644
--- a/src/com/android/contacts/EditContactActivity.java
+++ b/src/com/android/contacts/EditContactActivity.java
@@ -23,6 +23,7 @@
 import static com.android.contacts.ContactEntryAdapter.CONTACT_NOTES_COLUMN;
 import static com.android.contacts.ContactEntryAdapter.CONTACT_PROJECTION;
 import static com.android.contacts.ContactEntryAdapter.CONTACT_SEND_TO_VOICEMAIL_COLUMN;
+import static com.android.contacts.ContactEntryAdapter.CONTACT_PHONETIC_NAME_COLUMN;
 import static com.android.contacts.ContactEntryAdapter.METHODS_AUX_DATA_COLUMN;
 import static com.android.contacts.ContactEntryAdapter.METHODS_DATA_COLUMN;
 import static com.android.contacts.ContactEntryAdapter.METHODS_ID_COLUMN;
@@ -101,6 +102,7 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 /**
@@ -172,6 +174,8 @@
     private LayoutInflater mInflater;
     private MenuItem mPhotoMenuItem;
     private boolean mPhotoPresent = false;
+    private EditText mPhoneticNameView;
+    private LinearLayout mPhoneticNameLayout;
 
     // These are accessed by inner classes. They're package scoped to make access more efficient.
     /* package */ ContentResolver mResolver;
@@ -308,8 +312,20 @@
         mPhotoButton = findViewById(R.id.photoButton);
         mPhotoButton.setOnClickListener(this);
         mSendToVoicemailCheckBox = (CheckBox) findViewById(R.id.send_to_voicemail);
+        mPhoneticNameView = (EditText) findViewById(R.id.phonetic_name);
+        mPhoneticNameLayout = (LinearLayout) findViewById(R.id.phonetic_name_layout);
 
-        // Setup the bottom buttons 
+        // Setup phonetic name field.  mPhoneticNameLayout is GONE by default.
+        // TODO: Don't do this here in Java; instead do it purely using
+        // resources, by having mPhoneticNameLayout come from an XML
+        // <include> file that contains the real UI in layout-ja, but is
+        // empty in layout-finger...
+        String language = Locale.getDefault().getLanguage();
+        if (language != null && language.equals("ja")) {
+            mPhoneticNameLayout.setVisibility(View.VISIBLE);
+        }
+
+        // Setup the bottom buttons
         View view = findViewById(R.id.addMore);
         view.setOnClickListener(this);
         view = findViewById(R.id.saveButton);
@@ -378,6 +394,7 @@
         outState.putParcelable("photo", mPhoto);
         outState.putBoolean("photoChanged", mPhotoChanged);
         outState.putBoolean("sendToVoicemail", mSendToVoicemailCheckBox.isChecked());
+        outState.putString("phoneticName", mPhoneticNameView.getText().toString());
     }
 
     @Override
@@ -403,7 +420,8 @@
         }
         mPhotoChanged = inState.getBoolean("photoChanged");
         mSendToVoicemailCheckBox.setChecked(inState.getBoolean("sendToVoicemail"));
-        
+        mPhoneticNameView.setText(inState.getString("phoneticName"));
+
         // Now that everything is restored, build the view
         buildViews();
     }
@@ -547,11 +565,17 @@
         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) {
-            Uri ringtoneUri = Uri.parse(entry.data);
-            // Put checkmark next to the current ringtone for this contact
-            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtoneUri);
+            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);
     }
@@ -919,6 +943,7 @@
             numValues++;
         }
         values.put(People.NAME, name);
+        values.put(People.PHONETIC_NAME, mPhoneticNameView.getText().toString());
         values.put(People.SEND_TO_VOICEMAIL, mSendToVoicemailCheckBox.isChecked() ? 1 : 0);
         mResolver.update(mUri, values, null, null);
 
@@ -992,6 +1017,7 @@
             numValues++;
         }
         values.put(People.NAME, name);
+        values.put(People.PHONETIC_NAME, mPhoneticNameView.getText().toString());
         values.put(People.SEND_TO_VOICEMAIL, mSendToVoicemailCheckBox.isChecked() ? 1 : 0);
 
         // Add the contact to the My Contacts group
@@ -1129,6 +1155,10 @@
         entry = EditEntry.newRingtoneEntry(this,
                 personCursor.getString(CONTACT_CUSTOM_RINGTONE_COLUMN), mUri);
         mOtherEntries.add(entry);
+
+        // Phonetic name
+        mPhoneticNameView.setText(personCursor.getString(CONTACT_PHONETIC_NAME_COLUMN));
+
         personCursor.close();
 
         // Build up the phone entries
@@ -1279,7 +1309,6 @@
         // Ringtone
         entry = EditEntry.newRingtoneEntry(this, null, mUri);
         mOtherEntries.add(entry);
-        
     }
 
     private void addFromExtras(Bundle extras, Uri phonesUri, Uri methodsUri) {
@@ -1290,14 +1319,20 @@
         if (name != null && TextUtils.isGraphic(name)) {
             mNameView.setText(name);
         }
-        
+
+        // Read the phonetic name from the bundle
+        CharSequence phoneticName = extras.getCharSequence(Insert.PHONETIC_NAME);
+        if (!TextUtils.isEmpty(phoneticName)) {
+            mPhoneticNameView.setText(phoneticName);
+        }
+
         // Postal entries from extras
         CharSequence postal = extras.getCharSequence(Insert.POSTAL);
         int postalType = extras.getInt(Insert.POSTAL_TYPE, INVALID_TYPE);
         if (!TextUtils.isEmpty(postal) && postalType == INVALID_TYPE) {
             postalType = DEFAULT_POSTAL_TYPE;
         }
-        
+
         if (postalType != INVALID_TYPE) {
             entry = EditEntry.newPostalEntry(this, null, postalType, postal.toString(),
                     methodsUri, 0);
@@ -1344,14 +1379,24 @@
     private void addEmailFromExtras(Bundle extras, Uri methodsUri, String emailField,
             String typeField, String primaryField) {
         CharSequence email = extras.getCharSequence(emailField);
-        int emailType = extras.getInt(typeField, INVALID_TYPE);
+        
+        // Correctly handle String in typeField as TYPE_CUSTOM 
+        int emailType = INVALID_TYPE;
+        String customLabel = null;
+        if(extras.get(typeField) instanceof String) {
+            emailType = ContactMethods.TYPE_CUSTOM;
+            customLabel = extras.getString(typeField);
+        } else {
+            emailType = extras.getInt(typeField, INVALID_TYPE);
+        }
+
         if (!TextUtils.isEmpty(email) && emailType == INVALID_TYPE) {
             emailType = DEFAULT_EMAIL_TYPE;
             mPrimaryEmailAdded = true;
         }
 
         if (emailType != INVALID_TYPE) {
-            EditEntry entry = EditEntry.newEmailEntry(this, null, emailType, email.toString(),
+            EditEntry entry = EditEntry.newEmailEntry(this, customLabel, emailType, email.toString(),
                     methodsUri, 0);
             entry.isPrimary = (primaryField == null) ? false : extras.getBoolean(primaryField);
             mEmailEntries.add(entry);
@@ -1366,13 +1411,23 @@
     private void addPhoneFromExtras(Bundle extras, Uri phonesUri, String phoneField,
             String typeField, String primaryField) {
         CharSequence phoneNumber = extras.getCharSequence(phoneField);
-        int phoneType = extras.getInt(typeField, INVALID_TYPE);
+        
+        // Correctly handle String in typeField as TYPE_CUSTOM 
+        int phoneType = INVALID_TYPE;
+        String customLabel = null;
+        if(extras.get(typeField) instanceof String) {
+            phoneType = Phones.TYPE_CUSTOM;
+            customLabel = extras.getString(typeField);
+        } else {
+            phoneType = extras.getInt(typeField, INVALID_TYPE);
+        }
+        
         if (!TextUtils.isEmpty(phoneNumber) && phoneType == INVALID_TYPE) {
             phoneType = DEFAULT_PHONE_TYPE;
         }
 
         if (phoneType != INVALID_TYPE) {
-            EditEntry entry = EditEntry.newPhoneEntry(this, null, phoneType,
+            EditEntry entry = EditEntry.newPhoneEntry(this, customLabel, phoneType,
                     phoneNumber.toString(), phonesUri, 0);
             entry.isPrimary = (primaryField == null) ? false : extras.getBoolean(primaryField);
             mPhoneEntries.add(entry);
diff --git a/src/com/android/contacts/RecentCallsListActivity.java b/src/com/android/contacts/RecentCallsListActivity.java
index 550a385..85099fa 100644
--- a/src/com/android/contacts/RecentCallsListActivity.java
+++ b/src/com/android/contacts/RecentCallsListActivity.java
@@ -271,7 +271,7 @@
                 Cursor phonesCursor =
                     RecentCallsListActivity.this.getContentResolver().query(
                             Uri.withAppendedPath(Phones.CONTENT_FILTER_URL,
-                                    ciq.number),
+                                    Uri.encode(ciq.number)),
                     PHONES_PROJECTION, null, null, null);
                 if (phonesCursor != null) {
                     if (phonesCursor.moveToFirst()) {
@@ -434,7 +434,10 @@
             }
 
             // Set the time and date
-            views.dateView.setText(DateUtils.getRelativeTimeSpanString(date));
+            int flags = DateUtils.FORMAT_ABBREV_RELATIVE | DateUtils.FORMAT_SHOW_DATE
+                    | DateUtils.FORMAT_ABBREV_MONTH;
+            views.dateView.setText(DateUtils.getRelativeDateTimeString(context, date,
+                    DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, flags));
 
             // Set the icon
             switch (type) {
@@ -503,7 +506,7 @@
                 .getVoiceMailNumber();
         mQueryHandler = new QueryHandler(this);
     }
-
+    
     @Override
     protected void onResume() {
         // The adapter caches looked up numbers, clear it so they will get
@@ -516,16 +519,7 @@
         resetNewCallsFlag();
 
         super.onResume();
-        try {
-            ITelephony iTelephony = ITelephony.Stub.asInterface(ServiceManager.getService("phone"));
-            if (iTelephony != null) {
-                iTelephony.cancelMissedCallsNotification();
-            } else {
-                Log.w(TAG, "Telephony service is null, can't call cancelMissedCallsNotification");
-            }
-        } catch (RemoteException e) {
-            Log.e(TAG, "Failed to clear missed calls notification due to remote excetpion");
-        }
+
         mAdapter.mPreDrawListener = null; // Let it restart the thread after next draw
     }
 
@@ -547,6 +541,28 @@
         }
     }
 
+    @Override
+    public void onWindowFocusChanged(boolean hasFocus) {
+        super.onWindowFocusChanged(hasFocus);
+        
+        // Clear notifications only when window gains focus.  This activity won't
+        // immediately receive focus if the keyguard screen is above it.
+        if (hasFocus) {
+            try {
+                ITelephony iTelephony =
+                        ITelephony.Stub.asInterface(ServiceManager.getService("phone"));
+                if (iTelephony != null) {
+                    iTelephony.cancelMissedCallsNotification();
+                } else {
+                    Log.w(TAG, "Telephony service is null, can't call " +
+                            "cancelMissedCallsNotification");
+                }
+            } catch (RemoteException e) {
+                Log.e(TAG, "Failed to clear missed calls notification due to remote exception");
+            }
+        }
+    }
+
     private void resetNewCallsFlag() {
         // Mark all "new" missed calls as not new anymore
         StringBuilder where = new StringBuilder("type=");
diff --git a/src/com/android/contacts/TwelveKeyDialer.java b/src/com/android/contacts/TwelveKeyDialer.java
index 41adc5a..1a06026 100644
--- a/src/com/android/contacts/TwelveKeyDialer.java
+++ b/src/com/android/contacts/TwelveKeyDialer.java
@@ -196,18 +196,14 @@
         // Set up the "dialpad chooser" UI; see showDialpadChooser().
         mDialpadChooser = (ListView) findViewById(R.id.dialpadChooser);
         mDialpadChooser.setOnItemClickListener(this);
-        // Add a dummy "footer" view so that the divider under the bottom
-        // item will be visible.
-        // (We set android:footerDividersEnabled="true" on this ListView in XML.)
-        mDialpadChooser.addFooterView(new View(this), null, false);
 
         if (!resolveIntent() && icicle != null) {
             super.onRestoreInstanceState(icicle);
         }
-        
-        // if the mToneGenerator creation fails, just continue without it.  It is 
+
+        // If the mToneGenerator creation fails, just continue without it.  It is
         // a local audio signal, and is not as important as the dtmf tone itself.
-        synchronized(mToneGeneratorLock) {
+        synchronized (mToneGeneratorLock) {
             if (mToneGenerator == null) {
                 try {
                     mToneGenerator = new ToneGenerator(AudioManager.STREAM_RING,