summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/profiles/actions/item/ConnectionOverrideItem.java
blob: 3214174639f5ee8d7dc14ffc620f5ef3af1e2086 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * Copyright (C) 2014 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.settings.profiles.actions.item;

import cyanogenmod.profiles.ConnectionSettings;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.settings.R;
import com.android.settings.profiles.actions.ItemListAdapter;

public class ConnectionOverrideItem implements Item {
    int mConnectionId;
    ConnectionSettings mConnectionSettings;

    public static final int CM_MODE_2G = 0;
    public static final int CM_MODE_3G = 1;
    public static final int CM_MODE_4G = 2;
    public static final int CM_MODE_2G3G = 3;
    public static final int CM_MODE_ALL = 4;
    public static final int CM_MODE_UNCHANGED = 5;

    public ConnectionOverrideItem(int connectionId, ConnectionSettings settings) {
        mConnectionId = connectionId;
        if (settings == null) {
            settings = new ConnectionSettings(connectionId);
        }
        this.mConnectionSettings = settings;
    }

    @Override
    public ItemListAdapter.RowType getRowType() {
        return ItemListAdapter.RowType.CONNECTION_ITEM;
    }

    @Override
    public View getView(LayoutInflater inflater, View convertView, ViewGroup parent) {
        View view;
        if (convertView == null) {
            view = inflater.inflate(R.layout.list_two_line_item, parent, false);
            // Do some initialization
        } else {
            view = convertView;
        }

        TextView title = (TextView) view.findViewById(R.id.title);
        TextView summary = (TextView) view.findViewById(R.id.summary);

        title.setText(getConnectionTitle(mConnectionId));
        summary.setText(getSummary());

        return view;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public static int getConnectionTitle(int connectionId) {
        switch (connectionId) {
            case ConnectionSettings.PROFILE_CONNECTION_BLUETOOTH:
                return R.string.toggleBluetooth;
            case ConnectionSettings.PROFILE_CONNECTION_MOBILEDATA:
                return R.string.toggleData;
            case ConnectionSettings.PROFILE_CONNECTION_2G3G4G:
                return R.string.toggle2g3g4g;
            case ConnectionSettings.PROFILE_CONNECTION_GPS:
                return R.string.toggleGPS;
            case ConnectionSettings.PROFILE_CONNECTION_NFC:
                return R.string.toggleNfc;
            case ConnectionSettings.PROFILE_CONNECTION_SYNC:
                return R.string.toggleSync;
            case ConnectionSettings.PROFILE_CONNECTION_WIFI:
                return R.string.toggleWifi;
            case ConnectionSettings.PROFILE_CONNECTION_WIFIAP:
                return R.string.toggleWifiAp;
            default:
                return 0;
        }
    }

    public int getSummary() {
        if (mConnectionSettings != null) {
            if (mConnectionId == ConnectionSettings.PROFILE_CONNECTION_2G3G4G) { // different options
                if (mConnectionSettings.isOverride()) {
                    switch (mConnectionSettings.getValue()) {
                        case CM_MODE_2G:
                            return R.string.profile_networkmode_2g;
                        case CM_MODE_3G:
                            return R.string.profile_networkmode_3g;
                        case CM_MODE_4G:
                            return R.string.profile_networkmode_4g;
                        case CM_MODE_2G3G:
                            return R.string.profile_networkmode_2g3g;
                        default:
                        case CM_MODE_ALL:
                            return R.string.profile_networkmode_2g3g4g;
                    }
                } else {
                    return R.string.profile_action_none;
                }
            } else if (mConnectionSettings.isOverride()) { // enabled, disabled, or none
                if (mConnectionSettings.getValue() == 1) {
                    return R.string.profile_action_enable;
                } else {
                    return R.string.profile_action_disable;
                }
            } else {
                return R.string.profile_action_none;
            }
        } else {
            return R.string.profile_action_none;
        }
    }

    public ConnectionSettings getSettings() {
        return mConnectionSettings;
    }

    public int getConnectionType() {
        return mConnectionId;
    }
}