Example usage for android.content.res Resources getBoolean

List of usage examples for android.content.res Resources getBoolean

Introduction

In this page you can find the example usage for android.content.res Resources getBoolean.

Prototype

public boolean getBoolean(@BoolRes int id) throws NotFoundException 

Source Link

Document

Return a boolean associated with a particular resource ID.

Usage

From source file:Main.java

public static boolean checkDeviceHasNavigationBar(Context context) {
    boolean hasNavigationBar = false;
    Resources rs = context.getResources();
    int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
    if (id > 0) {
        hasNavigationBar = rs.getBoolean(id);
    }//from www . j  a v  a2  s.co m
    try {
        Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
        Method m = systemPropertiesClass.getMethod("get", String.class);
        String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
        if ("1".equals(navBarOverride)) {
            hasNavigationBar = false;
        } else if ("0".equals(navBarOverride)) {
            hasNavigationBar = true;
        }
    } catch (Exception e) {
    }
    return hasNavigationBar;
}

From source file:Main.java

/**
 * Check the device whether has soft navigation bar
 *///www.  j a  v a  2  s.  c  om
public static boolean hasNavigationBar(Context context) {
    Resources resources = context.getResources();
    int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
    if (id > 0) {
        return resources.getBoolean(id);
    } else { // Check for keys
        boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
        boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        return !hasMenuKey && !hasBackKey;
    }
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static boolean hasNavigationBar(Context activity) {
    boolean hasNavigationBar = false;
    Resources rs = activity.getResources();
    int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
    if (id > 0) {
        hasNavigationBar = rs.getBoolean(id);
    }//from  ww  w. j  a v  a2s . c  o m
    try {
        Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
        Method m = systemPropertiesClass.getMethod("get", String.class);
        String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
        if ("1".equals(navBarOverride)) {
            hasNavigationBar = false;
        } else if ("0".equals(navBarOverride)) {
            hasNavigationBar = true;
        }
    } catch (Exception e) {

    }

    return hasNavigationBar;
}

From source file:com.android.utils.SharedPreferencesUtils.java

/**
 * Returns the value of a boolean preference.
 *
 * @param prefs Shared preferences from which to obtain the value.
 * @param res Resources from which to obtain the key and default value.
 * @param keyResId Resource identifier for the key.
 * @param defaultResId Resource identifier for the default value.
 * @return The preference value, or the default value if not set.
 *//*from w  w  w . j a  va 2 s.  c o  m*/
public static boolean getBooleanPref(SharedPreferences prefs, Resources res, int keyResId, int defaultResId) {
    return prefs.getBoolean(res.getString(keyResId), res.getBoolean(defaultResId));
}

From source file:com.android.leanlauncher.LauncherAppState.java

public static boolean isScreenLarge(Resources res) {
    return res.getBoolean(R.bool.is_large_tablet);
}

From source file:Main.java

@TargetApi(14)
public static boolean hasNavigationBar(Context context) {
    Resources res = context.getResources();
    int resourceId = res.getIdentifier(SHOW_NAV_BAR_RES_NAME, "bool", "android");
    if (resourceId != 0) {
        boolean hasNav = res.getBoolean(resourceId);
        // check override flag (see static block)
        if ("1".equals(sNavBarOverride)) {
            hasNav = false;/*  ww w .  j a v a2  s  . c  o  m*/
        } else if ("0".equals(sNavBarOverride)) {
            hasNav = true;
        }
        return hasNav;
    } else { // fallback
        return !ViewConfiguration.get(context).hasPermanentMenuKey();
    }
}

From source file:org.catnut.core.CatnutApp.java

/**
 * boolean??//ww w  . jav  a 2  s  . c om
 *
 * @param key
 * @param defaultValue
 * @return a boolean with default res bool value
 */
public static boolean getBoolean(int key, int defaultValue) {
    SharedPreferences pref = sApp.getPreferences();
    Resources res = sApp.getResources();
    return sApp.getPreferences().getBoolean(sApp.getString(key), res.getBoolean(defaultValue));
}

From source file:Main.java

public static Object getResource(Context context, Field field, int value) {
    Resources resources = context.getResources();
    Class type = field.getType();

    if (type.isAssignableFrom(Boolean.TYPE) || type.isAssignableFrom(Boolean.class))
        return resources.getBoolean(value);
    else if (type.isAssignableFrom(Integer.TYPE) || type.isAssignableFrom(Integer.class)) {
        return resources.getInteger(value);
    } else if (type.isAssignableFrom(ColorStateList.class))
        return resources.getColorStateList(value);
    else if (type.isAssignableFrom(XmlResourceParser.class))
        return resources.getXml(value);
    else if (type.isAssignableFrom(Float.TYPE) || type.isAssignableFrom(Float.class))
        return resources.getDimension(value);
    else if (type.isAssignableFrom(Drawable.class))
        return resources.getDrawable(value);
    else if (type.isAssignableFrom(Animation.class))
        return AnimationUtils.loadAnimation(context, value);
    else if (type.isAssignableFrom(Movie.class))
        return resources.getMovie(value);
    else if (type.isAssignableFrom(String.class))
        return resources.getString(value);
    else if (type.isArray()) {
        if (type.getName().equals("[I")) {
            return resources.getIntArray(value);
        } else if (type.isAssignableFrom(String[].class)) {
            return resources.getStringArray(value);
        }//www  .  j  a v a2 s  .co m
    }

    return null;
}

From source file:mobisocial.musubi.objects.PictureObj.java

/**
 * Pass in one of raw or fd as the source of the image.
 * Not thread safe, only call on the ui thread.
 *///w  ww . j  a  v  a 2  s  .co  m
protected static void bindImageToView(Context context, ImageView imageView, byte[] raw, FileDescriptor fd) {
    // recycle old images (vs. caching in ImageCache)
    if (imageView.getDrawable() != null) {
        BitmapDrawable d = (BitmapDrawable) imageView.getDrawable();
        if (d != null && d.getBitmap() != null) {
            d.getBitmap().recycle();
        }
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    if (fd != null) {
        BitmapFactory.decodeFileDescriptor(fd, null, options);
    } else {
        BitmapFactory.decodeByteArray(raw, 0, raw.length, options);
    }
    Resources res = context.getResources();

    float scaleFactor;
    if (res.getBoolean(R.bool.is_tablet)) {
        scaleFactor = 3.0f;
    } else {
        scaleFactor = 2.0f;
    }
    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    int pixels = dm.widthPixels;
    if (dm.heightPixels < pixels) {
        pixels = dm.heightPixels;
    }
    int width = (int) (pixels / scaleFactor);
    int height = (int) ((float) width / options.outWidth * options.outHeight);
    int max_height = (int) (AppStateObj.MAX_HEIGHT * dm.density);
    if (height > max_height) {
        width = width * max_height / height;
        height = max_height;
    }

    options.inJustDecodeBounds = false;
    options.inTempStorage = getTempData();
    options.inSampleSize = 1;
    //TODO: lame, can just compute
    while (options.outWidth / (options.inSampleSize + 1) >= width
            && options.outHeight / (options.inSampleSize + 1) >= height) {
        options.inSampleSize++;
    }
    options.inPurgeable = true;
    options.inInputShareable = true;

    Bitmap bm;
    if (fd != null) {
        bm = BitmapFactory.decodeFileDescriptor(fd, null, options);
    } else {
        bm = BitmapFactory.decodeByteArray(raw, 0, raw.length, options);
    }
    imageView.getLayoutParams().width = width + 13;
    imageView.getLayoutParams().height = height + 14;
    imageView.setImageBitmap(bm);
}

From source file:ee.ioc.phon.android.speak.Utils.java

public static boolean getPrefBoolean(SharedPreferences prefs, Resources res, int key, int defaultValue) {
    return prefs.getBoolean(res.getString(key), res.getBoolean(defaultValue));
}