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.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.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 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 showOnScreenNavBar(int platformVersion)44 public static boolean showOnScreenNavBar(int platformVersion) { 45 return isGreaterOrEqual(platformVersion, ICE_CREAM_SANDWICH); 46 } 47 getStatusBarColor(int platformVersion)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 getResourceDirs(int platformVersion)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 getTime(int platformVersion)76 public static String getTime(int platformVersion) { 77 if (isGreaterOrEqual(platformVersion, M)) { 78 return "6: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 // Should never happen. 102 return "4:04"; 103 } 104 getTimeColor(int platformVersion)105 public static int getTimeColor(int platformVersion) { 106 if (isGreaterOrEqual(platformVersion, KITKAT) || 107 platformVersion > FROYO && platformVersion < HONEYCOMB) { 108 // Gingerbread and KitKat onwards. 109 return WHITE; 110 } 111 // Black for froyo. 112 if (platformVersion < GINGERBREAD) { 113 return BLACK; 114 } else if (platformVersion < KITKAT) { 115 // Honeycomb to JB-mr2: Holo blue light. 116 return 0xff33b5e5; 117 } 118 // Should never happen. 119 return WHITE; 120 } 121 getWifiIconType(int platformVersion)122 public static String getWifiIconType(int platformVersion) { 123 return isGreaterOrEqual(platformVersion, LOLLIPOP) ? "xml" : "png"; 124 } 125 126 /** 127 * Compare simulated platform version and code from {@link VERSION_CODES} to check if 128 * the simulated platform is greater than or equal to the version code. 129 */ isGreaterOrEqual(int platformVersion, int code)130 public static boolean isGreaterOrEqual(int platformVersion, int code) { 131 // simulated platform version = 0 means that we use the latest. 132 return platformVersion == 0 || platformVersion >= code; 133 } 134 } 135