Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / libaddressinput / src / java / src / com / android / i18n / addressinput / AddressWidgetUiComponentProvider.java
1 /*
2  * Copyright (C) 2014 Google Inc.
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
17 package com.android.i18n.addressinput;
18
19 import android.app.ProgressDialog;
20 import android.content.Context;
21 import android.view.LayoutInflater;
22 import android.widget.ArrayAdapter;
23 import android.widget.EditText;
24 import android.widget.Spinner;
25 import android.widget.TextView;
26
27 import com.android.i18n.addressinput.AddressField.WidthType;
28
29 /**
30  * Base class for customizing widgets for address input.
31  *
32  * <p>
33  * Clients can optionally override this class and use
34  * {@link AddressWidget#setUiComponentProvider(AddressWidgetUiComponentProvider)} to set the the
35  * componentProvider field of the address widget, which will be invoked by the widget to create UI
36  * components that provide consistent look-and-feel with other UI components clients might use
37  * alongside the address widget.
38  */
39 public class AddressWidgetUiComponentProvider {
40   protected Context context;
41   protected LayoutInflater inflater;
42
43   public AddressWidgetUiComponentProvider(Context context) {
44     this.context = context;
45     this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
46   }
47
48   /**
49    * Creates a label, e.g. "State", for an address input field.
50    *
51    * @param label the label of the address input field
52    * @param widthType {@link WidthType} of the field
53    * @return a custom {@link TextView} created for the field
54    */
55   protected TextView createUiLabel(CharSequence label, WidthType widthType) {
56     TextView textView = (TextView) inflater.inflate(R.layout.address_textview, null, false);
57     textView.setText(label);
58     return textView;
59   }
60
61   /**
62    * Creates a text input view for an address input field.
63    *
64    * @param widthType {@link WidthType} of the field
65    * @return a custom {@link EditText} created for the field
66    */
67   protected EditText createUiTextField(WidthType widthType) {
68     return (EditText) inflater.inflate(R.layout.address_edittext, null, false);
69   }
70
71   /**
72    * Creates a {@link Spinner} for a input field that uses UI picker.
73    *
74    * @param widthType {@link WidthType} of the field
75    * @return a custom {@link Spinner} created for the field
76    */
77   protected Spinner createUiPickerSpinner(WidthType widthType) {
78     return (Spinner) inflater.inflate(R.layout.address_spinner, null, false);
79   }
80
81   /**
82    * Creates an {@link ArrayAdapter} to work with the custom {@link Spinner} of a input field that
83    * uses UI picker.
84    *
85    * @param widthType {@link WidthType} of the field
86    * @return a custom {@link ArrayAdapter} for the field
87    */
88   protected ArrayAdapter<String> createUiPickerAdapter(WidthType widthType) {
89     ArrayAdapter<String> adapter =
90         new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item);
91     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
92     return adapter;
93   }
94
95   /** Gets an activity indicator to show that a task is in progress. */
96   protected ProgressDialog getUiActivityIndicatorView() {
97     return new ProgressDialog(context);
98   }
99 }