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