Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

packages-apps-AlarmClock: Commit

packages/apps/AlarmClock


Commit MetaInfo

Revision3dcb50786cff776cce667c9d8fa2061bea89b233 (tree)
Time2009-09-16 01:46:00
AuthorYi Sun <beyounn@gmai...>
CommiterYi Sun

Log Message

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

Change Summary

Incremental Difference

--- a/src/com/android/alarmclock/AlarmAlert.java
+++ b/src/com/android/alarmclock/AlarmAlert.java
@@ -54,7 +54,7 @@ public class AlarmAlert extends Activity {
5454 @Override
5555 protected void onCreate(Bundle icicle) {
5656 super.onCreate(icicle);
57-
57+ AlarmClock.setVolumeControlForPlatform(this);
5858 // Maintain a lock during the playback of the alarm. This lock may have
5959 // already been acquired in AlarmReceiver. If the process was killed,
6060 // the global wake lock is gone. Acquire again just to be sure.
--- a/src/com/android/alarmclock/AlarmClock.java
+++ b/src/com/android/alarmclock/AlarmClock.java
@@ -26,6 +26,7 @@ import android.database.Cursor;
2626 import android.net.Uri;
2727 import android.os.Bundle;
2828 import android.os.Handler;
29+import android.os.SystemProperties;
2930 import android.provider.Settings;
3031 import android.view.ContextMenu;
3132 import android.view.ContextMenu.ContextMenuInfo;
@@ -39,7 +40,7 @@ import android.widget.CursorAdapter;
3940 import android.widget.ListView;
4041 import android.widget.TextView;
4142 import android.widget.CheckBox;
42-
43+import android.media.AudioManager;
4344 import java.util.Calendar;
4445 import java.text.DateFormatSymbols;
4546
@@ -67,7 +68,7 @@ public class AlarmClock extends Activity {
6768 private MenuItem mToggleClockItem;
6869 private ListView mAlarmsList;
6970 private Cursor mCursor;
70-
71+ private static boolean volumeAdjustable;
7172 private String mAm, mPm;
7273
7374 /**
@@ -204,7 +205,9 @@ public class AlarmClock extends Activity {
204205 @Override
205206 protected void onCreate(Bundle icicle) {
206207 super.onCreate(icicle);
207-
208+ volumeAdjustable=SystemProperties.getBoolean("ro.alarm.volume.adjustable",false);
209+ AlarmClock.setVolumeControlForPlatform(this);
210+
208211 String[] ampm = new DateFormatSymbols().getAmPmStrings();
209212 mAm = ampm[0];
210213 mPm = ampm[1];
@@ -356,4 +359,15 @@ public class AlarmClock extends Activity {
356359 private void saveClockVisibility() {
357360 mPrefs.edit().putBoolean(PREF_SHOW_CLOCK, getClockVisibility()).commit();
358361 }
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+ }
359373 }
--- a/src/com/android/alarmclock/ClockPicker.java
+++ b/src/com/android/alarmclock/ClockPicker.java
@@ -45,7 +45,7 @@ public class ClockPicker extends Activity implements
4545 public void onCreate(Bundle icicle) {
4646 super.onCreate(icicle);
4747 requestWindowFeature(Window.FEATURE_NO_TITLE);
48-
48+ AlarmClock.setVolumeControlForPlatform(this);
4949 mFactory = LayoutInflater.from(this);
5050 setContentView(R.layout.clockpicker);
5151
--- a/src/com/android/alarmclock/SetAlarm.java
+++ b/src/com/android/alarmclock/SetAlarm.java
@@ -98,7 +98,7 @@ public class SetAlarm extends PreferenceActivity
9898 @Override
9999 protected void onCreate(Bundle icicle) {
100100 super.onCreate(icicle);
101-
101+ AlarmClock.setVolumeControlForPlatform(this);
102102 addPreferencesFromResource(R.xml.alarm_prefs);
103103 mLabel = (EditTextPreference) findPreference("label");
104104 mLabel.setOnPreferenceChangeListener(
@@ -114,6 +114,7 @@ public class SetAlarm extends PreferenceActivity
114114 mTimePref = findPreference("time");
115115 mAlarmPref = (AlarmPreference) findPreference("alarm");
116116 mVibratePref = (CheckBoxPreference) findPreference("vibrate");
117+ mVibratePref.setEnabled(!AlarmClock.isVolumeAdjustable());
117118 mRepeatPref = (RepeatPreference) findPreference("setRepeat");
118119
119120 Intent i = getIntent();
@@ -217,7 +218,7 @@ public class SetAlarm extends PreferenceActivity
217218 mMinutes = minutes;
218219 mAlarmOnPref.setChecked(enabled);
219220 mDaysOfWeek.set(daysOfWeek);
220- mVibratePref.setChecked(vibrate);
221+ mVibratePref.setChecked(vibrate && !AlarmClock.isVolumeAdjustable());
221222
222223 if (alert == null || alert.length() == 0) {
223224 if (Log.LOGV) Log.v("****** reportAlarm null or 0-length alert");
@@ -276,12 +277,18 @@ public class SetAlarm extends PreferenceActivity
276277 * contain the old value (i.e. during the preference value change).
277278 */
278279 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+ }
285292 }
286293
287294 /**
--- a/src/com/android/alarmclock/SettingsActivity.java
+++ b/src/com/android/alarmclock/SettingsActivity.java
@@ -39,7 +39,7 @@ public class SettingsActivity extends PreferenceActivity {
3939 @Override
4040 protected void onCreate(Bundle savedInstanceState) {
4141 super.onCreate(savedInstanceState);
42-
42+ AlarmClock.setVolumeControlForPlatform(this);
4343 addPreferencesFromResource(R.xml.settings);
4444
4545 mAlarmInSilentModePref =
Show on old repository browser