Android Open Source - amulet Shared Preferences Wrapper






From Project

Back to project page amulet.

License

The source code is released under:

MIT License

If you think the Android project amulet listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package scamell.michael.amulet;
//from   www.j a  va  2s. c om
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

public class SharedPreferencesWrapper {

    public static void saveToPrefs(Context context, String key, String value) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        final SharedPreferences.Editor editor = prefs.edit();
        editor.putString(key, value);
        editor.commit();
    }

    public static void saveToPrefs(Context context, String key, boolean value) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        final SharedPreferences.Editor editor = prefs.edit();
        editor.putBoolean(key, value);
        editor.commit();
    }

    public static void saveToPrefs(Context context, String key, int value) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        final SharedPreferences.Editor editor = prefs.edit();
        editor.putInt(key, value);
        editor.commit();
    }

    public static void saveToPrefs(Context context, String key, float value) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        final SharedPreferences.Editor editor = prefs.edit();
        editor.putFloat(key, value);
        editor.commit();
    }

    public static void removeFromPrefs(Context context, String key) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        final SharedPreferences.Editor editor = prefs.edit();
        editor.remove(key);
        editor.commit();
    }

    public static String getFromPrefs(Context context, String key, String defaultValue) {
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
        try {
            return sharedPrefs.getString(key, defaultValue);
        } catch (Exception e) {
            e.printStackTrace();
            Log.i("Wrong_Type", "Wrong value type returned");
            return defaultValue;
        }
    }

    public static boolean getFromPrefs(Context context, String key, boolean defaultValue) {
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
        try {
            return sharedPrefs.getBoolean(key, defaultValue);
        } catch (Exception e) {
            e.printStackTrace();
            Log.i("Wrong_Type", "Wrong value type returned");
            return defaultValue;
        }
    }

    public static int getFromPrefs(Context context, String key, int defaultValue) {
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
        try {
            return sharedPrefs.getInt(key, defaultValue);
        } catch (Exception e) {
            e.printStackTrace();
            Log.i("Wrong_Type", "Wrong value type returned");
            return defaultValue;
        }
    }

    public static float getFromPrefs(Context context, String key, float defaultValue) {
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
        try {
            return sharedPrefs.getFloat(key, defaultValue);
        } catch (Exception e) {
            e.printStackTrace();
            Log.i("Wrong_Type", "Wrong value type returned");
            return defaultValue;
        }
    }
}




Java Source Code List

scamell.michael.amulet.AboutDialogFragment.java
scamell.michael.amulet.AccountDetailsFragment.java
scamell.michael.amulet.ChangePasswordDialogFragment.java
scamell.michael.amulet.CoolveticaTextView.java
scamell.michael.amulet.DateAndTime.java
scamell.michael.amulet.DrinkDiaryEntries.java
scamell.michael.amulet.DrinkDiaryEntryAdapter.java
scamell.michael.amulet.DrinkDiaryEntry.java
scamell.michael.amulet.DrinkDiaryFavouriteDrinksDialogFragment.java
scamell.michael.amulet.DrinkDiaryFragment.java
scamell.michael.amulet.ExampleDrinksDialogFragment.java
scamell.michael.amulet.FavouriteDrinkUtility.java
scamell.michael.amulet.HomeFragment.java
scamell.michael.amulet.InspectionTaskActivity.java
scamell.michael.amulet.InspectionTaskInstructions1Fragment.java
scamell.michael.amulet.InspectionTaskInstructions2Fragment.java
scamell.michael.amulet.LastTaskInstructionFragment.java
scamell.michael.amulet.LoginActivity.java
scamell.michael.amulet.LogoutDialogFragment.java
scamell.michael.amulet.MainActivity.java
scamell.michael.amulet.OnPostHttpData.java
scamell.michael.amulet.OnRetrieveHttpData.java
scamell.michael.amulet.PostHTTPDataAsync.java
scamell.michael.amulet.RegisterActivity.java
scamell.michael.amulet.ResumeTaskDialogFragment.java
scamell.michael.amulet.RetrieveHTTPDataAsync.java
scamell.michael.amulet.RetrieveHTTPData.java
scamell.michael.amulet.RetrieveTaskDataFromServer.java
scamell.michael.amulet.SaveDrinkDiaryUtility.java
scamell.michael.amulet.SendDrinkDiaryEntriesToServer.java
scamell.michael.amulet.SendDrinkDiaryEntryToServer.java
scamell.michael.amulet.SendTaskEntriesToServer.java
scamell.michael.amulet.SendTaskEntryToServer.java
scamell.michael.amulet.SequenceTaskActivity.java
scamell.michael.amulet.SequenceTaskInstruction1Fragment.java
scamell.michael.amulet.SequenceTaskInstruction2Fragment.java
scamell.michael.amulet.SequenceTaskInstruction3Fragment.java
scamell.michael.amulet.SharedPreferencesWrapper.java
scamell.michael.amulet.Sound.java
scamell.michael.amulet.TaskEntries.java
scamell.michael.amulet.TaskEntry.java
scamell.michael.amulet.TaskFinishFragment.java
scamell.michael.amulet.TaskInstructionsActivity.java
scamell.michael.amulet.TaskStartCountdownFragment.java
scamell.michael.amulet.TasksFirstStartWelcomeFragment.java
scamell.michael.amulet.TasksMenuFragment.java
scamell.michael.amulet.UnitCalculatorFavouriteDrinksDialogFragment.java
scamell.michael.amulet.UnitCalculatorFragment.java
scamell.michael.amulet.UnitCalculator.java