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 * Keyboard 29 */ 30 KEYBOARD_OVERVIEW(R.string.system_keyboard), 31 KEYBOARD_OVERVIEW_CURRENT_KEYBOARD(R.string.title_current_keyboard), 32 KEYBOARD_OVERVIEW_CONFIGURE(R.string.title_configure, R.string.desc_configure_keyboard), 33 34 /* 35 * Security 36 */ 37 SECURITY_OVERVIEW(R.string.system_security), 38 SECURITY_UNKNOWN_SOURCES(R.string.security_unknown_sources_title, 39 R.string.security_unknown_sources_desc), 40 SECURITY_UNKNOWN_SOURCES_CONFIRM(R.string.security_unknown_sources_title, 41 R.string.security_unknown_sources_confirm_desc), 42 SECURITY_VERIFY_APPS(R.string.security_verify_apps_title, 43 R.string.security_verify_apps_desc), 44 45 CAPTIONS_OVERVIEW(R.string.accessibility_captions, 46 R.string.accessibility_captions_description), 47 CAPTIONS_DISPLAY(R.string.captions_display), 48 CAPTIONS_CONFIGURE(R.string.captions_configure), 49 CAPTIONS_LANGUAGE(R.string.captions_lanaguage), 50 CAPTIONS_TEXTSIZE(R.string.captions_textsize), 51 CAPTIONS_CAPTIONSTYLE(R.string.captions_captionstyle), 52 CAPTIONS_CUSTOMOPTIONS(R.string.captions_customoptions), 53 CAPTIONS_FONTFAMILY(R.string.captions_fontfamily), 54 CAPTIONS_TEXTCOLOR(R.string.captions_textcolor), 55 CAPTIONS_TEXTOPACITY(R.string.captions_textopacity), 56 CAPTIONS_EDGETYPE(R.string.captions_edgetype), 57 CAPTIONS_EDGECOLOR(R.string.captions_edgecolor), 58 CAPTIONS_BACKGROUNDCOLOR(R.string.captions_backgroundcolor), 59 CAPTIONS_BACKGROUNDOPACITY(R.string.captions_backgroundopacity), 60 CAPTIONS_WINDOWCOLOR(R.string.captions_windowcolor), 61 CAPTIONS_WINDOWOPACITY(R.string.captions_windowopacity); 62 63 private final int mTitleResource; 64 private final int mDescResource; 65 ActionType(int titleResource)66 private ActionType(int titleResource) { 67 mTitleResource = titleResource; 68 mDescResource = 0; 69 } 70 ActionType(int titleResource, int descResource)71 private ActionType(int titleResource, int descResource) { 72 mTitleResource = titleResource; 73 mDescResource = descResource; 74 } getTitle(Resources resources)75 String getTitle(Resources resources) { 76 return resources.getString(mTitleResource); 77 } 78 getDescription(Resources resources)79 String getDescription(Resources resources) { 80 if (mDescResource != 0) { 81 return resources.getString(mDescResource); 82 } 83 return null; 84 } 85 toAction(Resources resources)86 Action toAction(Resources resources) { 87 return toAction(resources, true/*enabled*/); 88 } 89 toAction(Resources resources, boolean enabled)90 Action toAction(Resources resources, boolean enabled) { 91 return toAction(resources, getDescription(resources), enabled, false/* not checked */); 92 } 93 toAction(Resources resources, String description)94 Action toAction(Resources resources, String description) { 95 return toAction(resources, description, true/*enabled*/, false /* not checked */); 96 } 97 toAction(Resources resources, String description, boolean enabled)98 Action toAction(Resources resources, String description, boolean enabled) { 99 return toAction(resources, description, enabled, false /* not checked */); 100 } 101 toAction(Resources resources, String description, boolean enabled, boolean checked)102 Action toAction(Resources resources, String description, boolean enabled, boolean checked) { 103 return new Action.Builder() 104 .key(getKey(this, ActionBehavior.INIT)) 105 .title(getTitle(resources)) 106 .description(description) 107 .enabled(enabled) 108 .checked(checked) 109 .build(); 110 } 111 getKey(ActionType t, ActionBehavior b)112 private String getKey(ActionType t, ActionBehavior b) { 113 return new ActionKey<>(t, b).getKey(); 114 } 115 } 116