Config.java revision 553a4e91385111f20ddf426f81b3193b9e951762
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.layoutlib.bridge.bars;
18
19import java.util.ArrayList;
20import java.util.Collections;
21import java.util.List;
22
23import static android.os.Build.VERSION_CODES.*;
24
25/**
26 * Various helper methods to simulate older versions of platform.
27 */
28public class Config {
29
30    // each of these resource dirs must end in '/'
31    private static final String GINGERBREAD_DIR      = "/bars/v9/";
32    private static final String JELLYBEAN_DIR        = "/bars/v18/";
33    private static final String KITKAT_DIR           = "/bars/v19/";
34    private static final String DEFAULT_RESOURCE_DIR = "/bars/v21/";
35
36    private static final List<String> sDefaultResourceDir =
37            Collections.singletonList(DEFAULT_RESOURCE_DIR);
38
39    private static final int WHITE = 0xFFFFFFFF;
40    private static final int BLACK = 0xFF000000;
41
42    public static boolean showOnScreenNavBar(int platformVersion) {
43        return platformVersion == 0 || platformVersion >= ICE_CREAM_SANDWICH;
44    }
45
46    public static int getStatusBarColor(int platformVersion) {
47        // return white for froyo and earlier; black otherwise.
48        return platformVersion == 0 || platformVersion >= GINGERBREAD ? BLACK : WHITE;
49    }
50
51    public static List<String> getResourceDirs(int platformVersion) {
52        // Special case the most used scenario.
53        if (platformVersion == 0) {
54            return sDefaultResourceDir;
55        }
56        List<String> list = new ArrayList<String>(4);
57        // Gingerbread - uses custom battery and wifi icons.
58        if (platformVersion <= GINGERBREAD) {
59            list.add(GINGERBREAD_DIR);
60        }
61        // ICS - JellyBean uses custom battery, wifi.
62        if (platformVersion <= JELLY_BEAN_MR2) {
63            list.add(JELLYBEAN_DIR);
64        }
65        // KitKat - uses custom wifi and nav icons.
66        if (platformVersion <= KITKAT) {
67            list.add(KITKAT_DIR);
68        }
69        list.add(DEFAULT_RESOURCE_DIR);
70
71        return Collections.unmodifiableList(list);
72    }
73
74    public static String getTime(int platformVersion) {
75        if (platformVersion == 0) {
76            // TODO: revisit when the version is selected.
77            return "4:57";
78        }
79        if (platformVersion < GINGERBREAD) {
80            return "2:20";
81        }
82        if (platformVersion < ICE_CREAM_SANDWICH) {
83            return "2:30";
84        }
85        if (platformVersion < JELLY_BEAN) {
86            return "4:00";
87        }
88        if (platformVersion < KITKAT) {
89            return "4:30";
90        }
91        if (platformVersion <= KITKAT_WATCH) {
92            return "4:40";
93        }
94        // Should never happen.
95        return "4:04";
96    }
97
98    public static int getTimeColor(int platformVersion) {
99        if (platformVersion == 0 || platformVersion >= KITKAT ||
100                platformVersion > FROYO && platformVersion < HONEYCOMB) {
101            // Gingerbread and KitKat onwards.
102            return WHITE;
103        }
104        // Black for froyo.
105        if (platformVersion < GINGERBREAD) {
106            return BLACK;
107        } else if (platformVersion < KITKAT) {
108            // Honeycomb to JB-mr2: Holo blue light.
109            return 0xff33b5e5;
110        }
111        // Should never happen.
112        return WHITE;
113    }
114
115    public static String getWifiIconType(int platformVersion) {
116        return platformVersion == 0 ? "xml" : "png";
117    }
118}
119