add invalidateOptionsMenuIf(), for working with action bar in a

safe-before-sdk-11 way
This commit is contained in:
Eric House 2013-10-01 07:41:59 -07:00
parent f4881dd00e
commit 4abc9623f9

View file

@ -72,6 +72,24 @@ public class Utils {
private static Boolean s_hasSmallScreen = null;
private static Random s_random = new Random();
private static interface SafeInvalOptionsMenu {
public void doInval( Activity activity );
}
private static class SafeInvalOptionsMenuImpl
implements SafeInvalOptionsMenu {
public void doInval( Activity activity ) {
activity.invalidateOptionsMenu();
}
}
private static SafeInvalOptionsMenu s_safeInval = null;
static {
int sdkVersion = Integer.valueOf( android.os.Build.VERSION.SDK );
if ( 11 <= sdkVersion ) {
s_safeInval = new SafeInvalOptionsMenuImpl();
}
}
private Utils() {}
public static int nextRandomInt()
@ -358,6 +376,13 @@ public class Utils {
item.setEnabled( enabled );
}
public static void invalidateOptionsMenuIf( Activity activity )
{
if ( null != s_safeInval ) {
s_safeInval.doInval( activity );
}
}
public static boolean hasSmallScreen( Context context )
{
if ( null == s_hasSmallScreen ) {