Back to project page tum-campus.
The source code is released under:
GNU General Public License
If you think the Android project tum-campus listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
?package de.tum.in.tumcampus.services; /*w w w. j a v a 2 s .c o m*/ import android.app.IntentService; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.media.AudioManager; import de.tum.in.tumcampus.common.Const; import de.tum.in.tumcampus.common.Utils; import de.tum.in.tumcampus.common.Const.Settings; import de.tum.in.tumcampus.models.LectureItemManager; /** * Service used to silence the mobile during lectures */ public class SilenceService extends IntentService { /** * Interval in milliseconds to check for current lectures */ public static int interval = 60000; /** * default init (run intent in new thread) */ public SilenceService() { super("SilenceService"); } @Override protected void onHandleIntent(Intent intent) { // loop until silence mode gets disabled in settings while (Utils.getSettingBool(this, Const.Settings.silence)) { AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); LectureItemManager lim = new LectureItemManager(this); if (!lim.hasLectures()) { // no lectures available return; } Cursor c = lim.getCurrentFromDb(); if (c.getCount() != 0) { // if current lecture(s) found, silence the mobile Utils.setSettingBool(this, Settings.silence_on, true); Utils.log("set ringer mode: silent"); am.setRingerMode(AudioManager.RINGER_MODE_SILENT); } else if (Utils.getSettingBool(this, Settings.silence_on)) { // default: no silence Utils.log("set ringer mode: normal"); am.setRingerMode(AudioManager.RINGER_MODE_NORMAL); Utils.setSettingBool(this, Settings.silence_on, false); } // wait unteil next check synchronized (this) { try { wait(interval); } catch (Exception e) { Utils.log(e, ""); } } } } @Override public void onDestroy() { super.onDestroy(); Utils.log(""); // log destroy } @Override public void onCreate() { super.onCreate(); Utils.log(""); // log create } }