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