Skip to content

Commit

Permalink
fix bug that alarm does not work when malarm is destroyed before wakeup
Browse files Browse the repository at this point in the history
time
correct toggle button state
  • Loading branch information
mamewotoko committed Nov 8, 2011
1 parent 0b27ed2 commit 6b9686e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
8 changes: 3 additions & 5 deletions README.md
Expand Up @@ -35,16 +35,14 @@ or Build malarm and install it on android device
- add help?
- restart music after phone call ends
- preset volume of sleep / wakeup mode
- raise wakeup volume by timer
- raise wakeup volume by timer or thread
- record wakeup time
- fix vibration bug (onNewIntent is called after unlocking device?)
- switch web page by gesture (2 finger) or horizontal scroll bar?
- add UI to edit playlist
- use au music player?
- make COOL widget to set alarm
- add option not to play sleep music?
- make COOL widget to set alarm (make clock widget?)
- add stop music into resource?
- change vibration timing
- fix vibration bug (onNewIntent is called after unlocking device?)
- implement more smart scroll
- link to music store (where?)

Expand Down
7 changes: 4 additions & 3 deletions src/com/mamewo/malarm/M3UPlaylist.java
Expand Up @@ -6,6 +6,8 @@
import java.io.IOException;
import java.util.Vector;

import android.util.Log;

/**
* @author Takashi Masuyama <mamewotoko@gmail.com>
*/
Expand All @@ -25,10 +27,9 @@ public M3UPlaylist(String basepath, String playlist_filename) {
_playlist = new Vector<String>();
loadPlaylist(_basepath + playlist_filename);
} catch (FileNotFoundException e) {
//TODO: set default playlist?
e.printStackTrace();
Log.i("M3UPlaylist", "cannot find playlist " + playlist_filename);
} catch (IOException e) {
//TODO: set default playlist?
Log.i("M3UPlaylist", "cannot read playlist " + playlist_filename);
e.printStackTrace();
}
}
Expand Down
52 changes: 39 additions & 13 deletions src/com/mamewo/malarm/MalarmActivity.java
Expand Up @@ -26,7 +26,6 @@
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Vibrator;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
Expand Down Expand Up @@ -72,8 +71,11 @@ public class MalarmActivity extends Activity implements OnClickListener, OnShare
public static class MalarmState implements Serializable {
private static final long serialVersionUID = 1L;
public Calendar _target;
public boolean _suspending;

public MalarmState(Calendar target) {
_target = target;
_suspending = false;
}
}

Expand All @@ -87,7 +89,7 @@ public MalarmState(Calendar target) {
private TextView _time_label;
private WebView _webview;
// private WebView _subwebview;
private Button _alarm_button;
private ToggleButton _alarm_button;

@SuppressWarnings("unused")
private PhoneStateListener _calllistener;
Expand All @@ -107,22 +109,27 @@ public MalarmState(Calendar target) {
};

public class MyCallListener extends PhoneStateListener {
MalarmActivity _activity;
private MalarmActivity _activity;

public MyCallListener(MalarmActivity context) {
_activity = context;
TelephonyManager telmgr = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
telmgr.listen(this, LISTEN_CALL_STATE);
}

public void onCallStateChanged (int state, String incomingNumber) {
//TODO: restart music when phone call is killed?
//TODO: save cursor and play
if (state == TelephonyManager.CALL_STATE_RINGING) {
Log.i(PACKAGE_NAME, "onCallStateChanged: RINGING");
//stop vibration
if (_vibrator != null) {
_vibrator.cancel();
}
//native player is OK
Player.stopMusic();
if (Player.isPlaying()) {
//pause
Player.pauseMusic();
}
}
}
}
Expand Down Expand Up @@ -156,7 +163,7 @@ public void onCreate(Bundle savedInstanceState) {
_time_label = (TextView) findViewById(R.id.target_time_label);
_webview = (WebView)findViewById(R.id.webView1);
// _subwebview = new WebView(this);
_alarm_button = (Button)findViewById(R.id.alarm_button);
_alarm_button = (ToggleButton)findViewById(R.id.alarm_button);
_alarm_button.setOnClickListener(this);
WebSettings config = _webview.getSettings();
//to display twitter...
Expand Down Expand Up @@ -293,7 +300,7 @@ protected void onStart () {
if (_state != null) {
updateAlarmUI(_state._target);
}

_alarm_button.setChecked(_state != null);
_alarm_button.requestFocus();
}

Expand All @@ -315,7 +322,6 @@ protected void onSaveInstanceState(Bundle outState) {

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
//TODO: show value when url and sleeptime is changed
if (key.equals("use_native_player")) {
_PREF_USE_NATIVE_PLAYER = sharedPreferences.getBoolean(key, false);
} else if (key.equals("vibrate")) {
Expand Down Expand Up @@ -369,8 +375,10 @@ private void cancelAlarm () {
protected void onNewIntent (Intent intent) {
String action = intent.getAction();
if (action != null && action.equals(WAKEUPAPP_ACTION)) {
//native player cannot start until lock screen is displayed
Player.playWakeupMusic(this, false);
if (_PREF_VIBRATE && _vibrator != null) {
long pattern[] = { 10, 2000, 500, 1500, 1000, 2000 };
long pattern[] = { 10, 2000, 500, 2000, 500 };
_vibrator.vibrate(pattern, 1);
}
}
Expand Down Expand Up @@ -547,9 +555,6 @@ public void onReceive(Context context, Intent intent) {
i.setAction(WAKEUPAPP_ACTION);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);

//native player cannot start until lock screen is displayed
Player.playWakeupMusic(context, false);
} else if (intent.getAction().equals(SLEEP_ACTION)) {
if (intent.getExtras().getBoolean(_NATIVE_PLAYER_KEY)) {
Player.stopMusicNativePlayer(context);
Expand Down Expand Up @@ -635,7 +640,7 @@ public boolean onError(MediaPlayer mp, int what, int extra) {

public static void playMusic(Playlist playlist) {
current_playlist = playlist;
Log.i(PACKAGE_NAME, "startMusic");
Log.i(PACKAGE_NAME, "playMusic");
if (playlist == null || playlist.isEmpty()) {
Log.i(PACKAGE_NAME, "playMusic: playlist is null");
return;
Expand Down Expand Up @@ -669,5 +674,26 @@ public static void playMusic(Playlist playlist) {
//do nothing
}
}

public static void playMusic() {
Log.i(PACKAGE_NAME, "playMusic (from pause) is called");
if (current_playlist == null) {
return;
}
try {
_player.start();
} catch (Exception e) {

}
}

public static void pauseMusic() {
Log.i(PACKAGE_NAME, "pause music is called");
try {
_player.pause();
} catch (Exception e) {

}
}
}
}
1 change: 0 additions & 1 deletion src/com/mamewo/malarm/MyPreference.java
Expand Up @@ -8,7 +8,6 @@

import android.os.Bundle;
import android.preference.*;
import android.util.Log;

public class MyPreference extends PreferenceActivity {
@Override
Expand Down

0 comments on commit 6b9686e

Please sign in to comment.