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
17package com.android.tv.settings;
18
19import com.android.tv.settings.R;
20import com.android.tv.settings.dialog.old.Action;
21
22import android.content.res.Resources;
23
24/**
25 * The different possible action behaviors.
26 */
27public 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
36    private ActionBehavior() {
37        this(0);
38    }
39
40    private ActionBehavior(int titleResource) {
41        mTitleResource = titleResource;
42    }
43
44    public Action toAction(String key, Resources resources) {
45        return new Action.Builder().key(key).title(resources.getString(mTitleResource)).build();
46    }
47
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
53    public Action.Builder toActionBuilder(String key, Resources resources) {
54        return new Action.Builder()
55                .key(key)
56                .title(resources.getString(mTitleResource));
57    }
58
59    public static String getOnKey(String typeName) {
60        return typeName + ":" + ActionBehavior.ON.name();
61    }
62
63    public static String getOffKey(String typeName) {
64        return typeName + ":" + ActionBehavior.OFF.name();
65    }
66}
67