Back to project page Tacere.
The source code is released under:
MIT License
If you think the Android project Tacere listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright (c) 2014 Jonathan Nelson/*from ww w .j a va2 s .com*/ * Released under the BSD license. For details see the COPYING file. */ package org.ciasaboark.tacere.event; import android.content.Context; import org.ciasaboark.tacere.event.ringer.RingerSource; import org.ciasaboark.tacere.event.ringer.RingerType; import org.ciasaboark.tacere.prefs.Prefs; public class EventManager { private final EventInstance event; private final Context context; private final Prefs prefs; // private RingerType ringerType = null; // private RingerSource ringerSource = null; // private Boolean shouldEventByIgnoredByDefault = null; public EventManager(Context ctx, EventInstance event) { if (ctx == null) { throw new IllegalArgumentException("Given context can not be null"); } if (event == null) { throw new IllegalArgumentException("Given event can not be null"); } this.context = ctx; this.event = event; prefs = new Prefs(ctx); } public RingerType getBestRinger() { RingerType defaultRinger = prefs.getRingerType(); RingerType eventRinger = prefs.getRingerForEventSeries(event.getEventId()); RingerType calendarRinger = prefs.getRingerForCalendar(event.getCalendarId()); RingerType bestRinger = defaultRinger; if (calendarRinger != RingerType.UNDEFINED) { bestRinger = calendarRinger; } //if the user has selected to ignore all day events then the event should be ignored, //this will be overridden by either a event series ringer, or an instance specific ringer if (shouldEventBeIgnoredByDefault()) { bestRinger = RingerType.IGNORE; } if (eventRinger != RingerType.UNDEFINED) { bestRinger = eventRinger; } //if the event has a specific ringer set then the above preferences should be ignored //for this particular instance if (event.getRingerType() != RingerType.UNDEFINED) { bestRinger = event.getRingerType(); } return bestRinger; } private boolean shouldEventBeIgnoredByDefault() { boolean ignoreEvent = false; if (event.isAllDay()) { //if the event is all day then we don't need to consider whether or not it is available if (!prefs.shouldAllDayEventsSilence()) { ignoreEvent = true; } } else if (event.isFreeTime()) { if (!prefs.shouldAvailableEventsSilence()) { ignoreEvent = true; } } else { //if the event is neither an all day event nor marked as available then we do not ignore //by default } return ignoreEvent; } public RingerSource getRingerSource() { RingerSource source = RingerSource.DEFAULT; RingerType calendarRinger = prefs.getRingerForCalendar(event.getCalendarId()); if (calendarRinger != RingerType.UNDEFINED) { //a calendar specific ringer has been set, but this should only be applied to events that //should not be ignored by default if (!shouldEventBeIgnoredByDefault()) { source = RingerSource.CALENDAR; } } if (prefs.getRingerForEventSeries(event.getEventId()) != RingerType.UNDEFINED) { source = RingerSource.EVENT_SERIES; } if (event.getRingerType() != RingerType.UNDEFINED) { source = RingerSource.INSTANCE; } return source; } }