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.accessories;
18
19import com.android.tv.settings.ActionBehavior;
20import com.android.tv.settings.ActionKey;
21import com.android.tv.settings.R;
22import com.android.tv.settings.dialog.old.Action;
23
24import android.content.res.Resources;
25
26enum ActionType {
27    /*
28     * General
29     */
30    OK(R.string.title_ok),
31    CANCEL(R.string.title_cancel),
32
33    /*
34     * Bluetooth Device Settings
35     */
36    BLUETOOTH_DEVICE_OVERVIEW(R.string.accessory_options),
37    BLUETOOTH_DEVICE_RENAME(R.string.accessory_rename),
38    BLUETOOTH_DEVICE_UNPAIR(R.string.accessory_unpair);
39
40
41    private final int mTitleResource;
42    private final int mDescResource;
43
44    private ActionType(int titleResource) {
45        mTitleResource = titleResource;
46        mDescResource = 0;
47    }
48
49    private ActionType(int titleResource, int descResource) {
50        mTitleResource = titleResource;
51        mDescResource = descResource;
52    }
53
54    String getTitle(Resources resources) {
55        return resources.getString(mTitleResource);
56    }
57
58    String getDesc(Resources resources) {
59        if (mDescResource != 0) {
60            return resources.getString(mDescResource);
61        }
62        return null;
63    }
64
65    Action toAction(Resources resources) {
66        return toAction(resources, getDesc(resources));
67    }
68
69    Action toAction(Resources resources, String description) {
70        return new Action.Builder()
71                .key(getKey(this, ActionBehavior.INIT))
72                .title(getTitle(resources))
73                .description(description)
74                .build();
75    }
76
77    private String getKey(ActionType t, ActionBehavior b) {
78        return new ActionKey<ActionType, ActionBehavior>(t, b).getKey();
79    }
80}
81