1 package com.actionbarsherlock.internal;
3 import android.content.Context;
4 import android.os.Build;
5 import android.util.DisplayMetrics;
6 import com.actionbarsherlock.R;
8 public final class ResourcesCompat {
10 private ResourcesCompat() {}
14 * Support implementation of {@code getResources().getBoolean()} that we
15 * can use to simulate filtering based on width and smallest width
16 * qualifiers on pre-3.2.
18 * @param context Context to load booleans from on 3.2+ and to fetch the
20 * @param id Id of boolean to load.
21 * @return Associated boolean value as reflected by the current display
24 public static boolean getResources_getBoolean(Context context, int id) {
25 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
26 return context.getResources().getBoolean(id);
29 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
30 float widthDp = metrics.widthPixels / metrics.density;
31 float heightDp = metrics.heightPixels / metrics.density;
32 float smallestWidthDp = (widthDp < heightDp) ? widthDp : heightDp;
34 if (id == R.bool.abs__action_bar_embed_tabs) {
36 return true; //values-w480dp
38 return false; //values
40 if (id == R.bool.abs__split_action_bar_is_narrow) {
42 return false; //values-w480dp
46 if (id == R.bool.abs__action_bar_expanded_action_views_exclusive) {
47 if (smallestWidthDp >= 600) {
48 return false; //values-sw600dp
52 if (id == R.bool.abs__config_allowActionMenuItemTextWithIcon) {
54 return true; //values-w480dp
56 return false; //values
59 throw new IllegalArgumentException("Unknown boolean resource ID " + id);
63 * Support implementation of {@code getResources().getInteger()} that we
64 * can use to simulate filtering based on width qualifiers on pre-3.2.
66 * @param context Context to load integers from on 3.2+ and to fetch the
68 * @param id Id of integer to load.
69 * @return Associated integer value as reflected by the current display
72 public static int getResources_getInteger(Context context, int id) {
73 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
74 return context.getResources().getInteger(id);
77 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
78 float widthDp = metrics.widthPixels / metrics.density;
80 if (id == R.integer.abs__max_action_buttons) {
82 return 5; //values-w600dp
85 return 4; //values-w500dp
88 return 3; //values-w360dp
93 throw new IllegalArgumentException("Unknown integer resource ID " + id);