| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.autofill; | 5 package org.chromium.chrome.browser.autofill; |
| 6 | 6 |
| 7 import android.app.AlertDialog; | 7 import android.app.AlertDialog; |
| 8 import android.app.Dialog; |
| 8 import android.content.Context; | 9 import android.content.Context; |
| 9 import android.content.DialogInterface; | |
| 10 import android.content.DialogInterface.OnClickListener; | |
| 11 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
| 12 import android.text.Editable; | 11 import android.text.Editable; |
| 13 import android.text.TextUtils; | 12 import android.text.TextUtils; |
| 14 import android.text.TextWatcher; | 13 import android.text.TextWatcher; |
| 15 import android.util.TypedValue; | 14 import android.util.TypedValue; |
| 16 import android.view.View; | 15 import android.view.View; |
| 16 import android.view.View.OnClickListener; |
| 17 import android.view.View.OnFocusChangeListener; | 17 import android.view.View.OnFocusChangeListener; |
| 18 import android.view.ViewGroup; | 18 import android.view.ViewGroup; |
| 19 import android.view.Window; |
| 19 import android.view.WindowManager; | 20 import android.view.WindowManager; |
| 20 import android.widget.AdapterView; | 21 import android.widget.AdapterView; |
| 21 import android.widget.AdapterView.OnItemSelectedListener; | 22 import android.widget.AdapterView.OnItemSelectedListener; |
| 23 import android.widget.LinearLayout.LayoutParams; |
| 22 import android.widget.Button; | 24 import android.widget.Button; |
| 23 import android.widget.CheckBox; | 25 import android.widget.CheckBox; |
| 24 import android.widget.CompoundButton; | 26 import android.widget.CompoundButton; |
| 25 import android.widget.CompoundButton.OnCheckedChangeListener; | 27 import android.widget.CompoundButton.OnCheckedChangeListener; |
| 26 import android.widget.EditText; | 28 import android.widget.EditText; |
| 27 import android.widget.ScrollView; | |
| 28 import android.widget.Spinner; | 29 import android.widget.Spinner; |
| 29 import android.widget.TextView; | 30 import android.widget.TextView; |
| 30 | 31 |
| 31 import org.chromium.chrome.R; | 32 import org.chromium.chrome.R; |
| 32 import org.chromium.ui.UiUtils; | 33 import org.chromium.ui.UiUtils; |
| 33 import org.chromium.ui.ViewAndroidDelegate; | 34 import org.chromium.ui.ViewAndroidDelegate; |
| 34 | 35 |
| 35 import java.util.Arrays; | 36 import java.util.Arrays; |
| 36 | 37 |
| 37 /** | 38 /** |
| 38 * This is the dialog that will act as the java side controller between the | 39 * This is the dialog that will act as the java side controller between the |
| 39 * AutofillDialogGlue object and the UI elements on the page. It contains the | 40 * AutofillDialogGlue object and the UI elements on the page. It contains the |
| 40 * title and the content views and relays messages from the backend to them. | 41 * title and the content views and relays messages from the backend to them. |
| 41 */ | 42 */ |
| 42 public class AutofillDialog extends AlertDialog | 43 public class AutofillDialog extends Dialog |
| 43 implements OnClickListener, OnItemSelectedListener, | 44 implements OnClickListener, OnItemSelectedListener, |
| 44 AutofillDialogContentView.OnItemEditButtonClickedListener, | 45 AutofillDialogView.OnItemEditButtonClickedListener, |
| 45 OnFocusChangeListener, ViewAndroidDelegate { | 46 OnFocusChangeListener, ViewAndroidDelegate { |
| 46 private final AutofillDialogContentView mContentView; | 47 private final AutofillDialogView mView; |
| 47 private final AutofillDialogTitleView mTitleView; | 48 private final AutofillDialogTitleView mTitleView; |
| 48 private final AutofillDialogDelegate mDelegate; | 49 private final AutofillDialogDelegate mDelegate; |
| 49 | 50 |
| 50 private AutofillDialogField[][] mAutofillSectionFieldData = | 51 private AutofillDialogField[][] mAutofillSectionFieldData = |
| 51 new AutofillDialogField[AutofillDialogConstants.NUM_SECTIONS][]; | 52 new AutofillDialogField[AutofillDialogConstants.NUM_SECTIONS][]; |
| 52 private TextWatcher mCurrentTextWatcher; | 53 private TextWatcher mCurrentTextWatcher; |
| 53 private int mFocusedFieldNativePointer; | 54 private int mFocusedFieldNativePointer; |
| 54 private EditText mFocusedField; | 55 private EditText mFocusedField; |
| 55 | 56 |
| 56 /** | 57 /** |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 /** | 205 /** |
| 205 * @param section The section. | 206 * @param section The section. |
| 206 * @param position The index of an item. | 207 * @param position The index of an item. |
| 207 * @return Whether an item is the "Add..." item. | 208 * @return Whether an item is the "Add..." item. |
| 208 */ | 209 */ |
| 209 public boolean isTheAddItem(int section, int position); | 210 public boolean isTheAddItem(int section, int position); |
| 210 } | 211 } |
| 211 | 212 |
| 212 protected AutofillDialog(Context context, AutofillDialogDelegate delegate) { | 213 protected AutofillDialog(Context context, AutofillDialogDelegate delegate) { |
| 213 super(context); | 214 super(context); |
| 215 requestWindowFeature(Window.FEATURE_NO_TITLE); |
| 214 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUS
T_RESIZE); | 216 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUS
T_RESIZE); |
| 215 mDelegate = delegate; | 217 mDelegate = delegate; |
| 218 mView = (AutofillDialogView) getLayoutInflater(). |
| 219 inflate(R.layout.autofill_dialog_content, null); |
| 216 | 220 |
| 217 mTitleView = new AutofillDialogTitleView(getContext()); | 221 mTitleView = (AutofillDialogTitleView) mView.findViewById(R.id.title); |
| 218 mTitleView.setOnItemSelectedListener(this); | 222 mTitleView.setOnItemSelectedListener(this); |
| 219 setCustomTitle(mTitleView); | |
| 220 | |
| 221 ScrollView scroll = new ScrollView(context); | |
| 222 mContentView = (AutofillDialogContentView) getLayoutInflater(). | |
| 223 inflate(R.layout.autofill_dialog_content, null); | |
| 224 mContentView.setAutofillDialog(this); | |
| 225 | 223 |
| 226 getSaveLocallyCheckBox().setText(mDelegate.getSaveLocallyText()); | 224 getSaveLocallyCheckBox().setText(mDelegate.getSaveLocallyText()); |
| 227 getSaveLocallyCheckBox().setChecked(true); | 225 getSaveLocallyCheckBox().setChecked(true); |
| 228 | 226 |
| 229 String[] labels = new String[AutofillDialogConstants.NUM_SECTIONS]; | 227 String[] labels = new String[AutofillDialogConstants.NUM_SECTIONS]; |
| 230 for (int i = 0; i < AutofillDialogConstants.NUM_SECTIONS; i++) { | 228 for (int i = 0; i < AutofillDialogConstants.NUM_SECTIONS; i++) { |
| 231 labels[i] = mDelegate.getLabelForSection(i); | 229 labels[i] = mDelegate.getLabelForSection(i); |
| 232 } | 230 } |
| 233 mContentView.initializeLabelsForEachSection(labels); | 231 getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARE
NT); |
| 234 scroll.addView(mContentView); | 232 setContentView(mView); |
| 235 setView(scroll); | 233 mView.initialize(this); |
| 234 mView.initializeLabelsForEachSection(labels); |
| 236 | 235 |
| 237 setButton(AlertDialog.BUTTON_NEGATIVE, | 236 setButton(AlertDialog.BUTTON_NEGATIVE, |
| 238 mDelegate.getDialogButtonText(AutofillDialogConstants.DIALOG_BUT
TON_CANCEL), this); | 237 mDelegate.getDialogButtonText(AutofillDialogConstants.DIALOG_BUT
TON_CANCEL), this); |
| 239 setButton(AlertDialog.BUTTON_POSITIVE, | 238 setButton(AlertDialog.BUTTON_POSITIVE, |
| 240 mDelegate.getDialogButtonText(AutofillDialogConstants.DIALOG_BUT
TON_OK), this); | 239 mDelegate.getDialogButtonText(AutofillDialogConstants.DIALOG_BUT
TON_OK), this); |
| 241 | 240 |
| 242 mContentView.setOnItemSelectedListener(this); | 241 mView.setOnItemSelectedListener(this); |
| 243 mContentView.setOnItemEditButtonClickedListener(this); | 242 mView.setOnItemEditButtonClickedListener(this); |
| 244 } | 243 } |
| 245 | 244 |
| 246 private AutofillDialogField[] getFieldsForSection(int section) { | 245 private AutofillDialogField[] getFieldsForSection(int section) { |
| 247 if (section < 0 || section >= mAutofillSectionFieldData.length) { | 246 if (section < 0 || section >= mAutofillSectionFieldData.length) { |
| 248 assert false; | 247 assert false; |
| 249 return new AutofillDialogField[0]; | 248 return new AutofillDialogField[0]; |
| 250 } | 249 } |
| 251 return mAutofillSectionFieldData[section]; | 250 return mAutofillSectionFieldData[section]; |
| 252 } | 251 } |
| 253 | 252 |
| 254 private void setFieldsForSection(int section, AutofillDialogField[] fields)
{ | 253 private void setFieldsForSection(int section, AutofillDialogField[] fields)
{ |
| 255 if (section < 0 || section >= mAutofillSectionFieldData.length) return; | 254 if (section < 0 || section >= mAutofillSectionFieldData.length) return; |
| 256 mAutofillSectionFieldData[section] = fields; | 255 mAutofillSectionFieldData[section] = fields; |
| 257 } | 256 } |
| 258 | 257 |
| 259 @Override | 258 @Override |
| 260 public void dismiss() { | 259 public void dismiss() { |
| 261 // Any calls coming from the Android View system are ignored. | 260 // Any calls coming from the Android View system are ignored. |
| 262 // If the dialog should be dismissed, internalDismiss() should be used. | 261 // If the dialog should be dismissed, internalDismiss() should be used. |
| 263 // TODO(yusufo): http://crbug.com/234477 Consider not using AlertDialog. | 262 // TODO(yusufo): http://crbug.com/234477 Consider not using AlertDialog. |
| 264 } | 263 } |
| 265 | 264 |
| 266 @Override | 265 @Override |
| 267 public void show() { | 266 public void show() { |
| 268 mContentView.createAdapters(); | 267 mView.createAdapters(); |
| 269 super.show(); | 268 super.show(); |
| 270 } | 269 } |
| 271 | 270 |
| 272 /** | 271 /** |
| 273 * Dismisses the dialog. | 272 * Dismisses the dialog. |
| 274 **/ | 273 **/ |
| 275 private void internalDismiss() { | 274 private void internalDismiss() { |
| 276 super.dismiss(); | 275 super.dismiss(); |
| 277 mDelegate.dialogDismissed(); | 276 mDelegate.dialogDismissed(); |
| 278 } | 277 } |
| 279 | 278 |
| 279 private void setButton(int which, String text, android.view.View.OnClickList
ener listener) { |
| 280 Button button = getButton(which); |
| 281 |
| 282 if (button == null) return; |
| 283 assert(button != null); |
| 284 |
| 285 button.setVisibility(View.VISIBLE); |
| 286 button.setText(text); |
| 287 button.setOnClickListener(listener); |
| 288 } |
| 289 |
| 290 private Button getButton(int which) { |
| 291 if (which == AlertDialog.BUTTON_POSITIVE) { |
| 292 return (Button) mView.findViewById(R.id.positive_button); |
| 293 } else { |
| 294 return (Button) mView.findViewById(R.id.negative_button); |
| 295 } |
| 296 } |
| 297 |
| 280 /** | 298 /** |
| 281 * Get the list associated with this field as a string array. | 299 * Get the list associated with this field as a string array. |
| 282 * @param field The field for which the list should be returned. | 300 * @param field The field for which the list should be returned. |
| 283 * @return A string array that contains the list | 301 * @return A string array that contains the list |
| 284 **/ | 302 **/ |
| 285 public String[] getListForField(int field) { | 303 public String[] getListForField(int field) { |
| 286 return mDelegate.getListForField(field); | 304 return mDelegate.getListForField(field); |
| 287 } | 305 } |
| 288 | 306 |
| 289 @Override | 307 @Override |
| 290 public void onClick(DialogInterface dialog, int which) { | 308 public void onClick(View button) { |
| 309 int which; |
| 310 if (button.getId() == R.id.positive_button) { |
| 311 which = AlertDialog.BUTTON_POSITIVE; |
| 312 } else { |
| 313 which = AlertDialog.BUTTON_NEGATIVE; |
| 314 } |
| 315 |
| 291 // Note that the dialog will NOT be dismissed automatically. | 316 // Note that the dialog will NOT be dismissed automatically. |
| 292 if (!mContentView.isInEditingMode()) { | 317 if (!mView.isInEditingMode()) { |
| 293 if (which == AlertDialog.BUTTON_POSITIVE) { | 318 if (which == AlertDialog.BUTTON_POSITIVE) { |
| 294 // The controller will dismiss the dialog if the validation succ
eeds. | 319 // The controller will dismiss the dialog if the validation succ
eeds. |
| 295 // Otherwise, the dialog should be in the operational state to s
how | 320 // Otherwise, the dialog should be in the operational state to s
how |
| 296 // errors, challenges and notifications. | 321 // errors, challenges and notifications. |
| 297 mDelegate.dialogSubmit(); | 322 mDelegate.dialogSubmit(); |
| 298 } else { | 323 } else { |
| 299 // The dialog will be dismissed with a call to dismissAutofillDi
alog(). | 324 // The dialog will be dismissed with a call to dismissAutofillDi
alog(). |
| 300 mDelegate.dialogCancel(); | 325 mDelegate.dialogCancel(); |
| 301 } | 326 } |
| 302 // The buttons will be updated as the result of a controller callbac
k. | 327 // The buttons will be updated as the result of a controller callbac
k. |
| 303 disableButtons(); | 328 disableButtons(); |
| 304 return; | 329 return; |
| 305 } | 330 } |
| 306 | 331 |
| 307 int section = mContentView.getCurrentSection(); | 332 int section = mView.getCurrentSection(); |
| 308 assert(section != AutofillDialogUtils.INVALID_SECTION); | 333 assert(section != AutofillDialogUtils.INVALID_SECTION); |
| 309 | 334 |
| 310 if (which == AlertDialog.BUTTON_POSITIVE) { | 335 if (which == AlertDialog.BUTTON_POSITIVE) { |
| 311 // Switch the layout only if validation passes. | 336 // Switch the layout only if validation passes. |
| 312 if (!mDelegate.editingComplete(section)) return; | 337 if (!mDelegate.editingComplete(section)) return; |
| 313 } else { | 338 } else { |
| 314 mDelegate.editingCancel(section); | 339 mDelegate.editingCancel(section); |
| 315 } | 340 } |
| 316 changeLayoutTo(AutofillDialogContentView.LAYOUT_STEADY); | 341 changeLayoutTo(AutofillDialogView.LAYOUT_STEADY); |
| 317 } | 342 } |
| 318 | 343 |
| 319 @Override | 344 @Override |
| 320 public void onItemSelected(AdapterView<?> spinner, View view, int position,
long id) { | 345 public void onItemSelected(AdapterView<?> spinner, View view, int position,
long id) { |
| 321 if (spinner.getId() == R.id.accounts_spinner) { | 346 if (spinner.getId() == R.id.accounts_spinner) { |
| 322 mDelegate.accountSelected(position); | 347 mDelegate.accountSelected(position); |
| 323 return; | 348 return; |
| 324 } | 349 } |
| 325 | 350 |
| 326 int section = AutofillDialogUtils.getSectionForSpinnerID(spinner.getId()
); | 351 int section = AutofillDialogUtils.getSectionForSpinnerID(spinner.getId()
); |
| 327 if (!isTheAddItem(spinner, section, position)) { | 352 if (!isTheAddItem(spinner, section, position)) { |
| 328 mDelegate.itemSelected(section, position); | 353 mDelegate.itemSelected(section, position); |
| 329 return; | 354 return; |
| 330 } | 355 } |
| 331 | 356 |
| 332 onItemEditButtonClicked(section, position); | 357 onItemEditButtonClicked(section, position); |
| 333 } | 358 } |
| 334 | 359 |
| 335 @Override | 360 @Override |
| 336 public void onItemEditButtonClicked(int section, int position) { | 361 public void onItemEditButtonClicked(int section, int position) { |
| 337 mContentView.updateMenuSelectionForSection(section, position); | 362 mView.updateMenuSelectionForSection(section, position); |
| 338 mDelegate.itemSelected(section, position); | 363 mDelegate.itemSelected(section, position); |
| 339 mDelegate.editingStart(section); | 364 mDelegate.editingStart(section); |
| 340 | 365 |
| 341 changeLayoutTo(AutofillDialogContentView.getLayoutModeForSection(section
)); | 366 changeLayoutTo(AutofillDialogView.getLayoutModeForSection(section)); |
| 342 } | 367 } |
| 343 | 368 |
| 344 @Override | 369 @Override |
| 345 public void onNothingSelected(AdapterView<?> spinner) { | 370 public void onNothingSelected(AdapterView<?> spinner) { |
| 346 } | 371 } |
| 347 | 372 |
| 348 /** | 373 /** |
| 349 * @param spinner The dropdown that was selected by the user. | 374 * @param spinner The dropdown that was selected by the user. |
| 350 * @param section The section that the dropdown corresponds to. | 375 * @param section The section that the dropdown corresponds to. |
| 351 * @param position The position for the selected item in the dropdown. | 376 * @param position The position for the selected item in the dropdown. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 366 | 391 |
| 367 /** | 392 /** |
| 368 * Updates the buttons state for the given mode. | 393 * Updates the buttons state for the given mode. |
| 369 * @param mode The layout mode. | 394 * @param mode The layout mode. |
| 370 */ | 395 */ |
| 371 private void updateButtons(int mode) { | 396 private void updateButtons(int mode) { |
| 372 final Button negative = getButton(BUTTON_NEGATIVE); | 397 final Button negative = getButton(BUTTON_NEGATIVE); |
| 373 final Button positive = getButton(BUTTON_POSITIVE); | 398 final Button positive = getButton(BUTTON_POSITIVE); |
| 374 | 399 |
| 375 switch (mode) { | 400 switch (mode) { |
| 376 case AutofillDialogContentView.LAYOUT_FETCHING: | 401 case AutofillDialogView.LAYOUT_FETCHING: |
| 377 negative.setText(mDelegate.getDialogButtonText( | 402 negative.setText(mDelegate.getDialogButtonText( |
| 378 AutofillDialogConstants.DIALOG_BUTTON_CANCEL)); | 403 AutofillDialogConstants.DIALOG_BUTTON_CANCEL)); |
| 379 negative.setEnabled(mDelegate.isDialogButtonEnabled( | 404 negative.setEnabled(mDelegate.isDialogButtonEnabled( |
| 380 AutofillDialogConstants.DIALOG_BUTTON_CANCEL)); | 405 AutofillDialogConstants.DIALOG_BUTTON_CANCEL)); |
| 381 positive.setText(mDelegate.getDialogButtonText( | 406 positive.setText(mDelegate.getDialogButtonText( |
| 382 AutofillDialogConstants.DIALOG_BUTTON_OK)); | 407 AutofillDialogConstants.DIALOG_BUTTON_OK)); |
| 383 positive.setEnabled(false); | 408 positive.setEnabled(false); |
| 384 mTitleView.setAccountChooserEnabled(false); | 409 mTitleView.setAccountChooserEnabled(false); |
| 385 break; | 410 break; |
| 386 case AutofillDialogContentView.LAYOUT_STEADY: | 411 case AutofillDialogView.LAYOUT_STEADY: |
| 387 negative.setText(mDelegate.getDialogButtonText( | 412 negative.setText(mDelegate.getDialogButtonText( |
| 388 AutofillDialogConstants.DIALOG_BUTTON_CANCEL)); | 413 AutofillDialogConstants.DIALOG_BUTTON_CANCEL)); |
| 389 negative.setEnabled(mDelegate.isDialogButtonEnabled( | 414 negative.setEnabled(mDelegate.isDialogButtonEnabled( |
| 390 AutofillDialogConstants.DIALOG_BUTTON_CANCEL)); | 415 AutofillDialogConstants.DIALOG_BUTTON_CANCEL)); |
| 391 positive.setText(mDelegate.getDialogButtonText( | 416 positive.setText(mDelegate.getDialogButtonText( |
| 392 AutofillDialogConstants.DIALOG_BUTTON_OK)); | 417 AutofillDialogConstants.DIALOG_BUTTON_OK)); |
| 393 positive.setEnabled(mDelegate.isDialogButtonEnabled( | 418 positive.setEnabled(mDelegate.isDialogButtonEnabled( |
| 394 AutofillDialogConstants.DIALOG_BUTTON_OK)); | 419 AutofillDialogConstants.DIALOG_BUTTON_OK)); |
| 395 mTitleView.setAccountChooserEnabled(true); | 420 mTitleView.setAccountChooserEnabled(true); |
| 396 break; | 421 break; |
| 397 default: | 422 default: |
| 398 negative.setText(R.string.autofill_negative_button_editing); | 423 negative.setText(R.string.autofill_negative_button_editing); |
| 399 negative.setEnabled(true); | 424 negative.setEnabled(true); |
| 400 positive.setText(R.string.autofill_positive_button_editing); | 425 positive.setText(R.string.autofill_positive_button_editing); |
| 401 positive.setEnabled(true); | 426 positive.setEnabled(true); |
| 402 mTitleView.setAccountChooserEnabled(false); | 427 mTitleView.setAccountChooserEnabled(false); |
| 403 break; | 428 break; |
| 404 } | 429 } |
| 405 } | 430 } |
| 406 | 431 |
| 407 /** | 432 /** |
| 408 * Transitions the layout shown to a given layout. | 433 * Transitions the layout shown to a given layout. |
| 409 * @param mode The layout mode to transition to. | 434 * @param mode The layout mode to transition to. |
| 410 */ | 435 */ |
| 411 private void changeLayoutTo(int mode) { | 436 private void changeLayoutTo(int mode) { |
| 412 mContentView.changeLayoutTo(mode); | 437 mView.changeLayoutTo(mode); |
| 413 updateButtons(mode); | 438 updateButtons(mode); |
| 414 UiUtils.hideKeyboard(mContentView); | 439 UiUtils.hideKeyboard(mView); |
| 415 if (mFocusedField != null && !mContentView.isInEditingMode()) { | 440 if (mFocusedField != null && !mView.isInEditingMode()) { |
| 416 mFocusedField.removeTextChangedListener(mCurrentTextWatcher); | 441 mFocusedField.removeTextChangedListener(mCurrentTextWatcher); |
| 417 mFocusedField = null; | 442 mFocusedField = null; |
| 418 } | 443 } |
| 419 } | 444 } |
| 420 | 445 |
| 421 /** | 446 /** |
| 422 * Updates the account chooser dropdown with given accounts. | 447 * Updates the account chooser dropdown with given accounts. |
| 423 * @param accounts The accounts to be used for the dropdown. | 448 * @param accounts The accounts to be used for the dropdown. |
| 424 * @param selectedAccountIndex The index of a currently selected account. | 449 * @param selectedAccountIndex The index of a currently selected account. |
| 425 */ | 450 */ |
| 426 public void updateAccountChooser(String[] accounts, int selectedAccountIndex
) { | 451 public void updateAccountChooser(String[] accounts, int selectedAccountIndex
) { |
| 427 mTitleView.updateAccountsAndSelect(Arrays.asList(accounts), selectedAcco
untIndex); | 452 mTitleView.updateAccountsAndSelect(Arrays.asList(accounts), selectedAcco
untIndex); |
| 428 mContentView.updateLegalDocumentsText(mDelegate.getLegalDocumentsText())
; | 453 mView.updateLegalDocumentsText(mDelegate.getLegalDocumentsText()); |
| 429 } | 454 } |
| 430 | 455 |
| 431 /** | 456 /** |
| 432 * Notifies the dialog that the underlying model is changed and all sections
will be updated. | 457 * Notifies the dialog that the underlying model is changed and all sections
will be updated. |
| 433 * Any editing should be invalidated. | 458 * Any editing should be invalidated. |
| 434 * The dialog should either go to the FETCHING or to the STEADY mode. | 459 * The dialog should either go to the FETCHING or to the STEADY mode. |
| 435 * @param fetchingIsActive If true, the data is being fetched and is not yet
available. | 460 * @param fetchingIsActive If true, the data is being fetched and is not yet
available. |
| 436 */ | 461 */ |
| 437 public void modelChanged(boolean fetchingIsActive) { | 462 public void modelChanged(boolean fetchingIsActive) { |
| 438 if (fetchingIsActive) { | 463 if (fetchingIsActive) { |
| 439 changeLayoutTo(AutofillDialogContentView.LAYOUT_FETCHING); | 464 changeLayoutTo(AutofillDialogView.LAYOUT_FETCHING); |
| 440 mTitleView.hideLogoAndAccountChooserVisibility(); | 465 mTitleView.hideLogoAndAccountChooserVisibility(); |
| 441 } else { | 466 } else { |
| 442 changeLayoutTo(AutofillDialogContentView.LAYOUT_STEADY); | 467 changeLayoutTo(AutofillDialogView.LAYOUT_STEADY); |
| 443 } | 468 } |
| 444 } | 469 } |
| 445 | 470 |
| 446 /** | 471 /** |
| 447 * Update notification area with the provided notifications. | 472 * Update notification area with the provided notifications. |
| 448 * @param notifications Array of notifications to be displayed in the dialog
. | 473 * @param notifications Array of notifications to be displayed in the dialog
. |
| 449 */ | 474 */ |
| 450 public void updateNotificationArea(AutofillDialogNotification[] notification
s) { | 475 public void updateNotificationArea(AutofillDialogNotification[] notification
s) { |
| 451 // Clear all the previous notifications | 476 // Clear all the previous notifications |
| 452 CheckBox checkBox = ((CheckBox) findViewById(R.id.top_checkbox_notificat
ion)); | 477 CheckBox checkBox = ((CheckBox) findViewById(R.id.top_checkbox_notificat
ion)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 * @param suggestionIcon The suggestion icon. | 525 * @param suggestionIcon The suggestion icon. |
| 501 * @param suggestionTextExtra The suggestion text extra. | 526 * @param suggestionTextExtra The suggestion text extra. |
| 502 * @param suggestionIconExtra The suggestion icon extra. | 527 * @param suggestionIconExtra The suggestion icon extra. |
| 503 * @param suggestionSectionEditable Whether the section is editable. | 528 * @param suggestionSectionEditable Whether the section is editable. |
| 504 * @param menuItems The array that contains the dropdown items to be shown f
or the section. | 529 * @param menuItems The array that contains the dropdown items to be shown f
or the section. |
| 505 * @param selectedMenuItem The menu item that is currently selected or -1 ot
herwise. | 530 * @param selectedMenuItem The menu item that is currently selected or -1 ot
herwise. |
| 506 * @param clobberInputs Whether to clobber the user input. | 531 * @param clobberInputs Whether to clobber the user input. |
| 507 * @param fieldTypeToAlwaysClobber Field type to be clobbered anyway, or UNK
NOWN_TYPE. | 532 * @param fieldTypeToAlwaysClobber Field type to be clobbered anyway, or UNK
NOWN_TYPE. |
| 508 */ | 533 */ |
| 509 public void updateSection(int section, boolean visible, AutofillDialogField[
] dialogInputs, | 534 public void updateSection(int section, boolean visible, AutofillDialogField[
] dialogInputs, |
| 510 String suggestionText, Bitmap suggestionIcon, | 535 String suggestionText, Bitmap suggestionIcon, String suggestionTextE
xtra, |
| 511 String suggestionTextExtra, Bitmap suggestionIconExtra, | 536 Bitmap suggestionIconExtra, boolean suggestionSectionEditabl
e, |
| 512 boolean suggestionSectionEditable, | 537 AutofillDialogMenuItem[] menuItems, |
| 513 AutofillDialogMenuItem[] menuItems, int selectedMenuItem, | 538 int selectedMenuItem, boolean clobberInputs, |
| 514 boolean clobberInputs, int fieldTypeToAlwaysClobber) { | 539 int fieldTypeToAlwaysClobber) { |
| 515 View currentField; | 540 View currentField; |
| 516 String inputValue; | 541 String inputValue; |
| 517 | 542 |
| 518 for (int i = 0; i < dialogInputs.length; i++) { | 543 for (int i = 0; i < dialogInputs.length; i++) { |
| 519 currentField = findViewById(AutofillDialogUtils.getViewIDForField( | 544 currentField = findViewById(AutofillDialogUtils.getViewIDForField( |
| 520 section, dialogInputs[i].mFieldType)); | 545 section, dialogInputs[i].mFieldType)); |
| 521 if (currentField instanceof EditText) { | 546 if (currentField instanceof EditText) { |
| 522 EditText currentEdit = (EditText) currentField; | 547 EditText currentEdit = (EditText) currentField; |
| 523 if (!clobberInputs | 548 if (!clobberInputs |
| 524 && !TextUtils.isEmpty(currentEdit.getText()) | 549 && !TextUtils.isEmpty(currentEdit.getText()) |
| 525 && dialogInputs[i].mFieldType != fieldTypeToAlwaysClobber) { | 550 && dialogInputs[i].mFieldType != fieldTypeToAlwaysClobber) { |
| 526 continue; | 551 continue; |
| 527 } | 552 } |
| 528 | 553 |
| 529 if (AutofillDialogUtils.containsCreditCardInfo(section) | 554 if (AutofillDialogUtils.containsCreditCardInfo(section) |
| 530 && dialogInputs[i].mFieldType | 555 && dialogInputs[i].mFieldType |
| 531 == AutofillDialogConstants.CREDIT_CARD_VERIFICAT
ION_CODE) { | 556 == AutofillDialogConstants.CREDIT_CARD_VERIFICAT
ION_CODE) { |
| 532 currentEdit.setCompoundDrawables(null, null, | 557 currentEdit.setCompoundDrawables(null, null, |
| 533 mContentView.createFieldIconDrawable(suggestionIconE
xtra), null); | 558 mView.createFieldIconDrawable(suggestionIconExtra),
null); |
| 534 } | 559 } |
| 535 | 560 |
| 536 currentEdit.setHint(dialogInputs[i].mPlaceholder); | 561 currentEdit.setHint(dialogInputs[i].mPlaceholder); |
| 537 currentField.setOnFocusChangeListener(this); | 562 currentField.setOnFocusChangeListener(this); |
| 538 inputValue = dialogInputs[i].getValue(); | 563 inputValue = dialogInputs[i].getValue(); |
| 539 if (TextUtils.isEmpty(inputValue)) { | 564 if (TextUtils.isEmpty(inputValue)) { |
| 540 currentEdit.setText(""); | 565 currentEdit.setText(""); |
| 541 } else { | 566 } else { |
| 542 currentEdit.setText(inputValue); | 567 currentEdit.setText(inputValue); |
| 543 } | 568 } |
| 544 } else if (currentField instanceof Spinner) { | 569 } else if (currentField instanceof Spinner) { |
| 545 Spinner currentSpinner = (Spinner) currentField; | 570 Spinner currentSpinner = (Spinner) currentField; |
| 546 for (int k = 0; k < currentSpinner.getCount(); k++) { | 571 for (int k = 0; k < currentSpinner.getCount(); k++) { |
| 547 if (currentSpinner.getItemAtPosition(k).equals(dialogInputs[
i] | 572 if (currentSpinner.getItemAtPosition(k).equals(dialogInputs[
i] |
| 548 .getValue())) { | 573 .getValue())) { |
| 549 currentSpinner.setSelection(k); | 574 currentSpinner.setSelection(k); |
| 550 } | 575 } |
| 551 currentSpinner.setPrompt(dialogInputs[i].mPlaceholder); | 576 currentSpinner.setPrompt(dialogInputs[i].mPlaceholder); |
| 552 } | 577 } |
| 553 } | 578 } |
| 554 } | 579 } |
| 555 setFieldsForSection(section, dialogInputs); | 580 setFieldsForSection(section, dialogInputs); |
| 556 mContentView.setVisibilityForSection(section, visible); | 581 mView.setVisibilityForSection(section, visible); |
| 557 | 582 |
| 558 updateSectionMenuItems(section, | 583 updateSectionMenuItems(section, |
| 559 suggestionText, suggestionIcon, | 584 suggestionText, suggestionIcon, suggestionTextExtra, suggestionI
conExtra, |
| 560 suggestionTextExtra, suggestionIconExtra, suggestionSectionEdita
ble, | 585 suggestionSectionEditable, menuItems, selectedMenuItem); |
| 561 menuItems, selectedMenuItem); | |
| 562 } | 586 } |
| 563 | 587 |
| 564 /** | 588 /** |
| 565 * Updates menu items in a given section with the data provided. | 589 * Updates menu items in a given section with the data provided. |
| 566 * @param section The section to update with the given data. | 590 * @param section The section to update with the given data. |
| 567 * @param suggestionText The suggestion text. | 591 * @param suggestionText The suggestion text. |
| 568 * @param suggestionIcon The suggestion icon. | 592 * @param suggestionIcon The suggestion icon. |
| 569 * @param suggestionTextExtra The suggestion text extra. | 593 * @param suggestionTextExtra The suggestion text extra. |
| 570 * @param suggestionIconExtra The suggestion icon extra. | 594 * @param suggestionIconExtra The suggestion icon extra. |
| 571 * @param suggestionSectionEditable Whether the section is editable. | 595 * @param suggestionSectionEditable Whether the section is editable. |
| 572 * @param menuItems The array that contains the dropdown items to be shown f
or the section. | 596 * @param menuItems The array that contains the dropdown items to be shown f
or the section. |
| 573 * @param selectedMenuItem The menu item that is currently selected or -1 ot
herwise. | 597 * @param selectedMenuItem The menu item that is currently selected or -1 ot
herwise. |
| 574 */ | 598 */ |
| 575 public void updateSectionMenuItems( | 599 public void updateSectionMenuItems( |
| 576 int section, | 600 int section, String suggestionText, Bitmap suggestionIcon, String su
ggestionTextExtra, |
| 577 String suggestionText, Bitmap suggestionIcon, | 601 Bitmap suggestionIconExtra, boolean suggestionSectionEditabl
e, |
| 578 String suggestionTextExtra, Bitmap suggestionIconExtra, | 602 AutofillDialogMenuItem[] menuItems, int selectedMenu
Item) { |
| 579 boolean suggestionSectionEditable, | 603 mView.updateMenuItemsForSection( |
| 580 AutofillDialogMenuItem[] menuItems, int selectedMenuItem) { | 604 section, suggestionText, suggestionIcon, suggestionTextExtra, |
| 581 mContentView.updateMenuItemsForSection( | 605 suggestionIconExtra, suggestionSectionEditable, |
| 582 section, | 606 Arrays.asList(menuItems), selectedMenuItem); |
| 583 suggestionText, suggestionIcon, | |
| 584 suggestionTextExtra, suggestionIconExtra, suggestionSectionEdita
ble, | |
| 585 Arrays.asList(menuItems), selectedMenuItem); | |
| 586 } | 607 } |
| 587 | 608 |
| 588 /** | 609 /** |
| 589 * Update validation error values for the given section. | 610 * Update validation error values for the given section. |
| 590 * @param section The section that needs to be updated. | 611 * @param section The section that needs to be updated. |
| 591 * @param errors The array of errors that were found when validating the fie
lds. | 612 * @param errors The array of errors that were found when validating the fie
lds. |
| 592 */ | 613 */ |
| 593 public void updateSectionErrors(int section, AutofillDialogFieldError[] erro
rs) { | 614 public void updateSectionErrors(int section, AutofillDialogFieldError[] erro
rs) { |
| 594 AutofillDialogField[] fields = getFieldsForSection(section); | 615 AutofillDialogField[] fields = getFieldsForSection(section); |
| 595 if (fields != null) { | 616 if (fields != null) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 // TODO(yusufo) remove this check when all the fields have been adde
d. | 665 // TODO(yusufo) remove this check when all the fields have been adde
d. |
| 645 if (currentField instanceof EditText) { | 666 if (currentField instanceof EditText) { |
| 646 ((EditText) currentField).setText(""); | 667 ((EditText) currentField).setText(""); |
| 647 } else if (currentField instanceof Spinner) { | 668 } else if (currentField instanceof Spinner) { |
| 648 ((Spinner) currentField).setSelected(false); | 669 ((Spinner) currentField).setSelected(false); |
| 649 } | 670 } |
| 650 } | 671 } |
| 651 } | 672 } |
| 652 | 673 |
| 653 private CheckBox getSaveLocallyCheckBox() { | 674 private CheckBox getSaveLocallyCheckBox() { |
| 654 return (CheckBox) mContentView.findViewById(R.id.save_locally_checkbox); | 675 return (CheckBox) mView.findViewById(R.id.save_locally_checkbox); |
| 655 } | 676 } |
| 656 | 677 |
| 657 /** | 678 /** |
| 658 * Update the visibility for the save locally checkbox. | 679 * Update the visibility for the save locally checkbox. |
| 659 * @param shouldShow Whether the checkbox should be shown or hidden. | 680 * @param shouldShow Whether the checkbox should be shown or hidden. |
| 660 */ | 681 */ |
| 661 public void updateSaveLocallyCheckBox(boolean shouldShow) { | 682 public void updateSaveLocallyCheckBox(boolean shouldShow) { |
| 662 getSaveLocallyCheckBox().setVisibility( | 683 getSaveLocallyCheckBox().setVisibility( |
| 663 shouldShow ? View.VISIBLE : View.GONE); | 684 shouldShow ? View.VISIBLE : View.GONE); |
| 664 } | 685 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 } | 763 } |
| 743 | 764 |
| 744 /** | 765 /** |
| 745 * Follow the EditText that is currently focused and add/remove text watcher
for that EditText. | 766 * Follow the EditText that is currently focused and add/remove text watcher
for that EditText. |
| 746 * Fields also get validated when one of them is defocused. | 767 * Fields also get validated when one of them is defocused. |
| 747 * @param v View that just got a focus change. | 768 * @param v View that just got a focus change. |
| 748 * @param hasFocus Whether the focus was gained. | 769 * @param hasFocus Whether the focus was gained. |
| 749 */ | 770 */ |
| 750 @Override | 771 @Override |
| 751 public void onFocusChange(View v, boolean hasFocus) { | 772 public void onFocusChange(View v, boolean hasFocus) { |
| 752 if (!mContentView.isInEditingMode()) return; | 773 if (!mView.isInEditingMode()) return; |
| 753 | 774 |
| 754 if (!(v instanceof EditText)) return; | 775 if (!(v instanceof EditText)) return; |
| 755 EditText currentfield = (EditText) v; | 776 EditText currentfield = (EditText) v; |
| 756 | 777 |
| 757 // New EditText just got focused. | 778 // New EditText just got focused. |
| 758 if (hasFocus) mFocusedField = currentfield; | 779 if (hasFocus) mFocusedField = currentfield; |
| 759 | 780 |
| 760 int section = mContentView.getCurrentSection(); | 781 int section = mView.getCurrentSection(); |
| 761 AutofillDialogField[] fields = getFieldsForSection(section); | 782 AutofillDialogField[] fields = getFieldsForSection(section); |
| 762 int fieldType = AutofillDialogConstants.UNKNOWN_TYPE; | 783 int fieldType = AutofillDialogConstants.UNKNOWN_TYPE; |
| 763 int nativePointer = 0; | 784 int nativePointer = 0; |
| 764 for (AutofillDialogField field : fields) { | 785 for (AutofillDialogField field : fields) { |
| 765 View currentView = findViewById(AutofillDialogUtils.getViewIDForFiel
d( | 786 View currentView = findViewById(AutofillDialogUtils.getViewIDForFiel
d( |
| 766 section, field.mFieldType)); | 787 section, field.mFieldType)); |
| 767 if (v.equals(currentView)) { | 788 if (v.equals(currentView)) { |
| 768 fieldType = field.mFieldType; | 789 fieldType = field.mFieldType; |
| 769 nativePointer = field.mNativePointer; | 790 nativePointer = field.mNativePointer; |
| 770 break; | 791 break; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 796 } | 817 } |
| 797 | 818 |
| 798 @Override | 819 @Override |
| 799 public void setAnchorViewPosition(View view, float x, float y, float width,
float height) { | 820 public void setAnchorViewPosition(View view, float x, float y, float width,
float height) { |
| 800 } | 821 } |
| 801 | 822 |
| 802 @Override | 823 @Override |
| 803 public void releaseAnchorView(View anchorView) { | 824 public void releaseAnchorView(View anchorView) { |
| 804 } | 825 } |
| 805 } | 826 } |
| OLD | NEW |