孙永霖_branch
syl 1 year ago
parent 46626096f5
commit 62f00cbff3

@ -56,7 +56,8 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); // 设置当前Activity的Window对象的属性使其在锁定状态时保持常亮 win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); // 设置当前Activity的Window对象的属性使其在锁定状态时保持常亮
if (!isScreenOn()) { // 判断当前屏幕是否处于锁定状态 if (!isScreenOn()) { // 判断当前屏幕是否处于锁定状态
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON // 如果当前屏幕处于锁定状态则设置当前Activity的Window对象的属性使其在锁定状态时保持常亮并允许锁定屏幕 win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON // 如果当前屏幕处于锁定状态,
//则设置当前Activity的Window对象的属性使其在锁定状态时保持常亮并允许锁定屏幕
| 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);
@ -77,7 +78,9 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
mPlayer = new MediaPlayer(); // 初始化mPlayer mPlayer = new MediaPlayer(); // 初始化mPlayer
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) { // 判断mNoteId对应的Notes表中的TYPE_NOTE字段是否可见
// 判断mNoteId对应的Notes表中的TYPE_NOTE字段是否可见
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
showActionDialog(); // 如果可见则显示ActionDialog showActionDialog(); // 如果可见则显示ActionDialog
playAlarmSound(); // 播放闹钟音效 playAlarmSound(); // 播放闹钟音效
} else { } else {
@ -88,7 +91,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
private boolean isScreenOn() { // 判断当前屏幕是否处于锁定状态 private boolean isScreenOn() { // 判断当前屏幕是否处于锁定状态
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); // 获取当前系统的PowerManager实例 PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); // 获取当前系统的PowerManager实例
return pm.isScreenOn(); // 判断当前屏幕是否处于锁定状态 return pm.isScreenOn(); // 返回当前屏幕锁定状态
} }
@ -104,6 +107,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); // 如果不包含则设置mPlayer的音频流类型为AudioManager.STREAM_ALARM mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); // 如果不包含则设置mPlayer的音频流类型为AudioManager.STREAM_ALARM
} }
try { try {
mPlayer.setDataSource(this, url); // 设置mPlayer的数据源 mPlayer.setDataSource(this, url); // 设置mPlayer的数据源
mPlayer.prepare(); // 准备播放 mPlayer.prepare(); // 准备播放
mPlayer.setLooping(true); // 设置mPlayer循环播放 mPlayer.setLooping(true); // 设置mPlayer循环播放
@ -125,7 +129,9 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
private void showActionDialog() { // 显示ActionDialog private void showActionDialog() { // 显示ActionDialog
AlertDialog.Builder dialog = new AlertDialog.Builder(this); // 创建一个AlertDialog.Builder实例 AlertDialog.Builder dialog = new AlertDialog.Builder(this); // 创建一个AlertDialog.Builder实例
dialog.setTitle(R.string.app_name); // 设置AlertDialog的标题 dialog.setTitle(R.string.app_name); // 设置AlertDialog的标题
dialog.setMessage(mSnippet); // 设置AlertDialog的消息 dialog.setMessage(mSnippet); // 设置AlertDialog的消息
dialog.setPositiveButton(R.string.notealert_ok, this); // 设置AlertDialog的确定按钮 dialog.setPositiveButton(R.string.notealert_ok, this); // 设置AlertDialog的确定按钮

@ -20,12 +20,13 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
// 创建一个AlarmReceiver类继承自BroadcastReceiver在接收到特定广播时启动 AlarmAlertActivity 活动。
public class AlarmReceiver extends BroadcastReceiver { // 创建一个AlarmReceiver类继承自BroadcastReceiver public class AlarmReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { // 重写onReceive方法接收Intent类型的参数 // 重写onReceive方法接收Intent类型的参数
intent.setClass(context, AlarmAlertActivity.class); // 设置AlarmAlertActivity的Class public void onReceive(Context context, Intent intent) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 设置AlarmAlertActivity的Flag intent.setClass(context, AlarmAlertActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent); // 启动AlarmAlertActivity context.startActivity(intent); // 启动AlarmAlertActivity
} }
} }

@ -165,7 +165,7 @@ private NumberPicker.OnValueChangeListener mOnDateChangedListener = new NumberPi
}; };
public interface OnDateTimeChangedListener { // 添加中文注释后 public interface OnDateTimeChangedListener {
void onDateTimeChanged(DateTimePicker view, int year, int month, // 当时间改变时调用 void onDateTimeChanged(DateTimePicker view, int year, int month, // 当时间改变时调用
int dayOfMonth, int hourOfDay, int minute); int dayOfMonth, int hourOfDay, int minute);

Loading…
Cancel
Save