packages/apps/AlarmClock
修訂 | 3dcb50786cff776cce667c9d8fa2061bea89b233 (tree) |
---|---|
時間 | 2009-09-16 01:46:00 |
作者 | Yi Sun <beyounn@gmai...> |
Commiter | Yi Sun |
Check in code for Wallace Wang
The changes add support to allow user to adjust the volume of the alarm sound.
It is configure-able feature. If user wants to allow the alarm sound to be adjust-able
user can set ro.alarm.volume.adjustable to true in the init.rc
@@ -54,7 +54,7 @@ public class AlarmAlert extends Activity { | ||
54 | 54 | @Override |
55 | 55 | protected void onCreate(Bundle icicle) { |
56 | 56 | super.onCreate(icicle); |
57 | - | |
57 | + AlarmClock.setVolumeControlForPlatform(this); | |
58 | 58 | // Maintain a lock during the playback of the alarm. This lock may have |
59 | 59 | // already been acquired in AlarmReceiver. If the process was killed, |
60 | 60 | // the global wake lock is gone. Acquire again just to be sure. |
@@ -26,6 +26,7 @@ import android.database.Cursor; | ||
26 | 26 | import android.net.Uri; |
27 | 27 | import android.os.Bundle; |
28 | 28 | import android.os.Handler; |
29 | +import android.os.SystemProperties; | |
29 | 30 | import android.provider.Settings; |
30 | 31 | import android.view.ContextMenu; |
31 | 32 | import android.view.ContextMenu.ContextMenuInfo; |
@@ -39,7 +40,7 @@ import android.widget.CursorAdapter; | ||
39 | 40 | import android.widget.ListView; |
40 | 41 | import android.widget.TextView; |
41 | 42 | import android.widget.CheckBox; |
42 | - | |
43 | +import android.media.AudioManager; | |
43 | 44 | import java.util.Calendar; |
44 | 45 | import java.text.DateFormatSymbols; |
45 | 46 |
@@ -67,7 +68,7 @@ public class AlarmClock extends Activity { | ||
67 | 68 | private MenuItem mToggleClockItem; |
68 | 69 | private ListView mAlarmsList; |
69 | 70 | private Cursor mCursor; |
70 | - | |
71 | + private static boolean volumeAdjustable; | |
71 | 72 | private String mAm, mPm; |
72 | 73 | |
73 | 74 | /** |
@@ -204,7 +205,9 @@ public class AlarmClock extends Activity { | ||
204 | 205 | @Override |
205 | 206 | protected void onCreate(Bundle icicle) { |
206 | 207 | super.onCreate(icicle); |
207 | - | |
208 | + volumeAdjustable=SystemProperties.getBoolean("ro.alarm.volume.adjustable",false); | |
209 | + AlarmClock.setVolumeControlForPlatform(this); | |
210 | + | |
208 | 211 | String[] ampm = new DateFormatSymbols().getAmPmStrings(); |
209 | 212 | mAm = ampm[0]; |
210 | 213 | mPm = ampm[1]; |
@@ -356,4 +359,15 @@ public class AlarmClock extends Activity { | ||
356 | 359 | private void saveClockVisibility() { |
357 | 360 | mPrefs.edit().putBoolean(PREF_SHOW_CLOCK, getClockVisibility()).commit(); |
358 | 361 | } |
362 | + public static void setVolumeControlForPlatform(Activity context){ | |
363 | + if (isVolumeAdjustable()){ | |
364 | + context.setVolumeControlStream(AudioManager.STREAM_ALARM); | |
365 | + }else{ | |
366 | + //Use default stream type,the default type use a fixed volume | |
367 | + context.setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE); | |
368 | + } | |
369 | + } | |
370 | + public static boolean isVolumeAdjustable(){ | |
371 | + return volumeAdjustable; | |
372 | + } | |
359 | 373 | } |
@@ -45,7 +45,7 @@ public class ClockPicker extends Activity implements | ||
45 | 45 | public void onCreate(Bundle icicle) { |
46 | 46 | super.onCreate(icicle); |
47 | 47 | requestWindowFeature(Window.FEATURE_NO_TITLE); |
48 | - | |
48 | + AlarmClock.setVolumeControlForPlatform(this); | |
49 | 49 | mFactory = LayoutInflater.from(this); |
50 | 50 | setContentView(R.layout.clockpicker); |
51 | 51 |
@@ -98,7 +98,7 @@ public class SetAlarm extends PreferenceActivity | ||
98 | 98 | @Override |
99 | 99 | protected void onCreate(Bundle icicle) { |
100 | 100 | super.onCreate(icicle); |
101 | - | |
101 | + AlarmClock.setVolumeControlForPlatform(this); | |
102 | 102 | addPreferencesFromResource(R.xml.alarm_prefs); |
103 | 103 | mLabel = (EditTextPreference) findPreference("label"); |
104 | 104 | mLabel.setOnPreferenceChangeListener( |
@@ -114,6 +114,7 @@ public class SetAlarm extends PreferenceActivity | ||
114 | 114 | mTimePref = findPreference("time"); |
115 | 115 | mAlarmPref = (AlarmPreference) findPreference("alarm"); |
116 | 116 | mVibratePref = (CheckBoxPreference) findPreference("vibrate"); |
117 | + mVibratePref.setEnabled(!AlarmClock.isVolumeAdjustable()); | |
117 | 118 | mRepeatPref = (RepeatPreference) findPreference("setRepeat"); |
118 | 119 | |
119 | 120 | Intent i = getIntent(); |
@@ -217,7 +218,7 @@ public class SetAlarm extends PreferenceActivity | ||
217 | 218 | mMinutes = minutes; |
218 | 219 | mAlarmOnPref.setChecked(enabled); |
219 | 220 | mDaysOfWeek.set(daysOfWeek); |
220 | - mVibratePref.setChecked(vibrate); | |
221 | + mVibratePref.setChecked(vibrate && !AlarmClock.isVolumeAdjustable()); | |
221 | 222 | |
222 | 223 | if (alert == null || alert.length() == 0) { |
223 | 224 | if (Log.LOGV) Log.v("****** reportAlarm null or 0-length alert"); |
@@ -276,12 +277,18 @@ public class SetAlarm extends PreferenceActivity | ||
276 | 277 | * contain the old value (i.e. during the preference value change). |
277 | 278 | */ |
278 | 279 | private void saveAlarm(boolean popToast, String label) { |
279 | - if (mReportAlarmCalled && mAlarmPref.mAlert != null) { | |
280 | - String alertString = mAlarmPref.mAlert.toString(); | |
281 | - saveAlarm(this, mId, mAlarmOnPref.isChecked(), mHour, mMinutes, | |
282 | - mDaysOfWeek, mVibratePref.isChecked(), label, alertString, | |
283 | - popToast); | |
284 | - } | |
280 | + if (mReportAlarmCalled) { | |
281 | + if(mAlarmPref.mAlert != null){ | |
282 | + String alertString = mAlarmPref.mAlert.toString(); | |
283 | + saveAlarm(this, mId, mAlarmOnPref.isChecked(), mHour, mMinutes, | |
284 | + mDaysOfWeek, mVibratePref.isChecked(), label, alertString, | |
285 | + popToast); | |
286 | + }else{ | |
287 | + saveAlarm(this, mId, mAlarmOnPref.isChecked(), mHour, mMinutes, | |
288 | + mDaysOfWeek, mVibratePref.isChecked(), label, label, | |
289 | + popToast); | |
290 | + } | |
291 | + } | |
285 | 292 | } |
286 | 293 | |
287 | 294 | /** |
@@ -39,7 +39,7 @@ public class SettingsActivity extends PreferenceActivity { | ||
39 | 39 | @Override |
40 | 40 | protected void onCreate(Bundle savedInstanceState) { |
41 | 41 | super.onCreate(savedInstanceState); |
42 | - | |
42 | + AlarmClock.setVolumeControlForPlatform(this); | |
43 | 43 | addPreferencesFromResource(R.xml.settings); |
44 | 44 | |
45 | 45 | mAlarmInSilentModePref = |