├── .gitignore ├── LICENSE ├── README.md └── com └── aracem └── utils └── version └── SupportVersion.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/dictionaries 41 | .idea/libraries 42 | 43 | # Keystore files 44 | *.jks 45 | 46 | # External native build folder generated in Android Studio 2.2 and later 47 | .externalNativeBuild 48 | 49 | # Google Services (e.g. APIs or Firebase) 50 | google-services.json 51 | 52 | # Freeline 53 | freeline.py 54 | freeline/ 55 | freeline_project_description.json 56 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Marcos Trujillo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Support Version 2 | This library is for you if: 3 | * You are lazy. 4 | * You hate search how the f*** check the Android version every time you need it. 5 | * You think that ```Build.VERSION.SDK_INT >= Build.VERSION_CODES.SOMETHING``` it's a very ugly code to write here and there. 6 | 7 | With SupportVersion you simple can do: 8 | 9 | ``` 10 | if (SupportVersion.lollipop()) { 11 | //do awesome stuff 12 | } 13 | ``` 14 | 15 | -------------------------------------------------------------------------------- /com/aracem/utils/version/SupportVersion.java: -------------------------------------------------------------------------------- 1 | package com.aracem.utils.version; 2 | 3 | import android.os.Build; 4 | 5 | /** 6 | * Util class to check if the current device is running some of the awesome Android versions. 7 | *
8 | * Created by Marcos Trujillo 9 | */ 10 | public class SupportVersion { 11 | 12 | /** 13 | * @return true when the caller API version is at least Cupcake 3 14 | */ 15 | public static boolean cupcake() { 16 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE; 17 | } 18 | 19 | /** 20 | * @return true when the caller API version is at least Donut 4 21 | */ 22 | public static boolean donut() { 23 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.DONUT; 24 | } 25 | 26 | /** 27 | * @return true when the caller API version is at least Eclair 5 28 | */ 29 | public static boolean eclair() { 30 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR; 31 | } 32 | 33 | /** 34 | * @return true when the caller API version is at least Froyo 8 35 | */ 36 | public static boolean froyo() { 37 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO; 38 | } 39 | 40 | /** 41 | * @return true when the caller API version is at least GingerBread 9 42 | */ 43 | public static boolean gingerbread() { 44 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD; 45 | } 46 | 47 | /** 48 | * @return true when the caller API version is at least Honeycomb 11 49 | */ 50 | public static boolean honeycomb() { 51 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; 52 | } 53 | 54 | /** 55 | * @return true when the caller API version is at least Honeycomb 3.2, 13 56 | */ 57 | public static boolean honeycombMR2() { 58 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2; 59 | } 60 | 61 | /** 62 | * @return true when the caller API version is at least ICS 14 63 | */ 64 | public static boolean iceCreamSandwich() { 65 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH; 66 | } 67 | 68 | /** 69 | * @return true when the caller API version is at least jellyBean 16 70 | */ 71 | public static boolean jellyBean() { 72 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; 73 | } 74 | 75 | /** 76 | * @return true when the caller API version is at least jellyBean MR1 17 77 | */ 78 | public static boolean jellyBeanMR1() { 79 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1; 80 | } 81 | 82 | /** 83 | * @return true when the caller API version is at least jellyBean MR2 18 84 | */ 85 | public static boolean jellyBeanMR2() { 86 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2; 87 | } 88 | 89 | /** 90 | * @return true when the caller API version is at least Kitkat 19 91 | */ 92 | public static boolean kitkat() { 93 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; 94 | } 95 | 96 | /** 97 | * @return true when the caller API version is at least Kitkat Watch 20 98 | */ 99 | public static boolean kitkatWatch() { 100 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH; 101 | } 102 | 103 | /** 104 | * @return true when the caller API version is at least lollipop 21 105 | */ 106 | public static boolean lollipop() { 107 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; 108 | } 109 | 110 | /** 111 | * @return true when the caller API version is at least lollipop 22 112 | */ 113 | public static boolean lollipopMR1() { 114 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1; 115 | } 116 | 117 | /** 118 | * @return true when the caller API version is at least marshmallow 23 119 | */ 120 | public static boolean marshmallow() { 121 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; 122 | } 123 | 124 | /** 125 | * @return true when the caller API version is at least nougat 24 126 | */ 127 | public static boolean nougat() { 128 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N; 129 | } 130 | 131 | /** 132 | * @return true when the caller API version is at least nougat MR1 25 133 | */ 134 | public static boolean nougatMR1() { 135 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1; 136 | } 137 | 138 | /** 139 | * @return true when the caller API version is at least oreo 26 140 | */ 141 | public static boolean oreo() { 142 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O; 143 | } 144 | 145 | /** 146 | * @param apiLevel minimum API level version that has to support the device 147 | * @return true when the caller API version is at least apiLevel 148 | */ 149 | public static boolean isAtLeastAPI(int apiLevel) { 150 | return Build.VERSION.SDK_INT >= apiLevel; 151 | } 152 | } 153 | --------------------------------------------------------------------------------