2 * Copyright (C) 2010 Google Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.i18n.addressinput;
19 import android.view.View;
20 import android.widget.EditText;
21 import android.widget.Spinner;
23 import java.util.ArrayList;
24 import java.util.List;
27 * Represents a component in the address widget UI. It could be either a text box (when there is no
28 * candidate) or a spinner.
30 class AddressUIComponent {
31 // The label for the UI component
32 private String mFieldName;
34 // The type of the UI component
35 private UIComponent mUiType;
37 // The list of elements in the UI component
38 private List<RegionData> mCandidatesList = new ArrayList<RegionData>();
40 // The id of this UI component
41 private AddressField mId;
43 // The id of the parent UI component. When the parent UI component is updated, this UI
44 // component should be updated.
45 private AddressField mParentId;
47 // The View representing the UI component
51 * Type of UI component. There are only EDIT (text-box) and SPINNER (drop-down) components.
57 AddressUIComponent(AddressField id) {
59 // By default, an AddressUIComponent doesn't depend on anything else.
61 mUiType = UIComponent.EDIT;
65 * Initializes the candidatesList, and set the uiType and parentId.
66 * @param candidatesList
68 void initializeCandidatesList(List<RegionData> candidatesList) {
69 mCandidatesList = candidatesList;
70 if (candidatesList.size() > 1) {
71 mUiType = UIComponent.SPINNER;
73 case DEPENDENT_LOCALITY:
74 mParentId = AddressField.LOCALITY;
77 mParentId = AddressField.ADMIN_AREA;
80 mParentId = AddressField.COUNTRY;
89 * Gets the value entered in the UI component.
93 return (mCandidatesList.size() == 0) ? "" : mCandidatesList.get(0).getDisplayName();
97 Object selectedItem = ((Spinner) mView).getSelectedItem();
98 if (selectedItem == null) {
101 return selectedItem.toString();
103 return ((EditText) mView).getText().toString();
109 String getFieldName() {
113 void setFieldName(String fieldName) {
114 mFieldName = fieldName;
117 UIComponent getUIType() {
121 void setUIType(UIComponent uiType) {
125 List<RegionData> getCandidatesList() {
126 return mCandidatesList;
129 void setCandidatesList(List<RegionData> candidatesList) {
130 mCandidatesList = candidatesList;
133 AddressField getId() {
137 void setId(AddressField id) {
141 AddressField getParentId() {
145 void setParentId(AddressField parentId) {
146 mParentId = parentId;
149 void setView(View view) {