PhotoEditorView.java revision 3efae4aeae8715fbfcf67c56f123da49330ea01a
1aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey/* 2aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * Copyright (C) 2009 The Android Open Source Project 3aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * 4aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * Licensed under the Apache License, Version 2.0 (the "License"); 5aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * you may not use this file except in compliance with the License. 6aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * You may obtain a copy of the License at 7aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * 8aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * http://www.apache.org/licenses/LICENSE-2.0 9aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * 10aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * Unless required by applicable law or agreed to in writing, software 11aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * distributed under the License is distributed on an "AS IS" BASIS, 12aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * See the License for the specific language governing permissions and 14aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * limitations under the License. 15aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey */ 16aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey 1718ffaa2561cc7dd2e3ef81737e6537931c0a9a11Dmitri Plotnikovpackage com.android.contacts.editor; 18aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey 19aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.content.Context; 20aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.graphics.Bitmap; 21aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.graphics.BitmapFactory; 22c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwellimport android.net.Uri; 23aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.provider.ContactsContract.CommonDataKinds.Photo; 24c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwellimport android.provider.ContactsContract.DisplayPhoto; 25aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.util.AttributeSet; 266f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkeyimport android.view.View; 277e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwellimport android.widget.Button; 28aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkeyimport android.widget.ImageView; 29740552201d103b80bc49ea8a39a30536222672eaDaniel Lehmannimport android.widget.LinearLayout; 307e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwellimport android.widget.RadioButton; 31aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey 32e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.R; 33c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwellimport com.android.contacts.common.ContactPhotoManager.DefaultImageProvider; 34c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwellimport com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; 35cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.model.RawContactDelta; 36f677450d82e7b961fda2a18fea2ad51e88437e8bYorke Leeimport com.android.contacts.common.ContactPhotoManager; 37cd321f65f1e50409812976380ad1f0fdb3fa35cbYorke Leeimport com.android.contacts.common.ContactsUtils; 38738ff8623dc77dd91a1b9023861e924ba5e4c27eChiao Chengimport com.android.contacts.common.model.ValuesDelta; 39428f008513d1591cc08fcfe2cf0c9237fb313241Chiao Chengimport com.android.contacts.common.model.dataitem.DataKind; 40e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.util.ContactPhotoUtils; 41e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Cheng 42aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey/** 43aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey * Simple editor for {@link Photo}. 44aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey */ 45740552201d103b80bc49ea8a39a30536222672eaDaniel Lehmannpublic class PhotoEditorView extends LinearLayout implements Editor { 466f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey 47850a8cca21ffc35858d2d55914ccef50e811629aDaniel Lehmann private ImageView mPhotoImageView; 487e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell private Button mChangeButton; 497e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell private RadioButton mPrimaryCheckBox; 50850a8cca21ffc35858d2d55914ccef50e811629aDaniel Lehmann 51aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey private ValuesDelta mEntry; 526f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey private EditorListener mListener; 53c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell private ContactPhotoManager mContactPhotoManager; 546f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey 556f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey private boolean mHasSetPhoto = false; 56753b74fd68a610cc30d1c7aa851aba58983ac566Jeff Hamilton private boolean mReadOnly; 57aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey 58aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey public PhotoEditorView(Context context) { 59aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey super(context); 60aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey } 61aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey 62aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey public PhotoEditorView(Context context, AttributeSet attrs) { 63aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey super(context, attrs); 64aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey } 65aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey 6602bb1252aa990813fa9e86ad75c458acc15e6801Dmitri Plotnikov @Override 6702bb1252aa990813fa9e86ad75c458acc15e6801Dmitri Plotnikov public void setEnabled(boolean enabled) { 6802bb1252aa990813fa9e86ad75c458acc15e6801Dmitri Plotnikov super.setEnabled(enabled); 6902bb1252aa990813fa9e86ad75c458acc15e6801Dmitri Plotnikov } 7002bb1252aa990813fa9e86ad75c458acc15e6801Dmitri Plotnikov 7126918da1650c1ff7b6f92deb978ab976525c811aJosh Gargus @Override 7226918da1650c1ff7b6f92deb978ab976525c811aJosh Gargus public void editNewlyAddedField() { 7326918da1650c1ff7b6f92deb978ab976525c811aJosh Gargus // Never called, since the user never adds a new photo-editor; 7426918da1650c1ff7b6f92deb978ab976525c811aJosh Gargus // you can only change the picture in an existing editor. 7526918da1650c1ff7b6f92deb978ab976525c811aJosh Gargus } 7626918da1650c1ff7b6f92deb978ab976525c811aJosh Gargus 77aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey /** {@inheritDoc} */ 786f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey @Override 796f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey protected void onFinishInflate() { 806f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey super.onFinishInflate(); 81f140227beb6d9e78955a7676dc0dd3f793f72017Brian Attwell mContactPhotoManager = ContactPhotoManager.getInstance(getContext()); 82850a8cca21ffc35858d2d55914ccef50e811629aDaniel Lehmann mPhotoImageView = (ImageView) findViewById(R.id.photo); 837e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell mPrimaryCheckBox = (RadioButton) findViewById(R.id.primary_checkbox); 847e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell mChangeButton = (Button) findViewById(R.id.change_button); 85da71919dcd16754cb378fc664967f4b278431c70Brian Attwell mPrimaryCheckBox = (RadioButton) findViewById(R.id.primary_checkbox); 86da71919dcd16754cb378fc664967f4b278431c70Brian Attwell if (mChangeButton != null) { 87da71919dcd16754cb378fc664967f4b278431c70Brian Attwell mChangeButton.setOnClickListener(new OnClickListener() { 88da71919dcd16754cb378fc664967f4b278431c70Brian Attwell @Override 89da71919dcd16754cb378fc664967f4b278431c70Brian Attwell public void onClick(View v) { 90da71919dcd16754cb378fc664967f4b278431c70Brian Attwell if (mListener != null) { 91da71919dcd16754cb378fc664967f4b278431c70Brian Attwell mListener.onRequest(EditorListener.REQUEST_PICK_PHOTO); 92da71919dcd16754cb378fc664967f4b278431c70Brian Attwell } 93850a8cca21ffc35858d2d55914ccef50e811629aDaniel Lehmann } 94da71919dcd16754cb378fc664967f4b278431c70Brian Attwell }); 95da71919dcd16754cb378fc664967f4b278431c70Brian Attwell } 967e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell // Turn off own state management. We do this ourselves on rotation. 977e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell mPrimaryCheckBox.setSaveEnabled(false); 987e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell mPrimaryCheckBox.setOnClickListener(new OnClickListener() { 997e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell @Override 1007e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell public void onClick(View v) { 1017e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell if (mListener != null) { 1027e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell mListener.onRequest(EditorListener.REQUEST_PICK_PRIMARY_PHOTO); 1037e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell } 1047e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell } 1057e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell }); 1066f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey } 1076f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey 1086f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey /** {@inheritDoc} */ 109850a8cca21ffc35858d2d55914ccef50e811629aDaniel Lehmann @Override 110aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey public void onFieldChanged(String column, String value) { 111aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey throw new UnsupportedOperationException("Photos don't support direct field changes"); 112aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey } 113aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey 1146f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey /** {@inheritDoc} */ 115850a8cca21ffc35858d2d55914ccef50e811629aDaniel Lehmann @Override 116851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu public void setValues(DataKind kind, ValuesDelta values, RawContactDelta state, boolean readOnly, 1174b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki ViewIdGenerator vig) { 118aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey mEntry = values; 119753b74fd68a610cc30d1c7aa851aba58983ac566Jeff Hamilton mReadOnly = readOnly; 1204b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki 1214b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki setId(vig.getId(state, kind, values, 0)); 1224b722a93f1ecdeb2890fb7e5db4c22794bccfdcdMakoto Onuki 1237e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell mPrimaryCheckBox.setChecked(values != null && values.isSuperPrimary()); 1247e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell 125aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey if (values != null) { 126aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey // Try decoding photo if actual entry 127aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey final byte[] photoBytes = values.getAsByteArray(Photo.PHOTO); 128aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey if (photoBytes != null) { 129aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey final Bitmap photo = BitmapFactory.decodeByteArray(photoBytes, 0, 130aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey photoBytes.length); 131aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey 132850a8cca21ffc35858d2d55914ccef50e811629aDaniel Lehmann mPhotoImageView.setImageBitmap(photo); 1336f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey mHasSetPhoto = true; 134e86b928be36bb3e7136796ad519e736325d1d2b1Megha Joshi mEntry.setFromTemplate(false); 135c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell 136c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell if (values.getAfter() == null || values.getAfter().get(Photo.PHOTO) == null) { 137c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell // If the user hasn't updated the PHOTO value, then PHOTO_FILE_ID may contain 138c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell // a reference to a larger version of PHOTO that we can bind to the UI. 139c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell // Otherwise, we need to wait for a call to #setFullSizedPhoto() to update 140c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell // our full sized image. 141c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell final Integer photoFileId = values.getAsInteger(Photo.PHOTO_FILE_ID); 142c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell if (photoFileId != null) { 143c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell final Uri photoUri = DisplayPhoto.CONTENT_URI.buildUpon() 144c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell .appendPath(photoFileId.toString()).build(); 145c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell setFullSizedPhoto(photoUri); 146c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell } 147c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell } 148c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell 149aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey } else { 150aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey resetDefault(); 151aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey } 152aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey } else { 153aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey resetDefault(); 154aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey } 155aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey } 156aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey 1576f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey /** 1587e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell * Whether to display a "Primary photo" RadioButton. This is only needed if there are multiple 1597e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell * candidate photos. 1607e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell */ 1617e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell public void setShowPrimary(boolean showPrimaryCheckBox) { 1627e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell mPrimaryCheckBox.setVisibility(showPrimaryCheckBox ? View.VISIBLE : View.GONE); 1637e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell } 1647e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell 1657e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell /** 1666f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey * Return true if a valid {@link Photo} has been set. 1676f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey */ 1686f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey public boolean hasSetPhoto() { 1696f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey return mHasSetPhoto; 1706f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey } 1716f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey 172764637aba745612a9fdc07adb99c615263916fa8Josh Gargus /** 173c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell * Assign the given {@link Bitmap} as the new value for the sake of building 174c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell * {@link ValuesDelta}. We may as well bind a thumbnail to the UI while we are at it. 1756f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey */ 176c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell public void setPhotoEntry(Bitmap photo) { 1776f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey if (photo == null) { 1786f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey // Clear any existing photo and return 1796f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey mEntry.put(Photo.PHOTO, (byte[])null); 1806f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey resetDefault(); 1816f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey return; 1826f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey } 1836f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey 184c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell final int size = ContactsUtils.getThumbnailSize(getContext()); 185c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell final Bitmap scaled = Bitmap.createScaledBitmap(photo, size, size, false); 186c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell 187c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell mPhotoImageView.setImageBitmap(scaled); 188e692e010ca02200087997280e7c239ebf94aa8f9Josh Gargus mHasSetPhoto = true; 189e692e010ca02200087997280e7c239ebf94aa8f9Josh Gargus mEntry.setFromTemplate(false); 190e692e010ca02200087997280e7c239ebf94aa8f9Josh Gargus 191e692e010ca02200087997280e7c239ebf94aa8f9Josh Gargus // When the user chooses a new photo mark it as super primary 192851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu mEntry.setSuperPrimary(true); 193764637aba745612a9fdc07adb99c615263916fa8Josh Gargus 194764637aba745612a9fdc07adb99c615263916fa8Josh Gargus // Even though high-res photos cannot be saved by passing them via 195764637aba745612a9fdc07adb99c615263916fa8Josh Gargus // an EntityDeltaList (since they cause the Bundle size limit to be 196764637aba745612a9fdc07adb99c615263916fa8Josh Gargus // exceeded), we still pass a low-res thumbnail. This simplifies 197764637aba745612a9fdc07adb99c615263916fa8Josh Gargus // code all over the place, because we don't have to test whether 198764637aba745612a9fdc07adb99c615263916fa8Josh Gargus // there is a change in EITHER the delta-list OR a changed photo... 199764637aba745612a9fdc07adb99c615263916fa8Josh Gargus // this way, there is always a change in the delta-list. 200e5d3f897689c8ba0f275c7679c72eacb190ae9b8Josh Gargus final byte[] compressed = ContactPhotoUtils.compressBitmap(scaled); 201c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell if (compressed != null) { 202c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell mEntry.setPhoto(compressed); 203c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell } 204c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell } 205c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell 206c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell /** 207c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell * Bind the {@param photoUri}'s photo to editor's UI. This doesn't affect {@link ValuesDelta}. 208c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell */ 209c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell public void setFullSizedPhoto(Uri photoUri) { 210c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell if (photoUri != null) { 211c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell final DefaultImageProvider fallbackToPreviousImage = new DefaultImageProvider() { 212c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell @Override 213c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell public void applyDefaultImage(ImageView view, int extent, boolean darkTheme, 214c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell DefaultImageRequest defaultImageRequest) { 215c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell // Before we finish setting the full sized image, don't change the current 216c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell // image that is set in any way. 217c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell } 218c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell }; 219c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell mContactPhotoManager.loadPhoto(mPhotoImageView, photoUri, 220c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell mPhotoImageView.getWidth(), /* darkTheme = */ false, /* isCircular = */ false, 221c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell /* defaultImageRequest = */ null, fallbackToPreviousImage); 222c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell } 2236f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey } 2246f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey 225753b74fd68a610cc30d1c7aa851aba58983ac566Jeff Hamilton /** 226753b74fd68a610cc30d1c7aa851aba58983ac566Jeff Hamilton * Set the super primary bit on the photo. 227753b74fd68a610cc30d1c7aa851aba58983ac566Jeff Hamilton */ 228753b74fd68a610cc30d1c7aa851aba58983ac566Jeff Hamilton public void setSuperPrimary(boolean superPrimary) { 229753b74fd68a610cc30d1c7aa851aba58983ac566Jeff Hamilton mEntry.put(Photo.IS_SUPER_PRIMARY, superPrimary ? 1 : 0); 230753b74fd68a610cc30d1c7aa851aba58983ac566Jeff Hamilton } 231753b74fd68a610cc30d1c7aa851aba58983ac566Jeff Hamilton 232aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey protected void resetDefault() { 2336f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey // Invalid photo, show default "add photo" place-holder 234f677450d82e7b961fda2a18fea2ad51e88437e8bYorke Lee mPhotoImageView.setImageDrawable( 235f677450d82e7b961fda2a18fea2ad51e88437e8bYorke Lee ContactPhotoManager.getDefaultAvatarDrawableForContact(getResources(), false, null)); 2366f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey mHasSetPhoto = false; 237e86b928be36bb3e7136796ad519e736325d1d2b1Megha Joshi mEntry.setFromTemplate(true); 238aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey } 239aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey 2406f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey /** {@inheritDoc} */ 241850a8cca21ffc35858d2d55914ccef50e811629aDaniel Lehmann @Override 242aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey public void setEditorListener(EditorListener listener) { 2436f8d46b5fb96c2bead1317aae93a73fc89b093abJeff Sharkey mListener = listener; 244aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey } 245d25f958595b190586bd838d50718b1a2a3f0d417Dmitri Plotnikov 246d25f958595b190586bd838d50718b1a2a3f0d417Dmitri Plotnikov @Override 247d25f958595b190586bd838d50718b1a2a3f0d417Dmitri Plotnikov public void setDeletable(boolean deletable) { 248d25f958595b190586bd838d50718b1a2a3f0d417Dmitri Plotnikov // Photo is not deletable 249d25f958595b190586bd838d50718b1a2a3f0d417Dmitri Plotnikov } 2501b22073590c1801c3e6c7bde2f4636632a049f6cKatherine Kuan 2512591436971bad3050c85929c8e0c5a8d48111f88Katherine Kuan @Override 2522591436971bad3050c85929c8e0c5a8d48111f88Katherine Kuan public boolean isEmpty() { 2532591436971bad3050c85929c8e0c5a8d48111f88Katherine Kuan return !mHasSetPhoto; 2541b22073590c1801c3e6c7bde2f4636632a049f6cKatherine Kuan } 2552293e55d550fbc9974d1185960715e59acb14a85Katherine Kuan 2562293e55d550fbc9974d1185960715e59acb14a85Katherine Kuan @Override 2572293e55d550fbc9974d1185960715e59acb14a85Katherine Kuan public void deleteEditor() { 2582293e55d550fbc9974d1185960715e59acb14a85Katherine Kuan // Photo is not deletable 2592293e55d550fbc9974d1185960715e59acb14a85Katherine Kuan } 2602293e55d550fbc9974d1185960715e59acb14a85Katherine Kuan 2612293e55d550fbc9974d1185960715e59acb14a85Katherine Kuan @Override 2622293e55d550fbc9974d1185960715e59acb14a85Katherine Kuan public void clearAllFields() { 2632293e55d550fbc9974d1185960715e59acb14a85Katherine Kuan resetDefault(); 2642293e55d550fbc9974d1185960715e59acb14a85Katherine Kuan } 2657e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell 2667e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell /** 2677e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell * The change drop down menu should be anchored to this view. 2687e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell */ 2697e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell public View getChangeAnchorView() { 2707e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell return mChangeButton; 2717e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell } 272aad8848282f51d73ad308e9ad3ebcef592fa153fJeff Sharkey} 273