1/* 2 * Copyright (C) 2012 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 17package com.example.android.bitmapfun.util; 18 19import com.example.android.bitmapfun.ui.ImageDetailActivity; 20import com.example.android.bitmapfun.ui.ImageGridActivity; 21 22import android.annotation.TargetApi; 23import android.os.Build; 24import android.os.StrictMode; 25 26/** 27 * Class containing some static utility methods. 28 */ 29public class Utils { 30 private Utils() {}; 31 32 @TargetApi(11) 33 public static void enableStrictMode() { 34 if (Utils.hasGingerbread()) { 35 StrictMode.ThreadPolicy.Builder threadPolicyBuilder = 36 new StrictMode.ThreadPolicy.Builder() 37 .detectAll() 38 .penaltyLog(); 39 StrictMode.VmPolicy.Builder vmPolicyBuilder = 40 new StrictMode.VmPolicy.Builder() 41 .detectAll() 42 .penaltyLog(); 43 44 if (Utils.hasHoneycomb()) { 45 threadPolicyBuilder.penaltyFlashScreen(); 46 vmPolicyBuilder 47 .setClassInstanceLimit(ImageGridActivity.class, 1) 48 .setClassInstanceLimit(ImageDetailActivity.class, 1); 49 } 50 StrictMode.setThreadPolicy(threadPolicyBuilder.build()); 51 StrictMode.setVmPolicy(vmPolicyBuilder.build()); 52 } 53 } 54 55 public static boolean hasFroyo() { 56 // Can use static final constants like FROYO, declared in later versions 57 // of the OS since they are inlined at compile time. This is guaranteed behavior. 58 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO; 59 } 60 61 public static boolean hasGingerbread() { 62 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD; 63 } 64 65 public static boolean hasHoneycomb() { 66 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; 67 } 68 69 public static boolean hasHoneycombMR1() { 70 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1; 71 } 72 73 public static boolean hasJellyBean() { 74 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; 75 } 76} 77