Loading res/layout/item_photo_editor.xml +2 −2 Original line number Diff line number Diff line Loading @@ -22,8 +22,8 @@ android:orientation="horizontal" > <FrameLayout android:layout_width="48dip" android:layout_height="48dip" android:layout_width="72dp" android:layout_height="72dp" > <ImageView android:id="@+id/photo" Loading src/com/android/contacts/editor/BaseRawContactEditorView.java +12 −14 Original line number Diff line number Diff line Loading @@ -19,9 +19,9 @@ package com.android.contacts.editor; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; import android.net.Uri; import android.provider.ContactsContract.CommonDataKinds.Photo; import android.provider.ContactsContract.Data; import android.provider.ContactsContract.RawContacts; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; Loading @@ -46,7 +46,6 @@ import com.android.contacts.common.model.account.AccountType.EditType; public abstract class BaseRawContactEditorView extends LinearLayout { private PhotoEditorView mPhoto; private boolean mHasPhotoEditor = false; private View mBody; private View mDivider; Loading Loading @@ -77,23 +76,22 @@ public abstract class BaseRawContactEditorView extends LinearLayout { /** * Assign the given {@link Bitmap} to the internal {@link PhotoEditorView} * for the {@link RawContactDelta} currently being edited. * in order to update the {@link RawContactDelta} currently being edited. */ public void setPhotoBitmap(Bitmap bitmap) { mPhoto.setPhotoBitmap(bitmap); } protected void setHasPhotoEditor(boolean hasPhotoEditor) { mHasPhotoEditor = hasPhotoEditor; mPhoto.setVisibility(hasPhotoEditor ? View.VISIBLE : View.GONE); public void setPhotoEntry(Bitmap bitmap) { mPhoto.setPhotoEntry(bitmap); } /** * Return true if the current {@link RawContacts} supports {@link Photo}, * which means that {@link PhotoEditorView} is enabled. * Assign the given photo {@link Uri} to UI of the {@link PhotoEditorView}, so that it can * display a full sized photo. */ public boolean hasPhotoEditor() { return mHasPhotoEditor; public void setFullSizedPhoto(Uri uri) { mPhoto.setFullSizedPhoto(uri); } protected void setHasPhotoEditor(boolean hasPhotoEditor) { mPhoto.setVisibility(hasPhotoEditor ? View.VISIBLE : View.GONE); } /** Loading src/com/android/contacts/editor/ContactEditorFragment.java +11 −14 Original line number Diff line number Diff line Loading @@ -34,7 +34,6 @@ import android.content.Intent; import android.content.Loader; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Rect; import android.media.RingtoneManager; import android.net.Uri; Loading Loading @@ -862,10 +861,10 @@ public class ContactEditorFragment extends Fragment implements // Set up the photo handler. bindPhotoHandler(editor, type, mState); // If a new photo was chosen but not yet saved, we need to // update the thumbnail to reflect this. Bitmap bitmap = updatedBitmapForRawContact(rawContactId); if (bitmap != null) editor.setPhotoBitmap(bitmap); // If a new photo was chosen but not yet saved, we need to update the UI to // reflect this. final Uri photoUri = updatedPhotoUriForRawContact(rawContactId); if (photoUri != null) editor.setFullSizedPhoto(photoUri); if (editor instanceof RawContactEditorView) { final Activity activity = getActivity(); Loading Loading @@ -922,14 +921,12 @@ public class ContactEditorFragment extends Fragment implements } /** * If we've stashed a temporary file containing a contact's new photo, * decode it and return the bitmap. * If we've stashed a temporary file containing a contact's new photo, return its URI. * @param rawContactId identifies the raw-contact whose Bitmap we'll try to return. * @return Bitmap of photo for specified raw-contact, or null * @return Uru of photo for specified raw-contact, or null */ private Bitmap updatedBitmapForRawContact(long rawContactId) { String path = mUpdatedPhotos.getString(String.valueOf(rawContactId)); return path == null ? null : BitmapFactory.decodeFile(path); private Uri updatedPhotoUriForRawContact(long rawContactId) { return (Uri) mUpdatedPhotos.get(String.valueOf(rawContactId)); } private void bindPhotoHandler(BaseRawContactEditorView editor, AccountType type, Loading Loading @@ -1861,7 +1858,7 @@ public class ContactEditorFragment extends Fragment implements } if (requestingEditor != null) { requestingEditor.setPhotoBitmap(photo); requestingEditor.setPhotoEntry(photo); } else { Log.w(TAG, "The contact that requested the photo is no longer present."); } Loading Loading @@ -2065,7 +2062,7 @@ public class ContactEditorFragment extends Fragment implements */ @Override public void onRemovePictureChosen() { mEditor.setPhotoBitmap(null); mEditor.setPhotoEntry(null); // Prevent bitmap from being restored if rotate the device. // (only if we first chose a new photo before removing it) Loading src/com/android/contacts/editor/PhotoEditorView.java +49 −7 Original line number Diff line number Diff line Loading @@ -19,13 +19,17 @@ package com.android.contacts.editor; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.provider.ContactsContract.CommonDataKinds.Photo; import android.provider.ContactsContract.DisplayPhoto; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import com.android.contacts.R; import com.android.contacts.common.ContactPhotoManager.DefaultImageProvider; import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; import com.android.contacts.common.model.RawContactDelta; import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.ContactsUtils; Loading @@ -44,6 +48,7 @@ public class PhotoEditorView extends LinearLayout implements Editor { private ValuesDelta mEntry; private EditorListener mListener; private View mTriangleAffordance; private ContactPhotoManager mContactPhotoManager; private boolean mHasSetPhoto = false; private boolean mReadOnly; Loading Loading @@ -72,6 +77,7 @@ public class PhotoEditorView extends LinearLayout implements Editor { @Override protected void onFinishInflate() { super.onFinishInflate(); mContactPhotoManager = ContactPhotoManager.getInstance(mContext); mTriangleAffordance = findViewById(R.id.photo_triangle_affordance); mPhotoImageView = (ImageView) findViewById(R.id.photo); mFrameView = findViewById(R.id.frame); Loading Loading @@ -111,6 +117,20 @@ public class PhotoEditorView extends LinearLayout implements Editor { mFrameView.setEnabled(isEnabled()); mHasSetPhoto = true; mEntry.setFromTemplate(false); if (values.getAfter() == null || values.getAfter().get(Photo.PHOTO) == null) { // If the user hasn't updated the PHOTO value, then PHOTO_FILE_ID may contain // a reference to a larger version of PHOTO that we can bind to the UI. // Otherwise, we need to wait for a call to #setFullSizedPhoto() to update // our full sized image. final Integer photoFileId = values.getAsInteger(Photo.PHOTO_FILE_ID); if (photoFileId != null) { final Uri photoUri = DisplayPhoto.CONTENT_URI.buildUpon() .appendPath(photoFileId.toString()).build(); setFullSizedPhoto(photoUri); } } } else { resetDefault(); } Loading @@ -127,10 +147,10 @@ public class PhotoEditorView extends LinearLayout implements Editor { } /** * Assign the given {@link Bitmap} as the new value, updating UI and * readying for persisting through {@link ValuesDelta}. * Assign the given {@link Bitmap} as the new value for the sake of building * {@link ValuesDelta}. We may as well bind a thumbnail to the UI while we are at it. */ public void setPhotoBitmap(Bitmap photo) { public void setPhotoEntry(Bitmap photo) { if (photo == null) { // Clear any existing photo and return mEntry.put(Photo.PHOTO, (byte[])null); Loading @@ -138,7 +158,10 @@ public class PhotoEditorView extends LinearLayout implements Editor { return; } mPhotoImageView.setImageBitmap(photo); final int size = ContactsUtils.getThumbnailSize(getContext()); final Bitmap scaled = Bitmap.createScaledBitmap(photo, size, size, false); mPhotoImageView.setImageBitmap(scaled); mFrameView.setEnabled(isEnabled()); mHasSetPhoto = true; mEntry.setFromTemplate(false); Loading @@ -152,10 +175,29 @@ public class PhotoEditorView extends LinearLayout implements Editor { // code all over the place, because we don't have to test whether // there is a change in EITHER the delta-list OR a changed photo... // this way, there is always a change in the delta-list. final int size = ContactsUtils.getThumbnailSize(getContext()); final Bitmap scaled = Bitmap.createScaledBitmap(photo, size, size, false); final byte[] compressed = ContactPhotoUtils.compressBitmap(scaled); if (compressed != null) mEntry.setPhoto(compressed); if (compressed != null) { mEntry.setPhoto(compressed); } } /** * Bind the {@param photoUri}'s photo to editor's UI. This doesn't affect {@link ValuesDelta}. */ public void setFullSizedPhoto(Uri photoUri) { if (photoUri != null) { final DefaultImageProvider fallbackToPreviousImage = new DefaultImageProvider() { @Override public void applyDefaultImage(ImageView view, int extent, boolean darkTheme, DefaultImageRequest defaultImageRequest) { // Before we finish setting the full sized image, don't change the current // image that is set in any way. } }; mContactPhotoManager.loadPhoto(mPhotoImageView, photoUri, mPhotoImageView.getWidth(), /* darkTheme = */ false, /* isCircular = */ false, /* defaultImageRequest = */ null, fallbackToPreviousImage); } } /** Loading Loading
res/layout/item_photo_editor.xml +2 −2 Original line number Diff line number Diff line Loading @@ -22,8 +22,8 @@ android:orientation="horizontal" > <FrameLayout android:layout_width="48dip" android:layout_height="48dip" android:layout_width="72dp" android:layout_height="72dp" > <ImageView android:id="@+id/photo" Loading
src/com/android/contacts/editor/BaseRawContactEditorView.java +12 −14 Original line number Diff line number Diff line Loading @@ -19,9 +19,9 @@ package com.android.contacts.editor; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; import android.net.Uri; import android.provider.ContactsContract.CommonDataKinds.Photo; import android.provider.ContactsContract.Data; import android.provider.ContactsContract.RawContacts; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; Loading @@ -46,7 +46,6 @@ import com.android.contacts.common.model.account.AccountType.EditType; public abstract class BaseRawContactEditorView extends LinearLayout { private PhotoEditorView mPhoto; private boolean mHasPhotoEditor = false; private View mBody; private View mDivider; Loading Loading @@ -77,23 +76,22 @@ public abstract class BaseRawContactEditorView extends LinearLayout { /** * Assign the given {@link Bitmap} to the internal {@link PhotoEditorView} * for the {@link RawContactDelta} currently being edited. * in order to update the {@link RawContactDelta} currently being edited. */ public void setPhotoBitmap(Bitmap bitmap) { mPhoto.setPhotoBitmap(bitmap); } protected void setHasPhotoEditor(boolean hasPhotoEditor) { mHasPhotoEditor = hasPhotoEditor; mPhoto.setVisibility(hasPhotoEditor ? View.VISIBLE : View.GONE); public void setPhotoEntry(Bitmap bitmap) { mPhoto.setPhotoEntry(bitmap); } /** * Return true if the current {@link RawContacts} supports {@link Photo}, * which means that {@link PhotoEditorView} is enabled. * Assign the given photo {@link Uri} to UI of the {@link PhotoEditorView}, so that it can * display a full sized photo. */ public boolean hasPhotoEditor() { return mHasPhotoEditor; public void setFullSizedPhoto(Uri uri) { mPhoto.setFullSizedPhoto(uri); } protected void setHasPhotoEditor(boolean hasPhotoEditor) { mPhoto.setVisibility(hasPhotoEditor ? View.VISIBLE : View.GONE); } /** Loading
src/com/android/contacts/editor/ContactEditorFragment.java +11 −14 Original line number Diff line number Diff line Loading @@ -34,7 +34,6 @@ import android.content.Intent; import android.content.Loader; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Rect; import android.media.RingtoneManager; import android.net.Uri; Loading Loading @@ -862,10 +861,10 @@ public class ContactEditorFragment extends Fragment implements // Set up the photo handler. bindPhotoHandler(editor, type, mState); // If a new photo was chosen but not yet saved, we need to // update the thumbnail to reflect this. Bitmap bitmap = updatedBitmapForRawContact(rawContactId); if (bitmap != null) editor.setPhotoBitmap(bitmap); // If a new photo was chosen but not yet saved, we need to update the UI to // reflect this. final Uri photoUri = updatedPhotoUriForRawContact(rawContactId); if (photoUri != null) editor.setFullSizedPhoto(photoUri); if (editor instanceof RawContactEditorView) { final Activity activity = getActivity(); Loading Loading @@ -922,14 +921,12 @@ public class ContactEditorFragment extends Fragment implements } /** * If we've stashed a temporary file containing a contact's new photo, * decode it and return the bitmap. * If we've stashed a temporary file containing a contact's new photo, return its URI. * @param rawContactId identifies the raw-contact whose Bitmap we'll try to return. * @return Bitmap of photo for specified raw-contact, or null * @return Uru of photo for specified raw-contact, or null */ private Bitmap updatedBitmapForRawContact(long rawContactId) { String path = mUpdatedPhotos.getString(String.valueOf(rawContactId)); return path == null ? null : BitmapFactory.decodeFile(path); private Uri updatedPhotoUriForRawContact(long rawContactId) { return (Uri) mUpdatedPhotos.get(String.valueOf(rawContactId)); } private void bindPhotoHandler(BaseRawContactEditorView editor, AccountType type, Loading Loading @@ -1861,7 +1858,7 @@ public class ContactEditorFragment extends Fragment implements } if (requestingEditor != null) { requestingEditor.setPhotoBitmap(photo); requestingEditor.setPhotoEntry(photo); } else { Log.w(TAG, "The contact that requested the photo is no longer present."); } Loading Loading @@ -2065,7 +2062,7 @@ public class ContactEditorFragment extends Fragment implements */ @Override public void onRemovePictureChosen() { mEditor.setPhotoBitmap(null); mEditor.setPhotoEntry(null); // Prevent bitmap from being restored if rotate the device. // (only if we first chose a new photo before removing it) Loading
src/com/android/contacts/editor/PhotoEditorView.java +49 −7 Original line number Diff line number Diff line Loading @@ -19,13 +19,17 @@ package com.android.contacts.editor; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.provider.ContactsContract.CommonDataKinds.Photo; import android.provider.ContactsContract.DisplayPhoto; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import com.android.contacts.R; import com.android.contacts.common.ContactPhotoManager.DefaultImageProvider; import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; import com.android.contacts.common.model.RawContactDelta; import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.ContactsUtils; Loading @@ -44,6 +48,7 @@ public class PhotoEditorView extends LinearLayout implements Editor { private ValuesDelta mEntry; private EditorListener mListener; private View mTriangleAffordance; private ContactPhotoManager mContactPhotoManager; private boolean mHasSetPhoto = false; private boolean mReadOnly; Loading Loading @@ -72,6 +77,7 @@ public class PhotoEditorView extends LinearLayout implements Editor { @Override protected void onFinishInflate() { super.onFinishInflate(); mContactPhotoManager = ContactPhotoManager.getInstance(mContext); mTriangleAffordance = findViewById(R.id.photo_triangle_affordance); mPhotoImageView = (ImageView) findViewById(R.id.photo); mFrameView = findViewById(R.id.frame); Loading Loading @@ -111,6 +117,20 @@ public class PhotoEditorView extends LinearLayout implements Editor { mFrameView.setEnabled(isEnabled()); mHasSetPhoto = true; mEntry.setFromTemplate(false); if (values.getAfter() == null || values.getAfter().get(Photo.PHOTO) == null) { // If the user hasn't updated the PHOTO value, then PHOTO_FILE_ID may contain // a reference to a larger version of PHOTO that we can bind to the UI. // Otherwise, we need to wait for a call to #setFullSizedPhoto() to update // our full sized image. final Integer photoFileId = values.getAsInteger(Photo.PHOTO_FILE_ID); if (photoFileId != null) { final Uri photoUri = DisplayPhoto.CONTENT_URI.buildUpon() .appendPath(photoFileId.toString()).build(); setFullSizedPhoto(photoUri); } } } else { resetDefault(); } Loading @@ -127,10 +147,10 @@ public class PhotoEditorView extends LinearLayout implements Editor { } /** * Assign the given {@link Bitmap} as the new value, updating UI and * readying for persisting through {@link ValuesDelta}. * Assign the given {@link Bitmap} as the new value for the sake of building * {@link ValuesDelta}. We may as well bind a thumbnail to the UI while we are at it. */ public void setPhotoBitmap(Bitmap photo) { public void setPhotoEntry(Bitmap photo) { if (photo == null) { // Clear any existing photo and return mEntry.put(Photo.PHOTO, (byte[])null); Loading @@ -138,7 +158,10 @@ public class PhotoEditorView extends LinearLayout implements Editor { return; } mPhotoImageView.setImageBitmap(photo); final int size = ContactsUtils.getThumbnailSize(getContext()); final Bitmap scaled = Bitmap.createScaledBitmap(photo, size, size, false); mPhotoImageView.setImageBitmap(scaled); mFrameView.setEnabled(isEnabled()); mHasSetPhoto = true; mEntry.setFromTemplate(false); Loading @@ -152,10 +175,29 @@ public class PhotoEditorView extends LinearLayout implements Editor { // code all over the place, because we don't have to test whether // there is a change in EITHER the delta-list OR a changed photo... // this way, there is always a change in the delta-list. final int size = ContactsUtils.getThumbnailSize(getContext()); final Bitmap scaled = Bitmap.createScaledBitmap(photo, size, size, false); final byte[] compressed = ContactPhotoUtils.compressBitmap(scaled); if (compressed != null) mEntry.setPhoto(compressed); if (compressed != null) { mEntry.setPhoto(compressed); } } /** * Bind the {@param photoUri}'s photo to editor's UI. This doesn't affect {@link ValuesDelta}. */ public void setFullSizedPhoto(Uri photoUri) { if (photoUri != null) { final DefaultImageProvider fallbackToPreviousImage = new DefaultImageProvider() { @Override public void applyDefaultImage(ImageView view, int extent, boolean darkTheme, DefaultImageRequest defaultImageRequest) { // Before we finish setting the full sized image, don't change the current // image that is set in any way. } }; mContactPhotoManager.loadPhoto(mPhotoImageView, photoUri, mPhotoImageView.getWidth(), /* darkTheme = */ false, /* isCircular = */ false, /* defaultImageRequest = */ null, fallbackToPreviousImage); } } /** Loading