OSDN Git Service

auto import from //branches/cupcake_rel/...@141571
authorThe Android Open Source Project <initial-contribution@android.com>
Fri, 20 Mar 2009 06:08:56 +0000 (23:08 -0700)
committerThe Android Open Source Project <initial-contribution@android.com>
Fri, 20 Mar 2009 06:08:56 +0000 (23:08 -0700)
AndroidManifest.xml
res/values/strings.xml
res/xml/settings.xml [new file with mode: 0644]
src/com/android/alarmclock/AlarmClock.java
src/com/android/alarmclock/SettingsActivity.java [new file with mode: 0644]

index 81a6c78..0e1c94e 100644 (file)
             </intent-filter>
         </activity>
 
+        <activity android:name="SettingsActivity" android:label="@string/settings">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+            </intent-filter>
+        </activity>
+
         <activity android:name="SetAlarm" android:label="@string/set_alarm" />
 
         <activity android:name="AlarmAlert" android:label="@string/alert_title"
@@ -27,6 +33,7 @@
                 android:theme="@android:style/Theme.Dialog"
                 android:launchMode="singleTask"
                 android:taskAffinity=":AlarmAlert"
+                android:screenOrientation="nosensor"
                 android:configChanges="orientation|keyboardHidden|keyboard|navigation" />
 
         <activity android:name="ClockPicker" />
index d5d6760..e84f68a 100644 (file)
         <!-- Short Day of week: Sun -->
         <item>Sun</item>
     </string-array>
+    
+    <!-- Menu item title for general Alarm Clock Settings -->
+    <string name="settings">Settings</string>
+
+    <!-- Setting title for whether the alarm should play in silent mode.
+         Usually, silent mode only affects the ringer, but this setting
+         will make the alarms respect silent mode too. -->
+    <string name="alarm_in_silent_mode_title">Alarm in silent mode</string>
+
+    <!-- Setting summary for whether the alarm should play in silent mode. -->
+    <string name="alarm_in_silent_mode_summary">Play alarm even when the phone is in silent mode</string>
 
 </resources>
 
diff --git a/res/xml/settings.xml b/res/xml/settings.xml
new file mode 100644 (file)
index 0000000..5863e89
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+  
+          http://www.apache.org/licenses/LICENSE-2.0
+  
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:title="@string/settings">
+
+    <CheckBoxPreference
+        android:key="alarm_in_silent_mode"
+        android:title="@string/alarm_in_silent_mode_title"
+        android:summary="@string/alarm_in_silent_mode_summary" />
+
+</PreferenceScreen>
index ca1c900..f8902b9 100644 (file)
@@ -281,6 +281,10 @@ public class AlarmClock extends Activity {
 
         mToggleClockItem = menu.add(0, 0, 0, R.string.hide_clock);
         mToggleClockItem.setIcon(R.drawable.ic_menu_clock_face);
+        
+        MenuItem settingsItem = menu.add(0, 0, 0, R.string.settings);
+        settingsItem.setIcon(android.R.drawable.ic_menu_preferences);
+        settingsItem.setIntent(new Intent(this, SettingsActivity.class));
 
         return true;
     }
diff --git a/src/com/android/alarmclock/SettingsActivity.java b/src/com/android/alarmclock/SettingsActivity.java
new file mode 100644 (file)
index 0000000..44c4045
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.alarmclock;
+
+import android.media.AudioManager;
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceScreen;
+import android.provider.Settings;
+
+/**
+ * Settings for the Alarm Clock.
+ */
+public class SettingsActivity extends PreferenceActivity {
+
+    private static final int ALARM_STREAM_TYPE_BIT =
+            1 << AudioManager.STREAM_ALARM;
+    
+    private static final String KEY_ALARM_IN_SILENT_MODE =
+            "alarm_in_silent_mode";
+    private CheckBoxPreference mAlarmInSilentModePref;
+    
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        
+        addPreferencesFromResource(R.xml.settings);
+        
+        mAlarmInSilentModePref =
+                (CheckBoxPreference) findPreference(KEY_ALARM_IN_SILENT_MODE);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        refresh();
+    }
+
+    @Override
+    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
+            Preference preference) {
+        
+        if (preference == mAlarmInSilentModePref) {
+            
+            int ringerModeStreamTypes = Settings.System.getInt(
+                    getContentResolver(),
+                    Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
+            
+            if (mAlarmInSilentModePref.isChecked()) {
+                ringerModeStreamTypes &= ~ALARM_STREAM_TYPE_BIT;
+            } else {
+                ringerModeStreamTypes |= ALARM_STREAM_TYPE_BIT;
+            }
+            
+            Settings.System.putInt(getContentResolver(),
+                    Settings.System.MODE_RINGER_STREAMS_AFFECTED,
+                    ringerModeStreamTypes);
+            
+            return true;
+        }
+        
+        return super.onPreferenceTreeClick(preferenceScreen, preference);
+    }
+
+    private void refresh() {
+        int silentModeStreams = Settings.System.getInt(getContentResolver(),
+                Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
+        mAlarmInSilentModePref.setChecked(
+                (silentModeStreams & ALARM_STREAM_TYPE_BIT) == 0);
+    }
+    
+}