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//www.java2s.com
* Copyright (C) 2014 by Dan Wallach
* Home page: http://www.cs.rice.edu/~dwallach/calwatch/
* Licensing: http://www.cs.rice.edu/~dwallach/calwatch/licensing.html
*/package org.dwallach.calwatch;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
publicclass PreferencesHelper {
privatefinalstatic String TAG = "PreferencesHelper";
publicstaticvoid 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");
return;
}
editor.putInt("faceMode", clockState.getFaceMode());
editor.putBoolean("showSeconds", clockState.getShowSeconds());
editor.putBoolean("showDayDate", clockState.getShowDayDate());
if(!editor.commit())
Log.v(TAG, "savePreferences commit failed ?!");
}
publicstaticvoid 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");
return;
}
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.setFaceMode(faceMode);
clockState.setShowSeconds(showSeconds);
clockState.setShowDayDate(showDayDate);
clockState.pingObservers(); // we only need to do this once, versus multiple times when done internally
}
}