summaryrefslogtreecommitdiffstats
path: root/core/java/android/provider/CmSystem.java
blob: 5644a8bd6822657180818773389ca196449d054f (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/*
 * Created by Sven Dawitz; Copyright (C) 2011 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 android.provider;

import android.content.Context;
import android.view.KeyEvent;

import com.android.internal.R;

/**
 * CmSystem
 * @hide
 */
public final class CmSystem {
    // explaination of each default value in detail at
    // frameworks/base/core/res/res/value/config.xml
    // can be overridden system wide by overlay usage

    // sorted in order of appearance in tablet tweaks options menu
    public static final int CM_IS_TABLET=0;
    public static final int CM_HAS_SOFT_BUTTONS=1;

    public static final int CM_DEFAULT_BOTTOM_STATUS_BAR=2;
    public static final int CM_DEFAULT_USE_DEAD_ZONE=3;
    public static final int CM_DEFAULT_SOFT_BUTTONS_LEFT=4;

    public static final int CM_DEFAULT_SHOW_SOFT_HOME=5;
    public static final int CM_DEFAULT_SHOW_SOFT_MENU=6;
    public static final int CM_DEFAULT_SHOW_SOFT_BACK=7;
    public static final int CM_DEFAULT_SHOW_SOFT_SEARCH=8;
    public static final int CM_DEFAULT_SHOW_SOFT_QUICK_NA=9;

    public static final int CM_DEFAULT_DISABLE_LOCKSCREEN=10;
    public static final int CM_DEFAULT_DISABLE_FULLSCREEN=11;

    public static final int CM_DEFAULT_UNHIDE_BUTTON_INDEX=12;

    public static final int CM_DEFAULT_EXTEND_POWER_MENU=13;

    public static final int CM_DEFAULT_POWER_MENU_HOME=14;
    public static final int CM_DEFAULT_POWER_MENU_MENU=15;
    public static final int CM_DEFAULT_POWER_MENU_BACK=16;

    public static final int CM_DEFAULT_REVERSE_VOLUME_BEHAVIOR=17;
    public static final int CM_DEFAULT_REMAPPED_LONG_VOL_UP_INDEX=18;
    public static final int CM_DEFAULT_REMAPPED_LONG_VOL_DOWN_INDEX=19;
    public static final int CM_DEFAULT_REMAPPED_BOTH_VOL_INDEX=20;
    public static final int CM_DEFAULT_REMAPPED_LONG_BOTH_VOL_INDEX=21;

    // not a keycode, so negative value can never be considered keycode - user -1, -2, -3...
    // used in PhoneWindowManager
    public static final int VOLUME_ACTION_LONG_HOME = -1;
    public static final int VOLUME_ACTION_NONE = 0;
    public static final int KEYCODE_NONE = -1;


    public enum LockscreenStyle {
        Slider,
        Rotary,
        Lense,
        Ring;

        static public LockscreenStyle getStyleById(int id) {
            switch (id) {
                case 1:
                    return Slider;
                case 2:
                    return Rotary;
                case 3:
                    /* backwards compat */
                    return Rotary;
                case 4:
                    return Lense;
                case 5:
                    return Ring;
                default:
                    return Ring;
            }
        }

        static public LockscreenStyle getStyleById(String id) {
            return getStyleById(Integer.valueOf(id));
        }

        static public int getIdByStyle(LockscreenStyle lockscreenstyle) {
            switch (lockscreenstyle){
                case Slider:
                    return 1;
                case Rotary:
                    return 2;
                case Lense:
                    return 4;
                case Ring:
                    return 5;
                default:
                    return 5;
            }
        }
    }

    public enum InCallStyle {
        Slider,
        Rotary,
        Ring;

        static public InCallStyle getStyleById(int id) {
            switch (id) {
                case 1:
                    return Slider;
                case 2:
                    return Rotary;
                case 3:
                    /* backwards compat */
                    return Rotary;
                case 4:
                    return Ring;
                default:
                    return Ring;
            }
        }

        static public InCallStyle getStyleById(String id) {
            return getStyleById(Integer.valueOf(id));
        }

        static public int getIdByStyle(InCallStyle inCallStyle) {
            switch (inCallStyle) {
                case Slider:
                    return 1;
                case Rotary:
                    return 2;
                case Ring:
                    return 4;
                default:
                    return 4;
            }
        }
    }

    public enum RotaryStyle {
        Normal,
        Revamped;

        static public RotaryStyle getStyleById(int id) {
            switch (id) {
                case 1:
                    return Normal;
                case 2:
                    return Revamped;
                default:
                    return Normal;
            }
        }

        static public RotaryStyle getStyleById(String id) {
            return getStyleById(Integer.valueOf(id));
        }

        static public int getIdByStyle(RotaryStyle style) {
            switch (style) {
                case Normal:
                    return 1;
                case Revamped:
                    return 2;
                default:
                    return 1;
            }
        }
    }

    public enum RinglockStyle {
        Bubble,
        Revamped,
        Holo,
        Blade;

        static public RinglockStyle getStyleById(int id) {
            switch (id) {
                case 1:
                    return Bubble;
                case 2:
                    return Revamped;
                case 3:
                    return Holo;
                case 4:
                    return Blade;
                default:
                    return Bubble;
            }
        }

        static public RinglockStyle getStyleById(String id) {
            return getStyleById(Integer.valueOf(id));
        }

        static public int getIdByStyle(RinglockStyle style) {
            switch (style) {
                case Bubble:
                    return 1;
                case Revamped:
                    return 2;
                case Holo:
                    return 3;
                case Blade:
                    return 4;
                default:
                    return 1;
            }
        }
    }

    public CmSystem(){
        //nothing to be done, as long as only static functions in here
    }

    public static boolean getDefaultBool(Context context, int which){
        int res=getResourceId(which);

        if(res!=0)
            return context.getResources().getBoolean(res);

        // default if id not found
        return false;
    }

    public static int getDefaultInt(Context context, int which){
        int res=getResourceId(which);

        if(res!=0)
            return context.getResources().getInteger(res);

        // default if id not found
        return 0;
    }

    private static int getResourceId(int which){
        int resId=0;

        switch(which){
            case CM_IS_TABLET:
                resId=R.bool.cm_default_is_tablet;
                break;
            case CM_HAS_SOFT_BUTTONS:
                resId=R.bool.cm_default_has_soft_buttons;
                break;

            case CM_DEFAULT_BOTTOM_STATUS_BAR:
                resId=R.bool.cm_default_bottom_status_bar;
                break;
            case CM_DEFAULT_USE_DEAD_ZONE:
                resId=R.bool.cm_default_use_dead_zone;
                break;
            case CM_DEFAULT_SOFT_BUTTONS_LEFT:
                resId=R.bool.cm_default_soft_buttons_left;
                break;

            case CM_DEFAULT_SHOW_SOFT_HOME:
                resId=R.bool.cm_default_show_soft_home;
                break;
            case CM_DEFAULT_SHOW_SOFT_MENU:
                resId=R.bool.cm_default_show_soft_menu;
                break;
            case CM_DEFAULT_SHOW_SOFT_BACK:
                resId=R.bool.cm_default_show_soft_back;
                break;
            case CM_DEFAULT_SHOW_SOFT_SEARCH:
                resId=R.bool.cm_default_show_soft_search;
                break;
            case CM_DEFAULT_SHOW_SOFT_QUICK_NA:
                resId=R.bool.cm_default_show_soft_quick_na;
                break;

            case CM_DEFAULT_DISABLE_LOCKSCREEN:
                resId=R.bool.cm_default_disable_lockscreen;
                break;
            case CM_DEFAULT_DISABLE_FULLSCREEN:
                resId=R.bool.cm_default_disable_fullscreen;
                break;

            case CM_DEFAULT_EXTEND_POWER_MENU:
                resId=R.bool.cm_default_extend_power_menu;
                break;

            case CM_DEFAULT_POWER_MENU_HOME:
                resId=R.bool.cm_default_power_menu_home;
                break;
            case CM_DEFAULT_POWER_MENU_MENU:
                resId=R.bool.cm_default_power_menu_menu;
                break;
            case CM_DEFAULT_POWER_MENU_BACK:
                resId=R.bool.cm_default_power_menu_back;
                break;

            case CM_DEFAULT_REVERSE_VOLUME_BEHAVIOR:
                resId=R.bool.cm_default_reverse_volume_behavior;
                break;

            // integer values
            case CM_DEFAULT_UNHIDE_BUTTON_INDEX:
                resId=R.integer.cm_default_unhide_button_index;
                break;
            case CM_DEFAULT_REMAPPED_LONG_VOL_UP_INDEX:
                resId=R.integer.cm_default_remapped_long_vol_up_index;
                break;
            case CM_DEFAULT_REMAPPED_LONG_VOL_DOWN_INDEX:
                resId=R.integer.cm_default_remapped_long_vol_down_index;
                break;
            case CM_DEFAULT_REMAPPED_BOTH_VOL_INDEX:
                resId=R.integer.cm_default_remapped_both_vol_index;
                break;
            case CM_DEFAULT_REMAPPED_LONG_BOTH_VOL_INDEX:
                resId=R.integer.cm_default_remapped_long_both_vol_index;
                break;
        }

        return resId;
    }

    // remaped indexes of CmParts' array.xml file
    public static int translateActionToKeycode(int longActionIndex) {
        switch (longActionIndex){
            case 1: return KeyEvent.KEYCODE_HOME;
            case 2: return KeyEvent.KEYCODE_MENU;
            case 3: return KeyEvent.KEYCODE_BACK;
            case 4: return KeyEvent.KEYCODE_SEARCH;
            case 5: return KeyEvent.KEYCODE_POWER;
            case 6: return KeyEvent.KEYCODE_CALL;
            case 7: return KeyEvent.KEYCODE_ENDCALL;
            case 8: return KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
            case 9: return KeyEvent.KEYCODE_MEDIA_NEXT;
            case 10: return KeyEvent.KEYCODE_MEDIA_PREVIOUS;
            case 11: return VOLUME_ACTION_LONG_HOME;
            default: return VOLUME_ACTION_NONE;
        }
    }

    // remaped indexes of CmParts' array.xml file
    public static final int translateUnhideIndexToKeycode(int unhideButtonIndex) {
        switch (unhideButtonIndex){
            case 1: return KeyEvent.KEYCODE_MENU;
            case 2: return KeyEvent.KEYCODE_BACK;
            case 3: return KeyEvent.KEYCODE_SEARCH;
            case 4: return KeyEvent.KEYCODE_CAMERA;
            case 5: return KeyEvent.KEYCODE_VOLUME_UP;
            case 6: return KeyEvent.KEYCODE_VOLUME_DOWN;
            default: return KeyEvent.KEYCODE_HOME;
        }
    }
}