private void resetFormFields(int countryCodeIndex, boolean autoFocusFirstField) { // Save field text so we can restore it after updating the fields for the current country, // and reset mAddressFields. String[] fieldText = new String[mAddressFields.length]; for (int i = 0; i < mAddressFields.length; i++) { if (mAddressFields[i] != null) { fieldText[i] = mAddressFields[i].getEditText().getText().toString(); mAddressFields[i] = null; } } // Remove all address form fields. mWidgetRoot.removeAllViews(); // Get address fields for the selected country. List<Pair<Integer, String>> fields = mAutofillProfileBridge.getAddressUiComponents( mCountryCodes.get(countryCodeIndex), mLanguageCodeString); if (!mUseSavedProfileLanguage) { mLanguageCodeString = mAutofillProfileBridge.getCurrentBestLanguageCode(); } // Create form fields and focus the first field if autoFocusFirstField is true. boolean firstField = true; for (Pair<Integer, String> field : fields) { int fieldId = field.first; String fieldLabel = field.second; FloatLabelLayout fieldFloatLabel = (FloatLabelLayout) mInflater.inflate(R.layout.preference_address_float_label_layout, mWidgetRoot, false); fieldFloatLabel.setHint(fieldLabel); EditText fieldEditText = (EditText) fieldFloatLabel.findViewById(R.id.address_edit_text); fieldEditText.setHint(fieldLabel); fieldEditText.setContentDescription(fieldLabel); fieldEditText.addTextChangedListener(this); if (fieldId == AddressField.STREET_ADDRESS) { fieldEditText.setSingleLine(false); } mAddressFields[fieldId] = fieldFloatLabel; mWidgetRoot.addView(fieldFloatLabel); if (firstField && autoFocusFirstField) { fieldFloatLabel.focusWithoutAnimation(); firstField = false; } } // Add back saved field text. for (int i = 0; i < mAddressFields.length; i++) { if (mAddressFields[i] != null && fieldText[i] != null && !TextUtils.isEmpty(fieldText[i])) { mAddressFields[i].setText(fieldText[i]); } } }
@Override protected void addTopbarItems(LinearLayout topbar) { LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.HORIZONTAL); placementTxt = new EditText(this); placementTxt.setLayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, .9f)); // smaller weight means bigger? placementTxt.setHint(R.string.default_placement); placementTxt.setContentDescription("placementTxt"); layout.addView(placementTxt); layout.addView(createPreloadButton()); topbar.addView(layout); super.addTopbarItems(topbar); // will add start button on the right }