OSDN Git Service

auto import from //branches/cupcake/...@131421
authorThe Android Open Source Project <initial-contribution@android.com>
Fri, 13 Feb 2009 20:57:52 +0000 (12:57 -0800)
committerThe Android Open Source Project <initial-contribution@android.com>
Fri, 13 Feb 2009 20:57:52 +0000 (12:57 -0800)
AndroidManifest.xml
res/values-en-rGB/strings.xml [deleted file]
res/values-nb/strings.xml
src/com/android/alarmclock/AlarmAlert.java
src/com/android/alarmclock/AlarmKlaxon.java
src/com/android/alarmclock/AnalogGadgetProvider.java

index 8c187ca..efcc882 100644 (file)
@@ -26,7 +26,8 @@
                 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" />
 
diff --git a/res/values-en-rGB/strings.xml b/res/values-en-rGB/strings.xml
deleted file mode 100644 (file)
index e868719..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-<?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>
index 4a30b31..ca5ae66 100644 (file)
@@ -18,8 +18,7 @@
     <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>
@@ -44,7 +43,7 @@
     <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>
@@ -55,8 +54,7 @@
     <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>
index c006d4d..a9b27bc 100644 (file)
@@ -21,6 +21,7 @@ import android.app.KeyguardManager;
 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;
@@ -57,8 +58,6 @@ public class AlarmAlert extends Activity {
            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
@@ -77,18 +76,6 @@ public class AlarmAlert extends Activity {
 
         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
@@ -97,33 +84,76 @@ public class AlarmAlert extends Activity {
         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();
@@ -131,32 +161,14 @@ public class AlarmAlert extends Activity {
         });
 
         /* 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();
+                    }
+                });
     }
 
     /**
@@ -200,6 +212,12 @@ public class AlarmAlert extends Activity {
         mKlaxon.onSaveInstanceState(icicle);
     }
 
+    @Override
+    public void onConfigurationChanged(Configuration config) {
+        super.onConfigurationChanged(config);
+        updateLayout();
+    }
+
     private synchronized void enableKeyguard() {
         if (mKeyguardLock != null) {
             mKeyguardLock.reenableKeyguard();
index 6ea7f9a..c582da5 100644 (file)
@@ -18,6 +18,7 @@ package com.android.alarmclock;
 
 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;
@@ -91,44 +92,60 @@ class AlarmKlaxon implements Alarms.AlarmSettings {
 
         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;
     }
@@ -144,7 +161,11 @@ class AlarmKlaxon implements Alarms.AlarmSettings {
             mPlaying = false;
 
             // Stop audio playing
-            if (mMediaPlayer != null) mMediaPlayer.stop();
+            if (mMediaPlayer != null) {
+                mMediaPlayer.stop();
+                mMediaPlayer.release();
+                mMediaPlayer = null;
+            }
 
             // Stop vibrator
             mVibrator.cancel();
index 1a6a627..1143da5 100644 (file)
@@ -52,7 +52,7 @@ public class AnalogGadgetProvider extends BroadcastReceiver {
     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);