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.connectivity;
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    /*
29     * Wifi settings.
30     */
31    CONECTIVITY_SETTINGS_MAIN(0),
32    CONECTIVITY_SETTINGS_STATUS_INFO(R.string.wifi_action_status_info),
33    CONECTIVITY_SETTINGS_ADVANCED_OPTIONS(R.string.wifi_action_advanced_options_title),
34    CONECTIVITY_SETTINGS_FORGET_NETWORK(R.string.wifi_forget_network),
35
36    /*
37     * Status info.
38     */
39    CONECTIVITY_SETTINGS_CONNECTION(R.string.title_internet_connection),
40    CONECTIVITY_SETTINGS_IP_ADDRESS(R.string.title_ip_address),
41    CONECTIVITY_SETTINGS_MAC_ADDRESS(R.string.title_mac_address),
42    CONECTIVITY_SETTINGS_SIGNAL_STRENGTH(R.string.title_signal_strength),
43
44    /*
45     * Advanced settings.
46     */
47    CONECTIVITY_SETTINGS_PROXY_SETTINGS(R.string.title_wifi_proxy_settings),
48    CONECTIVITY_SETTINGS_IP_SETTINGS(R.string.title_wifi_ip_settings);
49
50    private final int mTitleResource;
51    private final int mDescResource;
52
53    private ActionType(int titleResource) {
54        mTitleResource = titleResource;
55        mDescResource = 0;
56    }
57
58    private ActionType(int titleResource, int descResource) {
59        mTitleResource = titleResource;
60        mDescResource = descResource;
61    }
62
63    String getTitle(Resources resources) {
64        return resources.getString(mTitleResource);
65    }
66
67    String getDesc(Resources resources) {
68        if (mDescResource != 0) {
69            return resources.getString(mDescResource);
70        }
71        return null;
72    }
73
74    Action toAction(Resources resources) {
75        return toAction(resources, getDesc(resources));
76    }
77
78    Action toAction(Resources resources, String description) {
79        return new Action.Builder()
80                .key(getKey(this, ActionBehavior.INIT))
81                .title(getTitle(resources))
82                .description(description)
83                .build();
84    }
85
86    Action toInfo(Resources resources, String description) {
87        return new Action.Builder()
88                .key(getKey(this, ActionBehavior.INIT))
89                .title(getTitle(resources))
90                .description(description)
91                .enabled(false)
92                .build();
93    }
94
95    Action toInfo(Resources resources, int descResource) {
96        return toInfo(resources, resources.getString(descResource));
97    }
98
99    Action toAction(Resources resources, int descResource) {
100        return new Action.Builder()
101                .key(getKey(this, ActionBehavior.INIT))
102                .title(getTitle(resources))
103                .description(resources.getString(descResource))
104                .build();
105    }
106
107    private String getKey(ActionType t, ActionBehavior b) {
108        return new ActionKey<ActionType, ActionBehavior>(t, b).getKey();
109    }
110}
111