Created
June 1, 2012 23:08
-
-
Save alexjlockwood/2855673 to your computer and use it in GitHub Desktop.
Compatability Manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CompatibilityUtil { | |
/** | |
* Get the current Android API level. | |
*/ | |
public static int getSdkVersion() { | |
return Build.VERSION.SDK_INT; | |
} | |
/** | |
* Determine if the device is running API level 8 or higher. | |
*/ | |
public static boolean isFroyo() { | |
return getSdkVersion() >= Build.VERSION_CODES.FROYO; | |
} | |
/** | |
* Determine if the device is running API level 11 or higher. | |
*/ | |
public static boolean isHoneycomb() { | |
return getSdkVersion() >= Build.VERSION_CODES.HONEYCOMB; | |
} | |
/** | |
* Determine if the device is a tablet (i.e. it has a large screen). | |
* | |
* @param context The calling context. | |
*/ | |
public static boolean isTablet(Context context) { | |
return (context.getResources().getConfiguration().screenLayout | |
& Configuration.SCREENLAYOUT_SIZE_MASK) | |
>= Configuration.SCREENLAYOUT_SIZE_LARGE; | |
} | |
/** | |
* Determine if the device is a HoneyComb tablet. | |
* | |
* @param context The calling context. | |
*/ | |
public static boolean isHoneycombTablet(Context context) { | |
return isHoneycomb() && isTablet(context); | |
} | |
/** | |
* This class can't be instantiated. | |
*/ | |
private CompatibilityUtil() { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment