|
|
|
@ -39,13 +39,19 @@ import net.micode.notes.tool.DataUtils;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 闹钟应用活动类
|
|
|
|
|
*/
|
|
|
|
|
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
|
|
|
|
|
private long mNoteId;
|
|
|
|
|
private String mSnippet;
|
|
|
|
|
private static final int SNIPPET_PREW_MAX_LEN = 60;
|
|
|
|
|
MediaPlayer mPlayer;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onCreate 生命周期方法
|
|
|
|
|
* @param savedInstanceState 之前保存的实例状态
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
@ -83,11 +89,18 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 屏幕是否开着
|
|
|
|
|
* @return 状态
|
|
|
|
|
*/
|
|
|
|
|
private boolean isScreenOn() {
|
|
|
|
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
|
|
|
|
return pm.isScreenOn();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 播放闹钟提示音
|
|
|
|
|
*/
|
|
|
|
|
private void playAlarmSound() {
|
|
|
|
|
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
|
|
|
|
|
|
|
|
|
@ -119,6 +132,9 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示操作弹窗
|
|
|
|
|
*/
|
|
|
|
|
private void showActionDialog() {
|
|
|
|
|
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
|
|
|
|
|
dialog.setTitle(R.string.app_name);
|
|
|
|
@ -130,6 +146,11 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
|
dialog.show().setOnDismissListener(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 在点击时调用该时间
|
|
|
|
|
* @param dialog 弹窗接口
|
|
|
|
|
* @param which 接口类型
|
|
|
|
|
*/
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
switch (which) {
|
|
|
|
|
case DialogInterface.BUTTON_NEGATIVE:
|
|
|
|
@ -143,11 +164,18 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 在活动停止调用,停止播放闹钟声音
|
|
|
|
|
* @param dialog
|
|
|
|
|
*/
|
|
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
|
stopAlarmSound();
|
|
|
|
|
finish();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 停止播放闹钟声音
|
|
|
|
|
*/
|
|
|
|
|
private void stopAlarmSound() {
|
|
|
|
|
if (mPlayer != null) {
|
|
|
|
|
mPlayer.stop();
|
|
|
|
|