最近标注

曾晨曦_branch
zcx 2 years ago
parent 48849a21d6
commit ed719ab579

@ -14,19 +14,23 @@
* limitations under the License.
*/
package net.micode.notes.data;
package net.micode.notes.data;//指明包的位置
import android.content.Context;
import android.content.Context;//引用android.content.Context
import android.database.Cursor;
import android.database.Cursor;//引用android.database.Cursor
import android.provider.ContactsContract.CommonDataKinds.Phone;
//引用CommonDataKinds.Phone
import android.provider.ContactsContract.Data;
//引用android.provider.ContactsContract.Data
import android.telephony.PhoneNumberUtils;
import android.util.Log;
//引用android.telephony.PhoneNumberUtils
import android.util.Log;//引用android.util.Log
import java.util.HashMap;
//change
public class Contact { //联系人
import java.util.HashMap;//引用java.util.HashMap
//联系人
public class Contact {
private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact";
@ -49,6 +53,7 @@ public class Contact { //
// 查找HashMap中是否已有phoneNumber信息
if(sContactCache.containsKey(phoneNumber)) {
return sContactCache.get(phoneNumber);
//返回phoneNumber信息
}
String selection = CALLER_ID_SELECTION.replace("+",
@ -64,14 +69,15 @@ public class Contact { //
// 判定查询结果
// moveToFirst()返回第一条
if (cursor != null && cursor.moveToFirst()) {
try {
// 找到相关信息
try {
String name = cursor.getString(0);
sContactCache.put(phoneNumber, name);
return name;
// 异常处理
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, " Cursor get string error " + e.toString());
//输出相关string error错误信息
return null;
} finally {
cursor.close();
@ -79,6 +85,7 @@ public class Contact { //
// 未找到相关信息处理
} else {
Log.d(TAG, "No contact matched with number:" + phoneNumber);
//输出No contact matched错误信息
return null;
}
}

@ -14,12 +14,13 @@
* limitations under the License.
*/
package net.micode.notes.data;
package net.micode.notes.data;//此类在文件中的位置
import android.content.ContentUris;
import android.net.Uri;
import android.content.ContentUris;//引用android.content.ContentUris
import android.net.Uri;//引用android.net.Uri
// Notes 类中定义了很多常量这些常量大多是int型和string型
public class Notes {
//定义两个常量
public static final String AUTHORITY = "micode_notes";
public static final String TAG = "Notes";
@ -29,10 +30,10 @@ public class Notes {
public static final int TYPE_SYSTEM = 2;
/**
* Following IDs are system folders' identifiers
* {@link Notes#ID_ROOT_FOLDER } is default folder
* {@link Notes#ID_TEMPARAY_FOLDER } is for notes belonging no folder
* {@link Notes#ID_CALL_RECORD_FOLDER} is to store call records
* ID
* {@link Notes#ID_ROOT_FOLDER }
* {@link Notes#ID_TEMPARAY_FOLDER }notes
* {@link Notes#ID_CALL_RECORD_FOLDER}
*/
public static final int ID_ROOT_FOLDER = 0;
public static final int ID_TEMPARAY_FOLDER = -1;
@ -40,24 +41,25 @@ public class Notes {
public static final int ID_TRASH_FOLER = -3;
public static final String INTENT_EXTRA_ALERT_DATE =
//定义net.micode.notes.alert_date的常量
"net.micode.notes.alert_date";
public static final String INTENT_EXTRA_BACKGROUND_ID =
//定义net.micode.notes.background_color_id的常量
"net.micode.notes.background_color_id";
public static final String INTENT_EXTRA_WIDGET_ID =
//定义net.micode.notes.widget_id的常量
"net.micode.notes.widget_id";
public static final String INTENT_EXTRA_WIDGET_TYPE =
//定义net.micode.notes.widget_type的常量
"net.micode.notes.widget_type";
public static final String INTENT_EXTRA_FOLDER_ID =
//定义net.micode.notes.folder_id的常量
"net.micode.notes.folder_id";
public static final String INTENT_EXTRA_CALL_DATE =
//定义net.micode.notes.call_date的常量
"net.micode.notes.call_date";
//定义使用widget挂件的常量
public static final int TYPE_WIDGET_INVALIDE = -1;
public static final int TYPE_WIDGET_2X = 0;
public static final int TYPE_WIDGET_4X = 1;
@ -68,16 +70,15 @@ public class Notes {
}
/**
* Uri to query all notes and folders
* 便 URI
*/
public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" +
AUTHORITY + "/note");//定义查询便签和文件夹的指针。
// public static final Uri my_URI = ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI , 10);
public static final Uri my_URI = ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI , 10);
/**
* Uri to query data
* URI
*/
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" +
@ -86,93 +87,92 @@ AUTHORITY + "/data");//
// 定义NoteColumns的常量,用于后面创建数据库的表头
public interface NoteColumns {
/**
* The unique ID for a row
* ID
* <P> Type: INTEGER (long) </P>
*/
public static final String ID = "_id";
/**
* The parent's id for note or folder
* 便ID
* <P> Type: INTEGER (long) </P>
*/
public static final String PARENT_ID = "parent_id";//为什么会有parent_id
/**
* Created data for note or folder
*
* <P> Type: INTEGER (long) </P>
*/
public static final String CREATED_DATE = "created_date";
/**
* Latest modified date
*
* <P> Type: INTEGER (long) </P>
*/
public static final String MODIFIED_DATE = "modified_date";
/**
* Alert date
*
* <P> Type: INTEGER (long) </P>
*/
public static final String ALERTED_DATE = "alert_date";
/**
* Folder's name or text content of note
*
* <P> Type: TEXT </P>
*/
public static final String SNIPPET = "snippet";
/**
* Note's widget id
* noteswidget ID
* <P> Type: INTEGER (long) </P>
*/
public static final String WIDGET_ID = "widget_id";
/**
* Note's widget type
* noteswidget
* <P> Type: INTEGER (long) </P>
*/
public static final String WIDGET_TYPE = "widget_type";
/**
* Note's background color's id
* ID
* <P> Type: INTEGER (long) </P>
*/
public static final String BG_COLOR_ID = "bg_color_id";
/**
* For text note, it doesn't has attachment, for multi-media
* note, it has at least one attachment
*
* <P> Type: INTEGER </P>
*/
public static final String HAS_ATTACHMENT = "has_attachment";
/**
* Folder's count of notes
*
* <P> Type: INTEGER (long) </P>
*/
public static final String NOTES_COUNT = "notes_count";
/**
* The file type: folder or note
* 便
* <P> Type: INTEGER </P>
*/
public static final String TYPE = "type";
/**
* The last sync id
* ID
* <P> Type: INTEGER (long) </P>
*/
public static final String SYNC_ID = "sync_id";//同步
/**
* Sign to indicate local modified or not
*
* <P> Type: INTEGER </P>
*/
public static final String LOCAL_MODIFIED = "local_modified";
/**
* Original parent id before moving into temporary folder
* ID
* <P> Type : INTEGER </P>
*/
public static final String ORIGIN_PARENT_ID = "origin_parent_id";
@ -193,77 +193,72 @@ AUTHORITY + "/data");//
// 定义DataColumns的常量,用于后面创建数据库的表头
public interface DataColumns {
/**
* The unique ID for a row
* ID
* <P> Type: INTEGER (long) </P>
*/
public static final String ID = "_id";
/**
* The MIME type of the item represented by this row.
* MIME
* <P> Type: Text </P>
*/
public static final String MIME_TYPE = "mime_type";
/**
* The reference id to note that this data belongs to
* ID
* <P> Type: INTEGER (long) </P>
*/
public static final String NOTE_ID = "note_id";
/**
* Created data for note or folder
*
* <P> Type: INTEGER (long) </P>
*/
public static final String CREATED_DATE = "created_date";
/**
* Latest modified date
*
* <P> Type: INTEGER (long) </P>
*/
public static final String MODIFIED_DATE = "modified_date";
/**
* Data's content
*
* <P> Type: TEXT </P>
*/
public static final String CONTENT = "content";
/**
* Generic data column, the meaning is {@link #MIMETYPE} specific,
used for
* integer data type
* {@link #MIMETYPE}
* Integer
* <P> Type: INTEGER </P>
*/
public static final String DATA1 = "data1";
/**
* Generic data column, the meaning is {@link #MIMETYPE} specific,
used for
* integer data type
* {@link #MIMETYPE}
* Integer
* <P> Type: INTEGER </P>
*/
public static final String DATA2 = "data2";
/**
* Generic data column, the meaning is {@link #MIMETYPE} specific,
used for
* {@link #MIMETYPE}
* TEXT data type
* <P> Type: TEXT </P>
*/
public static final String DATA3 = "data3";
/**
* Generic data column, the meaning is {@link #MIMETYPE} specific,
used for
* {@link #MIMETYPE}
* TEXT data type
* <P> Type: TEXT </P>
*/
public static final String DATA4 = "data4";
/**
* Generic data column, the meaning is {@link #MIMETYPE} specific,
used for
* {@link #MIMETYPE}
* TEXT data type
* <P> Type: TEXT </P>
*/
@ -271,7 +266,7 @@ used for
}//主要是定义存储便签内容数据的
public static final class TextNote implements DataColumns {
/**
* Mode to indicate the text in check list mode or not
*
* <P> Type: Integer 1:check list mode 0: normal mode </P>
*/
public static final String MODE = DATA1;
@ -293,13 +288,13 @@ AUTHORITY + "/text_note");
public static final class CallNote implements DataColumns {
/**
* Call date for this record
*
* <P> Type: INTEGER (long) </P>
*/
public static final String CALL_DATE = DATA1;
/**
* Phone number for this record
*
* <P> Type: TEXT </P>
*/
public static final String PHONE_NUMBER = DATA3;

@ -38,6 +38,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
public static final String DATA = "data";
}
//定义数据库中需要的常量
private static final String TAG = "NotesDatabaseHelper";
private static NotesDatabaseHelper mInstance;
@ -83,7 +84,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";//存储便签编号的一个数据表格
/**
* Increase folder's note count when move note to the folder
*
*/
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_update "+
@ -95,7 +96,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";//在文件夹中移入一个Note之后需要更改的数据的表格。
/**
* Decrease folder's note count when move note from folder
*
*/
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_update " +
@ -108,7 +109,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";//在文件夹中移出一个Note之后需要更改的数据的表格。
/**
* Increase folder's note count when insert new note to the folder
*
*/
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_insert " +
@ -120,7 +121,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";//在文件夹中插入一个Note之后需要更改的数据的表格。
/**
* Decrease folder's note count when delete note from the folder
*
*/
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_delete " +
@ -133,7 +134,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";//在文件夹中删除一个Note之后需要更改的数据的表格。
/**
* Update note's content when insert data with type {@link DataConstants#NOTE}
* {@link DataConstants#NOTE}
*/
private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER =
"CREATE TRIGGER update_note_content_on_insert " +
@ -146,7 +147,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";//在文件夹中对一个Note导入新的数据之后需要更改的数据的表格。
/**
* Update note's content when data with {@link DataConstants#NOTE} type has changed
* {@link DataConstants#NOTE}
*/
private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER update_note_content_on_update " +
@ -159,7 +160,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";//Note数据被修改后需要更改的数据的表格。
/**
* Update note's content when data with {@link DataConstants#NOTE} type has deleted
* {@link DataConstants#NOTE}
*/
private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER =
"CREATE TRIGGER update_note_content_on_delete " +
@ -172,7 +173,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";//Note数据被删除后需要更改的数据的表格。
/**
* Delete datas belong to note which has been deleted
*
*/
private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER =
"CREATE TRIGGER delete_data_on_delete " +
@ -183,7 +184,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";//删除已删除的便签的数据后需要更改的数据的表格。
/**
* Delete notes belong to folder which has been deleted
* 便
*/
private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER =
"CREATE TRIGGER folder_delete_notes_on_delete " +
@ -194,7 +195,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";//删除已删除的文件夹的便签后需要更改的数据的表格。
/**
* Move notes belong to folder which has been moved to trash folder
* 便
*/
private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER =
"CREATE TRIGGER folder_move_notes_on_trash " +
@ -204,7 +205,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" UPDATE " + TABLE.NOTE +
" SET " + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER +
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
" END";//还原垃圾桶中便签后需要更改的数据的表格。
" END";
public NotesDatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
@ -240,14 +241,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
ContentValues values = new ContentValues();
/**
* call record foler for call notes
* Foler
*/
values.put(NoteColumns.ID, Notes.ID_CALL_RECORD_FOLDER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
db.insert(TABLE.NOTE, null, values);
/**
* root folder which is default folder
*
*/
values.clear();
values.put(NoteColumns.ID, Notes.ID_ROOT_FOLDER);
@ -255,7 +256,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.insert(TABLE.NOTE, null, values);
/**
* temporary folder which is used for moving note
*
*/
values.clear();
values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER);
@ -263,7 +264,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.insert(TABLE.NOTE, null, values);
/**
* create trash folder
*
*/
values.clear();
values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER);
@ -310,7 +311,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
if (oldVersion == 1) {
upgradeToV2(db);
skipV2 = true; // this upgrade including the upgrade from v2 to v3
skipV2 = true; // 此升级包括从 v2 到 v3 的升级
oldVersion++;
}

@ -14,8 +14,9 @@
* limitations under the License.
*/
package net.micode.notes.data;
package net.micode.notes.data;//此类所在位置
//以下为引用的各种工具
import android.app.SearchManager;
import android.content.ContentProvider;
import android.content.ContentUris;
@ -69,8 +70,8 @@ public class NotesProvider extends ContentProvider {
}
/**
* 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.
* x'0A' sqlite 'n'
* n.
*/
// 声明 NOTES_SEARCH_PROJECTION
private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + ","
@ -188,14 +189,14 @@ public class NotesProvider extends ContentProvider {
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
// Notify the note uri
// 通知注释 uri
// notifyChange获得一个ContextResolver对象并且更新里面的内容
if (noteId > 0) {
getContext().getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);
}
// Notify the data uri
// 通知数据 URI
if (dataId > 0) {
getContext().getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);
@ -222,8 +223,7 @@ public class NotesProvider extends ContentProvider {
case URI_NOTE_ITEM:
id = uri.getPathSegments().get(1);
/**
* ID that smaller than 0 is system folder which is not allowed to
* trash
* 0 ID
*/
long noteId = Long.valueOf(id);
if (noteId <= 0) {
@ -329,7 +329,7 @@ public class NotesProvider extends ContentProvider {
@Override
public String getType(Uri uri) {
// TODO Auto-generated method stub
// TODO 自动生成的方法存根
return null;
}

@ -19,7 +19,7 @@ package net.micode.notes.tool;
public class BackupUtils {
private static final String TAG = "BackupUtils";
// Singleton stuff
private static BackupUtils sInstance; //类里面为什么可以定义自身类的对象
private static BackupUtils sInstance; //类里面为什么可以定义自身类的对象
public static synchronized BackupUtils getInstance(Context context) {
//ynchronized 关键字,代表这个方法加锁,相当于不管哪一个线程例如线程A
@ -33,8 +33,7 @@ public class BackupUtils {
}
/**
* Following states are signs to represents backup or restore
* status
*
*/
// Currently, the sdcard is not mounted SD卡没有被装入手机
public static final int STATE_SD_CARD_UNMOUONTED = 0;
@ -49,11 +48,13 @@ public class BackupUtils {
private TextExport mTextExport;
private BackupUtils(Context context) { //初始化函数
//初始化函数
private BackupUtils(Context context) {
mTextExport = new TextExport(context);
}
private static boolean externalStorageAvailable() { //外部存储功能是否可用
//外部存储功能是否可用
private static boolean externalStorageAvailable() {
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}
@ -69,6 +70,7 @@ public class BackupUtils {
return mTextExport.mFileDirectory;
}
//TextExport方法
private static class TextExport {
private static final String[] NOTE_PROJECTION = {
NoteColumns.ID,
@ -92,6 +94,7 @@ public class BackupUtils {
DataColumns.DATA4,
};
//定义数据类型的常量
private static final int DATA_COLUMN_CONTENT = 0;
private static final int DATA_COLUMN_MIME_TYPE = 1;
@ -116,12 +119,13 @@ public class BackupUtils {
mFileDirectory = "";
}
private String getFormat(int id) { //获取文本的组成部分
//获取文本的组成部分
private String getFormat(int id) {
return TEXT_FORMAT[id];
}
/**
* Export the folder identified by folder id to text
* ID
*/
private void exportFolderToText(String folderId, PrintStream ps) {
// Query notes belong to this folder 通过查询parent id是文件夹id的note来选出制定ID文件夹下的Note
@ -137,7 +141,7 @@ public class BackupUtils {
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm),
notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
// Query data belong to this note
// 查询属于此说明数据
String noteId = notesCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps); //将文件导出到text
} while (notesCursor.moveToNext());
@ -147,7 +151,7 @@ public class BackupUtils {
}
/**
* Export note identified by id to a print stream
* id
*/
private void exportNoteToText(String noteId, PrintStream ps) {
Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI,
@ -169,11 +173,11 @@ public class BackupUtils {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
phoneNumber));
}
// Print call date
// 打印通话日期
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat
.format(mContext.getString(R.string.format_datetime_mdhm),
callDate)));
// Print call attachment location
// 打印使用附件位置
if (!TextUtils.isEmpty(location)) {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
location));
@ -189,7 +193,7 @@ public class BackupUtils {
}
dataCursor.close();
}
// print a line separator between note
// 在注释之间打印行分隔符
try {
ps.write(new byte[] {
Character.LINE_SEPARATOR, Character.LETTER_NUMBER
@ -200,7 +204,7 @@ public class BackupUtils {
}
/**
* Note will be exported as text which is user readable
*
*/
public int exportToText() { //总函数调用上面的exportFolder和exportNote
if (!externalStorageAvailable()) {
@ -213,7 +217,7 @@ public class BackupUtils {
Log.e(TAG, "get print stream error");
return STATE_SYSTEM_ERROR;
}
// First export folder and its notes 导出文件夹,就是导出里面包含的便签
//导出文件夹,就是导出里面包含的便签
Cursor folderCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
@ -241,7 +245,7 @@ public class BackupUtils {
folderCursor.close();
}
// Export notes in root's folder 将根目录里的便签导出(由于不属于任何文件夹,因此无法通过文件夹导出来实现这一部分便签的导出)
// 将根目录里的便签导出(由于不属于任何文件夹,因此无法通过文件夹导出来实现这一部分便签的导出)
Cursor noteCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
@ -254,7 +258,7 @@ public class BackupUtils {
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm),
noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
// Query data belong to this note
// 查询数据属于此说明
String noteId = noteCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps);
} while (noteCursor.moveToNext());
@ -267,7 +271,7 @@ public class BackupUtils {
}
/**
* Get a print stream pointed to the file {@generateExportedTextFile}
* {@generateExportedTextFile}
*/
private PrintStream getExportToTextPrintStream() {
File file = generateFileMountedOnSDcard(mContext, R.string.file_path,
@ -281,7 +285,8 @@ public class BackupUtils {
PrintStream ps = null;
try {
FileOutputStream fos = new FileOutputStream(file);
ps = new PrintStream(fos); //将ps输出流输出到特定的文件目的就是导出到文件而不是直接输出
ps = new PrintStream(fos);
//将ps输出流输出到特定的文件目的就是导出到文件而不是直接输出
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
@ -294,7 +299,7 @@ public class BackupUtils {
}
/**
* Generate the text file to store imported data
*
*/
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
StringBuilder sb = new StringBuilder();

@ -1,4 +1,4 @@
package net.micode.notes.tool;
package net.micode.notes.tool;//此类所在位置
public class DataUtils {
public static final String TAG = "DataUtils";
@ -78,7 +78,7 @@ public class DataUtils {
}
/**
* Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}}
* {@link Notes#TYPE_SYSTEM}}
*/
public static int getUserFolderCount(ContentResolver resolver) {
Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
@ -94,6 +94,7 @@ public class DataUtils {
count = cursor.getInt(0);
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "get folder count failed:" + e.toString());
//get folder count failed报错
} finally {
cursor.close();
}
@ -119,7 +120,8 @@ public class DataUtils {
return exist;
}
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
// 检查给定的noteId是否存在于笔记数据库中
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {// 构建查询笔记数据的Uri使用ContentUris.withAppendedId()方法将noteId添加到笔记Uri中
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null);
@ -139,10 +141,10 @@ public class DataUtils {
boolean exist = false;
if (cursor != null) {
if (cursor.getCount() > 0) {
if (cursor.getCount() > 0) {// 如果count中有数据则说明noteId存在于笔记数据库中
exist = true;
}
cursor.close();
cursor.close();//释放资源
}
return exist;
}
@ -191,7 +193,8 @@ public class DataUtils {
return set;
}
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
//根据给定的noteId从笔记数据库中获取电话号码
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {// 构建查询条件返回值为String类型表示根据noteId获取到的电话号码如果获取失败则返回空字符串
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.PHONE_NUMBER },
CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
@ -200,7 +203,7 @@ public class DataUtils {
if (cursor != null && cursor.moveToFirst()) {
try {
return cursor.getString(0);
return cursor.getString(0);// 获取第一列的电话号码数据
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call number fails " + e.toString());
} finally {

@ -14,102 +14,96 @@
* limitations under the License.
*/
//简介:定义了很多的静态字符串目的就是为了提供jsonObject中相应字符串的"key"。把这些静态的定义单独写到了一个类里面,这是非常好的编程规范
package net.micode.notes.tool;
//定义了很多的静态字符串目的就是为了提供jsonObject中相应字符串的"key"。把这些静态的定义单独写到了一个类里面
package net.micode.notes.tool;//定位此类
//这个类就是定义了一堆static string实际就是为jsonObject提供Key把这些定义全部写到一个类里方便查看管理,是一个非常好的编程习惯
//这个类定义了一些static string实际就是为jsonObject提供Key把这些定义全部写到一个类里方便查看管理
public class GTaskStringUtils {
public final static String GTASK_JSON_ACTION_ID = "action_id";
// 动作相关常量
public final static String GTASK_JSON_ACTION_ID = "action_id"; // 动作ID
public final static String GTASK_JSON_ACTION_LIST = "action_list"; // 动作列表
public final static String GTASK_JSON_ACTION_TYPE = "action_type"; // 动作类型
public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; // 创建动作类型
public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; // 获取所有动作类型
public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; // 移动动作类型
public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; // 更新动作类型
public final static String GTASK_JSON_ACTION_LIST = "action_list";
public final static String GTASK_JSON_CREATOR_ID = "creator_id"; // 创建者ID
public final static String GTASK_JSON_ACTION_TYPE = "action_type";
public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; // 子实体
public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create";
public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; // 客户端版本
public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all";
public final static String GTASK_JSON_COMPLETED = "completed"; // 完成状态
public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move";
public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; // 当前列表ID
public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update";
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; // 默认列表ID
public final static String GTASK_JSON_CREATOR_ID = "creator_id";
public final static String GTASK_JSON_DELETED = "deleted"; // 删除状态
public final static String GTASK_JSON_CHILD_ENTITY = "child_entity";
public final static String GTASK_JSON_DEST_LIST = "dest_list"; // 目标列表
public final static String GTASK_JSON_CLIENT_VERSION = "client_version";
public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; // 目标父级
public final static String GTASK_JSON_COMPLETED = "completed";
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; // 目标父级类型
public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id";
public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta"; // 实体增量
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id";
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; // 实体类型
public final static String GTASK_JSON_DELETED = "deleted";
public final static String GTASK_JSON_GET_DELETED = "get_deleted"; // 获取已删除项
public final static String GTASK_JSON_DEST_LIST = "dest_list";
public final static String GTASK_JSON_ID = "id"; // ID
public final static String GTASK_JSON_DEST_PARENT = "dest_parent";
public final static String GTASK_JSON_INDEX = "index"; // 索引
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type";
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; // 最后修改时间
public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta";
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; // 最新同步点
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type";
public final static String GTASK_JSON_LIST_ID = "list_id"; // 列表ID
public final static String GTASK_JSON_GET_DELETED = "get_deleted";
public final static String GTASK_JSON_LISTS = "lists"; // 列表
public final static String GTASK_JSON_ID = "id";
public final static String GTASK_JSON_NAME = "name"; // 名称
public final static String GTASK_JSON_INDEX = "index";
public final static String GTASK_JSON_NEW_ID = "new_id"; // 新ID
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified";
public final static String GTASK_JSON_NOTES = "notes"; // 备注
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point";
public final static String GTASK_JSON_PARENT_ID = "parent_id"; // 父级ID
public final static String GTASK_JSON_LIST_ID = "list_id";
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; // 上一个兄弟节点ID
public final static String GTASK_JSON_LISTS = "lists";
public final static String GTASK_JSON_RESULTS = "results"; // 结果
public final static String GTASK_JSON_NAME = "name";
public final static String GTASK_JSON_SOURCE_LIST = "source_list"; // 源列表
public final static String GTASK_JSON_NEW_ID = "new_id";
public final static String GTASK_JSON_TASKS = "tasks"; // 任务
public final static String GTASK_JSON_NOTES = "notes";
// 类型相关常量
public final static String GTASK_JSON_TYPE = "type"; // 类型
public final static String GTASK_JSON_TYPE_GROUP = "GROUP"; // 分组类型
public final static String GTASK_JSON_TYPE_TASK = "TASK"; // 任务类型
public final static String GTASK_JSON_PARENT_ID = "parent_id";
public final static String GTASK_JSON_USER = "user"; // 用户
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id";
public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]"; // MIUI文件夹前缀
public final static String GTASK_JSON_RESULTS = "results";
public final static String FOLDER_DEFAULT = "Default"; // 默认文件夹
public final static String GTASK_JSON_SOURCE_LIST = "source_list";
public final static String FOLDER_CALL_NOTE = "Call_Note"; // 电话备注文件夹
public final static String GTASK_JSON_TASKS = "tasks";
public final static String FOLDER_META = "METADATA"; // 元数据文件夹
public final static String GTASK_JSON_TYPE = "type";
public final static String META_HEAD_GTASK_ID = "meta_gid"; // 元信息任务ID
public final static String GTASK_JSON_TYPE_GROUP = "GROUP";
public final static String META_HEAD_NOTE = "meta_note"; // 元信息备注
public final static String GTASK_JSON_TYPE_TASK = "TASK";
public final static String META_HEAD_DATA = "meta_data"; // 元信息数据
public final static String GTASK_JSON_USER = "user";
public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]";
public final static String FOLDER_DEFAULT = "Default";
public final static String FOLDER_CALL_NOTE = "Call_Note";
public final static String FOLDER_META = "METADATA";
public final static String META_HEAD_GTASK_ID = "meta_gid";
public final static String META_HEAD_NOTE = "meta_note";
public final static String META_HEAD_DATA = "meta_data";
public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE";
public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE"; // 元信息备注名称
}

@ -14,9 +14,9 @@
* limitations under the License.
*/
package net.micode.notes.tool;
package net.micode.notes.tool;//此类位置
/*使
/*使
* R.java
* R.id
* R.drawable 使
@ -31,6 +31,7 @@ package net.micode.notes.tool;
* BG_DEFAULT_FONT_SIZE
*/
//字体大小和颜色
public class ResourceParser {
public static final int YELLOW = 0;
@ -48,6 +49,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,
@ -57,6 +59,7 @@ public class ResourceParser {
R.drawable.edit_red
};
//标题颜色
private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] {
R.drawable.edit_title_yellow,
R.drawable.edit_title_blue,
@ -73,7 +76,8 @@ public class ResourceParser {
return BG_EDIT_TITLE_RESOURCES[id];
}
}
//直接获取默认的背景颜色。看不太懂这个PREFERENCE_SET_BG_COLOR_KEY是个final string,也就是说getBoolean肯定执行else为什么要这么写
//直接获取默认的背景颜色。
public static int getDefaultBgId(Context context) {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
@ -83,6 +87,7 @@ public class ResourceParser {
}
}
//用于存储不同类型笔记的第一个笔记的背景资源ID
public static class NoteItemBgResources {
private final static int [] BG_FIRST_RESOURCES = new int [] {
R.drawable.list_yellow_up,
@ -92,6 +97,7 @@ public class ResourceParser {
R.drawable.list_red_up
};
//用于存储不同类型笔记的中间笔记的背景资源ID
private final static int [] BG_NORMAL_RESOURCES = new int [] {
R.drawable.list_yellow_middle,
R.drawable.list_blue_middle,
@ -100,6 +106,7 @@ public class ResourceParser {
R.drawable.list_red_middle
};
//用于存储不同类型笔记的最后笔记的背景资源ID
private final static int [] BG_LAST_RESOURCES = new int [] {
R.drawable.list_yellow_down,
R.drawable.list_blue_down,
@ -108,6 +115,7 @@ public class ResourceParser {
R.drawable.list_red_down,
};
//定义了NoteItemBgResources内部类中的一个静态数组BG_SINGLE_RESOURCES用于存储不同类型笔记只有一个笔记时的背景资源ID。
private final static int [] BG_SINGLE_RESOURCES = new int [] {
R.drawable.list_yellow_single,
R.drawable.list_blue_single,
@ -116,18 +124,22 @@ public class ResourceParser {
R.drawable.list_red_single
};
//用于获取特定id对应的第一个笔记的背景资源ID。
public static int getNoteBgFirstRes(int id) {
return BG_FIRST_RESOURCES[id];
}
//用于获取特定id对应的最后一个笔记的背景资源ID
public static int getNoteBgLastRes(int id) {
return BG_LAST_RESOURCES[id];
}
//用于获取特定id对应的只有一个笔记时的背景资源ID
public static int getNoteBgSingleRes(int id) {
return BG_SINGLE_RESOURCES[id];
}
//用于获取特定id对应的中间笔记的背景资源ID
public static int getNoteBgNormalRes(int id) {
return BG_NORMAL_RESOURCES[id];
}
@ -174,9 +186,7 @@ public class ResourceParser {
//这里有一个容错的函数防止输入的id大于资源总量若如此则自动返回默认的设置结果
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}
* HACKME ID id {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
*/
if (id >= TEXTAPPEARANCE_RESOURCES.length) {
return BG_DEFAULT_FONT_SIZE;

Loading…
Cancel
Save