summaryrefslogtreecommitdiffstats
path: root/src/com/android/contacts/common/ContactPhotoManager.java
diff options
context:
space:
mode:
authorblong <blong@codeaurora.org>2014-08-08 09:52:57 +0800
committerYujing Gu <guy@codeaurora.org>2014-11-19 14:40:07 +0800
commit4b9bd1a4c401e08c16f0d7c8bf6ae0d0c35092f4 (patch)
tree885c1bf390cae1ec7c68190379fd6c05a4c78848 /src/com/android/contacts/common/ContactPhotoManager.java
parent48df08f753a3acd7579f7c14d86e824e1cc0aac2 (diff)
downloadandroid_packages_apps_ContactsCommon-4b9bd1a4c401e08c16f0d7c8bf6ae0d0c35092f4.tar.gz
android_packages_apps_ContactsCommon-4b9bd1a4c401e08c16f0d7c8bf6ae0d0c35092f4.tar.bz2
android_packages_apps_ContactsCommon-4b9bd1a4c401e08c16f0d7c8bf6ae0d0c35092f4.zip
Add SIM photo for SIM contacts
- Add the customize photo for SIM contacts Change-Id: I06cd4a7f9c0151a01fdc029e4b669e9cc02886c6
Diffstat (limited to 'src/com/android/contacts/common/ContactPhotoManager.java')
-rw-r--r--src/com/android/contacts/common/ContactPhotoManager.java117
1 files changed, 82 insertions, 35 deletions
diff --git a/src/com/android/contacts/common/ContactPhotoManager.java b/src/com/android/contacts/common/ContactPhotoManager.java
index 12faadb0..f700fd8a 100644
--- a/src/com/android/contacts/common/ContactPhotoManager.java
+++ b/src/com/android/contacts/common/ContactPhotoManager.java
@@ -16,6 +16,7 @@
package com.android.contacts.common;
+import android.accounts.Account;
import android.app.ActivityManager;
import android.content.ComponentCallbacks2;
import android.content.ContentResolver;
@@ -113,19 +114,24 @@ public abstract class ContactPhotoManager implements ComponentCallbacks2 {
* draw a letter tile avatar based on the request parameters defined in the
* {@link DefaultImageRequest}.
*/
- public static Drawable getDefaultAvatarDrawableForContact(Resources resources, boolean hires,
+ public static Drawable getDefaultAvatarDrawableForContact(Context context, boolean hires,
DefaultImageRequest defaultImageRequest) {
+ return getDefaultAvatarDrawableForContact(context, hires, defaultImageRequest, null);
+ }
+
+ public static Drawable getDefaultAvatarDrawableForContact(Context context, boolean hires,
+ DefaultImageRequest defaultImageRequest, Account account) {
if (defaultImageRequest == null) {
if (sDefaultLetterAvatar == null) {
// Cache and return the letter tile drawable that is created by a null request,
// so that it doesn't have to be recreated every time it is requested again.
sDefaultLetterAvatar = LetterTileDefaultImageProvider.getDefaultImageForContact(
- resources, null);
+ context, null, account);
}
return sDefaultLetterAvatar;
}
- return LetterTileDefaultImageProvider.getDefaultImageForContact(resources,
- defaultImageRequest);
+ return LetterTileDefaultImageProvider.getDefaultImageForContact(context,
+ defaultImageRequest, account);
}
/**
@@ -365,8 +371,8 @@ public abstract class ContactPhotoManager implements ComponentCallbacks2 {
* @param defaultImageRequest {@link DefaultImageRequest} object that specifies how a
* default letter tile avatar should be drawn.
*/
- public abstract void applyDefaultImage(ImageView view, int extent, boolean darkTheme,
- DefaultImageRequest defaultImageRequest);
+ public abstract void applyDefaultImage(ImageView view, Account account,
+ int extent, boolean darkTheme, DefaultImageRequest defaultImageRequest);
}
/**
@@ -376,16 +382,17 @@ public abstract class ContactPhotoManager implements ComponentCallbacks2 {
*/
private static class LetterTileDefaultImageProvider extends DefaultImageProvider {
@Override
- public void applyDefaultImage(ImageView view, int extent, boolean darkTheme,
- DefaultImageRequest defaultImageRequest) {
- final Drawable drawable = getDefaultImageForContact(view.getResources(),
- defaultImageRequest);
+ public void applyDefaultImage(ImageView view, Account account, int extent,
+ boolean darkTheme, DefaultImageRequest defaultImageRequest) {
+ final Drawable drawable = getDefaultImageForContact(view.getContext(),
+ defaultImageRequest, account);
view.setImageDrawable(drawable);
}
- public static Drawable getDefaultImageForContact(Resources resources,
- DefaultImageRequest defaultImageRequest) {
- final LetterTileDrawable drawable = new LetterTileDrawable(resources);
+ public static Drawable getDefaultImageForContact(Context context,
+ DefaultImageRequest defaultImageRequest, Account account) {
+ final LetterTileDrawable drawable = new LetterTileDrawable(
+ context, account);
if (defaultImageRequest != null) {
// If the contact identifier is null or empty, fallback to the
// displayName. In that case, use {@code null} for the contact's
@@ -410,8 +417,8 @@ public abstract class ContactPhotoManager implements ComponentCallbacks2 {
private static Drawable sDrawable;
@Override
- public void applyDefaultImage(ImageView view, int extent, boolean darkTheme,
- DefaultImageRequest defaultImageRequest) {
+ public void applyDefaultImage(ImageView view, Account account, int extent,
+ boolean darkTheme, DefaultImageRequest defaultImageRequest) {
if (sDrawable == null) {
Context context = view.getContext();
sDrawable = new ColorDrawable(context.getResources().getColor(
@@ -440,13 +447,15 @@ public abstract class ContactPhotoManager implements ComponentCallbacks2 {
return new ContactPhotoManagerImpl(context);
}
+ public abstract void clear();
+
/**
* Load thumbnail image into the supplied image view. If the photo is already cached,
* it is displayed immediately. Otherwise a request is sent to load the photo
* from the database.
*/
- public abstract void loadThumbnail(ImageView view, long photoId, boolean darkTheme,
- boolean isCircular, DefaultImageRequest defaultImageRequest,
+ public abstract void loadThumbnail(ImageView view, long photoId, Account account,
+ boolean darkTheme, boolean isCircular, DefaultImageRequest defaultImageRequest,
DefaultImageProvider defaultProvider);
/**
@@ -454,10 +463,23 @@ public abstract class ContactPhotoManager implements ComponentCallbacks2 {
* DefaultImageProvider)} using the {@link DefaultImageProvider} {@link #DEFAULT_AVATAR}.
*/
public final void loadThumbnail(ImageView view, long photoId, boolean darkTheme,
- boolean isCircular, DefaultImageRequest defaultImageRequest) {
- loadThumbnail(view, photoId, darkTheme, isCircular, defaultImageRequest, DEFAULT_AVATAR);
+ boolean isCircular, DefaultImageRequest defaultImageRequest) {
+ loadThumbnail(view, photoId, null, darkTheme, isCircular,
+ defaultImageRequest, DEFAULT_AVATAR);
}
+ public final void loadThumbnail(ImageView view, long photoId, Account account,
+ boolean darkTheme, boolean isCircular, DefaultImageRequest defaultImageRequest) {
+ loadThumbnail(view, photoId, account, darkTheme, isCircular,
+ defaultImageRequest, DEFAULT_AVATAR);
+ }
+
+ public final void loadThumbnail(ImageView view, long photoId, boolean darkTheme,
+ boolean isCircular, DefaultImageRequest defaultImageRequest,
+ DefaultImageProvider defaultProvider) {
+ loadThumbnail(view, photoId, null, darkTheme, isCircular,
+ defaultImageRequest, defaultProvider);
+ }
/**
* Load photo into the supplied image view. If the photo is already cached,
@@ -476,8 +498,9 @@ public abstract class ContactPhotoManager implements ComponentCallbacks2 {
* @param defaultProvider The provider of default avatars (this is used if photoUri doesn't
* refer to an existing image)
*/
- public abstract void loadPhoto(ImageView view, Uri photoUri, int requestedExtent,
- boolean darkTheme, boolean isCircular, DefaultImageRequest defaultImageRequest,
+ public abstract void loadPhoto(ImageView view, Uri photoUri,
+ Account account, int requestedExtent, boolean darkTheme,
+ boolean isCircular, DefaultImageRequest defaultImageRequest,
DefaultImageProvider defaultProvider);
/**
@@ -488,12 +511,26 @@ public abstract class ContactPhotoManager implements ComponentCallbacks2 {
* @param defaultImageRequest {@link DefaultImageRequest} object that specifies how a default
* letter tile avatar should be drawn.
*/
+
public final void loadPhoto(ImageView view, Uri photoUri, int requestedExtent,
boolean darkTheme, boolean isCircular, DefaultImageRequest defaultImageRequest) {
- loadPhoto(view, photoUri, requestedExtent, darkTheme, isCircular,
+ loadPhoto(view, photoUri, null, requestedExtent, darkTheme, isCircular,
defaultImageRequest, DEFAULT_AVATAR);
}
+ public final void loadPhoto(ImageView view, Uri photoUri, Account account, int requestedExtent,
+ boolean darkTheme, boolean isCircular, DefaultImageRequest defaultImageRequest) {
+ loadPhoto(view, photoUri, account, requestedExtent, darkTheme, isCircular,
+ defaultImageRequest, DEFAULT_AVATAR);
+ }
+
+ public final void loadPhoto(ImageView view, Uri photoUri, int requestedExtent,
+ boolean darkTheme, boolean isCircular, DefaultImageRequest defaultImageRequest,
+ DefaultImageProvider defaultProvider) {
+ loadPhoto(view, photoUri, null, requestedExtent, darkTheme, isCircular,
+ defaultImageRequest, defaultProvider);
+ }
+
/**
* Calls {@link #loadPhoto(ImageView, Uri, boolean, boolean, DefaultImageRequest,
* DefaultImageProvider)} with {@link #DEFAULT_AVATAR} and with the assumption, that
@@ -504,7 +541,15 @@ public abstract class ContactPhotoManager implements ComponentCallbacks2 {
*/
public final void loadDirectoryPhoto(ImageView view, Uri photoUri, boolean darkTheme,
boolean isCircular, DefaultImageRequest defaultImageRequest) {
- loadPhoto(view, photoUri, -1, darkTheme, isCircular, defaultImageRequest, DEFAULT_AVATAR);
+ loadPhoto(view, photoUri, null, -1, darkTheme, isCircular,
+ defaultImageRequest, DEFAULT_AVATAR);
+ }
+
+ public final void loadDirectoryPhoto(ImageView view, Uri photoUri,
+ Account account, boolean darkTheme, boolean isCircular,
+ DefaultImageRequest defaultImageRequest) {
+ loadPhoto(view, photoUri, account, -1, darkTheme, isCircular,
+ defaultImageRequest, DEFAULT_AVATAR);
}
/**
@@ -784,11 +829,12 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
}
@Override
- public void loadThumbnail(ImageView view, long photoId, boolean darkTheme, boolean isCircular,
- DefaultImageRequest defaultImageRequest, DefaultImageProvider defaultProvider) {
+ public void loadThumbnail(ImageView view, long photoId, Account account,
+ boolean darkTheme, boolean isCircular, DefaultImageRequest defaultImageRequest,
+ DefaultImageProvider defaultProvider) {
if (photoId == 0) {
// No photo is needed
- defaultProvider.applyDefaultImage(view, -1, darkTheme, defaultImageRequest);
+ defaultProvider.applyDefaultImage(view, account, -1, darkTheme, defaultImageRequest);
mPendingRequests.remove(view);
} else {
if (DEBUG) Log.d(TAG, "loadPhoto request: " + photoId);
@@ -798,19 +844,19 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
}
@Override
- public void loadPhoto(ImageView view, Uri photoUri, int requestedExtent, boolean darkTheme,
- boolean isCircular, DefaultImageRequest defaultImageRequest,
+ public void loadPhoto(ImageView view, Uri photoUri, Account account, int requestedExtent,
+ boolean darkTheme, boolean isCircular, DefaultImageRequest defaultImageRequest,
DefaultImageProvider defaultProvider) {
if (photoUri == null) {
// No photo is needed
- defaultProvider.applyDefaultImage(view, requestedExtent, darkTheme,
+ defaultProvider.applyDefaultImage(view, account, requestedExtent, darkTheme,
defaultImageRequest);
mPendingRequests.remove(view);
} else {
if (DEBUG) Log.d(TAG, "loadPhoto request: " + photoUri);
if (isDefaultImageUri(photoUri)) {
- createAndApplyDefaultImageForUri(view, photoUri, requestedExtent, darkTheme,
- isCircular, defaultProvider);
+ createAndApplyDefaultImageForUri(view, account, photoUri, requestedExtent,
+ darkTheme, isCircular, defaultProvider);
} else {
loadPhotoByIdOrUri(view, Request.createFromUri(photoUri, requestedExtent,
darkTheme, isCircular, defaultProvider));
@@ -818,11 +864,12 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
}
}
- private void createAndApplyDefaultImageForUri(ImageView view, Uri uri, int requestedExtent,
- boolean darkTheme, boolean isCircular, DefaultImageProvider defaultProvider) {
+ private void createAndApplyDefaultImageForUri(ImageView view,
+ Account account, Uri uri, int requestedExtent, boolean darkTheme,
+ boolean isCircular, DefaultImageProvider defaultProvider) {
DefaultImageRequest request = getDefaultImageRequestFromUri(uri);
request.isCircular = isCircular;
- defaultProvider.applyDefaultImage(view, requestedExtent, darkTheme, request);
+ defaultProvider.applyDefaultImage(view, account, requestedExtent, darkTheme, request);
}
private void loadPhotoByIdOrUri(ImageView view, Request request) {
@@ -1646,7 +1693,7 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
? DefaultImageRequest.EMPTY_DEFAULT_BUSINESS_IMAGE_REQUEST
: DefaultImageRequest.EMPTY_DEFAULT_IMAGE_REQUEST;
}
- mDefaultProvider.applyDefaultImage(view, mRequestedExtent, mDarkTheme, request);
+ mDefaultProvider.applyDefaultImage(view, null, mRequestedExtent, mDarkTheme, request);
}
}
}