/* * Copyright (C) 2012 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 in.srain.cube.util; import android.annotation.TargetApi; import android.os.Build; import android.os.Build.VERSION_CODES; import android.os.StrictMode; /** * Class containing some static utility methods about API version. */ public class Version { private Version() { } @TargetApi(VERSION_CODES.HONEYCOMB) public static void enableStrictMode() { if (Version.hasGingerbread()) { StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog(); StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll().penaltyLog(); if (Version.hasHoneycomb()) { threadPolicyBuilder.penaltyFlashScreen(); // vmPolicyBuilder.setClassInstanceLimit(ImageGridActivity.class, 1).setClassInstanceLimit(ImageDetailActivity.class, 1); } StrictMode.setThreadPolicy(threadPolicyBuilder.build()); StrictMode.setVmPolicy(vmPolicyBuilder.build()); } } /** * API level is or higher than 8 */ public static boolean hasFroyo() { // Can use static final constants like FROYO, declared in later versions // of the OS since they are inlined at compile time. This is guaranteed behavior. return Build.VERSION.SDK_INT >= VERSION_CODES.FROYO; } /** * API level is or higher than 9 */ public static boolean hasGingerbread() { return Build.VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD; } /** * API level is or higher than 11 */ public static boolean hasHoneycomb() { return Build.VERSION.SDK_INT >= 11; // VERSION_CODES.HONEYCOMB; } /** * API level is or higher than 12 */ public static boolean hasHoneycombMR1() { return Build.VERSION.SDK_INT >= 12; // VERSION_CODES.HONEYCOMB_MR1; } /** * API level is or higher than 16 */ public static boolean hasJellyBean() { return Build.VERSION.SDK_INT >= 16; // VERSION_CODES.JELLY_BEAN; } /** * API level is higher than 19 */ public static boolean hasKitKat() { return Build.VERSION.SDK_INT >= 19; //VERSION_CODES.KITKAT; } }