Android Open Source - powerstats User Preferences






From Project

Back to project page powerstats.

License

The source code is released under:

GNU General Public License

If you think the Android project powerstats 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 com.znasibov.powerstats;
/*from   w ww  . j  a  v a 2 s.  com*/
import android.content.Context;
import android.content.SharedPreferences;


public class UserPreferences {
    private static final String fileName = "UserPreferences";

    private static volatile UserPreferences instance = null;

    private final SharedPreferences prefs;
    private SharedPreferences.Editor editor;
    boolean editing = false;

    public UserPreferences(Context context) {
        prefs = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    }

    public static void init(Context context) {
        instance = new UserPreferences(context);
    }

    public static boolean getPowerStatsPlotSmoothScrollingEnabled() {
        return instance.prefs.getBoolean("PowerStatsPlotSmoothScrollingEnabled", false);
    }

    public static void setPowerStatsPlotSmoothScrollingEnabled(boolean value) {
        putBoolean("PowerStatsPlotSmoothScrollingEnabled", value);
    }

    public static long getPowerStatsPlotDefaultDomainSize() {
        return instance.prefs.getLong("PowerStatsPlotDefaultDomainSize", Util.hoursToMs(12));
    }

    public static void setPowerStatsPlotDefaultDomainSize(long value) {
        putLong("PowerStatsPlotDefaultDomainSize", value);
    }

    public static void beginEdit() {
        instance.editing = true;
    }

    public static void endEdit() {
        getEditor().commit();
    }

    public static void putLong(String key, long value) {
        getEditor().putLong(key, value);
        if (!instance.editing) {
            getEditor().apply();
        }
    }

    public static void putBoolean(String key, boolean value) {
        getEditor().putBoolean(key, value);
        if (!instance.editing) {
            getEditor().apply();
        }
    }

    private static SharedPreferences.Editor getEditor() {
        if (instance.editor == null) {
            instance.editor = instance.prefs.edit();
        }
        return instance.editor;
    }


}




Java Source Code List

com.znasibov.powerstats.Autostart.java
com.znasibov.powerstats.MainActivity.java
com.znasibov.powerstats.PowerRecord.java
com.znasibov.powerstats.PowerRecordsListenerMixin.java
com.znasibov.powerstats.PowerRecordsListener.java
com.znasibov.powerstats.PowerStatsApplication.java
com.znasibov.powerstats.PowerStatsChartFragment.java
com.znasibov.powerstats.PowerStatsDatabase.java
com.znasibov.powerstats.PowerStatsLoggerService.java
com.znasibov.powerstats.PowerStatsPlot.java
com.znasibov.powerstats.QuickStatsFragment.java
com.znasibov.powerstats.UserPreferences.java
com.znasibov.powerstats.Util.java