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 17 package com.android.layoutlib.bridge.bars; 18 19 import android.os._Original_Build.VERSION_CODES; 20 21 import java.util.ArrayList; 22 import java.util.Collections; 23 import java.util.List; 24 25 import static android.os._Original_Build.VERSION_CODES.*; 26 27 /** 28 * Various helper methods to simulate older versions of platform. 29 */ 30 public 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 LOLLIPOP_DIR = "/bars/v21/"; 37 private static final String PI_DIR = "/bars/v28/"; 38 39 40 private static final List<String> sDefaultResourceDir; 41 42 private static final int WHITE = 0xFFFFFFFF; 43 private static final int BLACK = 0xFF000000; 44 45 static { 46 sDefaultResourceDir = new ArrayList<>(6); 47 sDefaultResourceDir.add(PI_DIR); 48 sDefaultResourceDir.add("/bars/"); 49 // If something is not found in the default directories, we fall back to search in the 50 // old versions 51 sDefaultResourceDir.add(LOLLIPOP_DIR); 52 sDefaultResourceDir.add(KITKAT_DIR); 53 sDefaultResourceDir.add(JELLYBEAN_DIR); 54 sDefaultResourceDir.add(GINGERBREAD_DIR); 55 } 56 showOnScreenNavBar(int platformVersion)57 public static boolean showOnScreenNavBar(int platformVersion) { 58 return isGreaterOrEqual(platformVersion, ICE_CREAM_SANDWICH); 59 } 60 getStatusBarColor(int platformVersion)61 public static int getStatusBarColor(int platformVersion) { 62 // return white for froyo and earlier; black otherwise. 63 return isGreaterOrEqual(platformVersion, GINGERBREAD) ? BLACK : WHITE; 64 } 65 getResourceDirs(int platformVersion)66 public static List<String> getResourceDirs(int platformVersion) { 67 // Special case the most used scenario. 68 if (platformVersion == 0) { 69 return sDefaultResourceDir; 70 } 71 List<String> list = new ArrayList<String>(10); 72 // Gingerbread - uses custom battery and wifi icons. 73 if (platformVersion <= GINGERBREAD) { 74 list.add(GINGERBREAD_DIR); 75 } 76 // ICS - JellyBean uses custom battery, wifi. 77 if (platformVersion <= JELLY_BEAN_MR2) { 78 list.add(JELLYBEAN_DIR); 79 } 80 // KitKat - uses custom wifi and nav icons. 81 if (platformVersion <= KITKAT) { 82 list.add(KITKAT_DIR); 83 } 84 // Lollipop - Custom for sysbar and battery 85 if (platformVersion <= LOLLIPOP) { 86 list.add(LOLLIPOP_DIR); 87 } 88 89 list.addAll(sDefaultResourceDir); 90 91 return Collections.unmodifiableList(list); 92 } 93 getTime(int platformVersion)94 public static String getTime(int platformVersion) { 95 if (isGreaterOrEqual(platformVersion, O)) { 96 return "8:00"; 97 } 98 if (platformVersion < GINGERBREAD) { 99 return "2:20"; 100 } 101 if (platformVersion < ICE_CREAM_SANDWICH) { 102 return "2:30"; 103 } 104 if (platformVersion < JELLY_BEAN) { 105 return "4:00"; 106 } 107 if (platformVersion < KITKAT) { 108 return "4:30"; 109 } 110 if (platformVersion < LOLLIPOP) { 111 return "4:40"; 112 } 113 if (platformVersion < LOLLIPOP_MR1) { 114 return "5:00"; 115 } 116 if (platformVersion < M) { 117 return "5:10"; 118 } 119 if (platformVersion < N) { 120 return "6:00"; 121 } 122 if (platformVersion < O) { 123 return "7:00"; 124 } 125 // Should never happen. 126 return "4:04"; 127 } 128 getTimeColor(int platformVersion)129 public static int getTimeColor(int platformVersion) { 130 if (isGreaterOrEqual(platformVersion, KITKAT) || 131 platformVersion > FROYO && platformVersion < HONEYCOMB) { 132 // Gingerbread and KitKat onwards. 133 return WHITE; 134 } 135 // Black for froyo. 136 if (platformVersion < GINGERBREAD) { 137 return BLACK; 138 } else if (platformVersion < KITKAT) { 139 // Honeycomb to JB-mr2: Holo blue light. 140 return 0xff33b5e5; 141 } 142 // Should never happen. 143 return WHITE; 144 } 145 getWifiIconType(int platformVersion)146 public static String getWifiIconType(int platformVersion) { 147 return isGreaterOrEqual(platformVersion, LOLLIPOP) ? "xml" : "png"; 148 } 149 150 /** 151 * Compare simulated platform version and code from {@link VERSION_CODES} to check if 152 * the simulated platform is greater than or equal to the version code. 153 */ isGreaterOrEqual(int platformVersion, int code)154 public static boolean isGreaterOrEqual(int platformVersion, int code) { 155 // simulated platform version = 0 means that we use the latest. 156 return platformVersion == 0 || platformVersion >= code; 157 } 158 } 159