Config.java revision 1ea5da6d7051c886ee8051f88850ae2effd0bd1a
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 (isGreaterOrEqual(platformVersion, N)) {
78            return "7: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 < LOLLIPOP) {
93            return "4:40";
94        }
95        if (platformVersion < LOLLIPOP_MR1) {
96            return "5:00";
97        }
98        if (platformVersion < M) {
99            return "5:10";
100        }
101        if (platformVersion < N) {
102            return "6:00";
103        }
104        // Should never happen.
105        return "4:04";
106    }
107
108    public static int getTimeColor(int platformVersion) {
109        if (isGreaterOrEqual(platformVersion, KITKAT) ||
110                platformVersion > FROYO && platformVersion < HONEYCOMB) {
111            // Gingerbread and KitKat onwards.
112            return WHITE;
113        }
114        // Black for froyo.
115        if (platformVersion < GINGERBREAD) {
116            return BLACK;
117        } else if (platformVersion < KITKAT) {
118            // Honeycomb to JB-mr2: Holo blue light.
119            return 0xff33b5e5;
120        }
121        // Should never happen.
122        return WHITE;
123    }
124
125    public static String getWifiIconType(int platformVersion) {
126        return isGreaterOrEqual(platformVersion, LOLLIPOP) ? "xml" : "png";
127    }
128
129    /**
130     * Compare simulated platform version and code from {@link VERSION_CODES} to check if
131     * the simulated platform is greater than or equal to the version code.
132     */
133    public static boolean isGreaterOrEqual(int platformVersion, int code) {
134        // simulated platform version = 0 means that we use the latest.
135        return platformVersion == 0 || platformVersion >= code;
136    }
137}
138