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;
18 
19 import com.android.tv.settings.R;
20 import com.android.tv.settings.dialog.old.Action;
21 
22 import android.content.res.Resources;
23 
24 /**
25  * The different possible action behaviors.
26  */
27 public enum ActionBehavior {
28     INIT(),
29     ON(R.string.settings_on),
30     OFF(R.string.settings_off),
31     OK(R.string.settings_ok),
32     CANCEL(R.string.settings_cancel);
33 
34     private final int mTitleResource;
35 
ActionBehavior()36     private ActionBehavior() {
37         this(0);
38     }
39 
ActionBehavior(int titleResource)40     private ActionBehavior(int titleResource) {
41         mTitleResource = titleResource;
42     }
43 
toAction(String key, Resources resources)44     public Action toAction(String key, Resources resources) {
45         return new Action.Builder().key(key).title(resources.getString(mTitleResource)).build();
46     }
47 
toAction(String key, Resources resources, boolean selected)48     public Action toAction(String key, Resources resources, boolean selected) {
49         return new Action.Builder()
50                 .key(key).title(resources.getString(mTitleResource)).checked(selected).build();
51     }
52 
toActionBuilder(String key, Resources resources)53     public Action.Builder toActionBuilder(String key, Resources resources) {
54         return new Action.Builder()
55                 .key(key)
56                 .title(resources.getString(mTitleResource));
57     }
58 
getOnKey(String typeName)59     public static String getOnKey(String typeName) {
60         return typeName + ":" + ActionBehavior.ON.name();
61     }
62 
getOffKey(String typeName)63     public static String getOffKey(String typeName) {
64         return typeName + ":" + ActionBehavior.OFF.name();
65     }
66 }
67