|
|
@ -46,21 +46,23 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
// 设置界面显示——无标题
|
|
|
|
requestWindowFeature(Window.FEATURE_NO_TITLE);//设置界面显示——无标题
|
|
|
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
|
|
|
|
|
|
|
|
|
final Window win = getWindow();
|
|
|
|
final Window win = getWindow();
|
|
|
|
|
|
|
|
// 设置窗体属性——在锁屏时显示
|
|
|
|
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);//设置窗体属性——在锁屏时显示
|
|
|
|
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
|
|
|
|
|
|
|
|
|
|
|
if (!isScreenOn()) {
|
|
|
|
if (!isScreenOn()) {
|
|
|
|
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON//保持点亮、点亮屏幕、允许点亮时解锁
|
|
|
|
// 设置窗体属性——保持点亮、点亮屏幕、允许点亮时解锁
|
|
|
|
|
|
|
|
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
|
|
|
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|
|
|
|
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|
|
|
|
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
|
|
|
|
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
|
|
|
|
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
|
|
|
|
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Intent intent = getIntent();//获取传递的 Intent
|
|
|
|
// 获取传递的 Intent
|
|
|
|
|
|
|
|
Intent intent = getIntent();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 从 Intent 中获取数据并处理——获取标签 ID
|
|
|
|
// 从 Intent 中获取数据并处理——获取标签 ID
|
|
|
@ -78,33 +80,24 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
|
|
|
|
|
|
|
|
mPlayer = new MediaPlayer();
|
|
|
|
mPlayer = new MediaPlayer();
|
|
|
|
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
|
|
|
|
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
|
|
|
|
showActionDialog();// 显示对话框
|
|
|
|
// 显示对话框
|
|
|
|
playAlarmSound();// 播放闹钟提示音
|
|
|
|
showActionDialog();
|
|
|
|
|
|
|
|
// 播放闹钟提示音
|
|
|
|
|
|
|
|
playAlarmSound();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
finish();// 结束当前 Activity
|
|
|
|
// 结束当前 Activity
|
|
|
|
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method isScreenOn
|
|
|
|
|
|
|
|
* @description
|
|
|
|
|
|
|
|
* 判断屏幕是否锁屏,调用系统函数判断,最后返回值是布尔类型
|
|
|
|
|
|
|
|
* @date: 12/23/2023 11:21 PM
|
|
|
|
|
|
|
|
* @author: YangYizhe
|
|
|
|
|
|
|
|
* @param
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private boolean isScreenOn() {
|
|
|
|
private boolean isScreenOn() {
|
|
|
|
|
|
|
|
//判断屏幕是否锁屏,调用系统函数判断,最后返回值是布尔类型
|
|
|
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
|
|
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
|
|
|
return pm.isScreenOn();
|
|
|
|
return pm.isScreenOn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method playAlarmSound
|
|
|
|
|
|
|
|
* @description
|
|
|
|
|
|
|
|
* 播放闹钟提示音
|
|
|
|
|
|
|
|
* @date: 12/23/2023 11:21 PM
|
|
|
|
|
|
|
|
* @author: YangYizhe
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void playAlarmSound() {
|
|
|
|
private void playAlarmSound() {
|
|
|
|
|
|
|
|
//闹钟提示音激发
|
|
|
|
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
|
|
|
|
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
|
|
|
|
//调用系统的铃声管理URI,得到闹钟提示音
|
|
|
|
//调用系统的铃声管理URI,得到闹钟提示音
|
|
|
|
int silentModeStreams = Settings.System.getInt(getContentResolver(),
|
|
|
|
int silentModeStreams = Settings.System.getInt(getContentResolver(),
|
|
|
@ -117,12 +110,19 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
mPlayer.setDataSource(this, url);
|
|
|
|
mPlayer.setDataSource(this, url);
|
|
|
|
|
|
|
|
//方法:setDataSource(Context context, Uri uri)
|
|
|
|
|
|
|
|
//解释:无返回值,设置多媒体数据来源【根据 Uri】
|
|
|
|
mPlayer.prepare();
|
|
|
|
mPlayer.prepare();
|
|
|
|
mPlayer.setLooping(true);//设置是否循环播放
|
|
|
|
//准备同步
|
|
|
|
mPlayer.start();//开始播放
|
|
|
|
mPlayer.setLooping(true);
|
|
|
|
|
|
|
|
//设置是否循环播放
|
|
|
|
|
|
|
|
mPlayer.start();
|
|
|
|
|
|
|
|
//开始播放
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
//e.printStackTrace()函数功能是抛出异常, 还将显示出更深的调用信息
|
|
|
|
|
|
|
|
//System.out.println(e),这个方法打印出异常,并且输出在哪里出现的异常
|
|
|
|
} catch (SecurityException e) {
|
|
|
|
} catch (SecurityException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
@ -134,16 +134,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method showActionDialog
|
|
|
|
|
|
|
|
* @description
|
|
|
|
|
|
|
|
* AlertDialog的构造方法全部是Protected的
|
|
|
|
|
|
|
|
* 所以不能直接通过new一个AlertDialog来创建出一个AlertDialog。
|
|
|
|
|
|
|
|
* 要创建一个AlertDialog,就要用到AlertDialog.Builder中的create()方法
|
|
|
|
|
|
|
|
* 如这里的dialog就是新建了一个AlertDialog
|
|
|
|
|
|
|
|
* @date: 12/23/2023 11:28 PM
|
|
|
|
|
|
|
|
* @author: YangYizhe
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void showActionDialog() {
|
|
|
|
private void showActionDialog() {
|
|
|
|
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
|
|
|
|
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
|
|
|
|
/* AlertDialog的构造方法全部是Protected的
|
|
|
|
/* AlertDialog的构造方法全部是Protected的
|
|
|
@ -151,55 +142,53 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
* 要创建一个AlertDialog,就要用到AlertDialog.Builder中的create()方法
|
|
|
|
* 要创建一个AlertDialog,就要用到AlertDialog.Builder中的create()方法
|
|
|
|
* 如这里的dialog就是新建了一个AlertDialog
|
|
|
|
* 如这里的dialog就是新建了一个AlertDialog
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
dialog.setTitle(R.string.app_name);//为对话框设置标题
|
|
|
|
dialog.setTitle(R.string.app_name);
|
|
|
|
dialog.setMessage(mSnippet);//为对话框设置内容
|
|
|
|
//为对话框设置标题
|
|
|
|
dialog.setPositiveButton(R.string.notealert_ok, this);//给对话框添加"Yes"按钮
|
|
|
|
dialog.setMessage(mSnippet);
|
|
|
|
|
|
|
|
//为对话框设置内容
|
|
|
|
|
|
|
|
dialog.setPositiveButton(R.string.notealert_ok, this);
|
|
|
|
|
|
|
|
//给对话框添加"Yes"按钮
|
|
|
|
if (isScreenOn()) {
|
|
|
|
if (isScreenOn()) {
|
|
|
|
dialog.setNegativeButton(R.string.notealert_enter, this);//对话框添加"No"按钮
|
|
|
|
dialog.setNegativeButton(R.string.notealert_enter, this);
|
|
|
|
}
|
|
|
|
}//对话框添加"No"按钮
|
|
|
|
dialog.show().setOnDismissListener(this);
|
|
|
|
dialog.show().setOnDismissListener(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method onClick
|
|
|
|
|
|
|
|
* @description 处理点击事件
|
|
|
|
|
|
|
|
* @date: 12/23/2023 11:27 PM
|
|
|
|
|
|
|
|
* @author: YangYizhe
|
|
|
|
|
|
|
|
* @param dialog
|
|
|
|
|
|
|
|
* @param which
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
switch (which) {//用which来选择click后下一步的操作
|
|
|
|
switch (which) {
|
|
|
|
case DialogInterface.BUTTON_NEGATIVE://这是取消操作
|
|
|
|
//用which来选择click后下一步的操作
|
|
|
|
Intent intent = new Intent(this, NoteEditActivity.class);//实现两个类间的数据传输
|
|
|
|
case DialogInterface.BUTTON_NEGATIVE:
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);//设置动作属性
|
|
|
|
//这是取消操作
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, mNoteId);//实现key-value对 EXTRA_UID为key;mNoteId为键
|
|
|
|
Intent intent = new Intent(this, NoteEditActivity.class);
|
|
|
|
startActivity(intent);//开始动作
|
|
|
|
//实现两个类间的数据传输
|
|
|
|
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
|
|
|
|
//设置动作属性
|
|
|
|
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, mNoteId);
|
|
|
|
|
|
|
|
//实现key-value对
|
|
|
|
|
|
|
|
//EXTRA_UID为key;mNoteId为键
|
|
|
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
//开始动作
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
|
|
|
|
//这是确定操作
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method onDismiss
|
|
|
|
|
|
|
|
* @description 忽略
|
|
|
|
|
|
|
|
* @date: 12/23/2023 11:25 PM
|
|
|
|
|
|
|
|
* @author: YangYizhe
|
|
|
|
|
|
|
|
* @param dialog
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
stopAlarmSound();//停止闹钟声音
|
|
|
|
//忽略
|
|
|
|
|
|
|
|
stopAlarmSound();
|
|
|
|
|
|
|
|
//停止闹钟声音
|
|
|
|
finish();
|
|
|
|
finish();
|
|
|
|
|
|
|
|
//完成该动作
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method stopAlarmSound
|
|
|
|
|
|
|
|
* @description 停止闹钟的声音
|
|
|
|
|
|
|
|
* @date: 12/23/2023 11:26 PM
|
|
|
|
|
|
|
|
* @author: YangYizhe
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void stopAlarmSound() {
|
|
|
|
private void stopAlarmSound() {
|
|
|
|
if (mPlayer != null) {
|
|
|
|
if (mPlayer != null) {
|
|
|
|
mPlayer.stop();//停止播放
|
|
|
|
mPlayer.stop();
|
|
|
|
mPlayer.release();//释放MediaPlayer对象
|
|
|
|
//停止播放
|
|
|
|
|
|
|
|
mPlayer.release();
|
|
|
|
|
|
|
|
//释放MediaPlayer对象
|
|
|
|
mPlayer = null;
|
|
|
|
mPlayer = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|