ContactEditorFragment.java revision e3373dceb689209533e95a2cfbfbf1d9008ab6f6
1cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann/* 2ef3f8f045ed4150caa64749742227acd0e6b85d8Daniel Lehmann * Copyright (C) 2010 The Android Open Source Project 3cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann * 4cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann * Licensed under the Apache License, Version 2.0 (the "License"); 5cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann * you may not use this file except in compliance with the License. 6cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann * You may obtain a copy of the License at 7cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann * 8cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann * http://www.apache.org/licenses/LICENSE-2.0 9cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann * 10cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann * Unless required by applicable law or agreed to in writing, software 11cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann * distributed under the License is distributed on an "AS IS" BASIS, 12cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann * See the License for the specific language governing permissions and 14cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann * limitations under the License 15cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann */ 16cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann 1718ffaa2561cc7dd2e3ef81737e6537931c0a9a11Dmitri Plotnikovpackage com.android.contacts.editor; 18cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann 19cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmannimport android.app.Activity; 20cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmannimport android.content.Context; 21cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmannimport android.content.Intent; 22f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmannimport android.graphics.Bitmap; 23cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmannimport android.net.Uri; 24cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmannimport android.os.Bundle; 2591004b37683c15650eccde68ff04defcf94a1c84Maurice Chuimport android.provider.ContactsContract.CommonDataKinds.Photo; 26688c228b2d7cf0c812fb673451f24e7cb457d63bYorke Leeimport android.text.TextUtils; 27cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmannimport android.util.Log; 28cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmannimport android.view.LayoutInflater; 29655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wangimport android.view.MenuItem; 30cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmannimport android.view.View; 31cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmannimport android.view.ViewGroup; 32d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawaimport android.widget.AdapterView; 3380d527c94389cab477e2c75ded03eec877ea6835Daniel Lehmannimport android.widget.LinearLayout; 34d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawaimport android.widget.ListPopupWindow; 35cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann 36e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.ContactSaveService; 37e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.R; 38e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.activities.ContactEditorActivity; 3991cee2852497e918e9e04a6fb549c1117ed47ae0Tingting Wangimport com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor; 4044cfc56d1701629070384364416c1311b780535dChiao Chengimport com.android.contacts.common.model.AccountTypeManager; 4192101e77238e450dedb56814cec80edc0adf79c0Walter Jangimport com.android.contacts.common.model.RawContactDelta; 4292101e77238e450dedb56814cec80edc0adf79c0Walter Jangimport com.android.contacts.common.model.RawContactDeltaList; 4344cfc56d1701629070384364416c1311b780535dChiao Chengimport com.android.contacts.common.model.ValuesDelta; 4444cfc56d1701629070384364416c1311b780535dChiao Chengimport com.android.contacts.common.model.account.AccountType; 4544cfc56d1701629070384364416c1311b780535dChiao Chengimport com.android.contacts.common.model.account.AccountWithDataSet; 4644cfc56d1701629070384364416c1311b780535dChiao Chengimport com.android.contacts.common.util.AccountsListAdapter; 4744cfc56d1701629070384364416c1311b780535dChiao Chengimport com.android.contacts.common.util.AccountsListAdapter.AccountListFilter; 48e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.detail.PhotoSelectionHandler; 49e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.editor.Editor.EditorListener; 50e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.util.ContactPhotoUtils; 5186625158bdc52855c37e96bf098ba7a213c810d7Chiao Chengimport com.android.contacts.util.UiClosables; 5292101e77238e450dedb56814cec80edc0adf79c0Walter Jang 53637a38ec9de6b1f434d7a13105f2e747faae5107Yorke Leeimport java.io.FileNotFoundException; 54f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmannimport java.util.Collections; 55daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwellimport java.util.HashMap; 56f491ae914769f1062a4d9c31fcbec5ff0e01e4e6Dmitri Plotnikovimport java.util.List; 57f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann 583f990ba4e35a99078d831c041290e574a320caa5Walter Jang/** 593f990ba4e35a99078d831c041290e574a320caa5Walter Jang * Contact editor with all fields displayed. 603f990ba4e35a99078d831c041290e574a320caa5Walter Jang */ 613f990ba4e35a99078d831c041290e574a320caa5Walter Jangpublic class ContactEditorFragment extends ContactEditorBaseFragment implements 622b3ee0f34801444c7d775ce747125459f69712bbDaniel Lehmann RawContactReadOnlyEditorView.Listener { 63cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann 64daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell private static final String KEY_EXPANDED_EDITORS = "expandedEditors"; 65f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann 66cf718aa47c11453925bb20f7970ca7c897f6e376Walter Jang private static final String KEY_RAW_CONTACT_ID_REQUESTING_PHOTO = "photorequester"; 67cf718aa47c11453925bb20f7970ca7c897f6e376Walter Jang private static final String KEY_CURRENT_PHOTO_URI = "currentphotouri"; 6828a27279554af7b1e5ff664d3da97954c462a797Walter Jang private static final String KEY_UPDATED_PHOTOS = "updatedPhotos"; 69cf718aa47c11453925bb20f7970ca7c897f6e376Walter Jang 70fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang // Used to store which raw contact editors have been expanded. Keyed on raw contact ids. 71fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang private HashMap<Long, Boolean> mExpandedEditors = new HashMap<Long, Boolean>(); 72fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang 73fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang /** 74fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang * The raw contact for which we started "take photo" or "choose photo from gallery" most 75fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang * recently. Used to restore {@link #mCurrentPhotoHandler} after orientation change. 76fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang */ 77fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang private long mRawContactIdRequestingPhoto; 7844cfc56d1701629070384364416c1311b780535dChiao Cheng 79fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang /** 80fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang * The {@link PhotoHandler} for the photo editor for the {@link #mRawContactIdRequestingPhoto} 81fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang * raw contact. 82fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang * 83fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang * A {@link PhotoHandler} is created for each photo editor in {@link #bindPhotoHandler}, but 84fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang * the only "active" one should get the activity result. This member represents the active 85fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang * one. 86fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang */ 87fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang private PhotoHandler mCurrentPhotoHandler; 88fb5dc6f857104c38ff49993d7498e8aa5fbc462eWalter Jang private Uri mCurrentPhotoUri; 8928a27279554af7b1e5ff664d3da97954c462a797Walter Jang private Bundle mUpdatedPhotos = new Bundle(); 90daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell 91cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann public ContactEditorFragment() { 92cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann } 93cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann 94cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann @Override 95cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { 96cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann final View view = inflater.inflate(R.layout.contact_editor_fragment, container, false); 97cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann 98f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann mContent = (LinearLayout) view.findViewById(R.id.editors); 99e8767a1136d2a2f9cb3e3ca5f44b2142baab9709Daniel Lehmann 1003648d2ea76a6649230d1fdd3dba92797ae7cfb26Daniel Lehmann setHasOptionsMenu(true); 101cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann 102cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann return view; 103cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann } 104cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann 105222744ea3cd7233677f0ef88804eb3e2db710e43Daniel Lehmann @Override 106f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann public void onCreate(Bundle savedState) { 107f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann super.onCreate(savedState); 108f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann 109ba59deb669cf377bedf08af53c9196db3c1cc404Walter Jang if (savedState != null) { 110daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell mExpandedEditors = (HashMap<Long, Boolean>) 111daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell savedState.getSerializable(KEY_EXPANDED_EDITORS); 112cf718aa47c11453925bb20f7970ca7c897f6e376Walter Jang mRawContactIdRequestingPhoto = savedState.getLong( 113cf718aa47c11453925bb20f7970ca7c897f6e376Walter Jang KEY_RAW_CONTACT_ID_REQUESTING_PHOTO); 114cf718aa47c11453925bb20f7970ca7c897f6e376Walter Jang mCurrentPhotoUri = savedState.getParcelable(KEY_CURRENT_PHOTO_URI); 11528a27279554af7b1e5ff664d3da97954c462a797Walter Jang mUpdatedPhotos = savedState.getParcelable(KEY_UPDATED_PHOTOS); 116655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang mRawContactIdToDisplayAlone = savedState.getLong( 117c683d2273c4174c0e300ef2f4b17c77fb313da39Tingting Wang ContactEditorBaseFragment.INTENT_EXTRA_RAW_CONTACT_ID_TO_DISPLAY_ALONE, -1); 118655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang } 119655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang } 120655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang 121655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang @Override 122655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang public void load(String action, Uri lookupUri, Bundle intentExtras) { 123655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang super.load(action, lookupUri, intentExtras); 124655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang if (intentExtras != null) { 125655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang mRawContactIdToDisplayAlone = intentExtras.getLong( 126c683d2273c4174c0e300ef2f4b17c77fb313da39Tingting Wang ContactEditorBaseFragment.INTENT_EXTRA_RAW_CONTACT_ID_TO_DISPLAY_ALONE, -1); 1275a7a23bdb698b8e741a425c9617c5e33e6314cddWalter Jang } 1285a7a23bdb698b8e741a425c9617c5e33e6314cddWalter Jang } 1295a7a23bdb698b8e741a425c9617c5e33e6314cddWalter Jang 1305a7a23bdb698b8e741a425c9617c5e33e6314cddWalter Jang @Override 131d675315606e8be431e6e5487e0b1cc33036a6ed7Walter Jang public void onStart() { 132d675315606e8be431e6e5487e0b1cc33036a6ed7Walter Jang getLoaderManager().initLoader(LOADER_GROUPS, null, mGroupsLoaderListener); 133d675315606e8be431e6e5487e0b1cc33036a6ed7Walter Jang super.onStart(); 134d675315606e8be431e6e5487e0b1cc33036a6ed7Walter Jang } 135d675315606e8be431e6e5487e0b1cc33036a6ed7Walter Jang 136d675315606e8be431e6e5487e0b1cc33036a6ed7Walter Jang @Override 1372b3f3c54d3beb017b2f59f19e9ce0ecc3e039dbcDave Santoro public void onExternalEditorRequest(AccountWithDataSet account, Uri uri) { 138a69f58fcf5c143ac7dd6421a30004d56813e321aWalter Jang if (mListener != null) { 139a69f58fcf5c143ac7dd6421a30004d56813e321aWalter Jang mListener.onCustomEditContactActivityRequested(account, uri, null, false); 140a69f58fcf5c143ac7dd6421a30004d56813e321aWalter Jang } 141fff6f07a02d3e3bbeff2ecf94a703782b71aea66Dmitri Plotnikov } 142fff6f07a02d3e3bbeff2ecf94a703782b71aea66Dmitri Plotnikov 143daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell @Override 144daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell public void onEditorExpansionChanged() { 145daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell updatedExpandedEditorsMap(); 146daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell } 147daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell 148ba59deb669cf377bedf08af53c9196db3c1cc404Walter Jang @Override 14992f8ccc1f15df787b7434224857c056721281046Walter Jang protected void setGroupMetaData() { 15092f8ccc1f15df787b7434224857c056721281046Walter Jang if (mGroupMetaData == null) { 15192f8ccc1f15df787b7434224857c056721281046Walter Jang return; 15292f8ccc1f15df787b7434224857c056721281046Walter Jang } 15392f8ccc1f15df787b7434224857c056721281046Walter Jang int editorCount = mContent.getChildCount(); 15492f8ccc1f15df787b7434224857c056721281046Walter Jang for (int i = 0; i < editorCount; i++) { 15592f8ccc1f15df787b7434224857c056721281046Walter Jang BaseRawContactEditorView editor = (BaseRawContactEditorView) mContent.getChildAt(i); 15692f8ccc1f15df787b7434224857c056721281046Walter Jang editor.setGroupMetaData(mGroupMetaData); 15792f8ccc1f15df787b7434224857c056721281046Walter Jang } 15892f8ccc1f15df787b7434224857c056721281046Walter Jang } 15992f8ccc1f15df787b7434224857c056721281046Walter Jang 16092f8ccc1f15df787b7434224857c056721281046Walter Jang @Override 161655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang public boolean onOptionsItemSelected(MenuItem item) { 162655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang if (item.getItemId() == android.R.id.home) { 163655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang return revert(); 164655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang } 165655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang return super.onOptionsItemSelected(item); 166655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang } 167655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang 168655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang @Override 169ba59deb669cf377bedf08af53c9196db3c1cc404Walter Jang protected void bindEditors() { 1705671c7e7718c3285dc0391807401083986fcfd51Maurice Chu // bindEditors() can only bind views if there is data in mState, so immediately return 1715671c7e7718c3285dc0391807401083986fcfd51Maurice Chu // if mState is null 17244cfc56d1701629070384364416c1311b780535dChiao Cheng if (mState.isEmpty()) { 17344cfc56d1701629070384364416c1311b780535dChiao Cheng return; 17444cfc56d1701629070384364416c1311b780535dChiao Cheng } 17544cfc56d1701629070384364416c1311b780535dChiao Cheng 17644cfc56d1701629070384364416c1311b780535dChiao Cheng // Check if delta list is ready. Delta list is populated from existing data and when 17744cfc56d1701629070384364416c1311b780535dChiao Cheng // editing an read-only contact, it's also populated with newly created data for the 17844cfc56d1701629070384364416c1311b780535dChiao Cheng // blank form. When the data is not ready, skip. This method will be called multiple times. 17944cfc56d1701629070384364416c1311b780535dChiao Cheng if ((mIsEdit && !mExistingContactDataReady) || (mHasNewContact && !mNewContactDataReady)) { 1805671c7e7718c3285dc0391807401083986fcfd51Maurice Chu return; 1815671c7e7718c3285dc0391807401083986fcfd51Maurice Chu } 1825671c7e7718c3285dc0391807401083986fcfd51Maurice Chu 183f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann // Sort the editors 184f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann Collections.sort(mState, mComparator); 185cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann 186f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann // Remove any existing editors and rebuild any visible 187f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann mContent.removeAllViews(); 188cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann 189f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( 190f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann Context.LAYOUT_INFLATER_SERVICE); 191a07fa5f37031e4c5cd2933de02d2db41ec153e2bDmitri Plotnikov final AccountTypeManager accountTypes = AccountTypeManager.getInstance(mContext); 192a94859f61c216d4e137a631995026d3ddefbbf70Katherine Kuan int numRawContacts = mState.size(); 19344cfc56d1701629070384364416c1311b780535dChiao Cheng 194a94859f61c216d4e137a631995026d3ddefbbf70Katherine Kuan for (int i = 0; i < numRawContacts; i++) { 195f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann // TODO ensure proper ordering of entities in the list 196851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final RawContactDelta rawContactDelta = mState.get(i); 197851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu if (!rawContactDelta.isVisible()) continue; 198f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann 199851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final AccountType type = rawContactDelta.getAccountType(accountTypes); 200851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final long rawContactId = rawContactDelta.getRawContactId(); 201f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann 202655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang if (mRawContactIdToDisplayAlone != -1 && mRawContactIdToDisplayAlone != rawContactId) { 203655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang continue; 204655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang } 205655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang 20672af89f9e497bb8ef54fe3deeec7e8477d192242Daniel Lehmann final BaseRawContactEditorView editor; 2072b3ee0f34801444c7d775ce747125459f69712bbDaniel Lehmann if (!type.areContactsWritable()) { 208fff6f07a02d3e3bbeff2ecf94a703782b71aea66Dmitri Plotnikov editor = (BaseRawContactEditorView) inflater.inflate( 2092b3ee0f34801444c7d775ce747125459f69712bbDaniel Lehmann R.layout.raw_contact_readonly_editor_view, mContent, false); 210fff6f07a02d3e3bbeff2ecf94a703782b71aea66Dmitri Plotnikov } else { 211fd70903236883f47b21f23b8cb49a1ccacdfcdf1Katherine Kuan editor = (RawContactEditorView) inflater.inflate(R.layout.raw_contact_editor_view, 212fd70903236883f47b21f23b8cb49a1ccacdfcdf1Katherine Kuan mContent, false); 213cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann } 214daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell editor.setListener(this); 215daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell final List<AccountWithDataSet> accounts = AccountTypeManager.getInstance(mContext) 216daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell .getAccounts(true); 217daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell if (mHasNewContact && !mNewLocalProfile && accounts.size() > 1) { 218daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell addAccountSwitcher(mState.get(0), editor); 219d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa } 220a94859f61c216d4e137a631995026d3ddefbbf70Katherine Kuan 221b55107303cc46906c265582a8931172f13d684b6Walter Jang editor.setEnabled(isEnabled()); 222cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann 223655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang if (mRawContactIdToDisplayAlone != -1) { 224655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang editor.setCollapsed(false); 225655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang } else if (mExpandedEditors.containsKey(rawContactId)) { 226daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell editor.setCollapsed(mExpandedEditors.get(rawContactId)); 227daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell } else { 228daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell // By default, only the first editor will be expanded. 229daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell editor.setCollapsed(i != 0); 230daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell } 231daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell 232f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann mContent.addView(editor); 2337d901bb3d4118762e21f4db19e35fc937dcf96feDmitri Plotnikov 234851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu editor.setState(rawContactDelta, type, mViewIdGenerator, isEditingUserProfile()); 235655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang if (mRawContactIdToDisplayAlone != -1) { 236655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang editor.setCollapsible(false); 237655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang } else { 238655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang editor.setCollapsible(numRawContacts > 1); 239655ad1a2eeb36171d5f6e407bf7704f56f5583caTingting Wang } 240f491ae914769f1062a4d9c31fcbec5ff0e01e4e6Dmitri Plotnikov 2416fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro // Set up the photo handler. 2426fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro bindPhotoHandler(editor, type, mState); 2436fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro 244c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell // If a new photo was chosen but not yet saved, we need to update the UI to 245c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell // reflect this. 246c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell final Uri photoUri = updatedPhotoUriForRawContact(rawContactId); 247c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell if (photoUri != null) editor.setFullSizedPhoto(photoUri); 24828eadab78531e22a0d9fa22fbbcd61c451005890Josh Gargus 24972af89f9e497bb8ef54fe3deeec7e8477d192242Daniel Lehmann if (editor instanceof RawContactEditorView) { 2502828c48cc4537fe981918f80297d5408bedc87b5Makoto Onuki final Activity activity = getActivity(); 25172af89f9e497bb8ef54fe3deeec7e8477d192242Daniel Lehmann final RawContactEditorView rawContactEditor = (RawContactEditorView) editor; 252151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang final ValuesDelta nameValuesDelta = rawContactEditor.getNameEditor().getValues(); 253151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang final EditorListener structuredNameListener = new EditorListener() { 254f491ae914769f1062a4d9c31fcbec5ff0e01e4e6Dmitri Plotnikov 255f491ae914769f1062a4d9c31fcbec5ff0e01e4e6Dmitri Plotnikov @Override 256f491ae914769f1062a4d9c31fcbec5ff0e01e4e6Dmitri Plotnikov public void onRequest(int request) { 257151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang // Make sure the activity is running 258151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang if (activity.isFinishing()) { 2592828c48cc4537fe981918f80297d5408bedc87b5Makoto Onuki return; 2602828c48cc4537fe981918f80297d5408bedc87b5Makoto Onuki } 261151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang if (!isEditingUserProfile()) { 262151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang if (request == EditorListener.FIELD_CHANGED) { 263151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang if (!nameValuesDelta.isSuperPrimary()) { 264151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang unsetSuperPrimaryForAllNameEditors(); 265151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang nameValuesDelta.setSuperPrimary(true); 266151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang } 267151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang acquireAggregationSuggestions(activity, 268151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang rawContactEditor.getNameEditor().getRawContactId(), 269151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang rawContactEditor.getNameEditor().getValues()); 270151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang } else if (request == EditorListener.FIELD_TURNED_EMPTY) { 271151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang if (nameValuesDelta.isSuperPrimary()) { 272151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang nameValuesDelta.setSuperPrimary(false); 273151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang } 274151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang } 275151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang } 276151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang } 277151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang 278151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang @Override 279151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang public void onDeleteRequested(Editor removedEditor) { 280151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang } 281151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang }; 2825ec40b04041818bc042c0671cb1a43b54f650e25Dmitri Plotnikov 28344cfc56d1701629070384364416c1311b780535dChiao Cheng final StructuredNameEditorView nameEditor = rawContactEditor.getNameEditor(); 284151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang nameEditor.setEditorListener(structuredNameListener); 285f491ae914769f1062a4d9c31fcbec5ff0e01e4e6Dmitri Plotnikov 2867d901bb3d4118762e21f4db19e35fc937dcf96feDmitri Plotnikov rawContactEditor.setAutoAddToDefaultGroup(mAutoAddToDefaultGroup); 2877d901bb3d4118762e21f4db19e35fc937dcf96feDmitri Plotnikov 288953cea238c9969fd7703fbce2bf8a915b5c38955Walter Jang if (!isEditingUserProfile() && isAggregationSuggestionRawContactId(rawContactId)) { 289d35e5eff8737e757a4179d49dfe9c7db999b4e9dWalter Jang acquireAggregationSuggestions(activity, 290d35e5eff8737e757a4179d49dfe9c7db999b4e9dWalter Jang rawContactEditor.getNameEditor().getRawContactId(), 291d35e5eff8737e757a4179d49dfe9c7db999b4e9dWalter Jang rawContactEditor.getNameEditor().getValues()); 292f491ae914769f1062a4d9c31fcbec5ff0e01e4e6Dmitri Plotnikov } 293f491ae914769f1062a4d9c31fcbec5ff0e01e4e6Dmitri Plotnikov } 294cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann } 295f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann 296b55107303cc46906c265582a8931172f13d684b6Walter Jang setGroupMetaData(); 297e843f916942fff482ec162eee2a23914e32182cfDmitri Plotnikov 298f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann // Show editor now that we've loaded state 299f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann mContent.setVisibility(View.VISIBLE); 300a35a7e2aabc4edfafb9b4171e279bdb4c0c03d44Daniel Lehmann 301a35a7e2aabc4edfafb9b4171e279bdb4c0c03d44Daniel Lehmann // Refresh Action Bar as the visibility of the join command 302825cb62b7df3cfe208651d488278e1b57c863884Daniel Lehmann // Activity can be null if we have been detached from the Activity 30392f8ccc1f15df787b7434224857c056721281046Walter Jang invalidateOptionsMenu(); 304daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell 305daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell updatedExpandedEditorsMap(); 306daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell } 307daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell 308151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang private void unsetSuperPrimaryForAllNameEditors() { 309151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang for (int i = 0; i < mContent.getChildCount(); i++) { 310151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang final View view = mContent.getChildAt(i); 311151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang if (view instanceof RawContactEditorView) { 312151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang final RawContactEditorView rawContactEditorView = (RawContactEditorView) view; 313151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang final StructuredNameEditorView nameEditorView = 314151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang rawContactEditorView.getNameEditor(); 315151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang if (nameEditorView != null) { 316151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang final ValuesDelta valuesDelta = nameEditorView.getValues(); 317151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang if (valuesDelta != null) { 318151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang valuesDelta.setSuperPrimary(false); 319151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang } 320151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang } 321151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang } 322151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang } 323151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang } 324151f3e6883e5785019f7b5083dc8baf3e305dc18Walter Jang 325daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell /** 326daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell * Update the values in {@link #mExpandedEditors}. 327daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell */ 328daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell private void updatedExpandedEditorsMap() { 329daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell for (int i = 0; i < mContent.getChildCount(); i++) { 330daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell final View childView = mContent.getChildAt(i); 331daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell if (childView instanceof BaseRawContactEditorView) { 332daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell BaseRawContactEditorView childEditor = (BaseRawContactEditorView) childView; 333daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell mExpandedEditors.put(childEditor.getRawContactId(), childEditor.isCollapsed()); 334daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell } 335daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell } 3366fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro } 337eeb68a341734ded343004d4eecb585420e70605bDmitri Plotnikov 33828eadab78531e22a0d9fa22fbbcd61c451005890Josh Gargus /** 339c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell * If we've stashed a temporary file containing a contact's new photo, return its URI. 34028eadab78531e22a0d9fa22fbbcd61c451005890Josh Gargus * @param rawContactId identifies the raw-contact whose Bitmap we'll try to return. 341c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell * @return Uru of photo for specified raw-contact, or null 342c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell */ 343c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell private Uri updatedPhotoUriForRawContact(long rawContactId) { 344c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell return (Uri) mUpdatedPhotos.get(String.valueOf(rawContactId)); 34528eadab78531e22a0d9fa22fbbcd61c451005890Josh Gargus } 34628eadab78531e22a0d9fa22fbbcd61c451005890Josh Gargus 3476fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro private void bindPhotoHandler(BaseRawContactEditorView editor, AccountType type, 348851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu RawContactDeltaList state) { 3496fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro final int mode; 35091cee2852497e918e9e04a6fb549c1117ed47ae0Tingting Wang boolean showIsPrimaryOption; 3516fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro if (type.areContactsWritable()) { 3526fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro if (editor.hasSetPhoto()) { 3537e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell mode = PhotoActionPopup.Modes.WRITE_ABLE_PHOTO; 3547e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell showIsPrimaryOption = hasMoreThanOnePhoto(); 3556fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro } else { 356ced983d7a816256d93fdea1f81e63e4598c18875Josh Gargus mode = PhotoActionPopup.Modes.NO_PHOTO; 3577e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell showIsPrimaryOption = false; 3586fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro } 3597e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell } else if (editor.hasSetPhoto() && hasMoreThanOnePhoto()) { 3607e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell mode = PhotoActionPopup.Modes.READ_ONLY_PHOTO; 3617e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell showIsPrimaryOption = true; 3626fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro } else { 3637e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell // Read-only and either no photo or the only photo ==> no options 3647e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell editor.getPhotoEditor().setEditorListener(null); 3657e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell editor.getPhotoEditor().setShowPrimary(false); 3667e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell return; 3676fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro } 36891cee2852497e918e9e04a6fb549c1117ed47ae0Tingting Wang if (mRawContactIdToDisplayAlone != -1) { 36991cee2852497e918e9e04a6fb549c1117ed47ae0Tingting Wang showIsPrimaryOption = false; 37091cee2852497e918e9e04a6fb549c1117ed47ae0Tingting Wang } 37191004b37683c15650eccde68ff04defcf94a1c84Maurice Chu final PhotoHandler photoHandler = new PhotoHandler(mContext, editor, mode, state); 3726fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro editor.getPhotoEditor().setEditorListener( 37391004b37683c15650eccde68ff04defcf94a1c84Maurice Chu (PhotoHandler.PhotoEditorListener) photoHandler.getListener()); 3747e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell editor.getPhotoEditor().setShowPrimary(showIsPrimaryOption); 3754bff8fb686f2ac5500109a32cca9270965c620d6Makoto Onuki 3764bff8fb686f2ac5500109a32cca9270965c620d6Makoto Onuki // Note a newly created raw contact gets some random negative ID, so any value is valid 3774bff8fb686f2ac5500109a32cca9270965c620d6Makoto Onuki // here. (i.e. don't check against -1 or anything.) 3784bff8fb686f2ac5500109a32cca9270965c620d6Makoto Onuki if (mRawContactIdRequestingPhoto == editor.getRawContactId()) { 3794bff8fb686f2ac5500109a32cca9270965c620d6Makoto Onuki mCurrentPhotoHandler = photoHandler; 3804bff8fb686f2ac5500109a32cca9270965c620d6Makoto Onuki } 381cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann } 382cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann 383d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa private void addAccountSwitcher( 384851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final RawContactDelta currentState, BaseRawContactEditorView editor) { 3852b3f3c54d3beb017b2f59f19e9ce0ecc3e039dbcDave Santoro final AccountWithDataSet currentAccount = new AccountWithDataSet( 386851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu currentState.getAccountName(), 387851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu currentState.getAccountType(), 388851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu currentState.getDataSet()); 389d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa final View accountView = editor.findViewById(R.id.account); 390daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell final View anchorView = editor.findViewById(R.id.account_selector_container); 391daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell if (accountView == null) { 392daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell return; 393daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell } 394daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell anchorView.setVisibility(View.VISIBLE); 395d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa accountView.setOnClickListener(new View.OnClickListener() { 396d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa @Override 397d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa public void onClick(View v) { 398d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa final ListPopupWindow popup = new ListPopupWindow(mContext, null); 399a6c8f2daa80f1816dd25237457d7f6287c6b1b7cDaisuke Miyakawa final AccountsListAdapter adapter = 4006f74c0f3313cbb08ee8a8fbb79bfefc5b03fe215Makoto Onuki new AccountsListAdapter(mContext, 4016f74c0f3313cbb08ee8a8fbb79bfefc5b03fe215Makoto Onuki AccountListFilter.ACCOUNTS_CONTACT_WRITABLE, currentAccount); 402d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa popup.setWidth(anchorView.getWidth()); 403d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa popup.setAnchorView(anchorView); 404d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa popup.setAdapter(adapter); 405d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa popup.setModal(true); 406d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED); 407d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa popup.setOnItemClickListener(new AdapterView.OnItemClickListener() { 408d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa @Override 409d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa public void onItemClick(AdapterView<?> parent, View view, int position, 410d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa long id) { 41186625158bdc52855c37e96bf098ba7a213c810d7Chiao Cheng UiClosables.closeQuietly(popup); 4122b3f3c54d3beb017b2f59f19e9ce0ecc3e039dbcDave Santoro AccountWithDataSet newAccount = adapter.getItem(position); 413d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa if (!newAccount.equals(currentAccount)) { 414d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa rebindEditorsForNewContact(currentState, currentAccount, newAccount); 415d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa } 416d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa } 417d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa }); 418d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa popup.show(); 419d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa } 420d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa }); 421d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa } 422d37a891cb44cd17083c06d7be693c469403d16dfDaisuke Miyakawa 423b85b83ee4adc8b72fe68499f669ca530d58e6815Daniel Lehmann @Override 424e3373dceb689209533e95a2cfbfbf1d9008ab6f6Walter Jang protected boolean doSaveAction(int saveMode, Long joinContactId) { 42528a27279554af7b1e5ff664d3da97954c462a797Walter Jang final Intent intent = ContactSaveService.createSaveContactIntent(mContext, mState, 426ebc17929007ecf12f25b8e90023766e8a083d11eJosh Gargus SAVE_MODE_EXTRA_KEY, saveMode, isEditingUserProfile(), 427921287ef72ca601027bf2971b0733493adde16d2Walter Jang ((Activity) mContext).getClass(), ContactEditorActivity.ACTION_SAVE_COMPLETED, 428e3373dceb689209533e95a2cfbfbf1d9008ab6f6Walter Jang mUpdatedPhotos, JOIN_CONTACT_ID_EXTRA_KEY, joinContactId); 429ebc17929007ecf12f25b8e90023766e8a083d11eJosh Gargus mContext.startService(intent); 430f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann return true; 431f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann } 432f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann 433ba59deb669cf377bedf08af53c9196db3c1cc404Walter Jang @Override 434f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann public void onSaveInstanceState(Bundle outState) { 435daa2058979fda84a0ce22e21edd53aa049e80aa0Brian Attwell outState.putSerializable(KEY_EXPANDED_EDITORS, mExpandedEditors); 436cf718aa47c11453925bb20f7970ca7c897f6e376Walter Jang outState.putLong(KEY_RAW_CONTACT_ID_REQUESTING_PHOTO, mRawContactIdRequestingPhoto); 437cf718aa47c11453925bb20f7970ca7c897f6e376Walter Jang outState.putParcelable(KEY_CURRENT_PHOTO_URI, mCurrentPhotoUri); 43828a27279554af7b1e5ff664d3da97954c462a797Walter Jang outState.putParcelable(KEY_UPDATED_PHOTOS, mUpdatedPhotos); 439ba6c41ca6da97f56f608a9ef92617f2401f8371eTingting Wang outState.putLong(ContactEditorBaseFragment.INTENT_EXTRA_RAW_CONTACT_ID_TO_DISPLAY_ALONE, 440ba6c41ca6da97f56f608a9ef92617f2401f8371eTingting Wang mRawContactIdToDisplayAlone); 441f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann super.onSaveInstanceState(outState); 442f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann } 443f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann 444d364314c460152db7089b304beec81b3675893baDmitri Plotnikov @Override 445f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann public void onActivityResult(int requestCode, int resultCode, Intent data) { 446f9ca423c867ab2cd4f0d9025a95436489c41d405Dmitri Plotnikov if (mStatus == Status.SUB_ACTIVITY) { 447f9ca423c867ab2cd4f0d9025a95436489c41d405Dmitri Plotnikov mStatus = Status.EDITING; 448f9ca423c867ab2cd4f0d9025a95436489c41d405Dmitri Plotnikov } 449f9ca423c867ab2cd4f0d9025a95436489c41d405Dmitri Plotnikov 4506fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro // See if the photo selection handler handles this result. 45191004b37683c15650eccde68ff04defcf94a1c84Maurice Chu if (mCurrentPhotoHandler != null && mCurrentPhotoHandler.handlePhotoActivityResult( 4526fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro requestCode, resultCode, data)) { 4536fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro return; 4546fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro } 455f319cf8549738feca5965a598af9a310869e1f3dDaniel Lehmann 4563e9a62449b8ca3a38b1d51019c6ea13972263bc2Walter Jang super.onActivityResult(requestCode, resultCode, data); 457cdef2b60aa87b1178033fdc964a3402386c03d7cDaniel Lehmann } 4589cd1708f333eda622dc6a4fed2a0df9058193a9dDmitri Plotnikov 45949ed2033f83005f92c30068ae33c3138d75e1825Walter Jang @Override 46049ed2033f83005f92c30068ae33c3138d75e1825Walter Jang protected void joinAggregate(final long contactId) { 46149ed2033f83005f92c30068ae33c3138d75e1825Walter Jang final Intent intent = ContactSaveService.createJoinContactsIntent( 462d3946cae17273ed1c2fceb507990882e3f828ba9Brian Attwell mContext, mContactIdForJoin, contactId, ContactEditorActivity.class, 463d3946cae17273ed1c2fceb507990882e3f828ba9Brian Attwell ContactEditorActivity.ACTION_JOIN_COMPLETED); 46449ed2033f83005f92c30068ae33c3138d75e1825Walter Jang mContext.startService(intent); 46549ed2033f83005f92c30068ae33c3138d75e1825Walter Jang } 46649ed2033f83005f92c30068ae33c3138d75e1825Walter Jang 467c1406450bb2a1a214ff35e99a173ee1a28b926faDaniel Lehmann /** 468c1406450bb2a1a214ff35e99a173ee1a28b926faDaniel Lehmann * Sets the photo stored in mPhoto and writes it to the RawContact with the given id 469c1406450bb2a1a214ff35e99a173ee1a28b926faDaniel Lehmann */ 470637a38ec9de6b1f434d7a13105f2e747faae5107Yorke Lee private void setPhoto(long rawContact, Bitmap photo, Uri photoUri) { 471bd0c12c63bb0adbc78715d9d13ba588c8ae61839Dmitri Plotnikov BaseRawContactEditorView requestingEditor = getRawContactEditorView(rawContact); 472e692e010ca02200087997280e7c239ebf94aa8f9Josh Gargus 4733efae4aeae8715fbfcf67c56f123da49330ea01aWalter Jang if (photo == null || photo.getHeight() <= 0 || photo.getWidth() <= 0) { 474e692e010ca02200087997280e7c239ebf94aa8f9Josh Gargus // This is unexpected. 475e692e010ca02200087997280e7c239ebf94aa8f9Josh Gargus Log.w(TAG, "Invalid bitmap passed to setPhoto()"); 476e692e010ca02200087997280e7c239ebf94aa8f9Josh Gargus } 477e692e010ca02200087997280e7c239ebf94aa8f9Josh Gargus 4789302ba7bc47d995c88eba7604aeea00a7e41779fDmitri Plotnikov if (requestingEditor != null) { 479c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell requestingEditor.setPhotoEntry(photo); 4807e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell // Immediately set all other photos as non-primary. Otherwise the UI can display 4817e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell // multiple photos as "Primary photo". 4827e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell for (int i = 0; i < mContent.getChildCount(); i++) { 4837e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell final View childView = mContent.getChildAt(i); 4847e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell if (childView instanceof BaseRawContactEditorView 4857e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell && childView != requestingEditor) { 4867e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell final BaseRawContactEditorView rawContactEditor 4877e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell = (BaseRawContactEditorView) childView; 4887e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell rawContactEditor.getPhotoEditor().setSuperPrimary(false); 4897e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell } 4907e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell } 4919302ba7bc47d995c88eba7604aeea00a7e41779fDmitri Plotnikov } else { 4929302ba7bc47d995c88eba7604aeea00a7e41779fDmitri Plotnikov Log.w(TAG, "The contact that requested the photo is no longer present."); 4939302ba7bc47d995c88eba7604aeea00a7e41779fDmitri Plotnikov } 494e692e010ca02200087997280e7c239ebf94aa8f9Josh Gargus 495637a38ec9de6b1f434d7a13105f2e747faae5107Yorke Lee mUpdatedPhotos.putParcelable(String.valueOf(rawContact), photoUri); 4969302ba7bc47d995c88eba7604aeea00a7e41779fDmitri Plotnikov } 4979302ba7bc47d995c88eba7604aeea00a7e41779fDmitri Plotnikov 4989302ba7bc47d995c88eba7604aeea00a7e41779fDmitri Plotnikov /** 4999302ba7bc47d995c88eba7604aeea00a7e41779fDmitri Plotnikov * Finds raw contact editor view for the given rawContactId. 5009302ba7bc47d995c88eba7604aeea00a7e41779fDmitri Plotnikov */ 501d35e5eff8737e757a4179d49dfe9c7db999b4e9dWalter Jang @Override 502d35e5eff8737e757a4179d49dfe9c7db999b4e9dWalter Jang protected View getAggregationAnchorView(long rawContactId) { 503d35e5eff8737e757a4179d49dfe9c7db999b4e9dWalter Jang BaseRawContactEditorView editorView = getRawContactEditorView(rawContactId); 504d35e5eff8737e757a4179d49dfe9c7db999b4e9dWalter Jang return editorView == null ? null : editorView.findViewById(R.id.anchor_view); 505d35e5eff8737e757a4179d49dfe9c7db999b4e9dWalter Jang } 506d35e5eff8737e757a4179d49dfe9c7db999b4e9dWalter Jang 507bd0c12c63bb0adbc78715d9d13ba588c8ae61839Dmitri Plotnikov public BaseRawContactEditorView getRawContactEditorView(long rawContactId) { 508c1406450bb2a1a214ff35e99a173ee1a28b926faDaniel Lehmann for (int i = 0; i < mContent.getChildCount(); i++) { 509c1406450bb2a1a214ff35e99a173ee1a28b926faDaniel Lehmann final View childView = mContent.getChildAt(i); 51072af89f9e497bb8ef54fe3deeec7e8477d192242Daniel Lehmann if (childView instanceof BaseRawContactEditorView) { 51172af89f9e497bb8ef54fe3deeec7e8477d192242Daniel Lehmann final BaseRawContactEditorView editor = (BaseRawContactEditorView) childView; 5129302ba7bc47d995c88eba7604aeea00a7e41779fDmitri Plotnikov if (editor.getRawContactId() == rawContactId) { 5139302ba7bc47d995c88eba7604aeea00a7e41779fDmitri Plotnikov return editor; 514c1406450bb2a1a214ff35e99a173ee1a28b926faDaniel Lehmann } 515c1406450bb2a1a214ff35e99a173ee1a28b926faDaniel Lehmann } 516c1406450bb2a1a214ff35e99a173ee1a28b926faDaniel Lehmann } 5179302ba7bc47d995c88eba7604aeea00a7e41779fDmitri Plotnikov return null; 518c1406450bb2a1a214ff35e99a173ee1a28b926faDaniel Lehmann } 519c1406450bb2a1a214ff35e99a173ee1a28b926faDaniel Lehmann 520fe22aff8c87374cfa80a7a02ec29b442f2453d8cDaniel Lehmann /** 521fe22aff8c87374cfa80a7a02ec29b442f2453d8cDaniel Lehmann * Returns true if there is currently more than one photo on screen. 522fe22aff8c87374cfa80a7a02ec29b442f2453d8cDaniel Lehmann */ 523fe22aff8c87374cfa80a7a02ec29b442f2453d8cDaniel Lehmann private boolean hasMoreThanOnePhoto() { 524fe22aff8c87374cfa80a7a02ec29b442f2453d8cDaniel Lehmann int countWithPicture = 0; 52591004b37683c15650eccde68ff04defcf94a1c84Maurice Chu final int numEntities = mState.size(); 52691004b37683c15650eccde68ff04defcf94a1c84Maurice Chu for (int i = 0; i < numEntities; i++) { 527851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final RawContactDelta entity = mState.get(i); 528851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu if (entity.isVisible()) { 52991004b37683c15650eccde68ff04defcf94a1c84Maurice Chu final ValuesDelta primary = entity.getPrimaryEntry(Photo.CONTENT_ITEM_TYPE); 530851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu if (primary != null && primary.getPhoto() != null) { 531fe22aff8c87374cfa80a7a02ec29b442f2453d8cDaniel Lehmann countWithPicture++; 53291004b37683c15650eccde68ff04defcf94a1c84Maurice Chu } else { 533851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu final long rawContactId = entity.getRawContactId(); 534637a38ec9de6b1f434d7a13105f2e747faae5107Yorke Lee final Uri uri = mUpdatedPhotos.getParcelable(String.valueOf(rawContactId)); 535637a38ec9de6b1f434d7a13105f2e747faae5107Yorke Lee if (uri != null) { 536637a38ec9de6b1f434d7a13105f2e747faae5107Yorke Lee try { 537637a38ec9de6b1f434d7a13105f2e747faae5107Yorke Lee mContext.getContentResolver().openInputStream(uri); 53891004b37683c15650eccde68ff04defcf94a1c84Maurice Chu countWithPicture++; 539637a38ec9de6b1f434d7a13105f2e747faae5107Yorke Lee } catch (FileNotFoundException e) { 54091004b37683c15650eccde68ff04defcf94a1c84Maurice Chu } 54191004b37683c15650eccde68ff04defcf94a1c84Maurice Chu } 54291004b37683c15650eccde68ff04defcf94a1c84Maurice Chu } 54391004b37683c15650eccde68ff04defcf94a1c84Maurice Chu 54491004b37683c15650eccde68ff04defcf94a1c84Maurice Chu if (countWithPicture > 1) { 54591004b37683c15650eccde68ff04defcf94a1c84Maurice Chu return true; 546fe22aff8c87374cfa80a7a02ec29b442f2453d8cDaniel Lehmann } 547fe22aff8c87374cfa80a7a02ec29b442f2453d8cDaniel Lehmann } 548fe22aff8c87374cfa80a7a02ec29b442f2453d8cDaniel Lehmann } 549fe22aff8c87374cfa80a7a02ec29b442f2453d8cDaniel Lehmann return false; 5509cd1708f333eda622dc6a4fed2a0df9058193a9dDmitri Plotnikov } 551222744ea3cd7233677f0ef88804eb3e2db710e43Daniel Lehmann 5526fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro /** 5536fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro * Custom photo handler for the editor. The inner listener that this creates also has a 5546fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro * reference to the editor and acts as an {@link EditorListener}, and uses that editor to hold 5556fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro * state information in several of the listener methods. 5566fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro */ 5576fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro private final class PhotoHandler extends PhotoSelectionHandler { 55828eadab78531e22a0d9fa22fbbcd61c451005890Josh Gargus 55928eadab78531e22a0d9fa22fbbcd61c451005890Josh Gargus final long mRawContactId; 560e5d3f897689c8ba0f275c7679c72eacb190ae9b8Josh Gargus private final BaseRawContactEditorView mEditor; 5614bff8fb686f2ac5500109a32cca9270965c620d6Makoto Onuki private final PhotoActionListener mPhotoEditorListener; 56228eadab78531e22a0d9fa22fbbcd61c451005890Josh Gargus 5636fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro public PhotoHandler(Context context, BaseRawContactEditorView editor, int photoMode, 564851222a96b5d68602fb361ea3527101e893f67e3Maurice Chu RawContactDeltaList state) { 5657e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell super(context, editor.getPhotoEditor().getChangeAnchorView(), photoMode, false, state); 566e5d3f897689c8ba0f275c7679c72eacb190ae9b8Josh Gargus mEditor = editor; 56728eadab78531e22a0d9fa22fbbcd61c451005890Josh Gargus mRawContactId = editor.getRawContactId(); 5689a409d474b2b4f2e4261657f864eeb866fcb8816Daniel Lehmann mPhotoEditorListener = new PhotoEditorListener(); 569e5d3f897689c8ba0f275c7679c72eacb190ae9b8Josh Gargus } 570e5d3f897689c8ba0f275c7679c72eacb190ae9b8Josh Gargus 571e5d3f897689c8ba0f275c7679c72eacb190ae9b8Josh Gargus @Override 572e5d3f897689c8ba0f275c7679c72eacb190ae9b8Josh Gargus public PhotoActionListener getListener() { 5739a409d474b2b4f2e4261657f864eeb866fcb8816Daniel Lehmann return mPhotoEditorListener; 574e5d3f897689c8ba0f275c7679c72eacb190ae9b8Josh Gargus } 575e5d3f897689c8ba0f275c7679c72eacb190ae9b8Josh Gargus 576e5d3f897689c8ba0f275c7679c72eacb190ae9b8Josh Gargus @Override 577637a38ec9de6b1f434d7a13105f2e747faae5107Yorke Lee public void startPhotoActivity(Intent intent, int requestCode, Uri photoUri) { 5784bff8fb686f2ac5500109a32cca9270965c620d6Makoto Onuki mRawContactIdRequestingPhoto = mEditor.getRawContactId(); 57991004b37683c15650eccde68ff04defcf94a1c84Maurice Chu mCurrentPhotoHandler = this; 580e5d3f897689c8ba0f275c7679c72eacb190ae9b8Josh Gargus mStatus = Status.SUB_ACTIVITY; 581637a38ec9de6b1f434d7a13105f2e747faae5107Yorke Lee mCurrentPhotoUri = photoUri; 582e5d3f897689c8ba0f275c7679c72eacb190ae9b8Josh Gargus ContactEditorFragment.this.startActivityForResult(intent, requestCode); 5839442ef4d2667eab16f65535b63757a7ffe4ccf69Daniel Lehmann } 5849442ef4d2667eab16f65535b63757a7ffe4ccf69Daniel Lehmann 5856fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro private final class PhotoEditorListener extends PhotoSelectionHandler.PhotoActionListener 5866fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro implements EditorListener { 587fe22aff8c87374cfa80a7a02ec29b442f2453d8cDaniel Lehmann 5886fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro @Override 5896fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro public void onRequest(int request) { 5906fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro if (!hasValidState()) return; 591a35a7e2aabc4edfafb9b4171e279bdb4c0c03d44Daniel Lehmann 5926fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro if (request == EditorListener.REQUEST_PICK_PHOTO) { 5936fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro onClick(mEditor.getPhotoEditor()); 5949442ef4d2667eab16f65535b63757a7ffe4ccf69Daniel Lehmann } 5957e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell if (request == EditorListener.REQUEST_PICK_PRIMARY_PHOTO) { 5967e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell useAsPrimaryChosen(); 5977e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell } 5989442ef4d2667eab16f65535b63757a7ffe4ccf69Daniel Lehmann } 599a35a7e2aabc4edfafb9b4171e279bdb4c0c03d44Daniel Lehmann 6006fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro @Override 6016fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro public void onDeleteRequested(Editor removedEditor) { 6026fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro // The picture cannot be deleted, it can only be removed, which is handled by 6036fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro // onRemovePictureChosen() 6046fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro } 605a35a7e2aabc4edfafb9b4171e279bdb4c0c03d44Daniel Lehmann 6066fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro /** 6076fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro * User has chosen to set the selected photo as the (super) primary photo 6086fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro */ 6097e67082d3f7c4ab56945040c0e4617b71c7e5f0bBrian Attwell public void useAsPrimaryChosen() { 6106fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro // Set the IsSuperPrimary for each editor 6116fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro int count = mContent.getChildCount(); 6126fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro for (int i = 0; i < count; i++) { 6136fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro final View childView = mContent.getChildAt(i); 6146fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro if (childView instanceof BaseRawContactEditorView) { 6156fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro final BaseRawContactEditorView editor = 6166fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro (BaseRawContactEditorView) childView; 6176fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro final PhotoEditorView photoEditor = editor.getPhotoEditor(); 6186fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro photoEditor.setSuperPrimary(editor == mEditor); 6196fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro } 6206fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro } 62191004b37683c15650eccde68ff04defcf94a1c84Maurice Chu bindEditors(); 6226fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro } 6239442ef4d2667eab16f65535b63757a7ffe4ccf69Daniel Lehmann 6246fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro /** 6256fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro * User has chosen to remove a picture 6266fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro */ 6276fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro @Override 6286fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro public void onRemovePictureChosen() { 629c300521331c04767cd19dfe05ab77567514bbaa0Brian Attwell mEditor.setPhotoEntry(null); 63028eadab78531e22a0d9fa22fbbcd61c451005890Josh Gargus 63128eadab78531e22a0d9fa22fbbcd61c451005890Josh Gargus // Prevent bitmap from being restored if rotate the device. 63228eadab78531e22a0d9fa22fbbcd61c451005890Josh Gargus // (only if we first chose a new photo before removing it) 63328eadab78531e22a0d9fa22fbbcd61c451005890Josh Gargus mUpdatedPhotos.remove(String.valueOf(mRawContactId)); 63491004b37683c15650eccde68ff04defcf94a1c84Maurice Chu bindEditors(); 6356fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro } 6366fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro 6376fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro @Override 638637a38ec9de6b1f434d7a13105f2e747faae5107Yorke Lee public void onPhotoSelected(Uri uri) throws FileNotFoundException { 639637a38ec9de6b1f434d7a13105f2e747faae5107Yorke Lee final Bitmap bitmap = ContactPhotoUtils.getBitmapFromUri(mContext, uri); 640637a38ec9de6b1f434d7a13105f2e747faae5107Yorke Lee setPhoto(mRawContactId, bitmap, uri); 64191004b37683c15650eccde68ff04defcf94a1c84Maurice Chu mCurrentPhotoHandler = null; 64291004b37683c15650eccde68ff04defcf94a1c84Maurice Chu bindEditors(); 6436fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro } 6446fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro 6456fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro @Override 646637a38ec9de6b1f434d7a13105f2e747faae5107Yorke Lee public Uri getCurrentPhotoUri() { 647637a38ec9de6b1f434d7a13105f2e747faae5107Yorke Lee return mCurrentPhotoUri; 6486fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro } 6496fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro 6506fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro @Override 6516fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro public void onPhotoSelectionDismissed() { 6526fa7384a1a5576ace18159de61af91c8b7c34dc6Dave Santoro // Nothing to do. 6539442ef4d2667eab16f65535b63757a7ffe4ccf69Daniel Lehmann } 6544a62be4f5a365e5afde71becfd446381f2baa494Daniel Lehmann } 6554a62be4f5a365e5afde71becfd446381f2baa494Daniel Lehmann } 6562ae666ec99ae9318936a9326e5243987e4e1c586Jeff Sharkey} 657