Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.contacts.editor; |
| 18 | |
Walter Jang | 49ed203 | 2015-02-11 20:09:05 -0800 | [diff] [blame] | 19 | import com.android.contacts.ContactSaveService; |
Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 20 | import com.android.contacts.R; |
Walter Jang | 49ed203 | 2015-02-11 20:09:05 -0800 | [diff] [blame] | 21 | import com.android.contacts.activities.CompactContactEditorActivity; |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 22 | import com.android.contacts.common.model.AccountTypeManager; |
| 23 | import com.android.contacts.common.model.RawContactDelta; |
| 24 | import com.android.contacts.common.model.RawContactDeltaList; |
Walter Jang | 151f3e6 | 2015-02-26 15:29:40 -0800 | [diff] [blame] | 25 | import com.android.contacts.common.model.ValuesDelta; |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 26 | import com.android.contacts.common.model.account.AccountType; |
Walter Jang | 36d6a16 | 2015-02-20 10:56:59 -0800 | [diff] [blame] | 27 | import com.android.contacts.common.util.ImplicitIntentsUtil; |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 28 | import com.android.contacts.detail.PhotoSelectionHandler; |
| 29 | import com.android.contacts.util.ContactPhotoUtils; |
Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 30 | |
Walter Jang | 49ed203 | 2015-02-11 20:09:05 -0800 | [diff] [blame] | 31 | import android.app.Activity; |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 32 | import android.content.Context; |
Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 33 | import android.content.Intent; |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 34 | import android.graphics.Bitmap; |
| 35 | import android.net.Uri; |
Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 36 | import android.os.Bundle; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 37 | import android.util.Log; |
Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 38 | import android.view.LayoutInflater; |
Walter Jang | 0e72ce9 | 2015-02-23 12:27:21 -0800 | [diff] [blame] | 39 | import android.view.Menu; |
| 40 | import android.view.MenuItem; |
Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 41 | import android.view.View; |
| 42 | import android.view.ViewGroup; |
| 43 | import android.widget.LinearLayout; |
| 44 | |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 45 | import java.io.FileNotFoundException; |
| 46 | |
Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 47 | /** |
| 48 | * Contact editor with only the most important fields displayed initially. |
| 49 | */ |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 50 | public class CompactContactEditorFragment extends ContactEditorBaseFragment implements |
Walter Jang | 0e72ce9 | 2015-02-23 12:27:21 -0800 | [diff] [blame] | 51 | CompactRawContactsEditorView.Listener, PhotoSourceDialogFragment.Listener { |
Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 52 | |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 53 | private static final String KEY_PHOTO_URI = "photo_uri"; |
| 54 | private static final String KEY_PHOTO_RAW_CONTACT_ID = "photo_raw_contact_id"; |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Displays a PopupWindow with photo edit options. |
| 58 | */ |
Walter Jang | 0e72ce9 | 2015-02-23 12:27:21 -0800 | [diff] [blame] | 59 | final class PhotoHandler extends PhotoSelectionHandler implements View.OnClickListener { |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Receiver of photo edit option callbacks. |
| 63 | */ |
| 64 | private final class PhotoListener extends PhotoActionListener { |
Walter Jang | 0e72ce9 | 2015-02-23 12:27:21 -0800 | [diff] [blame] | 65 | |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 66 | @Override |
| 67 | public void onRemovePictureChosen() { |
| 68 | getContent().setPhoto(/* bitmap =*/ null); |
| 69 | mUpdatedPhotos.remove(String.valueOf(mPhotoRawContactId)); |
Walter Jang | ebfe75b | 2015-03-12 15:31:21 -0700 | [diff] [blame] | 70 | |
| 71 | // Update the mode so the options change if user clicks the photo again |
| 72 | mPhotoMode = getPhotoMode(); |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public void onPhotoSelected(Uri uri) throws FileNotFoundException { |
| 77 | final Bitmap bitmap = ContactPhotoUtils.getBitmapFromUri(getActivity(), uri); |
| 78 | if (bitmap == null || bitmap.getHeight() <= 0 || bitmap.getWidth() <= 0) { |
| 79 | Log.w(TAG, "Invalid photo selected"); |
| 80 | } |
| 81 | getContent().setPhoto(bitmap); |
Walter Jang | 41b3ea1 | 2015-03-09 17:30:06 -0700 | [diff] [blame] | 82 | |
Walter Jang | 1e8801b | 2015-03-10 15:57:05 -0700 | [diff] [blame] | 83 | // Clear any previously saved full resolution photos under negative raw contact IDs |
| 84 | // so that we will use the newly selected photo, instead of an old one on rotations. |
| 85 | removeNewRawContactPhotos(); |
| 86 | |
Walter Jang | 41b3ea1 | 2015-03-09 17:30:06 -0700 | [diff] [blame] | 87 | // If a new photo was chosen but not yet saved, |
| 88 | // we need to update the UI immediately |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 89 | mUpdatedPhotos.putParcelable(String.valueOf(mPhotoRawContactId), uri); |
Walter Jang | 41b3ea1 | 2015-03-09 17:30:06 -0700 | [diff] [blame] | 90 | getContent().setFullSizePhoto(uri); |
Walter Jang | ebfe75b | 2015-03-12 15:31:21 -0700 | [diff] [blame] | 91 | |
| 92 | // Update the mode so the options change if user clicks the photo again |
| 93 | mPhotoMode = getPhotoMode(); |
Walter Jang | ac48ce4 | 2015-04-28 08:59:41 -0700 | [diff] [blame] | 94 | |
| 95 | // Re-create the photo handler so that any additional photo selections create a |
| 96 | // new temp file (and don't hit the one that was just added to the cache). |
| 97 | mPhotoHandler = createPhotoHandler(); |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public Uri getCurrentPhotoUri() { |
| 102 | return mPhotoUri; |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public void onPhotoSelectionDismissed() { |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | private PhotoListener mPhotoListener; |
Walter Jang | 0e72ce9 | 2015-02-23 12:27:21 -0800 | [diff] [blame] | 111 | private int mPhotoMode; |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 112 | |
Walter Jang | 0e72ce9 | 2015-02-23 12:27:21 -0800 | [diff] [blame] | 113 | public PhotoHandler(Context context, int photoMode, RawContactDeltaList state) { |
| 114 | // We pass a null changeAnchorView since we are overriding onClick so that we |
| 115 | // can show the photo options in a dialog instead of a ListPopupWindow (which would |
| 116 | // be anchored at changeAnchorView). |
| 117 | super(context, /* changeAnchorView =*/ null, photoMode, /* isDirectoryContact =*/ false, |
| 118 | state); |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 119 | mPhotoListener = new PhotoListener(); |
Walter Jang | 0e72ce9 | 2015-02-23 12:27:21 -0800 | [diff] [blame] | 120 | mPhotoMode = photoMode; |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public void onClick(View view) { |
| 125 | PhotoSourceDialogFragment.show(CompactContactEditorFragment.this, mPhotoMode); |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public PhotoActionListener getListener() { |
| 130 | return mPhotoListener; |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | protected void startPhotoActivity(Intent intent, int requestCode, Uri photoUri) { |
| 135 | mPhotoUri = photoUri; |
| 136 | mStatus = Status.SUB_ACTIVITY; |
| 137 | |
| 138 | CompactContactEditorFragment.this.startActivityForResult(intent, requestCode); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | private PhotoHandler mPhotoHandler; |
| 143 | private Uri mPhotoUri; |
| 144 | private long mPhotoRawContactId; |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 145 | |
| 146 | @Override |
| 147 | public void onCreate(Bundle savedState) { |
| 148 | super.onCreate(savedState); |
| 149 | |
| 150 | if (savedState != null) { |
| 151 | mPhotoUri = savedState.getParcelable(KEY_PHOTO_URI); |
| 152 | mPhotoRawContactId = savedState.getLong(KEY_PHOTO_RAW_CONTACT_ID); |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 156 | @Override |
Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 157 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { |
Walter Jang | ed8f6c9 | 2015-01-30 16:07:47 -0800 | [diff] [blame] | 158 | setHasOptionsMenu(true); |
| 159 | |
Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 160 | final View view = inflater.inflate( |
| 161 | R.layout.compact_contact_editor_fragment, container, false); |
| 162 | mContent = (LinearLayout) view.findViewById(R.id.editors); |
| 163 | return view; |
| 164 | } |
| 165 | |
Walter Jang | ed8f6c9 | 2015-01-30 16:07:47 -0800 | [diff] [blame] | 166 | @Override |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 167 | public void onSaveInstanceState(Bundle outState) { |
| 168 | outState.putParcelable(KEY_PHOTO_URI, mPhotoUri); |
| 169 | outState.putLong(KEY_PHOTO_RAW_CONTACT_ID, mPhotoRawContactId); |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 170 | super.onSaveInstanceState(outState); |
| 171 | } |
| 172 | |
| 173 | @Override |
Walter Jang | ed8f6c9 | 2015-01-30 16:07:47 -0800 | [diff] [blame] | 174 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 175 | if (mStatus == Status.SUB_ACTIVITY) { |
| 176 | mStatus = Status.EDITING; |
| 177 | } |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 178 | if (mPhotoHandler != null |
| 179 | && mPhotoHandler.handlePhotoActivityResult(requestCode, resultCode, data)) { |
| 180 | return; |
| 181 | } |
Walter Jang | ed8f6c9 | 2015-01-30 16:07:47 -0800 | [diff] [blame] | 182 | super.onActivityResult(requestCode, resultCode, data); |
| 183 | } |
| 184 | |
Walter Jang | ba59deb | 2015-01-26 11:23:48 -0800 | [diff] [blame] | 185 | @Override |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 186 | public void onStop() { |
| 187 | super.onStop(); |
| 188 | |
| 189 | // If anything was left unsaved, save it now |
| 190 | if (!getActivity().isChangingConfigurations() && mStatus == Status.EDITING) { |
| 191 | save(SaveMode.RELOAD); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | @Override |
Walter Jang | ba59deb | 2015-01-26 11:23:48 -0800 | [diff] [blame] | 196 | protected void bindEditors() { |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 197 | if (!isReadyToBindEditors()) { |
| 198 | return; |
| 199 | } |
| 200 | |
Walter Jang | d35e5ef | 2015-02-24 09:18:16 -0800 | [diff] [blame] | 201 | // Add input fields for the loaded Contact |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 202 | final CompactRawContactsEditorView editorView = getContent(); |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 203 | editorView.setListener(this); |
Walter Jang | 921287e | 2015-03-10 09:53:36 -0700 | [diff] [blame] | 204 | editorView.setState(mState, getMaterialPalette(), mViewIdGenerator); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 205 | |
Walter Jang | d35e5ef | 2015-02-24 09:18:16 -0800 | [diff] [blame] | 206 | // Set up the photo widget |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 207 | mPhotoHandler = createPhotoHandler(); |
| 208 | mPhotoRawContactId = editorView.getPhotoRawContactId(); |
Walter Jang | 1e8801b | 2015-03-10 15:57:05 -0700 | [diff] [blame] | 209 | if (mPhotoRawContactId < 0) { |
| 210 | // Since the raw contact IDs for new contacts are random negative numbers |
| 211 | // we consider any negative key a match |
| 212 | for (String key : mUpdatedPhotos.keySet()) { |
| 213 | try { |
| 214 | if (Integer.parseInt(key) < 0) { |
| 215 | editorView.setFullSizePhoto((Uri) mUpdatedPhotos.getParcelable(key)); |
| 216 | break; |
| 217 | } |
| 218 | } catch (NumberFormatException ignored) { |
| 219 | } |
| 220 | } |
| 221 | } else if (mUpdatedPhotos.containsKey(String.valueOf(mPhotoRawContactId))) { |
Walter Jang | 41b3ea1 | 2015-03-09 17:30:06 -0700 | [diff] [blame] | 222 | editorView.setFullSizePhoto((Uri) mUpdatedPhotos.getParcelable( |
| 223 | String.valueOf(mPhotoRawContactId))); |
| 224 | } |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 225 | editorView.setPhotoHandler(mPhotoHandler); |
| 226 | |
Walter Jang | d35e5ef | 2015-02-24 09:18:16 -0800 | [diff] [blame] | 227 | // The editor is ready now so make it visible |
| 228 | editorView.setEnabled(isEnabled()); |
| 229 | editorView.setVisibility(View.VISIBLE); |
| 230 | |
| 231 | // Refresh the ActionBar as the visibility of the join command |
| 232 | // Activity can be null if we have been detached from the Activity. |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 233 | invalidateOptionsMenu(); |
| 234 | } |
| 235 | |
| 236 | private boolean isReadyToBindEditors() { |
| 237 | if (mState.isEmpty()) { |
| 238 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 239 | Log.v(TAG, "No data to bind editors"); |
| 240 | } |
| 241 | return false; |
| 242 | } |
| 243 | if (mIsEdit && !mExistingContactDataReady) { |
| 244 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 245 | Log.v(TAG, "Existing contact data is not ready to bind editors."); |
| 246 | } |
| 247 | return false; |
| 248 | } |
| 249 | if (mHasNewContact && !mNewContactDataReady) { |
| 250 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 251 | Log.v(TAG, "New contact data is not ready to bind editors."); |
| 252 | } |
| 253 | return false; |
| 254 | } |
| 255 | return true; |
Walter Jang | ba59deb | 2015-01-26 11:23:48 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 258 | private PhotoHandler createPhotoHandler() { |
Walter Jang | ebfe75b | 2015-03-12 15:31:21 -0700 | [diff] [blame] | 259 | return new PhotoHandler(getActivity(), getPhotoMode(), mState); |
| 260 | } |
| 261 | |
| 262 | private int getPhotoMode() { |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 263 | // To determine the options that are available to the user to update their photo |
| 264 | // (i.e. the photo mode), check if any of the writable raw contacts has a photo set |
| 265 | Integer photoMode = null; |
| 266 | boolean hasWritableAccountType = false; |
| 267 | final AccountTypeManager accountTypes = AccountTypeManager.getInstance(mContext); |
| 268 | for (RawContactDelta rawContactDelta : mState) { |
| 269 | if (!rawContactDelta.isVisible()) { |
| 270 | continue; |
| 271 | } |
| 272 | final AccountType accountType = rawContactDelta.getAccountType(accountTypes); |
| 273 | if (accountType.areContactsWritable()) { |
| 274 | hasWritableAccountType = true; |
| 275 | if (getContent().isWritablePhotoSet()) { |
| 276 | photoMode = PhotoActionPopup.Modes.WRITE_ABLE_PHOTO; |
| 277 | break; |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | // If the mode was not set, base it on whether we saw a writable contact or not |
| 282 | if (photoMode == null) { |
| 283 | photoMode = hasWritableAccountType |
| 284 | ? PhotoActionPopup.Modes.NO_PHOTO : PhotoActionPopup.Modes.READ_ONLY_PHOTO; |
| 285 | } |
Walter Jang | ebfe75b | 2015-03-12 15:31:21 -0700 | [diff] [blame] | 286 | return photoMode; |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 287 | } |
| 288 | |
Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 289 | @Override |
Walter Jang | d35e5ef | 2015-02-24 09:18:16 -0800 | [diff] [blame] | 290 | protected View getAggregationAnchorView(long rawContactId) { |
| 291 | return getContent().getAggregationAnchorView(); |
| 292 | } |
| 293 | |
| 294 | @Override |
Walter Jang | 92f8ccc | 2015-02-06 10:23:37 -0800 | [diff] [blame] | 295 | protected void setGroupMetaData() { |
Walter Jang | 49ed203 | 2015-02-11 20:09:05 -0800 | [diff] [blame] | 296 | // The compact editor does not support groups. |
Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | @Override |
Walter Jang | b551073 | 2015-02-03 13:56:15 -0800 | [diff] [blame] | 300 | protected boolean doSaveAction(int saveMode) { |
Walter Jang | 921287e | 2015-03-10 09:53:36 -0700 | [diff] [blame] | 301 | // Save contact. No need to pass the palette since we are finished editing after the save. |
Walter Jang | 49ed203 | 2015-02-11 20:09:05 -0800 | [diff] [blame] | 302 | final Intent intent = ContactSaveService.createSaveContactIntent(mContext, mState, |
| 303 | SAVE_MODE_EXTRA_KEY, saveMode, isEditingUserProfile(), |
| 304 | ((Activity) mContext).getClass(), |
Walter Jang | 921287e | 2015-03-10 09:53:36 -0700 | [diff] [blame] | 305 | CompactContactEditorActivity.ACTION_SAVE_COMPLETED, mUpdatedPhotos); |
Walter Jang | 49ed203 | 2015-02-11 20:09:05 -0800 | [diff] [blame] | 306 | mContext.startService(intent); |
| 307 | |
| 308 | return true; |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | protected void joinAggregate(final long contactId) { |
| 313 | final Intent intent = ContactSaveService.createJoinContactsIntent( |
Brian Attwell | d3946ca | 2015-03-03 11:13:49 -0800 | [diff] [blame] | 314 | mContext, mContactIdForJoin, contactId, CompactContactEditorActivity.class, |
Walter Jang | 49ed203 | 2015-02-11 20:09:05 -0800 | [diff] [blame] | 315 | CompactContactEditorActivity.ACTION_JOIN_COMPLETED); |
| 316 | mContext.startService(intent); |
Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 317 | } |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 318 | |
| 319 | @Override |
Walter Jang | 0e72ce9 | 2015-02-23 12:27:21 -0800 | [diff] [blame] | 320 | public void onRemovePictureChosen() { |
| 321 | if (mPhotoHandler != null) { |
| 322 | mPhotoHandler.getListener().onRemovePictureChosen(); |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | @Override |
| 327 | public void onTakePhotoChosen() { |
| 328 | if (mPhotoHandler != null) { |
| 329 | mPhotoHandler.getListener().onTakePhotoChosen(); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | @Override |
| 334 | public void onPickFromGalleryChosen() { |
| 335 | if (mPhotoHandler != null) { |
| 336 | mPhotoHandler.getListener().onPickFromGalleryChosen(); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | @Override |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 341 | public void onExpandEditor() { |
Walter Jang | 36d6a16 | 2015-02-20 10:56:59 -0800 | [diff] [blame] | 342 | // Determine if this is an insert (new contact) or edit |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 343 | final boolean isInsert = isInsert(getActivity().getIntent()); |
Walter Jang | 36d6a16 | 2015-02-20 10:56:59 -0800 | [diff] [blame] | 344 | |
| 345 | if (isInsert) { |
| 346 | // For inserts, prevent any changes from being saved when the base fragment is destroyed |
| 347 | mStatus = Status.CLOSING; |
Walter Jang | 36d6a16 | 2015-02-20 10:56:59 -0800 | [diff] [blame] | 348 | } else { |
Walter Jang | f638b6f | 2015-03-02 16:15:17 -0800 | [diff] [blame] | 349 | // Prevent a Toast from being displayed as we transition to the full editor |
| 350 | mShowToastAfterSave = false; |
| 351 | |
| 352 | // Save whatever is in the form |
Walter Jang | 36d6a16 | 2015-02-20 10:56:59 -0800 | [diff] [blame] | 353 | save(SaveMode.RELOAD); |
| 354 | } |
| 355 | |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 356 | // Prepare an Intent to start the expanded editor |
| 357 | final Intent intent = isInsert |
Walter Jang | 1e8801b | 2015-03-10 15:57:05 -0700 | [diff] [blame] | 358 | ? EditorIntents.createInsertContactIntent(mState, getDisplayName(), mUpdatedPhotos) |
Walter Jang | 921287e | 2015-03-10 09:53:36 -0700 | [diff] [blame] | 359 | : EditorIntents.createEditContactIntent(mLookupUri, getMaterialPalette()); |
Walter Jang | 36d6a16 | 2015-02-20 10:56:59 -0800 | [diff] [blame] | 360 | ImplicitIntentsUtil.startActivityInApp(getActivity(), intent); |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 361 | |
Walter Jang | 921287e | 2015-03-10 09:53:36 -0700 | [diff] [blame] | 362 | getActivity().finish(); |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 363 | } |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 364 | |
Walter Jang | 151f3e6 | 2015-02-26 15:29:40 -0800 | [diff] [blame] | 365 | @Override |
| 366 | public void onNameFieldChanged(long rawContactId, ValuesDelta valuesDelta) { |
| 367 | final Activity activity = getActivity(); |
| 368 | if (activity == null || activity.isFinishing()) { |
| 369 | return; |
| 370 | } |
| 371 | if (!mIsUserProfile) { |
| 372 | acquireAggregationSuggestions(activity, rawContactId, valuesDelta); |
| 373 | } |
| 374 | } |
| 375 | |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 376 | @Override |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 377 | public String getDisplayName() { |
| 378 | final StructuredNameEditorView structuredNameEditorView = |
| 379 | getContent().getStructuredNameEditorView(); |
| 380 | return structuredNameEditorView == null |
| 381 | ? null : structuredNameEditorView.getDisplayName(); |
| 382 | } |
| 383 | |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 384 | private CompactRawContactsEditorView getContent() { |
| 385 | return (CompactRawContactsEditorView) mContent; |
| 386 | } |
Walter Jang | 3f990ba | 2015-01-27 17:38:30 +0000 | [diff] [blame] | 387 | } |