更改了部分注释

pull/6/head
AetherPendragon 3 weeks ago
parent 4cfeb6bfd5
commit 06711ccca6

@ -26,15 +26,19 @@ import android.util.Log;
import java.util.HashMap;
/**
*
*
*
* <p></p>
* <p>使</p>
*/
public class Contact {
/** 联系人缓存,用于提高查询效率 */
/** 联系人缓存,用于提高查询效率key 为原始电话号码字符串value 为联系人姓名 */
private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact";
/** 查询联系人的SQL选择语句用于匹配电话号码 */
/**
* SQL
* <p> PHONE_NUMBERS_EQUAL </p>
*/
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
+ ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
+ " AND " + Data.RAW_CONTACT_ID + " IN "
@ -43,26 +47,27 @@ public class Contact {
+ " WHERE min_match = '+')";
/**
*
* @param context
* @param phoneNumber
* @return null
*
*
* @param context 访 ContentResolver
* @param phoneNumber
* @return null
*/
public static String getContact(Context context, String phoneNumber) {
// 初始化缓存
// 初始化缓存:首次调用时创建,后续复用
if(sContactCache == null) {
sContactCache = new HashMap<String, String>();
}
// 先从缓存中查找
// 先从缓存中查找,命中则直接返回,避免再次访问数据库
if(sContactCache.containsKey(phoneNumber)) {
return sContactCache.get(phoneNumber);
}
// 构建查询选择语句,使用电话号码的最小匹配格式
// 构建查询条件:将占位符中的“+”替换为待查询号码的最小匹配值
String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
// 查询联系人数据库
// 查询联系人数据库,仅投影联系人显示名
Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI,
new String [] { Phone.DISPLAY_NAME },
@ -72,9 +77,9 @@ public class Contact {
if (cursor != null && cursor.moveToFirst()) {
try {
// 取联系人姓名
// 出第一条记录的联系人姓名
String name = cursor.getString(0);
// 将结果存入缓存
// 将结果存入缓存,便于下次直接复用
sContactCache.put(phoneNumber, name);
return name;
} catch (IndexOutOfBoundsException e) {

@ -19,8 +19,9 @@ package net.micode.notes.data;
import android.net.Uri;
/**
*
* IDURI
*
* <p> ContentProvider URI ID</p>
* <p>ProviderDatabaseHelperUI</p>
*/
public class Notes {
/** ContentProvider的授权标识 */
@ -34,10 +35,13 @@ public class Notes {
public static final int TYPE_SYSTEM = 2;
/**
* ID
* {@link Notes#ID_ROOT_FOLDER }
* {@link Notes#ID_TEMPARAY_FOLDER }
* {@link Notes#ID_CALL_RECORD_FOLDER}
* ID
* <ul>
* <li>{@link #ID_ROOT_FOLDER} </li>
* <li>{@link #ID_TEMPARAY_FOLDER} </li>
* <li>{@link #ID_CALL_RECORD_FOLDER} </li>
* <li>{@link #ID_TRASH_FOLER} </li>
* </ul>
*/
/** 根文件夹ID */
public static final int ID_ROOT_FOLDER = 0;
@ -62,9 +66,7 @@ public class Notes {
/** 4x4小部件类型 */
public static final int TYPE_WIDGET_4X = 1;
/**
*
*/
/** 数据类型常量,指明不同数据行的 MIME 类型 */
public static class DataConstants {
/** 普通笔记的MIME类型 */
public static final String NOTE = TextNote.CONTENT_ITEM_TYPE;
@ -72,121 +74,97 @@ public class Notes {
public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE;
}
/**
* URI
*/
/** 查询所有笔记和文件夹的URI */
public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note");
/**
* URI
*/
/** 查询数据表的URI */
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
/**
*
*/
/** 笔记表的列名接口,声明 note 表包含的所有字段 */
public interface NoteColumns {
/**
* ID
* <P> : INTEGER (long) </P>
* ID: INTEGER (long)
*/
public static final String ID = "_id";
/**
* ID
* <P> : INTEGER (long) </P>
* ID: INTEGER (long)
*/
public static final String PARENT_ID = "parent_id";
/**
*
* <P> : INTEGER (long) </P>
* : INTEGER (long)
*/
public static final String CREATED_DATE = "created_date";
/**
*
* <P> : INTEGER (long) </P>
* : INTEGER (long)
*/
public static final String MODIFIED_DATE = "modified_date";
/**
*
* <P> : INTEGER (long) </P>
* : INTEGER (long)
*/
public static final String ALERTED_DATE = "alert_date";
/**
*
* <P> : TEXT </P>
* : TEXT
*/
public static final String SNIPPET = "snippet";
/**
* ID
* <P> : INTEGER (long) </P>
* ID: INTEGER (long)
*/
public static final String WIDGET_ID = "widget_id";
/**
*
* <P> : INTEGER (long) </P>
* : INTEGER (long)
*/
public static final String WIDGET_TYPE = "widget_type";
/**
* ID
* <P> : INTEGER (long) </P>
* ID: INTEGER (long)
*/
public static final String BG_COLOR_ID = "bg_color_id";
/**
*
*
* <P> : INTEGER </P>
* : INTEGER
*/
public static final String HAS_ATTACHMENT = "has_attachment";
/**
*
* <P> : INTEGER (long) </P>
* : INTEGER (long)
*/
public static final String NOTES_COUNT = "notes_count";
/**
*
* <P> : INTEGER </P>
* : INTEGER
*/
public static final String TYPE = "type";
/**
* ID
* <P> : INTEGER (long) </P>
* ID: INTEGER (long)
*/
public static final String SYNC_ID = "sync_id";
/**
*
* <P> : INTEGER </P>
* : INTEGER
*/
public static final String LOCAL_MODIFIED = "local_modified";
/**
* ID
* <P> : INTEGER </P>
* ID: INTEGER
*/
public static final String ORIGIN_PARENT_ID = "origin_parent_id";
/**
* Google TaskID
* <P> : TEXT </P>
* Google TaskID: TEXT
*/
public static final String GTASK_ID = "gtask_id";
/**
*
* <P> : INTEGER (long) </P>
* : INTEGER (long)
*/
public static final String VERSION = "version";
}
@ -196,69 +174,58 @@ public class Notes {
*/
public interface DataColumns {
/**
* ID
* <P> : INTEGER (long) </P>
* ID: INTEGER (long)
*/
public static final String ID = "_id";
/**
* MIME
* <P> : Text </P>
* MIME: TEXT
*/
public static final String MIME_TYPE = "mime_type";
/**
* ID
* <P> : INTEGER (long) </P>
* ID: INTEGER (long)
*/
public static final String NOTE_ID = "note_id";
/**
*
* <P> : INTEGER (long) </P>
* : INTEGER (long)
*/
public static final String CREATED_DATE = "created_date";
/**
*
* <P> : INTEGER (long) </P>
* : INTEGER (long)
*/
public static final String MODIFIED_DATE = "modified_date";
/**
*
* <P> : TEXT </P>
* : TEXT
*/
public static final String CONTENT = "content";
/**
* 1{@link #MIME_TYPE}
* <P> : INTEGER </P>
* 1{@link #MIME_TYPE}: INTEGER
*/
public static final String DATA1 = "data1";
/**
* 2{@link #MIME_TYPE}
* <P> : INTEGER </P>
* 2{@link #MIME_TYPE}: INTEGER
*/
public static final String DATA2 = "data2";
/**
* 3{@link #MIME_TYPE}TEXT
* <P> : TEXT </P>
* 3{@link #MIME_TYPE}TEXT: TEXT
*/
public static final String DATA3 = "data3";
/**
* 4{@link #MIME_TYPE}TEXT
* <P> : TEXT </P>
* 4{@link #MIME_TYPE}TEXT: TEXT
*/
public static final String DATA4 = "data4";
/**
* 5{@link #MIME_TYPE}TEXT
* <P> : TEXT </P>
* 5{@link #MIME_TYPE}TEXT: TEXT
*/
public static final String DATA5 = "data5";
}
@ -268,8 +235,7 @@ public class Notes {
*/
public static final class TextNote implements DataColumns {
/**
*
* <P> : Integer 1: 0: </P>
* : Integer1 0
*/
public static final String MODE = DATA1;
@ -291,14 +257,12 @@ public class Notes {
*/
public static final class CallNote implements DataColumns {
/**
*
* <P> : INTEGER (long) </P>
* : INTEGER (long)
*/
public static final String CALL_DATE = DATA1;
/**
*
* <P> : TEXT </P>
* : TEXT
*/
public static final String PHONE_NUMBER = DATA3;

@ -27,8 +27,9 @@ import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns;
/**
*
* SQLite
*
* <p> SQLite note/data </p>
* <p>使 {@link #getInstance(Context)} ContentProvider 使</p>
*/
public class NotesDatabaseHelper extends SQLiteOpenHelper {
/** 数据库名称 */
@ -93,9 +94,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
"CREATE INDEX IF NOT EXISTS note_id_index ON " +
TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";
/**
*
*/
/** 触发器:当笔记移动到文件夹时,增加目标文件夹的笔记计数 */
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_update "+
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
@ -105,9 +104,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" +
" END";
/**
*
*/
/** 触发器:当笔记从文件夹移出时,减少原文件夹的笔记计数 */
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_update " +
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
@ -118,9 +115,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" AND " + NoteColumns.NOTES_COUNT + ">0" + ";" +
" END";
/**
*
*/
/** 触发器:向某文件夹插入新笔记时,增加该文件夹的计数 */
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_insert " +
" AFTER INSERT ON " + TABLE.NOTE +
@ -130,9 +125,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" +
" END";
/**
*
*/
/** 触发器:删除笔记时,减少其父文件夹的计数 */
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_delete " +
" AFTER DELETE ON " + TABLE.NOTE +
@ -143,9 +136,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" AND " + NoteColumns.NOTES_COUNT + ">0;" +
" END";
/**
* {@link DataConstants#NOTE}
*/
/** 触发器:插入 TEXT_NOTE 类型的数据行时,用数据内容刷新 note.snippet */
private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER =
"CREATE TRIGGER update_note_content_on_insert " +
" AFTER INSERT ON " + TABLE.DATA +
@ -156,9 +147,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" +
" END";
/**
* {@link DataConstants#NOTE}
*/
/** 触发器:更新 TEXT_NOTE 数据行时,同步更新 note.snippet */
private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER update_note_content_on_update " +
" AFTER UPDATE ON " + TABLE.DATA +
@ -169,9 +158,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" +
" END";
/**
* {@link DataConstants#NOTE}
*/
/** 触发器:删除 TEXT_NOTE 数据行时,清空 note.snippet */
private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER =
"CREATE TRIGGER update_note_content_on_delete " +
" AFTER delete ON " + TABLE.DATA +
@ -182,9 +169,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.ID + "=old." + DataColumns.NOTE_ID + ";" +
" END";
/**
*
*/
/** 触发器:删除笔记时,级联删除 data 表中对应数据 */
private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER =
"CREATE TRIGGER delete_data_on_delete " +
" AFTER DELETE ON " + TABLE.NOTE +
@ -193,9 +178,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + DataColumns.NOTE_ID + "=old." + NoteColumns.ID + ";" +
" END";
/**
*
*/
/** 触发器:删除文件夹时,级联删除该文件夹下的笔记 */
private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER =
"CREATE TRIGGER folder_delete_notes_on_delete " +
" AFTER DELETE ON " + TABLE.NOTE +
@ -204,9 +187,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
" END";
/**
*
*/
/** 触发器:移动文件夹到回收站时,其子笔记也同步移动到回收站 */
private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER =
"CREATE TRIGGER folder_move_notes_on_trash " +
" AFTER UPDATE ON " + TABLE.NOTE +
@ -218,7 +199,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
*
*
*
* @param context
*/
public NotesDatabaseHelper(Context context) {
@ -226,7 +208,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
*
*
*
* @param db
*/
public void createNoteTable(SQLiteDatabase db) {
@ -237,7 +220,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
*
*
* <p></p>
*
* @param db
*/
private void reCreateNoteTableTriggers(SQLiteDatabase db) {
@ -259,38 +244,32 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
*
*
* <p></p>
*
* @param db
*/
private void createSystemFolder(SQLiteDatabase db) {
ContentValues values = new ContentValues();
/**
*
*/
// 创建通话记录文件夹
values.put(NoteColumns.ID, Notes.ID_CALL_RECORD_FOLDER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
db.insert(TABLE.NOTE, null, values);
/**
*
*/
// 创建根文件夹(默认文件夹)
values.clear();
values.put(NoteColumns.ID, Notes.ID_ROOT_FOLDER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
db.insert(TABLE.NOTE, null, values);
/**
*
*/
// 创建临时文件夹(用于移动笔记)
values.clear();
values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
db.insert(TABLE.NOTE, null, values);
/**
*
*/
// 创建回收站文件夹
values.clear();
values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
@ -298,7 +277,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
*
*
*
* @param db
*/
public void createDataTable(SQLiteDatabase db) {
@ -309,7 +289,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
*
*
*
* @param db
*/
private void reCreateDataTableTriggers(SQLiteDatabase db) {
@ -323,7 +304,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
*
*
*
* @param context
* @return
*/
@ -334,9 +316,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
return mInstance;
}
/**
*
*/
/** 创建数据库:依次创建 note 表与 data 表 */
@Override
public void onCreate(SQLiteDatabase db) {
createNoteTable(db);
@ -344,7 +324,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
*
*
* <p></p>
*/
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
@ -380,7 +361,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
* 2
* 2
*
* @param db
*/
private void upgradeToV2(SQLiteDatabase db) {
@ -391,7 +373,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
* 3
* 3 gtask_id
*
* @param db
*/
private void upgradeToV3(SQLiteDatabase db) {
@ -410,7 +393,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
* 4
* 4 note version
*
* @param db
*/
private void upgradeToV4(SQLiteDatabase db) {

@ -35,13 +35,14 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
/**
*
* CRUD
*
* <p> CRUD URI </p>
* <p>使UI ContentResolver 访 Provider</p>
*/
public class NotesProvider extends ContentProvider {
private static final UriMatcher mMatcher;
/** 数据库帮助类实例 */
/** 数据库帮助类实例,负责获取读写数据库 */
private NotesDatabaseHelper mHelper;
private static final String TAG = "NotesProvider";
@ -72,9 +73,8 @@ public class NotesProvider extends ContentProvider {
}
/**
*
* x'0A'SQLite'\n'
* '\n'便
*
* <p>x'0A' SQLite 便</p>
*/
private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + ","
+ NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + ","
@ -91,7 +91,7 @@ public class NotesProvider extends ContentProvider {
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
/**
* ContentProvider
* ContentProvider
*/
@Override
public boolean onCreate() {
@ -100,7 +100,8 @@ public class NotesProvider extends ContentProvider {
}
/**
*
*
* <p> note/data </p>
*/
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
@ -159,6 +160,7 @@ public class NotesProvider extends ContentProvider {
throw new IllegalArgumentException("Unknown URI " + uri);
}
if (c != null) {
// 通知游标所关联的 URI用于后续数据变更时自动刷新
c.setNotificationUri(getContext().getContentResolver(), uri);
}
return c;
@ -186,13 +188,13 @@ public class NotesProvider extends ContentProvider {
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
// 通知笔记URI的变化
// 通知笔记 URI 变化noteId>0 时)
if (noteId > 0) {
getContext().getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);
}
// 通知数据URI的变化
// 通知数据 URI 变化dataId>0 时)
if (dataId > 0) {
getContext().getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);
@ -202,7 +204,8 @@ public class NotesProvider extends ContentProvider {
}
/**
*
*
* <p>ID<=0data note UI</p>
*/
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
@ -242,6 +245,7 @@ public class NotesProvider extends ContentProvider {
}
if (count > 0) {
if (deleteData) {
// 数据行删除会影响笔记摘要,通知笔记 URI
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
}
getContext().getContentResolver().notifyChange(uri, null);
@ -250,7 +254,8 @@ public class NotesProvider extends ContentProvider {
}
/**
*
*
* <p> note version 便data note </p>
*/
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
@ -285,6 +290,7 @@ public class NotesProvider extends ContentProvider {
if (count > 0) {
if (updateData) {
// 数据行更新影响笔记摘要,通知笔记 URI
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
}
getContext().getContentResolver().notifyChange(uri, null);
@ -293,7 +299,8 @@ public class NotesProvider extends ContentProvider {
}
/**
*
* WHERE selection AND (...)
*
* @param selection
* @return
*/
@ -302,8 +309,9 @@ public class NotesProvider extends ContentProvider {
}
/**
*
* @param id ID0
*
*
* @param id ID0ID使 selection
* @param selection
* @param selectionArgs
*/
@ -333,7 +341,8 @@ public class NotesProvider extends ContentProvider {
}
/**
* URIMIME
* URI MIME
* <p>使 null</p>
*/
@Override
public String getType(Uri uri) {

@ -34,23 +34,25 @@ import net.micode.notes.data.Notes.TextNote;
import java.util.ArrayList;
/**
*
*
*
* <p>note data </p>
* <p>UI/ {@link #syncNote(Context, long)} </p>
*/
public class Note {
/** 笔记差异值,用于记录笔记的修改 */
/** 笔记差异值,用于记录笔记的修改字段(增量更新) */
private ContentValues mNoteDiffValues;
/** 笔记数据对象 */
/** 笔记数据对象,负责文本与通话相关的数据行 */
private NoteData mNoteData;
private static final String TAG = "Note";
/**
* ID
* ID
*
* @param context
* @param folderId ID
* @return ID
* @param folderId ID
* @return ID>00
*/
public static synchronized long getNewNoteId(Context context, long folderId) {
// 在数据库中创建新笔记
// 在数据库中创建新笔记:设置创建/修改时间、类型、父文件夹等初始值
ContentValues values = new ContentValues();
long createdTime = System.currentTimeMillis();
values.put(NoteColumns.CREATED_DATE, createdTime);
@ -74,7 +76,7 @@ public class Note {
}
/**
*
*
*/
public Note() {
mNoteDiffValues = new ContentValues();
@ -82,7 +84,8 @@ public class Note {
}
/**
*
*
*
* @param key
* @param value
*/
@ -93,7 +96,8 @@ public class Note {
}
/**
*
* data
*
* @param key
* @param value
*/
@ -102,7 +106,8 @@ public class Note {
}
/**
* ID
* ID
*
* @param id ID
*/
public void setTextDataId(long id) {
@ -110,7 +115,8 @@ public class Note {
}
/**
* ID
* ID
*
* @return ID
*/
public long getTextDataId() {
@ -118,7 +124,8 @@ public class Note {
}
/**
* ID
* ID
*
* @param id ID
*/
public void setCallDataId(long id) {
@ -126,7 +133,8 @@ public class Note {
}
/**
*
* data
*
* @param key
* @param value
*/
@ -135,18 +143,20 @@ public class Note {
}
/**
*
* @return truefalse
*
*
* @return true
*/
public boolean isLocalModified() {
return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified();
}
/**
*
*
*
* @param context
* @param noteId ID
* @return truefalse
* @return true false
*/
public boolean syncNote(Context context, long noteId) {
if (noteId <= 0) {
@ -157,11 +167,7 @@ public class Note {
return true;
}
/**
* {@link NoteColumns#LOCAL_MODIFIED}
* {@link NoteColumns#MODIFIED_DATE}使
*
*/
// 理论上任何变更都应更新 LOCAL_MODIFIED 与 MODIFIED_DATE即便 note 表更新失败,也继续尝试写 data
if (context.getContentResolver().update(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), mNoteDiffValues, null,
null) == 0) {
@ -179,8 +185,8 @@ public class Note {
}
/**
*
*
*
* <p> data </p>
*/
private class NoteData {
/** 文本数据ID */
@ -197,9 +203,7 @@ public class Note {
private static final String TAG = "NoteData";
/**
*
*/
/** 构造函数:初始化两个数据集与对应 ID */
public NoteData() {
mTextDataValues = new ContentValues();
mCallDataValues = new ContentValues();
@ -208,17 +212,15 @@ public class Note {
}
/**
*
* @return true
* data
*
* @return true
*/
boolean isLocalModified() {
return mTextDataValues.size() > 0 || mCallDataValues.size() > 0;
}
/**
* ID
* @param id ID
*/
/** 设置文本数据ID必须大于0 */
void setTextDataId(long id) {
if(id <= 0) {
throw new IllegalArgumentException("Text data id should larger than 0");
@ -226,10 +228,7 @@ public class Note {
mTextDataId = id;
}
/**
* ID
* @param id ID
*/
/** 设置通话数据ID必须大于0 */
void setCallDataId(long id) {
if (id <= 0) {
throw new IllegalArgumentException("Call data id should larger than 0");
@ -238,7 +237,8 @@ public class Note {
}
/**
*
* note
*
* @param key
* @param value
*/
@ -249,7 +249,8 @@ public class Note {
}
/**
*
* note
*
* @param key
* @param value
*/
@ -260,15 +261,14 @@ public class Note {
}
/**
* ContentResolver
* ContentResolver
*
* @param context
* @param noteId ID
* @return URInull
* @return URI null
*/
Uri pushIntoContentResolver(Context context, long noteId) {
/**
*
*/
// 安全检查
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId);
}
@ -277,6 +277,7 @@ public class Note {
ContentProviderOperation.Builder builder = null;
if(mTextDataValues.size() > 0) {
// 写入或更新文本数据MIME: text_note
mTextDataValues.put(DataColumns.NOTE_ID, noteId);
if (mTextDataId == 0) {
mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE);
@ -299,6 +300,7 @@ public class Note {
}
if(mCallDataValues.size() > 0) {
// 写入或更新通话数据MIME: call_note
mCallDataValues.put(DataColumns.NOTE_ID, noteId);
if (mCallDataId == 0) {
mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE);

@ -32,11 +32,12 @@ import net.micode.notes.data.Notes.TextNote;
import net.micode.notes.tool.ResourceParser.NoteBgResources;
/**
*
*
*
* <p>/</p>
* <p>使</p>
*/
public class WorkingNote {
/** 笔记对象 */
/** 底层笔记数据模型,负责具体增量同步 */
private Note mNote;
/** 笔记ID */
private long mNoteId;
@ -114,7 +115,8 @@ public class WorkingNote {
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
/**
*
*
*
* @param context
* @param folderId ID
*/
@ -131,7 +133,8 @@ public class WorkingNote {
}
/**
*
*
*
* @param context
* @param noteId ID
* @param folderId ID
@ -146,7 +149,8 @@ public class WorkingNote {
}
/**
*
* note
* data
*/
private void loadNote() {
Cursor cursor = mContext.getContentResolver().query(
@ -171,7 +175,8 @@ public class WorkingNote {
}
/**
*
* data
* <p>NOTECALL_NOTEID</p>
*/
private void loadNoteData() {
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
@ -202,12 +207,13 @@ public class WorkingNote {
}
/**
*
*
*
* @param context
* @param folderId ID
* @param widgetId ID
* @param folderId ID
* @param widgetId ID
* @param widgetType
* @param defaultBgColorId ID
* @param defaultBgColorId
* @return
*/
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
@ -220,7 +226,8 @@ public class WorkingNote {
}
/**
*
* ID
*
* @param context
* @param id ID
* @return
@ -230,7 +237,8 @@ public class WorkingNote {
}
/**
*
* note/data
*
* @return truefalse
*/
public synchronized boolean saveNote() {
@ -244,9 +252,7 @@ public class WorkingNote {
mNote.syncNote(mContext, mNoteId);
/**
*
*/
// 如果该笔记存在小部件,更新小部件内容
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE
&& mNoteSettingStatusListener != null) {
@ -259,7 +265,7 @@ public class WorkingNote {
}
/**
*
* noteId>0
* @return true
*/
public boolean existInDatabase() {
@ -267,7 +273,8 @@ public class WorkingNote {
}
/**
*
*
* <p></p>
* @return true
*/
private boolean isWorthSaving() {
@ -280,7 +287,7 @@ public class WorkingNote {
}
/**
*
* UI
* @param l
*/
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
@ -288,7 +295,7 @@ public class WorkingNote {
}
/**
*
*
* @param date
* @param set
*/
@ -303,7 +310,7 @@ public class WorkingNote {
}
/**
*
*
* @param mark
*/
public void markDeleted(boolean mark) {
@ -315,7 +322,7 @@ public class WorkingNote {
}
/**
* ID
*
* @param id ID
*/
public void setBgColorId(int id) {
@ -329,8 +336,8 @@ public class WorkingNote {
}
/**
*
* @param mode 01
*
* @param mode 0 1
*/
public void setCheckListMode(int mode) {
if (mMode != mode) {
@ -342,10 +349,7 @@ public class WorkingNote {
}
}
/**
*
* @param type
*/
/** 设置小部件类型,并记录本地修改 */
public void setWidgetType(int type) {
if (type != mWidgetType) {
mWidgetType = type;
@ -353,10 +357,7 @@ public class WorkingNote {
}
}
/**
* ID
* @param id ID
*/
/** 设置小部件ID并记录本地修改 */
public void setWidgetId(int id) {
if (id != mWidgetId) {
mWidgetId = id;
@ -365,7 +366,7 @@ public class WorkingNote {
}
/**
*
* data
* @param text
*/
public void setWorkingText(String text) {
@ -376,7 +377,7 @@ public class WorkingNote {
}
/**
*
*
* @param phoneNumber
* @param callDate
*/
@ -387,7 +388,7 @@ public class WorkingNote {
}
/**
*
*
* @return true
*/
public boolean hasClockAlert() {
@ -438,9 +439,7 @@ public class WorkingNote {
return mWidgetType;
}
/**
*
*/
/** 笔记设置变化监听器接口 */
public interface NoteSettingChangedListener {
/**
*

@ -36,8 +36,9 @@ import java.io.IOException;
import java.io.PrintStream;
/**
*
*
*
* <p> UI </p>
* <p></p>
*/
public class BackupUtils {
private static final String TAG = "BackupUtils";
@ -45,7 +46,8 @@ public class BackupUtils {
private static BackupUtils sInstance;
/**
*
*
*
* @param context
* @return
*/
@ -56,9 +58,7 @@ public class BackupUtils {
return sInstance;
}
/**
*
*/
/** 备份或恢复状态常量 */
/** SD卡未挂载 */
public static final int STATE_SD_CARD_UNMOUONTED = 0;
/** 备份文件不存在 */
@ -73,16 +73,13 @@ public class BackupUtils {
/** 文本导出对象 */
private TextExport mTextExport;
/**
*
* @param context
*/
/** 私有构造:初始化文本导出器 */
private BackupUtils(Context context) {
mTextExport = new TextExport(context);
}
/**
*
*
* @return true
*/
private static boolean externalStorageAvailable() {
@ -90,15 +87,15 @@ public class BackupUtils {
}
/**
*
* @return
*
* @return
*/
public int exportToText() {
return mTextExport.exportToText();
}
/**
*
*
* @return
*/
public String getExportedTextFileName() {
@ -106,7 +103,7 @@ public class BackupUtils {
}
/**
*
*
* @return
*/
public String getExportedTextFileDir() {
@ -114,7 +111,7 @@ public class BackupUtils {
}
/**
*
* note/data SD txt
*/
private static class TextExport {
private static final String[] NOTE_PROJECTION = {
@ -167,9 +164,7 @@ public class BackupUtils {
return TEXT_FORMAT[id];
}
/**
* Export the folder identified by folder id to text
*/
/** 将指定文件夹下的笔记导出为文本 */
private void exportFolderToText(String folderId, PrintStream ps) {
// Query notes belong to this folder
Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI,
@ -193,9 +188,7 @@ public class BackupUtils {
}
}
/**
* Export note identified by id to a print stream
*/
/** 将指定 noteId 的笔记数据写入输出流 */
private void exportNoteToText(String noteId, PrintStream ps) {
Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI,
DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] {
@ -246,9 +239,7 @@ public class BackupUtils {
}
}
/**
* Note will be exported as text which is user readable
*/
/** 导出所有文件夹及根目录笔记为文本文件 */
public int exportToText() {
if (!externalStorageAvailable()) {
Log.d(TAG, "Media was not mounted");
@ -313,9 +304,7 @@ public class BackupUtils {
return STATE_SUCCESS;
}
/**
* Get a print stream pointed to the file {@generateExportedTextFile}
*/
/** 创建指向导出文件的 PrintStream失败返回 null */
private PrintStream getExportToTextPrintStream() {
File file = generateFileMountedOnSDcard(mContext, R.string.file_path,
R.string.file_name_txt_format);
@ -340,9 +329,7 @@ public class BackupUtils {
}
}
/**
* Generate the text file to store imported data
*/
/** 生成存储导出内容的文件,位于 SD 卡指定目录下 */
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
StringBuilder sb = new StringBuilder();
sb.append(Environment.getExternalStorageDirectory());

@ -35,14 +35,16 @@ import java.util.ArrayList;
import java.util.HashSet;
/**
*
*
*
* <p></p>
* <p>使// note data </p>
*/
public class DataUtils {
public static final String TAG = "DataUtils";
/**
*
*
*
* @param resolver ContentResolver
* @param ids ID
* @return truefalse
@ -82,13 +84,7 @@ public class DataUtils {
return false;
}
/**
*
* @param resolver ContentResolver
* @param id ID
* @param srcFolderId ID
* @param desFolderId ID
*/
/** 单条笔记移动到文件夹记录原父ID并打本地修改标记 */
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
ContentValues values = new ContentValues();
values.put(NoteColumns.PARENT_ID, desFolderId);
@ -98,7 +94,8 @@ public class DataUtils {
}
/**
*
*
*
* @param resolver ContentResolver
* @param ids ID
* @param folderId ID
@ -135,9 +132,7 @@ public class DataUtils {
return false;
}
/**
* Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}}
*/
/** 获取用户文件夹数量(排除系统文件夹与回收站) */
public static int getUserFolderCount(ContentResolver resolver) {
Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { "COUNT(*)" },
@ -160,6 +155,7 @@ public class DataUtils {
return count;
}
/** 判断指定类型的笔记是否存在且未在回收站 */
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null,
@ -177,6 +173,7 @@ public class DataUtils {
return exist;
}
/** 判断指定 noteId 是否存在于 note 表 */
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null);
@ -191,6 +188,7 @@ public class DataUtils {
return exist;
}
/** 判断指定 dataId 是否存在于 data 表 */
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
null, null, null, null);
@ -205,6 +203,7 @@ public class DataUtils {
return exist;
}
/** 校验可见文件夹名称是否已存在(排除回收站内) */
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
@ -221,6 +220,7 @@ public class DataUtils {
return exist;
}
/** 获取某文件夹下所有笔记绑定的小部件属性集合 */
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
@ -248,6 +248,7 @@ public class DataUtils {
return set;
}
/** 根据 noteId 读取通话笔记的电话号码,未找到则返回空串 */
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.PHONE_NUMBER },
@ -267,6 +268,7 @@ public class DataUtils {
return "";
}
/** 根据号码与通话日期查找对应的通话记录笔记ID未找到返回0 */
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.NOTE_ID },
@ -288,6 +290,7 @@ public class DataUtils {
return 0;
}
/** 根据 noteId 获取摘要字段,找不到则抛出异常 */
public static String getSnippetById(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
new String [] { NoteColumns.SNIPPET },
@ -306,6 +309,7 @@ public class DataUtils {
throw new IllegalArgumentException("Note is not found with id: " + noteId);
}
/** 对摘要进行格式化:去首尾空格并截断首个换行后的内容 */
public static String getFormattedSnippet(String snippet) {
if (snippet != null) {
snippet = snippet.trim();

@ -17,8 +17,9 @@
package net.micode.notes.tool;
/**
* Google Task
* Google Task
* Google Task
* <p> GTask 使 JSON </p>
* <p>使 GTask JSON </p>
*/
public class GTaskStringUtils {

@ -23,8 +23,9 @@ import net.micode.notes.R;
import net.micode.notes.ui.NotesPreferenceActivity;
/**
*
*
*
* <p></p>
* <p>使UI / ID drawable style </p>
*/
public class ResourceParser {
@ -54,9 +55,7 @@ public class ResourceParser {
/** 默认字体大小 */
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
/**
*
*/
/** 笔记背景资源类:提供编辑区域及标题栏的背景资源映射 */
public static class NoteBgResources {
private final static int [] BG_EDIT_RESOURCES = new int [] {
R.drawable.edit_yellow,
@ -74,27 +73,20 @@ public class ResourceParser {
R.drawable.edit_title_red
};
/**
* ID
* @param id ID
* @return ID
*/
/** 获取笔记编辑背景资源ID */
public static int getNoteBgResource(int id) {
return BG_EDIT_RESOURCES[id];
}
/**
* ID
* @param id ID
* @return ID
*/
/** 获取笔记标题背景资源ID */
public static int getNoteTitleBgResource(int id) {
return BG_EDIT_TITLE_RESOURCES[id];
}
}
/**
* ID
* ID使
*
* @param context
* @return ID
*/
@ -195,12 +187,11 @@ public class ResourceParser {
R.style.TextAppearanceSuper
};
/**
* ID
* <p> SharedPreferences index 退</p>
*/
public static int getTexAppearanceResource(int id) {
/**
* HACKME: Fix bug of store the resource id in shared preference.
* The id may larger than the length of resources, in this case,
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
*/
if (id >= TEXTAPPEARANCE_RESOURCES.length) {
return BG_DEFAULT_FONT_SIZE;
}

@ -78,6 +78,11 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
/**
* Activity
* <p>/</p>
* <p>//</p>
*/
public class NotesListActivity extends Activity implements OnClickListener, OnItemLongClickListener {
private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0;
@ -91,6 +96,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction";
/**
*
* NOTE_LIST SUB_FOLDER CALL_RECORD_FOLDER
*/
private enum ListEditState {
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
};
@ -141,9 +150,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
setContentView(R.layout.note_list);
initResources();
/**
* Insert an introduction when user firstly use this application
*/
// 首次进入时插入“介绍”笔记
setAppInfoFromRawRes();
}
@ -356,22 +363,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
int newNoteViewHeight = mAddNewNote.getHeight();
int start = screenHeight - newNoteViewHeight;
int eventY = start + (int) event.getY();
/**
* Minus TitleBar's height
*/
// 子文件夹状态需减去标题栏高度
if (mState == ListEditState.SUB_FOLDER) {
eventY -= mTitleBar.getHeight();
start -= mTitleBar.getHeight();
}
/**
* HACKME:When click the transparent part of "New Note" button, dispatch
* the event to the list view behind this button. The transparent part of
* "New Note" button could be expressed by formula y=-0.12x+94Unit:pixel
* and the line top of the button. The coordinate based on left of the "New
* Note" button. The 94 represents maximum height of the transparent part.
* Notice that, if the background of the button changes, the formula should
* also change. This is very bad, just for the UI designer's strong requirement.
*/
// HACKME: 点击“新建”按钮透明区时,将事件派发给下方列表。
// 透明区近似线性公式 y = -0.12x + 94px背景改动需同步更新该公式。
if (event.getY() < (event.getX() * (-0.12) + 94)) {
View view = mNotesListView.getChildAt(mNotesListView.getChildCount() - 1
- mNotesListView.getFooterViewsCount());

@ -31,14 +31,14 @@ import java.util.HashSet;
import java.util.Iterator;
/**
*
* ListView
*
* <p>//</p>
*/
public class NotesListAdapter extends CursorAdapter {
private static final String TAG = "NotesListAdapter";
/** 上下文对象 */
private Context mContext;
/** 选中的索引映射 */
/** 选中的索引映射position -> 是否选中) */
private HashMap<Integer, Boolean> mSelectedIndex;
/** 笔记数量 */
private int mNotesCount;

@ -48,8 +48,9 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.gtask.remote.GTaskSyncService;
/**
*
*
*
* <p>/GTask </p>
* <p> gtask 广</p>
*/
public class NotesPreferenceActivity extends PreferenceActivity {
public static final String PREFERENCE_NAME = "notes_preferences";
@ -76,7 +77,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
/* using the app icon for navigation */
// ActionBar 返回上一层
getActionBar().setDisplayHomeAsUpEnabled(true);
addPreferencesFromResource(R.xml.preferences);
@ -95,8 +96,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
protected void onResume() {
super.onResume();
// need to set sync account automatically if user has added a new
// account
// 若用户刚新增了 Google 账号,自动选中新账号为同步账号
if (mHasAddedAccount) {
Account[] accounts = getGoogleAccounts();
if (mOriAccounts != null && accounts.length > mOriAccounts.length) {
@ -136,13 +136,12 @@ public class NotesPreferenceActivity extends PreferenceActivity {
accountPref.setSummary(getString(R.string.preferences_account_summary));
accountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
if (!GTaskSyncService.isSyncing()) {
if (!GTaskSyncService.isSyncing()) { // 同步中禁止切换账号
if (TextUtils.isEmpty(defaultAccount)) {
// the first time to set account
// 首次设置账户
showSelectAccountAlertDialog();
} else {
// if the account has already been set, we need to promp
// user about the risk
// 已绑定过账号,提示更换风险
showChangeAccountConfirmAlertDialog();
}
} else {
@ -161,7 +160,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
Button syncButton = (Button) findViewById(R.id.preference_sync_button);
TextView lastSyncTimeView = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
// set button state
// 根据同步状态配置按钮文案与行为
if (GTaskSyncService.isSyncing()) {
syncButton.setText(getString(R.string.preferences_button_sync_cancel));
syncButton.setOnClickListener(new View.OnClickListener() {
@ -179,7 +178,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this)));
// set last sync time
// 展示最近同步时间或实时进度
if (GTaskSyncService.isSyncing()) {
lastSyncTimeView.setText(GTaskSyncService.getProgressString());
lastSyncTimeView.setVisibility(View.VISIBLE);
@ -276,7 +275,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
showSelectAccountAlertDialog();
showSelectAccountAlertDialog(); // 重新选择账户
} else if (which == 1) {
removeSyncAccount();
refreshUI();
@ -302,10 +301,10 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
editor.commit();
// clean up last sync time
// 清空上次同步时间
setLastSyncTime(this, 0);
// clean up local gtask related info
// 清理本地 gtask 关联信息,避免账号切换后污染
new Thread(new Runnable() {
public void run() {
ContentValues values = new ContentValues();
@ -332,7 +331,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
editor.commit();
// clean up local gtask related info
// 清理本地 gtask 关联信息
new Thread(new Runnable() {
public void run() {
ContentValues values = new ContentValues();

Loading…
Cancel
Save