Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 1 | /* |
| 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 Plotnikov | 18ffaa2 | 2010-12-03 14:28:00 -0800 | [diff] [blame] | 17 | package com.android.contacts.editor; |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 18 | |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 19 | import android.app.AlertDialog; |
| 20 | import android.app.Dialog; |
| 21 | import android.content.Context; |
| 22 | import android.content.DialogInterface; |
Daniel Lehmann | a04dc9c | 2012-04-14 16:09:48 -0700 | [diff] [blame] | 23 | import android.content.DialogInterface.OnShowListener; |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 24 | import android.os.Bundle; |
Daniel Lehmann | 79c9c5a | 2010-11-11 16:05:27 -0800 | [diff] [blame] | 25 | import android.os.Handler; |
Daniel Lehmann | a04dc9c | 2012-04-14 16:09:48 -0700 | [diff] [blame] | 26 | import android.text.Editable; |
Dmitri Plotnikov | 11bb73b | 2011-02-25 20:39:58 -0800 | [diff] [blame] | 27 | import android.text.TextUtils; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 28 | import android.text.TextWatcher; |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 29 | import android.util.AttributeSet; |
Brian Attwell | 043fba6 | 2014-10-30 11:11:56 -0700 | [diff] [blame] | 30 | import android.util.TypedValue; |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 31 | import android.view.LayoutInflater; |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 32 | import android.view.View; |
| 33 | import android.view.ViewGroup; |
Daniel Lehmann | a04dc9c | 2012-04-14 16:09:48 -0700 | [diff] [blame] | 34 | import android.view.WindowManager; |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 35 | import android.view.inputmethod.EditorInfo; |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 36 | import android.widget.AdapterView; |
| 37 | import android.widget.AdapterView.OnItemSelectedListener; |
| 38 | import android.widget.ArrayAdapter; |
Daniel Lehmann | a04dc9c | 2012-04-14 16:09:48 -0700 | [diff] [blame] | 39 | import android.widget.Button; |
Gary Mai | 186d791 | 2016-08-10 14:41:45 -0700 | [diff] [blame] | 40 | import android.widget.CheckedTextView; |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 41 | import android.widget.EditText; |
Katherine Kuan | 12a9363 | 2011-05-05 13:38:01 -0700 | [diff] [blame] | 42 | import android.widget.ImageView; |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 43 | import android.widget.LinearLayout; |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 44 | import android.widget.Spinner; |
| 45 | import android.widget.TextView; |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 46 | |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 47 | import com.android.contacts.ContactsUtils; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 48 | import com.android.contacts.R; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 49 | import com.android.contacts.model.RawContactDelta; |
| 50 | import com.android.contacts.model.RawContactModifier; |
| 51 | import com.android.contacts.model.ValuesDelta; |
| 52 | import com.android.contacts.model.account.AccountType.EditType; |
| 53 | import com.android.contacts.model.dataitem.DataKind; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 54 | import com.android.contacts.util.DialogManager; |
| 55 | import com.android.contacts.util.DialogManager.DialogShowingView; |
| 56 | |
Dmitri Plotnikov | 14918c0 | 2010-12-07 17:20:27 -0800 | [diff] [blame] | 57 | import java.util.List; |
| 58 | |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 59 | /** |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 60 | * Base class for editors that handles labels and values. Uses |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 61 | * {@link ValuesDelta} to read any existing {@link RawContact} values, and to |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 62 | * correctly write any changes values. |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 63 | */ |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 64 | public abstract class LabeledEditorView extends LinearLayout implements Editor, DialogShowingView { |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 65 | protected static final String DIALOG_ID_KEY = "dialog_id"; |
| 66 | private static final int DIALOG_ID_CUSTOM = 1; |
| 67 | |
| 68 | private static final int INPUT_TYPE_CUSTOM = EditorInfo.TYPE_CLASS_TEXT |
| 69 | | EditorInfo.TYPE_TEXT_FLAG_CAP_WORDS; |
| 70 | |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 71 | private Spinner mLabel; |
| 72 | private EditTypeAdapter mEditTypeAdapter; |
avipul | eda7e56 | 2017-02-16 16:41:44 -0800 | [diff] [blame] | 73 | protected View mDeleteContainer; |
Katherine Kuan | 12a9363 | 2011-05-05 13:38:01 -0700 | [diff] [blame] | 74 | private ImageView mDelete; |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 75 | |
| 76 | private DataKind mKind; |
| 77 | private ValuesDelta mEntry; |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 78 | private RawContactDelta mState; |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 79 | private boolean mReadOnly; |
Katherine Kuan | 2591436 | 2011-04-29 19:42:01 -0700 | [diff] [blame] | 80 | private boolean mWasEmpty = true; |
Katherine Kuan | 5e330ed | 2011-07-15 15:06:06 -0700 | [diff] [blame] | 81 | private boolean mIsDeletable = true; |
Katherine Kuan | 2293e55 | 2011-07-21 20:25:44 -0700 | [diff] [blame] | 82 | private boolean mIsAttachedToWindow; |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 83 | |
| 84 | private EditType mType; |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 85 | |
| 86 | private ViewIdGenerator mViewIdGenerator; |
| 87 | private DialogManager mDialogManager = null; |
| 88 | private EditorListener mListener; |
Dmitri Plotnikov | 91d8e89 | 2010-12-07 20:36:51 -0800 | [diff] [blame] | 89 | protected int mMinLineItemHeight; |
Gary Mai | 186d791 | 2016-08-10 14:41:45 -0700 | [diff] [blame] | 90 | private int mSelectedLabelIndex; |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 91 | |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 92 | /** |
| 93 | * A marker in the spinner adapter of the currently selected custom type. |
| 94 | */ |
| 95 | public static final EditType CUSTOM_SELECTION = new EditType(0, 0); |
| 96 | |
| 97 | private OnItemSelectedListener mSpinnerListener = new OnItemSelectedListener() { |
| 98 | |
| 99 | @Override |
| 100 | public void onItemSelected( |
| 101 | AdapterView<?> parent, View view, int position, long id) { |
| 102 | onTypeSelectionChange(position); |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public void onNothingSelected(AdapterView<?> parent) { |
| 107 | } |
| 108 | }; |
| 109 | |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 110 | public LabeledEditorView(Context context) { |
| 111 | super(context); |
Dmitri Plotnikov | 91d8e89 | 2010-12-07 20:36:51 -0800 | [diff] [blame] | 112 | init(context); |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | public LabeledEditorView(Context context, AttributeSet attrs) { |
| 116 | super(context, attrs); |
Dmitri Plotnikov | 91d8e89 | 2010-12-07 20:36:51 -0800 | [diff] [blame] | 117 | init(context); |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | public LabeledEditorView(Context context, AttributeSet attrs, int defStyle) { |
| 121 | super(context, attrs, defStyle); |
Dmitri Plotnikov | 91d8e89 | 2010-12-07 20:36:51 -0800 | [diff] [blame] | 122 | init(context); |
| 123 | } |
| 124 | |
Walter Jang | d35e5ef | 2015-02-24 09:18:16 -0800 | [diff] [blame] | 125 | public Long getRawContactId() { |
| 126 | return mState == null ? null : mState.getRawContactId(); |
| 127 | } |
| 128 | |
Dmitri Plotnikov | 91d8e89 | 2010-12-07 20:36:51 -0800 | [diff] [blame] | 129 | private void init(Context context) { |
| 130 | mMinLineItemHeight = context.getResources().getDimensionPixelSize( |
| 131 | R.dimen.editor_min_line_item_height); |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 134 | /** {@inheritDoc} */ |
| 135 | @Override |
| 136 | protected void onFinishInflate() { |
| 137 | |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 138 | mLabel = (Spinner) findViewById(R.id.spinner); |
Daniel Lehmann | 67713b3 | 2012-02-21 21:57:09 -0800 | [diff] [blame] | 139 | // Turn off the Spinner's own state management. We do this ourselves on rotation |
| 140 | mLabel.setId(View.NO_ID); |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 141 | mLabel.setOnItemSelectedListener(mSpinnerListener); |
Wenyi Wang | 843de77 | 2015-11-10 10:24:04 -0800 | [diff] [blame] | 142 | ViewSelectedFilter.suppressViewSelectedEvent(mLabel); |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 143 | |
Katherine Kuan | 12a9363 | 2011-05-05 13:38:01 -0700 | [diff] [blame] | 144 | mDelete = (ImageView) findViewById(R.id.delete_button); |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 145 | mDeleteContainer = findViewById(R.id.delete_button_container); |
Katherine Kuan | 12a9363 | 2011-05-05 13:38:01 -0700 | [diff] [blame] | 146 | mDeleteContainer.setOnClickListener(new OnClickListener() { |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 147 | @Override |
| 148 | public void onClick(View v) { |
| 149 | // defer removal of this button so that the pressed state is visible shortly |
| 150 | new Handler().post(new Runnable() { |
| 151 | @Override |
| 152 | public void run() { |
Katherine Kuan | 2293e55 | 2011-07-21 20:25:44 -0700 | [diff] [blame] | 153 | // Don't do anything if the view is no longer attached to the window |
| 154 | // (This check is needed because when this {@link Runnable} is executed, |
| 155 | // we can't guarantee the view is still valid. |
| 156 | if (!mIsAttachedToWindow) { |
| 157 | return; |
| 158 | } |
| 159 | // Send the delete request to the listener (which will in turn call |
| 160 | // deleteEditor() on this view if the deletion is valid - i.e. this is not |
| 161 | // the last {@link Editor} in the section). |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 162 | if (mListener != null) { |
Katherine Kuan | 2293e55 | 2011-07-21 20:25:44 -0700 | [diff] [blame] | 163 | mListener.onDeleteRequested(LabeledEditorView.this); |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | }); |
| 167 | } |
| 168 | }); |
Brian Attwell | 043fba6 | 2014-10-30 11:11:56 -0700 | [diff] [blame] | 169 | |
| 170 | setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), |
| 171 | (int) getResources().getDimension(R.dimen.editor_padding_between_editor_views)); |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Katherine Kuan | 2293e55 | 2011-07-21 20:25:44 -0700 | [diff] [blame] | 174 | @Override |
| 175 | protected void onAttachedToWindow() { |
| 176 | super.onAttachedToWindow(); |
| 177 | // Keep track of when the view is attached or detached from the window, so we know it's |
| 178 | // safe to remove views (in case the user requests to delete this editor). |
| 179 | mIsAttachedToWindow = true; |
| 180 | } |
| 181 | |
| 182 | @Override |
| 183 | protected void onDetachedFromWindow() { |
| 184 | super.onDetachedFromWindow(); |
| 185 | mIsAttachedToWindow = false; |
| 186 | } |
| 187 | |
| 188 | @Override |
Walter Jang | 23a34d1 | 2015-07-08 09:41:05 -0700 | [diff] [blame] | 189 | public void markDeleted() { |
Katherine Kuan | 2293e55 | 2011-07-21 20:25:44 -0700 | [diff] [blame] | 190 | // Keep around in model, but mark as deleted |
| 191 | mEntry.markDeleted(); |
Walter Jang | 23a34d1 | 2015-07-08 09:41:05 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public void deleteEditor() { |
| 196 | markDeleted(); |
Katherine Kuan | 2293e55 | 2011-07-21 20:25:44 -0700 | [diff] [blame] | 197 | |
| 198 | // Remove the view |
Daniel Lehmann | ca87e9c | 2012-03-06 14:02:31 -0800 | [diff] [blame] | 199 | EditorAnimator.getInstance().removeEditorView(this); |
Katherine Kuan | 2293e55 | 2011-07-21 20:25:44 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Dmitri Plotnikov | 02bb125 | 2010-12-06 09:39:05 -0800 | [diff] [blame] | 202 | public boolean isReadOnly() { |
| 203 | return mReadOnly; |
| 204 | } |
| 205 | |
Dmitri Plotnikov | 91d8e89 | 2010-12-07 20:36:51 -0800 | [diff] [blame] | 206 | public int getBaseline(int row) { |
| 207 | if (row == 0 && mLabel != null) { |
| 208 | return mLabel.getBaseline(); |
| 209 | } |
| 210 | return -1; |
| 211 | } |
| 212 | |
| 213 | /** |
Katherine Kuan | a94859f | 2011-07-20 13:38:27 -0700 | [diff] [blame] | 214 | * Configures the visibility of the type label button and enables or disables it properly. |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 215 | */ |
| 216 | private void setupLabelButton(boolean shouldExist) { |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 217 | if (shouldExist) { |
Dmitri Plotnikov | 02bb125 | 2010-12-06 09:39:05 -0800 | [diff] [blame] | 218 | mLabel.setEnabled(!mReadOnly && isEnabled()); |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 219 | mLabel.setVisibility(View.VISIBLE); |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 220 | } else { |
| 221 | mLabel.setVisibility(View.GONE); |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
| 225 | /** |
Katherine Kuan | a94859f | 2011-07-20 13:38:27 -0700 | [diff] [blame] | 226 | * Configures the visibility of the "delete" button and enables or disables it properly. |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 227 | */ |
Katherine Kuan | 5e330ed | 2011-07-15 15:06:06 -0700 | [diff] [blame] | 228 | private void setupDeleteButton() { |
| 229 | if (mIsDeletable) { |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 230 | mDeleteContainer.setVisibility(View.VISIBLE); |
Dmitri Plotnikov | 02bb125 | 2010-12-06 09:39:05 -0800 | [diff] [blame] | 231 | mDelete.setEnabled(!mReadOnly && isEnabled()); |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 232 | } else { |
avipul | eda7e56 | 2017-02-16 16:41:44 -0800 | [diff] [blame] | 233 | mDeleteContainer.setVisibility(View.INVISIBLE); |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | |
Katherine Kuan | 5e330ed | 2011-07-15 15:06:06 -0700 | [diff] [blame] | 237 | public void setDeleteButtonVisible(boolean visible) { |
| 238 | if (mIsDeletable) { |
Katherine Kuan | a94859f | 2011-07-20 13:38:27 -0700 | [diff] [blame] | 239 | mDeleteContainer.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); |
Katherine Kuan | 5e330ed | 2011-07-15 15:06:06 -0700 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 243 | protected void onOptionalFieldVisibilityChange() { |
| 244 | if (mListener != null) { |
| 245 | mListener.onRequest(EditorListener.EDITOR_FORM_CHANGED); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | @Override |
| 250 | public void setEditorListener(EditorListener listener) { |
| 251 | mListener = listener; |
| 252 | } |
| 253 | |
Brian Attwell | d690dff | 2014-12-02 15:04:56 -0800 | [diff] [blame] | 254 | protected EditorListener getEditorListener(){ |
| 255 | return mListener; |
| 256 | } |
| 257 | |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 258 | @Override |
| 259 | public void setDeletable(boolean deletable) { |
Katherine Kuan | 5e330ed | 2011-07-15 15:06:06 -0700 | [diff] [blame] | 260 | mIsDeletable = deletable; |
| 261 | setupDeleteButton(); |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | @Override |
| 265 | public void setEnabled(boolean enabled) { |
Dmitri Plotnikov | 02bb125 | 2010-12-06 09:39:05 -0800 | [diff] [blame] | 266 | super.setEnabled(enabled); |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 267 | mLabel.setEnabled(!mReadOnly && enabled); |
| 268 | mDelete.setEnabled(!mReadOnly && enabled); |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 271 | public Spinner getLabel() { |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 272 | return mLabel; |
| 273 | } |
| 274 | |
Katherine Kuan | 12a9363 | 2011-05-05 13:38:01 -0700 | [diff] [blame] | 275 | public ImageView getDelete() { |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 276 | return mDelete; |
| 277 | } |
| 278 | |
| 279 | protected DataKind getKind() { |
| 280 | return mKind; |
| 281 | } |
| 282 | |
| 283 | protected ValuesDelta getEntry() { |
| 284 | return mEntry; |
| 285 | } |
| 286 | |
| 287 | protected EditType getType() { |
| 288 | return mType; |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Build the current label state based on selected {@link EditType} and |
| 293 | * possible custom label string. |
| 294 | */ |
Brian Attwell | d690dff | 2014-12-02 15:04:56 -0800 | [diff] [blame] | 295 | public void rebuildLabel() { |
Brian Attwell | f140227 | 2014-12-16 16:00:08 -0800 | [diff] [blame] | 296 | mEditTypeAdapter = new EditTypeAdapter(getContext()); |
Gary Mai | 186d791 | 2016-08-10 14:41:45 -0700 | [diff] [blame] | 297 | mEditTypeAdapter.setSelectedIndex(mSelectedLabelIndex); |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 298 | mLabel.setAdapter(mEditTypeAdapter); |
| 299 | if (mEditTypeAdapter.hasCustomSelection()) { |
| 300 | mLabel.setSelection(mEditTypeAdapter.getPosition(CUSTOM_SELECTION)); |
Wenyi Wang | daf8a41 | 2015-11-06 12:59:57 -0800 | [diff] [blame] | 301 | mDeleteContainer.setContentDescription( |
| 302 | getContext().getString(R.string.editor_delete_view_description, |
| 303 | mEntry.getAsString(mType.customColumn), |
| 304 | getContext().getString(mKind.titleRes))); |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 305 | } else { |
Walter Jang | 155299e | 2016-08-25 10:38:52 -0700 | [diff] [blame] | 306 | if (mType != null && mType.labelRes > 0 && mKind.titleRes > 0) { |
Tingting Wang | cfa628c | 2016-07-13 17:31:06 -0700 | [diff] [blame] | 307 | mLabel.setSelection(mEditTypeAdapter.getPosition(mType)); |
Wenyi Wang | daf8a41 | 2015-11-06 12:59:57 -0800 | [diff] [blame] | 308 | mDeleteContainer.setContentDescription( |
| 309 | getContext().getString(R.string.editor_delete_view_description, |
| 310 | getContext().getString(mType.labelRes), |
| 311 | getContext().getString(mKind.titleRes))); |
Walter Jang | 155299e | 2016-08-25 10:38:52 -0700 | [diff] [blame] | 312 | } else if (mKind.titleRes > 0) { |
Wenyi Wang | daf8a41 | 2015-11-06 12:59:57 -0800 | [diff] [blame] | 313 | mDeleteContainer.setContentDescription( |
| 314 | getContext().getString(R.string.editor_delete_view_description_short, |
| 315 | getContext().getString(mKind.titleRes))); |
| 316 | } |
| 317 | |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 318 | } |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 321 | @Override |
| 322 | public void onFieldChanged(String column, String value) { |
Dmitri Plotnikov | 11bb73b | 2011-02-25 20:39:58 -0800 | [diff] [blame] | 323 | if (!isFieldChanged(column, value)) { |
Dmitri Plotnikov | 7d4a8dd | 2010-12-07 20:49:25 -0800 | [diff] [blame] | 324 | return; |
| 325 | } |
| 326 | |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 327 | // Field changes are saved directly |
Katherine Kuan | e55faef | 2011-12-06 17:58:43 -0800 | [diff] [blame] | 328 | saveValue(column, value); |
| 329 | |
| 330 | // Notify listener if applicable |
| 331 | notifyEditorListener(); |
| 332 | } |
| 333 | |
yoichi kakimoto | 5ed462a | 2017-09-04 19:20:13 +0900 | [diff] [blame] | 334 | /** {@inheritDoc} */ |
| 335 | @Override |
| 336 | public void updatePhonetic(String column, String value) { |
| 337 | } |
| 338 | |
| 339 | /** {@inheritDoc} */ |
| 340 | @Override |
| 341 | public String getPhonetic(String column){ |
| 342 | return ""; |
| 343 | } |
| 344 | |
Katherine Kuan | e55faef | 2011-12-06 17:58:43 -0800 | [diff] [blame] | 345 | protected void saveValue(String column, String value) { |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 346 | mEntry.put(column, value); |
Katherine Kuan | e55faef | 2011-12-06 17:58:43 -0800 | [diff] [blame] | 347 | } |
| 348 | |
Brian Attwell | 8f9d84f | 2014-11-03 23:17:04 -0800 | [diff] [blame] | 349 | /** |
| 350 | * Sub classes should call this at the end of {@link #setValues} once they finish changing |
| 351 | * isEmpty(). This is needed to fix b/18194655. |
| 352 | */ |
| 353 | protected final void updateEmptiness() { |
| 354 | mWasEmpty = isEmpty(); |
| 355 | } |
| 356 | |
Katherine Kuan | e55faef | 2011-12-06 17:58:43 -0800 | [diff] [blame] | 357 | protected void notifyEditorListener() { |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 358 | if (mListener != null) { |
| 359 | mListener.onRequest(EditorListener.FIELD_CHANGED); |
| 360 | } |
Katherine Kuan | 2591436 | 2011-04-29 19:42:01 -0700 | [diff] [blame] | 361 | |
| 362 | boolean isEmpty = isEmpty(); |
| 363 | if (mWasEmpty != isEmpty) { |
| 364 | if (isEmpty) { |
Katherine Kuan | 37bddc2 | 2011-07-09 17:36:26 -0700 | [diff] [blame] | 365 | if (mListener != null) { |
| 366 | mListener.onRequest(EditorListener.FIELD_TURNED_EMPTY); |
| 367 | } |
Katherine Kuan | a94859f | 2011-07-20 13:38:27 -0700 | [diff] [blame] | 368 | if (mIsDeletable) mDeleteContainer.setVisibility(View.INVISIBLE); |
Katherine Kuan | 2591436 | 2011-04-29 19:42:01 -0700 | [diff] [blame] | 369 | } else { |
Katherine Kuan | 37bddc2 | 2011-07-09 17:36:26 -0700 | [diff] [blame] | 370 | if (mListener != null) { |
| 371 | mListener.onRequest(EditorListener.FIELD_TURNED_NON_EMPTY); |
| 372 | } |
Katherine Kuan | 5e330ed | 2011-07-15 15:06:06 -0700 | [diff] [blame] | 373 | if (mIsDeletable) mDeleteContainer.setVisibility(View.VISIBLE); |
Katherine Kuan | 2591436 | 2011-04-29 19:42:01 -0700 | [diff] [blame] | 374 | } |
| 375 | mWasEmpty = isEmpty; |
Walter Jang | 23942c0 | 2015-09-25 10:53:41 -0700 | [diff] [blame] | 376 | |
| 377 | // Update the label text color |
Walter Jang | 4f5594a | 2015-10-06 18:40:31 -0700 | [diff] [blame] | 378 | if (mEditTypeAdapter != null) { |
| 379 | mEditTypeAdapter.notifyDataSetChanged(); |
| 380 | } |
Katherine Kuan | 2591436 | 2011-04-29 19:42:01 -0700 | [diff] [blame] | 381 | } |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Dmitri Plotnikov | 11bb73b | 2011-02-25 20:39:58 -0800 | [diff] [blame] | 384 | protected boolean isFieldChanged(String column, String value) { |
Daniel Lehmann | 60b239c | 2011-03-07 20:01:45 -0800 | [diff] [blame] | 385 | final String dbValue = mEntry.getAsString(column); |
| 386 | // nullable fields (e.g. Middle Name) are usually represented as empty columns, |
| 387 | // so lets treat null and empty space equivalently here |
| 388 | final String dbValueNoNull = dbValue == null ? "" : dbValue; |
| 389 | final String valueNoNull = value == null ? "" : value; |
| 390 | return !TextUtils.equals(dbValueNoNull, valueNoNull); |
Dmitri Plotnikov | 11bb73b | 2011-02-25 20:39:58 -0800 | [diff] [blame] | 391 | } |
| 392 | |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 393 | protected void rebuildValues() { |
| 394 | setValues(mKind, mEntry, mState, mReadOnly, mViewIdGenerator); |
| 395 | } |
| 396 | |
| 397 | /** |
Brian Attwell | 8f9d84f | 2014-11-03 23:17:04 -0800 | [diff] [blame] | 398 | * Prepare this editor using the given {@link DataKind} for defining structure and |
| 399 | * {@link ValuesDelta} describing the content to edit. When overriding this, be careful |
| 400 | * to call {@link #updateEmptiness} at the end. |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 401 | */ |
| 402 | @Override |
Maurice Chu | 851222a | 2012-06-21 11:43:08 -0700 | [diff] [blame] | 403 | public void setValues(DataKind kind, ValuesDelta entry, RawContactDelta state, boolean readOnly, |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 404 | ViewIdGenerator vig) { |
| 405 | mKind = kind; |
| 406 | mEntry = entry; |
| 407 | mState = state; |
| 408 | mReadOnly = readOnly; |
| 409 | mViewIdGenerator = vig; |
| 410 | setId(vig.getId(state, kind, entry, ViewIdGenerator.NO_VIEW_INDEX)); |
| 411 | |
| 412 | if (!entry.isVisible()) { |
| 413 | // Hide ourselves entirely if deleted |
| 414 | setVisibility(View.GONE); |
| 415 | return; |
| 416 | } |
| 417 | setVisibility(View.VISIBLE); |
| 418 | |
| 419 | // Display label selector if multiple types available |
Walter Jang | f7dfa54 | 2015-10-26 14:27:27 -0700 | [diff] [blame] | 420 | final boolean hasTypes = RawContactModifier.hasEditTypes(kind); |
| 421 | setupLabelButton(hasTypes); |
Katherine Kuan | 63ffb90 | 2011-04-26 19:53:40 -0700 | [diff] [blame] | 422 | mLabel.setEnabled(!readOnly && isEnabled()); |
Walter Jang | 155299e | 2016-08-25 10:38:52 -0700 | [diff] [blame] | 423 | if (mKind.titleRes > 0) { |
| 424 | mLabel.setContentDescription(getContext().getResources().getString(mKind.titleRes)); |
| 425 | } |
Tingting Wang | cfa628c | 2016-07-13 17:31:06 -0700 | [diff] [blame] | 426 | mType = RawContactModifier.getCurrentType(entry, kind); |
| 427 | rebuildLabel(); |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | public ValuesDelta getValues() { |
| 431 | return mEntry; |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Prepare dialog for entering a custom label. The input value is trimmed: white spaces before |
| 436 | * and after the input text is removed. |
| 437 | * <p> |
| 438 | * If the final value is empty, this change request is ignored; |
| 439 | * no empty text is allowed in any custom label. |
| 440 | */ |
| 441 | private Dialog createCustomDialog() { |
Brian Attwell | f140227 | 2014-12-16 16:00:08 -0800 | [diff] [blame] | 442 | final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); |
Daniel Lehmann | a04dc9c | 2012-04-14 16:09:48 -0700 | [diff] [blame] | 443 | final LayoutInflater layoutInflater = LayoutInflater.from(builder.getContext()); |
Adam Powell | eb765ac | 2011-11-22 12:28:17 -0800 | [diff] [blame] | 444 | builder.setTitle(R.string.customLabelPickerTitle); |
| 445 | |
Daniel Lehmann | a04dc9c | 2012-04-14 16:09:48 -0700 | [diff] [blame] | 446 | final View view = layoutInflater.inflate(R.layout.contact_editor_label_name_dialog, null); |
| 447 | final EditText editText = (EditText) view.findViewById(R.id.custom_dialog_content); |
| 448 | editText.setInputType(INPUT_TYPE_CUSTOM); |
| 449 | editText.setSaveEnabled(true); |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 450 | |
Daniel Lehmann | a04dc9c | 2012-04-14 16:09:48 -0700 | [diff] [blame] | 451 | builder.setView(view); |
| 452 | editText.requestFocus(); |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 453 | |
| 454 | builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
| 455 | @Override |
| 456 | public void onClick(DialogInterface dialog, int which) { |
Daniel Lehmann | a04dc9c | 2012-04-14 16:09:48 -0700 | [diff] [blame] | 457 | final String customText = editText.getText().toString().trim(); |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 458 | if (ContactsUtils.isGraphic(customText)) { |
Dmitri Plotnikov | 14918c0 | 2010-12-07 17:20:27 -0800 | [diff] [blame] | 459 | final List<EditType> allTypes = |
Tingting Wang | 6062cec | 2015-12-10 14:54:59 -0800 | [diff] [blame] | 460 | RawContactModifier.getValidTypes(mState, mKind, null, true, null, true); |
Dmitri Plotnikov | 14918c0 | 2010-12-07 17:20:27 -0800 | [diff] [blame] | 461 | mType = null; |
| 462 | for (EditType editType : allTypes) { |
| 463 | if (editType.customColumn != null) { |
| 464 | mType = editType; |
| 465 | break; |
| 466 | } |
| 467 | } |
| 468 | if (mType == null) return; |
| 469 | |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 470 | mEntry.put(mKind.typeColumn, mType.rawValue); |
| 471 | mEntry.put(mType.customColumn, customText); |
| 472 | rebuildLabel(); |
| 473 | requestFocusForFirstEditField(); |
| 474 | onLabelRebuilt(); |
| 475 | } |
| 476 | } |
| 477 | }); |
| 478 | |
| 479 | builder.setNegativeButton(android.R.string.cancel, null); |
| 480 | |
Daniel Lehmann | a04dc9c | 2012-04-14 16:09:48 -0700 | [diff] [blame] | 481 | final AlertDialog dialog = builder.create(); |
| 482 | dialog.setOnShowListener(new OnShowListener() { |
| 483 | @Override |
| 484 | public void onShow(DialogInterface dialogInterface) { |
| 485 | updateCustomDialogOkButtonState(dialog, editText); |
| 486 | } |
| 487 | }); |
| 488 | editText.addTextChangedListener(new TextWatcher() { |
| 489 | @Override |
| 490 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 491 | } |
| 492 | |
| 493 | @Override |
| 494 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 495 | } |
| 496 | |
| 497 | @Override |
| 498 | public void afterTextChanged(Editable s) { |
| 499 | updateCustomDialogOkButtonState(dialog, editText); |
| 500 | } |
| 501 | }); |
| 502 | dialog.getWindow().setSoftInputMode( |
| 503 | WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); |
| 504 | |
| 505 | return dialog; |
| 506 | } |
| 507 | |
| 508 | /* package */ void updateCustomDialogOkButtonState(AlertDialog dialog, EditText editText) { |
| 509 | final Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE); |
| 510 | okButton.setEnabled(!TextUtils.isEmpty(editText.getText().toString().trim())); |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /** |
| 514 | * Called after the label has changed (either chosen from the list or entered in the Dialog) |
| 515 | */ |
| 516 | protected void onLabelRebuilt() { |
| 517 | } |
| 518 | |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 519 | protected void onTypeSelectionChange(int position) { |
| 520 | EditType selected = mEditTypeAdapter.getItem(position); |
| 521 | // See if the selection has in fact changed |
| 522 | if (mEditTypeAdapter.hasCustomSelection() && selected == CUSTOM_SELECTION) { |
| 523 | return; |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 526 | if (mType == selected && mType.customColumn == null) { |
| 527 | return; |
| 528 | } |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 529 | |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 530 | if (selected.customColumn != null) { |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 531 | showDialog(DIALOG_ID_CUSTOM); |
| 532 | } else { |
| 533 | // User picked type, and we're sure it's ok to actually write the entry. |
| 534 | mType = selected; |
| 535 | mEntry.put(mKind.typeColumn, mType.rawValue); |
Gary Mai | 186d791 | 2016-08-10 14:41:45 -0700 | [diff] [blame] | 536 | mSelectedLabelIndex = position; |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 537 | rebuildLabel(); |
| 538 | requestFocusForFirstEditField(); |
| 539 | onLabelRebuilt(); |
| 540 | } |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | /* package */ |
| 544 | void showDialog(int bundleDialogId) { |
| 545 | Bundle bundle = new Bundle(); |
| 546 | bundle.putInt(DIALOG_ID_KEY, bundleDialogId); |
| 547 | getDialogManager().showDialogInView(this, bundle); |
| 548 | } |
| 549 | |
| 550 | private DialogManager getDialogManager() { |
| 551 | if (mDialogManager == null) { |
| 552 | Context context = getContext(); |
| 553 | if (!(context instanceof DialogManager.DialogShowingViewActivity)) { |
| 554 | throw new IllegalStateException( |
| 555 | "View must be hosted in an Activity that implements " + |
| 556 | "DialogManager.DialogShowingViewActivity"); |
| 557 | } |
| 558 | mDialogManager = ((DialogManager.DialogShowingViewActivity)context).getDialogManager(); |
| 559 | } |
| 560 | return mDialogManager; |
| 561 | } |
| 562 | |
| 563 | @Override |
| 564 | public Dialog createDialog(Bundle bundle) { |
| 565 | if (bundle == null) throw new IllegalArgumentException("bundle must not be null"); |
| 566 | int dialogId = bundle.getInt(DIALOG_ID_KEY); |
| 567 | switch (dialogId) { |
| 568 | case DIALOG_ID_CUSTOM: |
| 569 | return createCustomDialog(); |
| 570 | default: |
| 571 | throw new IllegalArgumentException("Invalid dialogId: " + dialogId); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | protected abstract void requestFocusForFirstEditField(); |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 576 | |
| 577 | private class EditTypeAdapter extends ArrayAdapter<EditType> { |
| 578 | private final LayoutInflater mInflater; |
| 579 | private boolean mHasCustomSelection; |
Brian Attwell | d690dff | 2014-12-02 15:04:56 -0800 | [diff] [blame] | 580 | private int mTextColorHintUnfocused; |
| 581 | private int mTextColorDark; |
Gary Mai | 186d791 | 2016-08-10 14:41:45 -0700 | [diff] [blame] | 582 | private int mSelectedIndex; |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 583 | |
| 584 | public EditTypeAdapter(Context context) { |
| 585 | super(context, 0); |
| 586 | mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
Brian Attwell | d690dff | 2014-12-02 15:04:56 -0800 | [diff] [blame] | 587 | mTextColorHintUnfocused = context.getResources().getColor( |
| 588 | R.color.editor_disabled_text_color); |
Brian Attwell | d690dff | 2014-12-02 15:04:56 -0800 | [diff] [blame] | 589 | mTextColorDark = context.getResources().getColor(R.color.primary_text_color); |
| 590 | |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 591 | |
Dmitri Plotnikov | 4fa9cd0 | 2010-12-10 17:40:38 -0800 | [diff] [blame] | 592 | if (mType != null && mType.customColumn != null) { |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 593 | |
| 594 | // Use custom label string when present |
| 595 | final String customText = mEntry.getAsString(mType.customColumn); |
| 596 | if (customText != null) { |
| 597 | add(CUSTOM_SELECTION); |
| 598 | mHasCustomSelection = true; |
| 599 | } |
| 600 | } |
| 601 | |
Tingting Wang | 6062cec | 2015-12-10 14:54:59 -0800 | [diff] [blame] | 602 | addAll(RawContactModifier.getValidTypes(mState, mKind, mType, true, null, false)); |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | public boolean hasCustomSelection() { |
| 606 | return mHasCustomSelection; |
| 607 | } |
| 608 | |
| 609 | @Override |
| 610 | public View getView(int position, View convertView, ViewGroup parent) { |
Brian Attwell | d690dff | 2014-12-02 15:04:56 -0800 | [diff] [blame] | 611 | final TextView view = createViewFromResource( |
Brian Attwell | 043fba6 | 2014-10-30 11:11:56 -0700 | [diff] [blame] | 612 | position, convertView, parent, R.layout.edit_simple_spinner_item); |
| 613 | // We don't want any background on this view. The background would obscure |
| 614 | // the spinner's background. |
| 615 | view.setBackground(null); |
Brian Attwell | d690dff | 2014-12-02 15:04:56 -0800 | [diff] [blame] | 616 | // The text color should be a very light hint color when unfocused and empty. When |
| 617 | // focused and empty, use a less light hint color. When non-empty, use a dark non-hint |
| 618 | // color. |
| 619 | if (!LabeledEditorView.this.isEmpty()) { |
| 620 | view.setTextColor(mTextColorDark); |
Brian Attwell | d690dff | 2014-12-02 15:04:56 -0800 | [diff] [blame] | 621 | } else { |
| 622 | view.setTextColor(mTextColorHintUnfocused); |
| 623 | } |
Brian Attwell | 043fba6 | 2014-10-30 11:11:56 -0700 | [diff] [blame] | 624 | return view; |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | @Override |
| 628 | public View getDropDownView(int position, View convertView, ViewGroup parent) { |
Gary Mai | 186d791 | 2016-08-10 14:41:45 -0700 | [diff] [blame] | 629 | final CheckedTextView dropDownView = (CheckedTextView) createViewFromResource( |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 630 | position, convertView, parent, android.R.layout.simple_spinner_dropdown_item); |
Gary Mai | 186d791 | 2016-08-10 14:41:45 -0700 | [diff] [blame] | 631 | dropDownView.setBackground(getContext().getDrawable(R.drawable.drawer_item_background)); |
| 632 | dropDownView.setChecked(position == mSelectedIndex); |
| 633 | return dropDownView; |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 634 | } |
| 635 | |
Brian Attwell | d690dff | 2014-12-02 15:04:56 -0800 | [diff] [blame] | 636 | private TextView createViewFromResource(int position, View convertView, ViewGroup parent, |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 637 | int resource) { |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 638 | TextView textView; |
| 639 | |
| 640 | if (convertView == null) { |
Katherine Kuan | fd70903 | 2011-08-02 14:18:16 -0700 | [diff] [blame] | 641 | textView = (TextView) mInflater.inflate(resource, parent, false); |
Brian Attwell | 043fba6 | 2014-10-30 11:11:56 -0700 | [diff] [blame] | 642 | textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension( |
| 643 | R.dimen.editor_form_text_size)); |
Brian Attwell | d690dff | 2014-12-02 15:04:56 -0800 | [diff] [blame] | 644 | textView.setTextColor(mTextColorDark); |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 645 | } else { |
Katherine Kuan | fd70903 | 2011-08-02 14:18:16 -0700 | [diff] [blame] | 646 | textView = (TextView) convertView; |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 647 | } |
| 648 | |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 649 | EditType type = getItem(position); |
| 650 | String text; |
| 651 | if (type == CUSTOM_SELECTION) { |
| 652 | text = mEntry.getAsString(mType.customColumn); |
| 653 | } else { |
| 654 | text = getContext().getString(type.labelRes); |
| 655 | } |
Katherine Kuan | fd70903 | 2011-08-02 14:18:16 -0700 | [diff] [blame] | 656 | textView.setText(text); |
| 657 | return textView; |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 658 | } |
Gary Mai | 186d791 | 2016-08-10 14:41:45 -0700 | [diff] [blame] | 659 | |
| 660 | public void setSelectedIndex(int selectedIndex) { |
| 661 | mSelectedIndex = selectedIndex; |
| 662 | } |
Dmitri Plotnikov | 2fcfa49 | 2010-12-07 16:10:33 -0800 | [diff] [blame] | 663 | } |
Daniel Lehmann | 392ccec | 2010-11-01 20:50:03 -0700 | [diff] [blame] | 664 | } |