Home | History | Annotate | Download | only in bars
      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 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, O)) {
     78             return "8: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         if (platformVersion < O) {
    105             return "7:00";
    106         }
    107         // Should never happen.
    108         return "4:04";
    109     }
    110 
    111     public static int getTimeColor(int platformVersion) {
    112         if (isGreaterOrEqual(platformVersion, KITKAT) ||
    113                 platformVersion > FROYO && platformVersion < HONEYCOMB) {
    114             // Gingerbread and KitKat onwards.
    115             return WHITE;
    116         }
    117         // Black for froyo.
    118         if (platformVersion < GINGERBREAD) {
    119             return BLACK;
    120         } else if (platformVersion < KITKAT) {
    121             // Honeycomb to JB-mr2: Holo blue light.
    122             return 0xff33b5e5;
    123         }
    124         // Should never happen.
    125         return WHITE;
    126     }
    127 
    128     public static String getWifiIconType(int platformVersion) {
    129         return isGreaterOrEqual(platformVersion, LOLLIPOP) ? "xml" : "png";
    130     }
    131 
    132     /**
    133      * Compare simulated platform version and code from {@link VERSION_CODES} to check if
    134      * the simulated platform is greater than or equal to the version code.
    135      */
    136     public static boolean isGreaterOrEqual(int platformVersion, int code) {
    137         // simulated platform version = 0 means that we use the latest.
    138         return platformVersion == 0 || platformVersion >= code;
    139     }
    140 }
    141