diff --git a/app/src/main/java/net/micode/notes/ui/activities/AlarmAlertActivity.java b/app/src/main/java/net/micode/notes/ui/activities/AlarmAlertActivity.java index ae50b19..64bd8c7 100644 --- a/app/src/main/java/net/micode/notes/ui/activities/AlarmAlertActivity.java +++ b/app/src/main/java/net/micode/notes/ui/activities/AlarmAlertActivity.java @@ -43,8 +43,17 @@ import java.io.IOException; * 闹钟应用活动类 */ public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener { + /** + * 便签ID + */ private long mNoteId; + /** + * 片段 + */ private String mSnippet; + /** + * 片段前缀最长长度 + */ private static final int SNIPPET_PREW_MAX_LEN = 60; MediaPlayer mPlayer; @@ -67,22 +76,28 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR); } + //定义意图对象,调用系统应用 Intent intent = getIntent(); try { + // 便签ID mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1)); + // 片段名称 mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId); mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0, SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info) : mSnippet; } catch (IllegalArgumentException e) { + // 异常处理 e.printStackTrace(); return; } mPlayer = new MediaPlayer(); if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) { + // 显示弹出窗口 showActionDialog(); + // 播放提示音 playAlarmSound(); } else { finish(); @@ -137,12 +152,18 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD */ private void showActionDialog() { AlertDialog.Builder dialog = new AlertDialog.Builder(this); + // 设置标题 dialog.setTitle(R.string.app_name); + // 设置消息 dialog.setMessage(mSnippet); + // 设置按钮 dialog.setPositiveButton(R.string.notealert_ok, this); + // 判断屏幕状态是否正常 if (isScreenOn()) { + // 设置导航按钮 dialog.setNegativeButton(R.string.notealert_enter, this); } + // 展示弹窗并绑定监听器 dialog.show().setOnDismissListener(this); }