• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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 
17 package com.android.tv.settings.connectivity;
18 
19 import com.android.tv.settings.R;
20 import com.android.tv.settings.connectivity.setup.SelectFromListWizardFragment;
21 import com.android.tv.settings.connectivity.setup.TextInputWizardFragment;
22 import com.android.tv.settings.form.FormPage;
23 
24 import android.content.Context;
25 import android.content.Intent;
26 
27 import java.util.ArrayList;
28 
29 /**
30  * Wifi form pages.
31  */
32 public enum WifiFormPageType implements FormPageDisplayer.FormPageInfo {
33     CHOOSE_NETWORK(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE, R.string.title_select_wifi_network,
34             0, new int[] { R.string.other_network },
35             new int[] { R.drawable.ic_menu_add }),
36     ENTER_SSID(FormPageDisplayer.DISPLAY_TYPE_TEXT_INPUT, R.string.title_ssid, 0,
37             TextInputWizardFragment.INPUT_TYPE_NO_SUGGESTIONS),
38     CHOOSE_SECURITY(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE, R.string.security_type, 0,
39             new int[] { R.string.wifi_security_type_none, R.string.wifi_security_type_wep,
40             R.string.wifi_security_type_wpa, R.string.wifi_security_type_eap }),
41     ENTER_PASSWORD(FormPageDisplayer.DISPLAY_TYPE_PASSWORD_INPUT,
42             R.string.wifi_setup_input_password, 0, 0),
43     CONNECT(FormPageDisplayer.DISPLAY_TYPE_LOADING, R.string.wifi_connecting, 0),
44     CONNECT_FAILED(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE,
45             R.string.title_wifi_could_not_connect, 0, new int[] { R.string.wifi_action_try_again,
46             R.string.wifi_action_view_available_networks }),
47     CONNECT_TIMEOUT(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE,
48             R.string.title_wifi_could_not_connect_timeout, 0, new int[] {
49             R.string.wifi_action_try_again, R.string.wifi_action_view_available_networks }),
50     CONNECT_AUTHENTICATION_FAILURE(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE,
51             R.string.title_wifi_could_not_connect_authentication_failure, 0, new int[] {
52             R.string.wifi_action_try_again, R.string.wifi_action_view_available_networks }),
53     CONNECT_REJECTED_BY_AP(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE,
54             R.string.title_wifi_could_not_connect_ap_reject, 0, new int[] {
55             R.string.wifi_action_try_again, R.string.wifi_action_view_available_networks }),
56     SAVE(FormPageDisplayer.DISPLAY_TYPE_LOADING, R.string.wifi_saving, 0),
57     SAVE_FAILED(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE,
58             R.string.title_wifi_could_not_save, 0, new int[] { R.string.wifi_action_ok }),
59     SAVE_SUCCESS(FormPageDisplayer.DISPLAY_TYPE_LOADING, R.string.wifi_setup_save_success, 0),
60     SUCCESS(FormPageDisplayer.DISPLAY_TYPE_LOADING, R.string.wifi_setup_connection_success, 0),
61     SUMMARY_CONNECTED_WIFI(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE,
62             R.string.wifi_summary_title_connected,
63             R.string.wifi_summary_description_connected_to_wifi_network, new int[] {
64             R.string.wifi_action_dont_change_network, R.string.wifi_action_change_network }),
65     SUMMARY_CONNECTED_NON_WIFI(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE,
66             R.string.wifi_summary_title_connected, 0, new int[] { R.string.wifi_action_ok }),
67     SUMMARY_NOT_CONNECTED(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE,
68             R.string.wifi_summary_title_not_connected, 0, new int[] { R.string.wifi_action_ok }),
69     ADVANCED_OPTIONS(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE,
70             R.string.title_wifi_advanced_options, 0, new int[] { R.string.wifi_action_advanced_no,
71             R.string.wifi_action_advanced_yes }),
72     PROXY_SETTINGS(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE, R.string.title_wifi_proxy_settings,
73             R.string.proxy_warning_limited_support, new int[] { R.string.wifi_action_proxy_none,
74             R.string.wifi_action_proxy_manual }),
75     PROXY_HOSTNAME(FormPageDisplayer.DISPLAY_TYPE_TEXT_INPUT, R.string.title_wifi_proxy_hostname,
76             R.string.proxy_hostname_hint, TextInputWizardFragment.INPUT_TYPE_NO_SUGGESTIONS),
77     PROXY_PORT(FormPageDisplayer.DISPLAY_TYPE_TEXT_INPUT, R.string.title_wifi_proxy_port,
78             R.string.proxy_port_hint, TextInputWizardFragment.INPUT_TYPE_NUMERIC),
79     PROXY_BYPASS(FormPageDisplayer.DISPLAY_TYPE_TEXT_INPUT, R.string.title_wifi_proxy_bypass,
80             R.string.proxy_exclusionlist_hint, TextInputWizardFragment.INPUT_TYPE_NO_SUGGESTIONS),
81     IP_SETTINGS(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE, R.string.title_wifi_ip_settings, 0,
82             new int[] { R.string.wifi_action_dhcp, R.string.wifi_action_static }),
83     IP_ADDRESS(FormPageDisplayer.DISPLAY_TYPE_TEXT_INPUT, R.string.title_wifi_ip_address,
84             R.string.wifi_ip_address_hint, TextInputWizardFragment.INPUT_TYPE_NO_SUGGESTIONS),
85     GATEWAY(FormPageDisplayer.DISPLAY_TYPE_TEXT_INPUT, R.string.title_wifi_gateway,
86             R.string.wifi_gateway_hint, TextInputWizardFragment.INPUT_TYPE_NO_SUGGESTIONS),
87     NETWORK_PREFIX_LENGTH(FormPageDisplayer.DISPLAY_TYPE_TEXT_INPUT,
88             R.string.title_wifi_network_prefix_length, R.string.wifi_network_prefix_length_hint,
89             TextInputWizardFragment.INPUT_TYPE_NO_SUGGESTIONS),
90     DNS1(FormPageDisplayer.DISPLAY_TYPE_TEXT_INPUT, R.string.title_wifi_dns1,
91             R.string.wifi_dns1_hint, TextInputWizardFragment.INPUT_TYPE_NO_SUGGESTIONS),
92     DNS2(FormPageDisplayer.DISPLAY_TYPE_TEXT_INPUT, R.string.title_wifi_dns2,
93             R.string.wifi_dns2_hint, TextInputWizardFragment.INPUT_TYPE_NO_SUGGESTIONS),
94     PROXY_SETTINGS_INVALID(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE,
95             R.string.title_wifi_proxy_settings_invalid, 0, new int[] {
96             R.string.wifi_action_try_again }),
97     IP_SETTINGS_INVALID(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE,
98             R.string.title_wifi_ip_settings_invalid, 0, new int[] {
99             R.string.wifi_action_try_again }),
100     KNOWN_NETWORK(FormPageDisplayer.DISPLAY_TYPE_LIST_CHOICE, R.string.title_wifi_known_network, 0,
101             new int[] { R.string.wifi_connect, R.string.wifi_forget_network }),
102     WPS(FormPageDisplayer.DISPLAY_TYPE_LOADING, 0, 0);
103 
104     private final int mDisplayType;
105     private final int mTitleResource;
106     private final int mDescriptionResource;
107     private final int mInputType;
108     private final int[] mDefaultListItemTitles;
109     private final int[] mDefaultListItemIcons;
110 
WifiFormPageType(int displayType, int titleResource, int descriptionResource)111     private WifiFormPageType(int displayType, int titleResource, int descriptionResource) {
112         this(displayType, titleResource, descriptionResource,
113                 TextInputWizardFragment.INPUT_TYPE_NORMAL);
114     }
115 
WifiFormPageType(int displayType, int titleResource, int descriptionResource, int textType)116     private WifiFormPageType(int displayType, int titleResource, int descriptionResource,
117             int textType) {
118         mDisplayType = displayType;
119         mTitleResource = titleResource;
120         mDescriptionResource = descriptionResource;
121         mInputType = textType;
122         mDefaultListItemTitles = null;
123         mDefaultListItemIcons = null;
124     }
125 
WifiFormPageType(int displayType, int titleResource, int descriptionResource, int[] defaultListItemTitles)126     private WifiFormPageType(int displayType, int titleResource, int descriptionResource,
127             int[] defaultListItemTitles) {
128         this(displayType, titleResource, descriptionResource, defaultListItemTitles, null);
129     }
130 
WifiFormPageType(int displayType, int titleResource, int descriptionResource, int[] defaultListItemTitles, int[] defaultListItemIcons)131     private WifiFormPageType(int displayType, int titleResource, int descriptionResource,
132             int[] defaultListItemTitles, int[] defaultListItemIcons) {
133         mDisplayType = displayType;
134         mTitleResource = titleResource;
135         mDescriptionResource = descriptionResource;
136         mInputType = TextInputWizardFragment.INPUT_TYPE_NORMAL;
137         mDefaultListItemTitles = defaultListItemTitles;
138         mDefaultListItemIcons = defaultListItemIcons;
139         if (mDefaultListItemTitles != null && mDefaultListItemIcons != null
140                 && mDefaultListItemTitles.length != mDefaultListItemIcons.length) {
141             throw new IllegalArgumentException("Form page type " + name()
142                     + " had title and icon arrays that we'ren't the same length! "
143                     + "The title array had length " + mDefaultListItemTitles.length
144                     + " but the icon array had length " + mDefaultListItemIcons.length + "!");
145         }
146     }
147 
148     @Override
getTitleResourceId()149     public int getTitleResourceId() {
150         return mTitleResource;
151     }
152 
153     @Override
getDescriptionResourceId()154     public int getDescriptionResourceId() {
155         return mDescriptionResource;
156     }
157 
158     @Override
getInputType()159     public int getInputType() {
160         return mInputType;
161     }
162 
163     @Override
getDisplayType()164     public int getDisplayType() {
165         return mDisplayType;
166     }
167 
168     @Override
getChoices( Context context, ArrayList<SelectFromListWizardFragment.ListItem> extraChoices)169     public ArrayList<SelectFromListWizardFragment.ListItem> getChoices(
170             Context context, ArrayList<SelectFromListWizardFragment.ListItem> extraChoices) {
171         ArrayList<SelectFromListWizardFragment.ListItem> choices = new ArrayList<
172                 SelectFromListWizardFragment.ListItem>();
173         if (extraChoices != null) {
174             choices.addAll(extraChoices);
175         }
176         if (mDefaultListItemTitles != null) {
177             for (int i = 0; i < mDefaultListItemTitles.length; i++) {
178                 choices.add(new SelectFromListWizardFragment.ListItem(
179                         context.getString(mDefaultListItemTitles[i]).toUpperCase(),
180                         mDefaultListItemIcons == null ? 0 : mDefaultListItemIcons[i]));
181             }
182         }
183         return choices;
184     }
185 
create()186     public FormPage create() {
187         return FormPage.createTextInputForm(name());
188     }
189 
create(Intent intent)190     public FormPage create(Intent intent) {
191         if (mDisplayType != FormPageDisplayer.DISPLAY_TYPE_LOADING) {
192             throw new IllegalArgumentException("Form page type " + name() + " had display type "
193                     + mDisplayType + " but " + FormPageDisplayer.DISPLAY_TYPE_LOADING
194                     + " expected!");
195         }
196         return FormPage.createIntentForm(name(), intent);
197     }
198 }
199