|
|
@ -38,7 +38,10 @@ import net.micode.notes.data.Notes;
|
|
|
|
import net.micode.notes.tool.DataUtils;
|
|
|
|
import net.micode.notes.tool.DataUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
author:刘瑞轩
|
|
|
|
|
|
|
|
日期:2023-4-12
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
|
|
|
|
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
|
|
|
|
private long mNoteId;
|
|
|
|
private long mNoteId;
|
|
|
@ -48,23 +51,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//在锁定状态下唤醒屏幕。如果该标志被设置,则当 Activity 启动时,系统将唤醒设备并点亮屏幕。
|
|
|
|
| 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 = getIntent();//获取页面
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1));
|
|
|
|
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1));//
|
|
|
|
mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);
|
|
|
|
mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);
|
|
|
|
mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0,
|
|
|
|
mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0,
|
|
|
|
SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info)
|
|
|
|
SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info)
|
|
|
@ -89,11 +92,12 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void playAlarmSound() {
|
|
|
|
private void playAlarmSound() {
|
|
|
|
|
|
|
|
//获取系统中当前默认的闹钟铃声所对应的 Uri,并将其赋值给 url 变量
|
|
|
|
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
|
|
|
|
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
|
|
|
|
|
|
|
|
//获取当前系统中哪些音频流会受到静音模式的影响
|
|
|
|
int silentModeStreams = Settings.System.getInt(getContentResolver(),
|
|
|
|
int silentModeStreams = Settings.System.getInt(getContentResolver(),
|
|
|
|
Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
|
|
|
|
Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
|
|
|
|
|
|
|
|
//如果STREAM_ALARM受到影响,那么就将音频流形式设置为silentModeStreams
|
|
|
|
if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) {
|
|
|
|
if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) {
|
|
|
|
mPlayer.setAudioStreamType(silentModeStreams);
|
|
|
|
mPlayer.setAudioStreamType(silentModeStreams);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -101,7 +105,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
mPlayer.setDataSource(this, url);
|
|
|
|
mPlayer.setDataSource(this, url);
|
|
|
|
mPlayer.prepare();
|
|
|
|
mPlayer.prepare();//于为音频播放做一些准备工作。具体来说,该方法会解析音频数据、分离音频轨道、获取音频格式信息等操作
|
|
|
|
mPlayer.setLooping(true);
|
|
|
|
mPlayer.setLooping(true);
|
|
|
|
mPlayer.start();
|
|
|
|
mPlayer.start();
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
@ -121,22 +125,22 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
|
|
|
|
|
|
|
|
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.setAction(Intent.ACTION_VIEW);
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);//显示页面
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, mNoteId);
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, mNoteId);//放入对应的数据库中
|
|
|
|
startActivity(intent);
|
|
|
|
startActivity(intent);//运行该页面
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -144,14 +148,14 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
stopAlarmSound();
|
|
|
|
stopAlarmSound();//关闭闹钟铃声
|
|
|
|
finish();
|
|
|
|
finish();//该页面结束
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void stopAlarmSound() {
|
|
|
|
private void stopAlarmSound() {
|
|
|
|
if (mPlayer != null) {
|
|
|
|
if (mPlayer != null) {//如果该播放器存在
|
|
|
|
mPlayer.stop();
|
|
|
|
mPlayer.stop();//停下
|
|
|
|
mPlayer.release();
|
|
|
|
mPlayer.release();//释放资源
|
|
|
|
mPlayer = null;
|
|
|
|
mPlayer = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|