blob: c3a240a52f72cdbae3c97a484da429618fb8bb81 [file] [log] [blame]
Daniel Lehmann392ccec2010-11-01 20:50:03 -07001/*
2 * Copyright (C) 2010 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
Dmitri Plotnikov18ffaa22010-12-03 14:28:00 -080017package com.android.contacts.editor;
Daniel Lehmann392ccec2010-11-01 20:50:03 -070018
Daniel Lehmann392ccec2010-11-01 20:50:03 -070019import android.content.Context;
Daniel Lehmann392ccec2010-11-01 20:50:03 -070020import android.graphics.Rect;
Gary Mai3e9637f2016-09-06 18:22:55 -070021import android.graphics.drawable.Drawable;
Daniel Lehmann392ccec2010-11-01 20:50:03 -070022import android.os.Parcel;
23import android.os.Parcelable;
Tingting Wangb6949dc2015-11-03 13:17:12 -080024import android.provider.ContactsContract;
Daniel Lehmann392ccec2010-11-01 20:50:03 -070025import android.text.Editable;
26import android.text.InputType;
Wenyi Wang1d896222016-03-24 16:50:48 -070027import android.text.Spannable;
Katherine Kuan1b220732011-04-28 18:45:39 -070028import android.text.TextUtils;
Daniel Lehmann392ccec2010-11-01 20:50:03 -070029import android.text.TextWatcher;
Wenyi Wang1d896222016-03-24 16:50:48 -070030import android.text.style.TtsSpan;
Daniel Lehmann392ccec2010-11-01 20:50:03 -070031import android.util.AttributeSet;
Josh Gargus26918da2012-02-02 16:58:04 -080032import android.util.Log;
Brian Attwell043fba62014-10-30 11:11:56 -070033import android.util.TypedValue;
Daniel Lehmann392ccec2010-11-01 20:50:03 -070034import android.view.View;
Katherine Kuan63ffb902011-04-26 19:53:40 -070035import android.view.ViewGroup;
Katherine Kuan0af02582011-12-05 17:11:57 -080036import android.view.inputmethod.EditorInfo;
Josh Gargus26918da2012-02-02 16:58:04 -080037import android.view.inputmethod.InputMethodManager;
Daniel Lehmann392ccec2010-11-01 20:50:03 -070038import android.widget.EditText;
Katherine Kuan12a93632011-05-05 13:38:01 -070039import android.widget.ImageView;
Daniel Lehmann392ccec2010-11-01 20:50:03 -070040import android.widget.LinearLayout;
Dave Santoroda5bf1c2011-05-03 10:30:34 -070041
Gary Mai0a49afa2016-12-05 15:53:58 -080042import com.android.contacts.ContactsUtils;
Chiao Chenge0b2f1e2012-06-12 13:07:56 -070043import com.android.contacts.R;
Gary Mai69c182a2016-12-05 13:07:03 -080044import com.android.contacts.compat.PhoneNumberUtilsCompat;
45import com.android.contacts.model.RawContactDelta;
46import com.android.contacts.model.ValuesDelta;
47import com.android.contacts.model.account.AccountType.EditField;
48import com.android.contacts.model.dataitem.DataKind;
49import com.android.contacts.util.PhoneNumberFormatter;
Chiao Chenge0b2f1e2012-06-12 13:07:56 -070050
Daniel Lehmann392ccec2010-11-01 20:50:03 -070051/**
Katherine Kuan63ffb902011-04-26 19:53:40 -070052 * Simple editor that handles labels and any {@link EditField} defined for the
Maurice Chu851222a2012-06-21 11:43:08 -070053 * entry. Uses {@link ValuesDelta} to read any existing {@link RawContact} values,
Katherine Kuan63ffb902011-04-26 19:53:40 -070054 * and to correctly write any changes values.
Daniel Lehmann392ccec2010-11-01 20:50:03 -070055 */
56public class TextFieldsEditorView extends LabeledEditorView {
Josh Gargus26918da2012-02-02 16:58:04 -080057 private static final String TAG = TextFieldsEditorView.class.getSimpleName();
58
Daniel Lehmann392ccec2010-11-01 20:50:03 -070059 private EditText[] mFieldEditTexts = null;
Katherine Kuan63ffb902011-04-26 19:53:40 -070060 private ViewGroup mFields = null;
Gary Mai1c6298b2016-09-09 14:34:52 -070061 protected View mExpansionViewContainer;
62 protected ImageView mExpansionView;
63 protected String mCollapseButtonDescription;
64 protected String mExpandButtonDescription;
65 protected String mCollapsedAnnouncement;
66 protected String mExpandedAnnouncement;
Daniel Lehmann392ccec2010-11-01 20:50:03 -070067 private boolean mHideOptional = true;
68 private boolean mHasShortAndLongForms;
Katherine Kuan1ebbd5b2011-08-05 14:39:34 -070069 private int mMinFieldHeight;
Yorke Leeba48d212012-12-26 13:25:48 -080070 private int mPreviousViewHeight;
Brian Attwelld690dff2014-12-02 15:04:56 -080071 private int mHintTextColorUnfocused;
Daniel Lehmann392ccec2010-11-01 20:50:03 -070072
73 public TextFieldsEditorView(Context context) {
74 super(context);
75 }
76
77 public TextFieldsEditorView(Context context, AttributeSet attrs) {
78 super(context, attrs);
79 }
80
81 public TextFieldsEditorView(Context context, AttributeSet attrs, int defStyle) {
82 super(context, attrs, defStyle);
83 }
84
Katherine Kuan63ffb902011-04-26 19:53:40 -070085 /** {@inheritDoc} */
86 @Override
87 protected void onFinishInflate() {
88 super.onFinishInflate();
89
90 setDrawingCacheEnabled(true);
91 setAlwaysDrawnWithCacheEnabled(true);
92
Brian Attwellf1402272014-12-16 16:00:08 -080093 mMinFieldHeight = getContext().getResources().getDimensionPixelSize(
Katherine Kuan1ebbd5b2011-08-05 14:39:34 -070094 R.dimen.editor_min_line_item_height);
Katherine Kuan63ffb902011-04-26 19:53:40 -070095 mFields = (ViewGroup) findViewById(R.id.editors);
Brian Attwelld690dff2014-12-02 15:04:56 -080096 mHintTextColorUnfocused = getResources().getColor(R.color.editor_disabled_text_color);
Katherine Kuan12a93632011-05-05 13:38:01 -070097 mExpansionView = (ImageView) findViewById(R.id.expansion_view);
Gary Mai1c6298b2016-09-09 14:34:52 -070098 mCollapseButtonDescription = getResources()
99 .getString(R.string.collapse_fields_description);
100 mCollapsedAnnouncement = getResources()
101 .getString(R.string.announce_collapsed_fields);
102 mExpandButtonDescription = getResources()
103 .getString(R.string.expand_fields_description);
104 mExpandedAnnouncement = getResources()
105 .getString(R.string.announce_expanded_fields);
106
Katherine Kuan12a93632011-05-05 13:38:01 -0700107 mExpansionViewContainer = findViewById(R.id.expansion_view_container);
Brian Attwell043fba62014-10-30 11:11:56 -0700108 if (mExpansionViewContainer != null) {
109 mExpansionViewContainer.setOnClickListener(new OnClickListener() {
110 @Override
111 public void onClick(View v) {
112 mPreviousViewHeight = mFields.getHeight();
Yorke Leeba48d212012-12-26 13:25:48 -0800113
Brian Attwell043fba62014-10-30 11:11:56 -0700114 // Save focus
Gary Mai698cee72016-09-19 16:09:54 -0700115 final View focusedChild = findFocus();
Brian Attwell043fba62014-10-30 11:11:56 -0700116 final int focusedViewId = focusedChild == null ? -1 : focusedChild.getId();
Katherine Kuan63ffb902011-04-26 19:53:40 -0700117
Brian Attwell043fba62014-10-30 11:11:56 -0700118 // Reconfigure GUI
119 mHideOptional = !mHideOptional;
120 onOptionalFieldVisibilityChange();
121 rebuildValues();
Katherine Kuan63ffb902011-04-26 19:53:40 -0700122
Brian Attwell043fba62014-10-30 11:11:56 -0700123 // Restore focus
124 View newFocusView = findViewById(focusedViewId);
125 if (newFocusView == null || newFocusView.getVisibility() == GONE) {
126 // find first visible child
127 newFocusView = TextFieldsEditorView.this;
128 }
129 newFocusView.requestFocus();
130
131 EditorAnimator.getInstance().slideAndFadeIn(mFields, mPreviousViewHeight);
Gary Mai1c6298b2016-09-09 14:34:52 -0700132 announceForAccessibility(mHideOptional ?
133 mCollapsedAnnouncement : mExpandedAnnouncement);
Katherine Kuan63ffb902011-04-26 19:53:40 -0700134 }
Brian Attwell043fba62014-10-30 11:11:56 -0700135 });
136 }
Katherine Kuan63ffb902011-04-26 19:53:40 -0700137 }
138
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700139 @Override
Josh Gargus26918da2012-02-02 16:58:04 -0800140 public void editNewlyAddedField() {
141 // Some editors may have multiple fields (eg: first-name/last-name), but since the user
142 // has not selected a particular one, it is reasonable to simply pick the first.
143 final View editor = mFields.getChildAt(0);
144
145 // Show the soft-keyboard.
Wenyi Wanga07c90b2016-03-07 09:56:08 -0800146 InputMethodManager imm =
147 (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
148 if (imm != null) {
149 if (!imm.showSoftInput(editor, InputMethodManager.SHOW_IMPLICIT)) {
150 Log.w(TAG, "Failed to show soft input method.");
151 }
152 }
Josh Gargus26918da2012-02-02 16:58:04 -0800153 }
154
155 @Override
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700156 public void setEnabled(boolean enabled) {
157 super.setEnabled(enabled);
158
159 if (mFieldEditTexts != null) {
160 for (int index = 0; index < mFieldEditTexts.length; index++) {
Dmitri Plotnikov02bb1252010-12-06 09:39:05 -0800161 mFieldEditTexts[index].setEnabled(!isReadOnly() && enabled);
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700162 }
163 }
Brian Attwell043fba62014-10-30 11:11:56 -0700164 if (mExpansionView != null) {
165 mExpansionView.setEnabled(!isReadOnly() && enabled);
166 }
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700167 }
168
Brian Attwelld690dff2014-12-02 15:04:56 -0800169 private OnFocusChangeListener mTextFocusChangeListener = new OnFocusChangeListener() {
170 @Override
171 public void onFocusChange(View v, boolean hasFocus) {
Brian Attwelld690dff2014-12-02 15:04:56 -0800172 if (getEditorListener() != null) {
173 getEditorListener().onRequest(EditorListener.EDITOR_FOCUS_CHANGED);
174 }
175 // Rebuild the label spinner using the new colors.
176 rebuildLabel();
177 }
178 };
179
180 /**
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700181 * Creates or removes the type/label button. Doesn't do anything if already correctly configured
182 */
Katherine Kuan12a93632011-05-05 13:38:01 -0700183 private void setupExpansionView(boolean shouldExist, boolean collapsed) {
Gary Mai3e9637f2016-09-06 18:22:55 -0700184 final Drawable expandIcon = getContext().getDrawable(collapsed
John Shaobd9ef3c2016-12-15 12:42:03 -0800185 ? R.drawable.quantum_ic_expand_more_vd_theme_24
186 : R.drawable.quantum_ic_expand_less_vd_theme_24);
Gary Mai3e9637f2016-09-06 18:22:55 -0700187 mExpansionView.setImageDrawable(expandIcon);
Gary Mai1c6298b2016-09-09 14:34:52 -0700188 mExpansionView.setContentDescription(collapsed ? mExpandButtonDescription
189 : mCollapseButtonDescription);
Brian Attwell93f22ec2015-03-04 14:21:15 -0800190 mExpansionViewContainer.setVisibility(shouldExist ? View.VISIBLE : View.INVISIBLE);
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700191 }
192
193 @Override
194 protected void requestFocusForFirstEditField() {
195 if (mFieldEditTexts != null && mFieldEditTexts.length != 0) {
196 EditText firstField = null;
197 boolean anyFieldHasFocus = false;
198 for (EditText editText : mFieldEditTexts) {
199 if (firstField == null && editText.getVisibility() == View.VISIBLE) {
200 firstField = editText;
201 }
202 if (editText.hasFocus()) {
203 anyFieldHasFocus = true;
204 break;
205 }
206 }
207 if (!anyFieldHasFocus && firstField != null) {
208 firstField.requestFocus();
209 }
210 }
211 }
212
Chiao Cheng44cfc562012-09-13 13:06:23 -0700213 public void setValue(int field, String value) {
214 mFieldEditTexts[field].setText(value);
215 }
216
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700217 @Override
Maurice Chu851222a2012-06-21 11:43:08 -0700218 public void setValues(DataKind kind, ValuesDelta entry, RawContactDelta state, boolean readOnly,
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700219 ViewIdGenerator vig) {
220 super.setValues(kind, entry, state, readOnly, vig);
221 // Remove edit texts that we currently have
222 if (mFieldEditTexts != null) {
223 for (EditText fieldEditText : mFieldEditTexts) {
Katherine Kuan63ffb902011-04-26 19:53:40 -0700224 mFields.removeView(fieldEditText);
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700225 }
226 }
227 boolean hidePossible = false;
228
Walter Jangf5dfea42015-09-16 12:30:36 -0700229 int fieldCount = kind.fieldList == null ? 0 : kind.fieldList.size();
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700230 mFieldEditTexts = new EditText[fieldCount];
231 for (int index = 0; index < fieldCount; index++) {
232 final EditField field = kind.fieldList.get(index);
Brian Attwellf1402272014-12-16 16:00:08 -0800233 final EditText fieldView = new EditText(getContext());
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700234 fieldView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
Brian Attwell5cc21eb2014-06-03 21:08:01 -0700235 LayoutParams.WRAP_CONTENT));
Brian Attwell043fba62014-10-30 11:11:56 -0700236 fieldView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
237 getResources().getDimension(R.dimen.editor_form_text_size));
Brian Attwelld690dff2014-12-02 15:04:56 -0800238 fieldView.setHintTextColor(mHintTextColorUnfocused);
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700239 mFieldEditTexts[index] = fieldView;
240 fieldView.setId(vig.getId(state, kind, entry, index));
241 if (field.titleRes > 0) {
242 fieldView.setHint(field.titleRes);
243 }
244 int inputType = field.inputType;
245 fieldView.setInputType(inputType);
246 if (inputType == InputType.TYPE_CLASS_PHONE) {
guanxiongliu3d590492016-02-01 16:32:28 -0800247 PhoneNumberFormatter.setPhoneNumberFormattingTextWatcher(
Gary Maic03cfc02016-09-07 15:50:55 -0700248 getContext(), fieldView,
249 /* formatAfterWatcherSet =*/ state.isContactInsert());
Yorke Leecbfb1122013-05-03 17:41:07 -0700250 fieldView.setTextDirection(View.TEXT_DIRECTION_LTR);
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700251 }
Tingting Wang9f153a02015-11-05 18:11:04 -0800252 fieldView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700253
Brian Attwell043fba62014-10-30 11:11:56 -0700254 // Set either a minimum line requirement or a minimum height (because {@link TextView}
255 // only takes one or the other at a single time).
256 if (field.minLines > 1) {
257 fieldView.setMinLines(field.minLines);
258 } else {
259 // This needs to be called after setInputType. Otherwise, calling setInputType
260 // will unset this value.
261 fieldView.setMinHeight(mMinFieldHeight);
262 }
263
Katherine Kuan0af02582011-12-05 17:11:57 -0800264 // Show the "next" button in IME to navigate between text fields
265 // TODO: Still need to properly navigate to/from sections without text fields,
266 // See Bug: 5713510
Gary Mai6eb8e0d2016-07-20 15:24:00 -0700267 fieldView.setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_FULLSCREEN);
Katherine Kuan0af02582011-12-05 17:11:57 -0800268
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700269 // Read current value from state
270 final String column = field.column;
271 final String value = entry.getAsString(column);
Tingting Wangb6949dc2015-11-03 13:17:12 -0800272 if (ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE.equals(kind.mimeType)) {
Wenyi Wangfcc7dc92015-11-19 09:54:22 -0800273 fieldView.setText(PhoneNumberUtilsCompat.createTtsSpannable(value));
Tingting Wangb6949dc2015-11-03 13:17:12 -0800274 } else {
275 fieldView.setText(value);
276 }
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700277
Wenyi Wang83e7e632015-11-12 19:39:29 -0800278 // Show the delete button if we have a non-empty value
279 setDeleteButtonVisible(!TextUtils.isEmpty(value));
Katherine Kuan5e330ed2011-07-15 15:06:06 -0700280
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700281 // Prepare listener for writing changes
282 fieldView.addTextChangedListener(new TextWatcher() {
283 @Override
284 public void afterTextChanged(Editable s) {
285 // Trigger event for newly changed value
286 onFieldChanged(column, s.toString());
287 }
288
289 @Override
290 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
291 }
292
293 @Override
294 public void onTextChanged(CharSequence s, int start, int before, int count) {
Wenyi Wang1d896222016-03-24 16:50:48 -0700295 if (!ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE.equals(
296 getKind().mimeType) || !(s instanceof Spannable)) {
297 return;
298 }
299 final Spannable spannable = (Spannable) s;
300 final TtsSpan[] spans = spannable.getSpans(0, s.length(), TtsSpan.class);
301 for (int i = 0; i < spans.length; i++) {
302 spannable.removeSpan(spans[i]);
303 }
304 PhoneNumberUtilsCompat.addTtsSpan(spannable, 0, s.length());
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700305 }
306 });
307
Dmitri Plotnikov02bb1252010-12-06 09:39:05 -0800308 fieldView.setEnabled(isEnabled() && !readOnly);
Brian Attwelld690dff2014-12-02 15:04:56 -0800309 fieldView.setOnFocusChangeListener(mTextFocusChangeListener);
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700310
311 if (field.shortForm) {
312 hidePossible = true;
313 mHasShortAndLongForms = true;
314 fieldView.setVisibility(mHideOptional ? View.VISIBLE : View.GONE);
315 } else if (field.longForm) {
316 hidePossible = true;
317 mHasShortAndLongForms = true;
318 fieldView.setVisibility(mHideOptional ? View.GONE : View.VISIBLE);
319 } else {
320 // Hide field when empty and optional value
321 final boolean couldHide = (!ContactsUtils.isGraphic(value) && field.optional);
322 final boolean willHide = (mHideOptional && couldHide);
323 fieldView.setVisibility(willHide ? View.GONE : View.VISIBLE);
324 hidePossible = hidePossible || couldHide;
325 }
326
Katherine Kuan63ffb902011-04-26 19:53:40 -0700327 mFields.addView(fieldView);
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700328 }
329
Brian Attwell043fba62014-10-30 11:11:56 -0700330 if (mExpansionView != null) {
331 // When hiding fields, place expandable
332 setupExpansionView(hidePossible, mHideOptional);
333 mExpansionView.setEnabled(!readOnly && isEnabled());
334 }
Brian Attwell8f9d84f2014-11-03 23:17:04 -0800335 updateEmptiness();
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700336 }
337
Katherine Kuan25914362011-04-29 19:42:01 -0700338 @Override
339 public boolean isEmpty() {
Katherine Kuan1b220732011-04-28 18:45:39 -0700340 for (int i = 0; i < mFields.getChildCount(); i++) {
341 EditText editText = (EditText) mFields.getChildAt(i);
Katherine Kuan25914362011-04-29 19:42:01 -0700342 if (!TextUtils.isEmpty(editText.getText())) {
343 return false;
Katherine Kuan1b220732011-04-28 18:45:39 -0700344 }
345 }
Katherine Kuan25914362011-04-29 19:42:01 -0700346 return true;
Katherine Kuan1b220732011-04-28 18:45:39 -0700347 }
348
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700349 /**
350 * Returns true if the editor is currently configured to show optional fields.
351 */
352 public boolean areOptionalFieldsVisible() {
353 return !mHideOptional;
354 }
355
356 public boolean hasShortAndLongForms() {
357 return mHasShortAndLongForms;
358 }
359
360 /**
361 * Populates the bound rectangle with the bounds of the last editor field inside this view.
362 */
363 public void acquireEditorBounds(Rect bounds) {
364 if (mFieldEditTexts != null) {
365 for (int i = mFieldEditTexts.length; --i >= 0;) {
366 EditText editText = mFieldEditTexts[i];
367 if (editText.getVisibility() == View.VISIBLE) {
368 bounds.set(editText.getLeft(), editText.getTop(), editText.getRight(),
369 editText.getBottom());
370 return;
371 }
372 }
373 }
374 }
375
376 /**
377 * Saves the visibility of the child EditTexts, and mHideOptional.
378 */
379 @Override
380 protected Parcelable onSaveInstanceState() {
381 Parcelable superState = super.onSaveInstanceState();
382 SavedState ss = new SavedState(superState);
383
384 ss.mHideOptional = mHideOptional;
385
Dmitri Plotnikov5ec40b02011-03-01 18:36:16 -0800386 final int numChildren = mFieldEditTexts == null ? 0 : mFieldEditTexts.length;
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700387 ss.mVisibilities = new int[numChildren];
388 for (int i = 0; i < numChildren; i++) {
389 ss.mVisibilities[i] = mFieldEditTexts[i].getVisibility();
390 }
391
392 return ss;
393 }
394
395 /**
396 * Restores the visibility of the child EditTexts, and mHideOptional.
397 */
398 @Override
399 protected void onRestoreInstanceState(Parcelable state) {
400 SavedState ss = (SavedState) state;
401 super.onRestoreInstanceState(ss.getSuperState());
402
403 mHideOptional = ss.mHideOptional;
404
Jay Shrauner882128a2015-05-13 12:21:48 -0700405 int numChildren = Math.min(mFieldEditTexts == null ? 0 : mFieldEditTexts.length,
406 ss.mVisibilities == null ? 0 : ss.mVisibilities.length);
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700407 for (int i = 0; i < numChildren; i++) {
408 mFieldEditTexts[i].setVisibility(ss.mVisibilities[i]);
409 }
Gary Mai1c6298b2016-09-09 14:34:52 -0700410 rebuildValues();
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700411 }
412
413 private static class SavedState extends BaseSavedState {
414 public boolean mHideOptional;
415 public int[] mVisibilities;
416
417 SavedState(Parcelable superState) {
418 super(superState);
419 }
420
421 private SavedState(Parcel in) {
422 super(in);
423 mVisibilities = new int[in.readInt()];
424 in.readIntArray(mVisibilities);
425 }
426
427 @Override
428 public void writeToParcel(Parcel out, int flags) {
429 super.writeToParcel(out, flags);
430 out.writeInt(mVisibilities.length);
431 out.writeIntArray(mVisibilities);
432 }
433
Daniel Lehmanncfb525b2010-11-02 19:24:54 -0700434 @SuppressWarnings({"unused", "hiding" })
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700435 public static final Parcelable.Creator<SavedState> CREATOR
436 = new Parcelable.Creator<SavedState>() {
437 @Override
438 public SavedState createFromParcel(Parcel in) {
439 return new SavedState(in);
440 }
441
442 @Override
443 public SavedState[] newArray(int size) {
444 return new SavedState[size];
445 }
446 };
447 }
Dave Santoroda5bf1c2011-05-03 10:30:34 -0700448
Katherine Kuan2293e552011-07-21 20:25:44 -0700449 @Override
450 public void clearAllFields() {
451 if (mFieldEditTexts != null) {
452 for (EditText fieldEditText : mFieldEditTexts) {
453 // Update UI (which will trigger a state change through the {@link TextWatcher})
454 fieldEditText.setText("");
455 }
456 }
457 }
Daniel Lehmann392ccec2010-11-01 20:50:03 -0700458}