android:excludeFromRecents="true"
android:theme="@android:style/Theme.Dialog"
android:launchMode="singleTask"
- android:taskAffinity=":AlarmAlert" />
+ android:taskAffinity=":AlarmAlert"
+ android:configChanges="orientation|keyboardHidden|keyboard|navigation" />
<activity android:name="ClockPicker" />
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
- <!-- no translation found for app_label (719424688690928500) -->
- <skip />
- <string name="add_alarm">"Add alarm"</string>
- <string name="delete_alarm">"Delete alarm"</string>
- <string name="show_clock">"Show clock"</string>
- <string name="hide_clock">"Hide clock"</string>
- <string name="set_alarm">"Set alarm"</string>
- <string name="enable">"Alarm"</string>
- <string name="alarm_vibrate">"Vibrate"</string>
- <string name="alarm_repeat">"Repeat"</string>
- <string name="alert">"Ringtone"</string>
- <string name="time">"Time"</string>
- <!-- no translation found for alert_title (7145110266896791932) -->
- <skip />
- <string name="alarm_alert_dismiss_text">"Dismiss"</string>
- <!-- no translation found for alarm_alert_alert_silenced (6161953199860209948) -->
- <skip />
- <string name="alarm_alert_snooze_text">"Snooze"</string>
- <string name="alarm_alert_snooze_set">"Snoozing for <xliff:g id="MINUTES">%d</xliff:g> minutes."</string>
- <string name="alarm_alert_snooze_not_set">"Snooze not set -- next alarm set for <xliff:g id="TIME">%s</xliff:g>"</string>
- <string name="alarm_set">"This alarm is set for <xliff:g id="TIME_DELTA">%s</xliff:g> from now."</string>
- <string name="combiner">"<xliff:g id="XXX_0">%1$s</xliff:g><xliff:g id="XXX_1">%2$s</xliff:g><xliff:g id="XXX_2">%3$s</xliff:g><xliff:g id="XXX_3">%4$s</xliff:g><xliff:g id="XXX_4">%5$s</xliff:g>"</string>
- <string name="day">"1 day"</string>
- <string name="days">"<xliff:g id="DAYS">%s</xliff:g> days"</string>
- <string name="hour">"1 hour"</string>
- <string name="hours">"<xliff:g id="HOURS">%s</xliff:g> hours"</string>
- <string name="and">" and "</string>
- <string name="space">" "</string>
- <string name="subminute">"less than 1 minute"</string>
- <string name="minute">"1 minute"</string>
- <string name="minutes">"<xliff:g id="MINUTES">%s</xliff:g> minutes"</string>
- <string name="am">"am"</string>
- <string name="pm">"pm"</string>
- <string name="every_day">"every day"</string>
- <string name="never">"Never"</string>
- <string name="day_concat">", "</string>
- <string name="clock_instructions">"Select a clock to display."</string>
- <string name="error">"Alarm not set"</string>
- <string name="dberror">"Sorry, the alarm could not be set."</string>
- <!-- no translation found for days_of_week:0 (8344265315142161020) -->
- <!-- no translation found for days_of_week:1 (7541897985112185383) -->
- <!-- no translation found for days_of_week:2 (4893243935223768060) -->
- <!-- no translation found for days_of_week:3 (1609352753342325832) -->
- <!-- no translation found for days_of_week:4 (1959588981877324716) -->
- <!-- no translation found for days_of_week:5 (1888524930952528619) -->
- <!-- no translation found for days_of_week:6 (4773879695810324460) -->
- <!-- no translation found for days_of_week_short:0 (486773581413687657) -->
- <!-- no translation found for days_of_week_short:1 (5122948226489234004) -->
- <!-- no translation found for days_of_week_short:2 (2480532703743806857) -->
- <!-- no translation found for days_of_week_short:3 (7465873194133774157) -->
- <!-- no translation found for days_of_week_short:4 (934143296602731292) -->
- <!-- no translation found for days_of_week_short:5 (1100587425646981714) -->
- <!-- no translation found for days_of_week_short:6 (4871830994398665704) -->
-</resources>
<string name="app_label">"Alarm"</string>
<string name="add_alarm">"Legg til alarm"</string>
<string name="delete_alarm">"Slett alarm"</string>
- <!-- no translation found for delete_alarm_confirm (4237696873219106907) -->
- <skip />
+ <string name="delete_alarm_confirm">"Denne alarmen vil bli slettet."</string>
<string name="show_clock">"Vis klokke"</string>
<string name="hide_clock">"Fjern klokke"</string>
<string name="set_alarm">"Sett alarm"</string>
<string name="and">"og"</string>
<!-- no translation found for space (9141227650891547547) -->
<skip />
- <string name="subminute">"mindre en et minutt"</string>
+ <string name="subminute">"mindre enn et minutt"</string>
<string name="minute">"et minutt"</string>
<string name="minutes">"<xliff:g id="MINUTES">%s</xliff:g> minutter"</string>
<string name="am">"am"</string>
<string name="clock_instructions">"Velg klokken som skal vises."</string>
<string name="error">"Alarmen ble ikke satt"</string>
<string name="dberror">"Beklager, kunne ikke sette alarmen."</string>
- <!-- no translation found for analog_gadget (1670505720837152766) -->
- <skip />
+ <string name="analog_gadget">"Analog klokke"</string>
<string-array name="days_of_week">
<item>"Mandag"</item>
<item>"Tirsdag"</item>
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.View;
fully debugged the app failing to start up */
Log.v("AlarmAlert.onCreate()");
- setContentView(R.layout.alarm_alert);
-
mKlaxon = AlarmKlaxon.getInstance();
// Popup alert over black screen
mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
- /* set clock face */
- LayoutInflater mFactory = LayoutInflater.from(this);
- SharedPreferences settings = getSharedPreferences(AlarmClock.PREFERENCES, 0);
- int face = settings.getInt(AlarmClock.PREF_CLOCK_FACE, 0);
- if (face < 0 || face >= AlarmClock.CLOCKS.length) face = 0;
- View clockLayout = (View)mFactory.inflate(AlarmClock.CLOCKS[face], null);
- ViewGroup clockView = (ViewGroup)findViewById(R.id.clockView);
- clockView.addView(clockLayout);
- if (clockLayout instanceof DigitalClock) {
- ((DigitalClock)clockLayout).setAnimate();
- }
-
mAlarmId = getIntent().getIntExtra(Alarms.ID, -1);
/* allow next alarm to trigger while this activity is
Alarms.disableAlert(AlarmAlert.this, mAlarmId);
Alarms.setNextAlert(this);
+ mKlaxon.setKillerCallback(new AlarmKlaxon.KillerCallback() {
+ public void onKilled() {
+ if (Log.LOGV) Log.v("onKilled()");
+ TextView silenced = (TextView)findViewById(R.id.silencedText);
+ silenced.setText(
+ getString(R.string.alarm_alert_alert_silenced,
+ AlarmKlaxon.ALARM_TIMEOUT_SECONDS / 60));
+ silenced.setVisibility(View.VISIBLE);
+
+ /* don't allow snooze */
+ mSnoozeButton.setEnabled(false);
+
+ mKlaxon.stop(AlarmAlert.this, mSnoozed);
+ releaseLocks();
+ }
+ });
+
+ mKlaxon.restoreInstanceState(this, icicle);
+
+ updateLayout();
+ }
+
+ private void updateLayout() {
+ setContentView(R.layout.alarm_alert);
+
+ /* set clock face */
+ LayoutInflater mFactory = LayoutInflater.from(this);
+ SharedPreferences settings =
+ getSharedPreferences(AlarmClock.PREFERENCES, 0);
+ int face = settings.getInt(AlarmClock.PREF_CLOCK_FACE, 0);
+ if (face < 0 || face >= AlarmClock.CLOCKS.length) {
+ face = 0;
+ }
+ View clockLayout =
+ (View) mFactory.inflate(AlarmClock.CLOCKS[face], null);
+ ViewGroup clockView = (ViewGroup) findViewById(R.id.clockView);
+ clockView.addView(clockLayout);
+ if (clockLayout instanceof DigitalClock) {
+ ((DigitalClock) clockLayout).setAnimate();
+ }
+
/* snooze behavior: pop a snooze confirmation view, kick alarm
manager. */
mSnoozeButton = (Button) findViewById(R.id.snooze);
mSnoozeButton.requestFocus();
mSnoozeButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
- /* If next alarm is set for sooner than the snooze interval,
- don't snooze: instead toast user that snooze will not be set */
- final long snoozeTarget = System.currentTimeMillis() + 1000 * 60 * SNOOZE_MINUTES;
- long nextAlarm = Alarms.calculateNextAlert(AlarmAlert.this).getAlert();
+ // If next alarm is set for sooner than the snooze interval,
+ // don't snooze: instead toast user that snooze will not be set
+ final long snoozeTarget = System.currentTimeMillis()
+ + (1000 * 60 * SNOOZE_MINUTES);
+ final long nextAlarm =
+ Alarms.calculateNextAlert(AlarmAlert.this).getAlert();
+ String displayTime = null;
if (nextAlarm < snoozeTarget) {
Calendar c = Calendar.getInstance();
c.setTimeInMillis(nextAlarm);
- Toast.makeText(AlarmAlert.this,
- getString(R.string.alarm_alert_snooze_not_set,
- Alarms.formatTime(AlarmAlert.this, c)),
- Toast.LENGTH_LONG).show();
+ displayTime = getString(R.string.alarm_alert_snooze_set,
+ Alarms.formatTime(AlarmAlert.this, c));
} else {
- Toast.makeText(AlarmAlert.this,
- getString(R.string.alarm_alert_snooze_set,
- SNOOZE_MINUTES),
- Toast.LENGTH_LONG).show();
-
- Alarms.saveSnoozeAlert(AlarmAlert.this, mAlarmId, snoozeTarget);
+ Alarms.saveSnoozeAlert(AlarmAlert.this, mAlarmId,
+ snoozeTarget);
Alarms.setNextAlert(AlarmAlert.this);
mSnoozed = true;
+ displayTime = getString(R.string.alarm_alert_snooze_set,
+ SNOOZE_MINUTES);
}
+ // Display the snooze minutes in a toast.
+ Toast.makeText(AlarmAlert.this, displayTime,
+ Toast.LENGTH_LONG).show();
mKlaxon.stop(AlarmAlert.this, mSnoozed);
releaseLocks();
finish();
});
/* dismiss button: close notification */
- findViewById(R.id.dismiss).setOnClickListener(new Button.OnClickListener() {
- public void onClick(View v) {
- mKlaxon.stop(AlarmAlert.this, mSnoozed);
- releaseLocks();
- finish();
- }
- });
-
- mKlaxon.setKillerCallback(new AlarmKlaxon.KillerCallback() {
- public void onKilled() {
- if (Log.LOGV) Log.v("onKilled()");
- TextView silenced = (TextView)findViewById(R.id.silencedText);
- silenced.setText(
- getString(R.string.alarm_alert_alert_silenced,
- AlarmKlaxon.ALARM_TIMEOUT_SECONDS / 60));
- silenced.setVisibility(View.VISIBLE);
-
- /* don't allow snooze */
- mSnoozeButton.setEnabled(false);
-
- mKlaxon.stop(AlarmAlert.this, mSnoozed);
- releaseLocks();
- }
- });
-
- mKlaxon.restoreInstanceState(this, icicle);
+ findViewById(R.id.dismiss).setOnClickListener(
+ new Button.OnClickListener() {
+ public void onClick(View v) {
+ mKlaxon.stop(AlarmAlert.this, mSnoozed);
+ releaseLocks();
+ finish();
+ }
+ });
}
/**
mKlaxon.onSaveInstanceState(icicle);
}
+ @Override
+ public void onConfigurationChanged(Configuration config) {
+ super.onConfigurationChanged(config);
+ updateLayout();
+ }
+
private synchronized void enableKeyguard() {
if (mKeyguardLock != null) {
mKeyguardLock.reenableKeyguard();
import android.content.ContentResolver;
import android.content.Context;
+import android.content.res.AssetFileDescriptor;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnErrorListener;
if (Log.LOGV) Log.v("AlarmKlaxon.play() " + mAlarmId + " alert " + mAlert);
- if (mVibrate) {
- mVibrator.vibrate(sVibratePattern, 0);
- } else {
- mVibrator.cancel();
- }
-
/* play audio alert */
if (mAlert == null) {
Log.e("Unable to play alarm: no audio file available");
} else {
-
/* we need a new MediaPlayer when we change media URLs */
mMediaPlayer = new MediaPlayer();
- if (mMediaPlayer == null) {
- Log.e("Unable to instantiate MediaPlayer");
- } else {
- mMediaPlayer.setOnErrorListener(new OnErrorListener() {
- public boolean onError(MediaPlayer mp, int what, int extra) {
- Log.e("Error occurred while playing audio.");
- mMediaPlayer.stop();
- mMediaPlayer.release();
- mMediaPlayer = null;
- return true;
- }
- });
-
- try {
- mMediaPlayer.setDataSource(context, Uri.parse(mAlert));
- mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
- mMediaPlayer.setLooping(true);
- mMediaPlayer.prepare();
- } catch (Exception ex) {
- Log.e("Error playing alarm: " + mAlert, ex);
- return;
+ mMediaPlayer.setOnErrorListener(new OnErrorListener() {
+ public boolean onError(MediaPlayer mp, int what, int extra) {
+ Log.e("Error occurred while playing audio.");
+ mp.stop();
+ mp.release();
+ mMediaPlayer = null;
+ return true;
}
+ });
+
+ try {
+ mMediaPlayer.setDataSource(context, Uri.parse(mAlert));
+ } catch (Exception ex) {
+ Log.v("Using the fallback ringtone");
+ /* The alert may be on the sd card which could be busy right
+ * now. Use the fallback ringtone. */
+ AssetFileDescriptor afd =
+ context.getResources().openRawResourceFd(
+ com.android.internal.R.raw.fallbackring);
+ if (afd != null) {
+ try {
+ mMediaPlayer.setDataSource(afd.getFileDescriptor(),
+ afd.getStartOffset(), afd.getLength());
+ afd.close();
+ } catch (Exception ex2) {
+ Log.e("Failed to play fallback ringtone", ex2);
+ /* At this point we just don't play anything */
+ }
+ }
+ }
+ /* Now try to play the alert. */
+ try {
+ mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
+ mMediaPlayer.setLooping(true);
+ mMediaPlayer.prepare();
mMediaPlayer.start();
+ } catch (Exception ex) {
+ Log.e("Error playing alarm: " + mAlert, ex);
}
}
+
+ /* Start the vibrator after everything is ok with the media player */
+ if (mVibrate) {
+ mVibrator.vibrate(sVibratePattern, 0);
+ } else {
+ mVibrator.cancel();
+ }
+
enableKiller();
mPlaying = true;
}
mPlaying = false;
// Stop audio playing
- if (mMediaPlayer != null) mMediaPlayer.stop();
+ if (mMediaPlayer != null) {
+ mMediaPlayer.stop();
+ mMediaPlayer.release();
+ mMediaPlayer = null;
+ }
// Stop vibrator
mVibrator.cancel();
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
- if (GadgetManager.GADGET_UPDATE_ACTION.equals(action)) {
+ if (GadgetManager.ACTION_GADGET_UPDATE.equals(action)) {
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.analog_gadget);