diff --git a/doc/文档模板-开源软件泛读、标注和维护报告文档.docx b/doc/文档模板-开源软件泛读、标注和维护报告文档.docx
new file mode 100644
index 0000000..697a69e
Binary files /dev/null and b/doc/文档模板-开源软件泛读、标注和维护报告文档.docx differ
diff --git a/src/Notes-master/app/src/main/AndroidManifest.xml b/src/Notes-master/app/src/main/AndroidManifest.xml
deleted file mode 100644
index ad04419..0000000
--- a/src/Notes-master/app/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,164 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/data/Contact.java b/src/Notes-master/app/src/main/java/net/micode/notes/data/Contact.java
deleted file mode 100644
index 4bdf2a6..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/data/Contact.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- * 版权声明及开源协议说明
- */
-
-package net.micode.notes.data;
-
-import android.content.Context;
-import android.database.Cursor;
-import android.provider.ContactsContract.CommonDataKinds.Phone;
-import android.provider.ContactsContract.Data;
-import android.telephony.PhoneNumberUtils;
-import android.util.Log;
-
-import java.util.HashMap;
-
-/**
- * 联系人工具类:通过电话号码查询联系人姓名,并提供缓存机制
- */
-public class Contact {
- private static HashMap sContactCache; // 联系人缓存(电话号码 -> 姓名)
- private static final String TAG = "Contact"; // 日志标签
-
- /**
- * 联系人查询条件:匹配电话号码,并关联联系人数据
- * 使用PHONE_NUMBERS_EQUAL函数匹配电话号码,限制MIME类型为电话,且关联有效的原始联系人
- */
- private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
- + ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
- + " AND " + Data.RAW_CONTACT_ID + " IN "
- + "(SELECT raw_contact_id "
- + " FROM phone_lookup"
- + " WHERE min_match = '+')";
-
- /**
- * 根据电话号码查询联系人姓名
- * @param context 上下文环境
- * @param phoneNumber 电话号码
- * @return 联系人姓名(无匹配则返回null)
- */
- public static String getContact(Context context, String phoneNumber) {
- // 初始化缓存
- if(sContactCache == null) {
- sContactCache = new HashMap();
- }
-
- // 先从缓存查询,命中则直接返回
- if(sContactCache.containsKey(phoneNumber)) {
- return sContactCache.get(phoneNumber);
- }
-
- // 构建查询条件:替换占位符为最小匹配格式的电话号码
- String selection = CALLER_ID_SELECTION.replace("+",
- PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
- // 查询联系人数据
- Cursor cursor = context.getContentResolver().query(
- Data.CONTENT_URI, // 联系人数据URI
- new String [] { Phone.DISPLAY_NAME }, // 需要查询的字段(联系人姓名)
- selection, // 查询条件
- new String[] { phoneNumber }, // 条件参数(电话号码)
- null); // 排序方式
-
- // 处理查询结果
- if (cursor != null && cursor.moveToFirst()) {
- try {
- String name = cursor.getString(0); // 获取联系人姓名
- sContactCache.put(phoneNumber, name); // 存入缓存
- return name;
- } catch (IndexOutOfBoundsException e) {
- Log.e(TAG, " Cursor get string error " + e.toString());
- return null;
- } finally {
- cursor.close(); // 关闭游标,释放资源
- }
- } else {
- Log.d(TAG, "No contact matched with number:" + phoneNumber);
- return null;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/data/Notes.java b/src/Notes-master/app/src/main/java/net/micode/notes/data/Notes.java
deleted file mode 100644
index f42a3ee..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/data/Notes.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- * 版权声明及开源协议说明
- */
-
-package net.micode.notes.data;
-
-import android.net.Uri;
-
-/**
- * 笔记应用的核心数据定义类,包含常量、数据列定义及内容URI
- */
-public class Notes {
- // 内容提供者的权威名(用于ContentProvider标识)
- public static final String AUTHORITY = "micode_notes";
- // 日志标签
- public static final String TAG = "Notes";
-
- // 笔记类型:普通笔记、文件夹、系统文件夹
- public static final int TYPE_NOTE = 0;
- public static final int TYPE_FOLDER = 1;
- public static final int TYPE_SYSTEM = 2;
-
- /**
- * 系统文件夹ID定义
- * {@link Notes#ID_ROOT_FOLDER }:默认根文件夹
- * {@link Notes#ID_TEMPARAY_FOLDER }:临时文件夹(用于未归类笔记)
- * {@link Notes#ID_CALL_RECORD_FOLDER}:通话记录文件夹
- */
- public static final int ID_ROOT_FOLDER = 0;
- public static final int ID_TEMPARAY_FOLDER = -1;
- public static final int ID_CALL_RECORD_FOLDER = -2;
- public static final int ID_TRASH_FOLER = -3; // 回收站文件夹
-
- // 意图(Intent)传递的额外数据键名
- public static final String INTENT_EXTRA_ALERT_DATE = "net.micode.notes.alert_date"; // 提醒日期
- public static final String INTENT_EXTRA_BACKGROUND_ID = "net.micode.notes.background_color_id"; // 背景色ID
- public static final String INTENT_EXTRA_WIDGET_ID = "net.micode.notes.widget_id"; // 桌面部件ID
- public static final String INTENT_EXTRA_WIDGET_TYPE = "net.micode.notes.widget_type"; // 桌面部件类型
- public static final String INTENT_EXTRA_FOLDER_ID = "net.micode.notes.folder_id"; // 文件夹ID
- public static final String INTENT_EXTRA_CALL_DATE = "net.micode.notes.call_date"; // 通话日期
-
- // 桌面部件类型:无效、2x尺寸、4x尺寸
- public static final int TYPE_WIDGET_INVALIDE = -1;
- public static final int TYPE_WIDGET_2X = 0;
- public static final int TYPE_WIDGET_4X = 1;
-
- /**
- * 数据类型常量(关联TextNote和CallNote的MIME类型)
- */
- public static class DataConstants {
- public static final String NOTE = TextNote.CONTENT_ITEM_TYPE; // 文本笔记的MIME类型
- public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE; // 通话笔记的MIME类型
- }
-
- /**
- * 查询所有笔记和文件夹的内容URI
- */
- public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note");
-
- /**
- * 查询笔记详情数据的内容URI
- */
- public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
-
- /**
- * 笔记表(note)的列定义接口
- */
- public interface NoteColumns {
- /** 行唯一ID(类型:长整型) */
- public static final String ID = "_id";
-
- /** 父级ID(用于关联文件夹,类型:长整型) */
- public static final String PARENT_ID = "parent_id";
-
- /** 创建时间(类型:长整型,时间戳) */
- public static final String CREATED_DATE = "created_date";
-
- /** 最后修改时间(类型:长整型,时间戳) */
- public static final String MODIFIED_DATE = "modified_date";
-
- /** 提醒时间(类型:长整型,时间戳) */
- public static final String ALERTED_DATE = "alert_date";
-
- /** 文件夹名称或笔记内容摘要(类型:文本) */
- public static final String SNIPPET = "snippet";
-
- /** 关联的桌面部件ID(类型:长整型) */
- public static final String WIDGET_ID = "widget_id";
-
- /** 桌面部件类型(类型:长整型) */
- public static final String WIDGET_TYPE = "widget_type";
-
- /** 背景色ID(类型:长整型) */
- public static final String BG_COLOR_ID = "bg_color_id";
-
- /** 是否有附件(0:无,1:有,类型:整型) */
- public static final String HAS_ATTACHMENT = "has_attachment";
-
- /** 文件夹包含的笔记数量(类型:长整型) */
- public static final String NOTES_COUNT = "notes_count";
-
- /** 类型(笔记/文件夹/系统,对应TYPE_NOTE等,类型:整型) */
- public static final String TYPE = "type";
-
- /** 同步ID(用于数据同步,类型:长整型) */
- public static final String SYNC_ID = "sync_id";
-
- /** 本地修改标识(0:未修改,1:已修改,类型:整型) */
- public static final String LOCAL_MODIFIED = "local_modified";
-
- /** 移动到临时文件夹前的原始父ID(类型:整型) */
- public static final String ORIGIN_PARENT_ID = "origin_parent_id";
-
- /** GTask关联ID(类型:文本) */
- public static final String GTASK_ID = "gtask_id";
-
- /** 版本号(用于数据更新控制,类型:长整型) */
- public static final String VERSION = "version";
- }
-
- /**
- * 详情数据表(data)的列定义接口
- */
- public interface DataColumns {
- /** 行唯一ID(类型:长整型) */
- public static final String ID = "_id";
-
- /** 数据MIME类型(类型:文本) */
- public static final String MIME_TYPE = "mime_type";
-
- /** 关联的笔记ID(类型:长整型) */
- public static final String NOTE_ID = "note_id";
-
- /** 创建时间(类型:长整型,时间戳) */
- public static final String CREATED_DATE = "created_date";
-
- /** 最后修改时间(类型:长整型,时间戳) */
- public static final String MODIFIED_DATE = "modified_date";
-
- /** 数据内容(类型:文本) */
- public static final String CONTENT = "content";
-
- /** 通用整型数据1(含义由MIME_TYPE决定) */
- public static final String DATA1 = "data1";
-
- /** 通用整型数据2(含义由MIME_TYPE决定) */
- public static final String DATA2 = "data2";
-
- /** 通用文本数据3(含义由MIME_TYPE决定) */
- public static final String DATA3 = "data3";
-
- /** 通用文本数据4(含义由MIME_TYPE决定) */
- public static final String DATA4 = "data4";
-
- /** 通用文本数据5(含义由MIME_TYPE决定) */
- public static final String DATA5 = "data5";
- }
-
- /**
- * 文本笔记的数据定义(继承DataColumns,指定文本笔记特有的字段和URI)
- */
- public static final class TextNote implements DataColumns {
- /**
- * 文本模式(1: checklist模式,0:普通模式,对应DATA1)
- */
- public static final String MODE = DATA1;
- public static final int MODE_CHECK_LIST = 1; // checklist模式
-
- // 文本笔记的MIME类型(目录和单项)
- public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note";
- public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note";
-
- // 文本笔记的内容URI
- public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");
- }
-
- /**
- * 通话笔记的数据定义(继承DataColumns,指定通话笔记特有的字段和URI)
- */
- public static final class CallNote implements DataColumns {
- /**
- * 通话日期(对应DATA1,类型:长整型时间戳)
- */
- public static final String CALL_DATE = DATA1;
-
- /**
- * 电话号码(对应DATA3,类型:文本)
- */
- public static final String PHONE_NUMBER = DATA3;
-
- // 通话笔记的MIME类型(目录和单项)
- public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note";
- public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note";
-
- // 通话笔记的内容URI
- public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note");
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java b/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java
deleted file mode 100644
index 3cc06c6..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java
+++ /dev/null
@@ -1,386 +0,0 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- * 版权声明及开源协议说明
- */
-
-package net.micode.notes.data;
-
-import android.content.ContentValues;
-import android.content.Context;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteOpenHelper;
-import android.util.Log;
-
-import net.micode.notes.data.Notes.DataColumns;
-import net.micode.notes.data.Notes.DataConstants;
-import net.micode.notes.data.Notes.NoteColumns;
-
-/**
- * 笔记数据库帮助类,负责创建数据库表、触发器及数据库版本升级
- */
-public class NotesDatabaseHelper extends SQLiteOpenHelper {
- private static final String DB_NAME = "note.db"; // 数据库文件名
- private static final int DB_VERSION = 4; // 数据库版本号
-
- /**
- * 数据库表名常量
- */
- public interface TABLE {
- public static final String NOTE = "note"; // 笔记/文件夹表
- public static final String DATA = "data"; // 笔记详情数据表
- }
-
- private static final String TAG = "NotesDatabaseHelper"; // 日志标签
- private static NotesDatabaseHelper mInstance; // 单例实例
-
- // 创建note表的SQL语句(包含NoteColumns定义的所有字段)
- private static final String CREATE_NOTE_TABLE_SQL =
- "CREATE TABLE " + TABLE.NOTE + "(" +
- NoteColumns.ID + " INTEGER PRIMARY KEY," +
- NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
- NoteColumns.ALERTED_DATE + " INTEGER NOT NULL DEFAULT 0," +
- NoteColumns.BG_COLOR_ID + " INTEGER NOT NULL DEFAULT 0," +
- NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," + // 默认当前时间戳
- NoteColumns.HAS_ATTACHMENT + " INTEGER NOT NULL DEFAULT 0," +
- NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," + // 默认当前时间戳
- NoteColumns.NOTES_COUNT + " INTEGER NOT NULL DEFAULT 0," +
- NoteColumns.SNIPPET + " TEXT NOT NULL DEFAULT ''," +
- NoteColumns.TYPE + " INTEGER NOT NULL DEFAULT 0," +
- NoteColumns.WIDGET_ID + " INTEGER NOT NULL DEFAULT 0," +
- NoteColumns.WIDGET_TYPE + " INTEGER NOT NULL DEFAULT -1," +
- NoteColumns.SYNC_ID + " INTEGER NOT NULL DEFAULT 0," +
- NoteColumns.LOCAL_MODIFIED + " INTEGER NOT NULL DEFAULT 0," +
- NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
- NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," +
- NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +
- ")";
-
- // 创建data表的SQL语句(包含DataColumns定义的所有字段)
- private static final String CREATE_DATA_TABLE_SQL =
- "CREATE TABLE " + TABLE.DATA + "(" +
- DataColumns.ID + " INTEGER PRIMARY KEY," +
- DataColumns.MIME_TYPE + " TEXT NOT NULL," +
- DataColumns.NOTE_ID + " INTEGER NOT NULL DEFAULT 0," +
- NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
- NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
- DataColumns.CONTENT + " TEXT NOT NULL DEFAULT ''," +
- DataColumns.DATA1 + " INTEGER," +
- DataColumns.DATA2 + " INTEGER," +
- DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," +
- DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," +
- DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +
- ")";
-
- // 为data表的note_id字段创建索引(优化查询性能)
- private static final String CREATE_DATA_NOTE_ID_INDEX_SQL =
- "CREATE INDEX IF NOT EXISTS note_id_index ON " +
- TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";
-
- /**
- * 触发器:当笔记的父文件夹更新时,增加新父文件夹的笔记计数
- */
- private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
- "CREATE TRIGGER increase_folder_count_on_update "+
- " AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
- " BEGIN " +
- " UPDATE " + TABLE.NOTE +
- " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" +
- " WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" +
- " END";
-
- /**
- * 触发器:当笔记的父文件夹更新时,减少旧父文件夹的笔记计数
- */
- private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
- "CREATE TRIGGER decrease_folder_count_on_update " +
- " AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
- " BEGIN " +
- " UPDATE " + TABLE.NOTE +
- " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" +
- " WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID +
- " AND " + NoteColumns.NOTES_COUNT + ">0" + ";" + // 防止计数为负
- " END";
-
- /**
- * 触发器:当插入新笔记时,增加其父文件夹的笔记计数
- */
- private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER =
- "CREATE TRIGGER increase_folder_count_on_insert " +
- " AFTER INSERT ON " + TABLE.NOTE +
- " BEGIN " +
- " UPDATE " + TABLE.NOTE +
- " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" +
- " WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" +
- " END";
-
- /**
- * 触发器:当删除笔记时,减少其父文件夹的笔记计数
- */
- private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER =
- "CREATE TRIGGER decrease_folder_count_on_delete " +
- " AFTER DELETE ON " + TABLE.NOTE +
- " BEGIN " +
- " UPDATE " + TABLE.NOTE +
- " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" +
- " WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID +
- " AND " + NoteColumns.NOTES_COUNT + ">0;" + // 防止计数为负
- " END";
-
- /**
- * 触发器:当插入文本笔记数据时,更新对应笔记的摘要(snippet)
- */
- private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER =
- "CREATE TRIGGER update_note_content_on_insert " +
- " AFTER INSERT ON " + TABLE.DATA +
- " WHEN new." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" + // 仅处理文本笔记
- " BEGIN" +
- " UPDATE " + TABLE.NOTE +
- " SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT +
- " WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" +
- " END";
-
- /**
- * 触发器:当更新文本笔记数据时,更新对应笔记的摘要(snippet)
- */
- private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER =
- "CREATE TRIGGER update_note_content_on_update " +
- " AFTER UPDATE ON " + TABLE.DATA +
- " WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" + // 仅处理文本笔记
- " BEGIN" +
- " UPDATE " + TABLE.NOTE +
- " SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT +
- " WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" +
- " END";
-
- /**
- * 触发器:当删除文本笔记数据时,清空对应笔记的摘要(snippet)
- */
- private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER =
- "CREATE TRIGGER update_note_content_on_delete " +
- " AFTER delete ON " + TABLE.DATA +
- " WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" + // 仅处理文本笔记
- " BEGIN" +
- " UPDATE " + TABLE.NOTE +
- " SET " + NoteColumns.SNIPPET + "=''" +
- " WHERE " + NoteColumns.ID + "=old." + DataColumns.NOTE_ID + ";" +
- " END";
-
- /**
- * 触发器:当删除笔记时,级联删除其关联的data表数据
- */
- private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER =
- "CREATE TRIGGER delete_data_on_delete " +
- " AFTER DELETE ON " + TABLE.NOTE +
- " BEGIN" +
- " DELETE FROM " + TABLE.DATA +
- " WHERE " + DataColumns.NOTE_ID + "=old." + NoteColumns.ID + ";" +
- " END";
-
- /**
- * 触发器:当删除文件夹时,级联删除其包含的所有笔记
- */
- private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER =
- "CREATE TRIGGER folder_delete_notes_on_delete " +
- " AFTER DELETE ON " + TABLE.NOTE +
- " BEGIN" +
- " DELETE FROM " + TABLE.NOTE +
- " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
- " END";
-
- /**
- * 触发器:当文件夹被移到回收站时,其包含的所有笔记也移到回收站
- */
- private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER =
- "CREATE TRIGGER folder_move_notes_on_trash " +
- " AFTER UPDATE ON " + TABLE.NOTE +
- " WHEN new." + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER + // 新父ID为回收站
- " BEGIN" +
- " UPDATE " + TABLE.NOTE +
- " SET " + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER +
- " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + // 原父ID为当前文件夹
- " END";
-
- // 构造方法
- public NotesDatabaseHelper(Context context) {
- super(context, DB_NAME, null, DB_VERSION);
- }
-
- /**
- * 创建note表、触发器及系统文件夹
- */
- public void createNoteTable(SQLiteDatabase db) {
- db.execSQL(CREATE_NOTE_TABLE_SQL);
- reCreateNoteTableTriggers(db); // 创建note表相关触发器
- createSystemFolder(db); // 初始化系统文件夹
- Log.d(TAG, "note table has been created");
- }
-
- /**
- * 重新创建note表的触发器(先删除旧触发器,再创建新的)
- */
- private void reCreateNoteTableTriggers(SQLiteDatabase db) {
- db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update");
- db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_update");
- db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_delete");
- db.execSQL("DROP TRIGGER IF EXISTS delete_data_on_delete");
- db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_insert");
- db.execSQL("DROP TRIGGER IF EXISTS folder_delete_notes_on_delete");
- db.execSQL("DROP TRIGGER IF EXISTS folder_move_notes_on_trash");
-
- // 创建新触发器
- db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);
- db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);
- db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER);
- db.execSQL(NOTE_DELETE_DATA_ON_DELETE_TRIGGER);
- db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER);
- db.execSQL(FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER);
- db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER);
- }
-
- /**
- * 初始化系统文件夹(通话记录、根目录、临时文件夹、回收站)
- */
- private void createSystemFolder(SQLiteDatabase db) {
- ContentValues values = new ContentValues();
-
- // 通话记录文件夹
- values.put(NoteColumns.ID, Notes.ID_CALL_RECORD_FOLDER);
- values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
- db.insert(TABLE.NOTE, null, values);
-
- // 根文件夹
- values.clear();
- values.put(NoteColumns.ID, Notes.ID_ROOT_FOLDER);
- values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
- db.insert(TABLE.NOTE, null, values);
-
- // 临时文件夹
- values.clear();
- values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER);
- values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
- db.insert(TABLE.NOTE, null, values);
-
- // 回收站文件夹
- values.clear();
- values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER);
- values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
- db.insert(TABLE.NOTE, null, values);
- }
-
- /**
- * 创建data表、触发器及索引
- */
- public void createDataTable(SQLiteDatabase db) {
- db.execSQL(CREATE_DATA_TABLE_SQL);
- reCreateDataTableTriggers(db); // 创建data表相关触发器
- db.execSQL(CREATE_DATA_NOTE_ID_INDEX_SQL); // 创建note_id索引
- Log.d(TAG, "data table has been created");
- }
-
- /**
- * 重新创建data表的触发器(先删除旧触发器,再创建新的)
- */
- private void reCreateDataTableTriggers(SQLiteDatabase db) {
- db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_insert");
- db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_update");
- db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_delete");
-
- // 创建新触发器
- db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER);
- db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER);
- db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER);
- }
-
- /**
- * 获取单例实例(避免重复创建数据库连接)
- */
- static synchronized NotesDatabaseHelper getInstance(Context context) {
- if (mInstance == null) {
- mInstance = new NotesDatabaseHelper(context);
- }
- return mInstance;
- }
-
- /**
- * 数据库首次创建时调用,初始化表结构
- */
- @Override
- public void onCreate(SQLiteDatabase db) {
- createNoteTable(db);
- createDataTable(db);
- }
-
- /**
- * 数据库版本升级时调用
- */
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- boolean reCreateTriggers = false;
- boolean skipV2 = false;
-
- if (oldVersion == 1) {
- upgradeToV2(db); // 从版本1升级到2
- skipV2 = true; // 版本2的升级包含在版本1的升级中
- oldVersion++;
- }
-
- if (oldVersion == 2 && !skipV2) {
- upgradeToV3(db); // 从版本2升级到3
- reCreateTriggers = true; // 需要重新创建触发器
- oldVersion++;
- }
-
- if (oldVersion == 3) {
- upgradeToV4(db); // 从版本3升级到4
- oldVersion++;
- }
-
- // 重新创建触发器(如果需要)
- if (reCreateTriggers) {
- reCreateNoteTableTriggers(db);
- reCreateDataTableTriggers(db);
- }
-
- // 检查升级是否完成
- if (oldVersion != newVersion) {
- throw new IllegalStateException("Upgrade notes database to version " + newVersion
- + "fails");
- }
- }
-
- /**
- * 升级到版本2:删除旧表并重新创建(全量更新)
- */
- private void upgradeToV2(SQLiteDatabase db) {
- db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE);
- db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA);
- createNoteTable(db);
- createDataTable(db);
- }
-
- /**
- * 升级到版本3:删除无用触发器,添加gtask_id字段,创建回收站文件夹
- */
- private void upgradeToV3(SQLiteDatabase db) {
- // 删除无用触发器
- db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_insert");
- db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_delete");
- db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_update");
- // 为note表添加gtask_id字段
- db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.GTASK_ID
- + " TEXT NOT NULL DEFAULT ''");
- // 添加回收站系统文件夹
- ContentValues values = new ContentValues();
- values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER);
- values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
- db.insert(TABLE.NOTE, null, values);
- }
-
- /**
- * 升级到版本4:为note表添加version字段
- */
- private void upgradeToV4(SQLiteDatabase db) {
- db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION
- + " INTEGER NOT NULL DEFAULT 0");
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesProvider.java b/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesProvider.java
deleted file mode 100644
index 27058ae..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesProvider.java
+++ /dev/null
@@ -1,375 +0,0 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- * 版权声明及开源协议说明
- */
-
-package net.micode.notes.data;
-
-
-import android.app.SearchManager;
-import android.content.ContentProvider;
-import android.content.ContentUris;
-import android.content.ContentValues;
-import android.content.Intent;
-import android.content.UriMatcher;
-import android.database.Cursor;
-import android.database.sqlite.SQLiteDatabase;
-import android.net.Uri;
-import android.text.TextUtils;
-import android.util.Log;
-
-import net.micode.notes.R;
-import net.micode.notes.data.Notes.DataColumns;
-import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.data.NotesDatabaseHelper.TABLE;
-
-/**
- * 笔记内容提供者:实现ContentProvider接口,提供笔记数据的访问接口
- */
-public class NotesProvider extends ContentProvider {
- private static final UriMatcher mMatcher; // URI匹配器(用于匹配不同的请求URI)
-
- private NotesDatabaseHelper mHelper; // 数据库帮助类实例
- private static final String TAG = "NotesProvider"; // 日志标签
-
- // URI匹配常量(对应不同的操作类型)
- private static final int URI_NOTE = 1; // 匹配note表(所有笔记)
- private static final int URI_NOTE_ITEM = 2; // 匹配note表中的单个笔记(带ID)
- private static final int URI_DATA = 3; // 匹配data表(所有详情数据)
- private static final int URI_DATA_ITEM = 4; // 匹配data表中的单个数据(带ID)
- private static final int URI_SEARCH = 5; // 匹配搜索请求
- private static final int URI_SEARCH_SUGGEST = 6; // 匹配搜索建议请求
-
- static {
- // 初始化URI匹配器
- mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
- mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
- mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);
- mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA);
- mMatcher.addURI(Notes.AUTHORITY, "data/#", URI_DATA_ITEM);
- mMatcher.addURI(Notes.AUTHORITY, "search", URI_SEARCH);
- mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, URI_SEARCH_SUGGEST);
- mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", URI_SEARCH_SUGGEST);
- }
-
- /**
- * 搜索结果投影:定义搜索返回的字段(适配系统搜索框架)
- * 包含笔记ID、搜索建议文本、图标、意图动作等
- * 其中TRIM和REPLACE用于去除换行符和空格,优化显示
- */
- private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + ","
- + NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + ","
- + "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_1 + ","
- + "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_2 + ","
- + R.drawable.search_result + " AS " + SearchManager.SUGGEST_COLUMN_ICON_1 + ","
- + "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
- + "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
-
- /**
- * 笔记搜索查询SQL:查询非回收站的普通笔记,匹配摘要内容
- */
- private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION
- + " FROM " + TABLE.NOTE
- + " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
- + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
- + " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
-
- /**
- * 初始化ContentProvider,获取数据库帮助类实例
- */
- @Override
- public boolean onCreate() {
- mHelper = NotesDatabaseHelper.getInstance(getContext());
- return true;
- }
-
- /**
- * 查询数据
- * @param uri 请求URI
- * @param projection 需要返回的字段
- * @param selection 查询条件
- * @param selectionArgs 条件参数
- * @param sortOrder 排序方式
- * @return 查询结果游标(Cursor)
- */
- @Override
- public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
- String sortOrder) {
- Cursor c = null;
- SQLiteDatabase db = mHelper.getReadableDatabase(); // 获取只读数据库连接
- String id = null;
-
- // 根据URI匹配结果执行不同查询
- switch (mMatcher.match(uri)) {
- case URI_NOTE:
- // 查询所有笔记/文件夹
- c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null,
- sortOrder);
- break;
- case URI_NOTE_ITEM:
- // 查询单个笔记/文件夹(通过ID)
- id = uri.getPathSegments().get(1); // 从URI中提取ID
- c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id
- + parseSelection(selection), selectionArgs, null, null, sortOrder);
- break;
- case URI_DATA:
- // 查询所有详情数据
- c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null,
- sortOrder);
- break;
- case URI_DATA_ITEM:
- // 查询单个详情数据(通过ID)
- id = uri.getPathSegments().get(1); // 从URI中提取ID
- c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id
- + parseSelection(selection), selectionArgs, null, null, sortOrder);
- break;
- case URI_SEARCH:
- case URI_SEARCH_SUGGEST:
- // 处理搜索请求
- if (sortOrder != null || projection != null) {
- throw new IllegalArgumentException(
- "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");
- }
-
- // 提取搜索关键词
- String searchString = null;
- if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) {
- if (uri.getPathSegments().size() > 1) {
- searchString = uri.getPathSegments().get(1);
- }
- } else {
- searchString = uri.getQueryParameter("pattern");
- }
-
- if (TextUtils.isEmpty(searchString)) {
- return null;
- }
-
- // 执行搜索查询(模糊匹配)
- try {
- searchString = String.format("%%%s%%", searchString); // 拼接模糊查询符
- c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY,
- new String[] { searchString });
- } catch (IllegalStateException ex) {
- Log.e(TAG, "got exception: " + ex.toString());
- }
- break;
- default:
- throw new IllegalArgumentException("Unknown URI " + uri);
- }
-
- // 设置URI通知:当数据变化时通知观察者
- if (c != null) {
- c.setNotificationUri(getContext().getContentResolver(), uri);
- }
- return c;
- }
-
- /**
- * 插入数据
- * @param uri 请求URI
- * @param values 待插入的数据
- * @return 插入数据的URI(包含新记录ID)
- */
- @Override
- public Uri insert(Uri uri, ContentValues values) {
- SQLiteDatabase db = mHelper.getWritableDatabase(); // 获取可写数据库连接
- long dataId = 0, noteId = 0, insertedId = 0;
-
- // 根据URI匹配结果执行插入
- switch (mMatcher.match(uri)) {
- case URI_NOTE:
- // 插入笔记/文件夹
- insertedId = noteId = db.insert(TABLE.NOTE, null, values);
- break;
- case URI_DATA:
- // 插入详情数据(需关联笔记ID)
- if (values.containsKey(DataColumns.NOTE_ID)) {
- noteId = values.getAsLong(DataColumns.NOTE_ID);
- } else {
- Log.d(TAG, "Wrong data format without note id:" + values.toString());
- }
- insertedId = dataId = db.insert(TABLE.DATA, null, values);
- break;
- default:
- throw new IllegalArgumentException("Unknown URI " + uri);
- }
-
- // 通知数据变化
- if (noteId > 0) {
- getContext().getContentResolver().notifyChange(
- ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);
- }
- if (dataId > 0) {
- getContext().getContentResolver().notifyChange(
- ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);
- }
-
- return ContentUris.withAppendedId(uri, insertedId); // 返回包含新ID的URI
- }
-
- /**
- * 删除数据
- * @param uri 请求URI
- * @param selection 删除条件
- * @param selectionArgs 条件参数
- * @return 删除的记录数
- */
- @Override
- public int delete(Uri uri, String selection, String[] selectionArgs) {
- int count = 0;
- String id = null;
- SQLiteDatabase db = mHelper.getWritableDatabase(); // 获取可写数据库连接
- boolean deleteData = false; // 是否删除的是data表数据
-
- // 根据URI匹配结果执行删除
- switch (mMatcher.match(uri)) {
- case URI_NOTE:
- // 删除笔记/文件夹(过滤系统文件夹,ID>0)
- selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 ";
- count = db.delete(TABLE.NOTE, selection, selectionArgs);
- break;
- case URI_NOTE_ITEM:
- // 删除单个笔记/文件夹(通过ID,过滤系统文件夹)
- id = uri.getPathSegments().get(1);
- long noteId = Long.valueOf(id);
- if (noteId <= 0) { // 系统文件夹ID<=0,不允许删除
- break;
- }
- count = db.delete(TABLE.NOTE,
- NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
- break;
- case URI_DATA:
- // 删除详情数据
- count = db.delete(TABLE.DATA, selection, selectionArgs);
- deleteData = true;
- break;
- case URI_DATA_ITEM:
- // 删除单个详情数据(通过ID)
- id = uri.getPathSegments().get(1);
- count = db.delete(TABLE.DATA,
- DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
- deleteData = true;
- break;
- default:
- throw new IllegalArgumentException("Unknown URI " + uri);
- }
-
- // 通知数据变化
- if (count > 0) {
- if (deleteData) {
- getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
- }
- getContext().getContentResolver().notifyChange(uri, null);
- }
- return count;
- }
-
- /**
- * 更新数据
- * @param uri 请求URI
- * @param values 待更新的数据
- * @param selection 更新条件
- * @param selectionArgs 条件参数
- * @return 更新的记录数
- */
- @Override
- public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
- int count = 0;
- String id = null;
- SQLiteDatabase db = mHelper.getWritableDatabase(); // 获取可写数据库连接
- boolean updateData = false; // 是否更新的是data表数据
-
- // 根据URI匹配结果执行更新
- switch (mMatcher.match(uri)) {
- case URI_NOTE:
- // 更新笔记/文件夹(先递增版本号)
- increaseNoteVersion(-1, selection, selectionArgs);
- count = db.update(TABLE.NOTE, values, selection, selectionArgs);
- break;
- case URI_NOTE_ITEM:
- // 更新单个笔记/文件夹(通过ID,先递增版本号)
- id = uri.getPathSegments().get(1);
- increaseNoteVersion(Long.valueOf(id), selection, selectionArgs);
- count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id
- + parseSelection(selection), selectionArgs);
- break;
- case URI_DATA:
- // 更新详情数据
- count = db.update(TABLE.DATA, values, selection, selectionArgs);
- updateData = true;
- break;
- case URI_DATA_ITEM:
- // 更新单个详情数据(通过ID)
- id = uri.getPathSegments().get(1);
- count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id
- + parseSelection(selection), selectionArgs);
- updateData = true;
- break;
- default:
- throw new IllegalArgumentException("Unknown URI " + uri);
- }
-
- // 通知数据变化
- if (count > 0) {
- if (updateData) {
- getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
- }
- getContext().getContentResolver().notifyChange(uri, null);
- }
- return count;
- }
-
- /**
- * 解析查询条件:拼接额外条件(如需要)
- * @param selection 原始条件
- * @return 拼接后的条件字符串
- */
- private String parseSelection(String selection) {
- return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
- }
-
- /**
- * 递增笔记的版本号(用于数据同步和更新控制)
- * @param id 笔记ID(-1表示更新符合条件的所有笔记)
- * @param selection 更新条件
- * @param selectionArgs 条件参数
- */
- private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
- StringBuilder sql = new StringBuilder(120);
- sql.append("UPDATE ");
- sql.append(TABLE.NOTE);
- sql.append(" SET ");
- sql.append(NoteColumns.VERSION);
- sql.append("=" + NoteColumns.VERSION + "+1 "); // 版本号+1
-
- // 拼接WHERE条件
- if (id > 0 || !TextUtils.isEmpty(selection)) {
- sql.append(" WHERE ");
- }
- if (id > 0) {
- sql.append(NoteColumns.ID + "=" + String.valueOf(id));
- }
- if (!TextUtils.isEmpty(selection)) {
- String selectString = id > 0 ? parseSelection(selection) : selection;
- // 替换参数占位符
- for (String args : selectionArgs) {
- selectString = selectString.replaceFirst("\\?", args);
- }
- sql.append(selectString);
- }
-
- // 执行更新
- mHelper.getWritableDatabase().execSQL(sql.toString());
- }
-
- /**
- * 获取MIME类型(未实现)
- */
- @Override
- public String getType(Uri uri) {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/MetaData.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/MetaData.java
deleted file mode 100644
index 3a2050b..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/MetaData.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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.gtask.data;
-
-import android.database.Cursor;
-import android.util.Log;
-
-import net.micode.notes.tool.GTaskStringUtils;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-
-public class MetaData extends Task {
- private final static String TAG = MetaData.class.getSimpleName();
-
- private String mRelatedGid = null;
-
- public void setMeta(String gid, JSONObject metaInfo) {
- try {
- metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
- } catch (JSONException e) {
- Log.e(TAG, "failed to put related gid");
- }
- setNotes(metaInfo.toString());
- setName(GTaskStringUtils.META_NOTE_NAME);
- }
-
- public String getRelatedGid() {
- return mRelatedGid;
- }
-
- @Override
- public boolean isWorthSaving() {
- return getNotes() != null;
- }
-
- @Override
- public void setContentByRemoteJSON(JSONObject js) {
- super.setContentByRemoteJSON(js);
- if (getNotes() != null) {
- try {
- JSONObject metaInfo = new JSONObject(getNotes().trim());
- mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
- } catch (JSONException e) {
- Log.w(TAG, "failed to get related gid");
- mRelatedGid = null;
- }
- }
- }
-
- @Override
- public void setContentByLocalJSON(JSONObject js) {
- // this function should not be called
- throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
- }
-
- @Override
- public JSONObject getLocalJSONFromContent() {
- throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
- }
-
- @Override
- public int getSyncAction(Cursor c) {
- throw new IllegalAccessError("MetaData:getSyncAction should not be called");
- }
-
-}
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Node.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Node.java
deleted file mode 100644
index 63950e0..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Node.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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.gtask.data;
-
-import android.database.Cursor;
-
-import org.json.JSONObject;
-
-public abstract class Node {
- public static final int SYNC_ACTION_NONE = 0;
-
- public static final int SYNC_ACTION_ADD_REMOTE = 1;
-
- public static final int SYNC_ACTION_ADD_LOCAL = 2;
-
- public static final int SYNC_ACTION_DEL_REMOTE = 3;
-
- public static final int SYNC_ACTION_DEL_LOCAL = 4;
-
- public static final int SYNC_ACTION_UPDATE_REMOTE = 5;
-
- public static final int SYNC_ACTION_UPDATE_LOCAL = 6;
-
- public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;
-
- public static final int SYNC_ACTION_ERROR = 8;
-
- private String mGid;
-
- private String mName;
-
- private long mLastModified;
-
- private boolean mDeleted;
-
- public Node() {
- mGid = null;
- mName = "";
- mLastModified = 0;
- mDeleted = false;
- }
-
- public abstract JSONObject getCreateAction(int actionId);
-
- public abstract JSONObject getUpdateAction(int actionId);
-
- public abstract void setContentByRemoteJSON(JSONObject js);
-
- public abstract void setContentByLocalJSON(JSONObject js);
-
- public abstract JSONObject getLocalJSONFromContent();
-
- public abstract int getSyncAction(Cursor c);
-
- public void setGid(String gid) {
- this.mGid = gid;
- }
-
- public void setName(String name) {
- this.mName = name;
- }
-
- public void setLastModified(long lastModified) {
- this.mLastModified = lastModified;
- }
-
- public void setDeleted(boolean deleted) {
- this.mDeleted = deleted;
- }
-
- public String getGid() {
- return this.mGid;
- }
-
- public String getName() {
- return this.mName;
- }
-
- public long getLastModified() {
- return this.mLastModified;
- }
-
- public boolean getDeleted() {
- return this.mDeleted;
- }
-
-}
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlData.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlData.java
deleted file mode 100644
index d3ec3be..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlData.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * 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.gtask.data;
-
-import android.content.ContentResolver;
-import android.content.ContentUris;
-import android.content.ContentValues;
-import android.content.Context;
-import android.database.Cursor;
-import android.net.Uri;
-import android.util.Log;
-
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.DataColumns;
-import net.micode.notes.data.Notes.DataConstants;
-import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.data.NotesDatabaseHelper.TABLE;
-import net.micode.notes.gtask.exception.ActionFailureException;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-
-public class SqlData {
- private static final String TAG = SqlData.class.getSimpleName();
-
- private static final int INVALID_ID = -99999;
-
- public static final String[] PROJECTION_DATA = new String[] {
- DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1,
- DataColumns.DATA3
- };
-
- public static final int DATA_ID_COLUMN = 0;
-
- public static final int DATA_MIME_TYPE_COLUMN = 1;
-
- public static final int DATA_CONTENT_COLUMN = 2;
-
- public static final int DATA_CONTENT_DATA_1_COLUMN = 3;
-
- public static final int DATA_CONTENT_DATA_3_COLUMN = 4;
-
- private ContentResolver mContentResolver;
-
- private boolean mIsCreate;
-
- private long mDataId;
-
- private String mDataMimeType;
-
- private String mDataContent;
-
- private long mDataContentData1;
-
- private String mDataContentData3;
-
- private ContentValues mDiffDataValues;
-
- public SqlData(Context context) {
- mContentResolver = context.getContentResolver();
- mIsCreate = true;
- mDataId = INVALID_ID;
- mDataMimeType = DataConstants.NOTE;
- mDataContent = "";
- mDataContentData1 = 0;
- mDataContentData3 = "";
- mDiffDataValues = new ContentValues();
- }
-
- public SqlData(Context context, Cursor c) {
- mContentResolver = context.getContentResolver();
- mIsCreate = false;
- loadFromCursor(c);
- mDiffDataValues = new ContentValues();
- }
-
- private void loadFromCursor(Cursor c) {
- mDataId = c.getLong(DATA_ID_COLUMN);
- mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);
- mDataContent = c.getString(DATA_CONTENT_COLUMN);
- mDataContentData1 = c.getLong(DATA_CONTENT_DATA_1_COLUMN);
- mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);
- }
-
- public void setContent(JSONObject js) throws JSONException {
- long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID;
- if (mIsCreate || mDataId != dataId) {
- mDiffDataValues.put(DataColumns.ID, dataId);
- }
- mDataId = dataId;
-
- String dataMimeType = js.has(DataColumns.MIME_TYPE) ? js.getString(DataColumns.MIME_TYPE)
- : DataConstants.NOTE;
- if (mIsCreate || !mDataMimeType.equals(dataMimeType)) {
- mDiffDataValues.put(DataColumns.MIME_TYPE, dataMimeType);
- }
- mDataMimeType = dataMimeType;
-
- String dataContent = js.has(DataColumns.CONTENT) ? js.getString(DataColumns.CONTENT) : "";
- if (mIsCreate || !mDataContent.equals(dataContent)) {
- mDiffDataValues.put(DataColumns.CONTENT, dataContent);
- }
- mDataContent = dataContent;
-
- long dataContentData1 = js.has(DataColumns.DATA1) ? js.getLong(DataColumns.DATA1) : 0;
- if (mIsCreate || mDataContentData1 != dataContentData1) {
- mDiffDataValues.put(DataColumns.DATA1, dataContentData1);
- }
- mDataContentData1 = dataContentData1;
-
- String dataContentData3 = js.has(DataColumns.DATA3) ? js.getString(DataColumns.DATA3) : "";
- if (mIsCreate || !mDataContentData3.equals(dataContentData3)) {
- mDiffDataValues.put(DataColumns.DATA3, dataContentData3);
- }
- mDataContentData3 = dataContentData3;
- }
-
- public JSONObject getContent() throws JSONException {
- if (mIsCreate) {
- Log.e(TAG, "it seems that we haven't created this in database yet");
- return null;
- }
- JSONObject js = new JSONObject();
- js.put(DataColumns.ID, mDataId);
- js.put(DataColumns.MIME_TYPE, mDataMimeType);
- js.put(DataColumns.CONTENT, mDataContent);
- js.put(DataColumns.DATA1, mDataContentData1);
- js.put(DataColumns.DATA3, mDataContentData3);
- return js;
- }
-
- public void commit(long noteId, boolean validateVersion, long version) {
-
- if (mIsCreate) {
- if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) {
- mDiffDataValues.remove(DataColumns.ID);
- }
-
- mDiffDataValues.put(DataColumns.NOTE_ID, noteId);
- Uri uri = mContentResolver.insert(Notes.CONTENT_DATA_URI, mDiffDataValues);
- try {
- mDataId = Long.valueOf(uri.getPathSegments().get(1));
- } catch (NumberFormatException e) {
- Log.e(TAG, "Get note id error :" + e.toString());
- throw new ActionFailureException("create note failed");
- }
- } else {
- if (mDiffDataValues.size() > 0) {
- int result = 0;
- if (!validateVersion) {
- result = mContentResolver.update(ContentUris.withAppendedId(
- Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null);
- } else {
- result = mContentResolver.update(ContentUris.withAppendedId(
- Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues,
- " ? in (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE
- + " WHERE " + NoteColumns.VERSION + "=?)", new String[] {
- String.valueOf(noteId), String.valueOf(version)
- });
- }
- if (result == 0) {
- Log.w(TAG, "there is no update. maybe user updates note when syncing");
- }
- }
- }
-
- mDiffDataValues.clear();
- mIsCreate = false;
- }
-
- public long getId() {
- return mDataId;
- }
-}
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java
deleted file mode 100644
index 79a4095..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java
+++ /dev/null
@@ -1,505 +0,0 @@
-/*
- * 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.gtask.data;
-
-import android.appwidget.AppWidgetManager;
-import android.content.ContentResolver;
-import android.content.ContentValues;
-import android.content.Context;
-import android.database.Cursor;
-import android.net.Uri;
-import android.util.Log;
-
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.DataColumns;
-import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.gtask.exception.ActionFailureException;
-import net.micode.notes.tool.GTaskStringUtils;
-import net.micode.notes.tool.ResourceParser;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.util.ArrayList;
-
-
-public class SqlNote {
- private static final String TAG = SqlNote.class.getSimpleName();
-
- private static final int INVALID_ID = -99999;
-
- public static final String[] PROJECTION_NOTE = new String[] {
- NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID,
- NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE,
- NoteColumns.NOTES_COUNT, NoteColumns.PARENT_ID, NoteColumns.SNIPPET, NoteColumns.TYPE,
- NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE, NoteColumns.SYNC_ID,
- NoteColumns.LOCAL_MODIFIED, NoteColumns.ORIGIN_PARENT_ID, NoteColumns.GTASK_ID,
- NoteColumns.VERSION
- };
-
- public static final int ID_COLUMN = 0;
-
- public static final int ALERTED_DATE_COLUMN = 1;
-
- public static final int BG_COLOR_ID_COLUMN = 2;
-
- public static final int CREATED_DATE_COLUMN = 3;
-
- public static final int HAS_ATTACHMENT_COLUMN = 4;
-
- public static final int MODIFIED_DATE_COLUMN = 5;
-
- public static final int NOTES_COUNT_COLUMN = 6;
-
- public static final int PARENT_ID_COLUMN = 7;
-
- public static final int SNIPPET_COLUMN = 8;
-
- public static final int TYPE_COLUMN = 9;
-
- public static final int WIDGET_ID_COLUMN = 10;
-
- public static final int WIDGET_TYPE_COLUMN = 11;
-
- public static final int SYNC_ID_COLUMN = 12;
-
- public static final int LOCAL_MODIFIED_COLUMN = 13;
-
- public static final int ORIGIN_PARENT_ID_COLUMN = 14;
-
- public static final int GTASK_ID_COLUMN = 15;
-
- public static final int VERSION_COLUMN = 16;
-
- private Context mContext;
-
- private ContentResolver mContentResolver;
-
- private boolean mIsCreate;
-
- private long mId;
-
- private long mAlertDate;
-
- private int mBgColorId;
-
- private long mCreatedDate;
-
- private int mHasAttachment;
-
- private long mModifiedDate;
-
- private long mParentId;
-
- private String mSnippet;
-
- private int mType;
-
- private int mWidgetId;
-
- private int mWidgetType;
-
- private long mOriginParent;
-
- private long mVersion;
-
- private ContentValues mDiffNoteValues;
-
- private ArrayList mDataList;
-
- public SqlNote(Context context) {
- mContext = context;
- mContentResolver = context.getContentResolver();
- mIsCreate = true;
- mId = INVALID_ID;
- mAlertDate = 0;
- mBgColorId = ResourceParser.getDefaultBgId(context);
- mCreatedDate = System.currentTimeMillis();
- mHasAttachment = 0;
- mModifiedDate = System.currentTimeMillis();
- mParentId = 0;
- mSnippet = "";
- mType = Notes.TYPE_NOTE;
- mWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
- mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
- mOriginParent = 0;
- mVersion = 0;
- mDiffNoteValues = new ContentValues();
- mDataList = new ArrayList();
- }
-
- public SqlNote(Context context, Cursor c) {
- mContext = context;
- mContentResolver = context.getContentResolver();
- mIsCreate = false;
- loadFromCursor(c);
- mDataList = new ArrayList();
- if (mType == Notes.TYPE_NOTE)
- loadDataContent();
- mDiffNoteValues = new ContentValues();
- }
-
- public SqlNote(Context context, long id) {
- mContext = context;
- mContentResolver = context.getContentResolver();
- mIsCreate = false;
- loadFromCursor(id);
- mDataList = new ArrayList();
- if (mType == Notes.TYPE_NOTE)
- loadDataContent();
- mDiffNoteValues = new ContentValues();
-
- }
-
- private void loadFromCursor(long id) {
- Cursor c = null;
- try {
- c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",
- new String[] {
- String.valueOf(id)
- }, null);
- if (c != null) {
- c.moveToNext();
- loadFromCursor(c);
- } else {
- Log.w(TAG, "loadFromCursor: cursor = null");
- }
- } finally {
- if (c != null)
- c.close();
- }
- }
-
- private void loadFromCursor(Cursor c) {
- mId = c.getLong(ID_COLUMN);
- mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
- mBgColorId = c.getInt(BG_COLOR_ID_COLUMN);
- mCreatedDate = c.getLong(CREATED_DATE_COLUMN);
- mHasAttachment = c.getInt(HAS_ATTACHMENT_COLUMN);
- mModifiedDate = c.getLong(MODIFIED_DATE_COLUMN);
- mParentId = c.getLong(PARENT_ID_COLUMN);
- mSnippet = c.getString(SNIPPET_COLUMN);
- mType = c.getInt(TYPE_COLUMN);
- mWidgetId = c.getInt(WIDGET_ID_COLUMN);
- mWidgetType = c.getInt(WIDGET_TYPE_COLUMN);
- mVersion = c.getLong(VERSION_COLUMN);
- }
-
- private void loadDataContent() {
- Cursor c = null;
- mDataList.clear();
- try {
- c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA,
- "(note_id=?)", new String[] {
- String.valueOf(mId)
- }, null);
- if (c != null) {
- if (c.getCount() == 0) {
- Log.w(TAG, "it seems that the note has not data");
- return;
- }
- while (c.moveToNext()) {
- SqlData data = new SqlData(mContext, c);
- mDataList.add(data);
- }
- } else {
- Log.w(TAG, "loadDataContent: cursor = null");
- }
- } finally {
- if (c != null)
- c.close();
- }
- }
-
- public boolean setContent(JSONObject js) {
- try {
- JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
- if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
- Log.w(TAG, "cannot set system folder");
- } else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) {
- // for folder we can only update the snnipet and type
- String snippet = note.has(NoteColumns.SNIPPET) ? note
- .getString(NoteColumns.SNIPPET) : "";
- if (mIsCreate || !mSnippet.equals(snippet)) {
- mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
- }
- mSnippet = snippet;
-
- int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
- : Notes.TYPE_NOTE;
- if (mIsCreate || mType != type) {
- mDiffNoteValues.put(NoteColumns.TYPE, type);
- }
- mType = type;
- } else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) {
- JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
- long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID;
- if (mIsCreate || mId != id) {
- mDiffNoteValues.put(NoteColumns.ID, id);
- }
- mId = id;
-
- long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note
- .getLong(NoteColumns.ALERTED_DATE) : 0;
- if (mIsCreate || mAlertDate != alertDate) {
- mDiffNoteValues.put(NoteColumns.ALERTED_DATE, alertDate);
- }
- mAlertDate = alertDate;
-
- int bgColorId = note.has(NoteColumns.BG_COLOR_ID) ? note
- .getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext);
- if (mIsCreate || mBgColorId != bgColorId) {
- mDiffNoteValues.put(NoteColumns.BG_COLOR_ID, bgColorId);
- }
- mBgColorId = bgColorId;
-
- long createDate = note.has(NoteColumns.CREATED_DATE) ? note
- .getLong(NoteColumns.CREATED_DATE) : System.currentTimeMillis();
- if (mIsCreate || mCreatedDate != createDate) {
- mDiffNoteValues.put(NoteColumns.CREATED_DATE, createDate);
- }
- mCreatedDate = createDate;
-
- int hasAttachment = note.has(NoteColumns.HAS_ATTACHMENT) ? note
- .getInt(NoteColumns.HAS_ATTACHMENT) : 0;
- if (mIsCreate || mHasAttachment != hasAttachment) {
- mDiffNoteValues.put(NoteColumns.HAS_ATTACHMENT, hasAttachment);
- }
- mHasAttachment = hasAttachment;
-
- long modifiedDate = note.has(NoteColumns.MODIFIED_DATE) ? note
- .getLong(NoteColumns.MODIFIED_DATE) : System.currentTimeMillis();
- if (mIsCreate || mModifiedDate != modifiedDate) {
- mDiffNoteValues.put(NoteColumns.MODIFIED_DATE, modifiedDate);
- }
- mModifiedDate = modifiedDate;
-
- long parentId = note.has(NoteColumns.PARENT_ID) ? note
- .getLong(NoteColumns.PARENT_ID) : 0;
- if (mIsCreate || mParentId != parentId) {
- mDiffNoteValues.put(NoteColumns.PARENT_ID, parentId);
- }
- mParentId = parentId;
-
- String snippet = note.has(NoteColumns.SNIPPET) ? note
- .getString(NoteColumns.SNIPPET) : "";
- if (mIsCreate || !mSnippet.equals(snippet)) {
- mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
- }
- mSnippet = snippet;
-
- int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
- : Notes.TYPE_NOTE;
- if (mIsCreate || mType != type) {
- mDiffNoteValues.put(NoteColumns.TYPE, type);
- }
- mType = type;
-
- int widgetId = note.has(NoteColumns.WIDGET_ID) ? note.getInt(NoteColumns.WIDGET_ID)
- : AppWidgetManager.INVALID_APPWIDGET_ID;
- if (mIsCreate || mWidgetId != widgetId) {
- mDiffNoteValues.put(NoteColumns.WIDGET_ID, widgetId);
- }
- mWidgetId = widgetId;
-
- int widgetType = note.has(NoteColumns.WIDGET_TYPE) ? note
- .getInt(NoteColumns.WIDGET_TYPE) : Notes.TYPE_WIDGET_INVALIDE;
- if (mIsCreate || mWidgetType != widgetType) {
- mDiffNoteValues.put(NoteColumns.WIDGET_TYPE, widgetType);
- }
- mWidgetType = widgetType;
-
- long originParent = note.has(NoteColumns.ORIGIN_PARENT_ID) ? note
- .getLong(NoteColumns.ORIGIN_PARENT_ID) : 0;
- if (mIsCreate || mOriginParent != originParent) {
- mDiffNoteValues.put(NoteColumns.ORIGIN_PARENT_ID, originParent);
- }
- mOriginParent = originParent;
-
- for (int i = 0; i < dataArray.length(); i++) {
- JSONObject data = dataArray.getJSONObject(i);
- SqlData sqlData = null;
- if (data.has(DataColumns.ID)) {
- long dataId = data.getLong(DataColumns.ID);
- for (SqlData temp : mDataList) {
- if (dataId == temp.getId()) {
- sqlData = temp;
- }
- }
- }
-
- if (sqlData == null) {
- sqlData = new SqlData(mContext);
- mDataList.add(sqlData);
- }
-
- sqlData.setContent(data);
- }
- }
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- return false;
- }
- return true;
- }
-
- public JSONObject getContent() {
- try {
- JSONObject js = new JSONObject();
-
- if (mIsCreate) {
- Log.e(TAG, "it seems that we haven't created this in database yet");
- return null;
- }
-
- JSONObject note = new JSONObject();
- if (mType == Notes.TYPE_NOTE) {
- note.put(NoteColumns.ID, mId);
- note.put(NoteColumns.ALERTED_DATE, mAlertDate);
- note.put(NoteColumns.BG_COLOR_ID, mBgColorId);
- note.put(NoteColumns.CREATED_DATE, mCreatedDate);
- note.put(NoteColumns.HAS_ATTACHMENT, mHasAttachment);
- note.put(NoteColumns.MODIFIED_DATE, mModifiedDate);
- note.put(NoteColumns.PARENT_ID, mParentId);
- note.put(NoteColumns.SNIPPET, mSnippet);
- note.put(NoteColumns.TYPE, mType);
- note.put(NoteColumns.WIDGET_ID, mWidgetId);
- note.put(NoteColumns.WIDGET_TYPE, mWidgetType);
- note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent);
- js.put(GTaskStringUtils.META_HEAD_NOTE, note);
-
- JSONArray dataArray = new JSONArray();
- for (SqlData sqlData : mDataList) {
- JSONObject data = sqlData.getContent();
- if (data != null) {
- dataArray.put(data);
- }
- }
- js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
- } else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) {
- note.put(NoteColumns.ID, mId);
- note.put(NoteColumns.TYPE, mType);
- note.put(NoteColumns.SNIPPET, mSnippet);
- js.put(GTaskStringUtils.META_HEAD_NOTE, note);
- }
-
- return js;
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- }
- return null;
- }
-
- public void setParentId(long id) {
- mParentId = id;
- mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
- }
-
- public void setGtaskId(String gid) {
- mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
- }
-
- public void setSyncId(long syncId) {
- mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
- }
-
- public void resetLocalModified() {
- mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
- }
-
- public long getId() {
- return mId;
- }
-
- public long getParentId() {
- return mParentId;
- }
-
- public String getSnippet() {
- return mSnippet;
- }
-
- public boolean isNoteType() {
- return mType == Notes.TYPE_NOTE;
- }
-
- public void commit(boolean validateVersion) {
- if (mIsCreate) {
- if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {
- mDiffNoteValues.remove(NoteColumns.ID);
- }
-
- Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues);
- try {
- mId = Long.valueOf(uri.getPathSegments().get(1));
- } catch (NumberFormatException e) {
- Log.e(TAG, "Get note id error :" + e.toString());
- throw new ActionFailureException("create note failed");
- }
- if (mId == 0) {
- throw new IllegalStateException("Create thread id failed");
- }
-
- if (mType == Notes.TYPE_NOTE) {
- for (SqlData sqlData : mDataList) {
- sqlData.commit(mId, false, -1);
- }
- }
- } else {
- if (mId <= 0 && mId != Notes.ID_ROOT_FOLDER && mId != Notes.ID_CALL_RECORD_FOLDER) {
- Log.e(TAG, "No such note");
- throw new IllegalStateException("Try to update note with invalid id");
- }
- if (mDiffNoteValues.size() > 0) {
- mVersion ++;
- int result = 0;
- if (!validateVersion) {
- result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
- + NoteColumns.ID + "=?)", new String[] {
- String.valueOf(mId)
- });
- } else {
- result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
- + NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)",
- new String[] {
- String.valueOf(mId), String.valueOf(mVersion)
- });
- }
- if (result == 0) {
- Log.w(TAG, "there is no update. maybe user updates note when syncing");
- }
- }
-
- if (mType == Notes.TYPE_NOTE) {
- for (SqlData sqlData : mDataList) {
- sqlData.commit(mId, validateVersion, mVersion);
- }
- }
- }
-
- // refresh local info
- loadFromCursor(mId);
- if (mType == Notes.TYPE_NOTE)
- loadDataContent();
-
- mDiffNoteValues.clear();
- mIsCreate = false;
- }
-}
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Task.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Task.java
deleted file mode 100644
index 6a19454..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Task.java
+++ /dev/null
@@ -1,351 +0,0 @@
-/*
- * 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.gtask.data;
-
-import android.database.Cursor;
-import android.text.TextUtils;
-import android.util.Log;
-
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.DataColumns;
-import net.micode.notes.data.Notes.DataConstants;
-import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.gtask.exception.ActionFailureException;
-import net.micode.notes.tool.GTaskStringUtils;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-
-public class Task extends Node {
- private static final String TAG = Task.class.getSimpleName();
-
- private boolean mCompleted;
-
- private String mNotes;
-
- private JSONObject mMetaInfo;
-
- private Task mPriorSibling;
-
- private TaskList mParent;
-
- public Task() {
- super();
- mCompleted = false;
- mNotes = null;
- mPriorSibling = null;
- mParent = null;
- mMetaInfo = null;
- }
-
- public JSONObject getCreateAction(int actionId) {
- JSONObject js = new JSONObject();
-
- try {
- // action_type
- js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
- GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE);
-
- // action_id
- js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
-
- // index
- js.put(GTaskStringUtils.GTASK_JSON_INDEX, mParent.getChildTaskIndex(this));
-
- // entity_delta
- JSONObject entity = new JSONObject();
- entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
- entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null");
- entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE,
- GTaskStringUtils.GTASK_JSON_TYPE_TASK);
- if (getNotes() != null) {
- entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes());
- }
- js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
-
- // parent_id
- js.put(GTaskStringUtils.GTASK_JSON_PARENT_ID, mParent.getGid());
-
- // dest_parent_type
- js.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT_TYPE,
- GTaskStringUtils.GTASK_JSON_TYPE_GROUP);
-
- // list_id
- js.put(GTaskStringUtils.GTASK_JSON_LIST_ID, mParent.getGid());
-
- // prior_sibling_id
- if (mPriorSibling != null) {
- js.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, mPriorSibling.getGid());
- }
-
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("fail to generate task-create jsonobject");
- }
-
- return js;
- }
-
- public JSONObject getUpdateAction(int actionId) {
- JSONObject js = new JSONObject();
-
- try {
- // action_type
- js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
- GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE);
-
- // action_id
- js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
-
- // id
- js.put(GTaskStringUtils.GTASK_JSON_ID, getGid());
-
- // entity_delta
- JSONObject entity = new JSONObject();
- entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
- if (getNotes() != null) {
- entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes());
- }
- entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted());
- js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
-
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("fail to generate task-update jsonobject");
- }
-
- return js;
- }
-
- public void setContentByRemoteJSON(JSONObject js) {
- if (js != null) {
- try {
- // id
- if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
- setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
- }
-
- // last_modified
- if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) {
- setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED));
- }
-
- // name
- if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) {
- setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME));
- }
-
- // notes
- if (js.has(GTaskStringUtils.GTASK_JSON_NOTES)) {
- setNotes(js.getString(GTaskStringUtils.GTASK_JSON_NOTES));
- }
-
- // deleted
- if (js.has(GTaskStringUtils.GTASK_JSON_DELETED)) {
- setDeleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_DELETED));
- }
-
- // completed
- if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) {
- setCompleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_COMPLETED));
- }
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("fail to get task content from jsonobject");
- }
- }
- }
-
- public void setContentByLocalJSON(JSONObject js) {
- if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)
- || !js.has(GTaskStringUtils.META_HEAD_DATA)) {
- Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
- }
-
- try {
- JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
- JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
-
- if (note.getInt(NoteColumns.TYPE) != Notes.TYPE_NOTE) {
- Log.e(TAG, "invalid type");
- return;
- }
-
- for (int i = 0; i < dataArray.length(); i++) {
- JSONObject data = dataArray.getJSONObject(i);
- if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
- setName(data.getString(DataColumns.CONTENT));
- break;
- }
- }
-
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- }
- }
-
- public JSONObject getLocalJSONFromContent() {
- String name = getName();
- try {
- if (mMetaInfo == null) {
- // new task created from web
- if (name == null) {
- Log.w(TAG, "the note seems to be an empty one");
- return null;
- }
-
- JSONObject js = new JSONObject();
- JSONObject note = new JSONObject();
- JSONArray dataArray = new JSONArray();
- JSONObject data = new JSONObject();
- data.put(DataColumns.CONTENT, name);
- dataArray.put(data);
- js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
- note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
- js.put(GTaskStringUtils.META_HEAD_NOTE, note);
- return js;
- } else {
- // synced task
- JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
- JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
-
- for (int i = 0; i < dataArray.length(); i++) {
- JSONObject data = dataArray.getJSONObject(i);
- if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
- data.put(DataColumns.CONTENT, getName());
- break;
- }
- }
-
- note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
- return mMetaInfo;
- }
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- return null;
- }
- }
-
- public void setMetaInfo(MetaData metaData) {
- if (metaData != null && metaData.getNotes() != null) {
- try {
- mMetaInfo = new JSONObject(metaData.getNotes());
- } catch (JSONException e) {
- Log.w(TAG, e.toString());
- mMetaInfo = null;
- }
- }
- }
-
- public int getSyncAction(Cursor c) {
- try {
- JSONObject noteInfo = null;
- if (mMetaInfo != null && mMetaInfo.has(GTaskStringUtils.META_HEAD_NOTE)) {
- noteInfo = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
- }
-
- if (noteInfo == null) {
- Log.w(TAG, "it seems that note meta has been deleted");
- return SYNC_ACTION_UPDATE_REMOTE;
- }
-
- if (!noteInfo.has(NoteColumns.ID)) {
- Log.w(TAG, "remote note id seems to be deleted");
- return SYNC_ACTION_UPDATE_LOCAL;
- }
-
- // validate the note id now
- if (c.getLong(SqlNote.ID_COLUMN) != noteInfo.getLong(NoteColumns.ID)) {
- Log.w(TAG, "note id doesn't match");
- return SYNC_ACTION_UPDATE_LOCAL;
- }
-
- if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
- // there is no local update
- if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
- // no update both side
- return SYNC_ACTION_NONE;
- } else {
- // apply remote to local
- return SYNC_ACTION_UPDATE_LOCAL;
- }
- } else {
- // validate gtask id
- if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) {
- Log.e(TAG, "gtask id doesn't match");
- return SYNC_ACTION_ERROR;
- }
- if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
- // local modification only
- return SYNC_ACTION_UPDATE_REMOTE;
- } else {
- return SYNC_ACTION_UPDATE_CONFLICT;
- }
- }
- } catch (Exception e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- }
-
- return SYNC_ACTION_ERROR;
- }
-
- public boolean isWorthSaving() {
- return mMetaInfo != null || (getName() != null && getName().trim().length() > 0)
- || (getNotes() != null && getNotes().trim().length() > 0);
- }
-
- public void setCompleted(boolean completed) {
- this.mCompleted = completed;
- }
-
- public void setNotes(String notes) {
- this.mNotes = notes;
- }
-
- public void setPriorSibling(Task priorSibling) {
- this.mPriorSibling = priorSibling;
- }
-
- public void setParent(TaskList parent) {
- this.mParent = parent;
- }
-
- public boolean getCompleted() {
- return this.mCompleted;
- }
-
- public String getNotes() {
- return this.mNotes;
- }
-
- public Task getPriorSibling() {
- return this.mPriorSibling;
- }
-
- public TaskList getParent() {
- return this.mParent;
- }
-
-}
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/TaskList.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/TaskList.java
deleted file mode 100644
index 4ea21c5..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/TaskList.java
+++ /dev/null
@@ -1,343 +0,0 @@
-/*
- * 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.gtask.data;
-
-import android.database.Cursor;
-import android.util.Log;
-
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.gtask.exception.ActionFailureException;
-import net.micode.notes.tool.GTaskStringUtils;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.util.ArrayList;
-
-
-public class TaskList extends Node {
- private static final String TAG = TaskList.class.getSimpleName();
-
- private int mIndex;
-
- private ArrayList mChildren;
-
- public TaskList() {
- super();
- mChildren = new ArrayList();
- mIndex = 1;
- }
-
- public JSONObject getCreateAction(int actionId) {
- JSONObject js = new JSONObject();
-
- try {
- // action_type
- js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
- GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE);
-
- // action_id
- js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
-
- // index
- js.put(GTaskStringUtils.GTASK_JSON_INDEX, mIndex);
-
- // entity_delta
- JSONObject entity = new JSONObject();
- entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
- entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null");
- entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE,
- GTaskStringUtils.GTASK_JSON_TYPE_GROUP);
- js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
-
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("fail to generate tasklist-create jsonobject");
- }
-
- return js;
- }
-
- public JSONObject getUpdateAction(int actionId) {
- JSONObject js = new JSONObject();
-
- try {
- // action_type
- js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
- GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE);
-
- // action_id
- js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
-
- // id
- js.put(GTaskStringUtils.GTASK_JSON_ID, getGid());
-
- // entity_delta
- JSONObject entity = new JSONObject();
- entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
- entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted());
- js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
-
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("fail to generate tasklist-update jsonobject");
- }
-
- return js;
- }
-
- public void setContentByRemoteJSON(JSONObject js) {
- if (js != null) {
- try {
- // id
- if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
- setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
- }
-
- // last_modified
- if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) {
- setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED));
- }
-
- // name
- if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) {
- setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME));
- }
-
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("fail to get tasklist content from jsonobject");
- }
- }
- }
-
- public void setContentByLocalJSON(JSONObject js) {
- if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) {
- Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
- }
-
- try {
- JSONObject folder = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
-
- if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) {
- String name = folder.getString(NoteColumns.SNIPPET);
- setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + name);
- } else if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
- if (folder.getLong(NoteColumns.ID) == Notes.ID_ROOT_FOLDER)
- setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT);
- else if (folder.getLong(NoteColumns.ID) == Notes.ID_CALL_RECORD_FOLDER)
- setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX
- + GTaskStringUtils.FOLDER_CALL_NOTE);
- else
- Log.e(TAG, "invalid system folder");
- } else {
- Log.e(TAG, "error type");
- }
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- }
- }
-
- public JSONObject getLocalJSONFromContent() {
- try {
- JSONObject js = new JSONObject();
- JSONObject folder = new JSONObject();
-
- String folderName = getName();
- if (getName().startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX))
- folderName = folderName.substring(GTaskStringUtils.MIUI_FOLDER_PREFFIX.length(),
- folderName.length());
- folder.put(NoteColumns.SNIPPET, folderName);
- if (folderName.equals(GTaskStringUtils.FOLDER_DEFAULT)
- || folderName.equals(GTaskStringUtils.FOLDER_CALL_NOTE))
- folder.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
- else
- folder.put(NoteColumns.TYPE, Notes.TYPE_FOLDER);
-
- js.put(GTaskStringUtils.META_HEAD_NOTE, folder);
-
- return js;
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- return null;
- }
- }
-
- public int getSyncAction(Cursor c) {
- try {
- if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
- // there is no local update
- if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
- // no update both side
- return SYNC_ACTION_NONE;
- } else {
- // apply remote to local
- return SYNC_ACTION_UPDATE_LOCAL;
- }
- } else {
- // validate gtask id
- if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) {
- Log.e(TAG, "gtask id doesn't match");
- return SYNC_ACTION_ERROR;
- }
- if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
- // local modification only
- return SYNC_ACTION_UPDATE_REMOTE;
- } else {
- // for folder conflicts, just apply local modification
- return SYNC_ACTION_UPDATE_REMOTE;
- }
- }
- } catch (Exception e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- }
-
- return SYNC_ACTION_ERROR;
- }
-
- public int getChildTaskCount() {
- return mChildren.size();
- }
-
- public boolean addChildTask(Task task) {
- boolean ret = false;
- if (task != null && !mChildren.contains(task)) {
- ret = mChildren.add(task);
- if (ret) {
- // need to set prior sibling and parent
- task.setPriorSibling(mChildren.isEmpty() ? null : mChildren
- .get(mChildren.size() - 1));
- task.setParent(this);
- }
- }
- return ret;
- }
-
- public boolean addChildTask(Task task, int index) {
- if (index < 0 || index > mChildren.size()) {
- Log.e(TAG, "add child task: invalid index");
- return false;
- }
-
- int pos = mChildren.indexOf(task);
- if (task != null && pos == -1) {
- mChildren.add(index, task);
-
- // update the task list
- Task preTask = null;
- Task afterTask = null;
- if (index != 0)
- preTask = mChildren.get(index - 1);
- if (index != mChildren.size() - 1)
- afterTask = mChildren.get(index + 1);
-
- task.setPriorSibling(preTask);
- if (afterTask != null)
- afterTask.setPriorSibling(task);
- }
-
- return true;
- }
-
- public boolean removeChildTask(Task task) {
- boolean ret = false;
- int index = mChildren.indexOf(task);
- if (index != -1) {
- ret = mChildren.remove(task);
-
- if (ret) {
- // reset prior sibling and parent
- task.setPriorSibling(null);
- task.setParent(null);
-
- // update the task list
- if (index != mChildren.size()) {
- mChildren.get(index).setPriorSibling(
- index == 0 ? null : mChildren.get(index - 1));
- }
- }
- }
- return ret;
- }
-
- public boolean moveChildTask(Task task, int index) {
-
- if (index < 0 || index >= mChildren.size()) {
- Log.e(TAG, "move child task: invalid index");
- return false;
- }
-
- int pos = mChildren.indexOf(task);
- if (pos == -1) {
- Log.e(TAG, "move child task: the task should in the list");
- return false;
- }
-
- if (pos == index)
- return true;
- return (removeChildTask(task) && addChildTask(task, index));
- }
-
- public Task findChildTaskByGid(String gid) {
- for (int i = 0; i < mChildren.size(); i++) {
- Task t = mChildren.get(i);
- if (t.getGid().equals(gid)) {
- return t;
- }
- }
- return null;
- }
-
- public int getChildTaskIndex(Task task) {
- return mChildren.indexOf(task);
- }
-
- public Task getChildTaskByIndex(int index) {
- if (index < 0 || index >= mChildren.size()) {
- Log.e(TAG, "getTaskByIndex: invalid index");
- return null;
- }
- return mChildren.get(index);
- }
-
- public Task getChilTaskByGid(String gid) {
- for (Task task : mChildren) {
- if (task.getGid().equals(gid))
- return task;
- }
- return null;
- }
-
- public ArrayList getChildTaskList() {
- return this.mChildren;
- }
-
- public void setIndex(int index) {
- this.mIndex = index;
- }
-
- public int getIndex() {
- return this.mIndex;
- }
-}
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/exception/ActionFailureException.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/exception/ActionFailureException.java
deleted file mode 100644
index 15504be..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/exception/ActionFailureException.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.gtask.exception;
-
-public class ActionFailureException extends RuntimeException {
- private static final long serialVersionUID = 4425249765923293627L;
-
- public ActionFailureException() {
- super();
- }
-
- public ActionFailureException(String paramString) {
- super(paramString);
- }
-
- public ActionFailureException(String paramString, Throwable paramThrowable) {
- super(paramString, paramThrowable);
- }
-}
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/exception/NetworkFailureException.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/exception/NetworkFailureException.java
deleted file mode 100644
index b08cfb1..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/exception/NetworkFailureException.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.gtask.exception;
-
-public class NetworkFailureException extends Exception {
- private static final long serialVersionUID = 2107610287180234136L;
-
- public NetworkFailureException() {
- super();
- }
-
- public NetworkFailureException(String paramString) {
- super(paramString);
- }
-
- public NetworkFailureException(String paramString, Throwable paramThrowable) {
- super(paramString, paramThrowable);
- }
-}
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java
deleted file mode 100644
index 5c17c8c..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * 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.gtask.remote;
-
-import android.app.NotificationChannel;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.os.AsyncTask;
-import android.os.Build;
-
-import androidx.core.app.NotificationCompat; // 引入AndroidX通知兼容类
-
-import net.micode.notes.R;
-import net.micode.notes.ui.NotesListActivity;
-import net.micode.notes.ui.NotesPreferenceActivity;
-
-
-public class GTaskASyncTask extends AsyncTask {
-
- private static int GTASK_SYNC_NOTIFICATION_ID = 5234235;
- private static final String NOTIFICATION_CHANNEL_ID = "gtask_sync_channel"; // 通知渠道ID(唯一)
-
- public interface OnCompleteListener {
- void onComplete();
- }
-
- private Context mContext;
- private NotificationManager mNotifiManager;
- private GTaskManager mTaskManager;
- private OnCompleteListener mOnCompleteListener;
-
- public GTaskASyncTask(Context context, OnCompleteListener listener) {
- mContext = context;
- mOnCompleteListener = listener;
- mNotifiManager = (NotificationManager) mContext
- .getSystemService(Context.NOTIFICATION_SERVICE);
- mTaskManager = GTaskManager.getInstance();
- // 初始化通知渠道(仅首次创建时需要)
- createNotificationChannel();
- }
-
- // 创建Android 8.0+通知渠道
- private void createNotificationChannel() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- // 渠道名称(用户可见,可从strings.xml获取)
- CharSequence channelName = mContext.getString(R.string.app_name);
- // 渠道描述(用户可见)
- String channelDescription = mContext.getString(R.string.sync_notification_channel_desc);
- // 通知重要性(默认级别)
- int importance = NotificationManager.IMPORTANCE_DEFAULT;
- // 创建渠道
- NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, importance);
- channel.setDescription(channelDescription);
- // 注册渠道到系统
- mNotifiManager.createNotificationChannel(channel);
- }
- }
-
- public void cancelSync() {
- mTaskManager.cancelSync();
- }
-
- public void publishProgess(String message) {
- publishProgress(new String[] {message});
- }
-
- // 修改后的通知显示方法(替代setLatestEventInfo)
- private void showNotification(int tickerId, String content) {
- // 1. 构建点击通知的跳转意图(保持原有逻辑)
- PendingIntent pendingIntent;
- if (tickerId != R.string.ticker_success) {
- // 非成功状态:跳转到设置页面
- pendingIntent = PendingIntent.getActivity(
- mContext,
- 0,
- new Intent(mContext, NotesPreferenceActivity.class),
- PendingIntent.FLAG_IMMUTABLE // 适配API 31+的标志位
- );
- } else {
- // 成功状态:跳转到便签列表
- pendingIntent = PendingIntent.getActivity(
- mContext,
- 0,
- new Intent(mContext, NotesListActivity.class),
- PendingIntent.FLAG_IMMUTABLE
- );
- }
-
- // 2. 使用NotificationCompat.Builder构建通知(兼容所有版本)
- NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, NOTIFICATION_CHANNEL_ID)
- .setSmallIcon(R.drawable.notification) // 通知小图标(必须设置)
- .setTicker(mContext.getString(tickerId)) // 通知栏短暂提示文字(对应原tickerId)
- .setContentTitle(mContext.getString(R.string.app_name)) // 通知标题(原setLatestEventInfo的标题)
- .setContentText(content) // 通知内容(原setLatestEventInfo的内容)
- .setContentIntent(pendingIntent) // 点击意图(原setLatestEventInfo的intent)
- .setWhen(System.currentTimeMillis()) // 通知时间(原构造函数的时间)
- .setDefaults(NotificationCompat.DEFAULT_LIGHTS) // 灯光默认(原notification.defaults)
- .setAutoCancel(true); // 点击后自动消失(原notification.flags的FLAG_AUTO_CANCEL)
-
- // 3. 发送通知
- mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, builder.build());
- }
-
- @Override
- protected Integer doInBackground(Void... unused) {
- publishProgess(mContext.getString(R.string.sync_progress_login, NotesPreferenceActivity
- .getSyncAccountName(mContext)));
- return mTaskManager.sync(mContext, this);
- }
-
- @Override
- protected void onProgressUpdate(String... progress) {
- showNotification(R.string.ticker_syncing, progress[0]);
- if (mContext instanceof GTaskSyncService) {
- ((GTaskSyncService) mContext).sendBroadcast(progress[0]);
- }
- }
-
- @Override
- protected void onPostExecute(Integer result) {
- if (result == GTaskManager.STATE_SUCCESS) {
- showNotification(R.string.ticker_success, mContext.getString(
- R.string.success_sync_account, mTaskManager.getSyncAccount()));
- NotesPreferenceActivity.setLastSyncTime(mContext, System.currentTimeMillis());
- } else if (result == GTaskManager.STATE_NETWORK_ERROR) {
- showNotification(R.string.ticker_fail, mContext.getString(R.string.error_sync_network));
- } else if (result == GTaskManager.STATE_INTERNAL_ERROR) {
- showNotification(R.string.ticker_fail, mContext.getString(R.string.error_sync_internal));
- } else if (result == GTaskManager.STATE_SYNC_CANCELLED) {
- showNotification(R.string.ticker_cancel, mContext
- .getString(R.string.error_sync_cancelled));
- }
- if (mOnCompleteListener != null) {
- new Thread(new Runnable() {
- public void run() {
- mOnCompleteListener.onComplete();
- }
- }).start();
- }
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java
deleted file mode 100644
index c67dfdf..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java
+++ /dev/null
@@ -1,585 +0,0 @@
-/*
- * 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.gtask.remote;
-
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.accounts.AccountManagerFuture;
-import android.app.Activity;
-import android.os.Bundle;
-import android.text.TextUtils;
-import android.util.Log;
-
-import net.micode.notes.gtask.data.Node;
-import net.micode.notes.gtask.data.Task;
-import net.micode.notes.gtask.data.TaskList;
-import net.micode.notes.gtask.exception.ActionFailureException;
-import net.micode.notes.gtask.exception.NetworkFailureException;
-import net.micode.notes.tool.GTaskStringUtils;
-import net.micode.notes.ui.NotesPreferenceActivity;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.cookie.Cookie;
-import org.apache.http.impl.client.BasicCookieStore;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.message.BasicNameValuePair;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpProtocolParams;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.Inflater;
-import java.util.zip.InflaterInputStream;
-
-
-public class GTaskClient {
- private static final String TAG = GTaskClient.class.getSimpleName();
-
- private static final String GTASK_URL = "https://mail.google.com/tasks/";
-
- private static final String GTASK_GET_URL = "https://mail.google.com/tasks/ig";
-
- private static final String GTASK_POST_URL = "https://mail.google.com/tasks/r/ig";
-
- private static GTaskClient mInstance = null;
-
- private DefaultHttpClient mHttpClient;
-
- private String mGetUrl;
-
- private String mPostUrl;
-
- private long mClientVersion;
-
- private boolean mLoggedin;
-
- private long mLastLoginTime;
-
- private int mActionId;
-
- private Account mAccount;
-
- private JSONArray mUpdateArray;
-
- private GTaskClient() {
- mHttpClient = null;
- mGetUrl = GTASK_GET_URL;
- mPostUrl = GTASK_POST_URL;
- mClientVersion = -1;
- mLoggedin = false;
- mLastLoginTime = 0;
- mActionId = 1;
- mAccount = null;
- mUpdateArray = null;
- }
-
- public static synchronized GTaskClient getInstance() {
- if (mInstance == null) {
- mInstance = new GTaskClient();
- }
- return mInstance;
- }
-
- public boolean login(Activity activity) {
- // we suppose that the cookie would expire after 5 minutes
- // then we need to re-login
- final long interval = 1000 * 60 * 5;
- if (mLastLoginTime + interval < System.currentTimeMillis()) {
- mLoggedin = false;
- }
-
- // need to re-login after account switch
- if (mLoggedin
- && !TextUtils.equals(getSyncAccount().name, NotesPreferenceActivity
- .getSyncAccountName(activity))) {
- mLoggedin = false;
- }
-
- if (mLoggedin) {
- Log.d(TAG, "already logged in");
- return true;
- }
-
- mLastLoginTime = System.currentTimeMillis();
- String authToken = loginGoogleAccount(activity, false);
- if (authToken == null) {
- Log.e(TAG, "login google account failed");
- return false;
- }
-
- // login with custom domain if necessary
- if (!(mAccount.name.toLowerCase().endsWith("gmail.com") || mAccount.name.toLowerCase()
- .endsWith("googlemail.com"))) {
- StringBuilder url = new StringBuilder(GTASK_URL).append("a/");
- int index = mAccount.name.indexOf('@') + 1;
- String suffix = mAccount.name.substring(index);
- url.append(suffix + "/");
- mGetUrl = url.toString() + "ig";
- mPostUrl = url.toString() + "r/ig";
-
- if (tryToLoginGtask(activity, authToken)) {
- mLoggedin = true;
- }
- }
-
- // try to login with google official url
- if (!mLoggedin) {
- mGetUrl = GTASK_GET_URL;
- mPostUrl = GTASK_POST_URL;
- if (!tryToLoginGtask(activity, authToken)) {
- return false;
- }
- }
-
- mLoggedin = true;
- return true;
- }
-
- private String loginGoogleAccount(Activity activity, boolean invalidateToken) {
- String authToken;
- AccountManager accountManager = AccountManager.get(activity);
- Account[] accounts = accountManager.getAccountsByType("com.google");
-
- if (accounts.length == 0) {
- Log.e(TAG, "there is no available google account");
- return null;
- }
-
- String accountName = NotesPreferenceActivity.getSyncAccountName(activity);
- Account account = null;
- for (Account a : accounts) {
- if (a.name.equals(accountName)) {
- account = a;
- break;
- }
- }
- if (account != null) {
- mAccount = account;
- } else {
- Log.e(TAG, "unable to get an account with the same name in the settings");
- return null;
- }
-
- // get the token now
- AccountManagerFuture accountManagerFuture = accountManager.getAuthToken(account,
- "goanna_mobile", null, activity, null, null);
- try {
- Bundle authTokenBundle = accountManagerFuture.getResult();
- authToken = authTokenBundle.getString(AccountManager.KEY_AUTHTOKEN);
- if (invalidateToken) {
- accountManager.invalidateAuthToken("com.google", authToken);
- loginGoogleAccount(activity, false);
- }
- } catch (Exception e) {
- Log.e(TAG, "get auth token failed");
- authToken = null;
- }
-
- return authToken;
- }
-
- private boolean tryToLoginGtask(Activity activity, String authToken) {
- if (!loginGtask(authToken)) {
- // maybe the auth token is out of date, now let's invalidate the
- // token and try again
- authToken = loginGoogleAccount(activity, true);
- if (authToken == null) {
- Log.e(TAG, "login google account failed");
- return false;
- }
-
- if (!loginGtask(authToken)) {
- Log.e(TAG, "login gtask failed");
- return false;
- }
- }
- return true;
- }
-
- private boolean loginGtask(String authToken) {
- int timeoutConnection = 10000;
- int timeoutSocket = 15000;
- HttpParams httpParameters = new BasicHttpParams();
- HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
- HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
- mHttpClient = new DefaultHttpClient(httpParameters);
- BasicCookieStore localBasicCookieStore = new BasicCookieStore();
- mHttpClient.setCookieStore(localBasicCookieStore);
- HttpProtocolParams.setUseExpectContinue(mHttpClient.getParams(), false);
-
- // login gtask
- try {
- String loginUrl = mGetUrl + "?auth=" + authToken;
- HttpGet httpGet = new HttpGet(loginUrl);
- HttpResponse response = null;
- response = mHttpClient.execute(httpGet);
-
- // get the cookie now
- List cookies = mHttpClient.getCookieStore().getCookies();
- boolean hasAuthCookie = false;
- for (Cookie cookie : cookies) {
- if (cookie.getName().contains("GTL")) {
- hasAuthCookie = true;
- }
- }
- if (!hasAuthCookie) {
- Log.w(TAG, "it seems that there is no auth cookie");
- }
-
- // get the client version
- String resString = getResponseContent(response.getEntity());
- String jsBegin = "_setup(";
- String jsEnd = ")}";
- int begin = resString.indexOf(jsBegin);
- int end = resString.lastIndexOf(jsEnd);
- String jsString = null;
- if (begin != -1 && end != -1 && begin < end) {
- jsString = resString.substring(begin + jsBegin.length(), end);
- }
- JSONObject js = new JSONObject(jsString);
- mClientVersion = js.getLong("v");
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- return false;
- } catch (Exception e) {
- // simply catch all exceptions
- Log.e(TAG, "httpget gtask_url failed");
- return false;
- }
-
- return true;
- }
-
- private int getActionId() {
- return mActionId++;
- }
-
- private HttpPost createHttpPost() {
- HttpPost httpPost = new HttpPost(mPostUrl);
- httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
- httpPost.setHeader("AT", "1");
- return httpPost;
- }
-
- private String getResponseContent(HttpEntity entity) throws IOException {
- String contentEncoding = null;
- if (entity.getContentEncoding() != null) {
- contentEncoding = entity.getContentEncoding().getValue();
- Log.d(TAG, "encoding: " + contentEncoding);
- }
-
- InputStream input = entity.getContent();
- if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) {
- input = new GZIPInputStream(entity.getContent());
- } else if (contentEncoding != null && contentEncoding.equalsIgnoreCase("deflate")) {
- Inflater inflater = new Inflater(true);
- input = new InflaterInputStream(entity.getContent(), inflater);
- }
-
- try {
- InputStreamReader isr = new InputStreamReader(input);
- BufferedReader br = new BufferedReader(isr);
- StringBuilder sb = new StringBuilder();
-
- while (true) {
- String buff = br.readLine();
- if (buff == null) {
- return sb.toString();
- }
- sb = sb.append(buff);
- }
- } finally {
- input.close();
- }
- }
-
- private JSONObject postRequest(JSONObject js) throws NetworkFailureException {
- if (!mLoggedin) {
- Log.e(TAG, "please login first");
- throw new ActionFailureException("not logged in");
- }
-
- HttpPost httpPost = createHttpPost();
- try {
- LinkedList list = new LinkedList();
- list.add(new BasicNameValuePair("r", js.toString()));
- UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, "UTF-8");
- httpPost.setEntity(entity);
-
- // execute the post
- HttpResponse response = mHttpClient.execute(httpPost);
- String jsString = getResponseContent(response.getEntity());
- return new JSONObject(jsString);
-
- } catch (ClientProtocolException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new NetworkFailureException("postRequest failed");
- } catch (IOException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new NetworkFailureException("postRequest failed");
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("unable to convert response content to jsonobject");
- } catch (Exception e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("error occurs when posting request");
- }
- }
-
- public void createTask(Task task) throws NetworkFailureException {
- commitUpdate();
- try {
- JSONObject jsPost = new JSONObject();
- JSONArray actionList = new JSONArray();
-
- // action_list
- actionList.put(task.getCreateAction(getActionId()));
- jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList);
-
- // client_version
- jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
-
- // post
- JSONObject jsResponse = postRequest(jsPost);
- JSONObject jsResult = (JSONObject) jsResponse.getJSONArray(
- GTaskStringUtils.GTASK_JSON_RESULTS).get(0);
- task.setGid(jsResult.getString(GTaskStringUtils.GTASK_JSON_NEW_ID));
-
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("create task: handing jsonobject failed");
- }
- }
-
- public void createTaskList(TaskList tasklist) throws NetworkFailureException {
- commitUpdate();
- try {
- JSONObject jsPost = new JSONObject();
- JSONArray actionList = new JSONArray();
-
- // action_list
- actionList.put(tasklist.getCreateAction(getActionId()));
- jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList);
-
- // client version
- jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
-
- // post
- JSONObject jsResponse = postRequest(jsPost);
- JSONObject jsResult = (JSONObject) jsResponse.getJSONArray(
- GTaskStringUtils.GTASK_JSON_RESULTS).get(0);
- tasklist.setGid(jsResult.getString(GTaskStringUtils.GTASK_JSON_NEW_ID));
-
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("create tasklist: handing jsonobject failed");
- }
- }
-
- public void commitUpdate() throws NetworkFailureException {
- if (mUpdateArray != null) {
- try {
- JSONObject jsPost = new JSONObject();
-
- // action_list
- jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, mUpdateArray);
-
- // client_version
- jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
-
- postRequest(jsPost);
- mUpdateArray = null;
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("commit update: handing jsonobject failed");
- }
- }
- }
-
- public void addUpdateNode(Node node) throws NetworkFailureException {
- if (node != null) {
- // too many update items may result in an error
- // set max to 10 items
- if (mUpdateArray != null && mUpdateArray.length() > 10) {
- commitUpdate();
- }
-
- if (mUpdateArray == null)
- mUpdateArray = new JSONArray();
- mUpdateArray.put(node.getUpdateAction(getActionId()));
- }
- }
-
- public void moveTask(Task task, TaskList preParent, TaskList curParent)
- throws NetworkFailureException {
- commitUpdate();
- try {
- JSONObject jsPost = new JSONObject();
- JSONArray actionList = new JSONArray();
- JSONObject action = new JSONObject();
-
- // action_list
- action.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
- GTaskStringUtils.GTASK_JSON_ACTION_TYPE_MOVE);
- action.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, getActionId());
- action.put(GTaskStringUtils.GTASK_JSON_ID, task.getGid());
- if (preParent == curParent && task.getPriorSibling() != null) {
- // put prioring_sibing_id only if moving within the tasklist and
- // it is not the first one
- action.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, task.getPriorSibling());
- }
- action.put(GTaskStringUtils.GTASK_JSON_SOURCE_LIST, preParent.getGid());
- action.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT, curParent.getGid());
- if (preParent != curParent) {
- // put the dest_list only if moving between tasklists
- action.put(GTaskStringUtils.GTASK_JSON_DEST_LIST, curParent.getGid());
- }
- actionList.put(action);
- jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList);
-
- // client_version
- jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
-
- postRequest(jsPost);
-
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("move task: handing jsonobject failed");
- }
- }
-
- public void deleteNode(Node node) throws NetworkFailureException {
- commitUpdate();
- try {
- JSONObject jsPost = new JSONObject();
- JSONArray actionList = new JSONArray();
-
- // action_list
- node.setDeleted(true);
- actionList.put(node.getUpdateAction(getActionId()));
- jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList);
-
- // client_version
- jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
-
- postRequest(jsPost);
- mUpdateArray = null;
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("delete node: handing jsonobject failed");
- }
- }
-
- public JSONArray getTaskLists() throws NetworkFailureException {
- if (!mLoggedin) {
- Log.e(TAG, "please login first");
- throw new ActionFailureException("not logged in");
- }
-
- try {
- HttpGet httpGet = new HttpGet(mGetUrl);
- HttpResponse response = null;
- response = mHttpClient.execute(httpGet);
-
- // get the task list
- String resString = getResponseContent(response.getEntity());
- String jsBegin = "_setup(";
- String jsEnd = ")}";
- int begin = resString.indexOf(jsBegin);
- int end = resString.lastIndexOf(jsEnd);
- String jsString = null;
- if (begin != -1 && end != -1 && begin < end) {
- jsString = resString.substring(begin + jsBegin.length(), end);
- }
- JSONObject js = new JSONObject(jsString);
- return js.getJSONObject("t").getJSONArray(GTaskStringUtils.GTASK_JSON_LISTS);
- } catch (ClientProtocolException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new NetworkFailureException("gettasklists: httpget failed");
- } catch (IOException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new NetworkFailureException("gettasklists: httpget failed");
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("get task lists: handing jasonobject failed");
- }
- }
-
- public JSONArray getTaskList(String listGid) throws NetworkFailureException {
- commitUpdate();
- try {
- JSONObject jsPost = new JSONObject();
- JSONArray actionList = new JSONArray();
- JSONObject action = new JSONObject();
-
- // action_list
- action.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
- GTaskStringUtils.GTASK_JSON_ACTION_TYPE_GETALL);
- action.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, getActionId());
- action.put(GTaskStringUtils.GTASK_JSON_LIST_ID, listGid);
- action.put(GTaskStringUtils.GTASK_JSON_GET_DELETED, false);
- actionList.put(action);
- jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList);
-
- // client_version
- jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
-
- JSONObject jsResponse = postRequest(jsPost);
- return jsResponse.getJSONArray(GTaskStringUtils.GTASK_JSON_TASKS);
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("get task list: handing jsonobject failed");
- }
- }
-
- public Account getSyncAccount() {
- return mAccount;
- }
-
- public void resetUpdateArray() {
- mUpdateArray = null;
- }
-}
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java
deleted file mode 100644
index d2b4082..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java
+++ /dev/null
@@ -1,800 +0,0 @@
-/*
- * 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.gtask.remote;
-
-import android.app.Activity;
-import android.content.ContentResolver;
-import android.content.ContentUris;
-import android.content.ContentValues;
-import android.content.Context;
-import android.database.Cursor;
-import android.util.Log;
-
-import net.micode.notes.R;
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.DataColumns;
-import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.gtask.data.MetaData;
-import net.micode.notes.gtask.data.Node;
-import net.micode.notes.gtask.data.SqlNote;
-import net.micode.notes.gtask.data.Task;
-import net.micode.notes.gtask.data.TaskList;
-import net.micode.notes.gtask.exception.ActionFailureException;
-import net.micode.notes.gtask.exception.NetworkFailureException;
-import net.micode.notes.tool.DataUtils;
-import net.micode.notes.tool.GTaskStringUtils;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-
-
-public class GTaskManager {
- private static final String TAG = GTaskManager.class.getSimpleName();
-
- public static final int STATE_SUCCESS = 0;
-
- public static final int STATE_NETWORK_ERROR = 1;
-
- public static final int STATE_INTERNAL_ERROR = 2;
-
- public static final int STATE_SYNC_IN_PROGRESS = 3;
-
- public static final int STATE_SYNC_CANCELLED = 4;
-
- private static GTaskManager mInstance = null;
-
- private Activity mActivity;
-
- private Context mContext;
-
- private ContentResolver mContentResolver;
-
- private boolean mSyncing;
-
- private boolean mCancelled;
-
- private HashMap mGTaskListHashMap;
-
- private HashMap mGTaskHashMap;
-
- private HashMap mMetaHashMap;
-
- private TaskList mMetaList;
-
- private HashSet mLocalDeleteIdMap;
-
- private HashMap mGidToNid;
-
- private HashMap mNidToGid;
-
- private GTaskManager() {
- mSyncing = false;
- mCancelled = false;
- mGTaskListHashMap = new HashMap();
- mGTaskHashMap = new HashMap();
- mMetaHashMap = new HashMap();
- mMetaList = null;
- mLocalDeleteIdMap = new HashSet();
- mGidToNid = new HashMap();
- mNidToGid = new HashMap();
- }
-
- public static synchronized GTaskManager getInstance() {
- if (mInstance == null) {
- mInstance = new GTaskManager();
- }
- return mInstance;
- }
-
- public synchronized void setActivityContext(Activity activity) {
- // used for getting authtoken
- mActivity = activity;
- }
-
- public int sync(Context context, GTaskASyncTask asyncTask) {
- if (mSyncing) {
- Log.d(TAG, "Sync is in progress");
- return STATE_SYNC_IN_PROGRESS;
- }
- mContext = context;
- mContentResolver = mContext.getContentResolver();
- mSyncing = true;
- mCancelled = false;
- mGTaskListHashMap.clear();
- mGTaskHashMap.clear();
- mMetaHashMap.clear();
- mLocalDeleteIdMap.clear();
- mGidToNid.clear();
- mNidToGid.clear();
-
- try {
- GTaskClient client = GTaskClient.getInstance();
- client.resetUpdateArray();
-
- // login google task
- if (!mCancelled) {
- if (!client.login(mActivity)) {
- throw new NetworkFailureException("login google task failed");
- }
- }
-
- // get the task list from google
- asyncTask.publishProgess(mContext.getString(R.string.sync_progress_init_list));
- initGTaskList();
-
- // do content sync work
- asyncTask.publishProgess(mContext.getString(R.string.sync_progress_syncing));
- syncContent();
- } catch (NetworkFailureException e) {
- Log.e(TAG, e.toString());
- return STATE_NETWORK_ERROR;
- } catch (ActionFailureException e) {
- Log.e(TAG, e.toString());
- return STATE_INTERNAL_ERROR;
- } catch (Exception e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- return STATE_INTERNAL_ERROR;
- } finally {
- mGTaskListHashMap.clear();
- mGTaskHashMap.clear();
- mMetaHashMap.clear();
- mLocalDeleteIdMap.clear();
- mGidToNid.clear();
- mNidToGid.clear();
- mSyncing = false;
- }
-
- return mCancelled ? STATE_SYNC_CANCELLED : STATE_SUCCESS;
- }
-
- private void initGTaskList() throws NetworkFailureException {
- if (mCancelled)
- return;
- GTaskClient client = GTaskClient.getInstance();
- try {
- JSONArray jsTaskLists = client.getTaskLists();
-
- // init meta list first
- mMetaList = null;
- for (int i = 0; i < jsTaskLists.length(); i++) {
- JSONObject object = jsTaskLists.getJSONObject(i);
- String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID);
- String name = object.getString(GTaskStringUtils.GTASK_JSON_NAME);
-
- if (name
- .equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_META)) {
- mMetaList = new TaskList();
- mMetaList.setContentByRemoteJSON(object);
-
- // load meta data
- JSONArray jsMetas = client.getTaskList(gid);
- for (int j = 0; j < jsMetas.length(); j++) {
- object = (JSONObject) jsMetas.getJSONObject(j);
- MetaData metaData = new MetaData();
- metaData.setContentByRemoteJSON(object);
- if (metaData.isWorthSaving()) {
- mMetaList.addChildTask(metaData);
- if (metaData.getGid() != null) {
- mMetaHashMap.put(metaData.getRelatedGid(), metaData);
- }
- }
- }
- }
- }
-
- // create meta list if not existed
- if (mMetaList == null) {
- mMetaList = new TaskList();
- mMetaList.setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX
- + GTaskStringUtils.FOLDER_META);
- GTaskClient.getInstance().createTaskList(mMetaList);
- }
-
- // init task list
- for (int i = 0; i < jsTaskLists.length(); i++) {
- JSONObject object = jsTaskLists.getJSONObject(i);
- String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID);
- String name = object.getString(GTaskStringUtils.GTASK_JSON_NAME);
-
- if (name.startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX)
- && !name.equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX
- + GTaskStringUtils.FOLDER_META)) {
- TaskList tasklist = new TaskList();
- tasklist.setContentByRemoteJSON(object);
- mGTaskListHashMap.put(gid, tasklist);
- mGTaskHashMap.put(gid, tasklist);
-
- // load tasks
- JSONArray jsTasks = client.getTaskList(gid);
- for (int j = 0; j < jsTasks.length(); j++) {
- object = (JSONObject) jsTasks.getJSONObject(j);
- gid = object.getString(GTaskStringUtils.GTASK_JSON_ID);
- Task task = new Task();
- task.setContentByRemoteJSON(object);
- if (task.isWorthSaving()) {
- task.setMetaInfo(mMetaHashMap.get(gid));
- tasklist.addChildTask(task);
- mGTaskHashMap.put(gid, task);
- }
- }
- }
- }
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("initGTaskList: handing JSONObject failed");
- }
- }
-
- private void syncContent() throws NetworkFailureException {
- int syncType;
- Cursor c = null;
- String gid;
- Node node;
-
- mLocalDeleteIdMap.clear();
-
- if (mCancelled) {
- return;
- }
-
- // for local deleted note
- try {
- c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE,
- "(type<>? AND parent_id=?)", new String[] {
- String.valueOf(Notes.TYPE_SYSTEM), String.valueOf(Notes.ID_TRASH_FOLER)
- }, null);
- if (c != null) {
- while (c.moveToNext()) {
- gid = c.getString(SqlNote.GTASK_ID_COLUMN);
- node = mGTaskHashMap.get(gid);
- if (node != null) {
- mGTaskHashMap.remove(gid);
- doContentSync(Node.SYNC_ACTION_DEL_REMOTE, node, c);
- }
-
- mLocalDeleteIdMap.add(c.getLong(SqlNote.ID_COLUMN));
- }
- } else {
- Log.w(TAG, "failed to query trash folder");
- }
- } finally {
- if (c != null) {
- c.close();
- c = null;
- }
- }
-
- // sync folder first
- syncFolder();
-
- // for note existing in database
- try {
- c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE,
- "(type=? AND parent_id<>?)", new String[] {
- String.valueOf(Notes.TYPE_NOTE), String.valueOf(Notes.ID_TRASH_FOLER)
- }, NoteColumns.TYPE + " DESC");
- if (c != null) {
- while (c.moveToNext()) {
- gid = c.getString(SqlNote.GTASK_ID_COLUMN);
- node = mGTaskHashMap.get(gid);
- if (node != null) {
- mGTaskHashMap.remove(gid);
- mGidToNid.put(gid, c.getLong(SqlNote.ID_COLUMN));
- mNidToGid.put(c.getLong(SqlNote.ID_COLUMN), gid);
- syncType = node.getSyncAction(c);
- } else {
- if (c.getString(SqlNote.GTASK_ID_COLUMN).trim().length() == 0) {
- // local add
- syncType = Node.SYNC_ACTION_ADD_REMOTE;
- } else {
- // remote delete
- syncType = Node.SYNC_ACTION_DEL_LOCAL;
- }
- }
- doContentSync(syncType, node, c);
- }
- } else {
- Log.w(TAG, "failed to query existing note in database");
- }
-
- } finally {
- if (c != null) {
- c.close();
- c = null;
- }
- }
-
- // go through remaining items
- Iterator> iter = mGTaskHashMap.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = iter.next();
- node = entry.getValue();
- doContentSync(Node.SYNC_ACTION_ADD_LOCAL, node, null);
- }
-
- // mCancelled can be set by another thread, so we neet to check one by
- // one
- // clear local delete table
- if (!mCancelled) {
- if (!DataUtils.batchDeleteNotes(mContentResolver, mLocalDeleteIdMap)) {
- throw new ActionFailureException("failed to batch-delete local deleted notes");
- }
- }
-
- // refresh local sync id
- if (!mCancelled) {
- GTaskClient.getInstance().commitUpdate();
- refreshLocalSyncId();
- }
-
- }
-
- private void syncFolder() throws NetworkFailureException {
- Cursor c = null;
- String gid;
- Node node;
- int syncType;
-
- if (mCancelled) {
- return;
- }
-
- // for root folder
- try {
- c = mContentResolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI,
- Notes.ID_ROOT_FOLDER), SqlNote.PROJECTION_NOTE, null, null, null);
- if (c != null) {
- c.moveToNext();
- gid = c.getString(SqlNote.GTASK_ID_COLUMN);
- node = mGTaskHashMap.get(gid);
- if (node != null) {
- mGTaskHashMap.remove(gid);
- mGidToNid.put(gid, (long) Notes.ID_ROOT_FOLDER);
- mNidToGid.put((long) Notes.ID_ROOT_FOLDER, gid);
- // for system folder, only update remote name if necessary
- if (!node.getName().equals(
- GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT))
- doContentSync(Node.SYNC_ACTION_UPDATE_REMOTE, node, c);
- } else {
- doContentSync(Node.SYNC_ACTION_ADD_REMOTE, node, c);
- }
- } else {
- Log.w(TAG, "failed to query root folder");
- }
- } finally {
- if (c != null) {
- c.close();
- c = null;
- }
- }
-
- // for call-note folder
- try {
- c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE, "(_id=?)",
- new String[] {
- String.valueOf(Notes.ID_CALL_RECORD_FOLDER)
- }, null);
- if (c != null) {
- if (c.moveToNext()) {
- gid = c.getString(SqlNote.GTASK_ID_COLUMN);
- node = mGTaskHashMap.get(gid);
- if (node != null) {
- mGTaskHashMap.remove(gid);
- mGidToNid.put(gid, (long) Notes.ID_CALL_RECORD_FOLDER);
- mNidToGid.put((long) Notes.ID_CALL_RECORD_FOLDER, gid);
- // for system folder, only update remote name if
- // necessary
- if (!node.getName().equals(
- GTaskStringUtils.MIUI_FOLDER_PREFFIX
- + GTaskStringUtils.FOLDER_CALL_NOTE))
- doContentSync(Node.SYNC_ACTION_UPDATE_REMOTE, node, c);
- } else {
- doContentSync(Node.SYNC_ACTION_ADD_REMOTE, node, c);
- }
- }
- } else {
- Log.w(TAG, "failed to query call note folder");
- }
- } finally {
- if (c != null) {
- c.close();
- c = null;
- }
- }
-
- // for local existing folders
- try {
- c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE,
- "(type=? AND parent_id<>?)", new String[] {
- String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)
- }, NoteColumns.TYPE + " DESC");
- if (c != null) {
- while (c.moveToNext()) {
- gid = c.getString(SqlNote.GTASK_ID_COLUMN);
- node = mGTaskHashMap.get(gid);
- if (node != null) {
- mGTaskHashMap.remove(gid);
- mGidToNid.put(gid, c.getLong(SqlNote.ID_COLUMN));
- mNidToGid.put(c.getLong(SqlNote.ID_COLUMN), gid);
- syncType = node.getSyncAction(c);
- } else {
- if (c.getString(SqlNote.GTASK_ID_COLUMN).trim().length() == 0) {
- // local add
- syncType = Node.SYNC_ACTION_ADD_REMOTE;
- } else {
- // remote delete
- syncType = Node.SYNC_ACTION_DEL_LOCAL;
- }
- }
- doContentSync(syncType, node, c);
- }
- } else {
- Log.w(TAG, "failed to query existing folder");
- }
- } finally {
- if (c != null) {
- c.close();
- c = null;
- }
- }
-
- // for remote add folders
- Iterator> iter = mGTaskListHashMap.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = iter.next();
- gid = entry.getKey();
- node = entry.getValue();
- if (mGTaskHashMap.containsKey(gid)) {
- mGTaskHashMap.remove(gid);
- doContentSync(Node.SYNC_ACTION_ADD_LOCAL, node, null);
- }
- }
-
- if (!mCancelled)
- GTaskClient.getInstance().commitUpdate();
- }
-
- private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException {
- if (mCancelled) {
- return;
- }
-
- MetaData meta;
- switch (syncType) {
- case Node.SYNC_ACTION_ADD_LOCAL:
- addLocalNode(node);
- break;
- case Node.SYNC_ACTION_ADD_REMOTE:
- addRemoteNode(node, c);
- break;
- case Node.SYNC_ACTION_DEL_LOCAL:
- meta = mMetaHashMap.get(c.getString(SqlNote.GTASK_ID_COLUMN));
- if (meta != null) {
- GTaskClient.getInstance().deleteNode(meta);
- }
- mLocalDeleteIdMap.add(c.getLong(SqlNote.ID_COLUMN));
- break;
- case Node.SYNC_ACTION_DEL_REMOTE:
- meta = mMetaHashMap.get(node.getGid());
- if (meta != null) {
- GTaskClient.getInstance().deleteNode(meta);
- }
- GTaskClient.getInstance().deleteNode(node);
- break;
- case Node.SYNC_ACTION_UPDATE_LOCAL:
- updateLocalNode(node, c);
- break;
- case Node.SYNC_ACTION_UPDATE_REMOTE:
- updateRemoteNode(node, c);
- break;
- case Node.SYNC_ACTION_UPDATE_CONFLICT:
- // merging both modifications maybe a good idea
- // right now just use local update simply
- updateRemoteNode(node, c);
- break;
- case Node.SYNC_ACTION_NONE:
- break;
- case Node.SYNC_ACTION_ERROR:
- default:
- throw new ActionFailureException("unkown sync action type");
- }
- }
-
- private void addLocalNode(Node node) throws NetworkFailureException {
- if (mCancelled) {
- return;
- }
-
- SqlNote sqlNote;
- if (node instanceof TaskList) {
- if (node.getName().equals(
- GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT)) {
- sqlNote = new SqlNote(mContext, Notes.ID_ROOT_FOLDER);
- } else if (node.getName().equals(
- GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_CALL_NOTE)) {
- sqlNote = new SqlNote(mContext, Notes.ID_CALL_RECORD_FOLDER);
- } else {
- sqlNote = new SqlNote(mContext);
- sqlNote.setContent(node.getLocalJSONFromContent());
- sqlNote.setParentId(Notes.ID_ROOT_FOLDER);
- }
- } else {
- sqlNote = new SqlNote(mContext);
- JSONObject js = node.getLocalJSONFromContent();
- try {
- if (js.has(GTaskStringUtils.META_HEAD_NOTE)) {
- JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
- if (note.has(NoteColumns.ID)) {
- long id = note.getLong(NoteColumns.ID);
- if (DataUtils.existInNoteDatabase(mContentResolver, id)) {
- // the id is not available, have to create a new one
- note.remove(NoteColumns.ID);
- }
- }
- }
-
- if (js.has(GTaskStringUtils.META_HEAD_DATA)) {
- JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
- for (int i = 0; i < dataArray.length(); i++) {
- JSONObject data = dataArray.getJSONObject(i);
- if (data.has(DataColumns.ID)) {
- long dataId = data.getLong(DataColumns.ID);
- if (DataUtils.existInDataDatabase(mContentResolver, dataId)) {
- // the data id is not available, have to create
- // a new one
- data.remove(DataColumns.ID);
- }
- }
- }
-
- }
- } catch (JSONException e) {
- Log.w(TAG, e.toString());
- e.printStackTrace();
- }
- sqlNote.setContent(js);
-
- Long parentId = mGidToNid.get(((Task) node).getParent().getGid());
- if (parentId == null) {
- Log.e(TAG, "cannot find task's parent id locally");
- throw new ActionFailureException("cannot add local node");
- }
- sqlNote.setParentId(parentId.longValue());
- }
-
- // create the local node
- sqlNote.setGtaskId(node.getGid());
- sqlNote.commit(false);
-
- // update gid-nid mapping
- mGidToNid.put(node.getGid(), sqlNote.getId());
- mNidToGid.put(sqlNote.getId(), node.getGid());
-
- // update meta
- updateRemoteMeta(node.getGid(), sqlNote);
- }
-
- private void updateLocalNode(Node node, Cursor c) throws NetworkFailureException {
- if (mCancelled) {
- return;
- }
-
- SqlNote sqlNote;
- // update the note locally
- sqlNote = new SqlNote(mContext, c);
- sqlNote.setContent(node.getLocalJSONFromContent());
-
- Long parentId = (node instanceof Task) ? mGidToNid.get(((Task) node).getParent().getGid())
- : new Long(Notes.ID_ROOT_FOLDER);
- if (parentId == null) {
- Log.e(TAG, "cannot find task's parent id locally");
- throw new ActionFailureException("cannot update local node");
- }
- sqlNote.setParentId(parentId.longValue());
- sqlNote.commit(true);
-
- // update meta info
- updateRemoteMeta(node.getGid(), sqlNote);
- }
-
- private void addRemoteNode(Node node, Cursor c) throws NetworkFailureException {
- if (mCancelled) {
- return;
- }
-
- SqlNote sqlNote = new SqlNote(mContext, c);
- Node n;
-
- // update remotely
- if (sqlNote.isNoteType()) {
- Task task = new Task();
- task.setContentByLocalJSON(sqlNote.getContent());
-
- String parentGid = mNidToGid.get(sqlNote.getParentId());
- if (parentGid == null) {
- Log.e(TAG, "cannot find task's parent tasklist");
- throw new ActionFailureException("cannot add remote task");
- }
- mGTaskListHashMap.get(parentGid).addChildTask(task);
-
- GTaskClient.getInstance().createTask(task);
- n = (Node) task;
-
- // add meta
- updateRemoteMeta(task.getGid(), sqlNote);
- } else {
- TaskList tasklist = null;
-
- // we need to skip folder if it has already existed
- String folderName = GTaskStringUtils.MIUI_FOLDER_PREFFIX;
- if (sqlNote.getId() == Notes.ID_ROOT_FOLDER)
- folderName += GTaskStringUtils.FOLDER_DEFAULT;
- else if (sqlNote.getId() == Notes.ID_CALL_RECORD_FOLDER)
- folderName += GTaskStringUtils.FOLDER_CALL_NOTE;
- else
- folderName += sqlNote.getSnippet();
-
- Iterator> iter = mGTaskListHashMap.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = iter.next();
- String gid = entry.getKey();
- TaskList list = entry.getValue();
-
- if (list.getName().equals(folderName)) {
- tasklist = list;
- if (mGTaskHashMap.containsKey(gid)) {
- mGTaskHashMap.remove(gid);
- }
- break;
- }
- }
-
- // no match we can add now
- if (tasklist == null) {
- tasklist = new TaskList();
- tasklist.setContentByLocalJSON(sqlNote.getContent());
- GTaskClient.getInstance().createTaskList(tasklist);
- mGTaskListHashMap.put(tasklist.getGid(), tasklist);
- }
- n = (Node) tasklist;
- }
-
- // update local note
- sqlNote.setGtaskId(n.getGid());
- sqlNote.commit(false);
- sqlNote.resetLocalModified();
- sqlNote.commit(true);
-
- // gid-id mapping
- mGidToNid.put(n.getGid(), sqlNote.getId());
- mNidToGid.put(sqlNote.getId(), n.getGid());
- }
-
- private void updateRemoteNode(Node node, Cursor c) throws NetworkFailureException {
- if (mCancelled) {
- return;
- }
-
- SqlNote sqlNote = new SqlNote(mContext, c);
-
- // update remotely
- node.setContentByLocalJSON(sqlNote.getContent());
- GTaskClient.getInstance().addUpdateNode(node);
-
- // update meta
- updateRemoteMeta(node.getGid(), sqlNote);
-
- // move task if necessary
- if (sqlNote.isNoteType()) {
- Task task = (Task) node;
- TaskList preParentList = task.getParent();
-
- String curParentGid = mNidToGid.get(sqlNote.getParentId());
- if (curParentGid == null) {
- Log.e(TAG, "cannot find task's parent tasklist");
- throw new ActionFailureException("cannot update remote task");
- }
- TaskList curParentList = mGTaskListHashMap.get(curParentGid);
-
- if (preParentList != curParentList) {
- preParentList.removeChildTask(task);
- curParentList.addChildTask(task);
- GTaskClient.getInstance().moveTask(task, preParentList, curParentList);
- }
- }
-
- // clear local modified flag
- sqlNote.resetLocalModified();
- sqlNote.commit(true);
- }
-
- private void updateRemoteMeta(String gid, SqlNote sqlNote) throws NetworkFailureException {
- if (sqlNote != null && sqlNote.isNoteType()) {
- MetaData metaData = mMetaHashMap.get(gid);
- if (metaData != null) {
- metaData.setMeta(gid, sqlNote.getContent());
- GTaskClient.getInstance().addUpdateNode(metaData);
- } else {
- metaData = new MetaData();
- metaData.setMeta(gid, sqlNote.getContent());
- mMetaList.addChildTask(metaData);
- mMetaHashMap.put(gid, metaData);
- GTaskClient.getInstance().createTask(metaData);
- }
- }
- }
-
- private void refreshLocalSyncId() throws NetworkFailureException {
- if (mCancelled) {
- return;
- }
-
- // get the latest gtask list
- mGTaskHashMap.clear();
- mGTaskListHashMap.clear();
- mMetaHashMap.clear();
- initGTaskList();
-
- Cursor c = null;
- try {
- c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE,
- "(type<>? AND parent_id<>?)", new String[] {
- String.valueOf(Notes.TYPE_SYSTEM), String.valueOf(Notes.ID_TRASH_FOLER)
- }, NoteColumns.TYPE + " DESC");
- if (c != null) {
- while (c.moveToNext()) {
- String gid = c.getString(SqlNote.GTASK_ID_COLUMN);
- Node node = mGTaskHashMap.get(gid);
- if (node != null) {
- mGTaskHashMap.remove(gid);
- ContentValues values = new ContentValues();
- values.put(NoteColumns.SYNC_ID, node.getLastModified());
- mContentResolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI,
- c.getLong(SqlNote.ID_COLUMN)), values, null, null);
- } else {
- Log.e(TAG, "something is missed");
- throw new ActionFailureException(
- "some local items don't have gid after sync");
- }
- }
- } else {
- Log.w(TAG, "failed to query local note to refresh sync id");
- }
- } finally {
- if (c != null) {
- c.close();
- c = null;
- }
- }
- }
-
- public String getSyncAccount() {
- return GTaskClient.getInstance().getSyncAccount().name;
- }
-
- public void cancelSync() {
- mCancelled = true;
- }
-}
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskSyncService.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskSyncService.java
deleted file mode 100644
index cca36f7..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/remote/GTaskSyncService.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * 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.gtask.remote;
-
-import android.app.Activity;
-import android.app.Service;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.IBinder;
-
-public class GTaskSyncService extends Service {
- public final static String ACTION_STRING_NAME = "sync_action_type";
-
- public final static int ACTION_START_SYNC = 0;
-
- public final static int ACTION_CANCEL_SYNC = 1;
-
- public final static int ACTION_INVALID = 2;
-
- public final static String GTASK_SERVICE_BROADCAST_NAME = "net.micode.notes.gtask.remote.gtask_sync_service";
-
- public final static String GTASK_SERVICE_BROADCAST_IS_SYNCING = "isSyncing";
-
- public final static String GTASK_SERVICE_BROADCAST_PROGRESS_MSG = "progressMsg";
-
- private static GTaskASyncTask mSyncTask = null;
-
- private static String mSyncProgress = "";
-
- private void startSync() {
- if (mSyncTask == null) {
- mSyncTask = new GTaskASyncTask(this, new GTaskASyncTask.OnCompleteListener() {
- public void onComplete() {
- mSyncTask = null;
- sendBroadcast("");
- stopSelf();
- }
- });
- sendBroadcast("");
- mSyncTask.execute();
- }
- }
-
- private void cancelSync() {
- if (mSyncTask != null) {
- mSyncTask.cancelSync();
- }
- }
-
- @Override
- public void onCreate() {
- mSyncTask = null;
- }
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- Bundle bundle = intent.getExtras();
- if (bundle != null && bundle.containsKey(ACTION_STRING_NAME)) {
- switch (bundle.getInt(ACTION_STRING_NAME, ACTION_INVALID)) {
- case ACTION_START_SYNC:
- startSync();
- break;
- case ACTION_CANCEL_SYNC:
- cancelSync();
- break;
- default:
- break;
- }
- return START_STICKY;
- }
- return super.onStartCommand(intent, flags, startId);
- }
-
- @Override
- public void onLowMemory() {
- if (mSyncTask != null) {
- mSyncTask.cancelSync();
- }
- }
-
- public IBinder onBind(Intent intent) {
- return null;
- }
-
- public void sendBroadcast(String msg) {
- mSyncProgress = msg;
- Intent intent = new Intent(GTASK_SERVICE_BROADCAST_NAME);
- intent.putExtra(GTASK_SERVICE_BROADCAST_IS_SYNCING, mSyncTask != null);
- intent.putExtra(GTASK_SERVICE_BROADCAST_PROGRESS_MSG, msg);
- sendBroadcast(intent);
- }
-
- public static void startSync(Activity activity) {
- GTaskManager.getInstance().setActivityContext(activity);
- Intent intent = new Intent(activity, GTaskSyncService.class);
- intent.putExtra(GTaskSyncService.ACTION_STRING_NAME, GTaskSyncService.ACTION_START_SYNC);
- activity.startService(intent);
- }
-
- public static void cancelSync(Context context) {
- Intent intent = new Intent(context, GTaskSyncService.class);
- intent.putExtra(GTaskSyncService.ACTION_STRING_NAME, GTaskSyncService.ACTION_CANCEL_SYNC);
- context.startService(intent);
- }
-
- public static boolean isSyncing() {
- return mSyncTask != null;
- }
-
- public static String getProgressString() {
- return mSyncProgress;
- }
-}
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/model/Note.java b/src/Notes-master/app/src/main/java/net/micode/notes/model/Note.java
deleted file mode 100644
index 5d09ea9..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/model/Note.java
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
- * 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.model;
-
-import android.content.ContentProviderOperation;
-import android.content.ContentProviderResult;
-import android.content.ContentUris;
-import android.content.ContentValues;
-import android.content.Context;
-import android.content.OperationApplicationException;
-import android.net.Uri;
-import android.os.RemoteException;
-import android.util.Log;
-
-// 导入笔记数据相关类
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.CallNote;
-import net.micode.notes.data.Notes.DataColumns;
-import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.data.Notes.TextNote;
-
-import java.util.ArrayList;
-
-
-/**
- * 笔记数据管理类,负责与ContentProvider交互
- * 处理笔记的数据库操作细节(创建、更新等)
- */
-public class Note {
- // 存储笔记属性的变化(用于批量更新)
- private ContentValues mNoteDiffValues;
- // 存储笔记内容数据(文本/通话记录等)
- private NoteData mNoteData;
- // 日志标签
- private static final String TAG = "Note";
-
- /**
- * 为新笔记创建数据库ID(同步方法,保证线程安全)
- * @param context 上下文
- * @param folderId 所属文件夹ID
- * @return 新创建的笔记ID,失败返回0
- */
- public static synchronized long getNewNoteId(Context context, long folderId) {
- // 准备新笔记的初始数据
- ContentValues values = new ContentValues();
- long createdTime = System.currentTimeMillis();
- values.put(NoteColumns.CREATED_DATE, createdTime); // 创建时间
- values.put(NoteColumns.MODIFIED_DATE, createdTime); // 修改时间(初始同创建时间)
- values.put(NoteColumns.TYPE, Notes.TYPE_NOTE); // 笔记类型
- values.put(NoteColumns.LOCAL_MODIFIED, 1); // 标记为本地已修改
- values.put(NoteColumns.PARENT_ID, folderId); // 所属文件夹
-
- // 插入数据库并获取URI
- Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values);
-
- long noteId = 0;
- try {
- // 从URI中解析出笔记ID(URI格式通常为 content://.../notes/123)
- noteId = Long.valueOf(uri.getPathSegments().get(1));
- } catch (NumberFormatException e) {
- Log.e(TAG, "获取笔记ID失败:" + e.toString());
- noteId = 0;
- }
- if (noteId == -1) {
- throw new IllegalStateException("无效的笔记ID:" + noteId);
- }
- return noteId;
- }
-
- /**
- * 构造方法,初始化数据存储对象
- */
- public Note() {
- mNoteDiffValues = new ContentValues(); // 存储笔记属性变化
- mNoteData = new NoteData(); // 存储内容数据
- }
-
- /**
- * 设置笔记属性(如背景色、提醒时间等)
- * @param key 属性键(对应NoteColumns中的字段)
- * @param value 属性值
- */
- public void setNoteValue(String key, String value) {
- mNoteDiffValues.put(key, value);
- mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); // 标记为已修改
- mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); // 更新修改时间
- }
-
- /**
- * 设置文本笔记内容数据
- * @param key 数据键(如内容、模式等)
- * @param value 数据值
- */
- public void setTextData(String key, String value) {
- mNoteData.setTextData(key, value);
- }
-
- /**
- * 设置文本数据ID(数据库中的数据记录ID)
- * @param id 数据ID
- */
- public void setTextDataId(long id) {
- mNoteData.setTextDataId(id);
- }
-
- /**
- * 获取文本数据ID
- * @return 文本数据ID
- */
- public long getTextDataId() {
- return mNoteData.mTextDataId;
- }
-
- /**
- * 设置通话记录数据ID
- * @param id 数据ID
- */
- public void setCallDataId(long id) {
- mNoteData.setCallDataId(id);
- }
-
- /**
- * 设置通话记录数据(如电话号码、通话时间)
- * @param key 数据键
- * @param value 数据值
- */
- public void setCallData(String key, String value) {
- mNoteData.setCallData(key, value);
- }
-
- /**
- * 判断笔记是否有本地修改(未同步到数据库)
- * @return 有修改返回true,否则false
- */
- public boolean isLocalModified() {
- return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified();
- }
-
- /**
- * 将本地修改同步到数据库
- * @param context 上下文
- * @param noteId 笔记ID
- * @return 同步成功返回true,否则false
- */
- public boolean syncNote(Context context, long noteId) {
- if (noteId <= 0) {
- throw new IllegalArgumentException("无效的笔记ID:" + noteId);
- }
-
- if (!isLocalModified()) {
- return true; // 无修改,直接返回成功
- }
-
- /**
- * 理论上,数据修改后应更新LOCAL_MODIFIED和MODIFIED_DATE
- * 为保证数据安全,即使笔记属性更新失败,仍尝试更新内容数据
- */
- // 更新笔记属性
- if (context.getContentResolver().update(
- ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
- mNoteDiffValues,
- null, null) == 0) {
- Log.e(TAG, "更新笔记属性失败,不应出现此情况");
- // 不返回,继续尝试更新内容数据
- }
- mNoteDiffValues.clear(); // 清空已同步的属性变化
-
- // 更新笔记内容数据
- if (mNoteData.isLocalModified()
- && (mNoteData.pushIntoContentResolver(context, noteId) == null)) {
- return false; // 内容数据更新失败
- }
-
- return true;
- }
-
- /**
- * 内部类:管理笔记的内容数据(文本/通话记录等)
- */
- private class NoteData {
- // 文本数据ID(数据库中的记录ID)
- private long mTextDataId;
- // 文本数据的变化(待同步到数据库)
- private ContentValues mTextDataValues;
- // 通话记录数据ID
- private long mCallDataId;
- // 通话记录数据的变化
- private ContentValues mCallDataValues;
- // 日志标签
- private static final String TAG = "NoteData";
-
- /**
- * 构造方法,初始化数据存储对象
- */
- public NoteData() {
- mTextDataValues = new ContentValues();
- mCallDataValues = new ContentValues();
- mTextDataId = 0; // 初始无数据ID
- mCallDataId = 0;
- }
-
- /**
- * 判断内容数据是否有本地修改
- * @return 有修改返回true,否则false
- */
- boolean isLocalModified() {
- return mTextDataValues.size() > 0 || mCallDataValues.size() > 0;
- }
-
- /**
- * 设置文本数据ID(必须为正数)
- * @param id 数据ID
- */
- void setTextDataId(long id) {
- if(id <= 0) {
- throw new IllegalArgumentException("文本数据ID必须大于0");
- }
- mTextDataId = id;
- }
-
- /**
- * 设置通话数据ID(必须为正数)
- * @param id 数据ID
- */
- void setCallDataId(long id) {
- if (id <= 0) {
- throw new IllegalArgumentException("通话数据ID必须大于0");
- }
- mCallDataId = id;
- }
-
- /**
- * 设置通话数据并标记笔记为已修改
- * @param key 数据键
- * @param value 数据值
- */
- void setCallData(String key, String value) {
- mCallDataValues.put(key, value);
- mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
- mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
- }
-
- /**
- * 设置文本数据并标记笔记为已修改
- * @param key 数据键
- * @param value 数据值
- */
- void setTextData(String key, String value) {
- mTextDataValues.put(key, value);
- mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
- mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
- }
-
- /**
- * 将内容数据同步到数据库
- * @param context 上下文
- * @param noteId 所属笔记ID
- * @return 同步成功返回URI,否则null
- */
- Uri pushIntoContentResolver(Context context, long noteId) {
- // 安全检查:笔记ID必须有效
- if (noteId <= 0) {
- throw new IllegalArgumentException("无效的笔记ID:" + noteId);
- }
-
- // 批量操作列表(用于同时处理多个数据更新)
- ArrayList operationList = new ArrayList<>();
- ContentProviderOperation.Builder builder = null;
-
- // 处理文本数据
- if(mTextDataValues.size() > 0) {
- mTextDataValues.put(DataColumns.NOTE_ID, noteId); // 关联到当前笔记
- if (mTextDataId == 0) {
- // 新文本数据:插入数据库
- mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE);
- Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI, mTextDataValues);
- try {
- // 解析新插入的数据ID
- setTextDataId(Long.valueOf(uri.getPathSegments().get(1)));
- } catch (NumberFormatException e) {
- Log.e(TAG, "插入新文本数据失败,笔记ID:" + noteId);
- mTextDataValues.clear();
- return null;
- }
- } else {
- // 已有文本数据:更新数据库
- builder = ContentProviderOperation.newUpdate(
- ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, mTextDataId));
- builder.withValues(mTextDataValues);
- operationList.add(builder.build());
- }
- mTextDataValues.clear(); // 清空已同步的数据
- }
-
- // 处理通话记录数据
- if(mCallDataValues.size() > 0) {
- mCallDataValues.put(DataColumns.NOTE_ID, noteId); // 关联到当前笔记
- if (mCallDataId == 0) {
- // 新通话数据:插入数据库
- mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE);
- Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI, mCallDataValues);
- try {
- setCallDataId(Long.valueOf(uri.getPathSegments().get(1)));
- } catch (NumberFormatException e) {
- Log.e(TAG, "插入新通话数据失败,笔记ID:" + noteId);
- mCallDataValues.clear();
- return null;
- }
- } else {
- // 已有通话数据:更新数据库
- builder = ContentProviderOperation.newUpdate(
- ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, mCallDataId));
- builder.withValues(mCallDataValues);
- operationList.add(builder.build());
- }
- mCallDataValues.clear(); // 清空已同步的数据
- }
-
- // 执行批量更新操作
- if (operationList.size() > 0) {
- try {
- ContentProviderResult[] results = context.getContentResolver().applyBatch(
- Notes.AUTHORITY, operationList);
- // 返回同步后的笔记URI
- return (results == null || results.length == 0 || results[0] == null) ? null
- : ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId);
- } catch (RemoteException e) {
- Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
- return null;
- } catch (OperationApplicationException e) {
- Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
- return null;
- }
- }
- return null;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/model/WorkingNote.java b/src/Notes-master/app/src/main/java/net/micode/notes/model/WorkingNote.java
deleted file mode 100644
index cc9b837..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/model/WorkingNote.java
+++ /dev/null
@@ -1,477 +0,0 @@
-/*
- * 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.model;
-
-import android.appwidget.AppWidgetManager;
-import android.content.ContentUris;
-import android.content.Context;
-import android.database.Cursor;
-import android.text.TextUtils;
-import android.util.Log;
-
-// 导入笔记相关的数据类和常量
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.CallNote;
-import net.micode.notes.data.Notes.DataColumns;
-import net.micode.notes.data.Notes.DataConstants;
-import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.data.Notes.TextNote;
-import net.micode.notes.tool.ResourceParser.NoteBgResources;
-
-
-/**
- * 工作笔记类,用于管理单条笔记的内容、属性及数据库交互
- * 封装了笔记的创建、加载、保存、修改等核心操作
- */
-public class WorkingNote {
- // 内部维护的Note对象,处理数据库交互细节
- private Note mNote;
- // 笔记ID(数据库中的唯一标识)
- private long mNoteId;
- // 笔记内容
- private String mContent;
- // 笔记模式(如普通文本/ checklist模式)
- private int mMode;
- // 提醒时间戳
- private long mAlertDate;
- // 最后修改时间戳
- private long mModifiedDate;
- // 背景颜色ID
- private int mBgColorId;
- // 桌面小部件ID
- private int mWidgetId;
- // 桌面小部件类型
- private int mWidgetType;
- // 所属文件夹ID
- private long mFolderId;
- // 上下文对象,用于访问系统服务
- private Context mContext;
- // 日志标签
- private static final String TAG = "WorkingNote";
- // 是否标记为删除
- private boolean mIsDeleted;
- // 笔记设置变化监听器(用于UI回调)
- private NoteSettingChangedListener mNoteSettingStatusListener;
-
- /**
- * 数据查询投影(指定需要从数据库查询的字段)
- * 用于查询笔记的具体内容数据
- */
- public static final String[] DATA_PROJECTION = new String[] {
- DataColumns.ID, // 数据ID
- DataColumns.CONTENT, // 内容
- DataColumns.MIME_TYPE, // 数据类型(文本/通话记录等)
- DataColumns.DATA1, // 扩展字段1(存储模式)
- DataColumns.DATA2, // 扩展字段2
- DataColumns.DATA3, // 扩展字段3
- DataColumns.DATA4, // 扩展字段4
- };
-
- /**
- * 笔记查询投影
- * 用于查询笔记的属性信息
- */
- public static final String[] NOTE_PROJECTION = new String[] {
- NoteColumns.PARENT_ID, // 所属文件夹ID
- NoteColumns.ALERTED_DATE, // 提醒时间
- NoteColumns.BG_COLOR_ID, // 背景颜色ID
- NoteColumns.WIDGET_ID, // 小部件ID
- NoteColumns.WIDGET_TYPE, // 小部件类型
- NoteColumns.MODIFIED_DATE // 修改时间
- };
-
- // 数据投影字段索引(用于快速访问Cursor中的数据)
- private static final int DATA_ID_COLUMN = 0;
- private static final int DATA_CONTENT_COLUMN = 1;
- private static final int DATA_MIME_TYPE_COLUMN = 2;
- private static final int DATA_MODE_COLUMN = 3;
-
- // 笔记投影字段索引
- private static final int NOTE_PARENT_ID_COLUMN = 0;
- private static final int NOTE_ALERTED_DATE_COLUMN = 1;
- private static final int NOTE_BG_COLOR_ID_COLUMN = 2;
- private static final int NOTE_WIDGET_ID_COLUMN = 3;
- private static final int NOTE_WIDGET_TYPE_COLUMN = 4;
- private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
-
- /**
- * 构造新笔记(私有构造,通过createEmptyNote创建)
- * @param context 上下文
- * @param folderId 所属文件夹ID
- */
- private WorkingNote(Context context, long folderId) {
- mContext = context;
- mAlertDate = 0; // 初始无提醒
- mModifiedDate = System.currentTimeMillis(); // 初始修改时间为当前时间
- mFolderId = folderId;
- mNote = new Note(); // 初始化内部Note对象
- mNoteId = 0; // 新笔记暂未存入数据库,ID为0
- mIsDeleted = false; // 初始未删除
- mMode = 0; // 初始模式
- mWidgetType = Notes.TYPE_WIDGET_INVALIDE; // 初始无有效小部件
- }
-
- /**
- * 构造已有笔记(私有构造,通过load方法加载)
- * @param context 上下文
- * @param noteId 笔记ID
- * @param folderId 所属文件夹ID
- */
- private WorkingNote(Context context, long noteId, long folderId) {
- mContext = context;
- mNoteId = noteId; // 已存在的笔记ID
- mFolderId = folderId;
- mIsDeleted = false;
- mNote = new Note();
- loadNote(); // 从数据库加载笔记数据
- }
-
- /**
- * 从数据库加载笔记属性(文件夹、提醒时间、背景色等)
- */
- private void loadNote() {
- // 查询指定ID的笔记属性
- Cursor cursor = mContext.getContentResolver().query(
- ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId),
- NOTE_PROJECTION,
- null, null, null);
-
- if (cursor != null) {
- if (cursor.moveToFirst()) {
- // 从游标中读取数据并赋值
- mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);
- mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN);
- mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN);
- mWidgetType = cursor.getInt(NOTE_WIDGET_TYPE_COLUMN);
- mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN);
- mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
- }
- cursor.close(); // 关闭游标释放资源
- } else {
- Log.e(TAG, "No note with id:" + mNoteId);
- throw new IllegalArgumentException("无法找到ID为" + mNoteId + "的笔记");
- }
- loadNoteData(); // 加载笔记内容数据
- }
-
- /**
- * 从数据库加载笔记内容数据(文本内容、模式等)
- */
- private void loadNoteData() {
- // 查询当前笔记的内容数据
- Cursor cursor = mContext.getContentResolver().query(
- Notes.CONTENT_DATA_URI,
- DATA_PROJECTION,
- DataColumns.NOTE_ID + "=?", // 条件:笔记ID匹配
- new String[] { String.valueOf(mNoteId) },
- null);
-
- if (cursor != null) {
- if (cursor.moveToFirst()) {
- do {
- String type = cursor.getString(DATA_MIME_TYPE_COLUMN);
- if (DataConstants.NOTE.equals(type)) {
- // 文本笔记类型:读取内容和模式
- mContent = cursor.getString(DATA_CONTENT_COLUMN);
- mMode = cursor.getInt(DATA_MODE_COLUMN);
- mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN));
- } else if (DataConstants.CALL_NOTE.equals(type)) {
- // 通话笔记类型:记录数据ID
- mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN));
- } else {
- Log.d(TAG, "错误的笔记类型:" + type);
- }
- } while (cursor.moveToNext()); // 处理可能的多条数据
- }
- cursor.close();
- } else {
- Log.e(TAG, "No data with id:" + mNoteId);
- throw new IllegalArgumentException("无法找到ID为" + mNoteId + "的笔记内容");
- }
- }
-
- /**
- * 创建空笔记的工厂方法
- * @param context 上下文
- * @param folderId 所属文件夹ID
- * @param widgetId 小部件ID
- * @param widgetType 小部件类型
- * @param defaultBgColorId 默认背景色ID
- * @return 新创建的WorkingNote对象
- */
- public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
- int widgetType, int defaultBgColorId) {
- WorkingNote note = new WorkingNote(context, folderId);
- note.setBgColorId(defaultBgColorId);
- note.setWidgetId(widgetId);
- note.setWidgetType(widgetType);
- return note;
- }
-
- /**
- * 加载已有笔记的工厂方法
- * @param context 上下文
- * @param id 笔记ID
- * @return 加载后的WorkingNote对象
- */
- public static WorkingNote load(Context context, long id) {
- return new WorkingNote(context, id, 0);
- }
-
- /**
- * 保存笔记到数据库(线程安全)
- * @return 是否保存成功
- */
- public synchronized boolean saveNote() {
- if (isWorthSaving()) { // 判断是否需要保存
- if (!existInDatabase()) { // 新笔记:先创建ID
- if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
- Log.e(TAG, "创建新笔记失败,ID为:" + mNoteId);
- return false;
- }
- }
-
- mNote.syncNote(mContext, mNoteId); // 同步数据到数据库
-
- /**
- * 如果存在关联的小部件,通知小部件更新内容
- */
- if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
- && mWidgetType != Notes.TYPE_WIDGET_INVALIDE
- && mNoteSettingStatusListener != null) {
- mNoteSettingStatusListener.onWidgetChanged();
- }
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * 判断笔记是否已存在于数据库
- * @return 存在返回true,否则false
- */
- public boolean existInDatabase() {
- return mNoteId > 0;
- }
-
- /**
- * 判断笔记是否值得保存(避免无效保存操作)
- * @return 需要保存返回true,否则false
- */
- private boolean isWorthSaving() {
- // 已删除、新笔记无内容、已有笔记未修改:无需保存
- if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
- || (existInDatabase() && !mNote.isLocalModified())) {
- return false;
- } else {
- return true;
- }
- }
-
- /**
- * 设置笔记设置变化监听器
- * @param l 监听器实例
- */
- public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
- mNoteSettingStatusListener = l;
- }
-
- /**
- * 设置提醒时间
- * @param date 提醒时间戳
- * @param set 是否设置提醒
- */
- public void setAlertDate(long date, boolean set) {
- if (date != mAlertDate) {
- mAlertDate = date;
- mNote.setNoteValue(NoteColumns.ALERTED_DATE, String.valueOf(mAlertDate));
- }
- // 通知监听器提醒时间变化
- if (mNoteSettingStatusListener != null) {
- mNoteSettingStatusListener.onClockAlertChanged(date, set);
- }
- }
-
- /**
- * 标记笔记为删除状态
- * @param mark 是否标记删除
- */
- public void markDeleted(boolean mark) {
- mIsDeleted = mark;
- // 如果有关联小部件,通知更新
- if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
- && mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) {
- mNoteSettingStatusListener.onWidgetChanged();
- }
- }
-
- /**
- * 设置背景颜色ID
- * @param id 颜色ID
- */
- public void setBgColorId(int id) {
- if (id != mBgColorId) {
- mBgColorId = id;
- // 通知监听器背景色变化
- if (mNoteSettingStatusListener != null) {
- mNoteSettingStatusListener.onBackgroundColorChanged();
- }
- mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id));
- }
- }
-
- /**
- * 设置清单模式(普通/ checklist)
- * @param mode 新模式
- */
- public void setCheckListMode(int mode) {
- if (mMode != mode) {
- // 通知监听器模式变化
- if (mNoteSettingStatusListener != null) {
- mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode);
- }
- mMode = mode;
- mNote.setTextData(TextNote.MODE, String.valueOf(mMode));
- }
- }
-
- /**
- * 设置小部件类型
- * @param type 类型值
- */
- public void setWidgetType(int type) {
- if (type != mWidgetType) {
- mWidgetType = type;
- mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType));
- }
- }
-
- /**
- * 设置小部件ID
- * @param id 小部件ID
- */
- public void setWidgetId(int id) {
- if (id != mWidgetId) {
- mWidgetId = id;
- mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId));
- }
- }
-
- /**
- * 设置笔记文本内容
- * @param text 新内容
- */
- public void setWorkingText(String text) {
- // 内容有变化才更新
- if (!TextUtils.equals(mContent, text)) {
- mContent = text;
- mNote.setTextData(DataColumns.CONTENT, mContent);
- }
- }
-
- /**
- * 转换为通话笔记(添加通话相关信息)
- * @param phoneNumber 电话号码
- * @param callDate 通话时间
- */
- public void convertToCallNote(String phoneNumber, long callDate) {
- mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate));
- mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber);
- // 移动到通话记录文件夹
- mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER));
- }
-
- /**
- * 判断是否设置了提醒
- * @return 有提醒返回true,否则false
- */
- public boolean hasClockAlert() {
- return (mAlertDate > 0 ? true : false);
- }
-
- // 以下为各种属性的getter方法
- public String getContent() {
- return mContent;
- }
-
- public long getAlertDate() {
- return mAlertDate;
- }
-
- public long getModifiedDate() {
- return mModifiedDate;
- }
-
- /**
- * 获取背景颜色资源ID(用于UI显示)
- * @return 颜色资源ID
- */
- public int getBgColorResId() {
- return NoteBgResources.getNoteBgResource(mBgColorId);
- }
-
- public int getBgColorId() {
- return mBgColorId;
- }
-
- /**
- * 获取标题栏背景资源ID
- * @return 标题背景资源ID
- */
- public int getTitleBgResId() {
- return NoteBgResources.getNoteTitleBgResource(mBgColorId);
- }
-
- public int getCheckListMode() {
- return mMode;
- }
-
- public long getNoteId() {
- return mNoteId;
- }
-
- public long getFolderId() {
- return mFolderId;
- }
-
- public int getWidgetId() {
- return mWidgetId;
- }
-
- public int getWidgetType() {
- return mWidgetType;
- }
-
- /**
- * 笔记设置变化监听器接口
- * 用于通知UI更新
- */
- public interface NoteSettingChangedListener {
- /** 背景颜色变化时调用 */
- void onBackgroundColorChanged();
-
- /** 提醒时间变化时调用 */
- void onClockAlertChanged(long date, boolean set);
-
- /** 小部件相关变化时调用 */
- void onWidgetChanged();
-
- /** 清单模式切换时调用 */
- void onCheckListModeChanged(int oldMode, int newMode);
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/tool/BackupUtils.java b/src/Notes-master/app/src/main/java/net/micode/notes/tool/BackupUtils.java
deleted file mode 100644
index a09e982..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/tool/BackupUtils.java
+++ /dev/null
@@ -1,411 +0,0 @@
-/*
- * 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;
-
-import android.content.Context;
-import android.database.Cursor;
-import android.os.Environment;
-import android.text.TextUtils;
-import android.text.format.DateFormat;
-import android.util.Log;
-
-import net.micode.notes.R;
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.DataColumns;
-import net.micode.notes.data.Notes.DataConstants;
-import net.micode.notes.data.Notes.NoteColumns;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-
-
-/**
- * 备份工具类,提供笔记数据的导出功能(目前支持导出为文本文件)
- * 采用单例模式,确保全局只有一个实例处理备份操作
- */
-public class BackupUtils {
- private static final String TAG = "BackupUtils";
- // 单例实例
- private static BackupUtils sInstance;
-
- /**
- * 获取单例实例
- * @param context 上下文
- * @return BackupUtils唯一实例
- */
- public static synchronized BackupUtils getInstance(Context context) {
- if (sInstance == null) {
- sInstance = new BackupUtils(context);
- }
- return sInstance;
- }
-
- /**
- * 备份/恢复操作的状态常量
- */
- // SD卡未挂载
- public static final int STATE_SD_CARD_UNMOUONTED = 0;
- // 备份文件不存在
- public static final int STATE_BACKUP_FILE_NOT_EXIST = 1;
- // 数据格式错误(可能被其他程序修改)
- public static final int STATE_DATA_DESTROIED = 2;
- // 系统错误(如IO异常)导致操作失败
- public static final int STATE_SYSTEM_ERROR = 3;
- // 备份/恢复成功
- public static final int STATE_SUCCESS = 4;
-
- // 文本导出工具(内部类实例)
- private TextExport mTextExport;
-
- /**
- * 私有构造方法,初始化文本导出工具
- * @param context 上下文
- */
- private BackupUtils(Context context) {
- mTextExport = new TextExport(context);
- }
-
- /**
- * 检查外部存储(SD卡)是否可用
- * @return 可用返回true,否则返回false
- */
- private static boolean externalStorageAvailable() {
- // 检查SD卡是否已挂载且可读写
- return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
- }
-
- /**
- * 导出笔记数据为文本文件
- * @return 操作状态(对应STATE_*常量)
- */
- public int exportToText() {
- return mTextExport.exportToText();
- }
-
- /**
- * 获取导出的文本文件名
- * @return 文件名
- */
- public String getExportedTextFileName() {
- return mTextExport.mFileName;
- }
-
- /**
- * 获取导出的文本文件所在目录
- * @return 目录路径
- */
- public String getExportedTextFileDir() {
- return mTextExport.mFileDirectory;
- }
-
- /**
- * 文本导出内部类,处理具体的文本导出逻辑
- */
- private static class TextExport {
- // 笔记查询的字段投影(只查询需要的字段,优化性能)
- private static final String[] NOTE_PROJECTION = {
- NoteColumns.ID, // 笔记ID
- NoteColumns.MODIFIED_DATE, // 最后修改时间
- NoteColumns.SNIPPET, // 摘要(文件夹名称用此字段存储)
- NoteColumns.TYPE // 类型(文件夹/笔记)
- };
-
- // 笔记查询结果的字段索引(与NOTE_PROJECTION顺序对应)
- private static final int NOTE_COLUMN_ID = 0;
- private static final int NOTE_COLUMN_MODIFIED_DATE = 1;
- private static final int NOTE_COLUMN_SNIPPET = 2;
-
- // 笔记详情数据查询的字段投影
- private static final String[] DATA_PROJECTION = {
- DataColumns.CONTENT, // 内容
- DataColumns.MIME_TYPE, // 类型(普通笔记/通话笔记)
- DataColumns.DATA1, // 通话时间(通话笔记专用)
- DataColumns.DATA2, // 预留字段
- DataColumns.DATA3, // 电话号码(通话笔记专用)
- DataColumns.DATA4 // 预留字段
- };
-
- // 数据查询结果的字段索引(与DATA_PROJECTION顺序对应)
- private static final int DATA_COLUMN_CONTENT = 0;
- private static final int DATA_COLUMN_MIME_TYPE = 1;
- private static final int DATA_COLUMN_CALL_DATE = 2; // 通话时间
- private static final int DATA_COLUMN_PHONE_NUMBER = 4; // 电话号码
-
- // 文本导出的格式模板(从资源文件读取)
- private final String [] TEXT_FORMAT;
- // 格式模板的索引
- private static final int FORMAT_FOLDER_NAME = 0; // 文件夹名称格式
- private static final int FORMAT_NOTE_DATE = 1; // 笔记日期格式
- private static final int FORMAT_NOTE_CONTENT = 2; // 笔记内容格式
-
- private Context mContext; // 上下文
- private String mFileName; // 导出的文件名
- private String mFileDirectory; // 导出的文件目录
-
- /**
- * 构造方法,初始化格式模板和上下文
- * @param context 上下文
- */
- public TextExport(Context context) {
- // 从资源文件中读取导出格式模板(如文件夹名前缀、日期前缀等)
- TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note);
- mContext = context;
- mFileName = "";
- mFileDirectory = "";
- }
-
- /**
- * 获取指定索引的格式模板
- * @param id 格式索引(如FORMAT_FOLDER_NAME)
- * @return 格式字符串
- */
- private String getFormat(int id) {
- return TEXT_FORMAT[id];
- }
-
- /**
- * 将指定文件夹下的所有笔记导出到文本流
- * @param folderId 文件夹ID
- * @param ps 输出流(用于写入文本内容)
- */
- private void exportFolderToText(String folderId, PrintStream ps) {
- // 查询该文件夹下的所有笔记
- Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI,
- NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] {
- folderId
- }, null);
-
- if (notesCursor != null) {
- if (notesCursor.moveToFirst()) {
- do {
- // 写入笔记的最后修改时间(格式化显示)
- ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
- mContext.getString(R.string.format_datetime_mdhm), // 日期格式:月日时分
- notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
- // 导出该笔记的详细内容
- String noteId = notesCursor.getString(NOTE_COLUMN_ID);
- exportNoteToText(noteId, ps);
- } while (notesCursor.moveToNext()); // 遍历所有笔记
- }
- notesCursor.close(); // 关闭游标释放资源
- }
- }
-
- /**
- * 将指定笔记的详细内容导出到文本流
- * @param noteId 笔记ID
- * @param ps 输出流
- */
- private void exportNoteToText(String noteId, PrintStream ps) {
- // 查询该笔记的详细数据(如内容、通话记录等)
- Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI,
- DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] {
- noteId
- }, null);
-
- if (dataCursor != null) {
- if (dataCursor.moveToFirst()) {
- do {
- String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE);
- if (DataConstants.CALL_NOTE.equals(mimeType)) {
- // 处理通话笔记:导出电话号码、通话时间、位置等
- String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER);
- long callDate = dataCursor.getLong(DATA_COLUMN_CALL_DATE);
- String location = dataCursor.getString(DATA_COLUMN_CONTENT);
-
- if (!TextUtils.isEmpty(phoneNumber)) {
- ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), phoneNumber));
- }
- // 导出通话时间
- ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat
- .format(mContext.getString(R.string.format_datetime_mdhm), callDate)));
- // 导出通话位置(如果有)
- if (!TextUtils.isEmpty(location)) {
- ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), location));
- }
- } else if (DataConstants.NOTE.equals(mimeType)) {
- // 处理普通笔记:导出内容
- String content = dataCursor.getString(DATA_COLUMN_CONTENT);
- if (!TextUtils.isEmpty(content)) {
- ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), content));
- }
- }
- } while (dataCursor.moveToNext()); // 遍历所有数据项
- }
- dataCursor.close();
- }
- // 在笔记之间添加分隔符
- try {
- ps.write(new byte[] {
- Character.LINE_SEPARATOR, Character.LETTER_NUMBER
- });
- } catch (IOException e) {
- Log.e(TAG, e.toString());
- }
- }
-
- /**
- * 执行文本导出操作:将所有可见笔记(文件夹、普通笔记、通话笔记)导出为文本文件
- * @return 操作状态
- */
- public int exportToText() {
- // 检查SD卡是否可用
- if (!externalStorageAvailable()) {
- Log.d(TAG, "Media was not mounted");
- return STATE_SD_CARD_UNMOUONTED;
- }
-
- // 获取输出流(指向SD卡上的文件)
- PrintStream ps = getExportToTextPrintStream();
- if (ps == null) {
- Log.e(TAG, "get print stream error");
- return STATE_SYSTEM_ERROR;
- }
-
- // 1. 导出文件夹及其包含的笔记
- // 查询条件:用户创建的文件夹(排除回收站)和通话记录文件夹
- Cursor folderCursor = mContext.getContentResolver().query(
- Notes.CONTENT_NOTE_URI,
- NOTE_PROJECTION,
- "(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND "
- + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR "
- + NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null);
-
- if (folderCursor != null) {
- if (folderCursor.moveToFirst()) {
- do {
- // 获取文件夹名称(通话记录文件夹使用固定名称)
- String folderName = "";
- if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) {
- folderName = mContext.getString(R.string.call_record_folder_name);
- } else {
- folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET);
- }
- if (!TextUtils.isEmpty(folderName)) {
- ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName));
- }
- // 导出该文件夹下的笔记
- String folderId = folderCursor.getString(NOTE_COLUMN_ID);
- exportFolderToText(folderId, ps);
- } while (folderCursor.moveToNext());
- }
- folderCursor.close();
- }
-
- // 2. 导出根目录下的笔记(不属于任何文件夹的笔记)
- Cursor noteCursor = mContext.getContentResolver().query(
- Notes.CONTENT_NOTE_URI,
- NOTE_PROJECTION,
- NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID
- + "=0", null, null);
-
- if (noteCursor != null) {
- if (noteCursor.moveToFirst()) {
- do {
- // 写入笔记修改时间
- ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
- mContext.getString(R.string.format_datetime_mdhm),
- noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
- // 导出笔记内容
- String noteId = noteCursor.getString(NOTE_COLUMN_ID);
- exportNoteToText(noteId, ps);
- } while (noteCursor.moveToNext());
- }
- noteCursor.close();
- }
-
- ps.close(); // 关闭输出流
- return STATE_SUCCESS;
- }
-
- /**
- * 获取指向导出文件的打印流
- * @return 打印流,失败返回null
- */
- private PrintStream getExportToTextPrintStream() {
- // 在SD卡上创建导出文件
- File file = generateFileMountedOnSDcard(mContext, R.string.file_path,
- R.string.file_name_txt_format);
- if (file == null) {
- Log.e(TAG, "create file to exported failed");
- return null;
- }
- // 记录文件名和目录
- mFileName = file.getName();
- mFileDirectory = mContext.getString(R.string.file_path);
-
- // 创建文件输出流
- PrintStream ps = null;
- try {
- FileOutputStream fos = new FileOutputStream(file);
- ps = new PrintStream(fos);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- return null;
- } catch (NullPointerException e) {
- e.printStackTrace();
- return null;
- }
- return ps;
- }
- }
-
- /**
- * 在SD卡上生成导出文件(如果不存在则创建目录和文件)
- * @param context 上下文
- * @param filePathResId 文件夹路径的资源ID(如R.string.file_path)
- * @param fileNameFormatResId 文件名格式的资源ID(如R.string.file_name_txt_format)
- * @return 生成的文件,失败返回null
- */
- private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
- StringBuilder sb = new StringBuilder();
- // 构建文件路径:SD卡根目录 + 应用目录
- sb.append(Environment.getExternalStorageDirectory());
- sb.append(context.getString(filePathResId));
- File filedir = new File(sb.toString());
-
- // 构建文件名:格式 + 日期(如"notes_20231001.txt")
- sb.append(context.getString(
- fileNameFormatResId,
- DateFormat.format(context.getString(R.string.format_date_ymd), // 日期格式:年月日
- System.currentTimeMillis())));
- File file = new File(sb.toString());
-
- try {
- // 创建目录(如果不存在)
- if (!filedir.exists()) {
- filedir.mkdir();
- }
- // 创建文件(如果不存在)
- if (!file.exists()) {
- file.createNewFile();
- }
- return file;
- } catch (SecurityException e) {
- // 权限异常(如无写入SD卡权限)
- e.printStackTrace();
- } catch (IOException e) {
- // IO异常(如磁盘满)
- e.printStackTrace();
- }
-
- return null;
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/tool/DataUtils.java b/src/Notes-master/app/src/main/java/net/micode/notes/tool/DataUtils.java
deleted file mode 100644
index dd1836e..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/tool/DataUtils.java
+++ /dev/null
@@ -1,397 +0,0 @@
-/*
- * 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;
-
-import android.content.ContentProviderOperation;
-import android.content.ContentProviderResult;
-import android.content.ContentResolver;
-import android.content.ContentUris;
-import android.content.ContentValues;
-import android.content.OperationApplicationException;
-import android.database.Cursor;
-import android.os.RemoteException;
-import android.util.Log;
-
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.CallNote;
-import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-
-
-/**
- * 数据工具类,提供笔记数据的增删改查、移动、验证等操作
- * 主要通过ContentResolver与内容提供者交互,处理笔记和文件夹的相关数据逻辑
- */
-public class DataUtils {
- // 日志标签,用于调试输出
- public static final String TAG = "DataUtils";
-
- /**
- * 批量删除笔记或文件夹
- * @param resolver 内容解析器,用于与内容提供者交互
- * @param ids 要删除的笔记/文件夹ID集合
- * @return 删除成功返回true,否则返回false
- */
- public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) {
- // 校验参数:ID集合为空直接返回成功(无操作)
- if (ids == null) {
- Log.d(TAG, "the ids is null");
- return true;
- }
- if (ids.size() == 0) {
- Log.d(TAG, "no id is in the hashset");
- return true;
- }
-
- // 创建批量操作列表
- ArrayList operationList = new ArrayList();
- for (long id : ids) {
- // 禁止删除系统根文件夹
- if(id == Notes.ID_ROOT_FOLDER) {
- Log.e(TAG, "Don't delete system folder root");
- continue;
- }
- // 构建删除操作:根据ID删除对应的笔记/文件夹
- ContentProviderOperation.Builder builder = ContentProviderOperation
- .newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
- operationList.add(builder.build());
- }
-
- try {
- // 执行批量删除操作
- ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
- // 校验操作结果
- if (results == null || results.length == 0 || results[0] == null) {
- Log.d(TAG, "delete notes failed, ids:" + ids.toString());
- return false;
- }
- return true;
- } catch (RemoteException e) {
- // 远程调用异常(如内容提供者连接失败)
- Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
- } catch (OperationApplicationException e) {
- // 操作应用异常(如操作不符合约束)
- Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
- }
- return false;
- }
-
- /**
- * 将单个笔记移动到目标文件夹
- * @param resolver 内容解析器
- * @param id 要移动的笔记ID
- * @param srcFolderId 源文件夹ID(原所在文件夹)
- * @param desFolderId 目标文件夹ID(要移动到的文件夹)
- */
- public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
- // 封装更新数据:修改父文件夹ID、记录原文件夹ID、标记本地已修改
- ContentValues values = new ContentValues();
- values.put(NoteColumns.PARENT_ID, desFolderId); // 目标文件夹ID
- values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId); // 源文件夹ID(用于回退等场景)
- values.put(NoteColumns.LOCAL_MODIFIED, 1); // 标记为本地已修改,用于同步
- // 执行更新操作
- resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
- }
-
- /**
- * 批量将笔记移动到目标文件夹
- * @param resolver 内容解析器
- * @param ids 要移动的笔记ID集合
- * @param folderId 目标文件夹ID
- * @return 移动成功返回true,否则返回false
- */
- public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids,
- long folderId) {
- // 校验参数:ID集合为空直接返回成功
- if (ids == null) {
- Log.d(TAG, "the ids is null");
- return true;
- }
-
- // 创建批量更新操作列表
- ArrayList operationList = new ArrayList();
- for (long id : ids) {
- // 构建更新操作:修改父文件夹ID并标记本地修改
- ContentProviderOperation.Builder builder = ContentProviderOperation
- .newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
- builder.withValue(NoteColumns.PARENT_ID, folderId);
- builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);
- operationList.add(builder.build());
- }
-
- try {
- // 执行批量更新
- ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
- // 校验结果
- if (results == null || results.length == 0 || results[0] == null) {
- Log.d(TAG, "delete notes failed, ids:" + ids.toString()); // 日志文案有误,实际为移动操作
- return false;
- }
- return true;
- } catch (RemoteException e) {
- Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
- } catch (OperationApplicationException e) {
- Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
- }
- return false;
- }
-
- /**
- * 获取用户创建的文件夹数量(排除系统文件夹和回收站)
- * @param resolver 内容解析器
- * @return 文件夹数量
- */
- public static int getUserFolderCount(ContentResolver resolver) {
- // 查询条件:类型为文件夹,且父文件夹不是回收站
- Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
- new String[] { "COUNT(*)" }, // 聚合查询:统计数量
- NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?",
- new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)},
- null);
-
- int count = 0;
- if(cursor != null) {
- if(cursor.moveToFirst()) { // 游标指向第一条数据
- try {
- count = cursor.getInt(0); // 获取统计结果
- } catch (IndexOutOfBoundsException e) {
- Log.e(TAG, "get folder count failed:" + e.toString());
- } finally {
- cursor.close(); // 关闭游标释放资源
- }
- }
- }
- return count;
- }
-
- /**
- * 检查指定ID的笔记是否在数据库中可见(非回收站且类型匹配)
- * @param resolver 内容解析器
- * @param noteId 笔记ID
- * @param type 笔记类型(如普通笔记、文件夹等)
- * @return 可见返回true,否则返回false
- */
- public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
- // 查询条件:ID匹配、类型匹配、不在回收站
- Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
- null,
- NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
- new String [] {String.valueOf(type)},
- null);
-
- boolean exist = false;
- if (cursor != null) {
- exist = cursor.getCount() > 0; // 有查询结果则存在
- cursor.close();
- }
- return exist;
- }
-
- /**
- * 检查指定ID的笔记是否存在于数据库中(不区分是否在回收站)
- * @param resolver 内容解析器
- * @param noteId 笔记ID
- * @return 存在返回true,否则返回false
- */
- public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
- // 无查询条件,仅根据ID查询
- Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
- null, null, null, null);
-
- boolean exist = false;
- if (cursor != null) {
- exist = cursor.getCount() > 0;
- cursor.close();
- }
- return exist;
- }
-
- /**
- * 检查指定ID的笔记数据(如内容详情)是否存在于数据库中
- * @param resolver 内容解析器
- * @param dataId 数据ID
- * @return 存在返回true,否则返回false
- */
- public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
- // 查询数据表格中是否存在指定ID的记录
- Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
- null, null, null, null);
-
- boolean exist = false;
- if (cursor != null) {
- exist = cursor.getCount() > 0;
- cursor.close();
- }
- return exist;
- }
-
- /**
- * 检查可见文件夹中是否已存在指定名称的文件夹(排除回收站)
- * @param resolver 内容解析器
- * @param name 文件夹名称
- * @return 存在返回true,否则返回false
- */
- public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
- // 查询条件:类型为文件夹、不在回收站、名称匹配
- Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
- NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
- " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER +
- " AND " + NoteColumns.SNIPPET + "=?",
- new String[] { name }, null);
- boolean exist = false;
- if(cursor != null) {
- exist = cursor.getCount() > 0;
- cursor.close();
- }
- return exist;
- }
-
- /**
- * 获取指定文件夹下关联的桌面小部件属性集合
- * @param resolver 内容解析器
- * @param folderId 文件夹ID
- * @return 小部件属性集合(包含小部件ID和类型),无结果则返回null
- */
- public static HashSet getFolderNoteWidget(ContentResolver resolver, long folderId) {
- // 查询该文件夹下所有笔记关联的小部件ID和类型
- Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
- new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
- NoteColumns.PARENT_ID + "=?",
- new String[] { String.valueOf(folderId) },
- null);
-
- HashSet set = null;
- if (c != null) {
- if (c.moveToFirst()) {
- set = new HashSet();
- do {
- try {
- AppWidgetAttribute widget = new AppWidgetAttribute();
- widget.widgetId = c.getInt(0); // 小部件ID
- widget.widgetType = c.getInt(1); // 小部件类型
- set.add(widget);
- } catch (IndexOutOfBoundsException e) {
- Log.e(TAG, e.toString());
- }
- } while (c.moveToNext()); // 遍历所有结果
- }
- c.close();
- }
- return set;
- }
-
- /**
- * 根据笔记ID获取关联的通话记录号码
- * @param resolver 内容解析器
- * @param noteId 笔记ID(通话笔记)
- * @return 电话号码,获取失败返回空字符串
- */
- public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
- // 查询条件:属于指定笔记ID,且为通话笔记类型
- Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
- new String [] { CallNote.PHONE_NUMBER },
- CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
- new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE },
- null);
-
- if (cursor != null && cursor.moveToFirst()) {
- try {
- return cursor.getString(0); // 返回电话号码
- } catch (IndexOutOfBoundsException e) {
- Log.e(TAG, "Get call number fails " + e.toString());
- } finally {
- cursor.close();
- }
- }
- return "";
- }
-
- /**
- * 根据电话号码和通话时间获取对应的通话笔记ID
- * @param resolver 内容解析器
- * @param phoneNumber 电话号码
- * @param callDate 通话时间(毫秒时间戳)
- * @return 笔记ID,获取失败返回0
- */
- public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
- // 查询条件:通话时间匹配、通话笔记类型、电话号码匹配(使用PHONE_NUMBERS_EQUAL函数处理号码格式)
- Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
- new String [] { CallNote.NOTE_ID },
- CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
- + CallNote.PHONE_NUMBER + ",?)",
- new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber },
- null);
-
- if (cursor != null) {
- if (cursor.moveToFirst()) {
- try {
- return cursor.getLong(0); // 返回笔记ID
- } catch (IndexOutOfBoundsException e) {
- Log.e(TAG, "Get call note id fails " + e.toString());
- }
- }
- cursor.close();
- }
- return 0;
- }
-
- /**
- * 根据笔记ID获取笔记的摘要内容(snippet)
- * @param resolver 内容解析器
- * @param noteId 笔记ID
- * @return 摘要内容
- * @throws IllegalArgumentException 当笔记ID不存在时抛出异常
- */
- public static String getSnippetById(ContentResolver resolver, long noteId) {
- // 查询指定ID的笔记摘要
- Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
- new String [] { NoteColumns.SNIPPET },
- NoteColumns.ID + "=?",
- new String [] { String.valueOf(noteId)},
- null);
-
- if (cursor != null) {
- String snippet = "";
- if (cursor.moveToFirst()) {
- snippet = cursor.getString(0);
- }
- cursor.close();
- return snippet;
- }
- // 笔记不存在时抛出异常
- throw new IllegalArgumentException("Note is not found with id: " + noteId);
- }
-
- /**
- * 格式化笔记摘要:去除首尾空格,截取第一行内容
- * @param snippet 原始摘要
- * @return 格式化后的摘要
- */
- public static String getFormattedSnippet(String snippet) {
- if (snippet != null) {
- snippet = snippet.trim(); // 去除首尾空格
- int index = snippet.indexOf('\n'); // 查找换行符
- if (index != -1) {
- snippet = snippet.substring(0, index); // 截取到第一行
- }
- }
- return snippet;
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java b/src/Notes-master/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java
deleted file mode 100644
index 6ba5ab7..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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;
-
-/**
- * GTask相关字符串常量类,定义与GTask服务交互时使用的JSON键名和文件夹名称等常量
- * 统一管理常量,避免硬编码,提高代码可维护性
- */
-public class GTaskStringUtils {
-
- // ------------------------------ JSON字段键名 ------------------------------
- public final static String GTASK_JSON_ACTION_ID = "action_id"; // 操作ID
- public final static String GTASK_JSON_ACTION_LIST = "action_list"; // 操作列表
- public final static String GTASK_JSON_ACTION_TYPE = "action_type"; // 操作类型
- public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; // 操作类型:创建
- public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; // 操作类型:获取全部
- public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; // 操作类型:移动
- public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; // 操作类型:更新
- public final static String GTASK_JSON_CREATOR_ID = "creator_id"; // 创建者ID
- public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; // 子实体
- public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; // 客户端版本
- public final static String GTASK_JSON_COMPLETED = "completed"; // 是否已完成
- public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; // 当前列表ID
- public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; // 默认列表ID
- public final static String GTASK_JSON_DELETED = "deleted"; // 是否已删除
- public final static String GTASK_JSON_DEST_LIST = "dest_list"; // 目标列表
- public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; // 目标父节点
- public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; // 目标父节点类型
- public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta"; // 实体变更
- public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; // 实体类型
- public final static String GTASK_JSON_GET_DELETED = "get_deleted"; // 获取已删除项
- public final static String GTASK_JSON_ID = "id"; // 实体ID
- public final static String GTASK_JSON_INDEX = "index"; // 索引位置
- public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; // 最后修改时间
- public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; // 最新同步点
- public final static String GTASK_JSON_LIST_ID = "list_id"; // 列表ID
- public final static String GTASK_JSON_LISTS = "lists"; // 列表集合
- public final static String GTASK_JSON_NAME = "name"; // 名称
- public final static String GTASK_JSON_NEW_ID = "new_id"; // 新ID
- public final static String GTASK_JSON_NOTES = "notes"; // 备注
- public final static String GTASK_JSON_PARENT_ID = "parent_id"; // 父节点ID
- public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; // 前序节点ID
- public final static String GTASK_JSON_RESULTS = "results"; // 结果集合
- public final static String GTASK_JSON_SOURCE_LIST = "source_list"; // 源列表
- public final static String GTASK_JSON_TASKS = "tasks"; // 任务集合
- public final static String GTASK_JSON_TYPE = "type"; // 类型
- public final static String GTASK_JSON_TYPE_GROUP = "GROUP"; // 类型:分组
- public final static String GTASK_JSON_TYPE_TASK = "TASK"; // 类型:任务
- public final static String GTASK_JSON_USER = "user"; // 用户信息
-
- // ------------------------------ 文件夹名称常量 ------------------------------
- public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]"; // MIUI笔记文件夹前缀(用于区分其他文件夹)
- public final static String FOLDER_DEFAULT = "Default"; // 默认文件夹名称
- public final static String FOLDER_CALL_NOTE = "Call_Note"; // 通话笔记文件夹名称
- public final static String FOLDER_META = "METADATA"; // 元数据文件夹名称
-
- // ------------------------------ 元数据相关常量 ------------------------------
- public final static String META_HEAD_GTASK_ID = "meta_gid"; // 元数据头:GTaskID
- public final static String META_HEAD_NOTE = "meta_note"; // 元数据头:笔记
- public final static String META_HEAD_DATA = "meta_data"; // 元数据头:数据
- public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE"; // 元数据笔记名称(禁止更新和删除)
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/tool/ResourceParser.java b/src/Notes-master/app/src/main/java/net/micode/notes/tool/ResourceParser.java
deleted file mode 100644
index de3ea65..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/tool/ResourceParser.java
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * 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;
-
-import android.content.Context;
-import android.preference.PreferenceManager;
-
-import net.micode.notes.R;
-import net.micode.notes.ui.NotesPreferenceActivity;
-
-/**
- * 资源解析器类,管理应用中与UI相关的资源(如背景、文本样式等)
- * 提供各类资源的获取方法,统一管理资源ID与逻辑映射
- */
-public class ResourceParser {
-
- // 背景颜色常量(对应不同颜色的资源)
- public static final int YELLOW = 0; // 黄色
- public static final int BLUE = 1; // 蓝色
- public static final int WHITE = 2; // 白色
- public static final int GREEN = 3; // 绿色
- public static final int RED = 4; // 红色
-
- public static final int BG_DEFAULT_COLOR = YELLOW; // 默认背景颜色
-
- // 文本大小常量(对应不同尺寸的文本样式)
- public static final int TEXT_SMALL = 0; // 小
- public static final int TEXT_MEDIUM = 1; // 中
- public static final int TEXT_LARGE = 2; // 大
- public static final int TEXT_SUPER = 3; // 超大
-
- public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; // 默认字体大小
-
- /**
- * 笔记编辑界面的背景资源管理类
- * 提供笔记内容区和标题区的背景资源ID
- */
- public static class NoteBgResources {
- // 笔记内容区背景资源数组(与颜色常量顺序对应)
- private final static int [] BG_EDIT_RESOURCES = new int [] {
- R.drawable.edit_yellow, // 黄色背景
- R.drawable.edit_blue, // 蓝色背景
- R.drawable.edit_white, // 白色背景
- R.drawable.edit_green, // 绿色背景
- R.drawable.edit_red // 红色背景
- };
-
- // 笔记标题区背景资源数组(与颜色常量顺序对应)
- private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] {
- R.drawable.edit_title_yellow, // 黄色标题背景
- R.drawable.edit_title_blue, // 蓝色标题背景
- R.drawable.edit_title_white, // 白色标题背景
- R.drawable.edit_title_green, // 绿色标题背景
- R.drawable.edit_title_red // 红色标题背景
- };
-
- /**
- * 获取笔记内容区背景资源ID
- * @param id 颜色常量(如YELLOW、BLUE等)
- * @return 背景资源ID
- */
- public static int getNoteBgResource(int id) {
- return BG_EDIT_RESOURCES[id];
- }
-
- /**
- * 获取笔记标题区背景资源ID
- * @param id 颜色常量
- * @return 标题背景资源ID
- */
- public static int getNoteTitleBgResource(int id) {
- return BG_EDIT_TITLE_RESOURCES[id];
- }
- }
-
- /**
- * 获取默认的笔记背景颜色ID(根据用户设置或默认值)
- * @param context 上下文
- * @return 背景颜色常量(如YELLOW)
- */
- public static int getDefaultBgId(Context context) {
- // 检查用户是否开启了随机背景色设置
- if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
- NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
- // 随机选择一种背景色
- return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length);
- } else {
- // 使用默认背景色
- return BG_DEFAULT_COLOR;
- }
- }
-
- /**
- * 笔记列表项的背景资源管理类
- * 提供列表中不同位置项(首项、中间项、末项、单项)的背景资源
- */
- public static class NoteItemBgResources {
- // 列表首项背景资源数组
- private final static int [] BG_FIRST_RESOURCES = new int [] {
- R.drawable.list_yellow_up,
- R.drawable.list_blue_up,
- R.drawable.list_white_up,
- R.drawable.list_green_up,
- R.drawable.list_red_up
- };
-
- // 列表中间项背景资源数组
- private final static int [] BG_NORMAL_RESOURCES = new int [] {
- R.drawable.list_yellow_middle,
- R.drawable.list_blue_middle,
- R.drawable.list_white_middle,
- R.drawable.list_green_middle,
- R.drawable.list_red_middle
- };
-
- // 列表末项背景资源数组
- private final static int [] BG_LAST_RESOURCES = new int [] {
- R.drawable.list_yellow_down,
- R.drawable.list_blue_down,
- R.drawable.list_white_down,
- R.drawable.list_green_down,
- R.drawable.list_red_down,
- };
-
- // 列表单项(仅一项时)背景资源数组
- private final static int [] BG_SINGLE_RESOURCES = new int [] {
- R.drawable.list_yellow_single,
- R.drawable.list_blue_single,
- R.drawable.list_white_single,
- R.drawable.list_green_single,
- R.drawable.list_red_single
- };
-
- /**
- * 获取列表首项背景资源ID
- * @param id 颜色常量
- * @return 首项背景资源ID
- */
- public static int getNoteBgFirstRes(int id) {
- return BG_FIRST_RESOURCES[id];
- }
-
- /**
- * 获取列表末项背景资源ID
- * @param id 颜色常量
- * @return 末项背景资源ID
- */
- public static int getNoteBgLastRes(int id) {
- return BG_LAST_RESOURCES[id];
- }
-
- /**
- * 获取列表单项背景资源ID
- * @param id 颜色常量
- * @return 单项背景资源ID
- */
- public static int getNoteBgSingleRes(int id) {
- return BG_SINGLE_RESOURCES[id];
- }
-
- /**
- * 获取列表中间项背景资源ID
- * @param id 颜色常量
- * @return 中间项背景资源ID
- */
- public static int getNoteBgNormalRes(int id) {
- return BG_NORMAL_RESOURCES[id];
- }
-
- /**
- * 获取文件夹列表项的背景资源ID(固定资源)
- * @return 文件夹背景资源ID
- */
- public static int getFolderBgRes() {
- return R.drawable.list_folder;
- }
- }
-
- /**
- * 桌面小部件的背景资源管理类
- * 提供不同尺寸小部件的背景资源
- */
- public static class WidgetBgResources {
- // 2x尺寸小部件背景资源数组
- private final static int [] BG_2X_RESOURCES = new int [] {
- R.drawable.widget_2x_yellow,
- R.drawable.widget_2x_blue,
- R.drawable.widget_2x_white,
- R.drawable.widget_2x_green,
- R.drawable.widget_2x_red,
- };
-
- /**
- * 获取2x尺寸小部件背景资源ID
- * @param id 颜色常量
- * @return 2x小部件背景资源ID
- */
- public static int getWidget2xBgResource(int id) {
- return BG_2X_RESOURCES[id];
- }
-
- // 4x尺寸小部件背景资源数组
- private final static int [] BG_4X_RESOURCES = new int [] {
- R.drawable.widget_4x_yellow,
- R.drawable.widget_4x_blue,
- R.drawable.widget_4x_white,
- R.drawable.widget_4x_green,
- R.drawable.widget_4x_red
- };
-
- /**
- * 获取4x尺寸小部件背景资源ID
- * @param id 颜色常量
- * @return 4x小部件背景资源ID
- */
- public static int getWidget4xBgResource(int id) {
- return BG_4X_RESOURCES[id];
- }
- }
-
- /**
- * 文本外观样式资源管理类
- * 提供不同文本大小对应的样式资源
- */
- public static class TextAppearanceResources {
- // 文本样式资源数组(与文本大小常量顺序对应)
- private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
- R.style.TextAppearanceNormal, // 小
- R.style.TextAppearanceMedium, // 中
- R.style.TextAppearanceLarge, // 大
- R.style.TextAppearanceSuper // 超大
- };
-
- /**
- * 获取文本样式资源ID
- * @param id 文本大小常量(如TEXT_SMALL)
- * @return 文本样式资源ID
- */
- public static int getTexAppearanceResource(int id) {
- /**
- * 兼容处理:如果存储的ID超出资源数组长度,使用默认字体大小
- * 避免因SharedPreference中存储的旧值导致数组越界
- */
- if (id >= TEXTAPPEARANCE_RESOURCES.length) {
- return BG_DEFAULT_FONT_SIZE;
- }
- return TEXTAPPEARANCE_RESOURCES[id];
- }
-
- /**
- * 获取文本样式资源的数量
- * @return 资源数组长度
- */
- public static int getResourcesSize() {
- return TEXTAPPEARANCE_RESOURCES.length;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java
deleted file mode 100644
index 4cc9cf1..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java
+++ /dev/null
@@ -1,184 +0,0 @@
-package net.micode.notes.ui; // 假设包名
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.os.PowerManager;
-import android.view.Window;
-import android.view.WindowManager;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.AlertDialog;
-import android.widget.Toast;
-import android.content.Intent;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.DialogInterface.OnDismissListener;
-import android.media.MediaPlayer;
-import android.media.RingtoneManager;
-import android.net.Uri;
-import android.provider.Settings;
-import android.media.AudioManager;
-import android.text.TextUtils;
-import android.util.Log;
-
-import net.micode.notes.R;
-import net.micode.notes.data.Notes;
-import net.micode.notes.util.DataUtils;
-
-/**
- * 笔记提醒活动
- * 当笔记到达提醒时间时显示,播放提醒铃声并提供操作选项
- */
-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; // 媒体播放器(用于播放提醒铃声)
-
- /**
- * 初始化活动
- * @param savedInstanceState 保存的状态数据
- */
- @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(); // 获取启动意图
-
- 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(); // 笔记无效,直接结束
- }
- }
-
- /**
- * 判断屏幕是否亮着
- * @return 是/否
- */
- private boolean isScreenOn() {
- PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
- return pm.isScreenOn();
- }
-
- /**
- * 播放提醒铃声
- */
- private void playAlarmSound() {
- // 获取默认闹钟铃声的Uri
- 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);
- }
-
- /**
- * 对话框按钮点击事件
- * @param dialog 对话框
- * @param which 按钮标识
- */
- 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;
- }
- }
-
- /**
- * 对话框消失时调用
- * @param dialog 对话框
- */
- public void onDismiss(DialogInterface dialog) {
- stopAlarmSound(); // 停止铃声
- finish(); // 结束活动
- }
-
- /**
- * 停止提醒铃声
- */
- private void stopAlarmSound() {
- if (mPlayer != null) {
- mPlayer.stop(); // 停止播放
- mPlayer.release(); // 释放资源
- mPlayer = null;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java
deleted file mode 100644
index 5ad844d..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- *
- * 许可证声明:遵循Apache License 2.0协议
- */
-
-package net.micode.notes.ui;
-
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.ContentUris;
-import android.content.Context;
-import android.content.Intent;
-import android.database.Cursor;
-
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.NoteColumns;
-
-/**
- * 闹钟初始化接收器:系统启动时重新注册所有有效的笔记提醒
- */
-public class AlarmInitReceiver extends BroadcastReceiver {
-
- // 查询数据库的字段:笔记ID和提醒时间
- private static final String [] PROJECTION = new String [] {
- NoteColumns.ID,
- NoteColumns.ALERTED_DATE
- };
-
- // 字段索引
- private static final int COLUMN_ID = 0;
- private static final int COLUMN_ALERTED_DATE = 1;
-
- /**
- * 接收系统启动广播时调用:重新注册所有未过期的提醒
- */
- @Override
- public void onReceive(Context context, Intent intent) {
- long currentDate = System.currentTimeMillis(); // 当前时间
- // 查询所有未过期的笔记提醒
- Cursor c = context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
- PROJECTION,
- NoteColumns.ALERTED_DATE + ">? AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE,
- new String[] { String.valueOf(currentDate) }, // 只查询提醒时间在当前时间之后的
- null);
-
- if (c != null) {
- if (c.moveToFirst()) {
- do {
- // 读取提醒时间和笔记ID
- long alertDate = c.getLong(COLUMN_ALERTED_DATE);
- Intent sender = new Intent(context, AlarmReceiver.class);
- sender.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, c.getLong(COLUMN_ID)));
- // 创建延迟意图
- PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, 0);
- // 注册闹钟
- AlarmManager alermManager = (AlarmManager) context
- .getSystemService(Context.ALARM_SERVICE);
- alermManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent);
- } while (c.moveToNext()); // 处理所有符合条件的笔记
- }
- c.close(); // 关闭游标释放资源
- }
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/AlarmReceiver.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/AlarmReceiver.java
deleted file mode 100644
index 431659b..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/AlarmReceiver.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- *
- * 许可证声明:遵循Apache License 2.0协议
- */
-
-package net.micode.notes.ui;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-
-/**
- * 闹钟广播接收器:接收闹钟触发事件并启动提醒活动
- */
-public class AlarmReceiver extends BroadcastReceiver {
- /**
- * 接收广播时调用:启动提醒界面
- */
- @Override
- public void onReceive(Context context, Intent intent) {
- // 将意图转向提醒活动
- intent.setClass(context, AlarmAlertActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 允许在非活动上下文启动活动
- context.startActivity(intent); // 启动提醒界面
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/DateTimePicker.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/DateTimePicker.java
deleted file mode 100644
index 4a0b15a..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/DateTimePicker.java
+++ /dev/null
@@ -1,509 +0,0 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- *
- * 许可证声明:遵循Apache License 2.0协议
- */
-
-package net.micode.notes.ui;
-
-import java.text.DateFormatSymbols;
-import java.util.Calendar;
-
-import net.micode.notes.R;
-
-import android.content.Context;
-import android.text.format.DateFormat;
-import android.view.View;
-import android.widget.FrameLayout;
-import android.widget.NumberPicker;
-
-/**
- * 日期时间选择器:用于选择提醒时间的自定义视图
- */
-public class DateTimePicker extends FrameLayout {
-
- private static final boolean DEFAULT_ENABLE_STATE = true; // 默认启用状态
-
- // 时间常量定义
- private static final int HOURS_IN_HALF_DAY = 12; // 半天小时数
- private static final int HOURS_IN_ALL_DAY = 24; // 全天小时数
- private static final int DAYS_IN_ALL_WEEK = 7; // 一周天数
- private static final int DATE_SPINNER_MIN_VAL = 0; // 日期选择器最小值
- private static final int DATE_SPINNER_MAX_VAL = DAYS_IN_ALL_WEEK - 1; // 日期选择器最大值
- private static final int HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW = 0; // 24小时制小时最小值
- private static final int HOUR_SPINNER_MAX_VAL_24_HOUR_VIEW = 23; // 24小时制小时最大值
- private static final int HOUR_SPINNER_MIN_VAL_12_HOUR_VIEW = 1; // 12小时制小时最小值
- private static final int HOUR_SPINNER_MAX_VAL_12_HOUR_VIEW = 12; // 12小时制小时最大值
- private static final int MINUT_SPINNER_MIN_VAL = 0; // 分钟最小值
- private static final int MINUT_SPINNER_MAX_VAL = 59; // 分钟最大值
- private static final int AMPM_SPINNER_MIN_VAL = 0; // 上下午选择器最小值
- private static final int AMPM_SPINNER_MAX_VAL = 1; // 上下午选择器最大值
-
- // 选择器控件
- private final NumberPicker mDateSpinner; // 日期选择器
- private final NumberPicker mHourSpinner; // 小时选择器
- private final NumberPicker mMinuteSpinner; // 分钟选择器
- private final NumberPicker mAmPmSpinner; // 上下午选择器(12小时制)
- private Calendar mDate; // 当前日期时间
-
- private String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK]; // 日期显示文本
-
- private boolean mIsAm; // 是否上午(12小时制)
- private boolean mIs24HourView; // 是否24小时制
- private boolean mIsEnabled = DEFAULT_ENABLE_STATE; // 是否启用
- private boolean mInitialising; // 是否初始化中
-
- // 日期时间变更监听器
- private OnDateTimeChangedListener mOnDateTimeChangedListener;
-
- /**
- * 日期选择器变更监听:处理日期变更逻辑
- */
- private NumberPicker.OnValueChangeListener mOnDateChangedListener = new NumberPicker.OnValueChangeListener() {
- @Override
- public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
- // 调整日期(根据选择的偏移量)
- mDate.add(Calendar.DAY_OF_YEAR, newVal - oldVal);
- updateDateControl(); // 更新日期显示
- onDateTimeChanged(); // 触发变更回调
- }
- };
-
- /**
- * 小时选择器变更监听:处理小时变更逻辑
- */
- private NumberPicker.OnValueChangeListener mOnHourChangedListener = new NumberPicker.OnValueChangeListener() {
- @Override
- public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
- boolean isDateChanged = false;
- Calendar cal = Calendar.getInstance();
- if (!mIs24HourView) {
- // 12小时制逻辑:跨天处理
- if (!mIsAm && oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY) {
- cal.setTimeInMillis(mDate.getTimeInMillis());
- cal.add(Calendar.DAY_OF_YEAR, 1); // 切换到第二天
- isDateChanged = true;
- } else if (mIsAm && oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) {
- cal.setTimeInMillis(mDate.getTimeInMillis());
- cal.add(Calendar.DAY_OF_YEAR, -1); // 切换到前一天
- isDateChanged = true;
- }
- // 切换上下午
- if (oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY ||
- oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) {
- mIsAm = !mIsAm;
- updateAmPmControl(); // 更新上下午显示
- }
- } else {
- // 24小时制逻辑:跨天处理
- if (oldVal == HOURS_IN_ALL_DAY - 1 && newVal == 0) {
- cal.setTimeInMillis(mDate.getTimeInMillis());
- cal.add(Calendar.DAY_OF_YEAR, 1); // 切换到第二天
- isDateChanged = true;
- } else if (oldVal == 0 && newVal == HOURS_IN_ALL_DAY - 1) {
- cal.setTimeInMillis(mDate.getTimeInMillis());
- cal.add(Calendar.DAY_OF_YEAR, -1); // 切换到前一天
- isDateChanged = true;
- }
- }
- // 更新小时
- int newHour = mHourSpinner.getValue() % HOURS_IN_HALF_DAY + (mIsAm ? 0 : HOURS_IN_HALF_DAY);
- mDate.set(Calendar.HOUR_OF_DAY, newHour);
- onDateTimeChanged(); // 触发变更回调
- // 跨天则更新日期
- if (isDateChanged) {
- setCurrentYear(cal.get(Calendar.YEAR));
- setCurrentMonth(cal.get(Calendar.MONTH));
- setCurrentDay(cal.get(Calendar.DAY_OF_MONTH));
- }
- }
- };
-
- /**
- * 分钟选择器变更监听:处理分钟变更逻辑
- */
- private NumberPicker.OnValueChangeListener mOnMinuteChangedListener = new NumberPicker.OnValueChangeListener() {
- @Override
- public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
- int minValue = mMinuteSpinner.getMinValue();
- int maxValue = mMinuteSpinner.getMaxValue();
- int offset = 0;
- // 跨小时处理(如59分→0分:+1小时;0分→59分:-1小时)
- if (oldVal == maxValue && newVal == minValue) {
- offset += 1;
- } else if (oldVal == minValue && newVal == maxValue) {
- offset -= 1;
- }
- if (offset != 0) {
- mDate.add(Calendar.HOUR_OF_DAY, offset); // 调整小时
- mHourSpinner.setValue(getCurrentHour()); // 更新小时选择器
- updateDateControl(); // 更新日期显示
- // 更新上下午状态
- int newHour = getCurrentHourOfDay();
- if (newHour >= HOURS_IN_HALF_DAY) {
- mIsAm = false;
- } else {
- mIsAm = true;
- }
- updateAmPmControl(); // 更新上下午显示
- }
- mDate.set(Calendar.MINUTE, newVal); // 更新分钟
- onDateTimeChanged(); // 触发变更回调
- }
- };
-
- /**
- * 上下午选择器变更监听:处理上下午切换
- */
- private NumberPicker.OnValueChangeListener mOnAmPmChangedListener = new NumberPicker.OnValueChangeListener() {
- @Override
- public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
- mIsAm = !mIsAm; // 切换上下午
- // 调整小时(±12小时)
- if (mIsAm) {
- mDate.add(Calendar.HOUR_OF_DAY, -HOURS_IN_HALF_DAY);
- } else {
- mDate.add(Calendar.HOUR_OF_DAY, HOURS_IN_HALF_DAY);
- }
- updateAmPmControl(); // 更新上下午显示
- onDateTimeChanged(); // 触发变更回调
- }
- };
-
- /**
- * 日期时间变更监听器接口
- */
- public interface OnDateTimeChangedListener {
- void onDateTimeChanged(DateTimePicker view, int year, int month,
- int dayOfMonth, int hourOfDay, int minute);
- }
-
- /**
- * 构造方法:使用当前时间初始化
- */
- public DateTimePicker(Context context) {
- this(context, System.currentTimeMillis());
- }
-
- /**
- * 构造方法:使用指定时间初始化
- */
- public DateTimePicker(Context context, long date) {
- this(context, date, DateFormat.is24HourFormat(context)); // 根据系统设置判断是否24小时制
- }
-
- /**
- * 构造方法:使用指定时间和时间制初始化
- */
- public DateTimePicker(Context context, long date, boolean is24HourView) {
- super(context);
- mDate = Calendar.getInstance();
- mInitialising = true;
- mIsAm = getCurrentHourOfDay() >= HOURS_IN_HALF_DAY; // 初始化上下午状态
- inflate(context, R.layout.datetime_picker, this); // 加载布局
-
- // 初始化日期选择器
- mDateSpinner = (NumberPicker) findViewById(R.id.date);
- mDateSpinner.setMinValue(DATE_SPINNER_MIN_VAL);
- mDateSpinner.setMaxValue(DATE_SPINNER_MAX_VAL);
- mDateSpinner.setOnValueChangedListener(mOnDateChangedListener);
-
- // 初始化小时选择器
- mHourSpinner = (NumberPicker) findViewById(R.id.hour);
- mHourSpinner.setOnValueChangedListener(mOnHourChangedListener);
-
- // 初始化分钟选择器
- mMinuteSpinner = (NumberPicker) findViewById(R.id.minute);
- mMinuteSpinner.setMinValue(MINUT_SPINNER_MIN_VAL);
- mMinuteSpinner.setMaxValue(MINUT_SPINNER_MAX_VAL);
- mMinuteSpinner.setOnLongPressUpdateInterval(100); // 长按更新间隔(100ms)
- mMinuteSpinner.setOnValueChangedListener(mOnMinuteChangedListener);
-
- // 初始化上下午选择器
- String[] stringsForAmPm = new DateFormatSymbols().getAmPmStrings(); // 获取"上午"/"下午"文本
- mAmPmSpinner = (NumberPicker) findViewById(R.id.amPm);
- mAmPmSpinner.setMinValue(AMPM_SPINNER_MIN_VAL);
- mAmPmSpinner.setMaxValue(AMPM_SPINNER_MAX_VAL);
- mAmPmSpinner.setDisplayedValues(stringsForAmPm); // 设置显示文本
- mAmPmSpinner.setOnValueChangedListener(mOnAmPmChangedListener);
-
- // 更新控件到初始状态
- updateDateControl();
- updateHourControl();
- updateAmPmControl();
-
- set24HourView(is24HourView); // 设置时间制
-
- setCurrentDate(date); // 设置初始时间
-
- setEnabled(isEnabled()); // 设置启用状态
-
- mInitialising = false; // 初始化完成
- }
-
- /**
- * 设置控件启用状态
- */
- @Override
- public void setEnabled(boolean enabled) {
- if (mIsEnabled == enabled) {
- return;
- }
- super.setEnabled(enabled);
- // 同步所有选择器的启用状态
- mDateSpinner.setEnabled(enabled);
- mMinuteSpinner.setEnabled(enabled);
- mHourSpinner.setEnabled(enabled);
- mAmPmSpinner.setEnabled(enabled);
- mIsEnabled = enabled;
- }
-
- /**
- * 获取控件启用状态
- */
- @Override
- public boolean isEnabled() {
- return mIsEnabled;
- }
-
- /**
- * 获取当前日期时间(毫秒)
- */
- public long getCurrentDateInTimeMillis() {
- return mDate.getTimeInMillis();
- }
-
- /**
- * 设置当前日期时间(毫秒)
- */
- public void setCurrentDate(long date) {
- Calendar cal = Calendar.getInstance();
- cal.setTimeInMillis(date);
- setCurrentDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH),
- cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE));
- }
-
- /**
- * 设置当前日期时间(年月日时分)
- */
- public void setCurrentDate(int year, int month,
- int dayOfMonth, int hourOfDay, int minute) {
- setCurrentYear(year);
- setCurrentMonth(month);
- setCurrentDay(dayOfMonth);
- setCurrentHour(hourOfDay);
- setCurrentMinute(minute);
- }
-
- /**
- * 获取当前年份
- */
- public int getCurrentYear() {
- return mDate.get(Calendar.YEAR);
- }
-
- /**
- * 设置当前年份
- */
- public void setCurrentYear(int year) {
- if (!mInitialising && year == getCurrentYear()) {
- return;
- }
- mDate.set(Calendar.YEAR, year);
- updateDateControl(); // 更新日期显示
- onDateTimeChanged(); // 触发变更回调
- }
-
- /**
- * 获取当前月份(0-11)
- */
- public int getCurrentMonth() {
- return mDate.get(Calendar.MONTH);
- }
-
- /**
- * 设置当前月份(0-11)
- */
- public void setCurrentMonth(int month) {
- if (!mInitialising && month == getCurrentMonth()) {
- return;
- }
- mDate.set(Calendar.MONTH, month);
- updateDateControl(); // 更新日期显示
- onDateTimeChanged(); // 触发变更回调
- }
-
- /**
- * 获取当前日
- */
- public int getCurrentDay() {
- return mDate.get(Calendar.DAY_OF_MONTH);
- }
-
- /**
- * 设置当前日
- */
- public void setCurrentDay(int dayOfMonth) {
- if (!mInitialising && dayOfMonth == getCurrentDay()) {
- return;
- }
- mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
- updateDateControl(); // 更新日期显示
- onDateTimeChanged(); // 触发变更回调
- }
-
- /**
- * 获取当前小时(24小时制,0-23)
- */
- public int getCurrentHourOfDay() {
- return mDate.get(Calendar.HOUR_OF_DAY);
- }
-
- /**
- * 获取当前小时(根据时间制转换)
- */
- private int getCurrentHour() {
- if (mIs24HourView){
- return getCurrentHourOfDay(); // 24小时制直接返回
- } else {
- // 12小时制转换(0→12,13→1等)
- int hour = getCurrentHourOfDay();
- if (hour > HOURS_IN_HALF_DAY) {
- return hour - HOURS_IN_HALF_DAY;
- } else {
- return hour == 0 ? HOURS_IN_HALF_DAY : hour;
- }
- }
- }
-
- /**
- * 设置当前小时(24小时制,0-23)
- */
- public void setCurrentHour(int hourOfDay) {
- if (!mInitialising && hourOfDay == getCurrentHourOfDay()) {
- return;
- }
- mDate.set(Calendar.HOUR_OF_DAY, hourOfDay);
- if (!mIs24HourView) {
- // 12小时制处理上下午
- if (hourOfDay >= HOURS_IN_HALF_DAY) {
- mIsAm = false;
- if (hourOfDay > HOURS_IN_HALF_DAY) {
- hourOfDay -= HOURS_IN_HALF_DAY; // 转换为12小时制
- }
- } else {
- mIsAm = true;
- if (hourOfDay == 0) {
- hourOfDay = HOURS_IN_HALF_DAY; // 0点→12点
- }
- }
- updateAmPmControl(); // 更新上下午显示
- }
- mHourSpinner.setValue(hourOfDay); // 更新选择器
- onDateTimeChanged(); // 触发变更回调
- }
-
- /**
- * 获取当前分钟
- */
- public int getCurrentMinute() {
- return mDate.get(Calendar.MINUTE);
- }
-
- /**
- * 设置当前分钟
- */
- public void setCurrentMinute(int minute) {
- if (!mInitialising && minute == getCurrentMinute()) {
- return;
- }
- mMinuteSpinner.setValue(minute); // 更新选择器
- mDate.set(Calendar.MINUTE, minute); // 更新日期
- onDateTimeChanged(); // 触发变更回调
- }
-
- /**
- * 判断是否为24小时制
- */
- public boolean is24HourView () {
- return mIs24HourView;
- }
-
- /**
- * 设置时间制(24小时/12小时)
- */
- public void set24HourView(boolean is24HourView) {
- if (mIs24HourView == is24HourView) {
- return;
- }
- mIs24HourView = is24HourView;
- // 显示/隐藏上下午选择器
- mAmPmSpinner.setVisibility(is24HourView ? View.GONE : View.VISIBLE);
- int hour = getCurrentHourOfDay();
- updateHourControl(); // 更新小时选择器范围
- setCurrentHour(hour); // 重新设置小时
- updateAmPmControl(); // 更新上下午显示
- }
-
- /**
- * 更新日期选择器显示:生成近7天的日期文本
- */
- private void updateDateControl() {
- Calendar cal = Calendar.getInstance();
- cal.setTimeInMillis(mDate.getTimeInMillis());
- cal.add(Calendar.DAY_OF_YEAR, -DAYS_IN_ALL_WEEK / 2 - 1); // 计算起始日期
- mDateSpinner.setDisplayedValues(null);
- // 生成7天的日期文本(如"05.20 星期一")
- for (int i = 0; i < DAYS_IN_ALL_WEEK; ++i) {
- cal.add(Calendar.DAY_OF_YEAR, 1);
- mDateDisplayValues[i] = (String) DateFormat.format("MM.dd EEEE", cal);
- }
- mDateSpinner.setDisplayedValues(mDateDisplayValues);
- mDateSpinner.setValue(DAYS_IN_ALL_WEEK / 2); // 默认选中中间项(当前日期)
- mDateSpinner.invalidate();
- }
-
- /**
- * 更新上下午选择器显示
- */
- private void updateAmPmControl() {
- if (mIs24HourView) {
- mAmPmSpinner.setVisibility(View.GONE); // 24小时制隐藏
- } else {
- // 12小时制设置上下午值
- int index = mIsAm ? Calendar.AM : Calendar.PM;
- mAmPmSpinner.setValue(index);
- mAmPmSpinner.setVisibility(View.VISIBLE);
- }
- }
-
- /**
- * 更新小时选择器范围(根据时间制)
- */
- private void updateHourControl() {
- if (mIs24HourView) {
- mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW);
- mHourSpinner.setMaxValue(HOUR_SPINNER_MAX_VAL_24_HOUR_VIEW);
- } else {
- mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_12_HOUR_VIEW);
- mHourSpinner.setMaxValue(HOUR_SPINNER_MAX_VAL_12_HOUR_VIEW);
- }
- }
-
- /**
- * 设置日期时间变更监听器
- */
- public void setOnDateTimeChangedListener(OnDateTimeChangedListener callback) {
- mOnDateTimeChangedListener = callback;
- }
-
- /**
- * 触发日期时间变更回调
- */
- private void onDateTimeChanged() {
- if (mOnDateTimeChangedListener != null) {
- mOnDateTimeChangedListener.onDateTimeChanged(this, getCurrentYear(),
- getCurrentMonth(), getCurrentDay(), getCurrentHourOfDay(), getCurrentMinute());
- }
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/DateTimePickerDialog.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/DateTimePickerDialog.java
deleted file mode 100644
index 8df9a36..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/DateTimePickerDialog.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * 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 java.util.Calendar;
-
-import net.micode.notes.R;
-import net.micode.notes.ui.DateTimePicker;
-import net.micode.notes.ui.DateTimePicker.OnDateTimeChangedListener;
-
-import android.app.AlertDialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.DialogInterface.OnClickListener;
-import android.text.format.DateFormat;
-import android.text.format.DateUtils;
-
-/**
- * 日期时间选择对话框
- * 用于选择具体的日期和时间(如笔记提醒时间)
- */
-public class DateTimePickerDialog extends AlertDialog implements OnClickListener {
-
- private Calendar mDate = Calendar.getInstance(); // 日历实例,用于处理日期时间
- private boolean mIs24HourView; // 是否为24小时制
- private OnDateTimeSetListener mOnDateTimeSetListener; // 日期时间设置监听器
- private DateTimePicker mDateTimePicker; // 日期时间选择器控件
-
- /**
- * 日期时间设置完成的监听器接口
- */
- public interface OnDateTimeSetListener {
- /**
- * 日期时间设置完成时回调
- * @param dialog 当前对话框
- * @param date 选中的日期时间(时间戳)
- */
- void OnDateTimeSet(AlertDialog dialog, long date);
- }
-
- /**
- * 构造方法
- * @param context 上下文环境
- * @param date 初始日期时间(时间戳)
- */
- public DateTimePickerDialog(Context context, long date) {
- super(context);
- mDateTimePicker = new DateTimePicker(context); // 初始化日期时间选择器
- setView(mDateTimePicker); // 设置对话框内容为选择器
-
- // 设置日期时间变化监听器
- mDateTimePicker.setOnDateTimeChangedListener(new OnDateTimeChangedListener() {
- public void onDateTimeChanged(DateTimePicker view, int year, int month,
- int dayOfMonth, int hourOfDay, int minute) {
- // 更新日历实例的日期时间
- mDate.set(Calendar.YEAR, year);
- mDate.set(Calendar.MONTH, month);
- mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
- mDate.set(Calendar.HOUR_OF_DAY, hourOfDay);
- mDate.set(Calendar.MINUTE, minute);
- updateTitle(mDate.getTimeInMillis()); // 更新对话框标题
- }
- });
-
- // 初始化日期时间
- mDate.setTimeInMillis(date);
- mDate.set(Calendar.SECOND, 0); // 秒数设为0
- mDateTimePicker.setCurrentDate(mDate.getTimeInMillis()); // 设置选择器的初始时间
-
- // 设置对话框按钮
- setButton(context.getString(R.string.datetime_dialog_ok), this); // 确定按钮
- setButton2(context.getString(R.string.datetime_dialog_cancel), (OnClickListener)null); // 取消按钮
-
- // 设置时间格式(24小时制或12小时制)
- set24HourView(DateFormat.is24HourFormat(this.getContext()));
- updateTitle(mDate.getTimeInMillis()); // 更新标题
- }
-
- /**
- * 设置是否为24小时制
- * @param is24HourView 是/否
- */
- public void set24HourView(boolean is24HourView) {
- mIs24HourView = is24HourView;
- }
-
- /**
- * 设置日期时间设置监听器
- * @param callBack 监听器实例
- */
- public void setOnDateTimeSetListener(OnDateTimeSetListener callBack) {
- mOnDateTimeSetListener = callBack;
- }
-
- /**
- * 更新对话框标题(显示当前选中的日期时间)
- * @param date 日期时间(时间戳)
- */
- private void updateTitle(long date) {
- // 日期时间格式:显示年、月、日、时间
- int flag = DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME;
- // 根据24小时制设置格式
- flag |= mIs24HourView ? DateUtils.FORMAT_24HOUR : DateUtils.FORMAT_24HOUR;
- // 设置标题为格式化后的日期时间
- setTitle(DateUtils.formatDateTime(this.getContext(), date, flag));
- }
-
- /**
- * 对话框按钮点击事件
- * @param arg0 对话框
- * @param arg1 按钮标识
- */
- public void onClick(DialogInterface arg0, int arg1) {
- if (mOnDateTimeSetListener != null) {
- // 回调监听器,传递选中的日期时间
- mOnDateTimeSetListener.OnDateTimeSet(this, mDate.getTimeInMillis());
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/DropdownMenu.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/DropdownMenu.java
deleted file mode 100644
index 5a200db..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/DropdownMenu.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package net.micode.notes.ui; // 假设包名
-
-import android.content.Context;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.PopupMenu;
-import android.widget.PopupMenu.OnMenuItemClickListener;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MenuInflater;
-
-import net.micode.notes.R;
-
-/**
- * 下拉菜单封装类
- * 用于在按钮点击时显示下拉菜单
- */
-public class DropdownMenu {
- private Button mButton; // 触发下拉菜单的按钮
- private PopupMenu mPopupMenu; // 弹出菜单
- private Menu mMenu; // 菜单实例
-
- /**
- * 构造方法
- * @param context 上下文环境
- * @param button 触发按钮
- * @param menuId 菜单资源ID
- */
- public DropdownMenu(Context context, Button button, int menuId) {
- mButton = button;
- mButton.setBackgroundResource(R.drawable.dropdown_icon); // 设置按钮背景(下拉图标)
- mPopupMenu = new PopupMenu(context, mButton); // 初始化弹出菜单,锚点为按钮
- mMenu = mPopupMenu.getMenu(); // 获取菜单实例
- // 加载菜单资源
- mPopupMenu.getMenuInflater().inflate(menuId, mMenu);
- // 设置按钮点击事件:显示下拉菜单
- mButton.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- mPopupMenu.show();
- }
- });
- }
-
- /**
- * 设置下拉菜单项的点击监听器
- * @param listener 监听器实例
- */
- public void setOnDropdownMenuItemClickListener(OnMenuItemClickListener listener) {
- if (mPopupMenu != null) {
- mPopupMenu.setOnMenuItemClickListener(listener);
- }
- }
-
- /**
- * 根据ID查找菜单项
- * @param id 菜单项ID
- * @return 菜单项,若未找到则为null
- */
- public MenuItem findItem(int id) {
- return mMenu.findItem(id);
- }
-
- /**
- * 设置按钮的文本(显示选中状态或数量等)
- * @param title 文本内容
- */
- public void setTitle(CharSequence title) {
- mButton.setText(title);
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/FoldersListAdapter.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/FoldersListAdapter.java
deleted file mode 100644
index 65433a2..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/FoldersListAdapter.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package net.micode.notes.ui; // 假设包名
-
-import android.content.Context;
-import android.database.Cursor;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.CursorAdapter;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-import net.micode.notes.R;
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.NoteColumns;
-
-/**
- * 文件夹列表适配器
- * 用于在文件夹选择对话框中显示文件夹列表
- */
-public class FoldersListAdapter extends CursorAdapter {
- // 查询文件夹时的字段投影
- public static final String [] PROJECTION = {
- NoteColumns.ID, // 文件夹ID
- NoteColumns.SNIPPET // 文件夹名称
- };
-
- // 字段索引(与PROJECTION对应)
- public static final int ID_COLUMN = 0;
- public static final int NAME_COLUMN = 1;
-
- /**
- * 构造方法
- * @param context 上下文环境
- * @param c 数据游标
- */
- public FoldersListAdapter(Context context, Cursor c) {
- super(context, c);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * 创建新的列表项视图
- * @param context 上下文环境
- * @param cursor 数据游标
- * @param parent 父容器
- * @return 新创建的视图
- */
- @Override
- public View newView(Context context, Cursor cursor, ViewGroup parent) {
- return new FolderListItem(context); // 创建自定义文件夹列表项
- }
-
- /**
- * 将数据绑定到视图
- * @param view 列表项视图
- * @param context 上下文环境
- * @param cursor 数据游标
- */
- @Override
- public void bindView(View view, Context context, Cursor cursor) {
- if (view instanceof FolderListItem) { // 确认视图类型
- // 根文件夹显示特定名称,其他文件夹显示自身名称
- String folderName = (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context
- .getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
- ((FolderListItem) view).bind(folderName); // 绑定文件夹名称
- }
- }
-
- /**
- * 获取指定位置的文件夹名称
- * @param context 上下文环境
- * @param position 位置
- * @return 文件夹名称
- */
- public String getFolderName(Context context, int position) {
- Cursor cursor = (Cursor) getItem(position); // 获取游标
- // 根文件夹返回特定名称,其他返回自身名称
- return (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context
- .getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
- }
-
- /**
- * 文件夹列表项视图的内部类
- */
- private class FolderListItem extends LinearLayout {
- private TextView mName; // 文件夹名称文本
-
- /**
- * 构造方法
- * @param context 上下文环境
- */
- public FolderListItem(Context context) {
- super(context);
- inflate(context, R.layout.folder_list_item, this); // 加载布局
- mName = (TextView) findViewById(R.id.tv_folder_name); // 获取名称文本控件
- }
-
- /**
- * 绑定文件夹名称到视图
- * @param name 文件夹名称
- */
- public void bind(String name) {
- mName.setText(name); // 设置名称
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java
deleted file mode 100644
index 8c84a7e..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java
+++ /dev/null
@@ -1,1034 +0,0 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- *
- * 许可证声明:遵循Apache License 2.0协议,允许在合规前提下使用、修改和分发本软件
- */
-
-package net.micode.notes.ui;
-
-import android.app.Activity;
-import android.app.AlarmManager;
-import android.app.AlertDialog;
-import android.app.PendingIntent;
-import android.app.SearchManager;
-import android.appwidget.AppWidgetManager;
-import android.content.ContentUris;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.graphics.Paint;
-import android.os.Bundle;
-import android.preference.PreferenceManager;
-import android.text.Spannable;
-import android.text.SpannableString;
-import android.text.TextUtils;
-import android.text.format.DateUtils;
-import android.text.style.BackgroundColorSpan;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.WindowManager;
-import android.widget.CheckBox;
-import android.widget.CompoundButton;
-import android.widget.CompoundButton.OnCheckedChangeListener;
-import android.widget.EditText;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import net.micode.notes.R;
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.TextNote;
-import net.micode.notes.model.WorkingNote;
-import net.micode.notes.model.WorkingNote.NoteSettingChangedListener;
-import net.micode.notes.tool.DataUtils;
-import net.micode.notes.tool.ResourceParser;
-import net.micode.notes.tool.ResourceParser.TextAppearanceResources;
-import net.micode.notes.ui.DateTimePickerDialog.OnDateTimeSetListener;
-import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener;
-import net.micode.notes.widget.NoteWidgetProvider_2x;
-import net.micode.notes.widget.NoteWidgetProvider_4x;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-
-/**
- * 笔记编辑活动类:负责笔记的创建、编辑、保存、设置提醒等核心功能
- * 实现了点击事件监听、笔记设置变更监听、文本变更监听接口
- */
-public class NoteEditActivity extends Activity implements OnClickListener,
- NoteSettingChangedListener, OnTextViewChangeListener {
-
- /**
- * 头部视图持有者:管理标题栏中的UI元素(修改时间、提醒图标、提醒日期、背景设置按钮)
- */
- private class HeadViewHolder {
- public TextView tvModified; // 显示笔记修改时间
- public ImageView ivAlertIcon; // 提醒图标
- public TextView tvAlertDate; // 显示提醒日期
- public ImageView ibSetBgColor; // 设置背景颜色按钮
- }
-
- // 背景颜色选择按钮与对应资源ID的映射(键:按钮ID,值:颜色资源ID)
- private static final Map sBgSelectorBtnsMap = new HashMap();
- static {
- sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
- sBgSelectorBtnsMap.put(R.id.iv_bg_red, ResourceParser.RED);
- sBgSelectorBtnsMap.put(R.id.iv_bg_blue, ResourceParser.BLUE);
- sBgSelectorBtnsMap.put(R.id.iv_bg_green, ResourceParser.GREEN);
- sBgSelectorBtnsMap.put(R.id.iv_bg_white, ResourceParser.WHITE);
- }
-
- // 背景颜色与选中状态图标的映射(键:颜色资源ID,值:选中图标ID)
- private static final Map sBgSelectorSelectionMap = new HashMap();
- static {
- sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select);
- sBgSelectorSelectionMap.put(ResourceParser.RED, R.id.iv_bg_red_select);
- sBgSelectorSelectionMap.put(ResourceParser.BLUE, R.id.iv_bg_blue_select);
- sBgSelectorSelectionMap.put(ResourceParser.GREEN, R.id.iv_bg_green_select);
- sBgSelectorSelectionMap.put(ResourceParser.WHITE, R.id.iv_bg_white_select);
- }
-
- // 字体大小按钮与对应资源ID的映射(键:按钮布局ID,值:字体大小资源ID)
- private static final Map sFontSizeBtnsMap = new HashMap();
- static {
- sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE);
- sFontSizeBtnsMap.put(R.id.ll_font_small, ResourceParser.TEXT_SMALL);
- sFontSizeBtnsMap.put(R.id.ll_font_normal, ResourceParser.TEXT_MEDIUM);
- sFontSizeBtnsMap.put(R.id.ll_font_super, ResourceParser.TEXT_SUPER);
- }
-
- // 字体大小与选中状态图标的映射(键:字体大小资源ID,值:选中图标ID)
- private static final Map sFontSelectorSelectionMap = new HashMap();
- static {
- sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select);
- sFontSelectorSelectionMap.put(ResourceParser.TEXT_SMALL, R.id.iv_small_select);
- sFontSelectorSelectionMap.put(ResourceParser.TEXT_MEDIUM, R.id.iv_medium_select);
- sFontSelectorSelectionMap.put(ResourceParser.TEXT_SUPER, R.id.iv_super_select);
- }
-
- private static final String TAG = "NoteEditActivity"; // 日志标签
-
- private HeadViewHolder mNoteHeaderHolder; // 头部视图持有者实例
- private View mHeadViewPanel; // 头部视图面板
- private View mNoteBgColorSelector; // 背景颜色选择器面板
- private View mFontSizeSelector; // 字体大小选择器面板
- private EditText mNoteEditor; // 笔记编辑文本框
- private View mNoteEditorPanel; // 笔记编辑面板
- private WorkingNote mWorkingNote; // 当前操作的笔记实例
- private SharedPreferences mSharedPrefs; // 共享偏好设置(用于保存字体大小)
- private int mFontSizeId; // 当前字体大小ID
-
- private static final String PREFERENCE_FONT_SIZE = "pref_font_size"; // 字体大小偏好键
- private static final int SHORTCUT_ICON_TITLE_MAX_LEN = 10; // 桌面快捷方式标题最大长度
-
- public static final String TAG_CHECKED = String.valueOf('\u221A'); // 复选框选中标记(√)
- public static final String TAG_UNCHECKED = String.valueOf('\u25A1'); // 复选框未选中标记(□)
-
- private LinearLayout mEditTextList; // 列表模式下的编辑框容器
- private String mUserQuery; // 搜索查询关键词(用于高亮显示)
- private Pattern mPattern; // 搜索关键词的正则表达式模式
-
-
- /**
- * 活动创建时调用:初始化布局和活动状态
- */
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- this.setContentView(R.layout.note_edit); // 设置布局文件
-
- // 如果是首次创建且初始化状态失败,则结束活动
- if (savedInstanceState == null && !initActivityState(getIntent())) {
- finish();
- return;
- }
- initResources(); // 初始化UI资源
- }
-
- /**
- * 活动重建时调用(如屏幕旋转):恢复之前保存的状态
- */
- @Override
- protected void onRestoreInstanceState(Bundle savedInstanceState) {
- super.onRestoreInstanceState(savedInstanceState);
- if (savedInstanceState != null && savedInstanceState.containsKey(Intent.EXTRA_UID)) {
- // 从保存的NoteID恢复笔记状态
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.putExtra(Intent.EXTRA_UID, savedInstanceState.getLong(Intent.EXTRA_UID));
- if (!initActivityState(intent)) {
- finish();
- return;
- }
- Log.d(TAG, "从被销毁的活动中恢复状态");
- }
- }
-
- /**
- * 初始化活动状态:根据意图(Intent)加载已有笔记或创建新笔记
- * @param intent 启动活动的意图
- * @return 是否初始化成功
- */
- private boolean initActivityState(Intent intent) {
- mWorkingNote = null;
- // 处理查看已有笔记的意图
- if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
- long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
- mUserQuery = "";
-
- // 从搜索结果启动时,获取搜索关键词和笔记ID
- if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {
- noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
- mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);
- }
-
- // 检查笔记是否存在,不存在则跳转到列表页
- if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) {
- Intent jump = new Intent(this, NotesListActivity.class);
- startActivity(jump);
- showToast(R.string.error_note_not_exist);
- finish();
- return false;
- } else {
- mWorkingNote = WorkingNote.load(this, noteId); // 加载笔记
- if (mWorkingNote == null) {
- Log.e(TAG, "加载笔记失败,ID: " + noteId);
- finish();
- return false;
- }
- }
- // 隐藏软键盘
- getWindow().setSoftInputMode(
- WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
- | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
- }
- // 处理创建或编辑新笔记的意图
- else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
- long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
- int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
- AppWidgetManager.INVALID_APPWIDGET_ID);
- int widgetType = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_TYPE,
- Notes.TYPE_WIDGET_INVALIDE);
- int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID,
- ResourceParser.getDefaultBgId(this));
-
- // 处理通话记录笔记(从通话记录跳转创建)
- String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
- long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);
- if (callDate != 0 && phoneNumber != null) {
- if (TextUtils.isEmpty(phoneNumber)) {
- Log.w(TAG, "通话记录号码为空");
- }
- // 检查是否已存在该通话记录的笔记
- long noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(),
- phoneNumber, callDate);
- if (noteId > 0) {
- mWorkingNote = WorkingNote.load(this, noteId);
- if (mWorkingNote == null) {
- Log.e(TAG, "加载通话笔记失败,ID: " + noteId);
- finish();
- return false;
- }
- } else {
- // 创建新的通话笔记
- mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId,
- widgetType, bgResId);
- mWorkingNote.convertToCallNote(phoneNumber, callDate);
- }
- } else {
- // 创建普通空笔记
- mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType,
- bgResId);
- }
-
- // 显示软键盘
- getWindow().setSoftInputMode(
- WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
- | WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
- } else {
- Log.e(TAG, "意图未指定动作,不支持该操作");
- finish();
- return false;
- }
- mWorkingNote.setOnSettingStatusChangedListener(this); // 设置笔记变更监听器
- return true;
- }
-
- /**
- * 活动恢复可见时调用:初始化笔记显示内容
- */
- @Override
- protected void onResume() {
- super.onResume();
- initNoteScreen();
- }
-
- /**
- * 初始化笔记屏幕显示:设置文本样式、内容、背景等
- */
- private void initNoteScreen() {
- // 设置字体样式
- mNoteEditor.setTextAppearance(this, TextAppearanceResources
- .getTexAppearanceResource(mFontSizeId));
- // 根据笔记模式(列表/普通)显示内容
- if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
- switchToListMode(mWorkingNote.getContent()); // 切换到列表模式
- } else {
- // 普通模式:高亮显示搜索关键词
- mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
- mNoteEditor.setSelection(mNoteEditor.getText().length()); // 光标定位到末尾
- }
- // 隐藏所有背景选中图标,只显示当前选中的
- for (Integer id : sBgSelectorSelectionMap.keySet()) {
- findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);
- }
- // 设置头部和编辑区背景
- mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
- mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
-
- // 显示修改时间
- mNoteHeaderHolder.tvModified.setText(DateUtils.formatDateTime(this,
- mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_DATE
- | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME
- | DateUtils.FORMAT_SHOW_YEAR));
-
- // 显示提醒信息
- showAlertHeader();
- }
-
- /**
- * 显示提醒头部信息:根据提醒状态显示过期或剩余时间
- */
- private void showAlertHeader() {
- if (mWorkingNote.hasClockAlert()) {
- long time = System.currentTimeMillis();
- if (time > mWorkingNote.getAlertDate()) {
- mNoteHeaderHolder.tvAlertDate.setText(R.string.note_alert_expired); // 提醒已过期
- } else {
- // 显示相对时间(如"30分钟后")
- mNoteHeaderHolder.tvAlertDate.setText(DateUtils.getRelativeTimeSpanString(
- mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS));
- }
- mNoteHeaderHolder.tvAlertDate.setVisibility(View.VISIBLE);
- mNoteHeaderHolder.ivAlertIcon.setVisibility(View.VISIBLE);
- } else {
- // 无提醒时隐藏相关控件
- mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
- mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
- };
- }
-
- /**
- * 处理新意图(如从其他地方再次启动该活动)
- */
- @Override
- protected void onNewIntent(Intent intent) {
- super.onNewIntent(intent);
- initActivityState(intent); // 重新初始化活动状态
- }
-
- /**
- * 保存活动状态:在活动可能被销毁前保存当前笔记ID
- */
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- // 新笔记需先保存以生成ID
- if (!mWorkingNote.existInDatabase()) {
- saveNote();
- }
- outState.putLong(Intent.EXTRA_UID, mWorkingNote.getNoteId());
- Log.d(TAG, "保存笔记ID: " + mWorkingNote.getNoteId() + " 到实例状态");
- }
-
- /**
- * 分发触摸事件:点击面板外区域时关闭选择器
- */
- @Override
- public boolean dispatchTouchEvent(MotionEvent ev) {
- // 点击背景选择器外时关闭
- if (mNoteBgColorSelector.getVisibility() == View.VISIBLE
- && !inRangeOfView(mNoteBgColorSelector, ev)) {
- mNoteBgColorSelector.setVisibility(View.GONE);
- return true;
- }
-
- // 点击字体选择器外时关闭
- if (mFontSizeSelector.getVisibility() == View.VISIBLE
- && !inRangeOfView(mFontSizeSelector, ev)) {
- mFontSizeSelector.setVisibility(View.GONE);
- return true;
- }
- return super.dispatchTouchEvent(ev);
- }
-
- /**
- * 判断触摸事件是否在指定视图范围内
- * @param view 目标视图
- * @param ev 触摸事件
- * @return 是否在范围内
- */
- private boolean inRangeOfView(View view, MotionEvent ev) {
- int []location = new int[2];
- view.getLocationOnScreen(location); // 获取视图在屏幕上的坐标
- int x = location[0];
- int y = location[1];
- // 检查触摸坐标是否在视图范围内
- if (ev.getX() < x
- || ev.getX() > (x + view.getWidth())
- || ev.getY() < y
- || ev.getY() > (y + view.getHeight())) {
- return false;
- }
- return true;
- }
-
- /**
- * 初始化UI资源:绑定视图控件并设置监听器
- */
- private void initResources() {
- mHeadViewPanel = findViewById(R.id.note_title);
- mNoteHeaderHolder = new HeadViewHolder();
- // 绑定头部视图控件
- mNoteHeaderHolder.tvModified = (TextView) findViewById(R.id.tv_modified_date);
- mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon);
- mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);
- mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
- mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this); // 背景设置按钮点击监听
-
- mNoteEditor = (EditText) findViewById(R.id.note_edit_view);
- mNoteEditorPanel = findViewById(R.id.sv_note_edit);
- mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector);
- // 绑定背景颜色选择按钮并设置监听
- for (int id : sBgSelectorBtnsMap.keySet()) {
- ImageView iv = (ImageView) findViewById(id);
- iv.setOnClickListener(this);
- }
-
- mFontSizeSelector = findViewById(R.id.font_size_selector);
- // 绑定字体大小选择按钮并设置监听
- for (int id : sFontSizeBtnsMap.keySet()) {
- View view = findViewById(id);
- view.setOnClickListener(this);
- };
-
- // 初始化字体大小偏好设置
- mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
- mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);
- // 修复字体大小ID可能超出范围的问题
- if(mFontSizeId >= TextAppearanceResources.getResourcesSize()) {
- mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE;
- }
-
- mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list); // 列表模式容器
- }
-
- /**
- * 活动暂停时调用:保存笔记并清除设置状态
- */
- @Override
- protected void onPause() {
- super.onPause();
- if(saveNote()) {
- Log.d(TAG, "笔记已保存,长度: " + mWorkingNote.getContent().length());
- }
- clearSettingState(); // 关闭所有选择器面板
- }
-
- /**
- * 更新桌面小组件:当笔记关联的小组件存在时,刷新其显示
- */
- private void updateWidget() {
- Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
- // 根据小组件类型设置对应的广播接收器
- if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {
- intent.setClass(this, NoteWidgetProvider_2x.class);
- } else if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_4X) {
- intent.setClass(this, NoteWidgetProvider_4x.class);
- } else {
- Log.e(TAG, "不支持的小组件类型");
- return;
- }
-
- intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
- mWorkingNote.getWidgetId()
- });
-
- sendBroadcast(intent); // 发送广播更新小组件
- setResult(RESULT_OK, intent);
- }
-
- /**
- * 处理点击事件:背景设置、颜色选择、字体大小选择等
- */
- public void onClick(View v) {
- int id = v.getId();
- // 点击背景设置按钮:显示背景选择器
- if (id == R.id.btn_set_bg_color) {
- mNoteBgColorSelector.setVisibility(View.VISIBLE);
- // 显示当前选中的背景图标
- findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
- View.VISIBLE);
- }
- // 点击背景颜色选择按钮:更新背景并关闭选择器
- else if (sBgSelectorBtnsMap.containsKey(id)) {
- // 隐藏之前选中的图标
- findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
- View.GONE);
- // 设置新的背景颜色
- mWorkingNote.setBgColorId(sBgSelectorBtnsMap.get(id));
- mNoteBgColorSelector.setVisibility(View.GONE);
- }
- // 点击字体大小选择按钮:更新字体大小并关闭选择器
- else if (sFontSizeBtnsMap.containsKey(id)) {
- // 隐藏之前选中的图标
- findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.GONE);
- // 更新字体大小并保存到偏好设置
- mFontSizeId = sFontSizeBtnsMap.get(id);
- mSharedPrefs.edit().putInt(PREFERENCE_FONT_SIZE, mFontSizeId).commit();
- // 显示新选中的图标
- findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
- // 更新文本样式(列表模式/普通模式)
- if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
- getWorkingText();
- switchToListMode(mWorkingNote.getContent());
- } else {
- mNoteEditor.setTextAppearance(this,
- TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
- }
- mFontSizeSelector.setVisibility(View.GONE);
- }
- }
-
- /**
- * 处理返回键:关闭选择器面板或保存笔记并返回
- */
- @Override
- public void onBackPressed() {
- if(clearSettingState()) { // 如果关闭了选择器,则不执行默认返回
- return;
- }
-
- saveNote(); // 保存笔记
- super.onBackPressed(); // 执行默认返回
- }
-
- /**
- * 清除设置状态:关闭所有打开的选择器面板
- * @return 是否关闭了面板
- */
- private boolean clearSettingState() {
- if (mNoteBgColorSelector.getVisibility() == View.VISIBLE) {
- mNoteBgColorSelector.setVisibility(View.GONE);
- return true;
- } else if (mFontSizeSelector.getVisibility() == View.VISIBLE) {
- mFontSizeSelector.setVisibility(View.GONE);
- return true;
- }
- return false;
- }
-
- /**
- * 背景颜色变更回调:更新UI显示新背景
- */
- @Override
- public void onBackgroundColorChanged() {
- // 显示当前选中的背景图标
- findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
- View.VISIBLE);
- // 更新头部和编辑区背景
- mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
- mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
- }
-
- /**
- * 准备菜单:根据笔记状态动态生成菜单选项
- */
- @Override
- public boolean onPrepareOptionsMenu(Menu menu) {
- if (isFinishing()) {
- return true;
- }
- clearSettingState(); // 关闭选择器面板
- menu.clear(); // 清空现有菜单
-
- // 根据笔记类型加载不同菜单(通话笔记/普通笔记)
- if (mWorkingNote.getFolderId() == Notes.ID_CALL_RECORD_FOLDER) {
- getMenuInflater().inflate(R.menu.call_note_edit, menu);
- } else {
- getMenuInflater().inflate(R.menu.note_edit, menu);
- }
-
- // 根据列表模式切换菜单文字(普通模式/列表模式)
- if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
- menu.findItem(R.id.menu_list_mode).setTitle(R.string.menu_normal_mode);
- } else {
- menu.findItem(R.id.menu_list_mode).setTitle(R.string.menu_list_mode);
- }
-
- // 根据提醒状态显示/隐藏相关菜单
- if (mWorkingNote.hasClockAlert()) {
- menu.findItem(R.id.menu_alert).setVisible(false); // 已设置提醒则隐藏"设置提醒"
- } else {
- menu.findItem(R.id.menu_delete_remind).setVisible(false); // 未设置提醒则隐藏"删除提醒"
- }
- return true;
- }
-
- /**
- * 处理菜单选项点击事件
- */
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- int itemId = item.getItemId(); // 获取菜单ID
-
- if (itemId == R.id.menu_new_note) {
- createNewNote(); // 创建新笔记
- return true;
- } else if (itemId == R.id.menu_delete) {
- // 显示删除确认对话框
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(getString(R.string.alert_title_delete));
- builder.setIcon(android.R.drawable.ic_dialog_alert);
- builder.setMessage(getString(R.string.alert_message_delete_note));
- builder.setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- deleteCurrentNote(); // 确认删除
- finish();
- }
- });
- builder.setNegativeButton(android.R.string.cancel, null);
- builder.show();
- return true;
- } else if (itemId == R.id.menu_font_size) {
- // 显示字体大小选择器
- mFontSizeSelector.setVisibility(View.VISIBLE);
- findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
- return true;
- } else if (itemId == R.id.menu_list_mode) {
- // 切换列表模式/普通模式
- mWorkingNote.setCheckListMode(mWorkingNote.getCheckListMode() == 0 ?
- TextNote.MODE_CHECK_LIST : 0);
- return true;
- } else if (itemId == R.id.menu_share) {
- // 分享笔记内容
- getWorkingText();
- sendTo(this, mWorkingNote.getContent());
- return true;
- } else if (itemId == R.id.menu_send_to_desktop) {
- // 添加到桌面快捷方式
- sendToDesktop();
- return true;
- } else if (itemId == R.id.menu_alert) {
- // 设置提醒
- setReminder();
- return true;
- } else if (itemId == R.id.menu_delete_remind) {
- // 删除提醒
- mWorkingNote.setAlertDate(0, false);
- return true;
- } else {
- return super.onOptionsItemSelected(item);
- }
- }
-
- /**
- * 设置提醒:显示日期时间选择对话框
- */
- private void setReminder() {
- DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
- d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
- public void OnDateTimeSet(AlertDialog dialog, long date) {
- mWorkingNote.setAlertDate(date , true); // 设置提醒时间
- }
- });
- d.show();
- }
-
- /**
- * 分享笔记内容:调用系统分享功能
- * @param context 上下文
- * @param info 分享的文本内容
- */
- private void sendTo(Context context, String info) {
- Intent intent = new Intent(Intent.ACTION_SEND);
- intent.putExtra(Intent.EXTRA_TEXT, info);
- intent.setType("text/plain"); // 文本类型
- context.startActivity(intent);
- }
-
- /**
- * 创建新笔记:保存当前笔记后启动新的编辑活动
- */
- private void createNewNote() {
- saveNote(); // 保存当前笔记
-
- // 启动新的笔记编辑活动
- finish();
- Intent intent = new Intent(this, NoteEditActivity.class);
- intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
- intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mWorkingNote.getFolderId());
- startActivity(intent);
- }
-
- /**
- * 删除当前笔记:根据同步模式决定直接删除或移到回收站
- */
- private void deleteCurrentNote() {
- if (mWorkingNote.existInDatabase()) {
- HashSet ids = new HashSet();
- long id = mWorkingNote.getNoteId();
- if (id != Notes.ID_ROOT_FOLDER) { // 排除根目录
- ids.add(id);
- } else {
- Log.d(TAG, "错误的笔记ID,不应发生");
- }
- // 非同步模式:直接删除
- if (!isSyncMode()) {
- if (!DataUtils.batchDeleteNotes(getContentResolver(), ids)) {
- Log.e(TAG, "删除笔记错误");
- }
- } else {
- // 同步模式:移到回收站
- if (!DataUtils.batchMoveToFolder(getContentResolver(), ids, Notes.ID_TRASH_FOLER)) {
- Log.e(TAG, "移动到回收站错误");
- }
- }
- }
- mWorkingNote.markDeleted(true); // 标记为已删除
- }
-
- /**
- * 判断是否为同步模式:检查是否设置了同步账户
- * @return 是否开启同步
- */
- private boolean isSyncMode() {
- return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
- }
-
- /**
- * 提醒时间变更回调:设置或取消系统闹钟
- */
- @Override
- public void onClockAlertChanged(long date, boolean set) {
- // 未保存的笔记需先保存以获取ID
- if (!mWorkingNote.existInDatabase()) {
- saveNote();
- }
- if (mWorkingNote.getNoteId() > 0) {
- // 创建闹钟广播意图
- Intent intent = new Intent(this, AlarmReceiver.class);
- intent.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mWorkingNote.getNoteId()));
- // 创建延迟意图(适配高版本系统)
- PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_IMMUTABLE);
- AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE));
- showAlertHeader(); // 更新提醒显示
- if(!set) {
- alarmManager.cancel(pendingIntent); // 取消闹钟
- } else {
- alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent); // 设置闹钟
- }
- } else {
- // 笔记为空时提示错误
- Log.e(TAG, "设置提醒错误");
- showToast(R.string.error_note_empty_for_clock);
- }
- }
-
- /**
- * 小组件变更回调:更新小组件显示
- */
- @Override
- public void onWidgetChanged() {
- updateWidget();
- }
-
- /**
- * 列表项删除回调:处理列表模式下的项删除逻辑
- */
- public void onEditTextDelete(int index, String text) {
- int childCount = mEditTextList.getChildCount();
- if (childCount == 1) { // 至少保留一项
- return;
- }
-
- // 更新剩余项的索引
- for (int i = index + 1; i < childCount; i++) {
- ((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
- .setIndex(i - 1);
- }
-
- // 删除指定项并调整焦点
- mEditTextList.removeViewAt(index);
- NoteEditText edit = null;
- if(index == 0) {
- edit = (NoteEditText) mEditTextList.getChildAt(0).findViewById(R.id.et_edit_text);
- } else {
- edit = (NoteEditText) mEditTextList.getChildAt(index - 1).findViewById(R.id.et_edit_text);
- }
- int length = edit.length();
- edit.append(text); // 合并删除项的文本
- edit.requestFocus();
- edit.setSelection(length);
- }
-
- /**
- * 列表项回车回调:处理列表模式下的换行添加新项
- */
- public void onEditTextEnter(int index, String text) {
- if(index > mEditTextList.getChildCount()) { // 索引越界检查
- Log.e(TAG, "索引超出列表范围,不应发生");
- }
-
- // 添加新项并更新索引
- View view = getListItem(text, index);
- mEditTextList.addView(view, index);
- NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
- edit.requestFocus();
- edit.setSelection(0);
- for (int i = index + 1; i < mEditTextList.getChildCount(); i++) {
- ((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
- .setIndex(i);
- }
- }
-
- /**
- * 切换到列表模式:将文本拆分为多项并显示复选框
- * @param text 笔记内容
- */
- private void switchToListMode(String text) {
- mEditTextList.removeAllViews(); // 清空列表
- String[] items = text.split("\n"); // 按换行拆分
- int index = 0;
- for (String item : items) {
- if(!TextUtils.isEmpty(item)) { // 跳过空项
- mEditTextList.addView(getListItem(item, index));
- index++;
- }
- }
- // 添加一个空项用于继续输入
- mEditTextList.addView(getListItem("", index));
- mEditTextList.getChildAt(index).findViewById(R.id.et_edit_text).requestFocus();
-
- // 切换显示模式(隐藏普通编辑框,显示列表)
- mNoteEditor.setVisibility(View.GONE);
- mEditTextList.setVisibility(View.VISIBLE);
- }
-
- /**
- * 高亮显示搜索结果:在文本中标记搜索关键词
- * @param fullText 完整文本
- * @param userQuery 搜索关键词
- * @return 带高亮的富文本
- */
- private Spannable getHighlightQueryResult(String fullText, String userQuery) {
- SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
- if (!TextUtils.isEmpty(userQuery)) {
- mPattern = Pattern.compile(userQuery);
- Matcher m = mPattern.matcher(fullText);
- int start = 0;
- // 循环匹配并标记关键词
- while (m.find(start)) {
- spannable.setSpan(
- new BackgroundColorSpan(this.getResources().getColor(
- R.color.user_query_highlight)), m.start(), m.end(),
- Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
- start = m.end(); // 避免重复匹配
- }
- }
- return spannable;
- }
-
- /**
- * 创建列表项视图:包含复选框和编辑框
- * @param item 项文本内容
- * @param index 项索引
- * @return 列表项视图
- */
- private View getListItem(String item, int index) {
- View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null);
- final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
- // 设置字体样式
- edit.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
- CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item));
- // 复选框状态变更监听(设置删除线)
- cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (isChecked) {
- edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); // 添加删除线
- } else {
- edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG); // 移除删除线
- }
- }
- });
-
- // 根据文本前缀初始化复选框状态
- if (item.startsWith(TAG_CHECKED)) {
- cb.setChecked(true);
- edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
- item = item.substring(TAG_CHECKED.length(), item.length()).trim(); // 去除前缀
- } else if (item.startsWith(TAG_UNCHECKED)) {
- cb.setChecked(false);
- edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
- item = item.substring(TAG_UNCHECKED.length(), item.length()).trim(); // 去除前缀
- }
-
- edit.setOnTextViewChangeListener(this);
- edit.setIndex(index);
- edit.setText(getHighlightQueryResult(item, mUserQuery)); // 高亮搜索关键词
- return view;
- }
-
- /**
- * 文本变更回调:根据文本是否为空显示/隐藏复选框
- */
- @Override
- public void onTextChange(int index, boolean hasText) {
- if (index >= mEditTextList.getChildCount()) {
- Log.e(TAG, "索引错误,不应发生");
- return;
- }
- // 有文本则显示复选框,否则隐藏
- if(hasText) {
- mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.VISIBLE);
- } else {
- mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.GONE);
- }
- }
-
- /**
- * 列表模式变更回调:切换列表/普通模式时更新UI
- */
- @Override
- public void onCheckListModeChanged(int oldMode, int newMode) {
- if (newMode == TextNote.MODE_CHECK_LIST) {
- switchToListMode(mNoteEditor.getText().toString()); // 切换到列表模式
- } else {
- // 切换到普通模式:合并列表项为文本
- if (!getWorkingText()) {
- mWorkingNote.setWorkingText(mWorkingNote.getContent().replace(TAG_UNCHECKED + " ",
- ""));
- }
- mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
- mEditTextList.setVisibility(View.GONE);
- mNoteEditor.setVisibility(View.VISIBLE);
- }
- }
-
- /**
- * 获取当前编辑的文本内容:根据模式(列表/普通)拼接内容
- * @return 是否包含已选中的项
- */
- private boolean getWorkingText() {
- boolean hasChecked = false;
- if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
- StringBuilder sb = new StringBuilder();
- // 遍历列表项拼接内容
- for (int i = 0; i < mEditTextList.getChildCount(); i++) {
- View view = mEditTextList.getChildAt(i);
- NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
- if (!TextUtils.isEmpty(edit.getText())) {
- // 添加选中/未选中标记
- if (((CheckBox) view.findViewById(R.id.cb_edit_item)).isChecked()) {
- sb.append(TAG_CHECKED).append(" ").append(edit.getText()).append("\n");
- hasChecked = true;
- } else {
- sb.append(TAG_UNCHECKED).append(" ").append(edit.getText()).append("\n");
- }
- }
- }
- mWorkingNote.setWorkingText(sb.toString());
- } else {
- // 普通模式直接获取编辑框内容
- mWorkingNote.setWorkingText(mNoteEditor.getText().toString());
- }
- return hasChecked;
- }
-
- /**
- * 保存笔记:将当前编辑内容保存到数据库
- * @return 是否保存成功
- */
- private boolean saveNote() {
- getWorkingText(); // 获取当前编辑内容
- boolean saved = mWorkingNote.saveNote(); // 保存到数据库
- if (saved) {
- // 设置返回结果(用于列表页定位)
- setResult(RESULT_OK);
- }
- return saved;
- }
-
- /**
- * 添加到桌面快捷方式:创建桌面快捷方式指向当前笔记
- */
- private void sendToDesktop() {
- // 新笔记需先保存以获取ID
- if (!mWorkingNote.existInDatabase()) {
- saveNote();
- }
-
- if (mWorkingNote.getNoteId() > 0) {
- Intent sender = new Intent();
- // 创建快捷方式点击意图(打开笔记编辑页)
- Intent shortcutIntent = new Intent(this, NoteEditActivity.class);
- shortcutIntent.setAction(Intent.ACTION_VIEW);
- shortcutIntent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId());
- sender.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
- // 设置快捷方式标题(截断过长文本)
- sender.putExtra(Intent.EXTRA_SHORTCUT_NAME,
- makeShortcutIconTitle(mWorkingNote.getContent()));
- // 设置快捷方式图标
- sender.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
- Intent.ShortcutIconResource.fromContext(this, R.drawable.icon_app));
- sender.putExtra("duplicate", true); // 允许重复创建
- sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); // 系统安装快捷方式动作
- showToast(R.string.info_note_enter_desktop); // 提示成功
- sendBroadcast(sender); // 发送广播创建快捷方式
- } else {
- // 笔记为空时提示错误
- Log.e(TAG, "添加到桌面错误");
- showToast(R.string.error_note_empty_for_send_to_desktop);
- }
- }
-
- /**
- * 生成快捷方式标题:去除标记并截断过长文本
- * @param content 笔记内容
- * @return 处理后的标题
- */
- private String makeShortcutIconTitle(String content) {
- content = content.replace(TAG_CHECKED, "");
- content = content.replace(TAG_UNCHECKED, "");
- return content.length() > SHORTCUT_ICON_TITLE_MAX_LEN ? content.substring(0,
- SHORTCUT_ICON_TITLE_MAX_LEN) : content;
- }
-
- /**
- * 显示短提示
- * @param resId 提示文本资源ID
- */
- private void showToast(int resId) {
- showToast(resId, Toast.LENGTH_SHORT);
- }
-
- /**
- * 显示提示
- * @param resId 提示文本资源ID
- * @param duration 显示时长
- */
- private void showToast(int resId, int duration) {
- Toast.makeText(this, resId, duration).show();
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteEditText.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteEditText.java
deleted file mode 100644
index 97e1d06..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteEditText.java
+++ /dev/null
@@ -1,277 +0,0 @@
-package net.micode.notes.ui; // 假设包名,实际需根据项目结构调整
-
-import android.content.Context;
-import android.graphics.Rect;
-import android.text.Selection;
-import android.text.Spanned;
-import android.text.TextUtils;
-import android.text.style.URLSpan;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.KeyEvent;
-import android.view.LayoutInflater;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.ContextMenu;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MenuItem.OnMenuItemClickListener;
-import android.view.inputmethod.EditorInfo;
-import android.widget.EditText;
-import android.widget.TextView;
-
-import net.micode.notes.R;
-import net.micode.notes.data.Notes;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * 自定义的EditText控件,用于笔记编辑功能
- * 支持链接识别、按键事件处理、文本变化监听等功能
- */
-public class NoteEditText extends EditText {
- private static final String TAG = "NoteEditText"; // 日志标签
- private int mIndex; // 当前EditText在列表中的索引
- private int mSelectionStartBeforeDelete; // 记录删除操作前的光标位置
-
- // 定义支持的链接协议类型
- private static final String SCHEME_TEL = "tel:" ; // 电话协议
- private static final String SCHEME_HTTP = "http:" ; // 网络链接协议
- private static final String SCHEME_EMAIL = "mailto:" ; // 邮件协议
-
- // 协议与对应菜单文本资源的映射表
- private static final Map sSchemaActionResMap = new HashMap();
- static {
- sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel); // 电话链接对应的菜单文本
- sSchemaActionResMap.put(SCHEME_HTTP, R.string.note_link_web); // 网页链接对应的菜单文本
- sSchemaActionResMap.put(SCHEME_EMAIL, R.string.note_link_email); // 邮件链接对应的菜单文本
- }
-
- /**
- * 文本变化监听器接口,由NoteEditActivity调用
- * 用于处理删除、添加EditText及文本变化时的回调
- */
- public interface OnTextViewChangeListener {
- /**
- * 当按下删除键且文本为空时,删除当前EditText
- * @param index 当前EditText的索引
- * @param text 当前EditText的文本内容
- */
- void onEditTextDelete(int index, String text);
-
- /**
- * 当按下回车键时,在当前EditText后添加新的EditText
- * @param index 新EditText的索引
- * @param text 需要转移到新EditText的文本
- */
- void onEditTextEnter(int index, String text);
-
- /**
- * 当文本变化时,显示或隐藏项目选项
- * @param index 当前EditText的索引
- * @param hasText 文本是否非空
- */
- void onTextChange(int index, boolean hasText);
- }
-
- private OnTextViewChangeListener mOnTextViewChangeListener; // 文本变化监听器实例
-
- /**
- * 构造方法:上下文初始化
- * @param context 上下文环境
- */
- public NoteEditText(Context context) {
- super(context, null);
- mIndex = 0; // 初始索引设为0
- }
-
- /**
- * 设置当前EditText的索引
- * @param index 索引值
- */
- public void setIndex(int index) {
- mIndex = index;
- }
-
- /**
- * 设置文本变化监听器
- * @param listener 监听器实例
- */
- public void setOnTextViewChangeListener(OnTextViewChangeListener listener) {
- mOnTextViewChangeListener = listener;
- }
-
- /**
- * 构造方法:带属性集的初始化
- * @param context 上下文环境
- * @param attrs 属性集
- */
- public NoteEditText(Context context, AttributeSet attrs) {
- super(context, attrs, android.R.attr.editTextStyle);
- }
-
- /**
- * 构造方法:带属性集和默认样式的初始化
- * @param context 上下文环境
- * @param attrs 属性集
- * @param defStyle 默认样式
- */
- public NoteEditText(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * 重写触摸事件,处理点击位置的光标定位
- * @param event 触摸事件
- * @return 事件处理结果(是否消费事件)
- */
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- switch (event.getAction()) {
- case MotionEvent.ACTION_DOWN: // 按下事件
- // 计算触摸位置在文本中的坐标
- int x = (int) event.getX();
- int y = (int) event.getY();
- x -= getTotalPaddingLeft(); // 减去左内边距
- y -= getTotalPaddingTop(); // 减去上内边距
- x += getScrollX(); // 加上横向滚动距离
- y += getScrollY(); // 加上纵向滚动距离
-
- // 根据坐标获取对应的文本位置
- Layout layout = getLayout();
- int line = layout.getLineForVertical(y); // 获取所在行
- int off = layout.getOffsetForHorizontal(line, x); // 获取行内偏移
- Selection.setSelection(getText(), off); // 设置光标位置
- break;
- }
- return super.onTouchEvent(event); // 调用父类处理其他事件
- }
-
- /**
- * 重写按键按下事件,预处理删除和回车事件
- * @param keyCode 按键码
- * @param event 按键事件
- * @return 事件处理结果
- */
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- switch (keyCode) {
- case KeyEvent.KEYCODE_ENTER: // 回车键
- if (mOnTextViewChangeListener != null) {
- return false; // 让onKeyUp处理回车事件
- }
- break;
- case KeyEvent.KEYCODE_DEL: // 删除键
- mSelectionStartBeforeDelete = getSelectionStart(); // 记录删除前的光标位置
- break;
- default:
- break;
- }
- return super.onKeyDown(keyCode, event); // 调用父类处理其他按键
- }
-
- /**
- * 重写按键抬起事件,处理删除和回车的具体逻辑
- * @param keyCode 按键码
- * @param event 按键事件
- * @return 事件处理结果
- */
- @Override
- public boolean onKeyUp(int keyCode, KeyEvent event) {
- switch(keyCode) {
- case KeyEvent.KEYCODE_DEL: // 删除键抬起
- if (mOnTextViewChangeListener != null) {
- // 若光标在起始位置且不是第一个EditText,触发删除回调
- if (0 == mSelectionStartBeforeDelete && mIndex != 0) {
- mOnTextViewChangeListener.onEditTextDelete(mIndex, getText().toString());
- return true; // 消费事件
- }
- } else {
- Log.d(TAG, "OnTextViewChangeListener was not seted"); // 日志提示监听器未设置
- }
- break;
- case KeyEvent.KEYCODE_ENTER: // 回车键抬起
- if (mOnTextViewChangeListener != null) {
- int selectionStart = getSelectionStart(); // 获取光标位置
- // 截取光标后的文本
- String text = getText().subSequence(selectionStart, length()).toString();
- // 保留光标前的文本
- setText(getText().subSequence(0, selectionStart));
- // 触发添加新EditText的回调
- mOnTextViewChangeListener.onEditTextEnter(mIndex + 1, text);
- } else {
- Log.d(TAG, "OnTextViewChangeListener was not seted"); // 日志提示监听器未设置
- }
- break;
- default:
- break;
- }
- return super.onKeyUp(keyCode, event); // 调用父类处理其他按键
- }
-
- /**
- * 重写焦点变化事件,通知文本是否为空
- * @param focused 是否获得焦点
- * @param direction 焦点变化方向
- * @param previouslyFocusedRect 上一个焦点区域
- */
- @Override
- protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
- if (mOnTextViewChangeListener != null) {
- if (!focused && TextUtils.isEmpty(getText())) {
- // 失去焦点且文本为空,通知隐藏选项
- mOnTextViewChangeListener.onTextChange(mIndex, false);
- } else {
- // 获得焦点或文本非空,通知显示选项
- mOnTextViewChangeListener.onTextChange(mIndex, true);
- }
- }
- super.onFocusChanged(focused, direction, previouslyFocusedRect); // 调用父类方法
- }
-
- /**
- * 重写上下文菜单创建方法,为链接添加操作菜单
- * @param menu 上下文菜单
- */
- @Override
- protected void onCreateContextMenu(ContextMenu menu) {
- if (getText() instanceof Spanned) { // 文本包含富文本(如链接)
- int selStart = getSelectionStart(); // 选中起始位置
- int selEnd = getSelectionEnd(); // 选中结束位置
-
- int min = Math.min(selStart, selEnd); // 计算最小位置
- int max = Math.max(selStart, selEnd); // 计算最大位置
-
- // 获取选中区域内的URLSpan(链接)
- final URLSpan[] urls = ((Spanned) getText()).getSpans(min, max, URLSpan.class);
- if (urls.length == 1) { // 只有一个链接时
- int defaultResId = 0; // 菜单文本资源ID
- // 匹配链接协议,获取对应的菜单文本
- for(String schema: sSchemaActionResMap.keySet()) {
- if(urls[0].getURL().indexOf(schema) >= 0) {
- defaultResId = sSchemaActionResMap.get(schema);
- break;
- }
- }
-
- if (defaultResId == 0) {
- defaultResId = R.string.note_link_other; // 默认菜单文本(其他链接)
- }
-
- // 向菜单添加选项
- menu.add(0, 0, 0, defaultResId).setOnMenuItemClickListener(
- new OnMenuItemClickListener() {
- public boolean onMenuItemClick(MenuItem item) {
- // 点击菜单时触发链接点击事件(如拨打电话、打开网页等)
- urls[0].onClick(NoteEditText.this);
- return true;
- }
- });
- }
- }
- super.onCreateContextMenu(menu); // 调用父类方法
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteItemData.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteItemData.java
deleted file mode 100644
index b5daf25..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NoteItemData.java
+++ /dev/null
@@ -1,320 +0,0 @@
-package net.micode.notes.ui; // 假设包名
-
-import android.content.Context;
-import android.database.Cursor;
-import android.text.TextUtils;
-
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.NoteColumns;
-import net.micode.notes.util.Contact;
-import net.micode.notes.util.DataUtils;
-
-/**
- * 笔记项数据封装类
- * 用于存储和提供笔记列表项所需的所有数据
- */
-public class NoteItemData {
- // 查询数据时的字段投影(需要获取的列)
- static final String [] PROJECTION = new String [] {
- NoteColumns.ID, // 笔记ID
- NoteColumns.ALERTED_DATE, // 提醒时间
- NoteColumns.BG_COLOR_ID, // 背景颜色ID
- NoteColumns.CREATED_DATE, // 创建时间
- NoteColumns.HAS_ATTACHMENT, // 是否有附件
- NoteColumns.MODIFIED_DATE, // 修改时间
- NoteColumns.NOTES_COUNT, // 包含的笔记数量(用于文件夹)
- NoteColumns.PARENT_ID, // 父文件夹ID
- NoteColumns.SNIPPET, // 内容摘要
- NoteColumns.TYPE, // 类型(笔记/文件夹等)
- NoteColumns.WIDGET_ID, // 小部件ID
- NoteColumns.WIDGET_TYPE, // 小部件类型
- };
-
- // 字段索引(与PROJECTION对应)
- private static final int ID_COLUMN = 0;
- private static final int ALERTED_DATE_COLUMN = 1;
- private static final int BG_COLOR_ID_COLUMN = 2;
- private static final int CREATED_DATE_COLUMN = 3;
- private static final int HAS_ATTACHMENT_COLUMN = 4;
- private static final int MODIFIED_DATE_COLUMN = 5;
- private static final int NOTES_COUNT_COLUMN = 6;
- private static final int PARENT_ID_COLUMN = 7;
- private static final int SNIPPET_COLUMN = 8;
- private static final int TYPE_COLUMN = 9;
- private static final int WIDGET_ID_COLUMN = 10;
- private static final int WIDGET_TYPE_COLUMN = 11;
-
- // 数据字段
- private long mId; // 笔记ID
- private long mAlertDate; // 提醒时间(时间戳)
- private int mBgColorId; // 背景颜色ID
- private long mCreatedDate; // 创建时间(时间戳)
- private boolean mHasAttachment; // 是否有附件
- private long mModifiedDate; // 修改时间(时间戳)
- private int mNotesCount; // 包含的笔记数量(文件夹用)
- private long mParentId; // 父文件夹ID
- private String mSnippet; // 内容摘要
- private int mType; // 类型(笔记/文件夹等)
- private int mWidgetId; // 小部件ID
- private int mWidgetType; // 小部件类型
- private String mName; // 联系人名称(通话记录用)
- private String mPhoneNumber; // 电话号码(通话记录用)
-
- // 列表位置相关标记
- private boolean mIsLastItem; // 是否为列表最后一项
- private boolean mIsFirstItem; // 是否为列表第一项
- private boolean mIsOnlyOneItem; // 是否为列表唯一一项
- private boolean mIsOneNoteFollowingFolder; // 是否为文件夹后的唯一笔记
- private boolean mIsMultiNotesFollowingFolder; // 是否为文件夹后的多个笔记之一
-
- /**
- * 构造方法:从游标初始化数据
- * @param context 上下文环境
- * @param cursor 数据游标
- */
- public NoteItemData(Context context, Cursor cursor) {
- mId = cursor.getLong(ID_COLUMN);
- mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN);
- mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN);
- mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN);
- mHasAttachment = (cursor.getInt(HAS_ATTACHMENT_COLUMN) > 0) ? true : false;
- mModifiedDate = cursor.getLong(MODIFIED_DATE_COLUMN);
- mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN);
- mParentId = cursor.getLong(PARENT_ID_COLUMN);
- mSnippet = cursor.getString(SNIPPET_COLUMN);
- // 移除摘要中的勾选标记(用于 checklist 类型)
- mSnippet = mSnippet.replace(NoteEditActivity.TAG_CHECKED, "").replace(
- NoteEditActivity.TAG_UNCHECKED, "");
- mType = cursor.getInt(TYPE_COLUMN);
- mWidgetId = cursor.getInt(WIDGET_ID_COLUMN);
- mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
-
- mPhoneNumber = "";
- // 若为通话记录文件夹下的笔记,获取电话号码和联系人名称
- if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {
- mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId);
- if (!TextUtils.isEmpty(mPhoneNumber)) {
- mName = Contact.getContact(context, mPhoneNumber); // 获取联系人名称
- if (mName == null) {
- mName = mPhoneNumber; // 若无联系人,显示电话号码
- }
- }
- }
-
- if (mName == null) {
- mName = "";
- }
- checkPostion(cursor); // 检查在列表中的位置
- }
-
- /**
- * 检查当前项在列表中的位置(首项、末项等)
- * @param cursor 数据游标
- */
- private void checkPostion(Cursor cursor) {
- mIsLastItem = cursor.isLast() ? true : false; // 是否为最后一项
- mIsFirstItem = cursor.isFirst() ? true : false; // 是否为第一项
- mIsOnlyOneItem = (cursor.getCount() == 1); // 是否为唯一一项
- mIsMultiNotesFollowingFolder = false;
- mIsOneNoteFollowingFolder = false;
-
- // 若为笔记类型且不是第一项,检查前一项是否为文件夹
- if (mType == Notes.TYPE_NOTE && !mIsFirstItem) {
- int position = cursor.getPosition();
- if (cursor.moveToPrevious()) { // 移动到前一项
- // 前一项是文件夹或系统类型
- if (cursor.getInt(TYPE_COLUMN) == Notes.TYPE_FOLDER
- || cursor.getInt(TYPE_COLUMN) == Notes.TYPE_SYSTEM) {
- // 若后面还有项,则为多个笔记跟随文件夹
- if (cursor.getCount() > (position + 1)) {
- mIsMultiNotesFollowingFolder = true;
- } else {
- // 否则为单个笔记跟随文件夹
- mIsOneNoteFollowingFolder = true;
- }
- }
- // 移回原位置
- if (!cursor.moveToNext()) {
- throw new IllegalStateException("cursor move to previous but can't move back");
- }
- }
- }
- }
-
- /**
- * 是否为文件夹后的唯一笔记
- * @return 是/否
- */
- public boolean isOneFollowingFolder() {
- return mIsOneNoteFollowingFolder;
- }
-
- /**
- * 是否为文件夹后的多个笔记之一
- * @return 是/否
- */
- public boolean isMultiFollowingFolder() {
- return mIsMultiNotesFollowingFolder;
- }
-
- /**
- * 是否为列表最后一项
- * @return 是/否
- */
- public boolean isLast() {
- return mIsLastItem;
- }
-
- /**
- * 获取联系人名称(通话记录用)
- * @return 联系人名称
- */
- public String getCallName() {
- return mName;
- }
-
- /**
- * 是否为列表第一项
- * @return 是/否
- */
- public boolean isFirst() {
- return mIsFirstItem;
- }
-
- /**
- * 是否为列表唯一一项
- * @return 是/否
- */
- public boolean isSingle() {
- return mIsOnlyOneItem;
- }
-
- /**
- * 获取笔记ID
- * @return 笔记ID
- */
- public long getId() {
- return mId;
- }
-
- /**
- * 获取提醒时间
- * @return 提醒时间(时间戳)
- */
- public long getAlertDate() {
- return mAlertDate;
- }
-
- /**
- * 获取创建时间
- * @return 创建时间(时间戳)
- */
- public long getCreatedDate() {
- return mCreatedDate;
- }
-
- /**
- * 是否有附件
- * @return 是/否
- */
- public boolean hasAttachment() {
- return mHasAttachment;
- }
-
- /**
- * 获取修改时间
- * @return 修改时间(时间戳)
- */
- public long getModifiedDate() {
- return mModifiedDate;
- }
-
- /**
- * 获取背景颜色ID
- * @return 背景颜色ID
- */
- public int getBgColorId() {
- return mBgColorId;
- }
-
- /**
- * 获取父文件夹ID
- * @return 父文件夹ID
- */
- public long getParentId() {
- return mParentId;
- }
-
- /**
- * 获取包含的笔记数量(文件夹用)
- * @return 笔记数量
- */
- public int getNotesCount() {
- return mNotesCount;
- }
-
- /**
- * 获取文件夹ID(同getParentId())
- * @return 文件夹ID
- */
- public long getFolderId () {
- return mParentId;
- }
-
- /**
- * 获取类型(笔记/文件夹等)
- * @return 类型
- */
- public int getType() {
- return mType;
- }
-
- /**
- * 获取小部件类型
- * @return 小部件类型
- */
- public int getWidgetType() {
- return mWidgetType;
- }
-
- /**
- * 获取小部件ID
- * @return 小部件ID
- */
- public int getWidgetId() {
- return mWidgetId;
- }
-
- /**
- * 获取内容摘要
- * @return 内容摘要
- */
- public String getSnippet() {
- return mSnippet;
- }
-
- /**
- * 是否有提醒
- * @return 是/否
- */
- public boolean hasAlert() {
- return (mAlertDate > 0);
- }
-
- /**
- * 是否为通话记录
- * @return 是/否
- */
- public boolean isCallRecord() {
- return (mParentId == Notes.ID_CALL_RECORD_FOLDER && !TextUtils.isEmpty(mPhoneNumber));
- }
-
- /**
- * 从游标获取笔记类型
- * @param cursor 数据游标
- * @return 笔记类型
- */
- public static int getNoteType(Cursor cursor) {
- return cursor.getInt(TYPE_COLUMN);
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListActivity.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListActivity.java
deleted file mode 100644
index 586d6f4..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListActivity.java
+++ /dev/null
@@ -1,1100 +0,0 @@
-/**
- * NotesListActivity 类,用于显示笔记列表,处理笔记的创建、删除、查看等操作
- */
-public class NotesListActivity extends Activity implements OnClickListener, OnItemLongClickListener {
- // 查询文件夹笔记列表的标识
- private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0;
- // 查询文件夹列表的标识
- private static final int FOLDER_LIST_QUERY_TOKEN = 1;
- // 文件夹删除菜单标识
- private static final int MENU_FOLDER_DELETE = 0;
- // 文件夹查看菜单标识
- private static final int MENU_FOLDER_VIEW = 1;
- // 文件夹重命名菜单标识
- private static final int MENU_FOLDER_CHANGE_NAME = 2;
- // 用于标记是否已添加应用介绍笔记的偏好设置键
- private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction";
-
- /**
- * 列表编辑状态的枚举
- */
- private enum ListEditState {
- NOTE_LIST, // 笔记列表状态
- SUB_FOLDER, // 子文件夹状态
- CALL_RECORD_FOLDER // 通话记录文件夹状态
- };
-
- // 当前列表状态
- private ListEditState mState;
- // 用于异步查询数据的处理器
- private BackgroundQueryHandler mBackgroundQueryHandler;
- // 笔记列表适配器
- private NotesListAdapter mNotesListAdapter;
- // 笔记列表视图
- private ListView mNotesListView;
- // 添加新笔记的按钮
- private Button mAddNewNote;
- // 是否分发触摸事件的标记
- private boolean mDispatch;
- // 触摸事件起始Y坐标
- private int mOriginY;
- // 分发触摸事件的Y坐标
- private int mDispatchY;
- // 标题栏文本视图
- private TextView mTitleBar;
- // 当前文件夹ID
- private long mCurrentFolderId;
- // 内容解析器
- private ContentResolver mContentResolver;
- // 多选模式的回调
- private ModeCallback mModeCallBack;
- // 日志标记
- private static final String TAG = "NotesListActivity";
- // 列表滚动速率
- public static final int NOTES_LISTVIEW_SCROLL_RATE = 30;
- // 当前长按的笔记数据项
- private NoteItemData mFocusNoteDataItem;
- // 普通查询条件(根据父文件夹ID)
- private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?";
- // 根文件夹查询条件(包含非系统类型且父文件夹为根目录,或通话记录文件夹且有笔记)
- private static final String ROOT_FOLDER_SELECTION = "(" + NoteColumns.TYPE + "<>"
- + Notes.TYPE_SYSTEM + " AND " + NoteColumns.PARENT_ID + "=?)" + " OR ("
- + NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER + " AND "
- + NoteColumns.NOTES_COUNT + ">0)";
- // 打开笔记的请求码
- private final static int REQUEST_CODE_OPEN_NODE = 102;
- // 新建笔记的请求码
- private final static int REQUEST_CODE_NEW_NODE = 103;
-
- /**
- * onCreate 方法,初始化活动
- * @param savedInstanceState 保存的实例状态
- */
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.note_list);
- initResources();
-
- // 首次使用时添加应用介绍笔记
- setAppInfoFromRawRes();
- }
-
- /**
- * 处理活动返回结果
- * @param requestCode 请求码
- * @param resultCode 结果码
- * @param data 意图数据
- */
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- // 如果是打开或新建笔记成功返回,刷新列表
- if (resultCode == RESULT_OK
- && (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) {
- mNotesListAdapter.changeCursor(null);
- } else {
- super.onActivityResult(requestCode, resultCode, data);
- }
- }
-
- /**
- * 从原始资源文件中读取应用介绍并创建笔记(首次使用时)
- */
- private void setAppInfoFromRawRes() {
- SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
- // 如果尚未添加介绍笔记
- if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
- StringBuilder sb = new StringBuilder();
- InputStream in = null;
- try {
- // 打开原始资源文件
- in = getResources().openRawResource(R.raw.introduction);
- if (in != null) {
- InputStreamReader isr = new InputStreamReader(in);
- BufferedReader br = new BufferedReader(isr);
- char [] buf = new char[1024];
- int len = 0;
- // 读取文件内容
- while ((len = br.read(buf)) > 0) {
- sb.append(buf, 0, len);
- }
- } else {
- Log.e(TAG, "Read introduction file error");
- return;
- }
- } catch (IOException e) {
- e.printStackTrace();
- return;
- } finally {
- // 关闭输入流
- if(in != null) {
- try {
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
- // 创建介绍笔记并保存
- WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER,
- AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE,
- ResourceParser.RED);
- note.setWorkingText(sb.toString());
- if (note.saveNote()) {
- sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit();
- } else {
- Log.e(TAG, "Save introduction note error");
- return;
- }
- }
- }
-
- /**
- * onStart 方法,活动启动时调用
- */
- @Override
- protected void onStart() {
- super.onStart();
- // 异步查询笔记列表
- startAsyncNotesListQuery();
- }
-
- /**
- * 初始化资源
- */
- private void initResources() {
- mContentResolver = this.getContentResolver();
- mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
- // 默认显示根文件夹
- mCurrentFolderId = Notes.ID_ROOT_FOLDER;
- mNotesListView = (ListView) findViewById(R.id.notes_list);
- // 添加列表底部布局
- mNotesListView.addFooterView(LayoutInflater.from(this).inflate(R.layout.note_list_footer, null),
- null, false);
- // 设置列表项点击监听器
- mNotesListView.setOnItemClickListener(new OnListItemClickListener());
- // 设置列表项长按监听器
- mNotesListView.setOnItemLongClickListener(this);
- mNotesListAdapter = new NotesListAdapter(this);
- mNotesListView.setAdapter(mNotesListAdapter);
- mAddNewNote = (Button) findViewById(R.id.btn_new_note);
- mAddNewNote.setOnClickListener(this);
- // 设置添加笔记按钮的触摸监听器
- mAddNewNote.setOnTouchListener(new NewNoteOnTouchListener());
- mDispatch = false;
- mDispatchY = 0;
- mOriginY = 0;
- mTitleBar = (TextView) findViewById(R.id.tv_title_bar);
- // 默认状态为笔记列表
- mState = ListEditState.NOTE_LIST;
- mModeCallBack = new ModeCallback();
- }
-
- /**
- * 多选模式的回调类
- */
- private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
- // 下拉菜单
- private DropdownMenu mDropDownMenu;
- // 动作模式
- private ActionMode mActionMode;
- // 移动菜单
- private MenuItem mMoveMenu;
-
- /**
- * 创建动作模式时调用
- * @param mode 动作模式
- * @param menu 菜单
- * @return 是否创建成功
- */
- public boolean onCreateActionMode(ActionMode mode, Menu menu) {
- // 加载菜单资源
- getMenuInflater().inflate(R.menu.note_list_options, menu);
- menu.findItem(R.id.delete).setOnMenuItemClickListener(this);
- mMoveMenu = menu.findItem(R.id.move);
- // 如果是通话记录文件夹或没有用户文件夹,隐藏移动菜单
- if (mFocusNoteDataItem.getParentId() == Notes.ID_CALL_RECORD_FOLDER
- || DataUtils.getUserFolderCount(mContentResolver) == 0) {
- mMoveMenu.setVisible(false);
- } else {
- mMoveMenu.setVisible(true);
- mMoveMenu.setOnMenuItemClickListener(this);
- }
- mActionMode = mode;
- // 开启适配器的多选模式
- mNotesListAdapter.setChoiceMode(true);
- mNotesListView.setLongClickable(false);
- // 隐藏添加新笔记按钮
- mAddNewNote.setVisibility(View.GONE);
-
- // 设置自定义视图
- View customView = LayoutInflater.from(NotesListActivity.this).inflate(
- R.layout.note_list_dropdown_menu, null);
- mode.setCustomView(customView);
- mDropDownMenu = new DropdownMenu(NotesListActivity.this,
- (Button) customView.findViewById(R.id.selection_menu),
- R.menu.note_list_dropdown);
- // 设置下拉菜单项点击监听器(全选/取消全选)
- mDropDownMenu.setOnDropdownMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){
- public boolean onMenuItemClick(MenuItem item) {
- mNotesListAdapter.selectAll(!mNotesListAdapter.isAllSelected());
- updateMenu();
- return true;
- }
-
- });
- return true;
- }
-
- /**
- * 更新菜单显示(选中数量等)
- */
- private void updateMenu() {
- int selectedCount = mNotesListAdapter.getSelectedCount();
- // 更新下拉菜单标题
- String format = getResources().getString(R.string.menu_select_title, selectedCount);
- mDropDownMenu.setTitle(format);
- MenuItem item = mDropDownMenu.findItem(R.id.action_select_all);
- if (item != null) {
- // 根据是否全选更新菜单项
- if (mNotesListAdapter.isAllSelected()) {
- item.setChecked(true);
- item.setTitle(R.string.menu_deselect_all);
- } else {
- item.setChecked(false);
- item.setTitle(R.string.menu_select_all);
- }
- }
- }
-
- /**
- * 准备动作模式时调用
- * @param mode 动作模式
- * @param menu 菜单
- * @return 是否准备成功
- */
- public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
- return false;
- }
-
- /**
- * 动作菜单项点击时调用
- * @param mode 动作模式
- * @param item 菜单项
- * @return 是否处理了事件
- */
- public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- return false;
- }
-
- /**
- * 动作模式销毁时调用
- * @param mode 动作模式
- */
- public void onDestroyActionMode(ActionMode mode) {
- // 关闭适配器的多选模式
- mNotesListAdapter.setChoiceMode(false);
- mNotesListView.setLongClickable(true);
- // 显示添加新笔记按钮
- mAddNewNote.setVisibility(View.VISIBLE);
- }
-
- /**
- * 结束动作模式
- */
- public void finishActionMode() {
- mActionMode.finish();
- }
-
- /**
- * 列表项选中状态变化时调用
- * @param mode 动作模式
- * @param position 位置
- * @param id 项ID
- * @param checked 是否选中
- */
- public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
- boolean checked) {
- mNotesListAdapter.setCheckedItem(position, checked);
- updateMenu();
- }
-
- /**
- * 菜单项点击时调用
- * @param item 菜单项
- * @return 是否处理了事件
- */
- public boolean onMenuItemClick(MenuItem item) {
- // 如果没有选中项,提示
- if (mNotesListAdapter.getSelectedCount() == 0) {
- Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none),
- Toast.LENGTH_SHORT).show();
- return true;
- }
-
- int itemId = item.getItemId();
- if (itemId == R.id.delete) {
- // 显示删除确认对话框
- AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
- builder.setTitle(getString(R.string.alert_title_delete));
- builder.setIcon(android.R.drawable.ic_dialog_alert);
- builder.setMessage(getString(R.string.alert_message_delete_notes,
- mNotesListAdapter.getSelectedCount()));
- builder.setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog,
- int which) {
- batchDelete();
- }
- });
- builder.setNegativeButton(android.R.string.cancel, null);
- builder.show();
- } else if (itemId == R.id.move) {
- // 查询目标文件夹列表
- startQueryDestinationFolders();
- } else {
- return false;
- }
- return true;
- }
- }
-
- /**
- * 新笔记按钮的触摸监听器,处理特殊的触摸事件分发
- */
- private class NewNoteOnTouchListener implements OnTouchListener {
-
- public boolean onTouch(View v, MotionEvent event) {
- switch (event.getAction()) {
- case MotionEvent.ACTION_DOWN: {
- Display display = getWindowManager().getDefaultDisplay();
- int screenHeight = display.getHeight();
- int newNoteViewHeight = mAddNewNote.getHeight();
- int start = screenHeight - newNoteViewHeight;
- int eventY = start + (int) event.getY();
- // 如果是子文件夹状态,减去标题栏高度
- if (mState == ListEditState.SUB_FOLDER) {
- eventY -= mTitleBar.getHeight();
- start -= mTitleBar.getHeight();
- }
- /**
- * 特殊处理:当点击"新建笔记"按钮的透明部分时,将事件分发给后面的列表视图
- * 透明部分由公式 y = -0.12x + 94(像素)和按钮顶部边界定义
- * 坐标基于按钮左侧,94是透明部分的最大高度
- * 注意:如果按钮背景变化,此公式可能需要调整(UI设计要求)
- */
- if (event.getY() < (event.getX() * (-0.12) + 94)) {
- // 获取列表最后一个可见项
- View view = mNotesListView.getChildAt(mNotesListView.getChildCount() - 1
- - mNotesListView.getFooterViewsCount());
- // 检查视图是否在有效区域
- if (view != null && view.getBottom() > start
- && (view.getTop() < (start + 94))) {
- mOriginY = (int) event.getY();
- mDispatchY = eventY;
- event.setLocation(event.getX(), mDispatchY);
- mDispatch = true;
- // 分发触摸事件到列表视图
- return mNotesListView.dispatchTouchEvent(event);
- }
- }
- break;
- }
- case MotionEvent.ACTION_MOVE: {
- // 如果正在分发事件,更新Y坐标并继续分发
- if (mDispatch) {
- mDispatchY += (int) event.getY() - mOriginY;
- event.setLocation(event.getX(), mDispatchY);
- return mNotesListView.dispatchTouchEvent(event);
- }
- break;
- }
- default: {
- // 其他动作,停止分发并处理
- if (mDispatch) {
- event.setLocation(event.getX(), mDispatchY);
- mDispatch = false;
- return mNotesListView.dispatchTouchEvent(event);
- }
- break;
- }
- }
- return false;
- }
-
- };
-
- /**
- * 异步查询笔记列表
- */
- private void startAsyncNotesListQuery() {
- // 根据当前文件夹ID选择查询条件
- String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
- : NORMAL_SELECTION;
- mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
- Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] {
- String.valueOf(mCurrentFolderId)
- }, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
- }
-
- /**
- * 异步查询处理器,用于在后台处理查询操作
- */
- private final class BackgroundQueryHandler extends AsyncQueryHandler {
- public BackgroundQueryHandler(ContentResolver contentResolver) {
- super(contentResolver);
- }
-
- /**
- * 查询完成时调用
- * @param token 查询标识
- * @param cookie 附加数据
- * @param cursor 查询结果游标
- */
- @Override
- protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
- switch (token) {
- case FOLDER_NOTE_LIST_QUERY_TOKEN:
- // 更新笔记列表适配器
- mNotesListAdapter.changeCursor(cursor);
- break;
- case FOLDER_LIST_QUERY_TOKEN:
- // 显示文件夹列表菜单
- if (cursor != null && cursor.getCount() > 0) {
- showFolderListMenu(cursor);
- } else {
- Log.e(TAG, "Query folder failed");
- }
- break;
- default:
- return;
- }
- }
- }
-
- /**
- * 显示文件夹列表菜单(用于移动笔记)
- * @param cursor 文件夹数据游标
- */
- private void showFolderListMenu(Cursor cursor) {
- AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
- builder.setTitle(R.string.menu_title_select_folder);
- final FoldersListAdapter adapter = new FoldersListAdapter(this, cursor);
- builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
-
- public void onClick(DialogInterface dialog, int which) {
- // 批量移动笔记到选中的文件夹
- DataUtils.batchMoveToFolder(mContentResolver,
- mNotesListAdapter.getSelectedItemIds(), adapter.getItemId(which));
- // 显示移动成功提示
- Toast.makeText(
- NotesListActivity.this,
- getString(R.string.format_move_notes_to_folder,
- mNotesListAdapter.getSelectedCount(),
- adapter.getFolderName(NotesListActivity.this, which)),
- Toast.LENGTH_SHORT).show();
- // 结束动作模式
- mModeCallBack.finishActionMode();
- }
- });
- builder.show();
- }
-
- /**
- * 创建新笔记
- */
- private void createNewNote() {
- Intent intent = new Intent(this, NoteEditActivity.class);
- intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
- intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mCurrentFolderId);
- this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
- }
-
- /**
- * 批量删除笔记
- */
- private void batchDelete() {
- new AsyncTask>() {
- /**
- * 后台执行删除操作
- * @param unused 无参数
- * @return 受影响的小部件属性集合
- */
- protected HashSet doInBackground(Void... unused) {
- HashSet widgets = mNotesListAdapter.getSelectedWidget();
- if (!isSyncMode()) {
- // 非同步模式,直接删除笔记
- if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter
- .getSelectedItemIds())) {
- } else {
- Log.e(TAG, "Delete notes error, should not happens");
- }
- } else {
- // 同步模式,将笔记移动到回收站
- if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter
- .getSelectedItemIds(), Notes.ID_TRASH_FOLER)) {
- Log.e(TAG, "Move notes to trash folder error, should not happens");
- }
- }
- return widgets;
- }
-
- /**
- * 后台操作完成后更新UI
- * @param widgets 受影响的小部件属性集合
- */
- @Override
- protected void onPostExecute(HashSet widgets) {
- if (widgets != null) {
- // 更新相关小部件
- for (AppWidgetAttribute widget : widgets) {
- if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID
- && widget.widgetType != Notes.TYPE_WIDGET_INVALIDE) {
- updateWidget(widget.widgetId, widget.widgetType);
- }
- }
- }
- // 结束动作模式
- mModeCallBack.finishActionMode();
- }
- }.execute();
- }
-
- /**
- * 删除文件夹
- * @param folderId 文件夹ID
- */
- private void deleteFolder(long folderId) {
- // 根文件夹不能删除
- if (folderId == Notes.ID_ROOT_FOLDER) {
- Log.e(TAG, "Wrong folder id, should not happen " + folderId);
- return;
- }
-
- HashSet ids = new HashSet();
- ids.add(folderId);
- // 获取文件夹中笔记关联的小部件
- HashSet widgets = DataUtils.getFolderNoteWidget(mContentResolver,
- folderId);
- if (!isSyncMode()) {
- // 非同步模式,直接删除文件夹
- DataUtils.batchDeleteNotes(mContentResolver, ids);
- } else {
- // 同步模式,将文件夹移动到回收站
- DataUtils.batchMoveToFolder(mContentResolver, ids, Notes.ID_TRASH_FOLER);
- }
- // 更新相关小部件
- if (widgets != null) {
- for (AppWidgetAttribute widget : widgets) {
- if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID
- && widget.widgetType != Notes.TYPE_WIDGET_INVALIDE) {
- updateWidget(widget.widgetId, widget.widgetType);
- }
- }
- }
- }
-
- /**
- * 打开笔记进行编辑或查看
- * @param data 笔记数据
- */
- private void openNode(NoteItemData data) {
- Intent intent = new Intent(this, NoteEditActivity.class);
- intent.setAction(Intent.ACTION_VIEW);
- intent.putExtra(Intent.EXTRA_UID, data.getId());
- this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
- }
-
- /**
- * 打开文件夹,显示其中的笔记
- * @param data 文件夹数据
- */
- private void openFolder(NoteItemData data) {
- mCurrentFolderId = data.getId();
- // 查询文件夹中的笔记
- startAsyncNotesListQuery();
- // 如果是通话记录文件夹
- if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
- mState = ListEditState.CALL_RECORD_FOLDER;
- mAddNewNote.setVisibility(View.GONE);
- } else {
- mState = ListEditState.SUB_FOLDER;
- }
- // 设置标题栏文本
- if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
- mTitleBar.setText(R.string.call_record_folder_name);
- } else {
- mTitleBar.setText(data.getSnippet());
- }
- mTitleBar.setVisibility(View.VISIBLE);
- }
-
- /**
- * 点击事件处理
- * @param v 点击的视图
- */
- public void onClick(View v) {
- int id = v.getId();
- if (id == R.id.btn_new_note) {
- // 点击新建笔记按钮
- createNewNote();
- }
- }
-
- /**
- * 显示软键盘
- */
- private void showSoftInput() {
- InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- if (inputMethodManager != null) {
- inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
- }
- }
-
- /**
- * 隐藏软键盘
- * @param view 关联的视图
- */
- private void hideSoftInput(View view) {
- InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
- }
-
- /**
- * 显示创建或修改文件夹的对话框
- * @param create 是否为创建(true)或修改(false)
- */
- private void showCreateOrModifyFolderDialog(final boolean create) {
- final AlertDialog.Builder builder = new AlertDialog.Builder(this);
- View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
- final EditText etName = (EditText) view.findViewById(R.id.et_foler_name);
- showSoftInput();
- if (!create) {
- // 修改文件夹,设置当前名称
- if (mFocusNoteDataItem != null) {
- etName.setText(mFocusNoteDataItem.getSnippet());
- builder.setTitle(getString(R.string.menu_folder_change_name));
- } else {
- Log.e(TAG, "The long click data item is null");
- return;
- }
- } else {
- // 创建文件夹,清空输入框
- etName.setText("");
- builder.setTitle(this.getString(R.string.menu_create_folder));
- }
-
- builder.setPositiveButton(android.R.string.ok, null);
- builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- hideSoftInput(etName);
- }
- });
-
- final Dialog dialog = builder.setView(view).show();
- final Button positive = (Button)dialog.findViewById(android.R.id.button1);
- positive.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- hideSoftInput(etName);
- String name = etName.getText().toString();
- // 检查文件夹名称是否已存在
- if (DataUtils.checkVisibleFolderName(mContentResolver, name)) {
- Toast.makeText(NotesListActivity.this, getString(R.string.folder_exist, name),
- Toast.LENGTH_LONG).show();
- etName.setSelection(0, etName.length());
- return;
- }
- if (!create) {
- // 修改文件夹名称
- if (!TextUtils.isEmpty(name)) {
- ContentValues values = new ContentValues();
- values.put(NoteColumns.SNIPPET, name);
- values.put(NoteColumns.TYPE, Notes.TYPE_FOLDER);
- values.put(NoteColumns.LOCAL_MODIFIED, 1);
- mContentResolver.update(Notes.CONTENT_NOTE_URI, values, NoteColumns.ID
- + "=?", new String[] {
- String.valueOf(mFocusNoteDataItem.getId())
- });
- }
- } else if (!TextUtils.isEmpty(name)) {
- // 创建新文件夹
- ContentValues values = new ContentValues();
- values.put(NoteColumns.SNIPPET, name);
- values.put(NoteColumns.TYPE, Notes.TYPE_FOLDER);
- mContentResolver.insert(Notes.CONTENT_NOTE_URI, values);
- }
- dialog.dismiss();
- }
- });
-
- // 输入框为空时禁用确定按钮
- if (TextUtils.isEmpty(etName.getText())) {
- positive.setEnabled(false);
- }
- etName.addTextChangedListener(new TextWatcher() {
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
-
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- // 根据输入内容启用/禁用确定按钮
- if (TextUtils.isEmpty(etName.getText())) {
- positive.setEnabled(false);
- } else {
- positive.setEnabled(true);
- }
- }
-
- public void afterTextChanged(Editable s) {
- }
- });
- }
-
- /**
- * 处理返回键事件
- */
- @Override
- public void onBackPressed() {
- switch (mState) {
- case SUB_FOLDER:
- // 从子文件夹返回根目录
- mCurrentFolderId = Notes.ID_ROOT_FOLDER;
- mState = ListEditState.NOTE_LIST;
- startAsyncNotesListQuery();
- mTitleBar.setVisibility(View.GONE);
- break;
- case CALL_RECORD_FOLDER:
- // 从通话记录文件夹返回根目录
- mCurrentFolderId = Notes.ID_ROOT_FOLDER;
- mState = ListEditState.NOTE_LIST;
- mAddNewNote.setVisibility(View.VISIBLE);
- mTitleBar.setVisibility(View.GONE);
- startAsyncNotesListQuery();
- break;
- case NOTE_LIST:
- // 根目录状态,直接返回
- super.onBackPressed();
- break;
- default:
- break;
- }
- }
-
- /**
- * 更新小部件
- * @param appWidgetId 小部件ID
- * @param appWidgetType 小部件类型
- */
- private void updateWidget(int appWidgetId, int appWidgetType) {
- Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
- // 根据小部件类型设置对应的广播接收器
- if (appWidgetType == Notes.TYPE_WIDGET_2X) {
- intent.setClass(this, NoteWidgetProvider_2x.class);
- } else if (appWidgetType == Notes.TYPE_WIDGET_4X) {
- intent.setClass(this, NoteWidgetProvider_4x.class);
- } else {
- Log.e(TAG, "Unspported widget type");
- return;
- }
-
- intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
- appWidgetId
- });
-
- sendBroadcast(intent);
- setResult(RESULT_OK, intent);
- }
-
- /**
- * 文件夹的上下文菜单创建监听器
- */
- private final OnCreateContextMenuListener mFolderOnCreateContextMenuListener = new OnCreateContextMenuListener() {
- public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
- if (mFocusNoteDataItem != null) {
- menu.setHeaderTitle(mFocusNoteDataItem.getSnippet());
- menu.add(0, MENU_FOLDER_VIEW, 0, R.string.menu_folder_view);
- menu.add(0, MENU_FOLDER_DELETE, 0, R.string.menu_folder_delete);
- menu.add(0, MENU_FOLDER_CHANGE_NAME, 0, R.string.menu_folder_change_name);
- }
- }
- };
-
- /**
- * 上下文菜单关闭时调用
- * @param menu 菜单
- */
- @Override
- public void onContextMenuClosed(Menu menu) {
- if (mNotesListView != null) {
- mNotesListView.setOnCreateContextMenuListener(null);
- }
- super.onContextMenuClosed(menu);
- }
-
- /**
- * 上下文菜单项点击时调用
- * @param item 菜单项
- * @return 是否处理了事件
- */
- @Override
- public boolean onContextItemSelected(MenuItem item) {
- if (mFocusNoteDataItem == null) {
- Log.e(TAG, "The long click data item is null");
- return false;
- }
- // 根据菜单项ID处理
- if (item.getItemId() == MENU_FOLDER_VIEW) {
- openFolder(mFocusNoteDataItem);
- } else if (item.getItemId() == MENU_FOLDER_DELETE) {
- // 显示删除文件夹确认对话框
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(getString(R.string.alert_title_delete));
- builder.setIcon(android.R.drawable.ic_dialog_alert);
- builder.setMessage(getString(R.string.alert_message_delete_folder));
- builder.setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- deleteFolder(mFocusNoteDataItem.getId());
- }
- });
- builder.setNegativeButton(android.R.string.cancel, null);
- builder.show();
- } else if (item.getItemId() == MENU_FOLDER_CHANGE_NAME) {
- showCreateOrModifyFolderDialog(false);
- }
-
- return true;
- }
-
- /**
- * 准备菜单时调用
- * @param menu 菜单
- * @return 是否准备成功
- */
- @Override
- public boolean onPrepareOptionsMenu(Menu menu) {
- menu.clear();
- // 根据当前状态加载不同的菜单
- if (mState == ListEditState.NOTE_LIST) {
- getMenuInflater().inflate(R.menu.note_list, menu);
- // 设置同步/取消同步菜单文本
- menu.findItem(R.id.menu_sync).setTitle(
- GTaskSyncService.isSyncing() ? R.string.menu_sync_cancel : R.string.menu_sync);
- } else if (mState == ListEditState.SUB_FOLDER) {
- getMenuInflater().inflate(R.menu.sub_folder, menu);
- } else if (mState == ListEditState.CALL_RECORD_FOLDER) {
- getMenuInflater().inflate(R.menu.call_record_folder, menu);
- } else {
- Log.e(TAG, "Wrong state:" + mState);
- }
- return true;
- }
-
- /**
- * 选项菜单项点击时调用
- * @param item 菜单项
- * @return 是否处理了事件
- */
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- int itemId = item.getItemId();
- if (itemId == R.id.menu_new_folder) {
- // 创建新文件夹
- showCreateOrModifyFolderDialog(true);
- } else if (itemId == R.id.menu_export_text) {
- // 导出笔记为文本
- exportNoteToText();
- } else if (itemId == R.id.menu_sync) {
- // 同步或取消同步
- if (isSyncMode()) {
- if (TextUtils.equals(item.getTitle(), getString(R.string.menu_sync))) {
- GTaskSyncService.startSync(this);
- } else {
- GTaskSyncService.cancelSync(this);
- }
- } else {
- // 未设置同步账户,跳转到偏好设置
- startPreferenceActivity();
- }
- } else if (itemId == R.id.menu_setting) {
- // 跳转到偏好设置
- startPreferenceActivity();
- } else if (itemId == R.id.menu_new_note) {
- // 创建新笔记
- createNewNote();
- } else if (itemId == R.id.menu_search) {
- // 搜索
- onSearchRequested();
- }
- return true;
- }
-
- /**
- * 处理搜索请求
- * @return 是否处理成功
- */
- @Override
- public boolean onSearchRequested() {
- startSearch(null, false, null /* appData */, false);
- return true;
- }
-
- /**
- * 导出笔记为文本文件
- */
- private void exportNoteToText() {
- final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this);
- new AsyncTask() {
-
- @Override
- protected Integer doInBackground(Void... unused) {
- return backup.exportToText();
- }
-
- @Override
- protected void onPostExecute(Integer result) {
- // 根据导出结果显示不同的对话框
- if (result == BackupUtils.STATE_SD_CARD_UNMOUONTED) {
- AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
- builder.setTitle(NotesListActivity.this
- .getString(R.string.failed_sdcard_export));
- builder.setMessage(NotesListActivity.this
- .getString(R.string.error_sdcard_unmounted));
- builder.setPositiveButton(android.R.string.ok, null);
- builder.show();
- } else if (result == BackupUtils.STATE_SUCCESS) {
- AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
- builder.setTitle(NotesListActivity.this
- .getString(R.string.success_sdcard_export));
- builder.setMessage(NotesListActivity.this.getString(
- R.string.format_exported_file_location, backup
- .getExportedTextFileName(), backup.getExportedTextFileDir()));
- builder.setPositiveButton(android.R.string.ok, null);
- builder.show();
- } else if (result == BackupUtils.STATE_SYSTEM_ERROR) {
- AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
- builder.setTitle(NotesListActivity.this
- .getString(R.string.failed_sdcard_export));
- builder.setMessage(NotesListActivity.this
- .getString(R.string.error_sdcard_export));
- builder.setPositiveButton(android.R.string.ok, null);
- builder.show();
- }
- }
-
- }.execute();
- }
-
- /**
- * 检查是否为同步模式(已设置同步账户)
- * @return 是否为同步模式
- */
- private boolean isSyncMode() {
- return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
- }
-
- /**
- * 启动偏好设置活动
- */
- private void startPreferenceActivity() {
- Activity from = getParent() != null ? getParent() : this;
- Intent intent = new Intent(from, NotesPreferenceActivity.class);
- from.startActivityIfNeeded(intent, -1);
- }
-
- /**
- * 列表项点击监听器
- */
- private class OnListItemClickListener implements OnItemClickListener {
-
- public void onItemClick(AdapterView> parent, View view, int position, long id) {
- if (view instanceof NotesListItem) {
- NoteItemData item = ((NotesListItem) view).getItemData();
- // 如果是多选模式
- if (mNotesListAdapter.isInChoiceMode()) {
- if (item.getType() == Notes.TYPE_NOTE) {
- position = position - mNotesListView.getHeaderViewsCount();
- mModeCallBack.onItemCheckedStateChanged(null, position, id,
- !mNotesListAdapter.isSelectedItem(position));
- }
- return;
- }
-
- // 根据当前状态处理点击
- switch (mState) {
- case NOTE_LIST:
- if (item.getType() == Notes.TYPE_FOLDER
- || item.getType() == Notes.TYPE_SYSTEM) {
- openFolder(item);
- } else if (item.getType() == Notes.TYPE_NOTE) {
- openNode(item);
- } else {
- Log.e(TAG, "Wrong note type in NOTE_LIST");
- }
- break;
- case SUB_FOLDER:
- case CALL_RECORD_FOLDER:
- if (item.getType() == Notes.TYPE_NOTE) {
- openNode(item);
- } else {
- Log.e(TAG, "Wrong note type in SUB_FOLDER");
- }
- break;
- default:
- break;
- }
- }
- }
-
- }
-
- /**
- * 查询目标文件夹列表(用于移动笔记)
- */
- private void startQueryDestinationFolders() {
- // 构建查询条件:文件夹类型,父文件夹不是回收站,ID不是当前文件夹
- String selection = NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>? AND " + NoteColumns.ID + "<>?";
- // 如果是笔记列表状态,添加根文件夹作为可选目标
- selection = (mState == ListEditState.NOTE_LIST) ? selection:
- "(" + selection + ") OR (" + NoteColumns.ID + "=" + Notes.ID_ROOT_FOLDER + ")";
-
- mBackgroundQueryHandler.startQuery(FOLDER_LIST_QUERY_TOKEN,
- null,
- Notes.CONTENT_NOTE_URI,
- FoldersListAdapter.PROJECTION,
- selection,
- new String[] {
- String.valueOf(Notes.TYPE_FOLDER),
- String.valueOf(Notes.ID_TRASH_FOLER),
- String.valueOf(mCurrentFolderId)
- },
- NoteColumns.MODIFIED_DATE + " DESC");
- }
-
- /**
- * 列表项长按事件处理
- * @param parent 父视图
- * @param view 长按的视图
- * @param position 位置
- * @param id 项ID
- * @return 是否处理了事件
- */
- public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
- if (view instanceof NotesListItem) {
- mFocusNoteDataItem = ((NotesListItem) view).getItemData();
- // 如果是笔记且不在多选模式,启动多选动作模式
- if (mFocusNoteDataItem.getType() == Notes.TYPE_NOTE && !mNotesListAdapter.isInChoiceMode()) {
- if (mNotesListView.startActionMode(mModeCallBack) != null) {
- mModeCallBack.onItemCheckedStateChanged(null, position, id, true);
- mNotesListView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
- } else {
- Log.e(TAG, "startActionMode fails");
- }
- } else if (mFocusNoteDataItem.getType() == Notes.TYPE_FOLDER) {
- // 如果是文件夹,显示上下文菜单
- mNotesListView.setOnCreateContextMenuListener(mFolderOnCreateContextMenuListener);
- }
- }
- return false;
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListAdapter.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListAdapter.java
deleted file mode 100644
index 805cd1f..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListAdapter.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * 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.content.Context;
-import android.database.Cursor;
-import android.util.Log;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.CursorAdapter;
-
-import net.micode.notes.data.Notes;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-
-/**
- * 笔记列表的适配器,用于将笔记数据绑定到ListView
- * 支持多选模式、选择状态管理等功能
- */
-public class NotesListAdapter extends CursorAdapter {
- private static final String TAG = "NotesListAdapter"; // 日志标签
- private Context mContext; // 上下文环境
- private HashMap mSelectedIndex; // 记录选中项的位置(键:位置,值:是否选中)
- private int mNotesCount; // 笔记总数(不包含文件夹等非笔记类型)
- private boolean mChoiceMode; // 是否为多选模式
-
- /**
- * 应用小部件属性的内部类
- */
- public static class AppWidgetAttribute {
- public int widgetId; // 小部件ID
- public int widgetType; // 小部件类型
- };
-
- /**
- * 构造方法
- * @param context 上下文环境
- */
- public NotesListAdapter(Context context) {
- super(context, null); // 初始化CursorAdapter,暂时无Cursor
- mSelectedIndex = new HashMap(); // 初始化选中项集合
- mContext = context;
- mNotesCount = 0; // 初始笔记数为0
- }
-
- /**
- * 创建新的列表项视图
- * @param context 上下文环境
- * @param cursor 数据游标
- * @param parent 父容器
- * @return 新创建的列表项视图
- */
- @Override
- public View newView(Context context, Cursor cursor, ViewGroup parent) {
- return new NotesListItem(context); // 创建自定义的笔记列表项
- }
-
- /**
- * 将数据绑定到列表项视图
- * @param view 列表项视图
- * @param context 上下文环境
- * @param cursor 数据游标
- */
- @Override
- public void bindView(View view, Context context, Cursor cursor) {
- if (view instanceof NotesListItem) { // 确认视图类型
- NoteItemData itemData = new NoteItemData(context, cursor); // 封装笔记数据
- // 绑定数据到视图,包含多选模式和选中状态
- ((NotesListItem) view).bind(context, itemData, mChoiceMode,
- isSelectedItem(cursor.getPosition()));
- }
- }
-
- /**
- * 设置指定位置的选中状态
- * @param position 列表项位置
- * @param checked 是否选中
- */
- public void setCheckedItem(final int position, final boolean checked) {
- mSelectedIndex.put(position, checked); // 更新选中状态
- notifyDataSetChanged(); // 通知数据变化,刷新列表
- }
-
- /**
- * 判断是否处于多选模式
- * @return 是/否
- */
- public boolean isInChoiceMode() {
- return mChoiceMode;
- }
-
- /**
- * 设置多选模式
- * @param mode 多选模式开关
- */
- public void setChoiceMode(boolean mode) {
- mSelectedIndex.clear(); // 清空选中状态
- mChoiceMode = mode; // 更新模式
- }
-
- /**
- * 全选或取消全选
- * @param checked 是否选中
- */
- public void selectAll(boolean checked) {
- Cursor cursor = getCursor(); // 获取当前游标
- for (int i = 0; i < getCount(); i++) { // 遍历所有项
- if (cursor.moveToPosition(i)) { // 移动游标到指定位置
- // 只处理笔记类型(过滤文件夹等)
- if (NoteItemData.getNoteType(cursor) == Notes.TYPE_NOTE) {
- setCheckedItem(i, checked); // 设置选中状态
- }
- }
- }
- }
-
- /**
- * 获取所有选中项的ID集合
- * @return 选中项ID的HashSet
- */
- public HashSet getSelectedItemIds() {
- HashSet itemSet = new HashSet();
- // 遍历所有选中项
- for (Integer position : mSelectedIndex.keySet()) {
- if (mSelectedIndex.get(position) == true) { // 选中状态
- Long id = getItemId(position); // 获取项ID
- if (id == Notes.ID_ROOT_FOLDER) { // 过滤根文件夹(不应选中)
- Log.d(TAG, "Wrong item id, should not happen");
- } else {
- itemSet.add(id); // 添加到集合
- }
- }
- }
- return itemSet;
- }
-
- /**
- * 获取选中的小部件属性集合
- * @return 小部件属性的HashSet
- */
- public HashSet getSelectedWidget() {
- HashSet itemSet = new HashSet();
- // 遍历所有选中项
- for (Integer position : mSelectedIndex.keySet()) {
- if (mSelectedIndex.get(position) == true) { // 选中状态
- Cursor c = (Cursor) getItem(position); // 获取游标
- if (c != null) {
- AppWidgetAttribute widget = new AppWidgetAttribute();
- NoteItemData item = new NoteItemData(mContext, c); // 封装数据
- widget.widgetId = item.getWidgetId(); // 设置小部件ID
- widget.widgetType = item.getWidgetType(); // 设置小部件类型
- itemSet.add(widget); // 添加到集合
- /**
- * 注意:此处不应关闭游标,游标由适配器管理
- */
- } else {
- Log.e(TAG, "Invalid cursor");
- return null;
- }
- }
- }
- return itemSet;
- }
-
- /**
- * 获取选中项的数量
- * @return 选中项数量
- */
- public int getSelectedCount() {
- Collection values = mSelectedIndex.values(); // 获取所有选中状态
- if (null == values) {
- return 0;
- }
- Iterator iter = values.iterator();
- int count = 0;
- while (iter.hasNext()) {
- if (true == iter.next()) { // 统计选中的项
- count++;
- }
- }
- return count;
- }
-
- /**
- * 判断是否全选
- * @return 是/否
- */
- public boolean isAllSelected() {
- int checkedCount = getSelectedCount(); // 选中数量
- // 选中数量不为0且等于总笔记数,即为全选
- return (checkedCount != 0 && checkedCount == mNotesCount);
- }
-
- /**
- * 判断指定位置是否选中
- * @param position 位置
- * @return 是/否
- */
- public boolean isSelectedItem(final int position) {
- if (null == mSelectedIndex.get(position)) {
- return false;
- }
- return mSelectedIndex.get(position);
- }
-
- /**
- * 内容变化时回调(如数据更新)
- */
- @Override
- protected void onContentChanged() {
- super.onContentChanged();
- calcNotesCount(); // 重新计算笔记总数
- }
-
- /**
- * 更换游标时回调
- * @param cursor 新游标
- */
- @Override
- public void changeCursor(Cursor cursor) {
- super.changeCursor(cursor);
- calcNotesCount(); // 重新计算笔记总数
- }
-
- /**
- * 计算笔记总数(仅统计笔记类型,排除文件夹等)
- */
- private void calcNotesCount() {
- mNotesCount = 0;
- for (int i = 0; i < getCount(); i++) { // 遍历所有项
- Cursor c = (Cursor) getItem(i); // 获取游标
- if (c != null) {
- // 统计笔记类型的数量
- if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) {
- mNotesCount++;
- }
- } else {
- Log.e(TAG, "Invalid cursor");
- return;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListItem.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListItem.java
deleted file mode 100644
index b625ba3..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesListItem.java
+++ /dev/null
@@ -1,148 +0,0 @@
-package net.micode.notes.ui; // 假设包名
-
-import android.content.Context;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.CheckBox;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-import android.text.format.DateUtils;
-
-import net.micode.notes.R;
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.NoteColumns;
-import net.micode.notes.util.DataUtils;
-import net.micode.notes.widget.NoteItemBgResources;
-
-/**
- * 笔记列表项视图
- * 用于在ListView中显示单个笔记或文件夹的内容和状态
- */
-public class NotesListItem extends LinearLayout {
- private ImageView mAlert; // 提醒图标(时钟图标)
- private TextView mTitle; // 标题/内容摘要
- private TextView mTime; // 修改时间
- private TextView mCallName; // 来电记录的联系人名称
- private NoteItemData mItemData; // 绑定的笔记数据
- private CheckBox mCheckBox; // 多选模式下的复选框
-
- /**
- * 构造方法
- * @param context 上下文环境
- */
- public NotesListItem(Context context) {
- super(context);
- // 加载列表项布局
- inflate(context, R.layout.note_item, this);
- // 初始化控件
- mAlert = (ImageView) findViewById(R.id.iv_alert_icon);
- mTitle = (TextView) findViewById(R.id.tv_title);
- mTime = (TextView) findViewById(R.id.tv_time);
- mCallName = (TextView) findViewById(R.id.tv_name);
- mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
- }
-
- /**
- * 绑定数据到视图
- * @param context 上下文环境
- * @param data 笔记数据
- * @param choiceMode 是否为多选模式
- * @param checked 是否选中
- */
- public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {
- // 处理多选模式的复选框显示
- if (choiceMode && data.getType() == Notes.TYPE_NOTE) {
- mCheckBox.setVisibility(View.VISIBLE); // 显示复选框
- mCheckBox.setChecked(checked); // 设置选中状态
- } else {
- mCheckBox.setVisibility(View.GONE); // 隐藏复选框
- }
-
- mItemData = data; // 保存数据引用
-
- // 处理通话记录文件夹
- if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
- mCallName.setVisibility(View.GONE); // 隐藏联系人名称
- mAlert.setVisibility(View.VISIBLE); // 显示图标
- mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); // 应用标题样式
- // 显示文件夹名称和包含的笔记数量
- mTitle.setText(context.getString(R.string.call_record_folder_name)
- + context.getString(R.string.format_folder_files_count, data.getNotesCount()));
- mAlert.setImageResource(R.drawable.call_record); // 设置通话记录图标
- }
- // 处理通话记录文件夹下的笔记
- else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) {
- mCallName.setVisibility(View.VISIBLE); // 显示联系人名称
- mCallName.setText(data.getCallName()); // 设置联系人名称
- mTitle.setTextAppearance(context,R.style.TextAppearanceSecondaryItem); // 应用次要文本样式
- mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet())); // 显示内容摘要
-
- // 显示提醒图标(如有)
- if (data.hasAlert()) {
- mAlert.setImageResource(R.drawable.clock);
- mAlert.setVisibility(View.VISIBLE);
- } else {
- mAlert.setVisibility(View.GONE);
- }
- }
- // 处理其他类型(普通笔记或文件夹)
- else {
- mCallName.setVisibility(View.GONE); // 隐藏联系人名称
- mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); // 应用标题样式
-
- if (data.getType() == Notes.TYPE_FOLDER) { // 文件夹类型
- // 显示文件夹名称和包含的笔记数量
- mTitle.setText(data.getSnippet()
- + context.getString(R.string.format_folder_files_count,
- data.getNotesCount()));
- mAlert.setVisibility(View.GONE); // 隐藏提醒图标
- } else { // 普通笔记类型
- mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet())); // 显示内容摘要
- // 显示提醒图标(如有)
- if (data.hasAlert()) {
- mAlert.setImageResource(R.drawable.clock);
- mAlert.setVisibility(View.VISIBLE);
- } else {
- mAlert.setVisibility(View.GONE);
- }
- }
- }
-
- // 显示修改时间(相对时间,如"10分钟前")
- mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));
-
- // 设置背景样式
- setBackground(data);
- }
-
- /**
- * 根据笔记数据设置背景样式
- * @param data 笔记数据
- */
- private void setBackground(NoteItemData data) {
- int id = data.getBgColorId(); // 获取背景颜色ID
- if (data.getType() == Notes.TYPE_NOTE) { // 笔记类型
- // 根据笔记在列表中的位置(首项、末项、单项等)设置不同背景
- if (data.isSingle() || data.isOneFollowingFolder()) {
- setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id));
- } else if (data.isLast()) {
- setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id));
- } else if (data.isFirst() || data.isMultiFollowingFolder()) {
- setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id));
- } else {
- setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id));
- }
- } else { // 文件夹类型
- setBackgroundResource(NoteItemBgResources.getFolderBgRes()); // 应用文件夹背景
- }
- }
-
- /**
- * 获取绑定的笔记数据
- * @return 笔记数据
- */
- public NoteItemData getItemData() {
- return mItemData;
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesPreferenceActivity.java b/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesPreferenceActivity.java
deleted file mode 100644
index e3547bc..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/ui/NotesPreferenceActivity.java
+++ /dev/null
@@ -1,446 +0,0 @@
-/**
- * 笔记PreferenceActivity 类,用于处理应用的偏好设置,特别是同步账户相关的配置
- */
-public class NotesPreferenceActivity extends PreferenceActivity {
- // 共享偏好设置的文件名
- public static final String PREFERENCE_NAME = "notes_preferences";
- // 存储同步账户名的键
- public static final String PREFERENCE_SYNC_ACCOUNT_NAME = "pref_key_account_name";
- // 存储最后同步时间的键
- public static final String PREFERENCE_LAST_SYNC_TIME = "pref_last_sync_time";
- // 设置背景颜色的键(未在当前代码中详细使用)
- public static final String PREFERENCE_SET_BG_COLOR_KEY = "pref_key_bg_random_appear";
- // 同步账户偏好设置的键
- private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key";
- // 账户权限过滤键
- private static final String AUTHORITIES_FILTER_KEY = "authorities";
-
- // 账户相关的偏好设置分类
- private PreferenceCategory mAccountCategory;
- // 用于接收同步服务广播的接收器
- private GTaskReceiver mReceiver;
- // 原始账户数组,用于检测账户变化
- private Account[] mOriAccounts;
- // 标记是否添加了新账户
- private boolean mHasAddedAccount;
-
- /**
- * onCreate 方法,初始化偏好设置界面
- * @param icicle 保存的实例状态
- */
- @Override
- protected void onCreate(Bundle icicle) {
- super.onCreate(icicle);
-
- // 启用ActionBar的返回按钮
- getActionBar().setDisplayHomeAsUpEnabled(true);
-
- // 从XML资源加载偏好设置
- addPreferencesFromResource(R.xml.preferences);
- // 获取账户相关的偏好设置分类
- mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);
- // 初始化广播接收器
- mReceiver = new GTaskReceiver();
- IntentFilter filter = new IntentFilter();
- // 设置接收GTaskSyncService的广播
- filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME);
- registerReceiver(mReceiver, filter);
-
- // 初始化原始账户数组为null
- mOriAccounts = null;
- // 加载设置界面的头部布局并添加到ListView
- View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null);
- getListView().addHeaderView(header, null, true);
- }
-
- /**
- * onResume 方法,当活动恢复时调用
- */
- @Override
- protected void onResume() {
- super.onResume();
-
- // 如果有新账户添加,自动设置同步账户
- if (mHasAddedAccount) {
- Account[] accounts = getGoogleAccounts();
- // 检查是否有新账户添加
- if (mOriAccounts != null && accounts.length > mOriAccounts.length) {
- for (Account accountNew : accounts) {
- boolean found = false;
- // 遍历原始账户,检查新账户是否已存在
- for (Account accountOld : mOriAccounts) {
- if (TextUtils.equals(accountOld.name, accountNew.name)) {
- found = true;
- break;
- }
- }
- // 如果是新账户,设置为同步账户
- if (!found) {
- setSyncAccount(accountNew.name);
- break;
- }
- }
- }
- }
-
- // 刷新界面
- refreshUI();
- }
-
- /**
- * onDestroy 方法,当活动销毁时调用
- */
- @Override
- protected void onDestroy() {
- // 注销广播接收器,避免内存泄漏
- if (mReceiver != null) {
- unregisterReceiver(mReceiver);
- }
- super.onDestroy();
- }
-
- /**
- * 加载账户相关的偏好设置
- */
- private void loadAccountPreference() {
- // 清除现有账户偏好设置项
- mAccountCategory.removeAll();
-
- // 创建新的偏好设置项
- Preference accountPref = new Preference(this);
- // 获取当前的同步账户名
- final String defaultAccount = getSyncAccountName(this);
- // 设置标题和摘要
- accountPref.setTitle(getString(R.string.preferences_account_title));
- accountPref.setSummary(getString(R.string.preferences_account_summary));
- // 设置点击事件监听器
- accountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
- public boolean onPreferenceClick(Preference preference) {
- // 如果不在同步中
- if (!GTaskSyncService.isSyncing()) {
- // 如果当前没有设置同步账户,显示选择账户对话框
- if (TextUtils.isEmpty(defaultAccount)) {
- showSelectAccountAlertDialog();
- } else {
- // 如果已设置账户,显示更改账户的确认对话框
- showChangeAccountConfirmAlertDialog();
- }
- } else {
- // 同步中,提示不能更改账户
- Toast.makeText(NotesPreferenceActivity.this,
- R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT)
- .show();
- }
- return true;
- }
- });
-
- // 将账户偏好设置项添加到分类中
- mAccountCategory.addPreference(accountPref);
- }
-
- /**
- * 加载同步按钮和同步状态
- */
- private void loadSyncButton() {
- // 获取同步按钮和最后同步时间的文本视图
- Button syncButton = (Button) findViewById(R.id.preference_sync_button);
- TextView lastSyncTimeView = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
-
- // 根据同步状态设置按钮
- if (GTaskSyncService.isSyncing()) {
- // 同步中,按钮显示取消同步
- syncButton.setText(getString(R.string.preferences_button_sync_cancel));
- syncButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- GTaskSyncService.cancelSync(NotesPreferenceActivity.this);
- }
- });
- } else {
- // 未同步,按钮显示立即同步
- syncButton.setText(getString(R.string.preferences_button_sync_immediately));
- syncButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- GTaskSyncService.startSync(NotesPreferenceActivity.this);
- }
- });
- }
- // 如果没有设置同步账户,禁用同步按钮
- syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this)));
-
- // 设置最后同步时间的显示
- if (GTaskSyncService.isSyncing()) {
- // 同步中,显示同步进度
- lastSyncTimeView.setText(GTaskSyncService.getProgressString());
- lastSyncTimeView.setVisibility(View.VISIBLE);
- } else {
- // 未同步,显示最后同步时间
- long lastSyncTime = getLastSyncTime(this);
- if (lastSyncTime != 0) {
- lastSyncTimeView.setText(getString(R.string.preferences_last_sync_time,
- DateFormat.format(getString(R.string.preferences_last_sync_time_format),
- lastSyncTime)));
- lastSyncTimeView.setVisibility(View.VISIBLE);
- } else {
- // 从未同步过,隐藏最后同步时间
- lastSyncTimeView.setVisibility(View.GONE);
- }
- }
- }
-
- /**
- * 刷新界面,重新加载账户偏好和同步按钮
- */
- private void refreshUI() {
- loadAccountPreference();
- loadSyncButton();
- }
-
- /**
- * 显示选择账户的对话框
- */
- private void showSelectAccountAlertDialog() {
- AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
-
- // 加载对话框标题布局
- View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
- TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
- titleTextView.setText(getString(R.string.preferences_dialog_select_account_title));
- TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
- subtitleTextView.setText(getString(R.string.preferences_dialog_select_account_tips));
-
- dialogBuilder.setCustomTitle(titleView);
- dialogBuilder.setPositiveButton(null, null);
-
- // 获取所有Google账户
- Account[] accounts = getGoogleAccounts();
- String defAccount = getSyncAccountName(this);
-
- // 保存当前账户数组,标记未添加新账户
- mOriAccounts = accounts;
- mHasAddedAccount = false;
-
- // 如果有Google账户
- if (accounts.length > 0) {
- CharSequence[] items = new CharSequence[accounts.length];
- final CharSequence[] itemMapping = items;
- int checkedItem = -1;
- int index = 0;
- // 构建账户列表
- for (Account account : accounts) {
- if (TextUtils.equals(account.name, defAccount)) {
- checkedItem = index;
- }
- items[index++] = account.name;
- }
- // 设置单选列表,选择后设置同步账户并关闭对话框
- dialogBuilder.setSingleChoiceItems(items, checkedItem,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- setSyncAccount(itemMapping[which].toString());
- dialog.dismiss();
- refreshUI();
- }
- });
- }
-
- // 加载添加账户的视图并设置点击事件
- View addAccountView = LayoutInflater.from(this).inflate(R.layout.add_account_text, null);
- dialogBuilder.setView(addAccountView);
-
- final AlertDialog dialog = dialogBuilder.show();
- addAccountView.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // 标记已添加账户,打开系统添加账户界面
- mHasAddedAccount = true;
- Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
- intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] {
- "gmail-ls"
- });
- startActivityForResult(intent, -1);
- dialog.dismiss();
- }
- });
- }
-
- /**
- * 显示更改账户的确认对话框
- */
- private void showChangeAccountConfirmAlertDialog() {
- AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
-
- // 加载对话框标题布局
- View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
- TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
- titleTextView.setText(getString(R.string.preferences_dialog_change_account_title,
- getSyncAccountName(this)));
- TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
- subtitleTextView.setText(getString(R.string.preferences_dialog_change_account_warn_msg));
- dialogBuilder.setCustomTitle(titleView);
-
- // 对话框选项:更改账户、移除账户、取消
- CharSequence[] menuItemArray = new CharSequence[] {
- getString(R.string.preferences_menu_change_account),
- getString(R.string.preferences_menu_remove_account),
- getString(R.string.preferences_menu_cancel)
- };
- dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- if (which == 0) {
- // 更改账户,显示选择账户对话框
- showSelectAccountAlertDialog();
- } else if (which == 1) {
- // 移除账户
- removeSyncAccount();
- refreshUI();
- }
- }
- });
- dialogBuilder.show();
- }
-
- /**
- * 获取所有Google账户
- * @return Google账户数组
- */
- private Account[] getGoogleAccounts() {
- AccountManager accountManager = AccountManager.get(this);
- return accountManager.getAccountsByType("com.google");
- }
-
- /**
- * 设置同步账户
- * @param account 账户名
- */
- private void setSyncAccount(String account) {
- // 如果账户名发生变化
- if (!getSyncAccountName(this).equals(account)) {
- // 获取共享偏好设置编辑器
- SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = settings.edit();
- if (account != null) {
- editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, account);
- } else {
- editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
- }
- editor.commit();
-
- // 清除最后同步时间
- setLastSyncTime(this, 0);
-
- // 在新线程中清除本地与GTask相关的信息
- new Thread(new Runnable() {
- public void run() {
- ContentValues values = new ContentValues();
- values.put(NoteColumns.GTASK_ID, "");
- values.put(NoteColumns.SYNC_ID, 0);
- getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
- }
- }).start();
-
- // 显示设置账户成功的提示
- Toast.makeText(NotesPreferenceActivity.this,
- getString(R.string.preferences_toast_success_set_accout, account),
- Toast.LENGTH_SHORT).show();
- }
- }
-
- /**
- * 移除同步账户
- */
- private void removeSyncAccount() {
- // 获取共享偏好设置编辑器
- SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = settings.edit();
- // 移除账户名和最后同步时间
- if (settings.contains(PREFERENCE_SYNC_ACCOUNT_NAME)) {
- editor.remove(PREFERENCE_SYNC_ACCOUNT_NAME);
- }
- if (settings.contains(PREFERENCE_LAST_SYNC_TIME)) {
- editor.remove(PREFERENCE_LAST_SYNC_TIME);
- }
- editor.commit();
-
- // 在新线程中清除本地与GTask相关的信息
- new Thread(new Runnable() {
- public void run() {
- ContentValues values = new ContentValues();
- values.put(NoteColumns.GTASK_ID, "");
- values.put(NoteColumns.SYNC_ID, 0);
- getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
- }
- }).start();
- }
-
- /**
- * 获取同步账户名
- * @param context 上下文
- * @return 账户名
- */
- public static String getSyncAccountName(Context context) {
- SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
- Context.MODE_PRIVATE);
- return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
- }
-
- /**
- * 设置最后同步时间
- * @param context 上下文
- * @param time 时间戳
- */
- public static void setLastSyncTime(Context context, long time) {
- SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
- Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = settings.edit();
- editor.putLong(PREFERENCE_LAST_SYNC_TIME, time);
- editor.commit();
- }
-
- /**
- * 获取最后同步时间
- * @param context 上下文
- * @return 时间戳
- */
- public static long getLastSyncTime(Context context) {
- SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
- Context.MODE_PRIVATE);
- return settings.getLong(PREFERENCE_LAST_SYNC_TIME, 0);
- }
-
- /**
- * 用于接收GTask同步服务广播的内部类
- */
- private class GTaskReceiver extends BroadcastReceiver {
-
- @Override
- public void onReceive(Context context, Intent intent) {
- // 刷新界面
- refreshUI();
- // 如果正在同步,更新同步状态文本
- if (intent.getBooleanExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_IS_SYNCING, false)) {
- TextView syncStatus = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
- syncStatus.setText(intent
- .getStringExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_PROGRESS_MSG));
- }
-
- }
- }
-
- /**
- * 处理ActionBar菜单项点击事件
- * @param item 菜单项
- * @return 是否处理了事件
- */
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- // 点击返回按钮,回到笔记列表界面
- Intent intent = new Intent(this, NotesListActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(intent);
- return true;
- default:
- return false;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java b/src/Notes-master/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java
deleted file mode 100644
index d881d5c..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * 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.widget;
-import android.app.PendingIntent;
-import android.appwidget.AppWidgetManager;
-import android.appwidget.AppWidgetProvider;
-import android.content.ContentValues;
-import android.content.Context;
-import android.content.Intent;
-import android.database.Cursor;
-import android.util.Log;
-import android.widget.RemoteViews;
-
-import net.micode.notes.R;
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.tool.ResourceParser;
-import net.micode.notes.ui.NoteEditActivity;
-import net.micode.notes.ui.NotesListActivity;
-
-/**
- * 笔记小组件的抽象基类,定义了小组件的基本行为和抽象方法
- * 子类需实现具体的布局、背景资源和组件类型
- */
-public abstract class NoteWidgetProvider extends AppWidgetProvider {
- // 查询数据库时需要的字段投影,包含笔记ID、背景色ID和摘要
- public static final String [] PROJECTION = new String [] {
- NoteColumns.ID, // 笔记ID
- NoteColumns.BG_COLOR_ID, // 背景颜色ID
- NoteColumns.SNIPPET // 笔记摘要
- };
-
- // 投影字段对应的索引常量,方便Cursor取值
- public static final int COLUMN_ID = 0; // 笔记ID在投影中的索引
- public static final int COLUMN_BG_COLOR_ID = 1; // 背景色ID在投影中的索引
- public static final int COLUMN_SNIPPET = 2; // 摘要在投影中的索引
-
- private static final String TAG = "NoteWidgetProvider"; // 日志标签
-
- /**
- * 当小组件被删除时调用
- * 功能:将数据库中关联该小组件ID的笔记记录置为无效小组件ID
- * @param context 上下文对象
- * @param appWidgetIds 被删除的小组件ID数组
- */
- @Override
- public void onDeleted(Context context, int[] appWidgetIds) {
- ContentValues values = new ContentValues();
- // 设置为无效的小组件ID,表示该笔记不再关联任何小组件
- values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
- for (int i = 0; i < appWidgetIds.length; i++) {
- // 更新数据库中关联该小组件ID的笔记记录
- context.getContentResolver().update(Notes.CONTENT_NOTE_URI,
- values,
- NoteColumns.WIDGET_ID + "=?", // 更新条件:widget_id等于当前ID
- new String[] { String.valueOf(appWidgetIds[i])});
- }
- }
-
- /**
- * 获取指定小组件关联的笔记信息
- * @param context 上下文对象
- * @param widgetId 小组件ID
- * @return 包含笔记信息的Cursor,若查询失败则返回null
- */
- private Cursor getNoteWidgetInfo(Context context, int widgetId) {
- return context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
- PROJECTION, // 查询的字段
- // 查询条件:widget_id等于指定ID,且不是回收站中的笔记
- NoteColumns.WIDGET_ID + "=? AND " + NoteColumns.PARENT_ID + "<>?",
- new String[] { String.valueOf(widgetId), String.valueOf(Notes.ID_TRASH_FOLER) },
- null); // 不指定排序
- }
-
- /**
- * 公开的更新方法,调用私有更新方法并默认关闭隐私模式
- * @param context 上下文对象
- * @param appWidgetManager 小组件管理器
- * @param appWidgetIds 需要更新的小组件ID数组
- */
- protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
- update(context, appWidgetManager, appWidgetIds, false);
- }
-
- /**
- * 私有更新方法,实际处理小组件的更新逻辑
- * @param context 上下文对象
- * @param appWidgetManager 小组件管理器
- * @param appWidgetIds 需要更新的小组件ID数组
- * @param privacyMode 是否启用隐私模式
- */
- private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds,
- boolean privacyMode) {
- for (int i = 0; i < appWidgetIds.length; i++) {
- // 过滤无效的小组件ID
- if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) {
- int bgId = ResourceParser.getDefaultBgId(context); // 默认背景ID
- String snippet = ""; // 笔记摘要
- // 创建跳转到笔记编辑页面的意图
- Intent intent = new Intent(context, NoteEditActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // 活动栈顶复用模式
- intent.putExtra(Notes.INTENT_EXTRA_WIDGET_ID, appWidgetIds[i]); // 传递小组件ID
- intent.putExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, getWidgetType()); // 传递小组件类型
-
- // 查询该小组件关联的笔记信息
- Cursor c = getNoteWidgetInfo(context, appWidgetIds[i]);
- if (c != null && c.moveToFirst()) {
- // 检查是否有多个笔记关联同一小组件(异常情况)
- if (c.getCount() > 1) {
- Log.e(TAG, "Multiple message with same widget id:" + appWidgetIds[i]);
- c.close();
- return;
- }
- // 从Cursor中获取笔记摘要和背景ID
- snippet = c.getString(COLUMN_SNIPPET);
- bgId = c.getInt(COLUMN_BG_COLOR_ID);
- // 传递笔记ID,用于查看已有笔记
- intent.putExtra(Intent.EXTRA_UID, c.getLong(COLUMN_ID));
- intent.setAction(Intent.ACTION_VIEW); // 设置动作为查看
- } else {
- // 没有关联的笔记时,显示默认提示文本
- snippet = context.getResources().getString(R.string.widget_havenot_content);
- intent.setAction(Intent.ACTION_INSERT_OR_EDIT); // 设置动作为新建或编辑
- }
-
- // 关闭Cursor释放资源
- if (c != null) {
- c.close();
- }
-
- // 加载小组件布局
- RemoteViews rv = new RemoteViews(context.getPackageName(), getLayoutId());
- // 设置小组件背景图片
- rv.setImageViewResource(R.id.widget_bg_image, getBgResourceId(bgId));
- intent.putExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, bgId); // 传递背景ID
-
- /**
- * 生成小组件点击时的PendingIntent
- */
- PendingIntent pendingIntent = null;
- if (privacyMode) {
- // 隐私模式:显示访问模式提示,点击跳转到笔记列表
- rv.setTextViewText(R.id.widget_text,
- context.getString(R.string.widget_under_visit_mode));
- pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], new Intent(
- context, NotesListActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
- } else {
- // 正常模式:显示笔记摘要,点击跳转到笔记编辑页面
- rv.setTextViewText(R.id.widget_text, snippet);
- pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], intent,
- PendingIntent.FLAG_UPDATE_CURRENT);
- }
-
- // 设置文本区域的点击事件
- rv.setOnClickPendingIntent(R.id.widget_text, pendingIntent);
- // 更新小组件
- appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
- }
- }
- }
-
- /**
- * 抽象方法:获取背景资源ID
- * @param bgId 背景ID
- * @return 对应的资源ID
- */
- protected abstract int getBgResourceId(int bgId);
-
- /**
- * 抽象方法:获取布局ID
- * @return 布局资源ID
- */
- protected abstract int getLayoutId();
-
- /**
- * 抽象方法:获取小组件类型
- * @return 小组件类型常量
- */
- protected abstract int getWidgetType();
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_2x.java b/src/Notes-master/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_2x.java
deleted file mode 100644
index ead994a..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_2x.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.widget;
-
-import android.appwidget.AppWidgetManager;
-import android.content.Context;
-
-import net.micode.notes.R;
-import net.micode.notes.data.Notes;
-import net.micode.notes.tool.ResourceParser;
-
-/**
- * 2x尺寸的笔记小组件实现类
- * 继承自抽象基类NoteWidgetProvider,实现具体的布局和资源
- */
-public class NoteWidgetProvider_2x extends NoteWidgetProvider {
- /**
- * 重写小组件更新方法,调用父类的更新逻辑
- * @param context 上下文对象
- * @param appWidgetManager 小组件管理器
- * @param appWidgetIds 需要更新的小组件ID数组
- */
- @Override
- public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
- super.update(context, appWidgetManager, appWidgetIds);
- }
-
- /**
- * 实现抽象方法:获取2x小组件的布局ID
- * @return 布局资源ID(widget_2x.xml)
- */
- @Override
- protected int getLayoutId() {
- return R.layout.widget_2x;
- }
-
- /**
- * 实现抽象方法:获取2x小组件的背景资源ID
- * @param bgId 背景ID
- * @return 对应的2x小组件背景资源ID
- */
- @Override
- protected int getBgResourceId(int bgId) {
- return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
- }
-
- /**
- * 实现抽象方法:获取2x小组件的类型
- * @return 类型常量(TYPE_WIDGET_2X)
- */
- @Override
- protected int getWidgetType() {
- return Notes.TYPE_WIDGET_2X;
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_4x.java b/src/Notes-master/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_4x.java
deleted file mode 100644
index 38c3821..0000000
--- a/src/Notes-master/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider_4x.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.widget;
-
-import android.appwidget.AppWidgetManager;
-import android.content.Context;
-
-import net.micode.notes.R;
-import net.micode.notes.data.Notes;
-import net.micode.notes.tool.ResourceParser;
-
-/**
- * 4x尺寸的笔记小组件实现类
- * 继承自抽象基类NoteWidgetProvider,实现具体的布局和资源
- */
-public class NoteWidgetProvider_4x extends NoteWidgetProvider {
- /**
- * 重写小组件更新方法,调用父类的更新逻辑
- * @param context 上下文对象
- * @param appWidgetManager 小组件管理器
- * @param appWidgetIds 需要更新的小组件ID数组
- */
- @Override
- public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
- super.update(context, appWidgetManager, appWidgetIds);
- }
-
- /**
- * 实现抽象方法:获取4x小组件的布局ID
- * @return 布局资源ID(widget_4x.xml)
- */
- protected int getLayoutId() {
- return R.layout.widget_4x;
- }
-
- /**
- * 实现抽象方法:获取4x小组件的背景资源ID
- * @param bgId 背景ID
- * @return 对应的4x小组件背景资源ID
- */
- @Override
- protected int getBgResourceId(int bgId) {
- return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId);
- }
-
- /**
- * 实现抽象方法:获取4x小组件的类型
- * @return 类型常量(TYPE_WIDGET_4X)
- */
- @Override
- protected int getWidgetType() {
- return Notes.TYPE_WIDGET_4X;
- }
-}
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/color/primary_text_dark.xml b/src/Notes-master/app/src/main/res/color/primary_text_dark.xml
deleted file mode 100644
index 7c85459..0000000
--- a/src/Notes-master/app/src/main/res/color/primary_text_dark.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/color/secondary_text_dark.xml b/src/Notes-master/app/src/main/res/color/secondary_text_dark.xml
deleted file mode 100644
index c1c2384..0000000
--- a/src/Notes-master/app/src/main/res/color/secondary_text_dark.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/bg_btn_set_color.png b/src/Notes-master/app/src/main/res/drawable-hdpi/bg_btn_set_color.png
deleted file mode 100644
index 5eb5d44..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/bg_btn_set_color.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/bg_color_btn_mask.png b/src/Notes-master/app/src/main/res/drawable-hdpi/bg_color_btn_mask.png
deleted file mode 100644
index 100db77..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/bg_color_btn_mask.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/call_record.png b/src/Notes-master/app/src/main/res/drawable-hdpi/call_record.png
deleted file mode 100644
index fb88ca4..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/call_record.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/clock.png b/src/Notes-master/app/src/main/res/drawable-hdpi/clock.png
deleted file mode 100644
index 5f2ae9a..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/clock.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/delete.png b/src/Notes-master/app/src/main/res/drawable-hdpi/delete.png
deleted file mode 100644
index 643de3e..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/delete.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/dropdown_icon.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/dropdown_icon.9.png
deleted file mode 100644
index 5525025..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/dropdown_icon.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_blue.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/edit_blue.9.png
deleted file mode 100644
index 55a1856..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_blue.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_green.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/edit_green.9.png
deleted file mode 100644
index 2cb2d60..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_green.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_red.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/edit_red.9.png
deleted file mode 100644
index bae944a..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_red.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_title_blue.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/edit_title_blue.9.png
deleted file mode 100644
index 96e6092..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_title_blue.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_title_green.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/edit_title_green.9.png
deleted file mode 100644
index 08d8644..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_title_green.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_title_red.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/edit_title_red.9.png
deleted file mode 100644
index 9c430e5..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_title_red.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_title_white.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/edit_title_white.9.png
deleted file mode 100644
index 19e8d95..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_title_white.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_title_yellow.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/edit_title_yellow.9.png
deleted file mode 100644
index bf8f580..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_title_yellow.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_white.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/edit_white.9.png
deleted file mode 100644
index 918f7a6..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_white.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_yellow.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/edit_yellow.9.png
deleted file mode 100644
index 10cb642..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/edit_yellow.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/font_large.png b/src/Notes-master/app/src/main/res/drawable-hdpi/font_large.png
deleted file mode 100644
index 78cf2e6..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/font_large.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/font_normal.png b/src/Notes-master/app/src/main/res/drawable-hdpi/font_normal.png
deleted file mode 100644
index 9de7ced..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/font_normal.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/font_size_selector_bg.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/font_size_selector_bg.9.png
deleted file mode 100644
index be8e64c..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/font_size_selector_bg.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/font_small.png b/src/Notes-master/app/src/main/res/drawable-hdpi/font_small.png
deleted file mode 100644
index d3ff104..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/font_small.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/font_super.png b/src/Notes-master/app/src/main/res/drawable-hdpi/font_super.png
deleted file mode 100644
index 85b13a1..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/font_super.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/icon_app.png b/src/Notes-master/app/src/main/res/drawable-hdpi/icon_app.png
deleted file mode 100644
index 418aadc..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/icon_app.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_background.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_background.png
deleted file mode 100644
index 087e1f9..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_background.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_blue_down.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_blue_down.9.png
deleted file mode 100644
index b88eebf..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_blue_down.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_blue_middle.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_blue_middle.9.png
deleted file mode 100644
index 96b1c8b..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_blue_middle.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_blue_single.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_blue_single.9.png
deleted file mode 100644
index d7e7206..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_blue_single.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_blue_up.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_blue_up.9.png
deleted file mode 100644
index 632e88c..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_blue_up.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_folder.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_folder.9.png
deleted file mode 100644
index 829f61b..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_folder.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_footer_bg.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_footer_bg.9.png
deleted file mode 100644
index 5325c25..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_footer_bg.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_green_down.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_green_down.9.png
deleted file mode 100644
index 64a39d9..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_green_down.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_green_middle.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_green_middle.9.png
deleted file mode 100644
index 897325a..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_green_middle.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_green_single.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_green_single.9.png
deleted file mode 100644
index c83405f..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_green_single.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_green_up.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_green_up.9.png
deleted file mode 100644
index 141f9e1..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_green_up.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_red_down.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_red_down.9.png
deleted file mode 100644
index 4224309..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_red_down.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_red_middle.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_red_middle.9.png
deleted file mode 100644
index 9988f17..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_red_middle.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_red_single.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_red_single.9.png
deleted file mode 100644
index 587c348..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_red_single.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_red_up.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_red_up.9.png
deleted file mode 100644
index 46b4757..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_red_up.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_white_down.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_white_down.9.png
deleted file mode 100644
index 29f9d8c..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_white_down.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_white_middle.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_white_middle.9.png
deleted file mode 100644
index 77a4ab4..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_white_middle.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_white_single.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_white_single.9.png
deleted file mode 100644
index 3e79189..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_white_single.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_white_up.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_white_up.9.png
deleted file mode 100644
index e23cd5c..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_white_up.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_yellow_down.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_yellow_down.9.png
deleted file mode 100644
index 31cfc1e..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_yellow_down.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_yellow_middle.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_yellow_middle.9.png
deleted file mode 100644
index b6549b2..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_yellow_middle.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_yellow_single.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_yellow_single.9.png
deleted file mode 100644
index 3faf507..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_yellow_single.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/list_yellow_up.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/list_yellow_up.9.png
deleted file mode 100644
index 4ae791c..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/list_yellow_up.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/menu_delete.png b/src/Notes-master/app/src/main/res/drawable-hdpi/menu_delete.png
deleted file mode 100644
index ccdfc4b..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/menu_delete.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/menu_move.png b/src/Notes-master/app/src/main/res/drawable-hdpi/menu_move.png
deleted file mode 100644
index 1140b71..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/menu_move.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/new_note_normal.png b/src/Notes-master/app/src/main/res/drawable-hdpi/new_note_normal.png
deleted file mode 100644
index e24e0d1..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/new_note_normal.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/new_note_pressed.png b/src/Notes-master/app/src/main/res/drawable-hdpi/new_note_pressed.png
deleted file mode 100644
index c748936..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/new_note_pressed.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/note_edit_color_selector_panel.png b/src/Notes-master/app/src/main/res/drawable-hdpi/note_edit_color_selector_panel.png
deleted file mode 100644
index fc49552..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/note_edit_color_selector_panel.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/notification.png b/src/Notes-master/app/src/main/res/drawable-hdpi/notification.png
deleted file mode 100644
index b13ab4a..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/notification.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/search_result.png b/src/Notes-master/app/src/main/res/drawable-hdpi/search_result.png
deleted file mode 100644
index ff2befd..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/search_result.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/selected.png b/src/Notes-master/app/src/main/res/drawable-hdpi/selected.png
deleted file mode 100644
index b889bef..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/selected.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/title_alert.png b/src/Notes-master/app/src/main/res/drawable-hdpi/title_alert.png
deleted file mode 100644
index 544ee9c..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/title_alert.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/title_bar_bg.9.png b/src/Notes-master/app/src/main/res/drawable-hdpi/title_bar_bg.9.png
deleted file mode 100644
index eb6bff0..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/title_bar_bg.9.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_2x_blue.png b/src/Notes-master/app/src/main/res/drawable-hdpi/widget_2x_blue.png
deleted file mode 100644
index a1707f4..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_2x_blue.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_2x_green.png b/src/Notes-master/app/src/main/res/drawable-hdpi/widget_2x_green.png
deleted file mode 100644
index f86886c..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_2x_green.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_2x_red.png b/src/Notes-master/app/src/main/res/drawable-hdpi/widget_2x_red.png
deleted file mode 100644
index 0e66c29..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_2x_red.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_2x_white.png b/src/Notes-master/app/src/main/res/drawable-hdpi/widget_2x_white.png
deleted file mode 100644
index 5f0619a..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_2x_white.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_2x_yellow.png b/src/Notes-master/app/src/main/res/drawable-hdpi/widget_2x_yellow.png
deleted file mode 100644
index 12d1c2b..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_2x_yellow.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_4x_blue.png b/src/Notes-master/app/src/main/res/drawable-hdpi/widget_4x_blue.png
deleted file mode 100644
index 9183738..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_4x_blue.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_4x_green.png b/src/Notes-master/app/src/main/res/drawable-hdpi/widget_4x_green.png
deleted file mode 100644
index fa8b452..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_4x_green.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_4x_red.png b/src/Notes-master/app/src/main/res/drawable-hdpi/widget_4x_red.png
deleted file mode 100644
index 62de074..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_4x_red.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_4x_white.png b/src/Notes-master/app/src/main/res/drawable-hdpi/widget_4x_white.png
deleted file mode 100644
index a37d67c..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_4x_white.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_4x_yellow.png b/src/Notes-master/app/src/main/res/drawable-hdpi/widget_4x_yellow.png
deleted file mode 100644
index d7c5fa4..0000000
Binary files a/src/Notes-master/app/src/main/res/drawable-hdpi/widget_4x_yellow.png and /dev/null differ
diff --git a/src/Notes-master/app/src/main/res/drawable/new_note.xml b/src/Notes-master/app/src/main/res/drawable/new_note.xml
deleted file mode 100644
index 2154ebc..0000000
--- a/src/Notes-master/app/src/main/res/drawable/new_note.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/src/Notes-master/app/src/main/res/layout/account_dialog_title.xml b/src/Notes-master/app/src/main/res/layout/account_dialog_title.xml
deleted file mode 100644
index 7717112..0000000
--- a/src/Notes-master/app/src/main/res/layout/account_dialog_title.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/layout/add_account_text.xml b/src/Notes-master/app/src/main/res/layout/add_account_text.xml
deleted file mode 100644
index c799178..0000000
--- a/src/Notes-master/app/src/main/res/layout/add_account_text.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/layout/datetime_picker.xml b/src/Notes-master/app/src/main/res/layout/datetime_picker.xml
deleted file mode 100644
index f10d592..0000000
--- a/src/Notes-master/app/src/main/res/layout/datetime_picker.xml
+++ /dev/null
@@ -1,56 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/layout/dialog_edit_text.xml b/src/Notes-master/app/src/main/res/layout/dialog_edit_text.xml
deleted file mode 100644
index 361b39a..0000000
--- a/src/Notes-master/app/src/main/res/layout/dialog_edit_text.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/layout/folder_list_item.xml b/src/Notes-master/app/src/main/res/layout/folder_list_item.xml
deleted file mode 100644
index 77e8148..0000000
--- a/src/Notes-master/app/src/main/res/layout/folder_list_item.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/layout/note_edit.xml b/src/Notes-master/app/src/main/res/layout/note_edit.xml
deleted file mode 100644
index 10b2aa7..0000000
--- a/src/Notes-master/app/src/main/res/layout/note_edit.xml
+++ /dev/null
@@ -1,400 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Notes-master/app/src/main/res/layout/note_edit_list_item.xml b/src/Notes-master/app/src/main/res/layout/note_edit_list_item.xml
deleted file mode 100644
index a885f9c..0000000
--- a/src/Notes-master/app/src/main/res/layout/note_edit_list_item.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Notes-master/app/src/main/res/layout/note_item.xml b/src/Notes-master/app/src/main/res/layout/note_item.xml
deleted file mode 100644
index d541f6a..0000000
--- a/src/Notes-master/app/src/main/res/layout/note_item.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Notes-master/app/src/main/res/layout/note_list.xml b/src/Notes-master/app/src/main/res/layout/note_list.xml
deleted file mode 100644
index 6b25d38..0000000
--- a/src/Notes-master/app/src/main/res/layout/note_list.xml
+++ /dev/null
@@ -1,58 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Notes-master/app/src/main/res/layout/note_list_dropdown_menu.xml b/src/Notes-master/app/src/main/res/layout/note_list_dropdown_menu.xml
deleted file mode 100644
index 3fa271d..0000000
--- a/src/Notes-master/app/src/main/res/layout/note_list_dropdown_menu.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/layout/note_list_footer.xml b/src/Notes-master/app/src/main/res/layout/note_list_footer.xml
deleted file mode 100644
index 5ca7b22..0000000
--- a/src/Notes-master/app/src/main/res/layout/note_list_footer.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/layout/settings_header.xml b/src/Notes-master/app/src/main/res/layout/settings_header.xml
deleted file mode 100644
index 5eb8c50..0000000
--- a/src/Notes-master/app/src/main/res/layout/settings_header.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/layout/widget_2x.xml b/src/Notes-master/app/src/main/res/layout/widget_2x.xml
deleted file mode 100644
index 55970ce..0000000
--- a/src/Notes-master/app/src/main/res/layout/widget_2x.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/src/Notes-master/app/src/main/res/layout/widget_4x.xml b/src/Notes-master/app/src/main/res/layout/widget_4x.xml
deleted file mode 100644
index dc9bb51..0000000
--- a/src/Notes-master/app/src/main/res/layout/widget_4x.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Notes-master/app/src/main/res/menu/call_note_edit.xml b/src/Notes-master/app/src/main/res/menu/call_note_edit.xml
deleted file mode 100644
index 02c0528..0000000
--- a/src/Notes-master/app/src/main/res/menu/call_note_edit.xml
+++ /dev/null
@@ -1,48 +0,0 @@
-
-
-
-
-
diff --git a/src/Notes-master/app/src/main/res/menu/call_record_folder.xml b/src/Notes-master/app/src/main/res/menu/call_record_folder.xml
deleted file mode 100644
index c664346..0000000
--- a/src/Notes-master/app/src/main/res/menu/call_record_folder.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
diff --git a/src/Notes-master/app/src/main/res/menu/note_edit.xml b/src/Notes-master/app/src/main/res/menu/note_edit.xml
deleted file mode 100644
index 35cacd1..0000000
--- a/src/Notes-master/app/src/main/res/menu/note_edit.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/menu/note_list.xml b/src/Notes-master/app/src/main/res/menu/note_list.xml
deleted file mode 100644
index 42ea736..0000000
--- a/src/Notes-master/app/src/main/res/menu/note_list.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-
-
-
-
-
diff --git a/src/Notes-master/app/src/main/res/menu/note_list_dropdown.xml b/src/Notes-master/app/src/main/res/menu/note_list_dropdown.xml
deleted file mode 100644
index 7cbaadc..0000000
--- a/src/Notes-master/app/src/main/res/menu/note_list_dropdown.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/menu/note_list_options.xml b/src/Notes-master/app/src/main/res/menu/note_list_options.xml
deleted file mode 100644
index daac008..0000000
--- a/src/Notes-master/app/src/main/res/menu/note_list_options.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/menu/sub_folder.xml b/src/Notes-master/app/src/main/res/menu/sub_folder.xml
deleted file mode 100644
index b00de26..0000000
--- a/src/Notes-master/app/src/main/res/menu/sub_folder.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/raw-zh-rCN/introduction b/src/Notes-master/app/src/main/res/raw-zh-rCN/introduction
deleted file mode 100644
index 7188359..0000000
--- a/src/Notes-master/app/src/main/res/raw-zh-rCN/introduction
+++ /dev/null
@@ -1,7 +0,0 @@
-欢迎使用MIUI便签!
-
- 无论从软件中直接添加,还是从桌面拖出widget,MIUI便签能让你快速建立和保存便签;
-
- 除了调整文字大小、便签背景、文件夹等基础功能外,你会发现MIUI便签也提供了清单模式、便签提醒、软件加密、导出到SD卡、同步google task的高级功能,让你的生活记录更加美好和安全;
-
- 来分享你的使用体验吧:http://www.miui.com/index.php
diff --git a/src/Notes-master/app/src/main/res/raw/introduction b/src/Notes-master/app/src/main/res/raw/introduction
deleted file mode 100644
index 269cf7b..0000000
--- a/src/Notes-master/app/src/main/res/raw/introduction
+++ /dev/null
@@ -1 +0,0 @@
-Welcome to use MIUI notes!
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/values-zh-rCN/arrays.xml b/src/Notes-master/app/src/main/res/values-zh-rCN/arrays.xml
deleted file mode 100644
index a092386..0000000
--- a/src/Notes-master/app/src/main/res/values-zh-rCN/arrays.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
- - 短信
- - 邮件
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/values-zh-rCN/strings.xml b/src/Notes-master/app/src/main/res/values-zh-rCN/strings.xml
deleted file mode 100644
index 09f75ed..0000000
--- a/src/Notes-master/app/src/main/res/values-zh-rCN/strings.xml
+++ /dev/null
@@ -1,126 +0,0 @@
-
-
-
-
-
- 便签
- 便签2x2
- 便签4x4
- 没有关联内容,点击新建便签。
- 访客模式下,便签内容不可见
- ...
- 新建便签
- 成功删除提醒
- 创建提醒
- 已过期
- yyyyMMdd
- MM月dd日 kk:mm
- 知道了
- 查看
- 呼叫电话
- 发送邮件
- 浏览网页
- 打开地图
-
- 新建文件夹
- 导出文本
- 同步
- 取消同步
- 设置
- 搜索
- 删除
- 移动到文件夹
- 选中了 %d 项
- 没有选中项,操作无效
- 全选
- 取消全选
- 文字大小
- 小
- 正常
- 大
- 超大
- 进入清单模式
- 退出清单模式
- 查看文件夹
- 刪除文件夹
- 修改文件夹名称
- 文件夹 %1$s 已存在,请重新命名
- 分享
- 发送到桌面
- 提醒我
- 删除提醒
- 选择文件夹
- 上一级文件夹
- 已添加到桌面
- 删除
- 确认要删除所选的 %d 条便签吗?
- 确认要删除该条便签吗?
- 确认删除文件夹及所包含的便签吗?
- 已将所选 %1$d 条便签移到 %2$s 文件夹
-
- SD卡被占用,不能操作
- 导出文本时发生错误,请检查SD卡
- 要查看的便签不存在
- 不能为空便签设置闹钟提醒
- 不能将空便签发送到桌面
- 导出成功
- 导出失败
- 已将文本文件(%1$s)输出至SD卡(%2$s)目录
-
- 同步便签...
- 同步成功
- 同步失败
- 同步已取消
- 与%1$s同步成功
- 同步失败,请检查网络和帐号设置
- 同步失败,发生内部错误
- 同步已取消
- 登录%1$s...
- 正在获取服务器便签列表...
- 正在同步本地便签...
-
- 设置
- 同步账号
- 与google task同步便签记录
- 上次同步于 %1$s
- 添加账号
- 更换账号
- 删除账号
- 取消
- 立即同步
- 取消同步
- 当前帐号 %1$s
- 如更换同步帐号,过去的帐号同步信息将被清空,再次切换的同时可能会造成数据重复
- 同步便签
- 请选择google帐号,便签将与该帐号的google task内容同步。
- 正在同步中,不能修改同步帐号
- 同步帐号已设置为%1$s
- 新建便签背景颜色随机
- 删除
- 通话便签
- 请输入名称
- 正在搜索便签
- 搜索便签
- 便签中的文字
- 便签
- 设置
- 取消
-
- - %1$s 条符合“%2$s”的搜索结果
-
-
-
diff --git a/src/Notes-master/app/src/main/res/values-zh-rTW/arrays.xml b/src/Notes-master/app/src/main/res/values-zh-rTW/arrays.xml
deleted file mode 100644
index 5297209..0000000
--- a/src/Notes-master/app/src/main/res/values-zh-rTW/arrays.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
- - 短信
- - 郵件
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/values-zh-rTW/strings.xml b/src/Notes-master/app/src/main/res/values-zh-rTW/strings.xml
deleted file mode 100644
index 3c41894..0000000
--- a/src/Notes-master/app/src/main/res/values-zh-rTW/strings.xml
+++ /dev/null
@@ -1,127 +0,0 @@
-
-
-
-
-
- 便簽
- 便簽2x2
- 便簽4x4
- 沒有關聯內容,點擊新建便簽。
- 訪客模式下,便籤內容不可見
- ...
- 新建便簽
- 成功刪除提醒
- 創建提醒
- 已過期
- yyyyMMdd
- MM月dd日 kk:mm
- 知道了
- 查看
- 呼叫電話
- 發送郵件
- 浏覽網頁
- 打開地圖
- 已將所選 %1$d 便籤移到 %2$s 文件夾
-
- 新建文件夾
- 導出文本
- 同步
- 取消同步
- 設置
- 搜尋
- 刪除
- 移動到文件夾
- 選中了 %d 項
- 沒有選中項,操作無效
- 全選
- 取消全選
- 文字大小
- 小
- 正常
- 大
- 超大
- 進入清單模式
- 退出清單模式
- 查看文件夾
- 刪除文件夾
- 修改文件夾名稱
- 文件夾 %1$s 已存在,請重新命名
- 分享
- 發送到桌面
- 提醒我
- 刪除提醒
- 選擇文件夾
- 上一級文件夾
- 已添加到桌面
- 刪除
- 确认要刪除所選的 %d 條便籤嗎?
- 确认要删除該條便籤嗎?
- 確認刪除檔夾及所包含的便簽嗎?
- SD卡被佔用,不能操作
- 導出TXT時發生錯誤,請檢查SD卡
- 要查看的便籤不存在
- 不能爲空便籤設置鬧鐘提醒
- 不能將空便籤發送到桌面
- 導出成功
- 導出失敗
- 已將文本文件(%1$s)導出至SD(%2$s)目錄
-
- 同步便簽...
- 同步成功
- 同步失敗
- 同步已取消
- 與%1$s同步成功
- 同步失敗,請檢查網絡和帳號設置
- 同步失敗,發生內部錯誤
- 同步已取消
- 登陸%1$s...
- 正在獲取服務器便籤列表...
- 正在同步本地便籤...
-
- 設置
- 同步賬號
- 与google task同步便簽記錄
- 上次同步于 %1$s
- 添加賬號
- 更換賬號
- 刪除賬號
- 取消
- 立即同步
- 取消同步
- 當前帳號 %1$s
- 如更換同步帳號,過去的帳號同步信息將被清空,再次切換的同時可能會造成數據重復
- 同步便簽
- 請選擇google帳號,便簽將與該帳號的google task內容同步。
- 正在同步中,不能修改同步帳號
- 同步帳號已設置為%1$s
- 新建便籤背景顏色隨機
-
- 刪除
- 通話便籤
- 請輸入名稱
-
- 正在搜索便籤
- 搜索便籤
- 便籤中的文字
- 便籤
- 設置
- 取消
-
- - %1$s 條符合”%2$s“的搜尋結果
-
-
-
diff --git a/src/Notes-master/app/src/main/res/values/arrays.xml b/src/Notes-master/app/src/main/res/values/arrays.xml
deleted file mode 100644
index e00210b..0000000
--- a/src/Notes-master/app/src/main/res/values/arrays.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
-
-
-
- - -%s
- - --%s
- - --%s
- - --%s
-
-
-
- - Messaging
- - Email
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/values/colors.xml b/src/Notes-master/app/src/main/res/values/colors.xml
deleted file mode 100644
index 123ffbf..0000000
--- a/src/Notes-master/app/src/main/res/values/colors.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
- #335b5b5b
-
diff --git a/src/Notes-master/app/src/main/res/values/dimens.xml b/src/Notes-master/app/src/main/res/values/dimens.xml
deleted file mode 100644
index 194e84f..0000000
--- a/src/Notes-master/app/src/main/res/values/dimens.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
- 33sp
- 26sp
- 20sp
- 17sp
- 14sp
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/values/strings.xml b/src/Notes-master/app/src/main/res/values/strings.xml
deleted file mode 100644
index 3c17d1b..0000000
--- a/src/Notes-master/app/src/main/res/values/strings.xml
+++ /dev/null
@@ -1,136 +0,0 @@
-
-
-
-
-
- Notes
- 便签同步通知
- Notes 2x2
- Notes 4x4
- No associated note found, click to create associated note.
- Privacy mode,can not see note content
- ...
- Add note
- Delete reminder successfully
- Set reminder
- Expired
- yyyyMMdd
- MMMd kk:mm
- Got it
- Take a look
- Call
- Send email
- Browse web
- Open map
-
- /MIUI/notes/
- notes_%s.txt
-
- (%d)
- New Folder
- Export text
- Sync
- Cancel syncing
- Settings
- Search
- Delete
- Move to folder
- %d selected
- Nothing selected, the operation is invalid
- Select all
- Deselect all
- Font size
- Small
- Medium
- Large
- Super
- Enter check list
- Leave check list
- View folder
- Delete folder
- Change folder name
- The folder %1$s exist, please rename
- Share
- Send to home
- Remind me
- Delete reminder
- Select folder
- Parent folder
- Note added to home
- Confirm to delete folder and its notes?
- Delete selected notes
- Confirm to delete the selected %d notes?
- Confirm to delete this note?
- Have moved selected %1$d notes to %2$s folder
-
- SD card busy, not available now
- Export failed, please check SD card
- The note is not exist
- Sorry, can not set clock on empty note
- Sorry, can not send and empty note to home
- Export successful
- Export fail
- Export text file (%1$s) to SD (%2$s) directory
-
- Syncing notes...
- Sync is successful
- Sync is failed
- Sync is canceled
- Sync is successful with account %1$s
- Sync failed, please check network and account settings
- Sync failed, internal error occurs
- Sync is canceled
- Logging into %1$s...
- Getting remote note list...
- Synchronize local notes with Google Task...
-
- Settings
- Sync account
- Sync notes with google task
- Last sync time %1$s
- yyyy-MM-dd hh:mm:ss
- Add account
- Change sync account
- Remove sync account
- Cancel
- Sync immediately
- Cancel syncing
- Current account %1$s
- All sync related information will be deleted, which may result in duplicated items sometime
- Sync notes
- Please select a google account. Local notes will be synced with google task.
- Cannot change the account because sync is in progress
- %1$s has been set as the sync account
- New note background color random
-
- Delete
- Call notes
- Input name
-
- Searching Notes
- Search notes
- Text in your notes
- Notes
- set
- cancel
-
- - %1$s result for \"%2$s\"
-
- - %1$s results for \"%2$s\"
-
-
-
diff --git a/src/Notes-master/app/src/main/res/values/styles.xml b/src/Notes-master/app/src/main/res/values/styles.xml
deleted file mode 100644
index 941db71..0000000
--- a/src/Notes-master/app/src/main/res/values/styles.xml
+++ /dev/null
@@ -1,68 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notes-master/app/src/main/res/xml/preferences.xml b/src/Notes-master/app/src/main/res/xml/preferences.xml
deleted file mode 100644
index fe58f8f..0000000
--- a/src/Notes-master/app/src/main/res/xml/preferences.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Notes-master/app/src/main/res/xml/searchable.xml b/src/Notes-master/app/src/main/res/xml/searchable.xml
deleted file mode 100644
index bf74f14..0000000
--- a/src/Notes-master/app/src/main/res/xml/searchable.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
diff --git a/src/Notes-master/app/src/main/res/xml/widget_2x_info.xml b/src/Notes-master/app/src/main/res/xml/widget_2x_info.xml
deleted file mode 100644
index ac8b225..0000000
--- a/src/Notes-master/app/src/main/res/xml/widget_2x_info.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
diff --git a/src/Notes-master/app/src/main/res/xml/widget_4x_info.xml b/src/Notes-master/app/src/main/res/xml/widget_4x_info.xml
deleted file mode 100644
index cf79f9c..0000000
--- a/src/Notes-master/app/src/main/res/xml/widget_4x_info.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-