private void startSpeech() { TextToSpeech tts = SFApplication.get().getTts(); doSpeech(SFApplication.get().getPrefs().getWeather()); // Remove the old weather information SFApplication.get().getPrefs().setWeather(null); // UtteranceProgressListener not available in api < 15 tts.setOnUtteranceCompletedListener(utteranceListener); }
@Override public void onReceive(Context context, Intent intent) { // Acquire wake-lock. WakeLocker.acquire(context); this.context = context; // Fetch extras. Bundle extras = intent.getExtras(); final int alarmId = new AlarmIntentHelper(intent).getAlarmId(); if (!this.isRequirementsMet(alarmId)) { return; } // Fetching alarm this.alarm = SFApplication.get().getPersister().fetchAlarmById(alarmId); // Start the alarm, this will wake the screen up! this.startAlarm(extras); if (alarm.isSpeech()) { startSpeech(); } }
private void startAudio() { SFApplication app = SFApplication.get(); AudioDriver driver = app.getAudioDriverFactory().produce(app, this.alarm.getAudioSource()); app.setAudioDriver(driver); driver.play(this.alarm.getAudioConfig()); }
/** * Returns a SpannableString of the enabled days in an alarm,<br> * where the days are differently colored if enabled/disabled. * * @param alarm the alarm to make text for. * @return the string. */ public static final SpannableString makeEnabledDaysText(final Alarm alarm) { // Compute weekday names & join. String[] names = DateTextUtils.getWeekdayNames(ENABLED_DAYS_INDICE_LENGTH, Locale.getDefault()); SpannableString text = new SpannableString(StringUtils.WS_JOINER.join(names)); // Create spans for enabled days. boolean[] enabledDays = alarm.getEnabledDays(); if (enabledDays.length != names.length || names.length != 7) { throw new AssertionError("A week has 7 days, wrong array lengths!"); } int enabledColor = Color.WHITE; int disabledColor = SFApplication.get().getResources().getColor(R.color.nearly_background_text); int start = 0; for (int i = 0; i < enabledDays.length; i++) { boolean enabled = enabledDays[i]; int length = names[i].length(); int color = enabled ? enabledColor : disabledColor; text.setSpan(new ForegroundColorSpan(color), start, start + length, 0); start += length + 1; } return text; }
/** * Checks whether or not requirements are met for starting alarm.<br> * * @param alarmId the ID of the alarm. * @return true if requirements are met. */ private boolean isRequirementsMet(int alarmId) { SFApplication app = SFApplication.get(); // Perform location filter. GPSFilterRequisitor locationReq = new GPSFilterRequisitor(app.getGPSSet(), app.getPrefs()); if (!locationReq.isSatisfied(app)) { return false; } app.releaseGPSSet(); return true; }
// read out the time and weather. public void doSpeech(String weather) { TextToSpeech tts = SFApplication.get().getTts(); // weren't able to obtain any weather. String s; if (weather == null) { s = new SpeechLocalizer(tts, this.context).getSpeech(); } else { s = new SpeechLocalizer(tts, this.context).getSpeech(weather); } lowerVolume(); TextToSpeechUtil.speakAlarm(tts, s); }
/** * Starts AlarmActivity, extras are passed on. * * @param extras extras to pass on. */ private void startAlarm(Bundle extras) { // start vibration. if (this.alarm.getAudioConfig().getVibrationEnabled()) { VibrationManager.getInstance().startVibrate(context.getApplicationContext()); } // Create intent & re-put extras. Intent activityIntent; activityIntent = new Intent(context, AlarmActivity.class); activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activityIntent.putExtras(extras); // Start activity! context.startActivity(activityIntent); showNotification(activityIntent); this.startAudio(); SFApplication.get().setRingingAlarm(alarm); }
private void lowerVolume() { AudioDriver d = SFApplication.get().getAudioDriver(); int origVolume = this.alarm.getAudioConfig().getVolume(); d.setVolume(origVolume / 5); }