Android Open Source - CalWatch Preferences Helper

From Project

Back to project page CalWatch.


The source code is released under:

GNU General Public License

If you think the Android project CalWatch 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

 * CalWatch// w w  w.  j a  va  2  s . c o m
 * Copyright (C) 2014 by Dan Wallach
 * Home page:
 * Licensing:
package org.dwallach.calwatch;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

public class PreferencesHelper {
    private final static String TAG = "PreferencesHelper";

    public static void savePreferences(Context context) {
        Log.v(TAG, "savePreferences");
        SharedPreferences prefs = context.getSharedPreferences("org.dwallach.calwatch.prefs", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();

        ClockState clockState = ClockState.getSingleton();
        if(clockState == null) {
            Log.e(TAG, "no clock state yet, can't save preferences");

        editor.putInt("faceMode", clockState.getFaceMode());
        editor.putBoolean("showSeconds", clockState.getShowSeconds());
        editor.putBoolean("showDayDate", clockState.getShowDayDate());

            Log.v(TAG, "savePreferences commit failed ?!");

    public static void loadPreferences(Context context) {
        Log.v(TAG, "loadPreferences");

        ClockState clockState = ClockState.getSingleton();
        if(clockState == null) {
            Log.e(TAG, "no clock state yet, can't load preferences");

        SharedPreferences prefs = context.getSharedPreferences("org.dwallach.calwatch.prefs", Context.MODE_PRIVATE);
        int faceMode = prefs.getInt("faceMode", Constants.DefaultWatchFace); // ClockState.FACE_TOOL
        boolean showSeconds = prefs.getBoolean("showSeconds", Constants.DefaultShowSeconds);
        boolean showDayDate = prefs.getBoolean("showDayDate", Constants.DefaultShowDayDate);

        Log.v(TAG, "faceMode: " + faceMode + ", showSeconds: " + showSeconds + ", showDayDate: " + showDayDate);


        clockState.pingObservers(); // we only need to do this once, versus multiple times when done internally

Java Source Code List