Compare commits
26 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
afba2965bf | 1 year ago |
|
|
82067486b4 | 1 year ago |
|
|
d31c4123fe | 1 year ago |
|
|
a7be0d57d5 | 1 year ago |
|
|
dc04031594 | 1 year ago |
|
|
04c54f9755 | 1 year ago |
|
|
2d0faea545 | 1 year ago |
|
|
ab8b156676 | 1 year ago |
|
|
dd62ce091c | 1 year ago |
|
|
742f3d8075 | 1 year ago |
|
|
43969bd7ee | 1 year ago |
|
|
0f46545651 | 1 year ago |
|
|
2f299132f0 | 1 year ago |
|
|
3fbfe0199e | 1 year ago |
|
|
deacd8ddce | 1 year ago |
|
|
ec16c1882d | 1 year ago |
|
|
9289dd03a6 | 1 year ago |
|
|
fda339a03a | 1 year ago |
|
|
2a9b55d05d | 1 year ago |
|
|
def43e495e | 1 year ago |
|
|
5f14a22bde | 1 year ago |
|
|
4110a39314 | 1 year ago |
|
|
b1537a7c87 | 1 year ago |
|
|
845559535f | 1 year ago |
|
|
461db7931b | 1 year ago |
|
|
6d748c7e51 | 1 year ago |
@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.micode.notes.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import net.micode.notes.R;
|
||||
import net.micode.notes.data.Notes;
|
||||
import net.micode.notes.tool.DataUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
// AlarmAlertActivity 是一个用于显示便签提醒的 Activity。
|
||||
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
|
||||
private long mNoteId; // 便签的ID。
|
||||
private String mSnippet; // 便签的预览文本。
|
||||
private static final int SNIPPET_PREW_MAX_LEN = 60; // 预览文本的最大长度。
|
||||
MediaPlayer mPlayer; // 用于播放提醒声音的 MediaPlayer。
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE); // 请求无标题栏的窗口特性。
|
||||
|
||||
final Window win = getWindow();
|
||||
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); // 锁屏时显示窗口。
|
||||
|
||||
if (!isScreenOn()) {
|
||||
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
||||
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|
||||
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
|
||||
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR); // 屏幕关闭时点亮屏幕。
|
||||
}
|
||||
|
||||
Intent intent = getIntent(); // 获取启动该 Activity 的 Intent。
|
||||
|
||||
try {
|
||||
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1)); // 从 Intent 中获取便签 ID。
|
||||
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(); // 初始化 MediaPlayer。
|
||||
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
|
||||
showActionDialog(); // 显示操作对话框。
|
||||
playAlarmSound(); // 播放提醒声音。
|
||||
} else {
|
||||
finish(); // 如果便签不可见,则结束 Activity。
|
||||
}
|
||||
}
|
||||
|
||||
// 检查屏幕是否开启。
|
||||
private boolean isScreenOn() {
|
||||
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
return pm.isScreenOn();
|
||||
}
|
||||
|
||||
// 播放提醒声音。
|
||||
private void playAlarmSound() {
|
||||
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
|
||||
int silentModeStreams = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
|
||||
|
||||
if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) {
|
||||
mPlayer.setAudioStreamType(silentModeStreams);
|
||||
} else {
|
||||
mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
|
||||
}
|
||||
try {
|
||||
mPlayer.setDataSource(this, url);
|
||||
mPlayer.prepare();
|
||||
mPlayer.setLooping(true);
|
||||
mPlayer.start();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalStateException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 显示操作对话框。
|
||||
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);
|
||||
}
|
||||
|
||||
// DialogInterface.OnClickListener 的实现,处理对话框按钮点击事件。
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_NEGATIVE:
|
||||
Intent intent = new Intent(this, NoteEditActivity.class);
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.putExtra(Intent.EXTRA_UID, mNoteId);
|
||||
startActivity(intent);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// DialogInterface.OnDismissListener 的实现,处理对话框消失事件。
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
stopAlarmSound();
|
||||
finish();
|
||||
}
|
||||
|
||||
// 停止提醒声音。
|
||||
private void stopAlarmSound() {
|
||||
if (mPlayer != null) {
|
||||
mPlayer.stop();
|
||||
mPlayer.release();
|
||||
mPlayer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.micode.notes.tool; // 包声明,表示该类位于 net.micode.notes.tool 包中
|
||||
|
||||
// 定义 GTaskStringUtils 类,用于管理 Google Tasks 或类似任务相关的常量字符串
|
||||
public class GTaskStringUtils {
|
||||
|
||||
// 这些常量字符串用于表示任务数据的各个字段名
|
||||
|
||||
// Action ID
|
||||
public final static String GTASK_JSON_ACTION_ID = "action_id"; // "action_id" 用于表示任务的操作标识符
|
||||
|
||||
// 操作列表
|
||||
public final static String GTASK_JSON_ACTION_LIST = "action_list"; // "action_list" 用于表示操作列表
|
||||
|
||||
// 操作类型
|
||||
public final static String GTASK_JSON_ACTION_TYPE = "action_type"; // "action_type" 用于表示操作的类型
|
||||
|
||||
// 创建操作类型
|
||||
public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; // "create" 表示创建操作
|
||||
|
||||
// 获取所有操作类型
|
||||
public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; // "get_all" 表示获取所有操作
|
||||
|
||||
// 移动操作类型
|
||||
public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; // "move" 表示移动操作
|
||||
|
||||
// 更新操作类型
|
||||
public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; // "update" 表示更新操作
|
||||
|
||||
// 创建者ID
|
||||
public final static String GTASK_JSON_CREATOR_ID = "creator_id"; // "creator_id" 表示任务创建者的ID
|
||||
|
||||
// 子实体
|
||||
public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; // "child_entity" 用于表示子实体
|
||||
|
||||
// 客户端版本
|
||||
public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; // "client_version" 表示客户端的版本
|
||||
|
||||
// 任务是否完成
|
||||
public final static String GTASK_JSON_COMPLETED = "completed"; // "completed" 表示任务是否完成
|
||||
|
||||
// 当前列表ID
|
||||
public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; // "current_list_id" 表示当前任务列表的ID
|
||||
|
||||
// 默认列表ID
|
||||
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; // "default_list_id" 表示默认任务列表的ID
|
||||
|
||||
// 是否删除
|
||||
public final static String GTASK_JSON_DELETED = "deleted"; // "deleted" 表示任务是否被删除
|
||||
|
||||
// 目标列表
|
||||
public final static String GTASK_JSON_DEST_LIST = "dest_list"; // "dest_list" 表示目标任务列表
|
||||
|
||||
// 目标父级任务
|
||||
public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; // "dest_parent" 表示目标任务的父级任务
|
||||
|
||||
// 目标父级类型
|
||||
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; // "dest_parent_type" 表示目标父级任务的类型
|
||||
|
||||
// 实体增量
|
||||
public final static String GTASK_JSON_ENTITY_DELTA = "entity"; // "entity" 表示实体数据的增量部分
|
||||
|
||||
// 实体类型
|
||||
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; // "entity_type" 用于表示实体类型(任务、列表等)
|
||||
|
||||
// 获取已删除任务
|
||||
public final static String GTASK_JSON_GET_DELETED = "get_deleted"; // "get_deleted" 表示获取已删除的任务
|
||||
|
||||
// 任务ID
|
||||
public final static String GTASK_JSON_ID = "id"; // "id" 用于表示任务的唯一标识符
|
||||
|
||||
// 任务索引
|
||||
public final static String GTASK_JSON_INDEX = "index"; // "index" 用于表示任务的索引位置
|
||||
|
||||
// 最后修改时间
|
||||
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; // "last_modified" 用于表示任务的最后修改时间
|
||||
|
||||
// 最新同步点
|
||||
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; // "latest_sync_point" 表示任务的最新同步点
|
||||
|
||||
// 列表ID
|
||||
public final static String GTASK_JSON_LIST_ID = "list_id"; // "list_id" 用于表示任务列表的ID
|
||||
|
||||
// 列表字段
|
||||
public final static String GTASK_JSON_LISTS = "lists"; // "lists" 用于表示多个任务列表
|
||||
|
||||
// 任务名称
|
||||
public final static String GTASK_JSON_NAME = "name"; // "name" 表示任务或任务列表的名称
|
||||
|
||||
// 新的ID
|
||||
public final static String GTASK_JSON_NEW_ID = "new_id"; // "new_id" 用于表示任务的新ID
|
||||
|
||||
// 任务备注
|
||||
public final static String GTASK_JSON_NOTES = "notes"; // "notes" 表示任务的备注信息
|
||||
|
||||
// 父任务ID
|
||||
public final static String GTASK_JSON_PARENT_ID = "parent_id"; // "parent_id" 表示父任务的ID
|
||||
|
||||
// 之前的兄弟任务ID
|
||||
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; // "prior_sibling_id" 用于表示之前的兄弟任务ID
|
||||
|
||||
// 任务结果
|
||||
public final static String GTASK_JSON_RESULTS = "results"; // "results" 用于表示任务操作的结果
|
||||
|
||||
// 源列表
|
||||
public final static String GTASK_JSON_SOURCE_LIST = "source_list"; // "source_list" 用于表示源任务列表
|
||||
|
||||
// 任务列表
|
||||
public final static String GTASK_JSON_TASKS = "tasks"; // "tasks" 用于表示任务数据
|
||||
|
||||
// 任务类型
|
||||
public final static String GTASK_JSON_TYPE = "type"; // "type" 表示任务的类型
|
||||
|
||||
// 任务组类型
|
||||
public final static String GTASK_JSON_TYPE_GROUP = "GROUP"; // "GROUP" 表示任务组类型
|
||||
|
||||
// 任务类型
|
||||
public final static String GTASK_JSON_TYPE_TASK = "TASK"; // "TASK" 表示单一任务类型
|
||||
|
||||
// 用户字段
|
||||
public final static String GTASK_JSON_USER = "user"; // "user" 用于表示任务所属用户的信息
|
||||
|
||||
// MIUI 文件夹前缀
|
||||
public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]"; // "[MIUI_Notes]" 用于表示 MIUI 系统中的笔记文件夹前缀
|
||||
|
||||
// 默认文件夹
|
||||
public final static String FOLDER_DEFAULT = "Default"; // "Default" 表示默认的文件夹名称
|
||||
|
||||
// 通话记录笔记文件夹
|
||||
public final static String FOLDER_CALL_NOTE = "Call_Note"; // "Call_Note" 用于表示通话记录的笔记文件夹
|
||||
|
||||
// 元数据文件夹
|
||||
public final static String FOLDER_META = "METADATA"; // "METADATA" 用于表示存储元数据的文件夹
|
||||
|
||||
// 元数据头部: GTASK ID
|
||||
public final static String META_HEAD_GTASK_ID = "meta_gid"; // "meta_gid" 用于表示任务的 Google Task ID 的元数据字段
|
||||
|
||||
// 元数据头部: 笔记
|
||||
public final static String META_HEAD_NOTE = "meta_note"; // "meta_note" 用于表示与任务相关的元数据笔记字段
|
||||
|
||||
// 元数据头部: 数据
|
||||
public final static String META_HEAD_DATA = "meta_data"; // "meta_data" 用于表示与任务相关的其他元数据字段
|
||||
|
||||
// 元数据笔记名称
|
||||
public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE"; // "[META INFO] DON'T UPDATE AND DELETE" 是一条标记元数据的警告信息,表示不要更新或删除该元数据
|
||||
}
|
||||
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.micode.notes.tool; // 包声明,表示该类位于 net.micode.notes.tool 包中
|
||||
|
||||
// 定义 GTaskStringUtils 类,用于管理 Google Tasks 或类似任务相关的常量字符串
|
||||
public class GTaskStringUtils {
|
||||
|
||||
// 这些常量字符串用于表示任务数据的各个字段名
|
||||
|
||||
// Action ID
|
||||
public final static String GTASK_JSON_ACTION_ID = "action_id"; // "action_id" 用于表示任务的操作标识符
|
||||
|
||||
// 操作列表
|
||||
public final static String GTASK_JSON_ACTION_LIST = "action_list"; // "action_list" 用于表示操作列表
|
||||
|
||||
// 操作类型
|
||||
public final static String GTASK_JSON_ACTION_TYPE = "action_type"; // "action_type" 用于表示操作的类型
|
||||
|
||||
// 创建操作类型
|
||||
public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; // "create" 表示创建操作
|
||||
|
||||
// 获取所有操作类型
|
||||
public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; // "get_all" 表示获取所有操作
|
||||
|
||||
// 移动操作类型
|
||||
public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; // "move" 表示移动操作
|
||||
|
||||
// 更新操作类型
|
||||
public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; // "update" 表示更新操作
|
||||
|
||||
// 创建者ID
|
||||
public final static String GTASK_JSON_CREATOR_ID = "creator_id"; // "creator_id" 表示任务创建者的ID
|
||||
|
||||
// 子实体
|
||||
public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; // "child_entity" 用于表示子实体
|
||||
|
||||
// 客户端版本
|
||||
public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; // "client_version" 表示客户端的版本
|
||||
|
||||
// 任务是否完成
|
||||
public final static String GTASK_JSON_COMPLETED = "completed"; // "completed" 表示任务是否完成
|
||||
|
||||
// 当前列表ID
|
||||
public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; // "current_list_id" 表示当前任务列表的ID
|
||||
|
||||
// 默认列表ID
|
||||
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; // "default_list_id" 表示默认任务列表的ID
|
||||
|
||||
// 是否删除
|
||||
public final static String GTASK_JSON_DELETED = "deleted"; // "deleted" 表示任务是否被删除
|
||||
|
||||
// 目标列表
|
||||
public final static String GTASK_JSON_DEST_LIST = "dest_list"; // "dest_list" 表示目标任务列表
|
||||
|
||||
// 目标父级任务
|
||||
public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; // "dest_parent" 表示目标任务的父级任务
|
||||
|
||||
// 目标父级类型
|
||||
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; // "dest_parent_type" 表示目标父级任务的类型
|
||||
|
||||
// 实体增量
|
||||
public final static String GTASK_JSON_ENTITY_DELTA = "entity"; // "entity" 表示实体数据的增量部分
|
||||
|
||||
// 实体类型
|
||||
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; // "entity_type" 用于表示实体类型(任务、列表等)
|
||||
|
||||
// 获取已删除任务
|
||||
public final static String GTASK_JSON_GET_DELETED = "get_deleted"; // "get_deleted" 表示获取已删除的任务
|
||||
|
||||
// 任务ID
|
||||
public final static String GTASK_JSON_ID = "id"; // "id" 用于表示任务的唯一标识符
|
||||
|
||||
// 任务索引
|
||||
public final static String GTASK_JSON_INDEX = "index"; // "index" 用于表示任务的索引位置
|
||||
|
||||
// 最后修改时间
|
||||
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; // "last_modified" 用于表示任务的最后修改时间
|
||||
|
||||
// 最新同步点
|
||||
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; // "latest_sync_point" 表示任务的最新同步点
|
||||
|
||||
// 列表ID
|
||||
public final static String GTASK_JSON_LIST_ID = "list_id"; // "list_id" 用于表示任务列表的ID
|
||||
|
||||
// 列表字段
|
||||
public final static String GTASK_JSON_LISTS = "lists"; // "lists" 用于表示多个任务列表
|
||||
|
||||
// 任务名称
|
||||
public final static String GTASK_JSON_NAME = "name"; // "name" 表示任务或任务列表的名称
|
||||
|
||||
// 新的ID
|
||||
public final static String GTASK_JSON_NEW_ID = "new_id"; // "new_id" 用于表示任务的新ID
|
||||
|
||||
// 任务备注
|
||||
public final static String GTASK_JSON_NOTES = "notes"; // "notes" 表示任务的备注信息
|
||||
|
||||
// 父任务ID
|
||||
public final static String GTASK_JSON_PARENT_ID = "parent_id"; // "parent_id" 表示父任务的ID
|
||||
|
||||
// 之前的兄弟任务ID
|
||||
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; // "prior_sibling_id" 用于表示之前的兄弟任务ID
|
||||
|
||||
// 任务结果
|
||||
public final static String GTASK_JSON_RESULTS = "results"; // "results" 用于表示任务操作的结果
|
||||
|
||||
// 源列表
|
||||
public final static String GTASK_JSON_SOURCE_LIST = "source_list"; // "source_list" 用于表示源任务列表
|
||||
|
||||
// 任务列表
|
||||
public final static String GTASK_JSON_TASKS = "tasks"; // "tasks" 用于表示任务数据
|
||||
|
||||
// 任务类型
|
||||
public final static String GTASK_JSON_TYPE = "type"; // "type" 表示任务的类型
|
||||
|
||||
// 任务组类型
|
||||
public final static String GTASK_JSON_TYPE_GROUP = "GROUP"; // "GROUP" 表示任务组类型
|
||||
|
||||
// 任务类型
|
||||
public final static String GTASK_JSON_TYPE_TASK = "TASK"; // "TASK" 表示单一任务类型
|
||||
|
||||
// 用户字段
|
||||
public final static String GTASK_JSON_USER = "user"; // "user" 用于表示任务所属用户的信息
|
||||
|
||||
// MIUI 文件夹前缀
|
||||
public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]"; // "[MIUI_Notes]" 用于表示 MIUI 系统中的笔记文件夹前缀
|
||||
|
||||
// 默认文件夹
|
||||
public final static String FOLDER_DEFAULT = "Default"; // "Default" 表示默认的文件夹名称
|
||||
|
||||
// 通话记录笔记文件夹
|
||||
public final static String FOLDER_CALL_NOTE = "Call_Note"; // "Call_Note" 用于表示通话记录的笔记文件夹
|
||||
|
||||
// 元数据文件夹
|
||||
public final static String FOLDER_META = "METADATA"; // "METADATA" 用于表示存储元数据的文件夹
|
||||
|
||||
// 元数据头部: GTASK ID
|
||||
public final static String META_HEAD_GTASK_ID = "meta_gid"; // "meta_gid" 用于表示任务的 Google Task ID 的元数据字段
|
||||
|
||||
// 元数据头部: 笔记
|
||||
public final static String META_HEAD_NOTE = "meta_note"; // "meta_note" 用于表示与任务相关的元数据笔记字段
|
||||
|
||||
// 元数据头部: 数据
|
||||
public final static String META_HEAD_DATA = "meta_data"; // "meta_data" 用于表示与任务相关的其他元数据字段
|
||||
|
||||
// 元数据笔记名称
|
||||
public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE"; // "[META INFO] DON'T UPDATE AND DELETE" 是一条标记元数据的警告信息,表示不要更新或删除该元数据
|
||||
}
|
||||
@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.micode.notes.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import net.micode.notes.R;
|
||||
import net.micode.notes.data.Notes;
|
||||
import net.micode.notes.tool.DataUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
// AlarmAlertActivity 是一个用于显示便签提醒的 Activity。
|
||||
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
|
||||
private long mNoteId; // 便签的ID。
|
||||
private String mSnippet; // 便签的预览文本。
|
||||
private static final int SNIPPET_PREW_MAX_LEN = 60; // 预览文本的最大长度。
|
||||
MediaPlayer mPlayer; // 用于播放提醒声音的 MediaPlayer。
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE); // 请求无标题栏的窗口特性。
|
||||
|
||||
final Window win = getWindow();
|
||||
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); // 锁屏时显示窗口。
|
||||
|
||||
if (!isScreenOn()) {
|
||||
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
||||
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|
||||
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
|
||||
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR); // 屏幕关闭时点亮屏幕。
|
||||
}
|
||||
|
||||
Intent intent = getIntent(); // 获取启动该 Activity 的 Intent。
|
||||
|
||||
try {
|
||||
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1)); // 从 Intent 中获取便签 ID。
|
||||
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(); // 初始化 MediaPlayer。
|
||||
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
|
||||
showActionDialog(); // 显示操作对话框。
|
||||
playAlarmSound(); // 播放提醒声音。
|
||||
} else {
|
||||
finish(); // 如果便签不可见,则结束 Activity。
|
||||
}
|
||||
}
|
||||
|
||||
// 检查屏幕是否开启。
|
||||
private boolean isScreenOn() {
|
||||
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
return pm.isScreenOn();
|
||||
}
|
||||
|
||||
// 播放提醒声音。
|
||||
private void playAlarmSound() {
|
||||
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
|
||||
int silentModeStreams = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
|
||||
|
||||
if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) {
|
||||
mPlayer.setAudioStreamType(silentModeStreams);
|
||||
} else {
|
||||
mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
|
||||
}
|
||||
try {
|
||||
mPlayer.setDataSource(this, url);
|
||||
mPlayer.prepare();
|
||||
mPlayer.setLooping(true);
|
||||
mPlayer.start();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalStateException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 显示操作对话框。
|
||||
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);
|
||||
}
|
||||
|
||||
// DialogInterface.OnClickListener 的实现,处理对话框按钮点击事件。
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_NEGATIVE:
|
||||
Intent intent = new Intent(this, NoteEditActivity.class);
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.putExtra(Intent.EXTRA_UID, mNoteId);
|
||||
startActivity(intent);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// DialogInterface.OnDismissListener 的实现,处理对话框消失事件。
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
stopAlarmSound();
|
||||
finish();
|
||||
}
|
||||
|
||||
// 停止提醒声音。
|
||||
private void stopAlarmSound() {
|
||||
if (mPlayer != null) {
|
||||
mPlayer.stop();
|
||||
mPlayer.release();
|
||||
mPlayer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue