Back to project page Android-Apps.
The source code is released under:
Apache License
If you think the Android project Android-Apps 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.kniezrec.xbmcgear.preferences; // w w w . j ava2 s. c om import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; import com.kniezrec.xbmcgear.R; import com.kniezrec.xbmcgear.connection.AndroidApplication; import com.kniezrec.xbmcgear.connection.Connection; public class SharedPreferencesUtil { private static final String FIRST_TIME = "_FirstTimeKey"; private static final String FIRST_GEAR_TIME = "_FirstGearTimeKey"; private static final String IP = "IP_"; private static final String PORT = "PORT_"; private static final String USERNAME = "USERNAME_"; private static final String PASSWORD = "PASSWORD_"; private static final String ID = "ID_"; private static final String MAC = "MAC_"; private static final String THEME_ID = "THEME_ID_"; private static final String PROFILE_NAME = "PROFILE_NAME"; public static boolean isHostDefined() { Context ctx = AndroidApplication.getInstance().getApplicationContext(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ctx); return (prefs.contains(IP)); } public static boolean isFirstRun() { Context ctx = AndroidApplication.getInstance().getApplicationContext(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ctx); if ((prefs.contains(FIRST_TIME))) { return false; } else { SharedPreferences.Editor edit = prefs.edit(); edit.putBoolean(FIRST_TIME, true); edit.apply(); return true; } } public static boolean isFirstGearRun() { Context ctx = AndroidApplication.getInstance().getApplicationContext(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ctx); if (prefs.contains(FIRST_TIME) || prefs.contains(FIRST_GEAR_TIME)) { return false; } else { SharedPreferences.Editor edit = prefs.edit(); edit.putBoolean(FIRST_GEAR_TIME, true); edit.apply(); return true; } } public static int getTheme() { Context ctx = AndroidApplication.getInstance().getApplicationContext(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ctx); return prefs.getInt(THEME_ID, R.drawable.watch_preview_1); } public static void setTheme(int id) { Context ctx = AndroidApplication.getInstance().getApplicationContext(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ctx); SharedPreferences.Editor edit = prefs.edit(); edit.putInt(THEME_ID, id); edit.apply(); } public static Host getPreferences() { Context ctx = AndroidApplication.getInstance().getApplicationContext(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ctx); Host h = new Host(); h.setIp(prefs.getString(IP, "")); h.setPort(prefs.getInt(PORT, 80)); h.setUsername(prefs.getString(USERNAME, "xbmc")); h.setPassword(prefs.getString(PASSWORD, "")); h.setID(prefs.getInt(ID, 0)); h.setProfileName(prefs.getString(PROFILE_NAME, "")); h.setHardware(prefs.getString(MAC, "")); return h; } public static int getActiveID() { Context ctx = AndroidApplication.getInstance().getApplicationContext(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ctx); return prefs.getInt(ID, 0); } public static void updateIfNeeded(Host h) { Context ctx = AndroidApplication.getInstance().getApplicationContext(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ctx); String ip = prefs.getString(IP, ""); if (ip != "" && ip.equals(h.getIp())) { SharedPreferences.Editor edit = prefs.edit(); edit.putString(MAC, h.getHardware()); edit.apply(); Connection.getInstance().setHost(h); } } public static void changePreferences(Host h) { Context ctx = AndroidApplication.getInstance().getApplicationContext(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ctx); SharedPreferences.Editor edit = prefs.edit(); edit.putString(IP, h.getIp()); edit.putString(USERNAME, h.getUsername()); edit.putString(PASSWORD, h.getPassword()); edit.putInt(PORT, h.getPort()); edit.putInt(ID, h.getID()); edit.putString(PROFILE_NAME, h.getProfileName()); edit.putString(MAC, h.getHardware()); edit.apply(); Connection.getInstance().setHost(h); } public static void clear() { Context ctx = AndroidApplication.getInstance().getApplicationContext(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ctx); SharedPreferences.Editor edit = prefs.edit(); edit.remove(IP); edit.apply(); Connection.getInstance().setHost(null); } }