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.system;
18 
19 import com.android.tv.settings.ActionBehavior;
20 import com.android.tv.settings.ActionKey;
21 import com.android.tv.settings.R;
22 import com.android.tv.settings.dialog.old.Action;
23 
24 import android.content.res.Resources;
25 
26 enum ActionType {
27     /*
28      * General
29      */
30     AGREE(R.string.agree),
31     DISAGREE(R.string.disagree),
32     EMAIL_ADDRESS(R.string.system_email_address),
33     OK(R.string.title_ok),
34     CANCEL(R.string.title_cancel),
35     ON(R.string.on),
36     OFF(R.string.off),
37     /*
38      * Date & Time
39      */
40     DATE_TIME_OVERVIEW(R.string.system_date_time),
41     DATE(R.string.system_date),
42     TIME(R.string.system_time),
43     DATE_SET_DATE(R.string.system_set_date),
44     TIME_SET_TIME(R.string.system_set_time),
45     TIME_SET_TIME_ZONE(R.string.system_set_time_zone),
46     TIME_CHOOSE_FORMAT(R.string.system_set_time_format),
47     AUTO_DATE_TIME(R.string.system_auto_date_time, R.string.desc_auto_date_time),
48     /*
49      * Location
50      */
51     LOCATION_OVERVIEW(R.string.system_location),
52     NETWORK_LOCATION_CONFIRM(R.string.system_network_location_confirm),
53     LOCATION_STATUS(R.string.location_status),
54     LOCATION_MODE(R.string.location_mode_title),
55     LOCATION_MODE_WIFI(R.string.location_mode_wifi_description),
56     LOCATION_RECENT_REQUESTS(R.string.location_category_recent_location_requests),
57     LOCATION_NO_RECENT_REQUESTS(R.string.location_no_recent_apps),
58     LOCATION_SERVICES(R.string.location_services),
59     LOCATION_SERVICES_GOOGLE(R.string.google_location_services_title),
60     LOCATION_SERVICES_GOOGLE_SETTINGS(R.string.google_location_services_title),
61     LOCATION_SERVICES_GOOGLE_REPORTING(R.string.location_reporting,
62             R.string.location_reporting_desc),
63     LOCATION_SERVICES_GOOGLE_HISTORY(R.string.location_history, R.string.location_history_desc),
64     LOCATION_SERVICES_THIRD_PARTY(R.string.third_party_location_services_title),
65     LOCATION_HISTORY_DELETE(R.string.delete_location_history_title,
66             R.string.delete_location_history_desc),
67     /*
68      * Developer Options
69      */
70     DEVELOPER_OVERVIEW(R.string.system_developer_options),
71     DEVELOPER_GENERAL(R.string.system_general),
72     DEVELOPER_DEBUGGING(R.string.system_debugging),
73     DEVELOPER_INPUT(R.string.system_input),
74     DEVELOPER_DRAWING(R.string.system_drawing),
75     DEVELOPER_MONITORING(R.string.system_monitoring),
76     DEVELOPER_APPS(R.string.system_apps),
77     DEVELOPER_GENERAL_STAY_AWAKE(R.string.system_stay_awake,
78             R.string.system_desc_stay_awake),
79     DEVELOPER_GENERAL_HDCP_CHECKING(R.string.system_hdcp_checking,
80             R.string.system_desc_hdcp_checking),
81     DEVELOPER_GENERAL_HDMI_OPTIMIZATION(R.string.system_hdmi_optimization,
82             R.string.system_desc_hdmi_optimization),
83     DEVELOPER_GENERAL_BT_HCI_LOG(R.string.system_bt_hci_log,
84             R.string.system_desc_bt_hci_log),
85     DEVELOPER_GENERAL_REBOOT(R.string.system_reboot_confirm,
86             R.string.system_desc_reboot_confirm),
87     DEVELOPER_HDCP_NEVER_CHECK(R.string.system_never_check),
88     DEVELOPER_HDCP_CHECK_FOR_DRM_CONTENT_ONLY(R.string.system_check_for_drm_content_only),
89     DEVELOPER_HDCP_ALWAYS_CHECK(R.string.system_always_check),
90     DEVELOPER_DEBUGGING_USB_DEBUGGING(R.string.system_usb_debugging,
91             R.string.system_desc_usb_debugging),
92     DEVELOPER_DEBUGGING_ALLOW_MOCK_LOCATIONS(R.string.system_allow_mock_locations),
93     DEVELOPER_DEBUGGING_SELECT_DEBUG_APP(R.string.system_select_debug_app),
94     DEVELOPER_DEBUGGING_WAIT_FOR_DEBUGGER(R.string.system_wait_for_debugger,
95             R.string.system_desc_wait_for_debugger),
96     DEVELOPER_DEBUGGING_VERIFY_APPS_OVER_USB(R.string.system_verify_apps_over_usb,
97             R.string.system_desc_verify_apps_over_usb),
98     DEVELOPER_DEBUGGING_WIFI_VERBOSE_LOGGING(R.string.system_wifi_verbose_logging,
99             R.string.system_desc_wifi_verbose_logging),
100     DEVELOPER_INPUT_SHOW_TOUCHES(R.string.system_show_touches),
101     DEVELOPER_INPUT_POINTER_LOCATION(R.string.system_pointer_location),
102     DEVELOPER_DRAWING_SHOW_LAYOUT_BOUNDS(R.string.system_show_layout_bounds,
103             R.string.system_desc_show_layout_bounds),
104     DEVELOPER_DRAWING_SHOW_GPU_VIEW_UPDATES(R.string.system_show_gpu_view_updates,
105             R.string.system_desc_show_gpu_view_updates),
106     DEVELOPER_DRAWING_SHOW_GPU_OVERDRAW(R.string.system_show_gpu_overdraw,
107                     R.string.system_desc_show_gpu_overdraw),
108     DEVELOPER_DRAWING_SHOW_HARDWARE_LAYER(R.string.system_show_hardware_layer,
109             R.string.system_desc_show_hardware_layer),
110     DEVELOPER_DRAWING_SHOW_SURFACE_UPDATES(R.string.system_show_surface_updates,
111             R.string.system_desc_show_surface_updates),
112     DEVELOPER_DRAWING_WINDOW_ANIMATION_SCALE(R.string.system_window_animation_scale),
113     DEVELOPER_DRAWING_TRANSITION_ANIMATION_SCALE(R.string.system_transition_animation_scale),
114     DEVELOPER_DRAWING_ANIMATOR_DURATION_SCALE(R.string.system_animator_duration_scale),
115     DEVELOPER_MONITORING_STRICT_MODE_ENABLED(R.string.system_strict_mode_enabled,
116             R.string.system_desc_strict_mode_enabled),
117     DEVELOPER_MONITORING_SHOW_CPU_USAGE(R.string.system_show_cpu_usage,
118             R.string.system_desc_show_cpu_usage),
119     DEVELOPER_MONITORING_PROFILE_GPU_RENDERING(R.string.system_profile_gpu_rendering,
120             R.string.system_desc_profile_gpu_rendering),
121     DEVELOPER_MONITORING_ENABLE_TRACES(R.string.system_enable_traces),
122     DEVELOPER_APPS_DONT_KEEP_ACTIVITIES(R.string.system_dont_keep_activities),
123     DEVELOPER_APPS_BACKGROUND_PROCESS_LIMIT(R.string.system_background_process_limit),
124     DEVELOPER_APPS_SHOW_ALL_ANRS(R.string.system_show_all_anrs),
125     /*
126      * Keyboard
127      */
128     KEYBOARD_OVERVIEW(R.string.system_keyboard),
129     KEYBOARD_OVERVIEW_CURRENT_KEYBOARD(R.string.title_current_keyboard),
130     KEYBOARD_OVERVIEW_CONFIGURE(R.string.title_configure, R.string.desc_configure_keyboard),
131 
132     /*
133      * Security
134      */
135     SECURITY_OVERVIEW(R.string.system_security),
136     SECURITY_UNKNOWN_SOURCES(R.string.security_unknown_sources_title,
137             R.string.security_unknown_sources_desc),
138     SECURITY_UNKNOWN_SOURCES_CONFIRM(R.string.security_unknown_sources_title,
139                     R.string.security_unknown_sources_confirm_desc),
140     SECURITY_VERIFY_APPS(R.string.security_verify_apps_title,
141              R.string.security_verify_apps_desc),
142 
143     /*
144      * StorageReset
145      */
146     STORAGERESET_OVERVIEW(R.string.device_storage_reset),
147     STORAGERESET_FACTORY_RESET(R.string.device_reset),
148     STORAGERESET_STORAGE(R.string.device_storage),
149 
150     /*
151      * Accessibility
152      */
153     ACCESSIBILITY_OVERVIEW(R.string.system_accessibility),
154     ACCESSIBILITY_SERVICES(R.string.system_services),
155     ACCESSIBILITY_SERVICES_SETTINGS(R.string.accessibility_service_settings),
156     ACCESSIBILITY_SERVICES_STATUS(R.string.system_accessibility_status),
157     ACCESSIBILITY_SERVICES_CONFIRM_ON(R.string.system_accessibility_status),
158     ACCESSIBILITY_SERVICES_CONFIRM_OFF(R.string.system_accessibility_status),
159     ACCESSIBILITY_SERVICE_CONFIG(R.string.system_accessibility_config),
160     ACCESSIBILITY_CAPTIONS(R.string.accessibility_captions),
161     ACCESSIBILITY_SPEAK_PASSWORDS(R.string.system_speak_passwords),
162     ACCESSIBILITY_TTS_OUTPUT(R.string.system_accessibility_tts_output),
163     ACCESSIBILITY_PREFERRED_ENGINE(R.string.system_preferred_engine),
164     ACCESSIBILITY_LANGUAGE(R.string.system_language),
165     ACCESSIBILITY_SPEECH_RATE(R.string.system_speech_rate),
166     ACCESSIBILITY_PLAY_SAMPLE(R.string.system_play_sample),
167     ACCESSIBILITY_INSTALL_VOICE_DATA(R.string.system_install_voice_data),
168 
169     CAPTIONS_OVERVIEW(R.string.accessibility_captions,
170                       R.string.accessibility_captions_description),
171     CAPTIONS_DISPLAY(R.string.captions_display),
172     CAPTIONS_CONFIGURE(R.string.captions_configure),
173     CAPTIONS_LANGUAGE(R.string.captions_lanaguage),
174     CAPTIONS_TEXTSIZE(R.string.captions_textsize),
175     CAPTIONS_CAPTIONSTYLE(R.string.captions_captionstyle),
176     CAPTIONS_CUSTOMOPTIONS(R.string.captions_customoptions),
177     CAPTIONS_FONTFAMILY(R.string.captions_fontfamily),
178     CAPTIONS_TEXTCOLOR(R.string.captions_textcolor),
179     CAPTIONS_TEXTOPACITY(R.string.captions_textopacity),
180     CAPTIONS_EDGETYPE(R.string.captions_edgetype),
181     CAPTIONS_EDGECOLOR(R.string.captions_edgecolor),
182     CAPTIONS_BACKGROUNDCOLOR(R.string.captions_backgroundcolor),
183     CAPTIONS_BACKGROUNDOPACITY(R.string.captions_backgroundopacity),
184     CAPTIONS_WINDOWCOLOR(R.string.captions_windowcolor),
185     CAPTIONS_WINDOWOPACITY(R.string.captions_windowopacity);
186 
187     private final int mTitleResource;
188     private final int mDescResource;
189 
ActionType(int titleResource)190     private ActionType(int titleResource) {
191         mTitleResource = titleResource;
192         mDescResource = 0;
193     }
194 
ActionType(int titleResource, int descResource)195     private ActionType(int titleResource, int descResource) {
196         mTitleResource = titleResource;
197         mDescResource = descResource;
198     }
getTitle(Resources resources)199     String getTitle(Resources resources) {
200         return resources.getString(mTitleResource);
201     }
202 
getDescription(Resources resources)203     String getDescription(Resources resources) {
204         if (mDescResource != 0) {
205             return resources.getString(mDescResource);
206         }
207         return null;
208     }
209 
toAction(Resources resources)210     Action toAction(Resources resources) {
211         return toAction(resources, true/*enabled*/);
212     }
213 
toAction(Resources resources, boolean enabled)214     Action toAction(Resources resources, boolean enabled) {
215         return toAction(resources, getDescription(resources), enabled, false/* not checked */);
216     }
217 
toAction(Resources resources, String description)218     Action toAction(Resources resources, String description) {
219         return toAction(resources, description, true/*enabled*/, false /* not checked */);
220     }
221 
toAction(Resources resources, String description, boolean enabled)222     Action toAction(Resources resources, String description, boolean enabled) {
223         return toAction(resources, description, enabled, false /* not checked */);
224     }
225 
toAction(Resources resources, String description, boolean enabled, boolean checked)226     Action toAction(Resources resources, String description, boolean enabled, boolean checked) {
227         return new Action.Builder()
228                 .key(getKey(this, ActionBehavior.INIT))
229                 .title(getTitle(resources))
230                 .description(description)
231                 .enabled(enabled)
232                 .checked(checked)
233                 .build();
234     }
235 
getKey(ActionType t, ActionBehavior b)236     private String getKey(ActionType t, ActionBehavior b) {
237         return new ActionKey<ActionType, ActionBehavior>(t, b).getKey();
238     }
239 }
240