Android Open Source - silent-meeting Setting






From Project

Back to project page silent-meeting.

License

The source code is released under:

GNU General Public License

If you think the Android project silent-meeting 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 uk.co.bensproule.silentmeeting.constants;
//w  w w.java2 s  . co  m
import android.app.AlarmManager;
import android.content.Context;
import android.content.SharedPreferences;

public class Setting {
    public static final String ACTIVE = "active";
    public static final String ACTIVE_AFTER_EVENTS = "activeafterevents";
    public static final String ACTIVE_BEFORE_EVENTS = "activebeforeevents";
    public static final String POLLING_INTERVAL = "pollinginterval";
    public static final String PREFERENCES_NAME = "options";

    public static boolean getActive(Context context) {
        return getBoolean(context, ACTIVE);
    }

    private static boolean getBoolean(Context context, String setting) {
        SharedPreferences settings = context.getSharedPreferences(Setting.PREFERENCES_NAME, 0);

        try {
            return settings.getBoolean(setting, true);
        } catch (ClassCastException e) {
            return true;
        }
    }

    public static void setActive(Context context, boolean value) {
        setBoolean(context, ACTIVE, value);
    }

    public static void setBoolean(Context context, String setting, boolean value) {
        SharedPreferences settings = context.getSharedPreferences(Setting.PREFERENCES_NAME, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(setting, value);
        editor.commit();
    }

    public static long getActiveAfterEvents(Context context) {
        return getLong(context, ACTIVE_AFTER_EVENTS);
    }

    public static long getActiveBeforeEvents(Context context) {
        return getLong(context, ACTIVE_BEFORE_EVENTS);
    }

    public static long getInterval(Context context) {
        long interval = getLong(context, POLLING_INTERVAL);

        if (interval < 1l) {
            interval = AlarmManager.INTERVAL_DAY;
        }

        return interval;
    }

    public static long getLong(Context context, String setting) {
        SharedPreferences settings = context.getSharedPreferences(Setting.PREFERENCES_NAME, 0);
        return settings.getLong(setting, 0l);
    }

    public static void setActiveAfterEvents(Context context, long value) {
        setLong(context, ACTIVE_AFTER_EVENTS, value);
    }

    public static void setActiveBeforeEvents(Context context, long value) {
        setLong(context, ACTIVE_BEFORE_EVENTS, value);
    }

    public static void setInterval(Context context, long value) {
        setLong(context, POLLING_INTERVAL, value);
    }

    public static void setLong(Context context, String setting, long value) {
        SharedPreferences settings = context.getSharedPreferences(Setting.PREFERENCES_NAME, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putLong(setting, value);
        editor.commit();
    }
}




Java Source Code List

uk.co.bensproule.silentmeeting.ApplicationTest.java
uk.co.bensproule.silentmeeting.activity.PreferencesActivity.java
uk.co.bensproule.silentmeeting.constants.Actions.java
uk.co.bensproule.silentmeeting.constants.Extra.java
uk.co.bensproule.silentmeeting.constants.Setting.java
uk.co.bensproule.silentmeeting.dao.EventDao.java
uk.co.bensproule.silentmeeting.dao.InstanceDao.java
uk.co.bensproule.silentmeeting.dao.SQLiteHelper.java
uk.co.bensproule.silentmeeting.domain.Attendee.java
uk.co.bensproule.silentmeeting.domain.Calendar.java
uk.co.bensproule.silentmeeting.domain.DialogCloseListener.java
uk.co.bensproule.silentmeeting.domain.Event.java
uk.co.bensproule.silentmeeting.domain.Instance.java
uk.co.bensproule.silentmeeting.fragment.TimePickerFragment.java
uk.co.bensproule.silentmeeting.receiver.CalendarEventsReceiver.java
uk.co.bensproule.silentmeeting.receiver.MutePhoneBroadcastReceiver.java
uk.co.bensproule.silentmeeting.receiver.UnmutePhoneBroadcastReceiver.java
uk.co.bensproule.silentmeeting.util.StringUtils.java