合并黄志祥的分支

合并黄志祥的分支
master
pwlfzbeg4 2 years ago
commit 0ce0499372

@ -1 +0,0 @@
Subproject commit d48acec0b0cae90d95d289c02545fcac5e7a1485

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Classdiagram><settings><option name="paintImplements" value="true" /><option name="paintDepends" value="true" /><option name="layoutOnChanges" value="false" /><option name="paintUses" value="true" /><option name="paintInner" value="true" /><option name="paintExtends" value="true" /></settings><classes><class name="net.micode.notes.data.NotesProvider" x="192" y="32"><option name="pinned" value="false" /><option name="fieldsExpanded" value="false" /><option name="constructorsExpanded" value="false" /><option name="methodsExpanded" value="false" /></class><class name="net.micode.notes.data.NotesDatabaseHelper" x="144" y="141"><option name="pinned" value="false" /><option name="fieldsExpanded" value="false" /><option name="constructorsExpanded" value="false" /><option name="methodsExpanded" value="false" /></class><class name="net.micode.notes.data.Contact" x="34" y="207"><option name="pinned" value="false" /><option name="fieldsExpanded" value="false" /><option name="constructorsExpanded" value="false" /><option name="methodsExpanded" value="false" /></class><class name="net.micode.notes.data.Notes" x="28" y="15"><option name="pinned" value="false" /><option name="fieldsExpanded" value="false" /><option name="constructorsExpanded" value="false" /><option name="methodsExpanded" value="false" /></class></classes><stickycomponents /><textcomponents /><connectors><connector from="net.micode.notes.data.NotesProvider" to="net.micode.notes.data.NotesDatabaseHelper"><anchor constraint="1" type="2" x="292" y="103" /><anchor constraint="1" type="2" x="285" y="141" /><decorator type="4" description="- mHelper" /></connector><connector from="net.micode.notes.data.NotesDatabaseHelper" to="net.micode.notes.data.NotesDatabaseHelper"><anchor constraint="1" type="2" x="376" y="212" /><anchor constraint="1" type="1" x="376" y="237" /><anchor constraint="1" type="1" x="422" y="237" /><anchor constraint="1" type="1" x="422" y="176" /><anchor constraint="1" type="2" x="412" y="176" /><decorator type="4" description="- mInstance" /></connector></connectors></Classdiagram>

@ -25,8 +25,14 @@ import android.util.Log;
import java.util.HashMap; import java.util.HashMap;
/**
* @author hzx
* 1.0
* 2023/10/28
* Contact
*/
public class Contact { public class Contact {
private static HashMap<String, String> sContactCache; private static HashMap<String, String> sContactCache; // 缓存联系人号码和姓名的映射关系
private static final String TAG = "Contact"; private static final String TAG = "Contact";
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
@ -34,19 +40,29 @@ public class Contact {
+ " AND " + Data.RAW_CONTACT_ID + " IN " + " AND " + Data.RAW_CONTACT_ID + " IN "
+ "(SELECT raw_contact_id " + "(SELECT raw_contact_id "
+ " FROM phone_lookup" + " FROM phone_lookup"
+ " WHERE min_match = '+')"; + " WHERE min_match = '+')"; // 查询条件
/**
*
* @param context
* @param phoneNumber
* @return
*/
public static String getContact(Context context, String phoneNumber) { public static String getContact(Context context, String phoneNumber) {
if(sContactCache == null) { if(sContactCache == null) {
// 初始化map缓存
sContactCache = new HashMap<String, String>(); sContactCache = new HashMap<String, String>();
} }
if(sContactCache.containsKey(phoneNumber)) { if(sContactCache.containsKey(phoneNumber)) {
// 如果map缓存中的键包含要查询的电话号码直接从缓存中读取
return sContactCache.get(phoneNumber); return sContactCache.get(phoneNumber);
} }
// 获取电话号码的min-match然后替换原始查询条件中的“+”
String selection = CALLER_ID_SELECTION.replace("+", String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
// 从联系人内容提供者中查询联系人信息
Cursor cursor = context.getContentResolver().query( Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI, Data.CONTENT_URI,
new String [] { Phone.DISPLAY_NAME }, new String [] { Phone.DISPLAY_NAME },
@ -54,18 +70,22 @@ public class Contact {
new String[] { phoneNumber }, new String[] { phoneNumber },
null); null);
// 读取查询结果
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
try { try {
String name = cursor.getString(0); String name = cursor.getString(0);
// 将这次电话号码和联系人姓名的匹配关系缓存起来
sContactCache.put(phoneNumber, name); sContactCache.put(phoneNumber, name);
return name; return name;
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
// 数组越界异常从cursor取不到指定字段输出日志信息
Log.e(TAG, " Cursor get string error " + e.toString()); Log.e(TAG, " Cursor get string error " + e.toString());
return null; return null;
} finally { } finally {
cursor.close(); cursor.close();
} }
} else { } else {
// 查询结果为空,输出日志信息
Log.d(TAG, "No contact matched with number:" + phoneNumber); Log.d(TAG, "No contact matched with number:" + phoneNumber);
return null; return null;
} }

@ -17,11 +17,21 @@
package net.micode.notes.data; package net.micode.notes.data;
import android.net.Uri; import android.net.Uri;
/**
* @author hzx
* 1.0
* 2023/10/28
* Notes 便便
*/
public class Notes { public class Notes {
public static final String AUTHORITY = "micode_notes"; public static final String AUTHORITY = "micode_notes";
public static final String TAG = "Notes"; public static final String TAG = "Notes";
// 便签标识
public static final int TYPE_NOTE = 0; public static final int TYPE_NOTE = 0;
// 文件夹标识
public static final int TYPE_FOLDER = 1; public static final int TYPE_FOLDER = 1;
// 系统文件夹标识
public static final int TYPE_SYSTEM = 2; public static final int TYPE_SYSTEM = 2;
/** /**
@ -30,9 +40,13 @@ public class Notes {
* {@link Notes#ID_TEMPARAY_FOLDER } is for notes belonging no folder * {@link Notes#ID_TEMPARAY_FOLDER } is for notes belonging no folder
* {@link Notes#ID_CALL_RECORD_FOLDER} is to store call records * {@link Notes#ID_CALL_RECORD_FOLDER} is to store call records
*/ */
// 根文件夹标识
public static final int ID_ROOT_FOLDER = 0; public static final int ID_ROOT_FOLDER = 0;
// 临时文件夹标识
public static final int ID_TEMPARAY_FOLDER = -1; public static final int ID_TEMPARAY_FOLDER = -1;
// 调用记录文件夹标识
public static final int ID_CALL_RECORD_FOLDER = -2; public static final int ID_CALL_RECORD_FOLDER = -2;
// 垃圾文件夹(回收站)标识
public static final int ID_TRASH_FOLER = -3; public static final int ID_TRASH_FOLER = -3;
public static final String INTENT_EXTRA_ALERT_DATE = "net.micode.notes.alert_date"; public static final String INTENT_EXTRA_ALERT_DATE = "net.micode.notes.alert_date";
@ -42,46 +56,56 @@ public class Notes {
public static final String INTENT_EXTRA_FOLDER_ID = "net.micode.notes.folder_id"; public static final String INTENT_EXTRA_FOLDER_ID = "net.micode.notes.folder_id";
public static final String INTENT_EXTRA_CALL_DATE = "net.micode.notes.call_date"; public static final String INTENT_EXTRA_CALL_DATE = "net.micode.notes.call_date";
// 小部件类型
public static final int TYPE_WIDGET_INVALIDE = -1; public static final int TYPE_WIDGET_INVALIDE = -1;
public static final int TYPE_WIDGET_2X = 0; public static final int TYPE_WIDGET_2X = 0;
public static final int TYPE_WIDGET_4X = 1; public static final int TYPE_WIDGET_4X = 1;
/**
*
*/
public static class DataConstants { public static class DataConstants {
public static final String NOTE = TextNote.CONTENT_ITEM_TYPE; public static final String NOTE = TextNote.CONTENT_ITEM_TYPE;
public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE; public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE;
} }
/** /**
* Uri to query all notes and folders * 便Uri
*/ */
public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note"); public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note");
/** /**
* Uri to query data * Uri
*/ */
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data"); public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
/**
* 便
*/
public interface NoteColumns { public interface NoteColumns {
/** /**
* The unique ID for a row * ID
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
public static final String ID = "_id"; public static final String ID = "_id";
/** /**
* The parent's id for note or folder * The parent's id for note or folder
* 便ID
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
public static final String PARENT_ID = "parent_id"; public static final String PARENT_ID = "parent_id";
/** /**
* Created data for note or folder * Created data for note or folder
* 便
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
public static final String CREATED_DATE = "created_date"; public static final String CREATED_DATE = "created_date";
/** /**
* Latest modified date * Latest modified date
*
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
public static final String MODIFIED_DATE = "modified_date"; public static final String MODIFIED_DATE = "modified_date";
@ -95,24 +119,28 @@ public class Notes {
/** /**
* Folder's name or text content of note * Folder's name or text content of note
* 便
* <P> Type: TEXT </P> * <P> Type: TEXT </P>
*/ */
public static final String SNIPPET = "snippet"; public static final String SNIPPET = "snippet";
/** /**
* Note's widget id * Note's widget id
* 便ID
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
public static final String WIDGET_ID = "widget_id"; public static final String WIDGET_ID = "widget_id";
/** /**
* Note's widget type * Note's widget type
* 便
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
public static final String WIDGET_TYPE = "widget_type"; public static final String WIDGET_TYPE = "widget_type";
/** /**
* Note's background color's id * Note's background color's id
* 便ID
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
public static final String BG_COLOR_ID = "bg_color_id"; public static final String BG_COLOR_ID = "bg_color_id";
@ -120,127 +148,149 @@ public class Notes {
/** /**
* For text note, it doesn't has attachment, for multi-media * For text note, it doesn't has attachment, for multi-media
* note, it has at least one attachment * note, it has at least one attachment
*
* <P> Type: INTEGER </P> * <P> Type: INTEGER </P>
*/ */
public static final String HAS_ATTACHMENT = "has_attachment"; public static final String HAS_ATTACHMENT = "has_attachment";
/** /**
* Folder's count of notes * Folder's count of notes
* 便
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
public static final String NOTES_COUNT = "notes_count"; public static final String NOTES_COUNT = "notes_count";
/** /**
* The file type: folder or note * The file type: folder or note
* 便
* <P> Type: INTEGER </P> * <P> Type: INTEGER </P>
*/ */
public static final String TYPE = "type"; public static final String TYPE = "type";
/** /**
* The last sync id * The last sync id
* ID
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
public static final String SYNC_ID = "sync_id"; public static final String SYNC_ID = "sync_id";
/** /**
* Sign to indicate local modified or not * Sign to indicate local modified or not
*
* <P> Type: INTEGER </P> * <P> Type: INTEGER </P>
*/ */
public static final String LOCAL_MODIFIED = "local_modified"; public static final String LOCAL_MODIFIED = "local_modified";
/** /**
* Original parent id before moving into temporary folder * Original parent id before moving into temporary folder
* 便ID
* <P> Type : INTEGER </P> * <P> Type : INTEGER </P>
*/ */
public static final String ORIGIN_PARENT_ID = "origin_parent_id"; public static final String ORIGIN_PARENT_ID = "origin_parent_id";
/** /**
* The gtask id * The gtask id
* ID
* <P> Type : TEXT </P> * <P> Type : TEXT </P>
*/ */
public static final String GTASK_ID = "gtask_id"; public static final String GTASK_ID = "gtask_id";
/** /**
* The version code * The version code
*
* <P> Type : INTEGER (long) </P> * <P> Type : INTEGER (long) </P>
*/ */
public static final String VERSION = "version"; public static final String VERSION = "version";
} }
/**
*
*/
public interface DataColumns { public interface DataColumns {
/** /**
* The unique ID for a row * The unique ID for a row
* ID
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
public static final String ID = "_id"; public static final String ID = "_id";
/** /**
* The MIME type of the item represented by this row. * The MIME type of the item represented by this row.
* MIME
* <P> Type: Text </P> * <P> Type: Text </P>
*/ */
public static final String MIME_TYPE = "mime_type"; public static final String MIME_TYPE = "mime_type";
/** /**
* The reference id to note that this data belongs to * The reference id to note that this data belongs to
* 便ID
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
public static final String NOTE_ID = "note_id"; public static final String NOTE_ID = "note_id";
/** /**
* Created data for note or folder * Created data for note or folder
*
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
public static final String CREATED_DATE = "created_date"; public static final String CREATED_DATE = "created_date";
/** /**
* Latest modified date * Latest modified date
*
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
public static final String MODIFIED_DATE = "modified_date"; public static final String MODIFIED_DATE = "modified_date";
/** /**
* Data's content * Data's content
*
* <P> Type: TEXT </P> * <P> Type: TEXT </P>
*/ */
public static final String CONTENT = "content"; public static final String CONTENT = "content";
/** /**
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for * Generic data column, the meaning is {@link #MIME_TYPE} specific, used for
* integer data type * integer data type
*
* <P> Type: INTEGER </P> * <P> Type: INTEGER </P>
*/ */
public static final String DATA1 = "data1"; public static final String DATA1 = "data1";
/** /**
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for * Generic data column, the meaning is {@link #MIME_TYPE} specific, used for
* integer data type * integer data type
* <P> Type: INTEGER </P> * <P> Type: INTEGER </P>
*/ */
public static final String DATA2 = "data2"; public static final String DATA2 = "data2";
/** /**
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for * Generic data column, the meaning is {@link #MIME_TYPE} specific, used for
* TEXT data type * TEXT data type
*
* <P> Type: TEXT </P> * <P> Type: TEXT </P>
*/ */
public static final String DATA3 = "data3"; public static final String DATA3 = "data3";
/** /**
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for * Generic data column, the meaning is {@link #MIME_TYPE} specific, used for
* TEXT data type * TEXT data type
* <P> Type: TEXT </P> * <P> Type: TEXT </P>
*/ */
public static final String DATA4 = "data4"; public static final String DATA4 = "data4";
/** /**
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for * Generic data column, the meaning is {@link #MIME_TYPE} specific, used for
* TEXT data type * TEXT data type
* <P> Type: TEXT </P> * <P> Type: TEXT </P>
*/ */
public static final String DATA5 = "data5"; public static final String DATA5 = "data5";
} }
/**
* 便
*/
public static final class TextNote implements DataColumns { public static final class TextNote implements DataColumns {
/** /**
* Mode to indicate the text in check list mode or not * Mode to indicate the text in check list mode or not
@ -250,16 +300,29 @@ public class Notes {
public static final int MODE_CHECK_LIST = 1; public static final int MODE_CHECK_LIST = 1;
/**
*
*/
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note"; 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"; 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"); public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");
} }
/**
*
*/
public static final class CallNote implements DataColumns { public static final class CallNote implements DataColumns {
/** /**
* Call date for this record * Call date for this record
*
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
public static final String CALL_DATE = DATA1; public static final String CALL_DATE = DATA1;
@ -270,10 +333,19 @@ public class Notes {
*/ */
public static final String PHONE_NUMBER = DATA3; public static final String PHONE_NUMBER = DATA3;
/**
*
*/
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note"; 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"; 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"); public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note");
} }
} }

@ -26,22 +26,35 @@ import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.DataConstants; import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.NoteColumns;
/**
* @author hzx
* 1.0
* 2023/10/28
* NotesDatabaseHelper 便
*
*/
public class NotesDatabaseHelper extends SQLiteOpenHelper { public class NotesDatabaseHelper extends SQLiteOpenHelper {
// 数据库名称
private static final String DB_NAME = "note.db"; private static final String DB_NAME = "note.db";
// 数据库版本
private static final int DB_VERSION = 4; private static final int DB_VERSION = 4;
// 数据库中的表名接口
public interface TABLE { public interface TABLE {
// 便签表
public static final String NOTE = "note"; public static final String NOTE = "note";
// 数据表
public static final String DATA = "data"; public static final String DATA = "data";
} }
private static final String TAG = "NotesDatabaseHelper"; private static final String TAG = "NotesDatabaseHelper";
// 实例
private static NotesDatabaseHelper mInstance; private static NotesDatabaseHelper mInstance;
// 创建便签表的SQL语句字符串常量
private static final String CREATE_NOTE_TABLE_SQL = private static final String CREATE_NOTE_TABLE_SQL =
"CREATE TABLE " + TABLE.NOTE + "(" + "CREATE TABLE " + TABLE.NOTE + "(" +
NoteColumns.ID + " INTEGER PRIMARY KEY," + NoteColumns.ID + " INTEGER PRIMARY KEY," +
@ -63,6 +76,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" + NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +
")"; ")";
// 创建数据表的SQL语句字符串常量
private static final String CREATE_DATA_TABLE_SQL = private static final String CREATE_DATA_TABLE_SQL =
"CREATE TABLE " + TABLE.DATA + "(" + "CREATE TABLE " + TABLE.DATA + "(" +
DataColumns.ID + " INTEGER PRIMARY KEY," + DataColumns.ID + " INTEGER PRIMARY KEY," +
@ -78,6 +92,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" + DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +
")"; ")";
// 给数据表中的便签ID字段创建索引的SQL语句字符串常量
private static final String CREATE_DATA_NOTE_ID_INDEX_SQL = private static final String CREATE_DATA_NOTE_ID_INDEX_SQL =
"CREATE INDEX IF NOT EXISTS note_id_index ON " + "CREATE INDEX IF NOT EXISTS note_id_index ON " +
TABLE.DATA + "(" + DataColumns.NOTE_ID + ");"; TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";
@ -85,6 +100,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/** /**
* Increase folder's note count when move note to the folder * Increase folder's note count when move note to the folder
*/ */
// 创建触发器的SQL语句当便签的父ID改变时也就是将便签移动到新的文件夹里将该文件夹的便签数量字段值加1
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER = private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_update "+ "CREATE TRIGGER increase_folder_count_on_update "+
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE + " AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
@ -97,6 +113,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/** /**
* Decrease folder's note count when move note from folder * Decrease folder's note count when move note from folder
*/ */
// 创建触发器的SQL语句把便签从文件夹里移走该文件夹的便签数量字段值减1
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER = private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_update " + "CREATE TRIGGER decrease_folder_count_on_update " +
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE + " AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
@ -110,6 +127,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/** /**
* Increase folder's note count when insert new note to the folder * Increase folder's note count when insert new note to the folder
*/ */
// 创建触发器的SQL语句该触发器处理当创建新的便签时增加便签所处文件夹中便签的数量
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER = private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_insert " + "CREATE TRIGGER increase_folder_count_on_insert " +
" AFTER INSERT ON " + TABLE.NOTE + " AFTER INSERT ON " + TABLE.NOTE +
@ -122,6 +140,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/** /**
* Decrease folder's note count when delete note from the folder * Decrease folder's note count when delete note from the folder
*/ */
// 创建触发器的SQL语句该触发器处理当删除便签时减少对应文件夹便签数量
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER = private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_delete " + "CREATE TRIGGER decrease_folder_count_on_delete " +
" AFTER DELETE ON " + TABLE.NOTE + " AFTER DELETE ON " + TABLE.NOTE +
@ -135,6 +154,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/** /**
* Update note's content when insert data with type {@link DataConstants#NOTE} * Update note's content when insert data with type {@link DataConstants#NOTE}
*/ */
// 创建触发器的SQL语句该触发器处理当插入新文本数据时便签的文本内容进行更新
private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER = private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER =
"CREATE TRIGGER update_note_content_on_insert " + "CREATE TRIGGER update_note_content_on_insert " +
" AFTER INSERT ON " + TABLE.DATA + " AFTER INSERT ON " + TABLE.DATA +
@ -148,6 +168,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/** /**
* Update note's content when data with {@link DataConstants#NOTE} type has changed * Update note's content when data with {@link DataConstants#NOTE} type has changed
*/ */
// 创建触发器的SQL语句该触发器处理当更新数据表中的文本数据时便签表中对应的便签内容进行更新
private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER = private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER update_note_content_on_update " + "CREATE TRIGGER update_note_content_on_update " +
" AFTER UPDATE ON " + TABLE.DATA + " AFTER UPDATE ON " + TABLE.DATA +
@ -161,6 +182,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/** /**
* Update note's content when data with {@link DataConstants#NOTE} type has deleted * Update note's content when data with {@link DataConstants#NOTE} type has deleted
*/ */
// 创建触发器的SQL语句数据表中的记录被删除时触发便签表的更新
private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER = private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER =
"CREATE TRIGGER update_note_content_on_delete " + "CREATE TRIGGER update_note_content_on_delete " +
" AFTER delete ON " + TABLE.DATA + " AFTER delete ON " + TABLE.DATA +
@ -174,6 +196,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/** /**
* Delete datas belong to note which has been deleted * Delete datas belong to note which has been deleted
*/ */
// 创建触发器的SQL语句便签表的记录被删除时触发数据表对应记录的删除
private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER = private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER =
"CREATE TRIGGER delete_data_on_delete " + "CREATE TRIGGER delete_data_on_delete " +
" AFTER DELETE ON " + TABLE.NOTE + " AFTER DELETE ON " + TABLE.NOTE +
@ -185,6 +208,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/** /**
* Delete notes belong to folder which has been deleted * Delete notes belong to folder which has been deleted
*/ */
// 创建触发器的SQL语句当文件夹被删除时它所包含的所有便签也被删除
private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER = private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER =
"CREATE TRIGGER folder_delete_notes_on_delete " + "CREATE TRIGGER folder_delete_notes_on_delete " +
" AFTER DELETE ON " + TABLE.NOTE + " AFTER DELETE ON " + TABLE.NOTE +
@ -196,6 +220,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/** /**
* Move notes belong to folder which has been moved to trash folder * Move notes belong to folder which has been moved to trash folder
*/ */
// 创建触发器的SQL语句当某文件夹被移入垃圾文件夹中时其包含的便签或文件夹也被移入垃圾文件夹中
private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER = private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER =
"CREATE TRIGGER folder_move_notes_on_trash " + "CREATE TRIGGER folder_move_notes_on_trash " +
" AFTER UPDATE ON " + TABLE.NOTE + " AFTER UPDATE ON " + TABLE.NOTE +
@ -207,17 +232,30 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END"; " END";
public NotesDatabaseHelper(Context context) { public NotesDatabaseHelper(Context context) {
// 初始化数据库
super(context, DB_NAME, null, DB_VERSION); super(context, DB_NAME, null, DB_VERSION);
} }
/**
* 便
* @param db
*/
public void createNoteTable(SQLiteDatabase db) { public void createNoteTable(SQLiteDatabase db) {
// 执行建表SQL语句创建便签表
db.execSQL(CREATE_NOTE_TABLE_SQL); db.execSQL(CREATE_NOTE_TABLE_SQL);
// 初始化创建便签表触发器
reCreateNoteTableTriggers(db); reCreateNoteTableTriggers(db);
// 创建系统文件夹
createSystemFolder(db); createSystemFolder(db);
Log.d(TAG, "note table has been created"); Log.d(TAG, "note table has been created");
} }
/**
* 便
* @param db
*/
private void reCreateNoteTableTriggers(SQLiteDatabase db) { private void reCreateNoteTableTriggers(SQLiteDatabase db) {
// 当要创建的便签表触发器存在时,删除该触发器
db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update"); 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_update");
db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_delete"); db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_delete");
@ -226,6 +264,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL("DROP TRIGGER IF EXISTS folder_delete_notes_on_delete"); db.execSQL("DROP TRIGGER IF EXISTS folder_delete_notes_on_delete");
db.execSQL("DROP TRIGGER IF EXISTS folder_move_notes_on_trash"); db.execSQL("DROP TRIGGER IF EXISTS folder_move_notes_on_trash");
// 重新创建便签表的触发器
db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER); 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_UPDATE_TRIGGER);
db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER); db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER);
@ -235,12 +274,17 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER); db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER);
} }
/**
*
* @param db
*/
private void createSystemFolder(SQLiteDatabase db) { private void createSystemFolder(SQLiteDatabase db) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
/** /**
* call record foler for call notes * call record folder for call notes
*/ */
// 创建调用记录文件夹
values.put(NoteColumns.ID, Notes.ID_CALL_RECORD_FOLDER); values.put(NoteColumns.ID, Notes.ID_CALL_RECORD_FOLDER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
db.insert(TABLE.NOTE, null, values); db.insert(TABLE.NOTE, null, values);
@ -248,6 +292,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/** /**
* root folder which is default folder * root folder which is default folder
*/ */
// 创建根文件夹
values.clear(); values.clear();
values.put(NoteColumns.ID, Notes.ID_ROOT_FOLDER); values.put(NoteColumns.ID, Notes.ID_ROOT_FOLDER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
@ -256,6 +301,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/** /**
* temporary folder which is used for moving note * temporary folder which is used for moving note
*/ */
// 创建临时文件夹
values.clear(); values.clear();
values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER); values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
@ -264,29 +310,47 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/** /**
* create trash folder * create trash folder
*/ */
// 创建垃圾文件夹(回收站)
values.clear(); values.clear();
values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER); values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
db.insert(TABLE.NOTE, null, values); db.insert(TABLE.NOTE, null, values);
} }
/**
*
* @param db
*/
public void createDataTable(SQLiteDatabase db) { public void createDataTable(SQLiteDatabase db) {
// 执行创建数据表的SQL语句
db.execSQL(CREATE_DATA_TABLE_SQL); db.execSQL(CREATE_DATA_TABLE_SQL);
// 重建所有的数据表触发器
reCreateDataTableTriggers(db); reCreateDataTableTriggers(db);
db.execSQL(CREATE_DATA_NOTE_ID_INDEX_SQL); db.execSQL(CREATE_DATA_NOTE_ID_INDEX_SQL);
Log.d(TAG, "data table has been created"); Log.d(TAG, "data table has been created");
} }
/**
*
* @param db
*/
private void reCreateDataTableTriggers(SQLiteDatabase db) { 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_insert");
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_update"); db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_update");
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_delete"); db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_delete");
// 执行创建数据表触发器的SQL语句
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER); 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_UPDATE_TRIGGER);
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER); db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER);
} }
/**
* 便线
* @param context
* @return
*/
static synchronized NotesDatabaseHelper getInstance(Context context) { static synchronized NotesDatabaseHelper getInstance(Context context) {
if (mInstance == null) { if (mInstance == null) {
mInstance = new NotesDatabaseHelper(context); mInstance = new NotesDatabaseHelper(context);
@ -296,66 +360,96 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
@Override @Override
public void onCreate(SQLiteDatabase db) { public void onCreate(SQLiteDatabase db) {
// 初始化创建便签表和数据表
createNoteTable(db); createNoteTable(db);
createDataTable(db); createDataTable(db);
} }
/**
*
* @param db
* @param oldVersion
* @param newVersion
*/
@Override @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
boolean reCreateTriggers = false; boolean reCreateTriggers = false;
boolean skipV2 = false; boolean skipV2 = false;
if (oldVersion == 1) { if (oldVersion == 1) {
// 升级到版本2包含了升级到版本3
upgradeToV2(db); upgradeToV2(db);
skipV2 = true; // this upgrade including the upgrade from v2 to v3 skipV2 = true; // this upgrade including the upgrade from v2 to v3
oldVersion++; oldVersion++;
} }
if (oldVersion == 2 && !skipV2) { if (oldVersion == 2 && !skipV2) {
// 升级到版本3
upgradeToV3(db); upgradeToV3(db);
reCreateTriggers = true; reCreateTriggers = true;
oldVersion++; oldVersion++;
} }
if (oldVersion == 3) { if (oldVersion == 3) {
// 升级到版本4
upgradeToV4(db); upgradeToV4(db);
oldVersion++; oldVersion++;
} }
if (reCreateTriggers) { if (reCreateTriggers) {
// 重新创建所有的触发器
reCreateNoteTableTriggers(db); reCreateNoteTableTriggers(db);
reCreateDataTableTriggers(db); reCreateDataTableTriggers(db);
} }
// 升级失败
if (oldVersion != newVersion) { if (oldVersion != newVersion) {
throw new IllegalStateException("Upgrade notes database to version " + newVersion throw new IllegalStateException("Upgrade notes database to version " + newVersion
+ "fails"); + "fails");
} }
} }
/**
* 2
* @param db
*/
private void upgradeToV2(SQLiteDatabase db) { private void upgradeToV2(SQLiteDatabase db) {
// 删除表
db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE); db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE);
db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA); db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA);
// 创建表
createNoteTable(db); createNoteTable(db);
createDataTable(db); createDataTable(db);
} }
/**
* 3
* @param db
*/
private void upgradeToV3(SQLiteDatabase db) { private void upgradeToV3(SQLiteDatabase db) {
// drop unused triggers // drop unused triggers
// 删除没用的触发器
db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_insert"); 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_delete");
db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_update"); db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_update");
// add a column for gtask id // add a column for gtask id
// 给便签表增加一个字段gtask_id
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.GTASK_ID db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.GTASK_ID
+ " TEXT NOT NULL DEFAULT ''"); + " TEXT NOT NULL DEFAULT ''");
// add a trash system folder // add a trash system folder
// 增加一个垃圾文件夹
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER); values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
db.insert(TABLE.NOTE, null, values); db.insert(TABLE.NOTE, null, values);
} }
/**
* 4
* @param db
*/
private void upgradeToV4(SQLiteDatabase db) { private void upgradeToV4(SQLiteDatabase db) {
// 给便签表增加一个字段version
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION
+ " INTEGER NOT NULL DEFAULT 0"); + " INTEGER NOT NULL DEFAULT 0");
} }

@ -34,23 +34,37 @@ import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE; import net.micode.notes.data.NotesDatabaseHelper.TABLE;
/**
* @author hzx
* 1.0
* 2023/10/28
* NotesProvider 便 便
*/
public class NotesProvider extends ContentProvider { public class NotesProvider extends ContentProvider {
// Uri匹配器
private static final UriMatcher mMatcher; private static final UriMatcher mMatcher;
// 数据库帮助类对象
private NotesDatabaseHelper mHelper; private NotesDatabaseHelper mHelper;
private static final String TAG = "NotesProvider"; private static final String TAG = "NotesProvider";
// 便签
private static final int URI_NOTE = 1; private static final int URI_NOTE = 1;
// 便签项
private static final int URI_NOTE_ITEM = 2; private static final int URI_NOTE_ITEM = 2;
// 数据
private static final int URI_DATA = 3; private static final int URI_DATA = 3;
// 数据项
private static final int URI_DATA_ITEM = 4; private static final int URI_DATA_ITEM = 4;
// 搜索
private static final int URI_SEARCH = 5; private static final int URI_SEARCH = 5;
// 搜索建议
private static final int URI_SEARCH_SUGGEST = 6; private static final int URI_SEARCH_SUGGEST = 6;
static { static {
// 初始化UriMatcher
mMatcher = new UriMatcher(UriMatcher.NO_MATCH); mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE); mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM); mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);
@ -65,6 +79,7 @@ public class NotesProvider extends ContentProvider {
* x'0A' represents the '\n' character in sqlite. For title and content in the search result, * x'0A' represents the '\n' character in sqlite. For title and content in the search result,
* we will trim '\n' and white space in order to show more information. * we will trim '\n' and white space in order to show more information.
*/ */
// 查询映射,对查询信息进行修剪,去掉换行符和空白字符
private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + "," private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + ","
+ NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + "," + 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_1 + ","
@ -73,6 +88,7 @@ public class NotesProvider extends ContentProvider {
+ "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + "," + "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
+ "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA; + "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
// 查询便签内容的SQL语句便签内容作为查询条件
private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION
+ " FROM " + TABLE.NOTE + " FROM " + TABLE.NOTE
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?" + " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
@ -81,37 +97,50 @@ public class NotesProvider extends ContentProvider {
@Override @Override
public boolean onCreate() { public boolean onCreate() {
// 获取便签数据库帮助类的实例
mHelper = NotesDatabaseHelper.getInstance(getContext()); mHelper = NotesDatabaseHelper.getInstance(getContext());
return true; return true;
} }
/**
*
* @param uri Uri
* @param projection
* @param selection
* @param selectionArgs
* @param sortOrder ascdesc
* @return cursor
*/
@Override @Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) { String sortOrder) {
Cursor c = null; Cursor c = null;
SQLiteDatabase db = mHelper.getReadableDatabase(); SQLiteDatabase db = mHelper.getReadableDatabase();
String id = null; String id = null;
// 根据uri执行对应的操作
switch (mMatcher.match(uri)) { switch (mMatcher.match(uri)) {
case URI_NOTE: case URI_NOTE: // 查询便签
c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null, c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null,
sortOrder); sortOrder);
break; break;
case URI_NOTE_ITEM: case URI_NOTE_ITEM: // 查询便签项 指定了便签ID
id = uri.getPathSegments().get(1); id = uri.getPathSegments().get(1);
c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs, null, null, sortOrder); + parseSelection(selection), selectionArgs, null, null, sortOrder);
break; break;
case URI_DATA: case URI_DATA: // 查询数据
c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null, c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null,
sortOrder); sortOrder);
break; break;
case URI_DATA_ITEM: case URI_DATA_ITEM: // 查询数据项指定了数据ID
id = uri.getPathSegments().get(1); id = uri.getPathSegments().get(1);
c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs, null, null, sortOrder); + parseSelection(selection), selectionArgs, null, null, sortOrder);
break; break;
// 搜索与搜索建议
case URI_SEARCH: case URI_SEARCH:
case URI_SEARCH_SUGGEST: case URI_SEARCH_SUGGEST:
// 不能指定排序方式和查询映射
if (sortOrder != null || projection != null) { if (sortOrder != null || projection != null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"do not specify sortOrder, selection, selectionArgs, or projection" + "with this query"); "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");
@ -119,10 +148,13 @@ public class NotesProvider extends ContentProvider {
String searchString = null; String searchString = null;
if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) { if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) {
// 搜索建议
if (uri.getPathSegments().size() > 1) { if (uri.getPathSegments().size() > 1) {
searchString = uri.getPathSegments().get(1); searchString = uri.getPathSegments().get(1);
} }
} else { } else {
// 搜索
// 获取查询参数pattern
searchString = uri.getQueryParameter("pattern"); searchString = uri.getQueryParameter("pattern");
} }
@ -131,68 +163,93 @@ public class NotesProvider extends ContentProvider {
} }
try { try {
// 格式化查询字符串,即 xxx --> %xxx%
searchString = String.format("%%%s%%", searchString); searchString = String.format("%%%s%%", searchString);
// 执行查询SQL语句
c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY, c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY,
new String[] { searchString }); new String[] { searchString });
} catch (IllegalStateException ex) { } catch (IllegalStateException ex) {
Log.e(TAG, "got exception: " + ex.toString()); Log.e(TAG, "got exception: " + ex.toString());
} }
break; break;
default: default: // 未知的Uri爬出异常
throw new IllegalArgumentException("Unknown URI " + uri); throw new IllegalArgumentException("Unknown URI " + uri);
} }
if (c != null) { if (c != null) { // 查询结果不为空
// 监视内容Uri的更改
c.setNotificationUri(getContext().getContentResolver(), uri); c.setNotificationUri(getContext().getContentResolver(), uri);
} }
return c; return c;
} }
/**
* 便
* @param uri Uri
* @param values
* @return uri
*/
@Override @Override
public Uri insert(Uri uri, ContentValues values) { public Uri insert(Uri uri, ContentValues values) {
// 获取可写数据库
SQLiteDatabase db = mHelper.getWritableDatabase(); SQLiteDatabase db = mHelper.getWritableDatabase();
long dataId = 0, noteId = 0, insertedId = 0; long dataId = 0, noteId = 0, insertedId = 0;
switch (mMatcher.match(uri)) { switch (mMatcher.match(uri)) {
case URI_NOTE: case URI_NOTE: // 要插入的是便签
insertedId = noteId = db.insert(TABLE.NOTE, null, values); insertedId = noteId = db.insert(TABLE.NOTE, null, values);
break; break;
case URI_DATA: case URI_DATA: // 要插入的是数据
// 插入数据时values需要包含便签ID
if (values.containsKey(DataColumns.NOTE_ID)) { if (values.containsKey(DataColumns.NOTE_ID)) {
// 获取便签ID
noteId = values.getAsLong(DataColumns.NOTE_ID); noteId = values.getAsLong(DataColumns.NOTE_ID);
} else { } else {
Log.d(TAG, "Wrong data format without note id:" + values.toString()); Log.d(TAG, "Wrong data format without note id:" + values.toString());
} }
insertedId = dataId = db.insert(TABLE.DATA, null, values); insertedId = dataId = db.insert(TABLE.DATA, null, values);
break; break;
default: default: // 未知的Uri
throw new IllegalArgumentException("Unknown URI " + uri); throw new IllegalArgumentException("Unknown URI " + uri);
} }
// Notify the note uri // Notify the note uri
if (noteId > 0) { if (noteId > 0) {
// 通知内容解析器便签发生了更改
getContext().getContentResolver().notifyChange( getContext().getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null); ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);
} }
// Notify the data uri // Notify the data uri
if (dataId > 0) { if (dataId > 0) {
// 通知内容解析器数据发生了更改
getContext().getContentResolver().notifyChange( getContext().getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null); ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);
} }
// 原来的uri添加id insertedId
return ContentUris.withAppendedId(uri, insertedId); return ContentUris.withAppendedId(uri, insertedId);
} }
/**
* 便
* @param uri Uri
* @param selection
* @param selectionArgs
* @return
*/
@Override @Override
public int delete(Uri uri, String selection, String[] selectionArgs) { public int delete(Uri uri, String selection, String[] selectionArgs) {
int count = 0; int count = 0;
String id = null; String id = null;
// 获取可写数据库
SQLiteDatabase db = mHelper.getWritableDatabase(); SQLiteDatabase db = mHelper.getWritableDatabase();
// 记录是否删除了数据没删除为false
boolean deleteData = false; boolean deleteData = false;
switch (mMatcher.match(uri)) { switch (mMatcher.match(uri)) {
case URI_NOTE: case URI_NOTE: // 要删除便签
// 保证便签ID大于0防止删除特殊的记录如根文件夹、临时文件夹、垃圾文件夹
selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 "; selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 ";
count = db.delete(TABLE.NOTE, selection, selectionArgs); count = db.delete(TABLE.NOTE, selection, selectionArgs);
break; break;
case URI_NOTE_ITEM: case URI_NOTE_ITEM: // 要删除指定ID的便签
id = uri.getPathSegments().get(1); id = uri.getPathSegments().get(1);
/** /**
* ID that smaller than 0 is system folder which is not allowed to * ID that smaller than 0 is system folder which is not allowed to
@ -200,26 +257,30 @@ public class NotesProvider extends ContentProvider {
*/ */
long noteId = Long.valueOf(id); long noteId = Long.valueOf(id);
if (noteId <= 0) { if (noteId <= 0) {
// 便签ID小于0的系统文件夹不能被删除
break; break;
} }
// 执行删除SQL语句
count = db.delete(TABLE.NOTE, count = db.delete(TABLE.NOTE,
NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs); NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
break; break;
case URI_DATA: case URI_DATA: // 要删除数据
count = db.delete(TABLE.DATA, selection, selectionArgs); count = db.delete(TABLE.DATA, selection, selectionArgs);
deleteData = true; deleteData = true;
break; break;
case URI_DATA_ITEM: case URI_DATA_ITEM: // 要删除指定ID的数据
// 获取数据ID
id = uri.getPathSegments().get(1); id = uri.getPathSegments().get(1);
count = db.delete(TABLE.DATA, count = db.delete(TABLE.DATA,
DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs); DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
deleteData = true; deleteData = true;
break; break;
default: default: // 未知的Uri
throw new IllegalArgumentException("Unknown URI " + uri); throw new IllegalArgumentException("Unknown URI " + uri);
} }
if (count > 0) { if (count > 0) {
if (deleteData) { if (deleteData) {
// 删除了数据,通知内容解析器 便签内容发生了改变
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null); getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
} }
getContext().getContentResolver().notifyChange(uri, null); getContext().getContentResolver().notifyChange(uri, null);
@ -227,58 +288,84 @@ public class NotesProvider extends ContentProvider {
return count; return count;
} }
/**
* 便
* @param uri Uri
* @param values
* @param selection
* @param selectionArgs
* @return
*/
@Override @Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
// 记录影响的行数
int count = 0; int count = 0;
String id = null; String id = null;
// 获取可写的数据库
SQLiteDatabase db = mHelper.getWritableDatabase(); SQLiteDatabase db = mHelper.getWritableDatabase();
// 记录数据表是否发生了变化
boolean updateData = false; boolean updateData = false;
switch (mMatcher.match(uri)) { switch (mMatcher.match(uri)) {
case URI_NOTE: case URI_NOTE: // 要更新便签
// 临时文件夹版本号加1
increaseNoteVersion(-1, selection, selectionArgs); increaseNoteVersion(-1, selection, selectionArgs);
count = db.update(TABLE.NOTE, values, selection, selectionArgs); count = db.update(TABLE.NOTE, values, selection, selectionArgs);
break; break;
case URI_NOTE_ITEM: case URI_NOTE_ITEM: // 要更新指定ID的便签项
// 获取便签ID
id = uri.getPathSegments().get(1); id = uri.getPathSegments().get(1);
// 便签的版本号加1
increaseNoteVersion(Long.valueOf(id), selection, selectionArgs); increaseNoteVersion(Long.valueOf(id), selection, selectionArgs);
count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs); + parseSelection(selection), selectionArgs);
break; break;
case URI_DATA: case URI_DATA: // 要更新数据
count = db.update(TABLE.DATA, values, selection, selectionArgs); count = db.update(TABLE.DATA, values, selection, selectionArgs);
updateData = true; updateData = true;
break; break;
case URI_DATA_ITEM: case URI_DATA_ITEM: // 要更新指定ID的数据项
id = uri.getPathSegments().get(1); id = uri.getPathSegments().get(1);
count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs); + parseSelection(selection), selectionArgs);
updateData = true; updateData = true;
break; break;
default: default: // 未知的Uri
throw new IllegalArgumentException("Unknown URI " + uri); throw new IllegalArgumentException("Unknown URI " + uri);
} }
if (count > 0) { if (count > 0) {
if (updateData) { if (updateData) {
// 如果更新了data表那么通知内容解析器note内容发生了改变
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null); getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
} }
// 通知uri内容发生了改变
getContext().getContentResolver().notifyChange(uri, null); getContext().getContentResolver().notifyChange(uri, null);
} }
// 返回更新操作影响的行数
return count; return count;
} }
// 解析查询条件
private String parseSelection(String selection) { private String parseSelection(String selection) {
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
} }
/**
* 便
* @param id 便ID
* @param selection
* @param selectionArgs
*/
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) { private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
StringBuilder sql = new StringBuilder(120); StringBuilder sql = new StringBuilder(120);
sql.append("UPDATE "); sql.append("UPDATE ");
sql.append(TABLE.NOTE); sql.append(TABLE.NOTE);
// 将version字段加1
sql.append(" SET "); sql.append(" SET ");
sql.append(NoteColumns.VERSION); sql.append(NoteColumns.VERSION);
sql.append("=" + NoteColumns.VERSION + "+1 "); sql.append("=" + NoteColumns.VERSION + "+1 ");
// 如果ID不为空或者条件不为空sql语句增加更新条件where
if (id > 0 || !TextUtils.isEmpty(selection)) { if (id > 0 || !TextUtils.isEmpty(selection)) {
sql.append(" WHERE "); sql.append(" WHERE ");
} }
@ -286,13 +373,16 @@ public class NotesProvider extends ContentProvider {
sql.append(NoteColumns.ID + "=" + String.valueOf(id)); sql.append(NoteColumns.ID + "=" + String.valueOf(id));
} }
if (!TextUtils.isEmpty(selection)) { if (!TextUtils.isEmpty(selection)) {
// 处理更新条件如果id>0前面添加AND否则不添加
String selectString = id > 0 ? parseSelection(selection) : selection; String selectString = id > 0 ? parseSelection(selection) : selection;
for (String args : selectionArgs) { for (String args : selectionArgs) {
// 填充占位符?
selectString = selectString.replaceFirst("\\?", args); selectString = selectString.replaceFirst("\\?", args);
} }
sql.append(selectString); sql.append(selectString);
} }
// 执行SQL语句
mHelper.getWritableDatabase().execSQL(sql.toString()); mHelper.getWritableDatabase().execSQL(sql.toString());
} }

@ -0,0 +1,115 @@
@startuml
title __DATA's Class Diagram__\n
namespace net.micode.notes {
namespace data {
class net.micode.notes.data.Contact {
}
}
}
namespace net.micode.notes {
namespace data {
class net.micode.notes.data.Notes {
}
}
}
namespace net.micode.notes {
namespace data {
class net.micode.notes.data.Notes.CallNote {
}
}
}
namespace net.micode.notes {
namespace data {
interface net.micode.notes.data.Notes.DataColumns {
}
}
}
namespace net.micode.notes {
namespace data {
class net.micode.notes.data.Notes.DataConstants {
}
}
}
namespace net.micode.notes {
namespace data {
interface net.micode.notes.data.Notes.NoteColumns {
}
}
}
namespace net.micode.notes {
namespace data {
class net.micode.notes.data.Notes.TextNote {
}
}
}
namespace net.micode.notes {
namespace data {
class net.micode.notes.data.NotesDatabaseHelper {
}
}
}
namespace net.micode.notes {
namespace data {
interface net.micode.notes.data.NotesDatabaseHelper.TABLE {
}
}
}
namespace net.micode.notes {
namespace data {
class net.micode.notes.data.NotesProvider {
}
}
}
net.micode.notes.data.Notes +-down- net.micode.notes.data.Notes.CallNote
net.micode.notes.data.Notes +-down- net.micode.notes.data.Notes.DataColumns
net.micode.notes.data.Notes +-down- net.micode.notes.data.Notes.DataConstants
net.micode.notes.data.Notes +-down- net.micode.notes.data.Notes.NoteColumns
net.micode.notes.data.Notes +-down- net.micode.notes.data.Notes.TextNote
net.micode.notes.data.Notes.CallNote .up.|> net.micode.notes.data.Notes.DataColumns
net.micode.notes.data.Notes.TextNote .up.|> net.micode.notes.data.Notes.DataColumns
net.micode.notes.data.NotesDatabaseHelper -up-|> android.database.sqlite.SQLiteOpenHelper
net.micode.notes.data.NotesDatabaseHelper +-down- net.micode.notes.data.NotesDatabaseHelper.TABLE
net.micode.notes.data.NotesProvider -up-|> android.content.ContentProvider
net.micode.notes.data.NotesProvider o-- net.micode.notes.data.NotesDatabaseHelper : mHelper
right footer
PlantUML diagram generated by SketchIt! (https://bitbucket.org/pmesmeur/sketch.it)
For more information about this tool, please contact philippe.mesmeur@gmail.com
endfooter
@enduml

@ -0,0 +1,73 @@
@startuml
title __DATA's Class Diagram__\n
namespace net.micode.notes {
namespace gtask.data {
class net.micode.notes.gtask.data.MetaData {
}
}
}
namespace net.micode.notes {
namespace gtask.data {
abstract class net.micode.notes.gtask.data.Node {
}
}
}
namespace net.micode.notes {
namespace gtask.data {
class net.micode.notes.gtask.data.SqlData {
}
}
}
namespace net.micode.notes {
namespace gtask.data {
class net.micode.notes.gtask.data.SqlNote {
}
}
}
namespace net.micode.notes {
namespace gtask.data {
class net.micode.notes.gtask.data.Task {
}
}
}
namespace net.micode.notes {
namespace gtask.data {
class net.micode.notes.gtask.data.TaskList {
}
}
}
net.micode.notes.gtask.data.MetaData -up-|> net.micode.notes.gtask.data.Task
net.micode.notes.gtask.data.Task -up-|> net.micode.notes.gtask.data.Node
net.micode.notes.gtask.data.Task o-- net.micode.notes.gtask.data.TaskList : mParent
net.micode.notes.gtask.data.Task o-- net.micode.notes.gtask.data.Task : mPriorSibling
net.micode.notes.gtask.data.TaskList -up-|> net.micode.notes.gtask.data.Node
right footer
PlantUML diagram generated by SketchIt! (https://bitbucket.org/pmesmeur/sketch.it)
For more information about this tool, please contact philippe.mesmeur@gmail.com
endfooter
@enduml

@ -0,0 +1,38 @@
@startuml
title __EXCEPTION's Class Diagram__\n
namespace net.micode.notes {
namespace gtask.exception {
class net.micode.notes.gtask.exception.ActionFailureException {
{static} - serialVersionUID : long
+ ActionFailureException()
+ ActionFailureException()
+ ActionFailureException()
}
}
}
namespace net.micode.notes {
namespace gtask.exception {
class net.micode.notes.gtask.exception.NetworkFailureException {
{static} - serialVersionUID : long
+ NetworkFailureException()
+ NetworkFailureException()
+ NetworkFailureException()
}
}
}
right footer
PlantUML diagram generated by SketchIt! (https://bitbucket.org/pmesmeur/sketch.it)
For more information about this tool, please contact philippe.mesmeur@gmail.com
endfooter
@enduml

@ -0,0 +1,65 @@
@startuml
title __REMOTE's Class Diagram__\n
namespace net.micode.notes {
namespace gtask.remote {
class net.micode.notes.gtask.remote.GTaskASyncTask {
}
}
}
namespace net.micode.notes {
namespace gtask.remote {
interface net.micode.notes.gtask.remote.GTaskASyncTask.OnCompleteListener {
}
}
}
namespace net.micode.notes {
namespace gtask.remote {
class net.micode.notes.gtask.remote.GTaskClient {
}
}
}
namespace net.micode.notes {
namespace gtask.remote {
class net.micode.notes.gtask.remote.GTaskManager {
}
}
}
namespace net.micode.notes {
namespace gtask.remote {
class net.micode.notes.gtask.remote.GTaskSyncService {
}
}
}
net.micode.notes.gtask.remote.GTaskASyncTask -up-|> android.os.AsyncTask
net.micode.notes.gtask.remote.GTaskASyncTask o-- net.micode.notes.gtask.remote.GTaskASyncTask.OnCompleteListener : mOnCompleteListener
net.micode.notes.gtask.remote.GTaskASyncTask o-- net.micode.notes.gtask.remote.GTaskManager : mTaskManager
net.micode.notes.gtask.remote.GTaskASyncTask +-down- net.micode.notes.gtask.remote.GTaskASyncTask.OnCompleteListener
net.micode.notes.gtask.remote.GTaskManager o-- net.micode.notes.gtask.data.TaskList : mMetaList
net.micode.notes.gtask.remote.GTaskSyncService -up-|> android.app.Service
right footer
PlantUML diagram generated by SketchIt! (https://bitbucket.org/pmesmeur/sketch.it)
For more information about this tool, please contact philippe.mesmeur@gmail.com
endfooter
@enduml

@ -34,12 +34,25 @@ import net.micode.notes.data.Notes.TextNote;
import java.util.ArrayList; import java.util.ArrayList;
/**
* @author hzx
* 1.0
* 2023/10/28
* Note 便
*/
public class Note { public class Note {
// 便签内容
private ContentValues mNoteDiffValues; private ContentValues mNoteDiffValues;
// 便签数据
private NoteData mNoteData; private NoteData mNoteData;
// 日志标签
private static final String TAG = "Note"; private static final String TAG = "Note";
/** /**
* Create a new note id for adding a new note to databases * 便ID便便 线
* @param context
* @param folderId ID
* @return long 便ID
*/ */
public static synchronized long getNewNoteId(Context context, long folderId) { public static synchronized long getNewNoteId(Context context, long folderId) {
// Create a new note in the database // Create a new note in the database
@ -54,8 +67,10 @@ public class Note {
long noteId = 0; long noteId = 0;
try { try {
// 从uri中获取便签ID
noteId = Long.valueOf(uri.getPathSegments().get(1)); noteId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
// 从uri中获取便签ID失败
Log.e(TAG, "Get note id error :" + e.toString()); Log.e(TAG, "Get note id error :" + e.toString());
noteId = 0; noteId = 0;
} }
@ -70,42 +85,81 @@ public class Note {
mNoteData = new NoteData(); mNoteData = new NoteData();
} }
/**
* mNoteDiffValues
* @param key
* @param value
*/
public void setNoteValue(String key, String value) { public void setNoteValue(String key, String value) {
mNoteDiffValues.put(key, value); mNoteDiffValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
} }
/**
* mNoteData
* @param key
* @param value
*/
public void setTextData(String key, String value) { public void setTextData(String key, String value) {
mNoteData.setTextData(key, value); mNoteData.setTextData(key, value);
} }
/**
* mNoteDataid
* @param id id
*/
public void setTextDataId(long id) { public void setTextDataId(long id) {
mNoteData.setTextDataId(id); mNoteData.setTextDataId(id);
} }
/**
* mNoteDataid
* @return id
*/
public long getTextDataId() { public long getTextDataId() {
return mNoteData.mTextDataId; return mNoteData.mTextDataId;
} }
/**
* mNoteDataid
* @param id id
*/
public void setCallDataId(long id) { public void setCallDataId(long id) {
mNoteData.setCallDataId(id); mNoteData.setCallDataId(id);
} }
/**
* mNoteData
* @param key
* @param value
*/
public void setCallData(String key, String value) { public void setCallData(String key, String value) {
mNoteData.setCallData(key, value); mNoteData.setCallData(key, value);
} }
/**
* 便 便mNoteDiffValues便mNoteData
* @return true or false
*/
public boolean isLocalModified() { public boolean isLocalModified() {
return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified(); return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified();
} }
/**
* 便
* @param context
* @param noteId 便ID
* @return boolean
*/
public boolean syncNote(Context context, long noteId) { public boolean syncNote(Context context, long noteId) {
if (noteId <= 0) { if (noteId <= 0) {
// 便签ID不合法
throw new IllegalArgumentException("Wrong note id:" + noteId); throw new IllegalArgumentException("Wrong note id:" + noteId);
} }
if (!isLocalModified()) { if (!isLocalModified()) {
// 如果便签没有被本地修改直接返回true不用同步了
return true; return true;
} }
@ -117,41 +171,61 @@ public class Note {
if (context.getContentResolver().update( if (context.getContentResolver().update(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), mNoteDiffValues, null, ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), mNoteDiffValues, null,
null) == 0) { null) == 0) {
// 更新失败
Log.e(TAG, "Update note error, should not happen"); Log.e(TAG, "Update note error, should not happen");
// Do not return, fall through // Do not return, fall through
} }
// 清空便签更新内容
mNoteDiffValues.clear(); mNoteDiffValues.clear();
// 将本地更新的便签数据更新到数据库
if (mNoteData.isLocalModified() if (mNoteData.isLocalModified()
&& (mNoteData.pushIntoContentResolver(context, noteId) == null)) { && (mNoteData.pushIntoContentResolver(context, noteId) == null)) {
// 更新失败
return false; return false;
} }
return true; return true;
} }
/**
* 便
*/
private class NoteData { private class NoteData {
// 文本数据ID
private long mTextDataId; private long mTextDataId;
// 文本数据修改内容,修改了但没写入数据库
private ContentValues mTextDataValues; private ContentValues mTextDataValues;
// 电话号码数据ID
private long mCallDataId; private long mCallDataId;
// 电话号码数据修改内容
private ContentValues mCallDataValues; private ContentValues mCallDataValues;
private static final String TAG = "NoteData"; private static final String TAG = "NoteData";
public NoteData() { public NoteData() {
// 初始化
mTextDataValues = new ContentValues(); mTextDataValues = new ContentValues();
mCallDataValues = new ContentValues(); mCallDataValues = new ContentValues();
mTextDataId = 0; mTextDataId = 0;
mCallDataId = 0; mCallDataId = 0;
} }
/**
* 便
* @return true or false
*/
boolean isLocalModified() { boolean isLocalModified() {
return mTextDataValues.size() > 0 || mCallDataValues.size() > 0; return mTextDataValues.size() > 0 || mCallDataValues.size() > 0;
} }
/**
* id
* @param id id
*/
void setTextDataId(long id) { void setTextDataId(long id) {
if(id <= 0) { if(id <= 0) {
throw new IllegalArgumentException("Text data id should larger than 0"); throw new IllegalArgumentException("Text data id should larger than 0");
@ -159,6 +233,10 @@ public class Note {
mTextDataId = id; mTextDataId = id;
} }
/**
* id
* @param id id
*/
void setCallDataId(long id) { void setCallDataId(long id) {
if (id <= 0) { if (id <= 0) {
throw new IllegalArgumentException("Call data id should larger than 0"); throw new IllegalArgumentException("Call data id should larger than 0");
@ -166,75 +244,107 @@ public class Note {
mCallDataId = id; mCallDataId = id;
} }
/**
*
* @param key
* @param value
*/
void setCallData(String key, String value) { void setCallData(String key, String value) {
mCallDataValues.put(key, value); mCallDataValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
} }
/**
* 便
* @param key
* @param value
*/
void setTextData(String key, String value) { void setTextData(String key, String value) {
mTextDataValues.put(key, value); mTextDataValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
} }
/**
* mTextDataValuesmCallDataValues
* @param context
* @param noteId 便ID
* @return 便Uri
*/
Uri pushIntoContentResolver(Context context, long noteId) { Uri pushIntoContentResolver(Context context, long noteId) {
/** // 检查便签ID是否合法
* Check for safety
*/
if (noteId <= 0) { if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId); throw new IllegalArgumentException("Wrong note id:" + noteId);
} }
// 操作列表
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
ContentProviderOperation.Builder builder = null; ContentProviderOperation.Builder builder = null;
// 维护文本数据
if(mTextDataValues.size() > 0) { if(mTextDataValues.size() > 0) {
mTextDataValues.put(DataColumns.NOTE_ID, noteId); mTextDataValues.put(DataColumns.NOTE_ID, noteId);
if (mTextDataId == 0) { if (mTextDataId == 0) { // 是新创建的数据项,而不是更新数据
// 设置文本数据的MIME类型
mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE); mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE);
// 使用内容解析器插入文本数据到data表中
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI, Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mTextDataValues); mTextDataValues);
try { try {
// 设置文本数据ID为插入data表后返回ID即新插入的那条记录的ID
setTextDataId(Long.valueOf(uri.getPathSegments().get(1))); setTextDataId(Long.valueOf(uri.getPathSegments().get(1)));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
// 插入数据失败 抛出异常
Log.e(TAG, "Insert new text data fail with noteId" + noteId); Log.e(TAG, "Insert new text data fail with noteId" + noteId);
// 清空要更新的文本数据内容
mTextDataValues.clear(); mTextDataValues.clear();
return null; return null;
} }
} else { } else { // 更新data表中ID为mTextDataId的记录
builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId( builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mTextDataId)); Notes.CONTENT_DATA_URI, mTextDataId));
builder.withValues(mTextDataValues); builder.withValues(mTextDataValues);
// 向操作列表中添加一个更新操作
operationList.add(builder.build()); operationList.add(builder.build());
} }
// 清空要更新的文本数据内容
mTextDataValues.clear(); mTextDataValues.clear();
} }
// 维护电话号码数据
if(mCallDataValues.size() > 0) { if(mCallDataValues.size() > 0) {
// 插入便签ID到要更新的电话号码数据内容中
mCallDataValues.put(DataColumns.NOTE_ID, noteId); mCallDataValues.put(DataColumns.NOTE_ID, noteId);
if (mCallDataId == 0) { if (mCallDataId == 0) { // 插入新的数据
// 设置MIME类型
mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE); mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE);
// 使用内容解析器插入电话号码数据到data表中
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI, Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mCallDataValues); mCallDataValues);
try { try {
// 设置电话号码数据ID
setCallDataId(Long.valueOf(uri.getPathSegments().get(1))); setCallDataId(Long.valueOf(uri.getPathSegments().get(1)));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
// 插入失败 抛出异常
Log.e(TAG, "Insert new call data fail with noteId" + noteId); Log.e(TAG, "Insert new call data fail with noteId" + noteId);
// 清空要更新的电话号码数据内容
mCallDataValues.clear(); mCallDataValues.clear();
return null; return null;
} }
} else { } else { // 更新数据
builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId( builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mCallDataId)); Notes.CONTENT_DATA_URI, mCallDataId));
builder.withValues(mCallDataValues); builder.withValues(mCallDataValues);
operationList.add(builder.build()); operationList.add(builder.build());
} }
// 清空要更新的电话号码数据内容
mCallDataValues.clear(); mCallDataValues.clear();
} }
if (operationList.size() > 0) { if (operationList.size() > 0) {
try { try {
// 批量处理操作
ContentProviderResult[] results = context.getContentResolver().applyBatch( ContentProviderResult[] results = context.getContentResolver().applyBatch(
Notes.AUTHORITY, operationList); Notes.AUTHORITY, operationList);
return (results == null || results.length == 0 || results[0] == null) ? null return (results == null || results.length == 0 || results[0] == null) ? null
@ -243,6 +353,7 @@ public class Note {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
return null; return null;
} catch (OperationApplicationException e) { } catch (OperationApplicationException e) {
// 操作异常
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
return null; return null;
} }

@ -31,7 +31,12 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.Notes.TextNote; import net.micode.notes.data.Notes.TextNote;
import net.micode.notes.tool.ResourceParser.NoteBgResources; import net.micode.notes.tool.ResourceParser.NoteBgResources;
/**
* @author hzx
* 1.0
* 2023/10/28
* WorkingNote 便便
*/
public class WorkingNote { public class WorkingNote {
// Note for the working note // Note for the working note
private Note mNote; private Note mNote;
@ -42,26 +47,37 @@ public class WorkingNote {
// Note mode // Note mode
private int mMode; private int mMode;
// 便签的提醒日期
private long mAlertDate; private long mAlertDate;
// 便签的上一次修改日期
private long mModifiedDate; private long mModifiedDate;
// 便签的背景颜色
private int mBgColorId; private int mBgColorId;
// 便签的小部件ID
private int mWidgetId; private int mWidgetId;
// 便签的小部件类型
private int mWidgetType; private int mWidgetType;
// 便签所处的文件夹ID
private long mFolderId; private long mFolderId;
// 工作便签所处的上下文
private Context mContext; private Context mContext;
// 日志标签
private static final String TAG = "WorkingNote"; private static final String TAG = "WorkingNote";
// 便签是否被删除
private boolean mIsDeleted; private boolean mIsDeleted;
// 便签设置状态改变监听器
private NoteSettingChangedListener mNoteSettingStatusListener; private NoteSettingChangedListener mNoteSettingStatusListener;
// 便签数据表字段的投影 即select后面的字段
public static final String[] DATA_PROJECTION = new String[] { public static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID, DataColumns.ID,
DataColumns.CONTENT, DataColumns.CONTENT,
@ -72,6 +88,7 @@ public class WorkingNote {
DataColumns.DATA4, DataColumns.DATA4,
}; };
// 便签表字段的投影
public static final String[] NOTE_PROJECTION = new String[] { public static final String[] NOTE_PROJECTION = new String[] {
NoteColumns.PARENT_ID, NoteColumns.PARENT_ID,
NoteColumns.ALERTED_DATE, NoteColumns.ALERTED_DATE,
@ -81,6 +98,9 @@ public class WorkingNote {
NoteColumns.MODIFIED_DATE NoteColumns.MODIFIED_DATE
}; };
/**
* datanote
*/
private static final int DATA_ID_COLUMN = 0; private static final int DATA_ID_COLUMN = 0;
private static final int DATA_CONTENT_COLUMN = 1; private static final int DATA_CONTENT_COLUMN = 1;
@ -101,12 +121,12 @@ public class WorkingNote {
private static final int NOTE_MODIFIED_DATE_COLUMN = 5; private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
// New note construct // 新便签的构造器 即当前编辑的便签是要新建的便签
private WorkingNote(Context context, long folderId) { private WorkingNote(Context context, long folderId) {
mContext = context; mContext = context;
mAlertDate = 0; mAlertDate = 0;
mModifiedDate = System.currentTimeMillis(); mModifiedDate = System.currentTimeMillis();
mFolderId = folderId; mFolderId = folderId; // 设置所处文件夹的ID
mNote = new Note(); mNote = new Note();
mNoteId = 0; mNoteId = 0;
mIsDeleted = false; mIsDeleted = false;
@ -114,23 +134,28 @@ public class WorkingNote {
mWidgetType = Notes.TYPE_WIDGET_INVALIDE; mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
} }
// Existing note construct // 已经存在的便签构造器 即当前编辑的便签是已有的便签
private WorkingNote(Context context, long noteId, long folderId) { private WorkingNote(Context context, long noteId, long folderId) {
mContext = context; mContext = context;
mNoteId = noteId; mNoteId = noteId;
mFolderId = folderId; mFolderId = folderId;
mIsDeleted = false; mIsDeleted = false;
mNote = new Note(); mNote = new Note();
loadNote(); loadNote(); // 加载便签的内容
} }
/**
* 便
*/
private void loadNote() { private void loadNote() {
// 通过内容解析器查询便签内容
Cursor cursor = mContext.getContentResolver().query( Cursor cursor = mContext.getContentResolver().query(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null, ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null,
null, null); null, null);
if (cursor != null) { if (cursor != null) { // 查询结果不为空
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
// 数据存入对应成员变量
mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN); mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);
mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN); mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN);
mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN); mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN);
@ -140,40 +165,60 @@ public class WorkingNote {
} }
cursor.close(); cursor.close();
} else { } else {
// 查询结果为空
Log.e(TAG, "No note with id:" + mNoteId); Log.e(TAG, "No note with id:" + mNoteId);
// 抛出异常
throw new IllegalArgumentException("Unable to find note with id " + mNoteId); throw new IllegalArgumentException("Unable to find note with id " + mNoteId);
} }
// 加载便签的数据
loadNoteData(); loadNoteData();
} }
/**
* 便
*/
private void loadNoteData() { private void loadNoteData() {
// 查询便签ID为mNoteId的便签数据
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION, Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
DataColumns.NOTE_ID + "=?", new String[] { DataColumns.NOTE_ID + "=?", new String[] {
String.valueOf(mNoteId) String.valueOf(mNoteId)
}, null); }, null);
if (cursor != null) { if (cursor != null) { // 查询结果不为空
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
do { do { // 遍历所有的便签数据
String type = cursor.getString(DATA_MIME_TYPE_COLUMN); String type = cursor.getString(DATA_MIME_TYPE_COLUMN);
if (DataConstants.NOTE.equals(type)) { if (DataConstants.NOTE.equals(type)) {
// 提取便签文本数据
// 存入成员变量
mContent = cursor.getString(DATA_CONTENT_COLUMN); mContent = cursor.getString(DATA_CONTENT_COLUMN);
mMode = cursor.getInt(DATA_MODE_COLUMN); mMode = cursor.getInt(DATA_MODE_COLUMN);
mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN)); mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN));
} else if (DataConstants.CALL_NOTE.equals(type)) { } else if (DataConstants.CALL_NOTE.equals(type)) {
// 提取便签电话号码数据ID
mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN)); mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN));
} else { } else {
// 错误的数据类型
Log.d(TAG, "Wrong note type with type:" + type); Log.d(TAG, "Wrong note type with type:" + type);
} }
} while (cursor.moveToNext()); } while (cursor.moveToNext());
} }
cursor.close(); cursor.close();
} else { } else { // 查询结果为空
Log.e(TAG, "No data with id:" + mNoteId); Log.e(TAG, "No data with id:" + mNoteId);
throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId); throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId);
} }
} }
/**
* 便
* @param context
* @param folderId ID
* @param widgetId ID
* @param widgetType
* @param defaultBgColorId
* @return 便
*/
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId, public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
int widgetType, int defaultBgColorId) { int widgetType, int defaultBgColorId) {
WorkingNote note = new WorkingNote(context, folderId); WorkingNote note = new WorkingNote(context, folderId);
@ -183,23 +228,38 @@ public class WorkingNote {
return note; return note;
} }
/**
* 便ID便便
* @param context
* @param id 便ID
* @return 便
*/
public static WorkingNote load(Context context, long id) { public static WorkingNote load(Context context, long id) {
return new WorkingNote(context, id, 0); return new WorkingNote(context, id, 0);
} }
/**
* 便 线
* @return
*/
public synchronized boolean saveNote() { public synchronized boolean saveNote() {
if (isWorthSaving()) { // 判断是否应该保存
if (!existInDatabase()) { if (isWorthSaving()) { // 应该保存
if (!existInDatabase()) { // 该便签不存在于数据库,即新创建的便签
// 在文件夹下创建一个新的便签然后获取其ID
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) { if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
// 创建新便签失败
Log.e(TAG, "Create new note fail with id:" + mNoteId); Log.e(TAG, "Create new note fail with id:" + mNoteId);
return false; return false;
} }
} }
// 将编辑的便签内容同步到数据库中
mNote.syncNote(mContext, mNoteId); mNote.syncNote(mContext, mNoteId);
/** /**
* Update widget content if there exist any widget of this note * Update widget content if there exist any widget of this note
* 便
*/ */
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mWidgetType != Notes.TYPE_WIDGET_INVALIDE
@ -207,59 +267,99 @@ public class WorkingNote {
mNoteSettingStatusListener.onWidgetChanged(); mNoteSettingStatusListener.onWidgetChanged();
} }
return true; return true;
} else { } else { // 不应该保存
return false; return false;
} }
} }
/**
* 便
* @return true or false
*/
public boolean existInDatabase() { public boolean existInDatabase() {
// 因为mNoteId的初始值为0如果是从数据库中加载的正常便签那mNoteId应该大于0
return mNoteId > 0; return mNoteId > 0;
} }
/**
* 便
* @return true or false
*/
private boolean isWorthSaving() { private boolean isWorthSaving() {
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent)) if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|| (existInDatabase() && !mNote.isLocalModified())) { || (existInDatabase() && !mNote.isLocalModified())) {
// 便签被删除 或 是新创建的便签但内容为空 或 数据库中已存在的便签但本地没有修改
// 不应该保存
return false; return false;
} else { } else {
// 应该保存
return true; return true;
} }
} }
/**
* 便
* @param l
*/
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
mNoteSettingStatusListener = l; mNoteSettingStatusListener = l;
} }
/**
* 便
* @param date
* @param set
*/
public void setAlertDate(long date, boolean set) { public void setAlertDate(long date, boolean set) {
if (date != mAlertDate) { if (date != mAlertDate) { // 如果是新设置的提醒日期
// 本地设置
mAlertDate = date; mAlertDate = date;
// 设置到便签模型中 将会被保存到数据库中
mNote.setNoteValue(NoteColumns.ALERTED_DATE, String.valueOf(mAlertDate)); mNote.setNoteValue(NoteColumns.ALERTED_DATE, String.valueOf(mAlertDate));
} }
if (mNoteSettingStatusListener != null) { if (mNoteSettingStatusListener != null) {
// 设置便签提醒监听
mNoteSettingStatusListener.onClockAlertChanged(date, set); mNoteSettingStatusListener.onClockAlertChanged(date, set);
} }
} }
/**
* 便
* @param mark
*/
public void markDeleted(boolean mark) { public void markDeleted(boolean mark) {
mIsDeleted = mark; mIsDeleted = mark;
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) { && mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) {
mNoteSettingStatusListener.onWidgetChanged(); // 更新小组件内容
mNoteSettingStatusListener.onWidgetChanged();
} }
} }
/**
* 便
* @param id ID
*/
public void setBgColorId(int id) { public void setBgColorId(int id) {
if (id != mBgColorId) { if (id != mBgColorId) { // 新的背景颜色
mBgColorId = id; mBgColorId = id;
if (mNoteSettingStatusListener != null) { if (mNoteSettingStatusListener != null) {
// 改变便签背景颜色
mNoteSettingStatusListener.onBackgroundColorChanged(); mNoteSettingStatusListener.onBackgroundColorChanged();
} }
// 保存到数据库
mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id)); mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id));
} }
} }
/**
* 便
* @param mode
*/
public void setCheckListMode(int mode) { public void setCheckListMode(int mode) {
if (mMode != mode) { if (mMode != mode) { // 新的模式
if (mNoteSettingStatusListener != null) { if (mNoteSettingStatusListener != null) {
// 实际改变便签的查看模式
mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode); mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode);
} }
mMode = mode; mMode = mode;
@ -267,99 +367,135 @@ public class WorkingNote {
} }
} }
/**
*
* @param type
*/
public void setWidgetType(int type) { public void setWidgetType(int type) {
if (type != mWidgetType) { if (type != mWidgetType) { // 新的小组件类型
mWidgetType = type; mWidgetType = type;
mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType)); mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType));
} }
} }
/**
* ID
* @param id ID
*/
public void setWidgetId(int id) { public void setWidgetId(int id) {
if (id != mWidgetId) { if (id != mWidgetId) { // 新的小组件ID
mWidgetId = id; mWidgetId = id;
mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId)); mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId));
} }
} }
/**
* 便
* @param text
*/
public void setWorkingText(String text) { public void setWorkingText(String text) {
if (!TextUtils.equals(mContent, text)) { if (!TextUtils.equals(mContent, text)) { // 文本发生变化
mContent = text; mContent = text;
mNote.setTextData(DataColumns.CONTENT, mContent); mNote.setTextData(DataColumns.CONTENT, mContent);
} }
} }
/**
* 便
* @param phoneNumber
* @param callDate
*/
public void convertToCallNote(String phoneNumber, long callDate) { public void convertToCallNote(String phoneNumber, long callDate) {
mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate)); mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate));
mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber); mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber);
mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER)); mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER));
} }
// 是否有闹钟提醒
public boolean hasClockAlert() { public boolean hasClockAlert() {
return (mAlertDate > 0 ? true : false); return (mAlertDate > 0 ? true : false);
} }
// 获取便签内容
public String getContent() { public String getContent() {
return mContent; return mContent;
} }
// 获取便签提醒日期
public long getAlertDate() { public long getAlertDate() {
return mAlertDate; return mAlertDate;
} }
// 获取上一次修改的日期
public long getModifiedDate() { public long getModifiedDate() {
return mModifiedDate; return mModifiedDate;
} }
// 获取便签背景颜色资源ID
public int getBgColorResId() { public int getBgColorResId() {
return NoteBgResources.getNoteBgResource(mBgColorId); return NoteBgResources.getNoteBgResource(mBgColorId);
} }
// 获取背景颜色ID
public int getBgColorId() { public int getBgColorId() {
return mBgColorId; return mBgColorId;
} }
// 获取便签标题资源ID
public int getTitleBgResId() { public int getTitleBgResId() {
return NoteBgResources.getNoteTitleBgResource(mBgColorId); return NoteBgResources.getNoteTitleBgResource(mBgColorId);
} }
// 获取便签查看模式
public int getCheckListMode() { public int getCheckListMode() {
return mMode; return mMode;
} }
// 获取便签ID
public long getNoteId() { public long getNoteId() {
return mNoteId; return mNoteId;
} }
// 获取便签所属文件夹ID
public long getFolderId() { public long getFolderId() {
return mFolderId; return mFolderId;
} }
// 获取小部件ID
public int getWidgetId() { public int getWidgetId() {
return mWidgetId; return mWidgetId;
} }
// 获取小部件类型
public int getWidgetType() { public int getWidgetType() {
return mWidgetType; return mWidgetType;
} }
/**
* 便
*/
public interface NoteSettingChangedListener { public interface NoteSettingChangedListener {
/** /**
* Called when the background color of current note has just changed * Called when the background color of current note has just changed
* 便
*/ */
void onBackgroundColorChanged(); void onBackgroundColorChanged();
/** /**
* Called when user set clock * Called when user set clock
*
*/ */
void onClockAlertChanged(long date, boolean set); void onClockAlertChanged(long date, boolean set);
/** /**
* Call when user create note from widget * Call when user create note from widget
* 便
*/ */
void onWidgetChanged(); void onWidgetChanged();
/** /**
* Call when switch between check list mode and normal mode * Call when switch between check list mode and normal mode
*
* @param oldMode is previous mode before change * @param oldMode is previous mode before change
* @param newMode is new mode * @param newMode is new mode
*/ */

@ -0,0 +1,55 @@
@startuml
title __MODEL's Class Diagram__\n
namespace net.micode.notes {
namespace model {
class net.micode.notes.model.Note {
}
}
}
namespace net.micode.notes {
namespace model {
class net.micode.notes.model.Note.NoteData {
}
}
}
namespace net.micode.notes {
namespace model {
class net.micode.notes.model.WorkingNote {
}
}
}
namespace net.micode.notes {
namespace model {
interface net.micode.notes.model.WorkingNote.NoteSettingChangedListener {
}
}
}
net.micode.notes.model.Note o-- net.micode.notes.model.Note.NoteData : mNoteData
net.micode.notes.model.Note +-down- net.micode.notes.model.Note.NoteData
net.micode.notes.model.WorkingNote o-- net.micode.notes.model.Note : mNote
net.micode.notes.model.WorkingNote o-- net.micode.notes.model.WorkingNote.NoteSettingChangedListener : mNoteSettingStatusListener
net.micode.notes.model.WorkingNote +-down- net.micode.notes.model.WorkingNote.NoteSettingChangedListener
right footer
PlantUML diagram generated by SketchIt! (https://bitbucket.org/pmesmeur/sketch.it)
For more information about this tool, please contact philippe.mesmeur@gmail.com
endfooter
@enduml

@ -29,14 +29,27 @@ import android.util.Log;
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.CallNote; import net.micode.notes.data.Notes.CallNote;
import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper;
import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
/**
* @author hzx
* 1.0
* 2023/10/29
* DataUtils 便便
*/
public class DataUtils { public class DataUtils {
public static final String TAG = "DataUtils"; public static final String TAG = "DataUtils";
/**
* 便
* @param resolver
* @param ids 便ID
* @return
*/
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) { public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
if (ids == null) { if (ids == null) {
Log.d(TAG, "the ids is null"); Log.d(TAG, "the ids is null");
@ -47,19 +60,26 @@ public class DataUtils {
return true; return true;
} }
// 内容操作列表
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
// 遍历便签ID集合
for (long id : ids) { for (long id : ids) {
if(id == Notes.ID_ROOT_FOLDER) { if(id == Notes.ID_ROOT_FOLDER) { // 如果是根文件夹
// 根文件夹不能被删除
Log.e(TAG, "Don't delete system folder root"); Log.e(TAG, "Don't delete system folder root");
continue; continue;
} }
// 创建一个删除操作
ContentProviderOperation.Builder builder = ContentProviderOperation ContentProviderOperation.Builder builder = ContentProviderOperation
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); .newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
// 将删除操作加入到操作列表中
operationList.add(builder.build()); operationList.add(builder.build());
} }
try { try {
// 批量处理删除便签的操作
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
if (results == null || results.length == 0 || results[0] == null) { if (results == null || results.length == 0 || results[0] == null) {
// 删除便签失败
Log.d(TAG, "delete notes failed, ids:" + ids.toString()); Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false; return false;
} }
@ -67,19 +87,37 @@ public class DataUtils {
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} catch (OperationApplicationException e) { } catch (OperationApplicationException e) {
// 执行删除操作发生错误
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} }
return false; 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) { public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
// 将便签的父ID改为目标文件夹ID
values.put(NoteColumns.PARENT_ID, desFolderId); values.put(NoteColumns.PARENT_ID, desFolderId);
// 将便签的原父ID改为移动前的文件夹ID
values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId); values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId);
values.put(NoteColumns.LOCAL_MODIFIED, 1); values.put(NoteColumns.LOCAL_MODIFIED, 1);
// 将便签ID放入uri中然后通过内容解析器执行更新操作
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
} }
/**
* 便
* @param resolver
* @param ids 便ID
* @param folderId ID
* @return
*/
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids, public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
long folderId) { long folderId) {
if (ids == null) { if (ids == null) {
@ -87,34 +125,43 @@ public class DataUtils {
return true; return true;
} }
// 创建一个内容提供者操作列表
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
for (long id : ids) { for (long id : ids) {
// 创建更新操作
ContentProviderOperation.Builder builder = ContentProviderOperation ContentProviderOperation.Builder builder = ContentProviderOperation
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); .newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
builder.withValue(NoteColumns.PARENT_ID, folderId); builder.withValue(NoteColumns.PARENT_ID, folderId);
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1); builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);
// 将更新操作加入到操作列表中,以便后面批量处理
operationList.add(builder.build()); operationList.add(builder.build());
} }
try { try {
// 批量执行更新操作
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
if (results == null || results.length == 0 || results[0] == null) { if (results == null || results.length == 0 || results[0] == null) {
Log.d(TAG, "delete notes failed, ids:" + ids.toString()); // 更新失败,没有行影响
Log.d(TAG, "update notes failed, ids:" + ids.toString());
return false; return false;
} }
return true; return true;
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} catch (OperationApplicationException e) { } catch (OperationApplicationException e) {
// 执行更新操作出错
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} }
return false; return false;
} }
/** /**
* Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}} * {@link Notes#TYPE_SYSTEM}
* @param resolver
* @return int
*/ */
public static int getUserFolderCount(ContentResolver resolver) { public static int getUserFolderCount(ContentResolver resolver) {
// 查询不在垃圾文件夹(回收站)中的普通文件夹数量
Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI, Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { "COUNT(*)" }, new String[] { "COUNT(*)" },
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?", NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?",
@ -125,6 +172,7 @@ public class DataUtils {
if(cursor != null) { if(cursor != null) {
if(cursor.moveToFirst()) { if(cursor.moveToFirst()) {
try { try {
// 获取查询结果
count = cursor.getInt(0); count = cursor.getInt(0);
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
Log.e(TAG, "get folder count failed:" + e.toString()); Log.e(TAG, "get folder count failed:" + e.toString());
@ -136,9 +184,15 @@ public class DataUtils {
return count; return count;
} }
//通过ContentResolver查询判断便签是否存在 /**
* ID便
* @param resolver
* @param noteId ID
* @param type {@link NoteColumns#TYPE} 便
* @return true or false
*/
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) { public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
//查询便签,返回查询结果 // 通过resolver查询
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null,
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER, NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
@ -148,6 +202,7 @@ public class DataUtils {
boolean exist = false; boolean exist = false;
if (cursor != null) { if (cursor != null) {
if (cursor.getCount() > 0) { if (cursor.getCount() > 0) {
// 有查询结果,说明指定便签在数据库可见
exist = true; exist = true;
} }
cursor.close(); cursor.close();
@ -155,13 +210,21 @@ public class DataUtils {
return exist; return exist;
} }
/**
* 便ID便
* @param resolver
* @param noteId 便ID
* @return true or false
*/
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) { public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
// 查询
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null); null, null, null, null);
boolean exist = false; boolean exist = false;
if (cursor != null) { if (cursor != null) {
if (cursor.getCount() > 0) { if (cursor.getCount() > 0) {
// 有结果
exist = true; exist = true;
} }
cursor.close(); cursor.close();
@ -169,13 +232,21 @@ public class DataUtils {
return exist; return exist;
} }
/**
* ID{@link NotesDatabaseHelper.TABLE#DATA}
* @param resolver
* @param dataId ID
* @return true or false
*/
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) { public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
// 查询
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
null, null, null, null); null, null, null, null);
boolean exist = false; boolean exist = false;
if (cursor != null) { if (cursor != null) {
if (cursor.getCount() > 0) { if (cursor.getCount() > 0) {
// 有结果
exist = true; exist = true;
} }
cursor.close(); cursor.close();
@ -183,7 +254,14 @@ public class DataUtils {
return exist; return exist;
} }
/**
*
* @param resolver
* @param name
* @return true or false
*/
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) { public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
// 通过内容解析器查询
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null, Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
" AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER +
@ -192,6 +270,7 @@ public class DataUtils {
boolean exist = false; boolean exist = false;
if(cursor != null) { if(cursor != null) {
if(cursor.getCount() > 0) { if(cursor.getCount() > 0) {
// 查询有结果
exist = true; exist = true;
} }
cursor.close(); cursor.close();
@ -199,7 +278,14 @@ public class DataUtils {
return exist; return exist;
} }
/**
* ID便
* @param resolver
* @param folderId ID
* @return HashSet<AppWidgetAttribute>
*/
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) { public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
// 查询小部件ID和类型
Cursor c = resolver.query(Notes.CONTENT_NOTE_URI, Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE }, new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
NoteColumns.PARENT_ID + "=?", NoteColumns.PARENT_ID + "=?",
@ -210,11 +296,13 @@ public class DataUtils {
if (c != null) { if (c != null) {
if (c.moveToFirst()) { if (c.moveToFirst()) {
set = new HashSet<AppWidgetAttribute>(); set = new HashSet<AppWidgetAttribute>();
// 遍历查询到的所有小部件
do { do {
try { try {
AppWidgetAttribute widget = new AppWidgetAttribute(); AppWidgetAttribute widget = new AppWidgetAttribute();
widget.widgetId = c.getInt(0); widget.widgetId = c.getInt(0);
widget.widgetType = c.getInt(1); widget.widgetType = c.getInt(1);
// 加入小部件属性集合
set.add(widget); set.add(widget);
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
@ -226,7 +314,14 @@ public class DataUtils {
return set; return set;
} }
/**
* 便ID
* @param resolver
* @param noteId 便ID
* @return
*/
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) { public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
// 通过内容解析器查询电话号码
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.PHONE_NUMBER }, new String [] { CallNote.PHONE_NUMBER },
CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?", CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
@ -235,6 +330,7 @@ public class DataUtils {
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
try { try {
// 返回查询到的电话号码
return cursor.getString(0); return cursor.getString(0);
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call number fails " + e.toString()); Log.e(TAG, "Get call number fails " + e.toString());
@ -245,7 +341,15 @@ public class DataUtils {
return ""; return "";
} }
/**
* 便ID
* @param resolver
* @param phoneNumber
* @param callDate
* @return 便ID
*/
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) { public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
// 通过内容解析器查询
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.NOTE_ID }, new String [] { CallNote.NOTE_ID },
CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL(" CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
@ -256,6 +360,7 @@ public class DataUtils {
if (cursor != null) { if (cursor != null) {
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
try { try {
// 返回查询到的便签ID
return cursor.getLong(0); return cursor.getLong(0);
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call note id fails " + e.toString()); Log.e(TAG, "Get call note id fails " + e.toString());
@ -266,7 +371,14 @@ public class DataUtils {
return 0; return 0;
} }
/**
* ID便
* @param resolver
* @param noteId ID
* @return 便
*/
public static String getSnippetById(ContentResolver resolver, long noteId) { public static String getSnippetById(ContentResolver resolver, long noteId) {
// 通过内容解析器查询
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
new String [] { NoteColumns.SNIPPET }, new String [] { NoteColumns.SNIPPET },
NoteColumns.ID + "=?", NoteColumns.ID + "=?",
@ -276,19 +388,28 @@ public class DataUtils {
if (cursor != null) { if (cursor != null) {
String snippet = ""; String snippet = "";
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
// 返回查询结果
snippet = cursor.getString(0); snippet = cursor.getString(0);
} }
cursor.close(); cursor.close();
return snippet; return snippet;
} }
// 查询不到,抛出异常
throw new IllegalArgumentException("Note is not found with id: " + noteId); throw new IllegalArgumentException("Note is not found with id: " + noteId);
} }
/**
* snippet
*
* @param snippet 便
* @return
*/
public static String getFormattedSnippet(String snippet) { public static String getFormattedSnippet(String snippet) {
if (snippet != null) { if (snippet != null) {
snippet = snippet.trim(); snippet = snippet.trim();
int index = snippet.indexOf('\n'); int index = snippet.indexOf('\n');
if (index != -1) { if (index != -1) {
// 截取第一个换行符之前的字符串
snippet = snippet.substring(0, index); snippet = snippet.substring(0, index);
} }
} }

@ -16,6 +16,12 @@
package net.micode.notes.tool; package net.micode.notes.tool;
/**
* @author hzx
* 1.0
* 2023/10/29
* GTaskStringUtils google
*/
public class GTaskStringUtils { public class GTaskStringUtils {
public final static String GTASK_JSON_ACTION_ID = "action_id"; public final static String GTASK_JSON_ACTION_ID = "action_id";

@ -22,24 +22,43 @@ import android.preference.PreferenceManager;
import net.micode.notes.R; import net.micode.notes.R;
import net.micode.notes.ui.NotesPreferenceActivity; import net.micode.notes.ui.NotesPreferenceActivity;
/**
* @author hzx
* 1.0
* 2023/10/29
* ResourceParser
* IDID
*/
public class ResourceParser { public class ResourceParser {
/**
*
*/
public static final int YELLOW = 0; public static final int YELLOW = 0;
public static final int BLUE = 1; public static final int BLUE = 1;
public static final int WHITE = 2; public static final int WHITE = 2;
public static final int GREEN = 3; public static final int GREEN = 3;
public static final int RED = 4; public static final int RED = 4;
// 默认的颜色 黄色 0
public static final int BG_DEFAULT_COLOR = YELLOW; public static final int BG_DEFAULT_COLOR = YELLOW;
/**
*
*/
public static final int TEXT_SMALL = 0; public static final int TEXT_SMALL = 0;
public static final int TEXT_MEDIUM = 1; public static final int TEXT_MEDIUM = 1;
public static final int TEXT_LARGE = 2; public static final int TEXT_LARGE = 2;
public static final int TEXT_SUPER = 3; public static final int TEXT_SUPER = 3;
// 默认的字体大小 中等 1
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
/**
* 便
*/
public static class NoteBgResources { public static class NoteBgResources {
// 编辑界面背景资源数组
private final static int [] BG_EDIT_RESOURCES = new int [] { private final static int [] BG_EDIT_RESOURCES = new int [] {
R.drawable.edit_yellow, R.drawable.edit_yellow,
R.drawable.edit_blue, R.drawable.edit_blue,
@ -48,6 +67,7 @@ public class ResourceParser {
R.drawable.edit_red R.drawable.edit_red
}; };
// 编辑标题背景资源数组
private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] { private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] {
R.drawable.edit_title_yellow, R.drawable.edit_title_yellow,
R.drawable.edit_title_blue, R.drawable.edit_title_blue,
@ -56,25 +76,39 @@ public class ResourceParser {
R.drawable.edit_title_red R.drawable.edit_title_red
}; };
// 根据背景颜色ID获取便签背景资源ID
public static int getNoteBgResource(int id) { public static int getNoteBgResource(int id) {
return BG_EDIT_RESOURCES[id]; return BG_EDIT_RESOURCES[id];
} }
// 根据背景颜色ID获取便签标题背景资源ID
public static int getNoteTitleBgResource(int id) { public static int getNoteTitleBgResource(int id) {
return BG_EDIT_TITLE_RESOURCES[id]; return BG_EDIT_TITLE_RESOURCES[id];
} }
} }
/**
* ID
* @param context
* @return ID
*/
public static int getDefaultBgId(Context context) { public static int getDefaultBgId(Context context) {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean( if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) { NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
// 设置了随机背景颜色
// 返回一个随机背景颜色ID
return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length); return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length);
} else { } else {
// 返回默认的背景颜色ID
return BG_DEFAULT_COLOR; return BG_DEFAULT_COLOR;
} }
} }
/**
* 便
*/
public static class NoteItemBgResources { public static class NoteItemBgResources {
// 开头背景资源
private final static int [] BG_FIRST_RESOURCES = new int [] { private final static int [] BG_FIRST_RESOURCES = new int [] {
R.drawable.list_yellow_up, R.drawable.list_yellow_up,
R.drawable.list_blue_up, R.drawable.list_blue_up,
@ -83,6 +117,7 @@ public class ResourceParser {
R.drawable.list_red_up R.drawable.list_red_up
}; };
// 正常背景资源
private final static int [] BG_NORMAL_RESOURCES = new int [] { private final static int [] BG_NORMAL_RESOURCES = new int [] {
R.drawable.list_yellow_middle, R.drawable.list_yellow_middle,
R.drawable.list_blue_middle, R.drawable.list_blue_middle,
@ -91,6 +126,7 @@ public class ResourceParser {
R.drawable.list_red_middle R.drawable.list_red_middle
}; };
// 结尾背景资源
private final static int [] BG_LAST_RESOURCES = new int [] { private final static int [] BG_LAST_RESOURCES = new int [] {
R.drawable.list_yellow_down, R.drawable.list_yellow_down,
R.drawable.list_blue_down, R.drawable.list_blue_down,
@ -99,6 +135,7 @@ public class ResourceParser {
R.drawable.list_red_down, R.drawable.list_red_down,
}; };
// 单独的背景资源
private final static int [] BG_SINGLE_RESOURCES = new int [] { private final static int [] BG_SINGLE_RESOURCES = new int [] {
R.drawable.list_yellow_single, R.drawable.list_yellow_single,
R.drawable.list_blue_single, R.drawable.list_blue_single,
@ -107,28 +144,37 @@ public class ResourceParser {
R.drawable.list_red_single R.drawable.list_red_single
}; };
// 根据背景颜色ID获取开头背景资源ID
public static int getNoteBgFirstRes(int id) { public static int getNoteBgFirstRes(int id) {
return BG_FIRST_RESOURCES[id]; return BG_FIRST_RESOURCES[id];
} }
// 根据背景颜色ID获取结尾背景资源ID
public static int getNoteBgLastRes(int id) { public static int getNoteBgLastRes(int id) {
return BG_LAST_RESOURCES[id]; return BG_LAST_RESOURCES[id];
} }
// 根据背景颜色ID获取单独的背景资源ID
public static int getNoteBgSingleRes(int id) { public static int getNoteBgSingleRes(int id) {
return BG_SINGLE_RESOURCES[id]; return BG_SINGLE_RESOURCES[id];
} }
// 根据背景颜色ID获取普通背景资源ID
public static int getNoteBgNormalRes(int id) { public static int getNoteBgNormalRes(int id) {
return BG_NORMAL_RESOURCES[id]; return BG_NORMAL_RESOURCES[id];
} }
// 获取文件夹背景资源ID
public static int getFolderBgRes() { public static int getFolderBgRes() {
return R.drawable.list_folder; return R.drawable.list_folder;
} }
} }
/**
*
*/
public static class WidgetBgResources { public static class WidgetBgResources {
// 2x的小部件背景资源
private final static int [] BG_2X_RESOURCES = new int [] { private final static int [] BG_2X_RESOURCES = new int [] {
R.drawable.widget_2x_yellow, R.drawable.widget_2x_yellow,
R.drawable.widget_2x_blue, R.drawable.widget_2x_blue,
@ -137,10 +183,12 @@ public class ResourceParser {
R.drawable.widget_2x_red, R.drawable.widget_2x_red,
}; };
// 根据背景颜色ID获取小部件背景资源ID
public static int getWidget2xBgResource(int id) { public static int getWidget2xBgResource(int id) {
return BG_2X_RESOURCES[id]; return BG_2X_RESOURCES[id];
} }
// 4x的小部件背景资源
private final static int [] BG_4X_RESOURCES = new int [] { private final static int [] BG_4X_RESOURCES = new int [] {
R.drawable.widget_4x_yellow, R.drawable.widget_4x_yellow,
R.drawable.widget_4x_blue, R.drawable.widget_4x_blue,
@ -149,12 +197,17 @@ public class ResourceParser {
R.drawable.widget_4x_red R.drawable.widget_4x_red
}; };
// 根据背景颜色ID获取小部件背景资源ID
public static int getWidget4xBgResource(int id) { public static int getWidget4xBgResource(int id) {
return BG_4X_RESOURCES[id]; return BG_4X_RESOURCES[id];
} }
} }
/**
*
*/
public static class TextAppearanceResources { public static class TextAppearanceResources {
// 字体资源
private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] { private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
R.style.TextAppearanceNormal, R.style.TextAppearanceNormal,
R.style.TextAppearanceMedium, R.style.TextAppearanceMedium,
@ -162,18 +215,21 @@ public class ResourceParser {
R.style.TextAppearanceSuper R.style.TextAppearanceSuper
}; };
// 根据字体大小ID获取字体资源ID
public static int getTexAppearanceResource(int id) { public static int getTexAppearanceResource(int id) {
/** /**
* HACKME: Fix bug of store the resource id in shared preference. * HACKME: Fix bug of store the resource id in shared preference.
* The id may larger than the length of resources, in this case, * The id may larger than the length of resources, in this case,
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE} * return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
*/ */
// 防止数组索引越界
if (id >= TEXTAPPEARANCE_RESOURCES.length) { if (id >= TEXTAPPEARANCE_RESOURCES.length) {
return BG_DEFAULT_FONT_SIZE; return BG_DEFAULT_FONT_SIZE;
} }
return TEXTAPPEARANCE_RESOURCES[id]; return TEXTAPPEARANCE_RESOURCES[id];
} }
// 获取字体资源数组的长度
public static int getResourcesSize() { public static int getResourcesSize() {
return TEXTAPPEARANCE_RESOURCES.length; return TEXTAPPEARANCE_RESOURCES.length;
} }

@ -0,0 +1,101 @@
@startuml
title __TOOL's Class Diagram__\n
namespace net.micode.notes {
namespace tool {
class net.micode.notes.tool.BackupUtils {
}
}
}
namespace net.micode.notes {
namespace tool {
class net.micode.notes.tool.BackupUtils.TextExport {
}
}
}
namespace net.micode.notes {
namespace tool {
class net.micode.notes.tool.DataUtils {
}
}
}
namespace net.micode.notes {
namespace tool {
class net.micode.notes.tool.GTaskStringUtils {
}
}
}
namespace net.micode.notes {
namespace tool {
class net.micode.notes.tool.ResourceParser {
}
}
}
namespace net.micode.notes {
namespace tool {
class net.micode.notes.tool.ResourceParser.NoteBgResources {
}
}
}
namespace net.micode.notes {
namespace tool {
class net.micode.notes.tool.ResourceParser.NoteItemBgResources {
}
}
}
namespace net.micode.notes {
namespace tool {
class net.micode.notes.tool.ResourceParser.TextAppearanceResources {
}
}
}
namespace net.micode.notes {
namespace tool {
class net.micode.notes.tool.ResourceParser.WidgetBgResources {
}
}
}
net.micode.notes.tool.BackupUtils o-- net.micode.notes.tool.BackupUtils.TextExport : mTextExport
net.micode.notes.tool.BackupUtils +-down- net.micode.notes.tool.BackupUtils.TextExport
net.micode.notes.tool.ResourceParser +-down- net.micode.notes.tool.ResourceParser.NoteBgResources
net.micode.notes.tool.ResourceParser +-down- net.micode.notes.tool.ResourceParser.NoteItemBgResources
net.micode.notes.tool.ResourceParser +-down- net.micode.notes.tool.ResourceParser.TextAppearanceResources
net.micode.notes.tool.ResourceParser +-down- net.micode.notes.tool.ResourceParser.WidgetBgResources
right footer
PlantUML diagram generated by SketchIt! (https://bitbucket.org/pmesmeur/sketch.it)
For more information about this tool, please contact philippe.mesmeur@gmail.com
endfooter
@enduml

@ -0,0 +1,283 @@
@startuml
title __UI's Class Diagram__\n
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.AlarmAlertActivity {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.AlarmInitReceiver {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.AlarmReceiver {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.DateTimePicker {
}
}
}
namespace net.micode.notes {
namespace ui {
interface net.micode.notes.ui.DateTimePicker.OnDateTimeChangedListener {
{abstract} + onDateTimeChanged()
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.DateTimePickerDialog {
}
}
}
namespace net.micode.notes {
namespace ui {
interface net.micode.notes.ui.DateTimePickerDialog.OnDateTimeSetListener {
{abstract} + OnDateTimeSet()
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.DropdownMenu {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.FoldersListAdapter {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.FoldersListAdapter.FolderListItem {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.NoteEditActivity {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.NoteEditActivity.HeadViewHolder {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.NoteEditText {
}
}
}
namespace net.micode.notes {
namespace ui {
interface net.micode.notes.ui.NoteEditText.OnTextViewChangeListener {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.NoteItemData {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.NotesListActivity {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.NotesListActivity.BackgroundQueryHandler {
}
}
}
namespace net.micode.notes {
namespace ui {
enum ListEditState {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.NotesListActivity.ModeCallback {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.NotesListActivity.NewNoteOnTouchListener {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.NotesListActivity.OnListItemClickListener {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.NotesListAdapter {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.NotesListItem {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.NotesPreferenceActivity {
}
}
}
namespace net.micode.notes {
namespace ui {
class net.micode.notes.ui.NotesPreferenceActivity.GTaskReceiver {
}
}
}
net.micode.notes.ui.DateTimePicker o-- net.micode.notes.ui.DateTimePicker.OnDateTimeChangedListener : mOnDateTimeChangedListener
net.micode.notes.ui.DateTimePicker +-down- net.micode.notes.ui.DateTimePicker.OnDateTimeChangedListener
net.micode.notes.ui.DateTimePickerDialog o-- net.micode.notes.ui.DateTimePicker : mDateTimePicker
net.micode.notes.ui.DateTimePickerDialog o-- net.micode.notes.ui.DateTimePickerDialog.OnDateTimeSetListener : mOnDateTimeSetListener
net.micode.notes.ui.DateTimePickerDialog +-down- net.micode.notes.ui.DateTimePickerDialog.OnDateTimeSetListener
net.micode.notes.ui.FoldersListAdapter +-down- net.micode.notes.ui.FoldersListAdapter.FolderListItem
net.micode.notes.ui.NoteEditActivity .up.|> net.micode.notes.ui.NoteEditText.OnTextViewChangeListener
net.micode.notes.ui.NoteEditActivity o-- net.micode.notes.ui.NoteEditActivity.HeadViewHolder : mNoteHeaderHolder
net.micode.notes.ui.NoteEditActivity +-down- net.micode.notes.ui.NoteEditActivity.HeadViewHolder
net.micode.notes.ui.NoteEditText o-- net.micode.notes.ui.NoteEditText.OnTextViewChangeListener : mOnTextViewChangeListener
net.micode.notes.ui.NoteEditText +-down- net.micode.notes.ui.NoteEditText.OnTextViewChangeListener
net.micode.notes.ui.NotesListActivity o-- net.micode.notes.ui.NotesListActivity.BackgroundQueryHandler : mBackgroundQueryHandler
net.micode.notes.ui.NotesListActivity o-- net.micode.notes.ui.NoteItemData : mFocusNoteDataItem
net.micode.notes.ui.NotesListActivity o-- net.micode.notes.ui.NotesListActivity.ModeCallback : mModeCallBack
net.micode.notes.ui.NotesListActivity o-- net.micode.notes.ui.NotesListAdapter : mNotesListAdapter
net.micode.notes.ui.NotesListActivity o-- net.micode.notes.ui.NotesListActivity.ListEditState : mState
net.micode.notes.ui.NotesListActivity +-down- net.micode.notes.ui.NotesListActivity.BackgroundQueryHandler
net.micode.notes.ui.NotesListActivity +-down- net.micode.notes.ui.NotesListActivity.ListEditState
net.micode.notes.ui.NotesListActivity +-down- net.micode.notes.ui.NotesListActivity.ModeCallback
net.micode.notes.ui.NotesListActivity +-down- net.micode.notes.ui.NotesListActivity.NewNoteOnTouchListener
net.micode.notes.ui.NotesListActivity +-down- net.micode.notes.ui.NotesListActivity.OnListItemClickListener
net.micode.notes.ui.NotesListActivity.ModeCallback o-- net.micode.notes.ui.DropdownMenu : mDropDownMenu
net.micode.notes.ui.NotesListAdapter +-down- net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute
net.micode.notes.ui.NotesListItem o-- net.micode.notes.ui.NoteItemData : mItemData
net.micode.notes.ui.NotesPreferenceActivity o-- net.micode.notes.ui.NotesPreferenceActivity.GTaskReceiver : mReceiver
net.micode.notes.ui.NotesPreferenceActivity +-down- net.micode.notes.ui.NotesPreferenceActivity.GTaskReceiver
right footer
PlantUML diagram generated by SketchIt! (https://bitbucket.org/pmesmeur/sketch.it)
For more information about this tool, please contact philippe.mesmeur@gmail.com
endfooter
@enduml

@ -0,0 +1,61 @@
@startuml
title __WIDGET's Class Diagram__\n
namespace net.micode.notes {
namespace widget {
abstract class net.micode.notes.widget.NoteWidgetProvider {
{static} + COLUMN_BG_COLOR_ID : int
{static} + COLUMN_ID : int
{static} + COLUMN_SNIPPET : int
{static} + PROJECTION : String[]
{static} - TAG : String
+ onDeleted()
{abstract} # getBgResourceId()
{abstract} # getLayoutId()
{abstract} # getWidgetType()
# update()
- getNoteWidgetInfo()
- update()
}
}
}
namespace net.micode.notes {
namespace widget {
class net.micode.notes.widget.NoteWidgetProvider_2x {
+ onUpdate()
# getBgResourceId()
# getLayoutId()
# getWidgetType()
}
}
}
namespace net.micode.notes {
namespace widget {
class net.micode.notes.widget.NoteWidgetProvider_4x {
+ onUpdate()
# getBgResourceId()
# getLayoutId()
# getWidgetType()
}
}
}
net.micode.notes.widget.NoteWidgetProvider -up-|> android.appwidget.AppWidgetProvider
net.micode.notes.widget.NoteWidgetProvider_2x -up-|> net.micode.notes.widget.NoteWidgetProvider
net.micode.notes.widget.NoteWidgetProvider_4x -up-|> net.micode.notes.widget.NoteWidgetProvider
right footer
PlantUML diagram generated by SketchIt! (https://bitbucket.org/pmesmeur/sketch.it)
For more information about this tool, please contact philippe.mesmeur@gmail.com
endfooter
@enduml

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save