Example usage for android.content.res Resources getConfiguration

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

Introduction

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

Prototype

public Configuration getConfiguration() 

Source Link

Document

Return the current configuration that is in effect for this resource object.

Usage

From source file:com.mendhak.gpslogger.common.Systems.java

public static void setLocale(String userSpecifiedLocale, Context baseContext, Resources resources) {

    if (!Strings.isNullOrEmpty(userSpecifiedLocale)) {
        LOG.debug("Setting language to " + userSpecifiedLocale);

        String language, country = "";

        if (userSpecifiedLocale.contains("-")) {
            language = userSpecifiedLocale.split("-")[0];
            country = userSpecifiedLocale.split("-")[1];
        } else {//from  w w w .j  a va 2  s. c om
            language = userSpecifiedLocale;
        }

        Locale locale = new Locale(language, country);
        Locale.setDefault(locale);
        resources.getConfiguration().locale = locale;
        baseContext.getResources().updateConfiguration(resources.getConfiguration(),
                baseContext.getResources().getDisplayMetrics());

    }
}

From source file:com.google.android.gms.common.GooglePlayServicesUtil.java

public static boolean m106a(Resources resources) {
    if (resources == null) {
        return false;
    }/*from ww w.  j a  v a 2  s  . com*/
    return (gr.fu() && ((resources.getConfiguration().screenLayout & 15) > 3)) || m112b(resources);
}

From source file:org.bottiger.podcast.utils.UIUtils.java

public static boolean isInNightMode(@NonNull Resources argResources) {

    if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES)
        return true;

    if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_NO)
        return false;

    int currentNightMode = argResources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;

    switch (currentNightMode) {
    case Configuration.UI_MODE_NIGHT_UNDEFINED:
        // We don't know what mode we're in, assume notnight
        return false;
    case Configuration.UI_MODE_NIGHT_NO:
        // Night mode is not active, we're in day time
        return false;
    case Configuration.UI_MODE_NIGHT_YES: {
        // Night mode is active, we're at night!
        //color = (int) (color * 0.2);
        //color = darken(color, 1f);
        return true;
    }/*from w ww.  j ava  2 s. com*/
    }

    return false;
}

From source file:com.bq.robotic.robopad_plusplus.fragments.ScheduleRobotMovementsFragment.java

public static int getSmallestScreenWidthDp(Context context) {
    Resources resources = context.getResources();
    try {//from  w w w .  j a v a  2 s . co m
        Field field = Configuration.class.getDeclaredField("smallestScreenWidthDp");
        return (Integer) field.get(resources.getConfiguration());
    } catch (Exception e) {
        // not perfect because reported screen size might not include status and button bars
        DisplayMetrics displayMetrics = resources.getDisplayMetrics();
        int smallestScreenWidthPixels = Math.min(displayMetrics.widthPixels, displayMetrics.heightPixels);
        return Math.round(smallestScreenWidthPixels / displayMetrics.density);
    }
}

From source file:br.com.frs.foodrestrictions.MessageCannibal.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.activity_message_cannibal, container, false);

    String language = getArguments().getString(MessageLanguageSelector.ARG_LANGUAGE);

    TextView tv = (TextView) v.findViewById(R.id.tvCannibal);

    /* Getting the current resource  and config info */
    Resources rsc = v.getContext().getResources();
    Configuration config = rsc.getConfiguration();
    /* Saving the original locale before changing to the new one
     * just to show the texts/*from   w ww.  j  av a 2  s  .  co m*/
     */
    Locale orgLocale = config.locale;

    /* Changing the language to the one the user have selected based on the
     * Languages.xml file
     */
    if (language != null) {
        config.locale = new Locale(language);
    }

    /* Setting the new locale */
    rsc.updateConfiguration(config, rsc.getDisplayMetrics());
    /* Updating the layout with the new selected language */
    tv.setText(rsc.getString(R.string.msg_joke_cannibal));

    /* Return to last locale to keep the app as it was before */
    config.locale = orgLocale;
    rsc.updateConfiguration(config, rsc.getDisplayMetrics());

    return v;
}

From source file:br.com.frs.foodrestrictions.MessageVegan.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.activity_message_vegan, container, false);

    String language = getArguments().getString(MessageLanguageSelector.ARG_LANGUAGE);

    TextView tv = (TextView) v.findViewById(R.id.tvVegegan);

    /* //TODO - Find a better way of doing it
     * I don't believe that this is the best approach to handle this problem but it is
     * the only way I found to do it so far. Do you have any better idea?
     * please help me here :D/* w w w. j  a  v  a2  s. c  om*/
     */

    /* Getting the current resource  and config info */
    Resources rsc = v.getContext().getResources();
    Configuration config = rsc.getConfiguration();
    /* Saving the original locale before changing to the new one
     * just to show the texts
     */
    Locale orgLocale = config.locale;

    if (language != null) {
        config.locale = new Locale(language);
    }

    /* Setting the new locale */
    rsc.updateConfiguration(config, rsc.getDisplayMetrics());
    /* Updating the layout with the new selected language */
    tv.setText(rsc.getString(R.string.msg_vegan));

    /* Return to last locale to keep the app as it was before */
    config.locale = orgLocale;
    rsc.updateConfiguration(config, rsc.getDisplayMetrics());

    return v;
}

From source file:br.com.frs.foodrestrictions.MessageVegetarian.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.activity_message_vegetarian, container, false);

    String language = getArguments().getString(MessageLanguageSelector.ARG_LANGUAGE);

    TextView tv = (TextView) v.findViewById(R.id.tvVegetarian);

    /* //TODO - Find a better way of doing it
     * I don't believe that this is the best approach to handle this problem but it is
     * the only way I found to do it so far. Do you have any better idea?
     * please help me here :D//from   w  w w . ja  v  a  2 s.  c om
     */

    /* Getting the current resource  and config info */
    Resources rsc = v.getContext().getResources();
    Configuration config = rsc.getConfiguration();
    /* Saving the original locale before changing to the new one
     * just to show the texts
     */
    Locale orgLocale = config.locale;

    if (language != null) {
        config.locale = new Locale(language);
    }

    /* Setting the new locale */
    rsc.updateConfiguration(config, rsc.getDisplayMetrics());
    /* Updating the layout with the new selected language */
    tv.setText(rsc.getString(R.string.msg_veget));

    /* Return to last locale to keep the app as it was before */
    config.locale = orgLocale;
    rsc.updateConfiguration(config, rsc.getDisplayMetrics());

    return v;
}

From source file:com.gm.goldencity.util.Utils.java

/**
 * Changing default language/*from www  . j  av  a2  s.co  m*/
 *
 * @param context       Application context
 * @param language_code Lang code to FA or EN - BR and etc.
 */
public static void changeLanguage(Context context, String language_code) {
    Resources res = context.getResources();
    // Change locale settings in the app.
    DisplayMetrics dm = res.getDisplayMetrics();
    android.content.res.Configuration conf = res.getConfiguration();
    conf.locale = new Locale(language_code);
    res.updateConfiguration(conf, dm);
}

From source file:com.gm.goldencity.util.Utils.java

/**
 * Changing default language/*from   w  w  w  .j  a  va  2s . c  om*/
 *
 * @param context       Application context
 * @param language_code Lang code to FA or EN - BR and etc.
 * @param title         Will set to activity
 */
public static void changeLanguage(Context context, String language_code, String title) {
    Resources res = context.getResources();
    // Change locale settings in the app.
    DisplayMetrics dm = res.getDisplayMetrics();
    android.content.res.Configuration conf = res.getConfiguration();
    conf.locale = new Locale(language_code);
    res.updateConfiguration(conf, dm);

    Activity activity = (Activity) context;
    activity.setTitle(title);
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

public static int getNavigationBarHeight(Context context) {
    int result = 0;
    try {//from w ww  .java  2s  . c  om
        final String NAV_BAR_HEIGHT_RES_NAME = "navigation_bar_height";
        final String NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME = "navigation_bar_height_landscape";

        Resources res = context.getResources();
        final boolean mInPortrait = (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            if (hasNavBar(context)) {
                String key;
                if (mInPortrait) {
                    key = NAV_BAR_HEIGHT_RES_NAME;
                } else {
                    key = NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME;
                }
                return getInternalDimensionSize(res, key);
            }
        }
    } catch (Exception e) {
        return 0;
    }
    return result;
}