Back to project page ProxSensorReset.
The source code is released under:
MIT License
If you think the Android project ProxSensorReset listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.abfactory.proxsensorreset; //from w w w. j a v a 2s . c o m import java.util.ArrayList; import java.util.List; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.preference.PreferenceManager; public class PreferencesHandler { private SharedPreferences sharedPrefs; private static final String defaultLanguage = "en"; public enum Settings { LANGUAGE_LOCALE; } public enum Language { ENGLISH(R.string.languageEnglish, "en"), FRENCH(R.string.languageFrench, "fr"); private String stringFileFolder; private int ressourceID; Language(int ri, String sff){ stringFileFolder = sff; ressourceID = ri; } public String getStringFileFolder() { return stringFileFolder; } public int getRessourceID() { return ressourceID; } public static List<Integer> getSuppportedLanguagesListAsRessources(){ List<Integer> languagesAsRessources = new ArrayList<Integer>(); for(Language l: Language.values()){ languagesAsRessources.add(l.getRessourceID()); } return languagesAsRessources; } public static String getLocaleStringFromIndex(int index){ return Language.values()[index].getStringFileFolder(); } public static int getDefaultItemPositionForLocale(String locale){ int index = 0; for(Language l: Language.values()){ if(l.getStringFileFolder().equals(locale)){ return index; } index++; } return index; } } public PreferencesHandler(Context applicationContext){ // Get app preferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(applicationContext); } public void saveSettings(String locale) { Editor edit = sharedPrefs.edit(); // Set changes to perform edit.putString(Settings.LANGUAGE_LOCALE.toString(), locale); // Save preferences edit.apply(); } public String getLanguage(){ return sharedPrefs.getString(Settings.LANGUAGE_LOCALE.toString(), defaultLanguage); } public int getDefaultLanguageIndex(){ return Language.getDefaultItemPositionForLocale(sharedPrefs.getString(Settings.LANGUAGE_LOCALE.toString(), defaultLanguage)); } }