Fix regression; once again we can apply Gallery photo to contact.
The changes to support hi-res photos in Ic0cabaa5 were not applied to
AttachPhotoActivity. This CL makes the analogous changes, and many other
cleanups besides.
In addition, applying the Gallery photo works even if the AttachPhotoActivity
is killed (eg: when selecting a contact, or when cropping the photo); this
didn't work even before the regression.
The save-contact Intent which invokes the ContactSaveService no longer
needs to specify a callback Activity (it is OK to pass null if you don't
care about getting a callback).
The subclasses of PhotoSelectionHandler have been significantly simplified,
partly by pushing common behavior to the superclass, and also by directly
accessing state in their outer class instead making their own copies.
ContactLoader.Result.getEntityDeltaList() is a new instance method that
replaces more verbose incantations.
New utility class, ContactPhotoUtils. Helps with compressing Bitmaps, and
generating temp-file names used when saving hi-res photos to a contact.
Bug: 6298601
Change-Id: I2fe90c33c9fa81716f263d82ed80c0d6f63c6a7e
diff --git a/src/com/android/contacts/ContactLoader.java b/src/com/android/contacts/ContactLoader.java
index 17cd1e7..c0399e4 100644
--- a/src/com/android/contacts/ContactLoader.java
+++ b/src/com/android/contacts/ContactLoader.java
@@ -19,6 +19,7 @@
import com.android.contacts.model.AccountType;
import com.android.contacts.model.AccountTypeManager;
import com.android.contacts.model.AccountTypeWithDataSet;
+import com.android.contacts.model.EntityDeltaList;
import com.android.contacts.util.ContactLoaderUtils;
import com.android.contacts.util.DataStatus;
import com.android.contacts.util.StreamItemEntry;
@@ -71,7 +72,7 @@
* Loads a single Contact and all it constituent RawContacts.
*/
public class ContactLoader extends AsyncTaskLoader<ContactLoader.Result> {
- private static final String TAG = "ContactLoader";
+ private static final String TAG = ContactLoader.class.getSimpleName();
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
@@ -313,6 +314,13 @@
}
/**
+ * Instantiate a new EntityDeltaList for this contact.
+ */
+ public EntityDeltaList createEntityDeltaList() {
+ return EntityDeltaList.fromIterator(getEntities().iterator());
+ }
+
+ /**
* Returns the contact ID.
*/
@VisibleForTesting
@@ -419,16 +427,31 @@
* writable raw-contact, and false otherwise.
*/
public boolean isWritableContact(final Context context) {
- if (isDirectoryEntry()) return false;
+ return getFirstWritableRawContactId(context) != -1;
+ }
+
+ /**
+ * Return the ID of the first raw-contact in the contact data that belongs to a
+ * contact-writable account, or -1 if no such entity exists.
+ */
+ public long getFirstWritableRawContactId(final Context context) {
+ // Directory entries are non-writable
+ if (isDirectoryEntry()) return -1;
+
+ // Iterate through raw-contacts; if we find a writable on, return its ID.
final AccountTypeManager accountTypes = AccountTypeManager.getInstance(context);
- for (Entity rawContact : getEntities()) {
- final ContentValues rawValues = rawContact.getEntityValues();
- final String accountType = rawValues.getAsString(RawContacts.ACCOUNT_TYPE);
- final String dataSet = rawValues.getAsString(RawContacts.DATA_SET);
- final AccountType type = accountTypes.getAccountType(accountType, dataSet);
- if (type != null && type.areContactsWritable()) return true;
+ for (Entity entity : getEntities()) {
+ ContentValues values = entity.getEntityValues();
+ String type = values.getAsString(RawContacts.ACCOUNT_TYPE);
+ String dataSet = values.getAsString(RawContacts.DATA_SET);
+
+ AccountType accountType = accountTypes.getAccountType(type, dataSet);
+ if (accountType != null && accountType.areContactsWritable()) {
+ return values.getAsLong(RawContacts._ID);
+ }
}
- return false;
+ // No writable raw-contact was found.
+ return -1;
}
public int getDirectoryExportSupport() {