Merge "Changed tablet tabs to be a drop down spinner" into jb-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 33da473..996bc78 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -121,7 +121,7 @@
             android:launchMode="singleTask"
             android:clearTaskOnLaunch="true"
             android:icon="@mipmap/ic_launcher_phone"
-            android:screenOrientation="nosensor"
+            android:screenOrientation="portrait"
             android:enabled="@*android:bool/config_voice_capable"
             android:taskAffinity="android.task.contacts.phone"
             android:windowSoftInputMode="stateAlwaysHidden|adjustNothing">
diff --git a/src/com/android/contacts/ContactLoader.java b/src/com/android/contacts/ContactLoader.java
index 5d188fb..ab2ac41 100644
--- a/src/com/android/contacts/ContactLoader.java
+++ b/src/com/android/contacts/ContactLoader.java
@@ -226,10 +226,11 @@
             mIsUserProfile = isUserProfile;
         }
 
-        private Result(Result from) {
+        private Result(Uri requestedUri, Result from) {
+            mRequestedUri = requestedUri;
+
             mStatus = from.mStatus;
             mException = from.mException;
-            mRequestedUri = from.mRequestedUri;
             mLookupUri = from.mLookupUri;
             mUri = from.mUri;
             mDirectoryId = from.mDirectoryId;
@@ -520,6 +521,12 @@
         public boolean isUserProfile() {
             return mIsUserProfile;
         }
+
+        @Override
+        public String toString() {
+            return "{requested=" + mRequestedUri + ",lookupkey=" + mLookupKey +
+                    ",uri=" + mUri + ",status=" + mStatus + "}";
+        }
     }
 
     /**
@@ -730,13 +737,13 @@
                     UriUtils.areEqual(cachedResult.getLookupUri(), mLookupUri)) {
                 // We are using a cached result from earlier. Below, we should make sure
                 // we are not doing any more network or disc accesses
-                result = cachedResult;
+                result = new Result(mRequestedUri, cachedResult);
                 resultIsCached = true;
             } else {
                 result = loadContactEntity(resolver, uriCurrentFormat);
                 resultIsCached = false;
             }
-            if (!result.isNotFound()) {
+            if (result.isLoaded()) {
                 if (result.isDirectoryEntry()) {
                     if (!resultIsCached) {
                         loadDirectoryMetaData(result);
@@ -1345,10 +1352,10 @@
      * contact. If the next load is for a different contact, the cached result will be dropped
      */
     public void cacheResult() {
-        if (mContact == null) {
+        if (mContact == null || !mContact.isLoaded()) {
             sCachedResult = null;
         } else {
-            sCachedResult = new Result(mContact);
+            sCachedResult = mContact;
         }
     }
 }
diff --git a/src/com/android/contacts/detail/ContactLoaderFragment.java b/src/com/android/contacts/detail/ContactLoaderFragment.java
index d8fa158..25c60d6 100644
--- a/src/com/android/contacts/detail/ContactLoaderFragment.java
+++ b/src/com/android/contacts/detail/ContactLoaderFragment.java
@@ -191,6 +191,7 @@
         @Override
         public void onLoadFinished(Loader<ContactLoader.Result> loader, ContactLoader.Result data) {
             if (!mLookupUri.equals(data.getRequestedUri())) {
+                Log.e(TAG, "Different URI: requested=" + mLookupUri + "  actual=" + data);
                 return;
             }
 
diff --git a/src/com/android/contacts/socialwidget/SocialWidgetConfigureActivity.java b/src/com/android/contacts/socialwidget/SocialWidgetConfigureActivity.java
index 98812d9..39307bf 100644
--- a/src/com/android/contacts/socialwidget/SocialWidgetConfigureActivity.java
+++ b/src/com/android/contacts/socialwidget/SocialWidgetConfigureActivity.java
@@ -23,12 +23,19 @@
 import android.provider.ContactsContract.Contacts;
 
 public class SocialWidgetConfigureActivity extends Activity {
+    private static final String KEY_LAUNCHED = "already_launched_picker_activity";
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         // If the user presses back, we want to cancel
         setResult(RESULT_CANCELED);
 
+        // Don't launch contact-picker if we already launched it (for example, if
+        // we launched it in a previous onCreate() and the device orientation changes
+        // before the picker returns its result, then this activity will be recreated).
+        if (savedInstanceState != null && savedInstanceState.getBoolean(KEY_LAUNCHED)) return;
+
         // Forward the Intent to the picker
         final Intent pickerIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
         pickerIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
@@ -36,6 +43,14 @@
     }
 
     @Override
+    protected void onSaveInstanceState(Bundle savedInstanceState) {
+        super.onSaveInstanceState(savedInstanceState);
+
+        // We know for sure that we've launched the contact-picker... see onCreate()
+        savedInstanceState.putBoolean(KEY_LAUNCHED, true);
+    }
+
+    @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         // We came back from the Picker. If the user actually selected a contact,
         // return it now