Skip to content

Commit

Permalink
set default alarm time in onNewIntent
Browse files Browse the repository at this point in the history
  • Loading branch information
mamewotoko committed Aug 21, 2011
1 parent 0d205c6 commit 50b1dbc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
16 changes: 11 additions & 5 deletions Hello/README.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
* What is this?

This is a sample application of android (version 2.3.3).
This is a simple alarm application of android (version 2.3.3).

OVERVIEW
sleep music (1h) wakeup music w/ vibration
Alarm set ------------------> ..... Alarm time --------------->

HOW TO RUN:
1. Rename Playlist_tmpl.java into Playlist.java.
Expand All @@ -17,12 +21,14 @@ After set/stop alarm button
* TODO:
- editable playlist support
-- add favorite music
- implement music player as Service to play long time
- preset volume of sleep / wakeup mode.
- add tweet button of now playing
- link to music store?
- add license file of this source
- fix vibration bug (related to intent handling)
- fix multiple application instance bug
- fix vibration bug (onNewIntent is called after unlocking device?)

* FUTURE WORK:
- add tweet button of now playing
- link to music store

----
Takashi Masuyama <mamewotoko@gmail.com>
Expand Down
8 changes: 6 additions & 2 deletions Hello/src/com/mamewo/hello/HelloActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ protected void onStart () {

protected void onNewIntent (Intent intent) {
String action = intent.getAction();
if (_time_picker.isEnabled()) {
_time_picker.setCurrentHour(DEFAULT_HOUR);
_time_picker.setCurrentMinute(DEFAULT_MIN);
}
if (action != null && action.equals(WAKEUPAPP_ACTION)) {
if (_vibrator != null) {
long pattern[] = { 10, 2000, 500, 1500, 1000, 2000 };
Expand Down Expand Up @@ -202,14 +206,13 @@ public void scheduleToPlaylist() {
}
//TODO: make function
_time_picker.setEnabled(false);
//TODO: localize date format?
_time_label.setText(String.format("%2d/%2d %02d:%02d", target.get(Calendar.MONTH)+1, target.get(Calendar.DATE), target_hour, target_min));
AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = makePintent(WAKEUP_ACTION);
mgr.set(AlarmManager.RTC_WAKEUP, target_millis, pendingIntent);
showMessage(this, getString(R.string.alarm_set) + tommorow);
Player.startSleepMusic();
//TODO: fix design...

if (target_millis - now_millis >= SLEEP_TIME) {
pendingIntent = makePintent(SLEEP_ACTION);
mgr.set(AlarmManager.RTC_WAKEUP, now_millis+SLEEP_TIME, pendingIntent);
Expand All @@ -230,6 +233,7 @@ private static void showMessage(Context c, String message) {
Toast.makeText(c, message, Toast.LENGTH_LONG).show();
}

//TODO: implement music player as Service to play long time
public static class Player extends BroadcastReceiver {
private static final String MUSIC_PATH = "/sdcard/music/";
private static MediaPlayer _player = null;
Expand Down

0 comments on commit 50b1dbc

Please sign in to comment.