mirror of https://github.com/tasks/tasks
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.5 KiB
Java
108 lines
3.5 KiB
Java
package com.timsu.astrid.utilities;
|
|
|
|
import android.content.Context;
|
|
import android.content.SharedPreferences;
|
|
import android.content.SharedPreferences.Editor;
|
|
import android.content.res.Resources;
|
|
import android.net.Uri;
|
|
import android.preference.PreferenceManager;
|
|
|
|
import com.timsu.astrid.R;
|
|
|
|
public class Preferences {
|
|
|
|
// pref keys
|
|
private static final String P_CURRENT_VERSION = "cv";
|
|
private static final String P_SHOW_REPEAT_HELP = "repeathelp";
|
|
|
|
// default values
|
|
private static final boolean DEFAULT_PERSISTENCE_MODE = true;
|
|
|
|
private static SharedPreferences getPrefs(Context context) {
|
|
return PreferenceManager.getDefaultSharedPreferences(context);
|
|
}
|
|
|
|
/** Set preference defaults, if unset. called at startup */
|
|
public static void setPreferenceDefaults(Context context) {
|
|
SharedPreferences prefs = getPrefs(context);
|
|
Resources r = context.getResources();
|
|
Editor editor = prefs.edit();
|
|
|
|
if(!prefs.contains(r.getString(R.string.p_notif_annoy))) {
|
|
editor.putBoolean(r.getString(R.string.p_notif_annoy),
|
|
DEFAULT_PERSISTENCE_MODE);
|
|
}
|
|
|
|
editor.commit();
|
|
}
|
|
|
|
/** CurrentVersion: the currently installed version of Astrid */
|
|
public static int getCurrentVersion(Context context) {
|
|
return getPrefs(context).getInt(P_CURRENT_VERSION, 0);
|
|
}
|
|
|
|
/** CurrentVersion: the currently installed version of Astrid */
|
|
public static void setCurrentVersion(Context context, int version) {
|
|
Editor editor = getPrefs(context).edit();
|
|
editor.putInt(P_CURRENT_VERSION, version);
|
|
editor.commit();
|
|
}
|
|
|
|
/** ShowRepeatHelp: whether help dialog should be shown about repeats */
|
|
public static boolean shouldShowRepeatHelp(Context context) {
|
|
return getPrefs(context).getBoolean(P_SHOW_REPEAT_HELP, true);
|
|
}
|
|
|
|
public static void setShowRepeatHelp(Context context, boolean setting) {
|
|
Editor editor = getPrefs(context).edit();
|
|
editor.putBoolean(P_SHOW_REPEAT_HELP, setting);
|
|
editor.commit();
|
|
}
|
|
|
|
/** returns hour at which quiet hours start, or null if not set */
|
|
public static Integer getQuietHourStart(Context context) {
|
|
Resources r = context.getResources();
|
|
String value = getPrefs(context).getString(r.getString(
|
|
R.string.p_notif_quietStart), "");
|
|
|
|
try {
|
|
return Integer.parseInt(value);
|
|
} catch (Exception e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/** returns hour at which quiet hours start, or null if not set */
|
|
public static Integer getQuietHourEnd(Context context) {
|
|
Resources r = context.getResources();
|
|
String value = getPrefs(context).getString(r.getString(
|
|
R.string.p_notif_quietEnd), "");
|
|
|
|
try {
|
|
return Integer.parseInt(value);
|
|
} catch (Exception e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/** Get notification ringtone, or null if not set */
|
|
public static Uri getNotificationRingtone(Context context) {
|
|
Resources r = context.getResources();
|
|
String value = getPrefs(context).getString(r.getString(
|
|
R.string.key_notification_ringtone), "");
|
|
|
|
try {
|
|
return Uri.parse(value);
|
|
} catch (RuntimeException e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/** Get perstence mode setting */
|
|
public static boolean isPersistenceMode(Context context) {
|
|
Resources r = context.getResources();
|
|
return getPrefs(context).getBoolean(r.getString(
|
|
R.string.p_notif_annoy), DEFAULT_PERSISTENCE_MODE);
|
|
}
|
|
}
|