aboutsummaryrefslogtreecommitdiff
path: root/bridge/src/com/android/layoutlib/bridge/bars/Config.java
blob: a49a6643a5392b8196b41ffc6ceaf1ac5bd557f6 (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
/*
 * Copyright (C) 2014 The Android Open Source 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.layoutlib.bridge.bars;

import android.os._Original_Build.VERSION_CODES;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static android.os._Original_Build.VERSION_CODES.*;

/**
 * Various helper methods to simulate older versions of platform.
 */
public class Config {

    // each of these resource dirs must end in '/'
    private static final String GINGERBREAD_DIR      = "/bars/v9/";
    private static final String JELLYBEAN_DIR        = "/bars/v18/";
    private static final String KITKAT_DIR           = "/bars/v19/";
    private static final String LOLLIPOP_DIR         = "/bars/v21/";
    private static final String PI_DIR = "/bars/v28/";


    private static final List<String> sDefaultResourceDir;

    private static final int WHITE = 0xFFFFFFFF;
    private static final int BLACK = 0xFF000000;

    static {
        sDefaultResourceDir = new ArrayList<>(6);
        sDefaultResourceDir.add(PI_DIR);
        sDefaultResourceDir.add("/bars/");
        // If something is not found in the default directories, we fall back to search in the
        // old versions
        sDefaultResourceDir.add(LOLLIPOP_DIR);
        sDefaultResourceDir.add(KITKAT_DIR);
        sDefaultResourceDir.add(JELLYBEAN_DIR);
        sDefaultResourceDir.add(GINGERBREAD_DIR);
    }

    public static boolean showOnScreenNavBar(int platformVersion) {
        return isGreaterOrEqual(platformVersion, ICE_CREAM_SANDWICH);
    }

    public static int getStatusBarColor(int platformVersion) {
        // return white for froyo and earlier; black otherwise.
        return isGreaterOrEqual(platformVersion, GINGERBREAD) ? BLACK : WHITE;
    }

    public static List<String> getResourceDirs(int platformVersion) {
        // Special case the most used scenario.
        if (platformVersion == 0) {
            return sDefaultResourceDir;
        }
        List<String> list = new ArrayList<String>(10);
        // Gingerbread - uses custom battery and wifi icons.
        if (platformVersion <= GINGERBREAD) {
            list.add(GINGERBREAD_DIR);
        }
        // ICS - JellyBean uses custom battery, wifi.
        if (platformVersion <= JELLY_BEAN_MR2) {
            list.add(JELLYBEAN_DIR);
        }
        // KitKat - uses custom wifi and nav icons.
        if (platformVersion <= KITKAT) {
            list.add(KITKAT_DIR);
        }
        // Lollipop - Custom for sysbar and battery
        if (platformVersion <= LOLLIPOP) {
            list.add(LOLLIPOP_DIR);
        }

        list.addAll(sDefaultResourceDir);

        return Collections.unmodifiableList(list);
    }

    public static String getTime(int platformVersion) {
        if (isGreaterOrEqual(platformVersion, R)) {
            return "11:00";
        }
        if (platformVersion < GINGERBREAD) {
            return "2:20";
        }
        if (platformVersion < ICE_CREAM_SANDWICH) {
            return "2:30";
        }
        if (platformVersion < JELLY_BEAN) {
            return "4:00";
        }
        if (platformVersion < KITKAT) {
            return "4:30";
        }
        if (platformVersion < LOLLIPOP) {
            return "4:40";
        }
        if (platformVersion < LOLLIPOP_MR1) {
            return "5:00";
        }
        if (platformVersion < M) {
            return "5:10";
        }
        if (platformVersion < N) {
            return "6:00";
        }
        if (platformVersion < N_MR1) {
            return "7:00";
        }
        if (platformVersion < O) {
            return "7:10";
        }
        if (platformVersion < O_MR1) {
            return "8:00";
        }
        if (platformVersion < P) {
            return "8:10";
        }
        if (platformVersion < Q) {
            return "9:00";
        }
        if (platformVersion < R) {
            return "10:00";
        }
        // Should never happen.
        return "4:04";
    }

    public static int getTimeColor(int platformVersion) {
        if (isGreaterOrEqual(platformVersion, KITKAT) ||
                platformVersion > FROYO && platformVersion < HONEYCOMB) {
            // Gingerbread and KitKat onwards.
            return WHITE;
        }
        // Black for froyo.
        if (platformVersion < GINGERBREAD) {
            return BLACK;
        } else if (platformVersion < KITKAT) {
            // Honeycomb to JB-mr2: Holo blue light.
            return 0xff33b5e5;
        }
        // Should never happen.
        return WHITE;
    }

    public static String getWifiIconType(int platformVersion) {
        return isGreaterOrEqual(platformVersion, LOLLIPOP) ? "xml" : "png";
    }

    /**
     * Compare simulated platform version and code from {@link VERSION_CODES} to check if
     * the simulated platform is greater than or equal to the version code.
     */
    public static boolean isGreaterOrEqual(int platformVersion, int code) {
        // simulated platform version = 0 means that we use the latest.
        return platformVersion == 0 || platformVersion >= code;
    }
}