|
|
@ -116,43 +116,39 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
|
|
|
|
mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
mPlayer.setDataSource(this, url);// 设置媒体放器的数据源为闹钟铃声的URI
|
|
|
|
mPlayer.setDataSource(this, url); // 设置媒体放器的数据源为闹钟铃声的URI
|
|
|
|
mPlayer.prepare();
|
|
|
|
mPlayer.prepare(); // 准备异步播放
|
|
|
|
mPlayer.setLooping(true);
|
|
|
|
mPlayer.setLooping(true); // 设置循环播放
|
|
|
|
mPlayer.start();
|
|
|
|
mPlayer.start(); // 开始播放
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
} catch (IllegalArgumentException e) { // 处理参数异常
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (SecurityException e) {
|
|
|
|
} catch (SecurityException e) { // 处理安全异常
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
} catch (IllegalStateException e) { // 处理状态异常
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) { // 处理IO异常
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void showActionDialog() {
|
|
|
|
private void showActionDialog() {
|
|
|
|
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
|
|
|
|
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
|
|
|
|
dialog.setTitle(R.string.app_name);
|
|
|
|
dialog.setTitle(R.string.app_name); // 设置对话框标题
|
|
|
|
dialog.setMessage(mSnippet);
|
|
|
|
dialog.setMessage(mSnippet); // 设置对话框消息内容
|
|
|
|
dialog.setPositiveButton(R.string.notealert_ok, this);
|
|
|
|
dialog.setPositiveButton(R.string.notealert_ok, this); // 设置对话框的确定按钮和点击事件
|
|
|
|
if (isScreenOn()) {
|
|
|
|
if (isScreenOn()) { // 判断屏幕是否亮屏
|
|
|
|
dialog.setNegativeButton(R.string.notealert_enter, this);
|
|
|
|
dialog.setNegativeButton(R.string.notealert_enter, this); // 设置对话框的取消按钮和点击事件
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dialog.show().setOnDismissListener(this);
|
|
|
|
dialog.show().setOnDismissListener(this); // 显示对话框,并设置对话框消失时的监听器
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
switch (which) {
|
|
|
|
switch (which) {
|
|
|
|
case DialogInterface.BUTTON_NEGATIVE:
|
|
|
|
case DialogInterface.BUTTON_NEGATIVE:
|
|
|
|
Intent intent = new Intent(this, NoteEditActivity.class);
|
|
|
|
Intent intent = new Intent(this, NoteEditActivity.class); // 创建一个Intent对象,跳转到NoteEditActivity
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
intent.setAction(Intent.ACTION_VIEW); // 设置Intent的操作为查看操作
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, mNoteId);
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, mNoteId); // 设置Intent的额外数据
|
|
|
|
startActivity(intent);
|
|
|
|
startActivity(intent); // 启动Activity
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -160,15 +156,14 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
stopAlarmSound();
|
|
|
|
stopAlarmSound(); // 停止播放铃声
|
|
|
|
finish();
|
|
|
|
finish(); // 结束当前Activity
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void stopAlarmSound() {
|
|
|
|
private void stopAlarmSound() {
|
|
|
|
if (mPlayer != null) {
|
|
|
|
if (mPlayer != null) {
|
|
|
|
mPlayer.stop();
|
|
|
|
mPlayer.stop(); // 停止播放
|
|
|
|
mPlayer.release();
|
|
|
|
mPlayer.release(); // 释放资源
|
|
|
|
mPlayer = null;
|
|
|
|
mPlayer = null; // 置空
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|