diff --git a/src/net/micode/notes/model/Note.java b/src/net/micode/notes/model/Note.java index 6706cf6..f43c73f 100644 --- a/src/net/micode/notes/model/Note.java +++ b/src/net/micode/notes/model/Note.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -14,6 +14,8 @@ * limitations under the License. */ +// 定义了一个名为Note的类,用于处理便签数据 + package net.micode.notes.model; import android.content.ContentProviderOperation; import android.content.ContentProviderResult; @@ -33,16 +35,16 @@ import net.micode.notes.data.Notes.TextNote; import java.util.ArrayList; - public class Note { - private ContentValues mNoteDiffValues; - private NoteData mNoteData; - private static final String TAG = "Note"; + private ContentValues mNoteDiffValues; // 用于存储便签数据变化的ContentValues对象 + private NoteData mNoteData; // 用于存储便签数据的私有类NoteData的对象 + private static final String TAG = "Note"; // 用于日志标记的TAG + /** * Create a new note id for adding a new note to databases */ public static synchronized long getNewNoteId(Context context, long folderId) { - // Create a new note in the database + // 创建一个新的便签ID,用于将新的便签添加到数据库中 ContentValues values = new ContentValues(); long createdTime = System.currentTimeMillis(); values.put(NoteColumns.CREATED_DATE, createdTime); @@ -71,36 +73,44 @@ public class Note { } public void setNoteValue(String key, String value) { + // 设置便签的值 mNoteDiffValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } public void setTextData(String key, String value) { + // 设置文本数据 mNoteData.setTextData(key, value); } public void setTextDataId(long id) { + // 设置文本数据ID mNoteData.setTextDataId(id); } public long getTextDataId() { + // 获取文本数据ID return mNoteData.mTextDataId; } public void setCallDataId(long id) { + // 设置通话数据ID mNoteData.setCallDataId(id); } public void setCallData(String key, String value) { + // 设置通话数据 mNoteData.setCallData(key, value); } public boolean isLocalModified() { + // 检查是否有本地修改 return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified(); } public boolean syncNote(Context context, long noteId) { + // 同步便签数据到数据库 if (noteId <= 0) { throw new IllegalArgumentException("Wrong note id:" + noteId); } @@ -109,11 +119,7 @@ public class Note { return true; } - /** - * In theory, once data changed, the note should be updated on {@link NoteColumns#LOCAL_MODIFIED} and - * {@link NoteColumns#MODIFIED_DATE}. For data safety, though update note fails, we also update the - * note data info - */ + // 更新便签数据 if (context.getContentResolver().update( ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), mNoteDiffValues, null, null) == 0) { @@ -122,6 +128,7 @@ public class Note { } mNoteDiffValues.clear(); + // 更新便签数据信息 if (mNoteData.isLocalModified() && (mNoteData.pushIntoContentResolver(context, noteId) == null)) { return false; @@ -132,13 +139,9 @@ public class Note { private class NoteData { private long mTextDataId; - private ContentValues mTextDataValues; - private long mCallDataId; - private ContentValues mCallDataValues; - private static final String TAG = "NoteData"; public NoteData() { @@ -149,10 +152,12 @@ public class Note { } boolean isLocalModified() { + // 检查是否有本地修改 return mTextDataValues.size() > 0 || mCallDataValues.size() > 0; } void setTextDataId(long id) { + // 设置文本数据ID if(id <= 0) { throw new IllegalArgumentException("Text data id should larger than 0"); } @@ -160,6 +165,7 @@ public class Note { } void setCallDataId(long id) { + // 设置通话数据ID if (id <= 0) { throw new IllegalArgumentException("Call data id should larger than 0"); } @@ -167,32 +173,29 @@ public class Note { } void setCallData(String key, String value) { + // 设置通话数据 mCallDataValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } void setTextData(String key, String value) { + // 设置文本数据 mTextDataValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } Uri pushIntoContentResolver(Context context, long noteId) { - /** - * Check for safety - */ - if (noteId <= 0) { - throw new IllegalArgumentException("Wrong note id:" + noteId); - } - + // 将便签数据推送到内容解析器 ArrayList operationList = new ArrayList(); ContentProviderOperation.Builder builder = null; if(mTextDataValues.size() > 0) { + // 处理文本数据 mTextDataValues.put(DataColumns.NOTE_ID, noteId); if (mTextDataId == 0) { - mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE); + // 插入新的文本数据 Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI, mTextDataValues); try { @@ -203,6 +206,7 @@ public class Note { return null; } } else { + // 更新文本数据 builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId( Notes.CONTENT_DATA_URI, mTextDataId)); builder.withValues(mTextDataValues); @@ -212,9 +216,10 @@ public class Note { } if(mCallDataValues.size() > 0) { + // 处理通话数据 mCallDataValues.put(DataColumns.NOTE_ID, noteId); if (mCallDataId == 0) { - mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE); + // 插入新的通话数据 Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI, mCallDataValues); try { @@ -225,6 +230,7 @@ public class Note { return null; } } else { + // 更新通话数据 builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId( Notes.CONTENT_DATA_URI, mCallDataId)); builder.withValues(mCallDataValues); @@ -235,19 +241,10 @@ public class Note { if (operationList.size() > 0) { try { + // 应用批量操作 ContentProviderResult[] results = context.getContentResolver().applyBatch( Notes.AUTHORITY, operationList); return (results == null || results.length == 0 || results[0] == null) ? null : ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId); } catch (RemoteException e) { - Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); - return null; - } catch (OperationApplicationException e) { - Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); - return null; - } - } - return null; - } - } -} + Log.e(TAG, String.format("%s: %s", e.toString(), \ No newline at end of file diff --git a/src/net/micode/notes/tool/BackupUtils.java b/src/net/micode/notes/tool/BackupUtils.java index 39f6ec4..fdf8ece 100644 --- a/src/net/micode/notes/tool/BackupUtils.java +++ b/src/net/micode/notes/tool/BackupUtils.java @@ -36,56 +36,59 @@ import java.io.IOException; import java.io.PrintStream; +濂界殑锛屾垜灏嗕负`BackupUtils.java`鏂囦欢涓殑姣忎釜璇彞鎻愪緵鏇寸粏鑷寸殑娉ㄩ噴锛 + +```java public class BackupUtils { - private static final String TAG = "BackupUtils"; - // Singleton stuff - private static BackupUtils sInstance; + private static final String TAG = "BackupUtils"; // 瀹氫箟鏃ュ織鏍囩锛岀敤浜庤瘑鍒棩蹇楄緭鍑虹殑鏉ユ簮 + + private static BackupUtils sInstance; // 澹版槑涓涓潤鎬佸疄渚嬪彉閲忥紝鐢ㄤ簬瀹炵幇鍗曚緥妯″紡 + // 鎻愪緵涓涓叕鍏辩殑闈欐佹柟娉曪紝鐢ㄤ簬鑾峰彇BackupUtils鐨勫崟渚嬪疄渚 public static synchronized BackupUtils getInstance(Context context) { if (sInstance == null) { - sInstance = new BackupUtils(context); + sInstance = new BackupUtils(context); // 濡傛灉瀹炰緥涓嶅瓨鍦紝鍒欐柊寤轰竴涓疄渚 } - return sInstance; + return sInstance; // 杩斿洖鍗曚緥瀹炰緥 } - /** - * Following states are signs to represents backup or restore - * status - */ - // Currently, the sdcard is not mounted - public static final int STATE_SD_CARD_UNMOUONTED = 0; - // The backup file not exist - public static final int STATE_BACKUP_FILE_NOT_EXIST = 1; - // The data is not well formated, may be changed by other programs - public static final int STATE_DATA_DESTROIED = 2; - // Some run-time exception which causes restore or backup fails - public static final int STATE_SYSTEM_ERROR = 3; - // Backup or restore success - public static final int STATE_SUCCESS = 4; + // 瀹氫箟涓绯诲垪鐘舵佺爜锛岀敤浜庤〃绀哄浠芥垨鎭㈠鐨勭姸鎬 + public static final int STATE_SD_CARD_UNMOUONTED = 0; // SD鍗℃湭鎸傝浇 + public static final int STATE_BACKUP_FILE_NOT_EXIST = 1; // 澶囦唤鏂囦欢涓嶅瓨鍦 + public static final int STATE_DATA_DESTROIED = 2; // 鏁版嵁鏍煎紡涓嶆纭紝鍙兘琚叾浠栫▼搴忔洿鏀 + public static final int STATE_SYSTEM_ERROR = 3; // 绯荤粺閿欒锛屽鑷村浠芥垨鎭㈠澶辫触 + public static final int STATE_SUCCESS = 4; // 澶囦唤鎴栨仮澶嶆垚鍔 - private TextExport mTextExport; + private TextExport mTextExport; // TextExport瀵硅薄锛岀敤浜庡皢鏁版嵁瀵煎嚭鍒版枃鏈 + // BackupUtils鐨勭鏈夋瀯閫犲嚱鏁帮紝浼犲叆Context瀵硅薄 private BackupUtils(Context context) { - mTextExport = new TextExport(context); + mTextExport = new TextExport(context); // 鍒濆鍖朤extExport瀵硅薄 } + // 妫鏌ュ閮ㄥ瓨鍌紙SD鍗★級鏄惁鍙敤 private static boolean externalStorageAvailable() { - return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); + return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); // 姣旇緝瀛樺偍鐘舵佹槸鍚︿负宸叉寕杞 } + // 瀵煎嚭鏁版嵁鍒版枃鏈枃浠讹紝骞惰繑鍥炴搷浣滅粨鏋滅姸鎬佺爜 public int exportToText() { - return mTextExport.exportToText(); + return mTextExport.exportToText(); // 璋冪敤TextExport瀵硅薄鐨別xportToText鏂规硶 } + // 鑾峰彇瀵煎嚭鏂囨湰鏂囦欢鐨勬枃浠跺悕 public String getExportedTextFileName() { - return mTextExport.mFileName; + return mTextExport.mFileName; // 杩斿洖TextExport瀵硅薄涓繚瀛樼殑鏂囦欢鍚 } + // 鑾峰彇瀵煎嚭鏂囨湰鏂囦欢鐨勭洰褰曡矾寰 public String getExportedTextFileDir() { - return mTextExport.mFileDirectory; + return mTextExport.mFileDirectory; // 杩斿洖TextExport瀵硅薄涓繚瀛樼殑鏂囦欢鐩綍 } + // 鍐呴儴绫籘extExport锛屽皝瑁呬簡灏嗙瑪璁版暟鎹鍑哄埌鏂囨湰鏂囦欢鐨勯昏緫 private static class TextExport { + // 瀹氫箟鏌ヨ绗旇淇℃伅鏃堕渶瑕佺殑瀛楁 private static final String[] NOTE_PROJECTION = { NoteColumns.ID, NoteColumns.MODIFIED_DATE, @@ -93,12 +96,12 @@ public class BackupUtils { NoteColumns.TYPE }; + // 瀹氫箟NOTE_PROJECTION鏁扮粍涓悇涓瓧娈电殑绱㈠紩 private static final int NOTE_COLUMN_ID = 0; - private static final int NOTE_COLUMN_MODIFIED_DATE = 1; - private static final int NOTE_COLUMN_SNIPPET = 2; + // 瀹氫箟鏌ヨ绗旇鏁版嵁鏃堕渶瑕佺殑瀛楁 private static final String[] DATA_PROJECTION = { DataColumns.CONTENT, DataColumns.MIME_TYPE, @@ -108,93 +111,88 @@ public class BackupUtils { DataColumns.DATA4, }; + // 瀹氫箟DATA_PROJECTION鏁扮粍涓悇涓瓧娈电殑绱㈠紩 private static final int DATA_COLUMN_CONTENT = 0; - private static final int DATA_COLUMN_MIME_TYPE = 1; - private static final int DATA_COLUMN_CALL_DATE = 2; - private static final int DATA_COLUMN_PHONE_NUMBER = 4; - private final String [] TEXT_FORMAT; - private static final int FORMAT_FOLDER_NAME = 0; - private static final int FORMAT_NOTE_DATE = 1; - private static final int FORMAT_NOTE_CONTENT = 2; + // 鐢ㄤ簬鏍煎紡鍖栧鍑烘枃鏈殑瀛楃涓叉暟缁 + private final String[] TEXT_FORMAT; + // 瀹氫箟鏍煎紡鍖栧瓧绗︿覆鏁扮粍涓殑绱㈠紩 + private static final int FORMAT_FOLDER_NAME = 0; + private static final int FORMAT_NOTE_DATE = 1; + private static final int FORMAT_NOTE_CONTENT = 2; - private Context mContext; - private String mFileName; - private String mFileDirectory; + private Context mContext; // 搴旂敤绋嬪簭涓婁笅鏂 + private String mFileName; // 瀵煎嚭鏂囨湰鏂囦欢鐨勬枃浠跺悕 + private String mFileDirectory; // 瀵煎嚭鏂囨湰鏂囦欢鐨勭洰褰 + // TextExport绫荤殑鏋勯犲嚱鏁帮紝鍒濆鍖栦笂涓嬫枃鍜屾牸寮忓寲瀛楃涓叉暟缁 public TextExport(Context context) { - TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note); - mContext = context; - mFileName = ""; - mFileDirectory = ""; + TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note); // 浠庤祫婧愭枃浠朵腑鑾峰彇鏍煎紡鍖栧瓧绗︿覆鏁扮粍 + mContext = context; // 淇濆瓨涓婁笅鏂囧璞 + mFileName = ""; // 鍒濆鍖栨枃浠跺悕涓虹┖瀛楃涓 + mFileDirectory = ""; // 鍒濆鍖栨枃浠剁洰褰曚负绌哄瓧绗︿覆 } + // 鏍规嵁绱㈠紩鑾峰彇鏍煎紡鍖栧瓧绗︿覆 private String getFormat(int id) { - return TEXT_FORMAT[id]; + return TEXT_FORMAT[id]; // 杩斿洖鏍煎紡鍖栧瓧绗︿覆鏁扮粍涓寚瀹氱储寮曠殑瀛楃涓 } - /** - * Export the folder identified by folder id to text - */ + // 瀵煎嚭鎸囧畾鏂囦欢澶笽D鐨勭瑪璁板埌鏂囨湰 private void exportFolderToText(String folderId, PrintStream ps) { - // Query notes belong to this folder + // 鏌ヨ灞炰簬璇ユ枃浠跺す鐨勭瑪璁 Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI, NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] { folderId }, null); - if (notesCursor != null) { if (notesCursor.moveToFirst()) { do { - // Print note's last modified date + // 鎵撳嵃绗旇鐨勬渶鍚庝慨鏀规棩鏈 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); } while (notesCursor.moveToNext()); } - notesCursor.close(); + notesCursor.close(); // 鍏抽棴娓告爣 } } - /** - * 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, DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] { noteId }, null); - if (dataCursor != null) { if (dataCursor.moveToFirst()) { do { String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE); if (DataConstants.CALL_NOTE.equals(mimeType)) { - // Print phone number + // 濡傛灉MIME绫诲瀷涓洪氳瘽绗旇锛屽垯鎵撳嵃鐢佃瘽鍙风爜銆侀氳瘽鏃ユ湡鍜屼綅缃 String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER); long callDate = dataCursor.getLong(DATA_COLUMN_CALL_DATE); String location = dataCursor.getString(DATA_COLUMN_CONTENT); - if (!TextUtils.isEmpty(phoneNumber)) { ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), phoneNumber)); } - // 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)); } } else if (DataConstants.NOTE.equals(mimeType)) { + // 濡傛灉MIME绫诲瀷涓烘櫘閫氱瑪璁帮紝鍒欐墦鍗扮瑪璁板唴瀹 String content = dataCursor.getString(DATA_COLUMN_CONTENT); if (!TextUtils.isEmpty(content)) { ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), @@ -203,9 +201,9 @@ public class BackupUtils { } } while (dataCursor.moveToNext()); } - dataCursor.close(); + dataCursor.close(); // 鍏抽棴娓告爣 } - // print a line separator between note + // 鎵撳嵃绗旇涔嬮棿鐨勫垎闅旂 try { ps.write(new byte[] { Character.LINE_SEPARATOR, Character.LETTER_NUMBER @@ -215,130 +213,37 @@ 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"); + Log.d(TAG, "Media was not mounted"); // 濡傛灉SD鍗℃湭鎸傝浇锛屽垯璁板綍鏃ュ織骞惰繑鍥炵姸鎬佺爜 return STATE_SD_CARD_UNMOUONTED; } - - PrintStream ps = getExportToTextPrintStream(); + PrintStream ps = getExportToTextPrintStream(); // 鑾峰彇鎸囧悜瀵煎嚭鏂囨湰鏂囦欢鐨凱rintStream瀵硅薄 if (ps == null) { - Log.e(TAG, "get print stream error"); + Log.e(TAG, "get print stream error"); // 濡傛灉鑾峰彇PrintStream澶辫触锛屽垯璁板綍鏃ュ織骞惰繑鍥炵姸鎬佺爜 return STATE_SYSTEM_ERROR; } - // First export folder and its notes + // 鏌ヨ鎵鏈夋枃浠跺す鍜屽叾绗旇锛岄櫎浜嗗瀮鍦剧鏂囦欢澶瑰拰閫氳瘽璁板綍鏂囦欢澶 Cursor folderCursor = mContext.getContentResolver().query( Notes.CONTENT_NOTE_URI, NOTE_PROJECTION, "(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR " + NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null); - if (folderCursor != null) { if (folderCursor.moveToFirst()) { do { - // Print folder's name + // 鎵撳嵃鏂囦欢澶瑰悕绉 String folderName = ""; if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) { - folderName = mContext.getString(R.string.call_record_folder_name); + folderName = mContext.getString(R.string.call_record_folder_name); // 濡傛灉鏄氳瘽璁板綍鏂囦欢澶癸紝鍒欎娇鐢ㄨ祫婧愭枃浠朵腑鐨勫悕绉 } else { - folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET); + folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET); // 鍚﹀垯锛屼娇鐢ㄦ煡璇㈠埌鐨勬枃浠跺す鍚嶇О } if (!TextUtils.isEmpty(folderName)) { ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName)); } String folderId = folderCursor.getString(NOTE_COLUMN_ID); - exportFolderToText(folderId, ps); - } while (folderCursor.moveToNext()); - } - folderCursor.close(); - } - - // Export notes in root's folder - Cursor noteCursor = mContext.getContentResolver().query( - Notes.CONTENT_NOTE_URI, - NOTE_PROJECTION, - NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID - + "=0", null, null); - - if (noteCursor != null) { - if (noteCursor.moveToFirst()) { - do { - ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( - mContext.getString(R.string.format_datetime_mdhm), - noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); - // Query data belong to this note - String noteId = noteCursor.getString(NOTE_COLUMN_ID); - exportNoteToText(noteId, ps); - } while (noteCursor.moveToNext()); - } - noteCursor.close(); - } - ps.close(); - - return STATE_SUCCESS; - } - - /** - * Get a print stream pointed to the file {@generateExportedTextFile} - */ - private PrintStream getExportToTextPrintStream() { - File file = generateFileMountedOnSDcard(mContext, R.string.file_path, - R.string.file_name_txt_format); - if (file == null) { - Log.e(TAG, "create file to exported failed"); - return null; - } - mFileName = file.getName(); - mFileDirectory = mContext.getString(R.string.file_path); - PrintStream ps = null; - try { - FileOutputStream fos = new FileOutputStream(file); - ps = new PrintStream(fos); - } catch (FileNotFoundException e) { - e.printStackTrace(); - return null; - } catch (NullPointerException e) { - e.printStackTrace(); - return null; - } - return ps; - } - } - - /** - * Generate the text file to store imported data - */ - private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) { - StringBuilder sb = new StringBuilder(); - sb.append(Environment.getExternalStorageDirectory()); - sb.append(context.getString(filePathResId)); - File filedir = new File(sb.toString()); - sb.append(context.getString( - fileNameFormatResId, - DateFormat.format(context.getString(R.string.format_date_ymd), - System.currentTimeMillis()))); - File file = new File(sb.toString()); - - try { - if (!filedir.exists()) { - filedir.mkdir(); - } - if (!file.exists()) { - file.createNewFile(); - } - return file; - } catch (SecurityException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - return null; - } -} - + exportFolderToText(folderId diff --git a/src/net/micode/notes/tool/DataUtils.java b/src/net/micode/notes/tool/DataUtils.java index 2a14982..bdb791b 100644 --- a/src/net/micode/notes/tool/DataUtils.java +++ b/src/net/micode/notes/tool/DataUtils.java @@ -34,262 +34,161 @@ import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; import java.util.ArrayList; import java.util.HashSet; - +/** + * 宸ュ叿绫伙紝鎻愪緵瀵圭瑪璁版暟鎹殑鎿嶄綔鏂规硶銆 + */ public class DataUtils { - public static final String TAG = "DataUtils"; + public static final String TAG = "DataUtils"; // 瀹氫箟鏃ュ織鏍囩 + + /** + * 鎵归噺鍒犻櫎绗旇銆 + * @param resolver ContentResolver瀹炰緥锛岀敤浜庤闂暟鎹 + * @param ids 瑕佸垹闄ょ殑绗旇ID闆嗗悎銆 + * @return 濡傛灉鍒犻櫎鎴愬姛杩斿洖true锛屽惁鍒欒繑鍥瀎alse銆 + */ public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) { - if (ids == null) { + if (ids == null) { // 妫鏌ヤ紶鍏ョ殑ID闆嗗悎鏄惁涓虹┖ Log.d(TAG, "the ids is null"); return true; } - if (ids.size() == 0) { + if (ids.size() == 0) { // 妫鏌D闆嗗悎鏄惁涓虹┖ Log.d(TAG, "no id is in the hashset"); return true; } - ArrayList operationList = new ArrayList(); + ArrayList operationList = new ArrayList(); // 鎿嶄綔鍒楄〃锛岀敤浜庢壒閲忔搷浣 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"); continue; } ContentProviderOperation.Builder builder = ContentProviderOperation - .newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); - operationList.add(builder.build()); + .newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); // 鏋勫缓鍒犻櫎鎿嶄綔 + operationList.add(builder.build()); // 灏嗗垹闄ゆ搷浣滄坊鍔犲埌鎿嶄綔鍒楄〃 } try { - ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); - if (results == null || results.length == 0 || results[0] == null) { + ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); // 鎵ц鎵归噺鎿嶄綔 + if (results == null || results.length == 0 || results[0] == null) { // 妫鏌ユ搷浣滅粨鏋 Log.d(TAG, "delete notes failed, ids:" + ids.toString()); return false; } return true; - } catch (RemoteException e) { + } catch (RemoteException e) { // 鎹曡幏杩滅▼寮傚父 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())); } - return false; + return false; // 鍙戠敓寮傚父鏃惰繑鍥瀎alse } + /** + * 灏嗙瑪璁扮Щ鍔ㄥ埌鍙︿竴涓枃浠跺す銆 + * @param resolver ContentResolver瀹炰緥锛岀敤浜庤闂暟鎹 + * @param id 瑕佺Щ鍔ㄧ殑绗旇ID銆 + * @param srcFolderId 褰撳墠鏂囦欢澶笽D銆 + * @param desFolderId 鐩爣鏂囦欢澶笽D銆 + */ public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) { - ContentValues values = new ContentValues(); - values.put(NoteColumns.PARENT_ID, desFolderId); - values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId); - values.put(NoteColumns.LOCAL_MODIFIED, 1); - resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); + ContentValues values = new ContentValues(); // 鍒涘缓ContentValues瀵硅薄锛岀敤浜庢洿鏂版暟鎹 + values.put(NoteColumns.PARENT_ID, desFolderId); // 璁剧疆鏂扮殑鐖禝D锛屽嵆鐩爣鏂囦欢澶笽D + values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId); // 璁剧疆鍘熷鐨勭埗ID锛屽嵆褰撳墠鏂囦欢澶笽D + values.put(NoteColumns.LOCAL_MODIFIED, 1); // 鏍囪绗旇涓烘湰鍦颁慨鏀 + resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); // 鏇存柊绗旇鏁版嵁 } + /** + * 鎵归噺灏嗙瑪璁扮Щ鍔ㄥ埌鎸囧畾鏂囦欢澶广 + * @param resolver ContentResolver瀹炰緥锛岀敤浜庤闂暟鎹 + * @param ids 瑕佺Щ鍔ㄧ殑绗旇ID闆嗗悎銆 + * @param folderId 鐩爣鏂囦欢澶笽D銆 + * @return 濡傛灉绉诲姩鎴愬姛杩斿洖true锛屽惁鍒欒繑鍥瀎alse銆 + */ public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids, long folderId) { - if (ids == null) { + if (ids == null) { // 妫鏌ヤ紶鍏ョ殑ID闆嗗悎鏄惁涓虹┖ Log.d(TAG, "the ids is null"); return true; } - ArrayList operationList = new ArrayList(); + ArrayList operationList = new ArrayList(); // 鎿嶄綔鍒楄〃锛岀敤浜庢壒閲忔搷浣 for (long id : ids) { ContentProviderOperation.Builder builder = ContentProviderOperation - .newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); - builder.withValue(NoteColumns.PARENT_ID, folderId); - builder.withValue(NoteColumns.LOCAL_MODIFIED, 1); - operationList.add(builder.build()); + .newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); // 鏋勫缓鏇存柊鎿嶄綔 + builder.withValue(NoteColumns.PARENT_ID, folderId); // 璁剧疆鏂扮殑鐖禝D锛屽嵆鐩爣鏂囦欢澶笽D + builder.withValue(NoteColumns.LOCAL_MODIFIED, 1); // 鏍囪绗旇涓烘湰鍦颁慨鏀 + operationList.add(builder.build()); // 灏嗘洿鏂版搷浣滄坊鍔犲埌鎿嶄綔鍒楄〃 } try { - ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); - if (results == null || results.length == 0 || results[0] == null) { + ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); // 鎵ц鎵归噺鎿嶄綔 + if (results == null || results.length == 0 || results[0] == null) { // 妫鏌ユ搷浣滅粨鏋 Log.d(TAG, "delete notes failed, ids:" + ids.toString()); return false; } return true; - } catch (RemoteException e) { + } catch (RemoteException e) { // 鎹曡幏杩滅▼寮傚父 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())); } - return false; + return false; // 鍙戠敓寮傚父鏃惰繑鍥瀎alse } /** - * Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}} + * 鑾峰彇鐢ㄦ埛鏂囦欢澶圭殑鏁伴噺锛堜笉鍖呮嫭绯荤粺鏂囦欢澶癸級銆 + * @param resolver ContentResolver瀹炰緥锛岀敤浜庤闂暟鎹 + * @return 鐢ㄦ埛鏂囦欢澶圭殑鏁伴噺銆 */ public static int getUserFolderCount(ContentResolver resolver) { - Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI, - new String[] { "COUNT(*)" }, - NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?", - new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)}, + Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, // 鏌ヨ绗旇鍐呭URI + new String[] { "COUNT(*)" }, // 鏌ヨ璁℃暟 + NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?", // 鏌ヨ鏉′欢锛岀被鍨嬩负鏂囦欢澶逛笖涓嶆槸鍨冨溇绠 + new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)}, // 鏌ヨ鍙傛暟 null); int count = 0; - if(cursor != null) { - if(cursor.moveToFirst()) { + if (cursor != null) { // 妫鏌ユ父鏍囨槸鍚︿负绌 + if (cursor.moveToFirst()) { // 绉诲姩鍒版父鏍囩殑绗竴琛 try { - count = cursor.getInt(0); - } catch (IndexOutOfBoundsException e) { + count = cursor.getInt(0); // 鑾峰彇鏂囦欢澶规暟閲 + } catch (IndexOutOfBoundsException e) { // 鎹曡幏绱㈠紩瓒婄晫寮傚父 Log.e(TAG, "get folder count failed:" + e.toString()); } finally { - cursor.close(); + cursor.close(); // 鍏抽棴娓告爣 } } } - return count; + return count; // 杩斿洖鏂囦欢澶规暟閲 } + /** + * 妫鏌ョ瑪璁板湪鏁版嵁搴撲腑鏄惁鍙銆 + * @param resolver ContentResolver瀹炰緥锛岀敤浜庤闂暟鎹 + * @param noteId 绗旇ID銆 + * @param type 绗旇绫诲瀷銆 + * @return 濡傛灉绗旇鍙杩斿洖true锛屽惁鍒欒繑鍥瀎alse銆 + */ public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) { - Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), - null, - NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER, - new String [] {String.valueOf(type)}, + Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), // 鏌ヨ绗旇URI + null, // 鏃犵壒瀹氬垪 + NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER, // 鏌ヨ鏉′欢锛岀被鍨嬪尮閰嶄笖涓嶅湪鍨冨溇绠 + new String[] {String.valueOf(type)}, // 鏌ヨ鍙傛暟 null); boolean exist = false; - if (cursor != null) { - if (cursor.getCount() > 0) { - exist = true; - } - cursor.close(); - } - return exist; - } - - public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) { - Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), - null, null, null, null); - - boolean exist = false; - if (cursor != null) { - if (cursor.getCount() > 0) { - exist = true; - } - cursor.close(); - } - return exist; - } - - public static boolean existInDataDatabase(ContentResolver resolver, long dataId) { - Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), - null, null, null, null); - - boolean exist = false; - if (cursor != null) { - if (cursor.getCount() > 0) { - exist = true; + if (cursor != null) { // 妫鏌ユ父鏍囨槸鍚︿负绌 + if (cursor.getCount() > 0) { // 妫鏌ユ煡璇㈢粨鏋滄暟閲 + exist = true; // 璁剧疆瀛樺湪鏍囧織涓簍rue } - cursor.close(); + cursor.close(); // 鍏抽棴娓告爣 } - return exist; + return exist; // 杩斿洖绗旇鏄惁瀛樺湪 } - public static boolean checkVisibleFolderName(ContentResolver resolver, String name) { - Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null, - NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + - " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + - " AND " + NoteColumns.SNIPPET + "=?", - new String[] { name }, null); - boolean exist = false; - if(cursor != null) { - if(cursor.getCount() > 0) { - exist = true; - } - cursor.close(); - } - return exist; - } - - public static HashSet getFolderNoteWidget(ContentResolver resolver, long folderId) { - Cursor c = resolver.query(Notes.CONTENT_NOTE_URI, - new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE }, - NoteColumns.PARENT_ID + "=?", - new String[] { String.valueOf(folderId) }, - null); - - HashSet set = null; - if (c != null) { - if (c.moveToFirst()) { - set = new HashSet(); - do { - try { - AppWidgetAttribute widget = new AppWidgetAttribute(); - widget.widgetId = c.getInt(0); - widget.widgetType = c.getInt(1); - set.add(widget); - } catch (IndexOutOfBoundsException e) { - Log.e(TAG, e.toString()); - } - } while (c.moveToNext()); - } - c.close(); - } - return set; - } - - public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) { - Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, - new String [] { CallNote.PHONE_NUMBER }, - CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?", - new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE }, - null); - - if (cursor != null && cursor.moveToFirst()) { - try { - return cursor.getString(0); - } catch (IndexOutOfBoundsException e) { - Log.e(TAG, "Get call number fails " + e.toString()); - } finally { - cursor.close(); - } - } - return ""; - } - - public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) { - Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, - new String [] { CallNote.NOTE_ID }, - CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL(" - + CallNote.PHONE_NUMBER + ",?)", - new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber }, - null); - - if (cursor != null) { - if (cursor.moveToFirst()) { - try { - return cursor.getLong(0); - } catch (IndexOutOfBoundsException e) { - Log.e(TAG, "Get call note id fails " + e.toString()); - } - } - cursor.close(); - } - return 0; - } - - public static String getSnippetById(ContentResolver resolver, long noteId) { - Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, - new String [] { NoteColumns.SNIPPET }, - NoteColumns.ID + "=?", - new String [] { String.valueOf(noteId)}, - null); - - if (cursor != null) { - String snippet = ""; - if (cursor.moveToFirst()) { - snippet = cursor.getString(0); - } - cursor.close(); - return snippet; - } - throw new IllegalArgumentException("Note is not found with id: " + noteId); - } - - public static String getFormattedSnippet(String snippet) { - if (snippet != null) { - snippet = snippet.trim(); - int index = snippet.indexOf('\n'); - if (index != -1) { - snippet = snippet.substring(0, index); - } - } - return snippet; - } -} + /** + * 妫鏌ョ瑪璁板湪鏁版嵁搴撲腑鏄惁瀛樺湪銆 + * @param resolver ContentResolver瀹炰緥锛岀敤浜庤闂暟鎹 + * @param noteId 绗旇ID銆 + * @return 濡傛灉绗旇瀛樺湪杩斿洖true锛屽惁鍒欒繑鍥瀎alse銆 + */ + public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) \ No newline at end of file diff --git a/src/net/micode/notes/tool/GTaskStringUtils.java b/src/net/micode/notes/tool/GTaskStringUtils.java index 666b729..86f3920 100644 --- a/src/net/micode/notes/tool/GTaskStringUtils.java +++ b/src/net/micode/notes/tool/GTaskStringUtils.java @@ -17,97 +17,98 @@ package net.micode.notes.tool; public class GTaskStringUtils { - + // 瀹氫箟GTASK_JSON_ACTION_ID甯搁噺锛岀敤浜庢爣璇嗗姩浣淚D public final static String GTASK_JSON_ACTION_ID = "action_id"; - + // 瀹氫箟GTASK_JSON_ACTION_LIST甯搁噺锛岀敤浜庢爣璇嗗姩浣滃垪琛 public final static String GTASK_JSON_ACTION_LIST = "action_list"; - + // 瀹氫箟GTASK_JSON_ACTION_TYPE甯搁噺锛岀敤浜庢爣璇嗗姩浣滅被鍨 public final static String GTASK_JSON_ACTION_TYPE = "action_type"; - + // 瀹氫箟GTASK_JSON_ACTION_TYPE_CREATE甯搁噺锛岃〃绀哄垱寤哄姩浣 public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; - + // 瀹氫箟GTASK_JSON_ACTION_TYPE_GETALL甯搁噺锛岃〃绀鸿幏鍙栨墍鏈夊姩浣 public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; - + // 瀹氫箟GTASK_JSON_ACTION_TYPE_MOVE甯搁噺锛岃〃绀虹Щ鍔ㄥ姩浣 public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; - + // 瀹氫箟GTASK_JSON_ACTION_TYPE_UPDATE甯搁噺锛岃〃绀烘洿鏂板姩浣 public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; - + // 瀹氫箟GTASK_JSON_CREATOR_ID甯搁噺锛岀敤浜庢爣璇嗗垱寤鸿匢D public final static String GTASK_JSON_CREATOR_ID = "creator_id"; - + // 瀹氫箟GTASK_JSON_CHILD_ENTITY甯搁噺锛岀敤浜庢爣璇嗗瓙瀹炰綋 public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; - + // 瀹氫箟GTASK_JSON_CLIENT_VERSION甯搁噺锛岀敤浜庢爣璇嗗鎴风鐗堟湰 public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; - + // 瀹氫箟GTASK_JSON_COMPLETED甯搁噺锛岀敤浜庢爣璇嗕换鍔℃槸鍚﹀畬鎴 public final static String GTASK_JSON_COMPLETED = "completed"; - + // 瀹氫箟GTASK_JSON_CURRENT_LIST_ID甯搁噺锛岀敤浜庢爣璇嗗綋鍓嶅垪琛↖D public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; - + // 瀹氫箟GTASK_JSON_DEFAULT_LIST_ID甯搁噺锛岀敤浜庢爣璇嗛粯璁ゅ垪琛↖D public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; - + // 瀹氫箟GTASK_JSON_DELETED甯搁噺锛岀敤浜庢爣璇嗕换鍔℃槸鍚﹁鍒犻櫎 public final static String GTASK_JSON_DELETED = "deleted"; - + // 瀹氫箟GTASK_JSON_DEST_LIST甯搁噺锛岀敤浜庢爣璇嗙洰鏍囧垪琛 public final static String GTASK_JSON_DEST_LIST = "dest_list"; - + // 瀹氫箟GTASK_JSON_DEST_PARENT甯搁噺锛岀敤浜庢爣璇嗙洰鏍囩埗浠诲姟 public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; - + // 瀹氫箟GTASK_JSON_DEST_PARENT_TYPE甯搁噺锛岀敤浜庢爣璇嗙洰鏍囩埗浠诲姟绫诲瀷 public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; - + // 瀹氫箟GTASK_JSON_ENTITY_DELTA甯搁噺锛岀敤浜庢爣璇嗗疄浣撳彉鍖 public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta"; - + // 瀹氫箟GTASK_JSON_ENTITY_TYPE甯搁噺锛岀敤浜庢爣璇嗗疄浣撶被鍨 public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; - + // 瀹氫箟GTASK_JSON_GET_DELETED甯搁噺锛岃〃绀鸿幏鍙栧凡鍒犻櫎鐨勪换鍔 public final static String GTASK_JSON_GET_DELETED = "get_deleted"; - + // 瀹氫箟GTASK_JSON_ID甯搁噺锛岀敤浜庢爣璇嗕换鍔D public final static String GTASK_JSON_ID = "id"; - + // 瀹氫箟GTASK_JSON_INDEX甯搁噺锛岀敤浜庢爣璇嗕换鍔″湪鍒楄〃涓殑绱㈠紩 public final static String GTASK_JSON_INDEX = "index"; - + // 瀹氫箟GTASK_JSON_LAST_MODIFIED甯搁噺锛岀敤浜庢爣璇嗕换鍔℃渶鍚庝慨鏀规椂闂 public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; - + // 瀹氫箟GTASK_JSON_LATEST_SYNC_POINT甯搁噺锛岀敤浜庢爣璇嗘渶鏂扮殑鍚屾鐐 public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; - + // 瀹氫箟GTASK_JSON_LIST_ID甯搁噺锛岀敤浜庢爣璇嗗垪琛↖D public final static String GTASK_JSON_LIST_ID = "list_id"; - + // 瀹氫箟GTASK_JSON_LISTS甯搁噺锛岀敤浜庢爣璇嗗垪琛ㄩ泦鍚 public final static String GTASK_JSON_LISTS = "lists"; - + // 瀹氫箟GTASK_JSON_NAME甯搁噺锛岀敤浜庢爣璇嗕换鍔℃垨鍒楄〃鐨勫悕绉 public final static String GTASK_JSON_NAME = "name"; - + // 瀹氫箟GTASK_JSON_NEW_ID甯搁噺锛岀敤浜庢爣璇嗘柊鐨勪换鍔D public final static String GTASK_JSON_NEW_ID = "new_id"; - + // 瀹氫箟GTASK_JSON_NOTES甯搁噺锛岀敤浜庢爣璇嗕换鍔$殑澶囨敞淇℃伅 public final static String GTASK_JSON_NOTES = "notes"; - + // 瀹氫箟GTASK_JSON_PARENT_ID甯搁噺锛岀敤浜庢爣璇嗙埗浠诲姟ID public final static String GTASK_JSON_PARENT_ID = "parent_id"; - + // 瀹氫箟GTASK_JSON_PRIOR_SIBLING_ID甯搁噺锛岀敤浜庢爣璇嗗墠涓涓厔寮熶换鍔D public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; - + // 瀹氫箟GTASK_JSON_RESULTS甯搁噺锛岀敤浜庢爣璇嗘搷浣滅粨鏋 public final static String GTASK_JSON_RESULTS = "results"; - + // 瀹氫箟GTASK_JSON_SOURCE_LIST甯搁噺锛岀敤浜庢爣璇嗘簮鍒楄〃 public final static String GTASK_JSON_SOURCE_LIST = "source_list"; - + // 瀹氫箟GTASK_JSON_TASKS甯搁噺锛岀敤浜庢爣璇嗕换鍔¢泦鍚 public final static String GTASK_JSON_TASKS = "tasks"; - + // 瀹氫箟GTASK_JSON_TYPE甯搁噺锛岀敤浜庢爣璇嗗疄浣撶被鍨 public final static String GTASK_JSON_TYPE = "type"; - + // 瀹氫箟GTASK_JSON_TYPE_GROUP甯搁噺锛岃〃绀哄垎缁勭被鍨 public final static String GTASK_JSON_TYPE_GROUP = "GROUP"; - + // 瀹氫箟GTASK_JSON_TYPE_TASK甯搁噺锛岃〃绀轰换鍔$被鍨 public final static String GTASK_JSON_TYPE_TASK = "TASK"; - + // 瀹氫箟GTASK_JSON_USER甯搁噺锛岀敤浜庢爣璇嗙敤鎴蜂俊鎭 public final static String GTASK_JSON_USER = "user"; + // 瀹氫箟MIUI_FOLDER_PREFFIX甯搁噺锛岀敤浜庢爣璇哅IUI绗旇鐨勬枃浠跺す鍓嶇紑 public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]"; - + // 瀹氫箟FOLDER_DEFAULT甯搁噺锛岀敤浜庢爣璇嗛粯璁ゆ枃浠跺す鍚嶇О public final static String FOLDER_DEFAULT = "Default"; - + // 瀹氫箟FOLDER_CALL_NOTE甯搁噺锛岀敤浜庢爣璇嗛氳瘽璁板綍鏂囦欢澶瑰悕绉 public final static String FOLDER_CALL_NOTE = "Call_Note"; - + // 瀹氫箟FOLDER_META甯搁噺锛岀敤浜庢爣璇嗗厓鏁版嵁鏂囦欢澶瑰悕绉 public final static String FOLDER_META = "METADATA"; + // 瀹氫箟META_HEAD_GTASK_ID甯搁噺锛岀敤浜庢爣璇嗗厓鏁版嵁涓殑GTask ID public final static String META_HEAD_GTASK_ID = "meta_gid"; - + // 瀹氫箟META_HEAD_NOTE甯搁噺锛岀敤浜庢爣璇嗗厓鏁版嵁涓殑绗旇淇℃伅 public final static String META_HEAD_NOTE = "meta_note"; - + // 瀹氫箟META_HEAD_DATA甯搁噺锛岀敤浜庢爣璇嗗厓鏁版嵁涓殑鍏朵粬鏁版嵁 public final static String META_HEAD_DATA = "meta_data"; - + // 瀹氫箟META_NOTE_NAME甯搁噺锛岀敤浜庢爣璇嗗厓鏁版嵁绗旇鐨勫悕绉帮紝璀﹀憡涓嶈鏇存柊鎴栧垹闄 public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE"; - -} +} \ No newline at end of file diff --git a/src/net/micode/notes/tool/ResourceParser.java b/src/net/micode/notes/tool/ResourceParser.java index 1ad3ad6..0b475e9 100644 --- a/src/net/micode/notes/tool/ResourceParser.java +++ b/src/net/micode/notes/tool/ResourceParser.java @@ -22,24 +22,35 @@ import android.preference.PreferenceManager; import net.micode.notes.R; import net.micode.notes.ui.NotesPreferenceActivity; +/** + * 璧勬簮瑙f瀽宸ュ叿绫伙紝鐢ㄤ簬绠$悊涓嶅悓棰滆壊鍜屽瓧浣撳ぇ灏忕殑璧勬簮ID銆 + */ public class ResourceParser { + // 瀹氫箟棰滆壊甯搁噺 public static final int YELLOW = 0; public static final int BLUE = 1; public static final int WHITE = 2; public static final int GREEN = 3; public static final int RED = 4; + // 瀹氫箟榛樿鑳屾櫙棰滆壊甯搁噺 public static final int BG_DEFAULT_COLOR = YELLOW; + // 瀹氫箟瀛椾綋澶у皬甯搁噺 public static final int TEXT_SMALL = 0; public static final int TEXT_MEDIUM = 1; public static final int TEXT_LARGE = 2; public static final int TEXT_SUPER = 3; + // 瀹氫箟榛樿瀛椾綋澶у皬甯搁噺 public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; + /** + * 绗旇鑳屾櫙璧勬簮绫伙紝鐢ㄤ簬鑾峰彇涓嶅悓棰滆壊鐨勭瑪璁拌儗鏅祫婧怚D銆 + */ public static class NoteBgResources { + // 瀹氫箟缂栬緫鐘舵佷笅涓嶅悓棰滆壊鐨勭瑪璁拌儗鏅祫婧怚D鏁扮粍 private final static int [] BG_EDIT_RESOURCES = new int [] { R.drawable.edit_yellow, R.drawable.edit_blue, @@ -48,6 +59,7 @@ public class ResourceParser { R.drawable.edit_red }; + // 瀹氫箟缂栬緫鐘舵佷笅涓嶅悓棰滆壊鐨勭瑪璁版爣棰樿儗鏅祫婧怚D鏁扮粍 private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] { R.drawable.edit_title_yellow, R.drawable.edit_title_blue, @@ -56,15 +68,21 @@ public class ResourceParser { R.drawable.edit_title_red }; + // 鑾峰彇缂栬緫鐘舵佷笅鎸囧畾棰滆壊鐨勭瑪璁拌儗鏅祫婧怚D public static int getNoteBgResource(int id) { return BG_EDIT_RESOURCES[id]; } + // 鑾峰彇缂栬緫鐘舵佷笅鎸囧畾棰滆壊鐨勭瑪璁版爣棰樿儗鏅祫婧怚D public static int getNoteTitleBgResource(int id) { return BG_EDIT_TITLE_RESOURCES[id]; } } + /** + * 鑾峰彇榛樿鐨勮儗鏅疘D銆 + * 濡傛灉璁剧疆浜嗚嚜瀹氫箟鑳屾櫙棰滆壊锛屽垯闅忔満杩斿洖涓涓儗鏅疘D锛屽惁鍒欒繑鍥為粯璁よ儗鏅疘D銆 + */ public static int getDefaultBgId(Context context) { if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean( NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) { @@ -74,7 +92,11 @@ public class ResourceParser { } } + /** + * 绗旇椤硅儗鏅祫婧愮被锛岀敤浜庤幏鍙栦笉鍚屼綅缃紙棣栭」銆佹湯椤广佸崟椤广佹櫘閫氶」锛夌殑绗旇鑳屾櫙璧勬簮ID銆 + */ public static class NoteItemBgResources { + // 瀹氫箟鍒楄〃涓椤逛笉鍚岄鑹茬殑绗旇鑳屾櫙璧勬簮ID鏁扮粍 private final static int [] BG_FIRST_RESOURCES = new int [] { R.drawable.list_yellow_up, R.drawable.list_blue_up, @@ -83,6 +105,7 @@ public class ResourceParser { R.drawable.list_red_up }; + // 瀹氫箟鍒楄〃涓櫘閫氶」涓嶅悓棰滆壊鐨勭瑪璁拌儗鏅祫婧怚D鏁扮粍 private final static int [] BG_NORMAL_RESOURCES = new int [] { R.drawable.list_yellow_middle, R.drawable.list_blue_middle, @@ -91,6 +114,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, @@ -99,6 +123,7 @@ public class ResourceParser { R.drawable.list_red_down, }; + // 瀹氫箟鍒楄〃涓崟椤逛笉鍚岄鑹茬殑绗旇鑳屾櫙璧勬簮ID鏁扮粍 private final static int [] BG_SINGLE_RESOURCES = new int [] { R.drawable.list_yellow_single, R.drawable.list_blue_single, @@ -107,28 +132,37 @@ public class ResourceParser { R.drawable.list_red_single }; + // 鑾峰彇鍒楄〃涓椤规寚瀹氶鑹茬殑绗旇鑳屾櫙璧勬簮ID public static int getNoteBgFirstRes(int id) { return BG_FIRST_RESOURCES[id]; } + // 鑾峰彇鍒楄〃涓湯椤规寚瀹氶鑹茬殑绗旇鑳屾櫙璧勬簮ID public static int getNoteBgLastRes(int id) { return BG_LAST_RESOURCES[id]; } + // 鑾峰彇鍒楄〃涓崟椤规寚瀹氶鑹茬殑绗旇鑳屾櫙璧勬簮ID public static int getNoteBgSingleRes(int id) { return BG_SINGLE_RESOURCES[id]; } + // 鑾峰彇鍒楄〃涓櫘閫氶」鎸囧畾棰滆壊鐨勭瑪璁拌儗鏅祫婧怚D public static int getNoteBgNormalRes(int id) { return BG_NORMAL_RESOURCES[id]; } + // 鑾峰彇鏂囦欢澶硅儗鏅祫婧怚D public static int getFolderBgRes() { return R.drawable.list_folder; } } + /** + * 閮ㄤ欢鑳屾櫙璧勬簮绫伙紝鐢ㄤ簬鑾峰彇涓嶅悓澶у皬锛2x2鍜4x4锛夌殑閮ㄤ欢鑳屾櫙璧勬簮ID銆 + */ public static class WidgetBgResources { + // 瀹氫箟2x2澶у皬涓嶅悓棰滆壊鐨勯儴浠惰儗鏅祫婧怚D鏁扮粍 private final static int [] BG_2X_RESOURCES = new int [] { R.drawable.widget_2x_yellow, R.drawable.widget_2x_blue, @@ -137,10 +171,12 @@ public class ResourceParser { R.drawable.widget_2x_red, }; + // 鑾峰彇2x2澶у皬鎸囧畾棰滆壊鐨勯儴浠惰儗鏅祫婧怚D public static int getWidget2xBgResource(int id) { return BG_2X_RESOURCES[id]; } + // 瀹氫箟4x4澶у皬涓嶅悓棰滆壊鐨勯儴浠惰儗鏅祫婧怚D鏁扮粍 private final static int [] BG_4X_RESOURCES = new int [] { R.drawable.widget_4x_yellow, R.drawable.widget_4x_blue, @@ -149,12 +185,17 @@ public class ResourceParser { R.drawable.widget_4x_red }; + // 鑾峰彇4x4澶у皬鎸囧畾棰滆壊鐨勯儴浠惰儗鏅祫婧怚D public static int getWidget4xBgResource(int id) { return BG_4X_RESOURCES[id]; } } + /** + * 鏂囨湰澶栬璧勬簮绫伙紝鐢ㄤ簬鑾峰彇涓嶅悓澶у皬鐨勬枃鏈瑙傝祫婧怚D銆 + */ public static class TextAppearanceResources { + // 瀹氫箟涓嶅悓澶у皬鐨勬枃鏈瑙傝祫婧怚D鏁扮粍 private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] { R.style.TextAppearanceNormal, R.style.TextAppearanceMedium, @@ -162,6 +203,7 @@ public class ResourceParser { R.style.TextAppearanceSuper }; + // 鑾峰彇鎸囧畾澶у皬鐨勬枃鏈瑙傝祫婧怚D public static int getTexAppearanceResource(int id) { /** * HACKME: Fix bug of store the resource id in shared preference. @@ -174,8 +216,9 @@ public class ResourceParser { return TEXTAPPEARANCE_RESOURCES[id]; } + // 鑾峰彇鏂囨湰澶栬璧勬簮鏁扮粍鐨勫ぇ灏 public static int getResourcesSize() { return TEXTAPPEARANCE_RESOURCES.length; } } -} +} \ No newline at end of file