public void enforceLocale(Activity activity) {
   Configuration config = activity.getBaseContext().getResources().getConfiguration();
   if (!mLocale.equals(config.locale)) {
     config.locale = mLocale;
     activity.getBaseContext().getResources().updateConfiguration(config, null);
   }
 }
  private SoftKeyboard getKeyboard(KeyboardId id) {
    SoftReference<SoftKeyboard> ref = mKeyboards.get(id);
    SoftKeyboard keyboard = (ref == null) ? null : ref.get();
    if (keyboard == null) {
      Resources orig = mInputMethodService.getResources();
      Configuration conf = orig.getConfiguration();
      Locale saveLocale = conf.locale;
      conf.locale = mInputLocale;
      orig.updateConfiguration(conf, null);
      if (mThemedContext != null) {
        keyboard = new SoftKeyboard(mThemedContext, id.mXml, id.mKeyboardMode, mThemeResId);
      } else {
        keyboard = new SoftKeyboard(mInputMethodService, id.mXml, id.mKeyboardMode);
      }
      keyboard.setLanguageSwitcher(
          mLanguageSwitcher,
          mIsAutoCompletionActive,
          mInputView.getLanguagebarTextColor(),
          mInputView.getLanguagebarShadowColor(),
          mLanguageSwitchMode);

      if (id.mEnableShiftLock) {
        keyboard.enableShiftLock();
      }
      mKeyboards.put(id, new SoftReference<SoftKeyboard>(keyboard));

      conf.locale = saveLocale;
      orig.updateConfiguration(conf, null);
    }
    return keyboard;
  }
Example #3
0
 /**
  * Set the current application language.
  *
  * @param useEnglish {@code true} if English should be used, {@code false} to use the systems
  *     settings
  */
 private void initApplicationLocale(final boolean useEnglish) {
   applicationLocale = useEnglish ? Locale.ENGLISH : Locale.getDefault();
   final Configuration config = new Configuration();
   config.locale = applicationLocale;
   final Resources resources = getResources();
   resources.updateConfiguration(config, resources.getDisplayMetrics());
 }
Example #4
0
 public static void changeLocale(Context context, String localeText) {
   Locale locale = new Locale(localeText);
   Locale.setDefault(locale);
   Configuration config = new Configuration();
   config.locale = locale;
   context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
 }
Example #5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    String Language = preferences.getString("Lang", "no_find");
    Locale mylocale = new Locale(Language);
    if (Language == "no_find") mylocale = Resources.getSystem().getConfiguration().locale;
    Resources res1 = getResources();
    Configuration conf = res1.getConfiguration();
    conf.locale = mylocale;
    DisplayMetrics dm = res1.getDisplayMetrics();
    res1.updateConfiguration(conf, dm);
    Locale.setDefault(mylocale);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(
        new ViewPager.SimpleOnPageChangeListener() {
          @Override
          public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
          }
        });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
      // Create a tab with text corresponding to the page title defined by
      // the adapter. Also specify this Activity object, which implements
      // the TabListener interface, as the callback (listener) for when
      // this tab is selected.
      actionBar.addTab(
          actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    // initializes the control object which serves as the interface between the gui and
    // the usb communication
    control = (Control) getLastCustomNonConfigurationInstance();
    if (control == null) {
      Resources res = getResources();
      String[] commands = res.getStringArray(R.array.command_select_options);
      control = new Control();
      Control.initialize(commands);
    }

    //        launchAboutActivity();
  }
  private void displayView(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;
    switch (position) {
      case 0:
        fragment = new FragmentDashboard();
        break;
      case 1:
        fragment = new FragmentProfile();
        break;
      case 2:
        Intent i = new Intent(ActivityHome.this, ActivityCarrierGraph.class); // ActivityExamModule

        startActivity(i);
        // fragment = new FragmentTakeExam();
        break;
      case 3:
        fragment = new FragmentViewResult();
        break;
      case 4:
        SharedPreferences.Editor editor = sharedPreferences.edit();

        editor.remove("userId");
        editor.commit();
        myLocale = Locale.ENGLISH;
        Locale.setDefault(myLocale);
        android.content.res.Configuration config = new android.content.res.Configuration();
        config.locale = myLocale;
        getBaseContext()
            .getResources()
            .updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
        Intent in = new Intent();
        in.setClass(ActivityHome.this, ActivityEmployeeLogin.class);
        startActivity(in);

        break;
      case 5:
        // fragment = new WhatsHotFragment();
        break;

      default:
        break;
    }

    if (fragment != null) {
      FragmentManager fragmentManager = getFragmentManager();
      fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();

      /*
       * mDrawerList.setItemChecked(position, true);
       * mDrawerList.setSelection(position);
       * setTitle(navMenuTitles[position]);
       * mDrawerLayout.closeDrawer(mDrawerList);
       */
    } else {
      // error in creating fragment
      // Log.e("MainActivity", "Error in creating fragment");
      // mDrawerLayout.closeDrawer(mDrawerList);
    }
  }
  private void setLocale() {
    // Check language
    String lang = mSettings.getLanguage();
    if (lang != null && !lang.equals("") && SettingsProvider.LANG.containsKey(lang)) {
      try {
        Locale newLocale;

        // If lang is <= 3 chars, it is a language code
        if (lang.length() <= 3) {
          newLocale = new Locale(lang);
        } else {
          newLocale = (Locale) Locale.class.getField(lang).get(Locale.getDefault());
        }

        Locale.setDefault(newLocale);

        Configuration config = new Configuration(getResources().getConfiguration());
        config.locale = newLocale;
        getResources().updateConfiguration(config, getResources().getDisplayMetrics());
      } catch (Exception e) {
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        String errorReason = errors.toString();
        Log.d(
            MainActivity.class.getName(),
            "Failed to load custom language setting: \n" + errorReason);
      }
    }
  }
 public void setLocale(Locale l) {
   Resources resources = getResources();
   Configuration config = resources.getConfiguration();
   DisplayMetrics dm = resources.getDisplayMetrics();
   config.locale = l;
   resources.updateConfiguration(config, dm);
 }
  @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
     */
    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;
  }
Example #10
0
 public static boolean updateLanguage(Locale locale) {
   try {
     Object objIActMag, objActMagNative;
     Class<?> clzIActMag = Class.forName("android.app.IActivityManager");
     Class<?> clzActMagNative = Class.forName("android.app.ActivityManagerNative");
     Method mtdActMagNative$getDefault = clzActMagNative.getDeclaredMethod("getDefault");
     // IActivityManager iActMag = ActivityManagerNative.getDefault();
     objIActMag = mtdActMagNative$getDefault.invoke(clzActMagNative);
     // Configuration config = iActMag.getConfiguration();
     Method mtdIActMag$getConfiguration = clzIActMag.getDeclaredMethod("getConfiguration");
     Configuration config = (Configuration) mtdIActMag$getConfiguration.invoke(objIActMag);
     config.locale = locale;
     // iActMag.updateConfiguration(config);
     // 此处需要声明权限:android.permission.CHANGE_CONFIGURATION
     // 会重新调用 onCreate();
     Class<?>[] clzParams = {Configuration.class};
     Method mtdIActMag$updateConfiguration =
         clzIActMag.getDeclaredMethod("updateConfiguration", clzParams);
     mtdIActMag$updateConfiguration.invoke(objIActMag, config);
     return true;
   } catch (Exception e) {
     e.printStackTrace();
   }
   return false;
 }
Example #11
0
 /**
  * Set the locale.
  *
  * @param locale The locale to be set.
  */
 private static void setLocale(final Locale locale) {
   Resources res = getAppContext().getResources();
   DisplayMetrics dm = res.getDisplayMetrics();
   Configuration conf = res.getConfiguration();
   conf.locale = locale;
   res.updateConfiguration(conf, dm);
 }
Example #12
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Locale locale = new Locale(ClientAuthentication.getLanguage());
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext()
        .getResources()
        .updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
    setContentView(R.layout.activity_main);
    initAlertDialog();

    Toolbar toolbar = (Toolbar) findViewById(R.id.actionToolBar);
    destination = (AutoCompleteTextView) findViewById(R.id.main_search_destination);
    context = getApplicationContext();
    setSupportActionBar(toolbar);

    recyclerView = (RecyclerView) findViewById(R.id.recycler_view_main);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getBaseContext());
    recyclerView.setLayoutManager(linearLayoutManager);

    String[] addresses = getAddressesFromFileAsset();
    if (addresses != null) {
      ArrayAdapter<String> adapterString =
          new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, addresses);
      destination.setAdapter(adapterString);
    }

    // Hide the keyboard when launching this activity
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
  }
  private static String initGeckoEnvironment() {
    final Context context = GeckoAppShell.getApplicationContext();
    GeckoLoader.loadMozGlue(context);
    setState(State.MOZGLUE_READY);

    final Locale locale = Locale.getDefault();
    final Resources res = context.getResources();
    if (locale.toString().equalsIgnoreCase("zh_hk")) {
      final Locale mappedLocale = Locale.TRADITIONAL_CHINESE;
      Locale.setDefault(mappedLocale);
      Configuration config = res.getConfiguration();
      config.locale = mappedLocale;
      res.updateConfiguration(config, null);
    }

    String[] pluginDirs = null;
    try {
      pluginDirs = GeckoAppShell.getPluginDirectories();
    } catch (Exception e) {
      Log.w(LOGTAG, "Caught exception getting plugin dirs.", e);
    }

    final String resourcePath = context.getPackageResourcePath();
    GeckoLoader.setupGeckoEnvironment(context, pluginDirs, context.getFilesDir().getPath());

    GeckoLoader.loadSQLiteLibs(context, resourcePath);
    GeckoLoader.loadNSSLibs(context, resourcePath);
    GeckoLoader.loadGeckoLibs(context, resourcePath);
    setState(State.LIBS_READY);

    return resourcePath;
  }
Example #14
0
  /** Event raised when the form is created for the first time */
  @Override
  public void onCreate(Bundle savedInstanceState) {

    Utilities.LogDebug("GpsMainActivity.onCreate");

    SharedPreferences prefs =
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String lang = prefs.getString("locale_override", "");

    if (!lang.equalsIgnoreCase("")) {
      Locale locale = new Locale(lang);
      Locale.setDefault(locale);
      Configuration config = new Configuration();
      config.locale = locale;
      getApplicationContext()
          .getResources()
          .updateConfiguration(config, getApplicationContext().getResources().getDisplayMetrics());
    }

    super.onCreate(savedInstanceState);

    Utilities.LogInfo("GPSLogger started");

    setContentView(R.layout.main);

    GetPreferences();

    StartAndBindService();
  }
Example #15
0
  // Must be called before setContentView()
  public static void changeLanguage(Context context, int lang) {
    String language = null;
    String country = null;

    switch (lang) {
      case 1:
        language = "zh";
        country = "CN";
        break;
      case 2:
        language = "zh";
        country = "TW";
        break;
      default:
        language = "en";
        country = "US";
        break;
    }

    Locale locale = new Locale(language, country);
    Configuration conf = context.getResources().getConfiguration();
    conf.locale = locale;
    context
        .getApplicationContext()
        .getResources()
        .updateConfiguration(conf, context.getResources().getDisplayMetrics());
  }
Example #16
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String locale = PreferenceConfiguration.readPreferences(this).language;
    if (!locale.equals(PreferenceConfiguration.DEFAULT_LANGUAGE)) {
      Configuration config = new Configuration(getResources().getConfiguration());
      config.locale = new Locale(locale);
      getResources().updateConfiguration(config, getResources().getDisplayMetrics());
    }

    // Bind to the computer manager service
    bindService(
        new Intent(PcView.this, ComputerManagerService.class),
        serviceConnection,
        Service.BIND_AUTO_CREATE);

    pcGridAdapter =
        new PcGridAdapter(
            this,
            PreferenceConfiguration.readPreferences(this).listMode,
            PreferenceConfiguration.readPreferences(this).smallIconMode);

    initializeViews();
  }
Example #17
0
 public Resources getEnglishRessources(Resources standardResources) {
   AssetManager assets = standardResources.getAssets();
   DisplayMetrics metrics = standardResources.getDisplayMetrics();
   Configuration config = new Configuration(standardResources.getConfiguration());
   config.locale = Locale.US;
   return new Resources(assets, metrics, config);
 }
Example #18
0
  @TargetApi(Build.VERSION_CODES.KITKAT)
  public void switchLocaleLanguage(View view) {
    // detect which language is currently set and switch to the alternative
    String lang;
    if (Objects.equals(Locale.getDefault().getLanguage(), "en")) {
      lang = "nl";
    } else {
      lang = "en";
    }

    Locale locale = new Locale(lang);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext()
        .getResources()
        .updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());

    // store the language in sharedpreferences
    SharedPreferences prefs =
        this.getSharedPreferences(
            getResources().getString(R.string.preference_file_key), Context.MODE_PRIVATE);
    prefs.edit().putString("system_lang", lang).apply();

    // refresh activity for locale changes to take effect
    Bundle extras = new Bundle();
    extras.putSerializable("gameID", game.getId());
    extras.putBoolean("flag_EN", dictionaryEnglish);
    extras.putSerializable("p1", player1);
    extras.putSerializable("p2", player2);
    Intent i = new Intent(this, GameActivity.class).putExtras(extras);
    startActivity(i);
    this.finish();
  }
Example #19
0
 private void changeLanguage() {
   String lang = getLang();
   if (lang.equals("EN")) {
     Locale locale = new Locale("ru");
     Locale.setDefault(locale);
     Configuration config = new Configuration();
     config.locale = locale;
     getBaseContext()
         .getResources()
         .updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
     invalidateOptionsMenu();
     loadActivity();
     setLang("RU");
   } else {
     if (lang.equals("RU")) {
       Locale locale = new Locale("en");
       Locale.setDefault(locale);
       Configuration config = new Configuration();
       config.locale = locale;
       getBaseContext()
           .getResources()
           .updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
       invalidateOptionsMenu();
       loadActivity();
       setLang("EN");
     }
   }
 }
 //	//app不随系统字体的设置而改变
 @Override
 public Resources getResources() {
   Resources res = super.getResources();
   Configuration config = new Configuration();
   config.setToDefaults();
   res.updateConfiguration(config, res.getDisplayMetrics());
   return res;
 }
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
 private boolean isRTL() {
   if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
     return false;
   }
   Configuration config = getResources().getConfiguration();
   return config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
 }
Example #22
0
 public void setLocale(Context context, String lang) {
   Locale locale = new Locale(lang);
   Locale.setDefault(locale);
   Configuration config = new Configuration();
   config.locale = locale;
   context.getApplicationContext().getResources().updateConfiguration(config, null);
   init();
 }
Example #23
0
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config, null);
  }
Example #24
0
 /** 设置程序初始化语言 */
 public void updataSystemLanguage(String languageCode) {
   St.writeLog("updataSystemLanguage+languageCode" + languageCode);
   Resources resources = mContext.getResources();
   Configuration config = resources.getConfiguration();
   Locale locale = getLocale(languageCode);
   config.locale = locale;
   DisplayMetrics metrics = resources.getDisplayMetrics();
   resources.updateConfiguration(config, metrics);
   sp.edit().putString(LANGUAGE_KEY, languageCode).commit();
 }
Example #25
0
  public static void setLocaleLanguage(Context context, Locale locale) {
    Resources resources = context.getResources(); // 获得res资源对象
    Configuration config = resources.getConfiguration(); // 获得设置对象
    DisplayMetrics dm = resources.getDisplayMetrics(); // 获得屏幕参数:主要是分辨率,像素等。
    //		config.locale = Locale.SIMPLIFIED_CHINESE; // 简体中文
    config.locale = locale; // 简体中文
    resources.updateConfiguration(config, dm);

    //		LocalePicker.updateLocale(locale);
  }
  /** Change the configuration used when retrieving resources. Not for use by applications. */
  @Override
  public void setConfiguration(
      int mcc,
      int mnc,
      String locale,
      int orientation,
      int touchscreen,
      int density,
      int keyboard,
      int keyboardHidden,
      int navigation,
      int screenWidth,
      int screenHeight,
      int version) {

    Configuration c = new Configuration();
    c.mcc = mcc;
    c.mnc = mnc;
    c.locale = new Locale(locale);
    c.touchscreen = touchscreen;
    c.keyboard = keyboard;
    c.keyboardHidden = keyboardHidden;
    c.navigation = navigation;
    c.orientation = orientation;
  }
Example #27
0
 public void setLocale(String lang) {
   myLocale = new Locale(lang);
   Resources res = getResources();
   DisplayMetrics dm = res.getDisplayMetrics();
   Configuration conf = res.getConfiguration();
   conf.locale = myLocale;
   res.updateConfiguration(conf, dm);
   Intent refresh = new Intent(this, MainActivity.class);
   startActivity(refresh);
   finish();
 }
Example #28
0
 @Implementation
 public Configuration getConfiguration() {
   if (configuration == null) {
     configuration = new Configuration();
     configuration.setToDefaults();
   }
   if (configuration.locale == null) {
     configuration.locale = Locale.getDefault();
   }
   return configuration;
 }
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
 private void setPivotXToTitle(View view) {
   final TextView mTitleView = (TextView) view.findViewById(R.id.title);
   Configuration config = getResources().getConfiguration();
   if (Build.VERSION_CODES.JELLY_BEAN_MR1 <= Build.VERSION.SDK_INT
       && config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
     ViewHelper.setPivotX(mTitleView, view.findViewById(android.R.id.content).getWidth());
   } else {
     ViewHelper.setPivotX(mTitleView, 0);
   }
 }
Example #30
0
 public void checkPrefferedLocale() {
   Configuration config = getBaseContext().getResources().getConfiguration();
   String lang = osmandSettings.PREFERRED_LOCALE.get();
   if (!"".equals(lang) && !config.locale.getLanguage().equals(lang)) {
     prefferedLocale = new Locale(lang);
     Locale.setDefault(prefferedLocale);
     config.locale = prefferedLocale;
     getBaseContext()
         .getResources()
         .updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
   }
 }