Example usage for android.content.res Resources updateConfiguration

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

Introduction

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

Prototype

@Deprecated
public void updateConfiguration(Configuration config, DisplayMetrics metrics) 

Source Link

Document

Store the newly updated configuration.

Usage

From source file:edu.mit.ll.dcds.android.AboutActivity.java

private void setLocale() {
    Locale locale = DataManager.getInstance().getLocale();
    Locale.setDefault(locale);//from   w w w .  java2 s .  com
    Configuration config = new Configuration();
    Resources res = getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    config.locale = locale;

    res.updateConfiguration(config, dm);
}

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

/**
 * Changing default language/*from  w  w w  .java2 s  .c  o 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 ww  w  . j ava  2  s  .  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.anykey.balala.activity.BaseActivity.java

@Override
public Resources getResources() {
    Resources res = super.getResources();
    Configuration config = new Configuration();
    config.setToDefaults();// ww w .  j a v  a2  s  .  c  o m
    res.updateConfiguration(config, res.getDisplayMetrics());
    return res;
}

From source file:com.anykey.balala.activity.BaseActivity.java

@Override
protected void onResume() {
    //?/*from ww  w  . j a v a 2s . c o m*/
    Resources resource = getResources();
    Configuration c = resource.getConfiguration();
    c.fontScale = 1.0f;
    resource.updateConfiguration(c, resource.getDisplayMetrics());
    super.onResume();
    TCAgent.onResume(this);
    MobclickAgent.onResume(this);
    AppsFlyerLib.onActivityResume(this);
}

From source file:co.edu.uniajc.vtf.content.controller.SettingsController.java

private void setLocal(String pISOLang) {
    Locale loLocale = new Locale(pISOLang);
    Resources loResource = ((Fragment) this.coView).getResources();
    DisplayMetrics loDm = loResource.getDisplayMetrics();
    Configuration loConfig = loResource.getConfiguration();
    loConfig.locale = loLocale;//from w  ww  .  java  2s  .  c  om
    loResource.updateConfiguration(loConfig, loDm);
}

From source file:net.eledge.android.europeana.gui.activity.HomeActivity.java

public void setLocale(String lang) {
    Resources res = getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    Configuration conf = res.getConfiguration();
    conf.locale = new Locale(lang);
    res.updateConfiguration(conf, dm);
    Intent refresh = new Intent(this, HomeActivity.class);
    startActivity(refresh);//from w w w  . ja  v  a2 s .  c  o  m
}

From source file:com.android.projectz.teamrocket.thebusapp.settings.SettingLanguageActivity.java

public void setLocale(String lang) {
    Resources res = this.getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    android.content.res.Configuration conf = res.getConfiguration();
    conf.locale = new Locale(lang.toLowerCase());
    res.updateConfiguration(conf, dm);
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    /*//from  ww  w. j  a v  a  2 s.c  om
    FLAG_ACTIVITY_CLEAR_TOP
    If set, and the activity being launched is already running in the current task,
    then instead of launching a new instance of that activity, all of the other
    activities on top of it will be closed and this Intent will be delivered to
    the (now on top) old activity as a new Intent.
     */
    startActivity(intent);
}

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//from w  ww  . j a v a2s. co  m
     */

    /* 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 .  j  ava 2 s  .c o  m
     */

    /* 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;
}