yangmingrui

main
yangmingrui 7 months ago
parent 87ae690941
commit ea93b3f501

@ -14,362 +14,316 @@
* limitations under the License. * limitations under the License.
*/ */
package net.micode.notes.tool; package net.micode.notes.tool;
import android.content.Context; public class BackupUtils {
import android.database.Cursor; private static final String TAG = "BackupUtils";
import android.net.Uri; // Singleton stuff
import android.os.Environment; private static BackupUtils sInstance; //类里面为什么可以定义自身类的对象?
import android.text.format.DateFormat;
import android.util.Log; public static synchronized BackupUtils getInstance(Context context) {
//ynchronized 关键字,代表这个方法加锁,相当于不管哪一个线程例如线程A
import net.micode.notes.data.Notes; //运行到这个方法时,都要检查有没有其它线程B或者C、 D等正在用这个方法(或者该类的其他同步方法)有的话要等正在使用synchronized方法的线程B或者C 、D运行完这个方法后再运行此线程A,没有的话,锁定调用者,然后直接运行。
import net.micode.notes.data.Notes.DataColumns; //它包括两种用法synchronized 方法和 synchronized 块。
import net.micode.notes.data.Notes.NoteColumns; if (sInstance == null) {
import net.micode.notes.tool.ResourceParser; //如果当前备份不存在,则新声明一个
sInstance = new BackupUtils(context);
import java.io.File; }
import java.io.FileNotFoundException; return sInstance;
import java.io.FileOutputStream; }
import java.io.IOException;
import java.io.PrintStream; /**
import java.text.SimpleDateFormat; * Following states are signs to represents backup or restore
* status
/** */
* BackupUtils 便 // Currently, the sdcard is not mounted SD卡没有被装入手机
* 便 public static final int STATE_SD_CARD_UNMOUONTED = 0;
*/ // The backup file not exist 备份文件夹不存在
public class BackupUtils { public static final int STATE_BACKUP_FILE_NOT_EXIST = 1;
private static final String TAG = "BackupUtils"; // The data is not well formated, may be changed by other programs 数据已被破坏,可能被修改
// 单例模式 public static final int STATE_DATA_DESTROIED = 2;
private static BackupUtils sInstance; // 类里面可以定义自身类的对象,用于实现单例模式 // Some run-time exception which causes restore or backup fails 超时异常
public static final int STATE_SYSTEM_ERROR = 3;
/** // Backup or restore success 成功存储
* BackupUtils public static final int STATE_SUCCESS = 4;
* @param context
* @return BackupUtils private TextExport mTextExport;
*/
public static synchronized BackupUtils getInstance(Context context) { private BackupUtils(Context context) { //初始化函数
// synchronized 关键字,确保多线程环境下线程安全 mTextExport = new TextExport(context);
if (sInstance == null) { }
// 如果当前实例不存在,则创建一个新的实例
sInstance = new BackupUtils(context); private static boolean externalStorageAvailable() { //外部存储功能是否可用
} return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
return sInstance; }
}
public int exportToText() {
/** return mTextExport.exportToText();
* }
*/
public static final int STATE_SD_CARD_UNMOUONTED = 0; // SD卡未挂载 public String getExportedTextFileName() {
public static final int STATE_BACKUP_FILE_NOT_EXIST = 1; // 备份文件不存在 return mTextExport.mFileName;
public static final int STATE_DATA_DESTROIED = 2; // 数据被破坏 }
public static final int STATE_SYSTEM_ERROR = 3; // 系统错误
public static final int STATE_SUCCESS = 4; // 成功 public String getExportedTextFileDir() {
return mTextExport.mFileDirectory;
private TextExport mTextExport; }
private BackupUtils(Context context) { // 初始化函数 private static class TextExport {
mTextExport = new TextExport(context); private static final String[] NOTE_PROJECTION = {
} NoteColumns.ID,
NoteColumns.MODIFIED_DATE,
/** NoteColumns.SNIPPET,
* NoteColumns.TYPE
* @return truefalse };
*/
private static boolean externalStorageAvailable() { private static final int NOTE_COLUMN_ID = 0;
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
} private static final int NOTE_COLUMN_MODIFIED_DATE = 1;
/** private static final int NOTE_COLUMN_SNIPPET = 2;
* 便
* @return private static final String[] DATA_PROJECTION = {
*/ DataColumns.CONTENT,
public int exportToText() { DataColumns.MIME_TYPE,
return mTextExport.exportToText(); DataColumns.DATA1,
} DataColumns.DATA2,
DataColumns.DATA3,
/** DataColumns.DATA4,
* };
* @return
*/ private static final int DATA_COLUMN_CONTENT = 0;
public String getExportedTextFileName() {
return mTextExport.mFileName; 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;
* @return
*/ private final String [] TEXT_FORMAT;
public String getExportedTextFileDir() { private static final int FORMAT_FOLDER_NAME = 0;
return mTextExport.mFileDirectory; private static final int FORMAT_NOTE_DATE = 1;
} private static final int FORMAT_NOTE_CONTENT = 2;
/** private Context mContext;
* TextExport 便 private String mFileName;
*/ private String mFileDirectory;
private static class TextExport {
private static final String[] NOTE_PROJECTION = { public TextExport(Context context) {
NoteColumns.ID, TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note);
NoteColumns.MODIFIED_DATE, mContext = context;
NoteColumns.SNIPPET, mFileName = ""; //为什么为空?
NoteColumns.TYPE mFileDirectory = "";
}; }
private static final int NOTE_COLUMN_ID = 0; private String getFormat(int id) { //获取文本的组成部分
private static final int NOTE_COLUMN_MODIFIED_DATE = 1; return TEXT_FORMAT[id];
private static final int NOTE_COLUMN_SNIPPET = 2; }
private static final String[] DATA_PROJECTION = { /**
DataColumns.CONTENT, * Export the folder identified by folder id to text
DataColumns.MIME_TYPE, */
DataColumns.DATA1, private void exportFolderToText(String folderId, PrintStream ps) {
DataColumns.DATA2, // Query notes belong to this folder 通过查询parent id是文件夹id的note来选出制定ID文件夹下的Note
DataColumns.DATA3, Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI,
DataColumns.DATA4, NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] {
}; folderId
}, null);
private static final int DATA_COLUMN_CONTENT = 0;
private static final int DATA_COLUMN_MIME_TYPE = 1; if (notesCursor != null) {
private static final int DATA_COLUMN_CALL_DATE = 2; if (notesCursor.moveToFirst()) {
private static final int DATA_COLUMN_PHONE_NUMBER = 4; do {
// Print note's last modified date ps里面保存有这份note的日期
private final String [] TEXT_FORMAT; ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
private static final int FORMAT_FOLDER_NAME = 0; mContext.getString(R.string.format_datetime_mdhm),
private static final int FORMAT_NOTE_DATE = 1; notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
private static final int FORMAT_NOTE_CONTENT = 2; // Query data belong to this note
String noteId = notesCursor.getString(NOTE_COLUMN_ID);
private Context mContext; exportNoteToText(noteId, ps); //将文件导出到text
private String mFileName; } while (notesCursor.moveToNext());
private String mFileDirectory; }
notesCursor.close();
public TextExport(Context context) { }
TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note); }
mContext = context;
mFileName = ""; // 初始化为空 /**
mFileDirectory = ""; * Export note identified by id to a print stream
} */
private void exportNoteToText(String noteId, PrintStream ps) {
/** Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI,
* DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] {
* @param id ID noteId
* @return }, null);
*/
private String getFormat(int id) { if (dataCursor != null) { //利用光标来扫描内容区别为callnote和note两种靠ps.printline输出
return TEXT_FORMAT[id]; if (dataCursor.moveToFirst()) {
} do {
String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE);
/** if (DataConstants.CALL_NOTE.equals(mimeType)) {
* 便 // Print phone number
* @param folderId ID String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER);
* @param ps long callDate = dataCursor.getLong(DATA_COLUMN_CALL_DATE);
*/ String location = dataCursor.getString(DATA_COLUMN_CONTENT);
private void exportFolderToText(String folderId, PrintStream ps) {
// 查询属于该文件夹的便签 if (!TextUtils.isEmpty(phoneNumber)) { //判断是否为空字符
Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI, ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] { phoneNumber));
folderId }
}, null); // Print call date
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat
if (notesCursor != null) { .format(mContext.getString(R.string.format_datetime_mdhm),
if (notesCursor.moveToFirst()) { callDate)));
do { // Print call attachment location
// 打印便签的最后修改日期 if (!TextUtils.isEmpty(location)) {
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
mContext.getString(R.string.format_datetime_mdhm), location));
notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); }
// 查询属于该便签的数据 } else if (DataConstants.NOTE.equals(mimeType)) {
String noteId = notesCursor.getString(NOTE_COLUMN_ID); String content = dataCursor.getString(DATA_COLUMN_CONTENT);
exportNoteToText(noteId, ps); // 将便签导出为文本 if (!TextUtils.isEmpty(content)) {
} while (notesCursor.moveToNext()); ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
} content));
notesCursor.close(); }
} }
} } while (dataCursor.moveToNext());
}
/** dataCursor.close();
* 便 }
* @param noteId 便ID // print a line separator between note
* @param ps try {
*/ ps.write(new byte[] {
private void exportNoteToText(String noteId, PrintStream ps) { Character.LINE_SEPARATOR, Character.LETTER_NUMBER
Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, });
DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] { } catch (IOException e) {
noteId Log.e(TAG, e.toString());
}, null); }
}
if (dataCursor != null) {
if (dataCursor.moveToFirst()) { /**
do { * Note will be exported as text which is user readable
String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE); */
if (DataConstants.CALL_NOTE.equals(mimeType)) { public int exportToText() { //总函数调用上面的exportFolder和exportNote
// 打印电话号码 if (!externalStorageAvailable()) {
String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER); Log.d(TAG, "Media was not mounted");
long callDate = dataCursor.getLong(DATA_COLUMN_CALL_DATE); return STATE_SD_CARD_UNMOUONTED;
String location = dataCursor.getString(DATA_COLUMN_CONTENT); }
if (!TextUtils.isEmpty(phoneNumber)) { PrintStream ps = getExportToTextPrintStream();
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), if (ps == null) {
phoneNumber)); Log.e(TAG, "get print stream error");
} return STATE_SYSTEM_ERROR;
// 打印通话日期 }
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat // First export folder and its notes 导出文件夹,就是导出里面包含的便签
.format(mContext.getString(R.string.format_datetime_mdhm), Cursor folderCursor = mContext.getContentResolver().query(
callDate))); Notes.CONTENT_NOTE_URI,
// 打印通话附件位置 NOTE_PROJECTION,
if (!TextUtils.isEmpty(location)) { "(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND "
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR "
location)); + NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null);
}
} else if (DataConstants.NOTE.equals(mimeType)) { if (folderCursor != null) {
String content = dataCursor.getString(DATA_COLUMN_CONTENT); if (folderCursor.moveToFirst()) {
if (!TextUtils.isEmpty(content)) { do {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), // Print folder's name
content)); String folderName = "";
} if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) {
} folderName = mContext.getString(R.string.call_record_folder_name);
} while (dataCursor.moveToNext()); } else {
} folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET);
dataCursor.close(); }
} if (!TextUtils.isEmpty(folderName)) {
// 打印便签之间的分隔符 ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName));
try { }
ps.write(new byte[] { String folderId = folderCursor.getString(NOTE_COLUMN_ID);
Character.LINE_SEPARATOR, Character.LETTER_NUMBER exportFolderToText(folderId, ps);
}); } while (folderCursor.moveToNext());
} catch (IOException e) { }
Log.e(TAG, e.toString()); folderCursor.close();
} }
}
// Export notes in root's folder 将根目录里的便签导出(由于不属于任何文件夹,因此无法通过文件夹导出来实现这一部分便签的导出)
/** Cursor noteCursor = mContext.getContentResolver().query(
* 便 Notes.CONTENT_NOTE_URI,
* @return NOTE_PROJECTION,
*/ NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID
public int exportToText() { + "=0", null, null);
if (!externalStorageAvailable()) {
Log.d(TAG, "Media was not mounted"); if (noteCursor != null) {
return STATE_SD_CARD_UNMOUONTED; if (noteCursor.moveToFirst()) {
} do {
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
PrintStream ps = getExportToTextPrintStream(); mContext.getString(R.string.format_datetime_mdhm),
if (ps == null) { noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
Log.e(TAG, "get print stream error"); // Query data belong to this note
return STATE_SYSTEM_ERROR; String noteId = noteCursor.getString(NOTE_COLUMN_ID);
} exportNoteToText(noteId, ps);
// 首先导出文件夹及其便签 } while (noteCursor.moveToNext());
Cursor folderCursor = mContext.getContentResolver().query( }
Notes.CONTENT_NOTE_URI, noteCursor.close();
NOTE_PROJECTION, }
"(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND " ps.close();
+ NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLDER + ") OR "
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null); return STATE_SUCCESS;
}
if (folderCursor != null) {
if (folderCursor.moveToFirst()) { /**
do { * Get a print stream pointed to the file {@generateExportedTextFile}
// 打印文件夹名称 */
String folderName = ""; private PrintStream getExportToTextPrintStream() {
if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) { File file = generateFileMountedOnSDcard(mContext, R.string.file_path,
folderName = mContext.getString(R.string.call_record_folder_name); R.string.file_name_txt_format);
} else { if (file == null) {
folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET); Log.e(TAG, "create file to exported failed");
} return null;
if (!TextUtils.isEmpty(folderName)) { }
ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName)); mFileName = file.getName();
} mFileDirectory = mContext.getString(R.string.file_path);
String folderId = folderCursor.getString(NOTE_COLUMN_ID); PrintStream ps = null;
exportFolderToText(folderId, ps); try {
} while (folderCursor.moveToNext()); FileOutputStream fos = new FileOutputStream(file);
} ps = new PrintStream(fos); //将ps输出流输出到特定的文件目的就是导出到文件而不是直接输出
folderCursor.close(); } catch (FileNotFoundException e) {
} e.printStackTrace();
return null;
// 导出根目录下的便签 } catch (NullPointerException e) {
Cursor noteCursor = mContext.getContentResolver().query( e.printStackTrace();
Notes.CONTENT_NOTE_URI, return null;
NOTE_PROJECTION, }
NoteColumns.TYPE + "=" + Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID return ps;
+ "=0", null, null); }
}
if (noteCursor != null) {
if (noteCursor.moveToFirst()) { /**
do { * Generate the text file to store imported data
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( */
mContext.getString(R.string.format_datetime_mdhm), private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); StringBuilder sb = new StringBuilder();
// 查询 sb.append(Environment.getExternalStorageDirectory()); //外部SD卡的存储路径
// 属于该便签的数据 sb.append(context.getString(filePathResId)); //文件的存储路径
String noteId = noteCursor.getString(NOTE_COLUMN_ID); File filedir = new File(sb.toString()); //filedir应该就是用来存储路径信息
exportNoteToText(noteId, ps); sb.append(context.getString(
} while (noteCursor.moveToNext()); fileNameFormatResId,
} DateFormat.format(context.getString(R.string.format_date_ymd),
noteCursor.close(); System.currentTimeMillis())));
} File file = new File(sb.toString());
ps.close();
try { //如果这些文件不存在,则新建
return STATE_SUCCESS; if (!filedir.exists()) {
} filedir.mkdir();
}
/** if (!file.exists()) {
* file.createNewFile();
* @return }
*/ return file;
private PrintStream getExportToTextPrintStream() { } catch (SecurityException e) {
File file = generateFileMountedOnSDcard(mContext, R.string.file_path, e.printStackTrace();
R.string.file_name_txt_format); } catch (IOException e) {
if (file == null) { e.printStackTrace();
Log.e(TAG, "create file to exported failed"); }
return null; // try catch 异常处理
} return null;
mFileName = file.getName(); }
mFileDirectory = mContext.getString(R.string.file_path); }
PrintStream ps = null;
try {
FileOutputStream fos = new FileOutputStream(file);
ps = new PrintStream(fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
} catch (NullPointerException e) {
e.printStackTrace();
return null;
}
return ps;
}
}
/**
* SD
* @param context
* @param filePathResId ID
* @param fileNameFormatResId ID
* @return
*/
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
StringBuilder sb = new StringBuilder();
sb.append(Environment.getExternalStorageDirectory()); // 外部SD卡的存储路径
sb.append(context.getString(filePathResId)); // 文件的存储路径
File filedir = new File(sb.toString()); // filedir用于存储路径信息
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;
}

@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/*该类定义在 net.micode.notes.tool 包下并导入了Android和Java的一些核心类。这些导入的类提供了对内容提供者操作、日志记录、游标以及存储值的支持。 */
package net.micode.notes.tool; package net.micode.notes.tool;
/*定义了一个公共类 DataUtils并创建了一个常量 TAG 用于日志记录。 */
import android.content.ContentProviderOperation; import android.content.ContentProviderOperation;
import android.content.ContentProviderResult; import android.content.ContentProviderResult;
import android.content.ContentResolver; import android.content.ContentResolver;
@ -33,19 +34,11 @@ import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
/** /*ID
* DataUtils 便 ID
* 便便便 ContentResolver true false */
*/
public class DataUtils { public class DataUtils {
public static final String TAG = "DataUtils"; public static final String TAG = "DataUtils";
/**
* 便
* @param resolver ContentResolverContentProvider
* @param ids 便ID
* @return truefalse
*/
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) { public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
if (ids == null) { if (ids == null) {
Log.d(TAG, "the ids is null"); Log.d(TAG, "the ids is null");
@ -80,14 +73,9 @@ public class DataUtils {
} }
return false; return false;
} }
/*
/** ID */
* 便 /*查询非系统文件夹的数量。异常处理用于确保在查询失败时释放游标资源。 */
* @param resolver ContentResolverContentProvider
* @param id 便ID
* @param srcFolderId ID
* @param desFolderId ID
*/
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) { public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(NoteColumns.PARENT_ID, desFolderId); values.put(NoteColumns.PARENT_ID, desFolderId);
@ -97,293 +85,301 @@ public class DataUtils {
} }
/** /**
* 便 * @method: batchMoveToFolder
* @param resolver ContentResolverContentProvider * @description: idsfolderId
* @param ids 便ID * @date: 2024/12/26 3:32
* @param folderId ID * @author: zhoukexing
* @return truefalse * @param: [resolver, ids, folderId]
* @return: boolean
*/ */
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids, long folderId) { /*检查数据库中是否存在特定类型的可见笔记。 */
if (ids == null) { /**
Log.d(TAG, "the ids is null"); * 便
return true; * @param resolver ContentResolver
} * @param ids 便ID
* @param folderId ID
* @return
*/
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids, long folderId) {
if (ids == null) {
Log.d(TAG, "the ids is null");
return true;
}
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
for (long id : ids) { for (long id : ids) {
ContentProviderOperation.Builder builder = ContentProviderOperation ContentProviderOperation.Builder builder = ContentProviderOperation
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); .newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
builder.withValue(NoteColumns.PARENT_ID, folderId); builder.withValue(NoteColumns.PARENT_ID, folderId);
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1); builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);
operationList.add(builder.build()); operationList.add(builder.build());
} }
try { try {
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
if (results == null || results.length == 0 || results[0] == null) { if (results == null || results.length == 0 || results[0] == null) {
Log.d(TAG, "move notes failed, ids:" + ids.toString()); Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false; return false;
}
return true;
} catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} catch (OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} }
return false; return true;
} catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} catch (OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} }
return false;
}
/** /**
* *
* @param resolver ContentResolverContentProvider * @param resolver ContentResolver
* @return * @return
*/ */
public static int getUserFolderCount(ContentResolver resolver) { public static int getUserFolderCount(ContentResolver resolver) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { "COUNT(*)" }, new String[] { "COUNT(*)" },
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?", NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?",
new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLDER)}, new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)},
null); null);
int count = 0; int count = 0;
if(cursor != null) { if(cursor != null) {
if(cursor.moveToFirst()) { if(cursor.moveToFirst()) {
try { try {
count = cursor.getInt(0); count = cursor.getInt(0);
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
Log.e(TAG, "get folder count failed:" + e.toString()); Log.e(TAG, "get folder count failed:" + e.toString());
} finally { } finally {
cursor.close(); cursor.close();
}
} }
} }
return count;
} }
return count;
}
/** /**
* ID便 * ID便
* @param resolver ContentResolverContentProvider * @param resolver ContentResolver
* @param noteId 便ID * @param noteId 便ID
* @param type 便 * @param type 便
* @return truefalse * @return
*/ */
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) { public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null,
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLDER, NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
new String [] {String.valueOf(type)}, new String [] {String.valueOf(type)},
null); null);
boolean exist = false; boolean exist = false;
if (cursor != null) { if (cursor != null) {
if (cursor.getCount() > 0) { if (cursor.getCount() > 0) {
exist = true; exist = true;
}
cursor.close();
} }
return exist; cursor.close();
} }
return exist;
}
/** /**
* ID便 * ID便
* @param resolver ContentResolverContentProvider * @param resolver ContentResolver
* @param noteId 便ID * @param noteId 便ID
* @return truefalse * @return
*/ */
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) { public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null); null, null, null, null);
boolean exist = false; boolean exist = false;
if (cursor != null) { if (cursor != null) {
if (cursor.getCount() > 0) { if (cursor.getCount() > 0) {
exist = true; exist = true;
}
cursor.close();
} }
return exist; cursor.close();
} }
return exist;
}
/** /**
* ID * ID
* @param resolver ContentResolverContentProvider * @param resolver ContentResolver
* @param dataId ID * @param dataId ID
* @return truefalse * @return
*/ */
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) { public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
null, null, null, null); null, null, null, null);
boolean exist = false; boolean exist = false;
if (cursor != null) { if (cursor != null) {
if (cursor.getCount() > 0) { if (cursor.getCount() > 0) {
exist = true; exist = true;
}
cursor.close();
} }
return exist; cursor.close();
} }
return exist;
}
/** /**
* *
* @param resolver ContentResolverContentProvider * @param resolver ContentResolver
* @param name * @param name
* @return truefalse * @return
*/ */
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) { public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null, Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
" AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLDER + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER +
" AND " + NoteColumns.SNIPPET + "=?", " AND " + NoteColumns.SNIPPET + "=?",
new String[] { name }, null); new String[] { name }, null);
boolean exist = false; boolean exist = false;
if(cursor != null) { if(cursor != null) {
if(cursor.getCount() > 0) { if(cursor.getCount() > 0) {
exist = true; exist = true;
}
cursor.close();
} }
return exist; cursor.close();
} }
return exist;
}
/** /**
* *
* @param resolver ContentResolverContentProvider * @param resolver ContentResolver
* @param folderId ID * @param folderId ID
* @return * @return
*/ */
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) { public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
Cursor c = resolver.query(Notes.CONTENT_NOTE_URI, Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE }, new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
NoteColumns.PARENT_ID + "=?", NoteColumns.PARENT_ID + "=?",
new String[] { String.valueOf(folderId) }, new String[] { String.valueOf(folderId) },
null); null);
HashSet<AppWidgetAttribute> set = null; HashSet<AppWidgetAttribute> set = null;
if (c != null) { if (c != null) {
if (c.moveToFirst()) { if (c.moveToFirst()) {
set = new HashSet<AppWidgetAttribute>(); set = new HashSet<AppWidgetAttribute>();
do { do {
try { try {
AppWidgetAttribute widget = new AppWidgetAttribute(); AppWidgetAttribute widget = new AppWidgetAttribute();
widget.widgetId = c.getInt(0); widget.widgetId = c.getInt(0);
widget.widgetType = c.getInt(1); widget.widgetType = c.getInt(1);
set.add(widget); set.add(widget);
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
} }
} while (c.moveToNext()); } while (c.moveToNext());
}
c.close();
} }
return set; c.close();
} }
return set;
}
/** /**
* 便ID * 便ID
* @param resolver ContentResolverContentProvider * @param resolver ContentResolver
* @param noteId 便ID * @param noteId 便ID
* @return * @return
*/ */
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) { public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.PHONE_NUMBER }, new String [] { CallNote.PHONE_NUMBER },
CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?", CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE }, new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE },
null); null);
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
try { try {
return cursor.getString(0); return cursor.getString(0);
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call number fails " + e.toString()); Log.e(TAG, "Get call number fails " + e.toString());
} finally { } finally {
cursor.close(); cursor.close();
}
} }
return "";
} }
return "";
}
/** /**
* 便ID * 便ID
* @param resolver ContentResolverContentProvider * @param resolver ContentResolver
* @param phoneNumber * @param phoneNumber
* @param callDate * @param callDate
* @return 便ID * @return 便ID
*/ */
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) { public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.NOTE_ID }, new String [] { CallNote.NOTE_ID },
CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL(" CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
+ CallNote.PHONE_NUMBER + ",?)", + CallNote.PHONE_NUMBER + ",?)",
new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber }, new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber },
null); null);
if (cursor != null) { if (cursor != null) {
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
try { try {
return cursor.getLong(0); return cursor.getLong(0);
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call note id fails " + e.toString()); Log.e(TAG, "Get call note id fails " + e.toString());
}
} }
cursor.close();
} }
return 0; cursor.close();
} }
return 0;
}
/** /**
* 便ID便 * 便ID便
* @param resolver ContentResolverContentProvider * @param resolver ContentResolver
* @param noteId 便ID * @param noteId 便ID
* @return 便 * @return 便
*/ */
public static String getSnippetById(ContentResolver resolver, long noteId) { public static String getSnippetById(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
new String [] { NoteColumns.SNIPPET }, new String [] { NoteColumns.SNIPPET },
NoteColumns.ID + "=?", NoteColumns.ID + "=?",
new String [] { String.valueOf(noteId)}, new String [] { String.valueOf(noteId)},
null); null);
if (cursor != null) { if (cursor != null) {
String snippet = ""; String snippet = "";
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
snippet = cursor.getString(0); snippet = cursor.getString(0);
}
cursor.close();
return snippet;
} }
throw new IllegalArgumentException("Note is not found with id: " + noteId); cursor.close();
return snippet;
} }
throw new IllegalArgumentException("Note is not found with id: " + noteId);
}
/** /**
* 便 * 便
* @param snippet 便 * @param snippet 便
* @return 便 * @return 便
*/ */
public static String getFormattedSnippet(String snippet) { public static String getFormattedSnippet(String snippet) {
if (snippet != null) { if (snippet != null) {
snippet = snippet.trim(); snippet = snippet.trim();
int index = snippet.indexOf('\n'); int index = snippet.indexOf('\n');
if (index != -1) { if (index != -1) {
snippet = snippet.substring(0, index); snippet = snippet.substring(0, index);
}
} }
return snippet;
} }
return snippet;
}
/** /**
* 便 * 便
* @param resolver ContentResolverContentProvider * @param resolver ContentResolver
* @param query * @param query
* @return Cursor * @return Cursor
*/ */
public static Cursor searchInNoteDatabase(ContentResolver resolver, String query) { public static Cursor searchInNoteDatabase(ContentResolver resolver, String query) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String[]{NoteColumns.ID}, new String[]{NoteColumns.ID},
Notes.DataColumns.CONTENT + " LIKE'%" + query +"%'", Notes.DataColumns.CONTENT + " LIKE'%" + query +"%'",
null, null,
null); null);
return cursor; return cursor;
}
} }

@ -14,245 +14,101 @@
* limitations under the License. * limitations under the License.
*/ */
package net.micode.notes.tool; package net.micode.notes.tool;
/** // 该类用于定义 Google 任务相关的 JSON 字段常量
* GTaskStringUtils Google JSON
* Google API JSON
*/
public class GTaskStringUtils { public class GTaskStringUtils {
/**
* JSON ID
*/
public final static String GTASK_JSON_ACTION_ID = "action_id"; public final static String GTASK_JSON_ACTION_ID = "action_id";
/**
* JSON
*/
public final static String GTASK_JSON_ACTION_LIST = "action_list"; public final static String GTASK_JSON_ACTION_LIST = "action_list";
/**
* JSON
*/
public final static String GTASK_JSON_ACTION_TYPE = "action_type"; public final static String GTASK_JSON_ACTION_TYPE = "action_type";
/**
* JSON
*/
public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create";
/**
* JSON
*/
public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all";
/**
* JSON
*/
public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move";
/**
* JSON
*/
public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update";
/**
* JSON ID
*/
public final static String GTASK_JSON_CREATOR_ID = "creator_id"; public final static String GTASK_JSON_CREATOR_ID = "creator_id";
/**
* JSON
*/
public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; public final static String GTASK_JSON_CHILD_ENTITY = "child_entity";
/**
* JSON
*/
public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; public final static String GTASK_JSON_CLIENT_VERSION = "client_version";
/**
* JSON
*/
public final static String GTASK_JSON_COMPLETED = "completed"; public final static String GTASK_JSON_COMPLETED = "completed";
/**
* JSON ID
*/
public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id";
/**
* JSON ID
*/
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id";
/**
* JSON
*/
public final static String GTASK_JSON_DELETED = "deleted"; public final static String GTASK_JSON_DELETED = "deleted";
/**
* JSON
*/
public final static String GTASK_JSON_DEST_LIST = "dest_list"; public final static String GTASK_JSON_DEST_LIST = "dest_list";
/**
* JSON
*/
public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; public final static String GTASK_JSON_DEST_PARENT = "dest_parent";
/**
* JSON
*/
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type";
/**
* JSON
*/
public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta"; public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta";
/**
* JSON
*/
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; public final static String GTASK_JSON_ENTITY_TYPE = "entity_type";
/**
* JSON
*/
public final static String GTASK_JSON_GET_DELETED = "get_deleted"; public final static String GTASK_JSON_GET_DELETED = "get_deleted";
/**
* JSON ID
*/
public final static String GTASK_JSON_ID = "id"; public final static String GTASK_JSON_ID = "id";
/**
* JSON
*/
public final static String GTASK_JSON_INDEX = "index"; public final static String GTASK_JSON_INDEX = "index";
/**
* JSON
*/
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; public final static String GTASK_JSON_LAST_MODIFIED = "last_modified";
/**
* JSON
*/
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point";
/**
* JSON ID
*/
public final static String GTASK_JSON_LIST_ID = "list_id"; public final static String GTASK_JSON_LIST_ID = "list_id";
/**
* JSON
*/
public final static String GTASK_JSON_LISTS = "lists"; public final static String GTASK_JSON_LISTS = "lists";
/**
* JSON
*/
public final static String GTASK_JSON_NAME = "name"; public final static String GTASK_JSON_NAME = "name";
/**
* JSON ID
*/
public final static String GTASK_JSON_NEW_ID = "new_id"; public final static String GTASK_JSON_NEW_ID = "new_id";
/**
* JSON 便
*/
public final static String GTASK_JSON_NOTES = "notes"; public final static String GTASK_JSON_NOTES = "notes";
/**
* JSON ID
*/
public final static String GTASK_JSON_PARENT_ID = "parent_id"; public final static String GTASK_JSON_PARENT_ID = "parent_id";
/**
* JSON ID
*/
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id";
/**
* JSON
*/
public final static String GTASK_JSON_RESULTS = "results"; public final static String GTASK_JSON_RESULTS = "results";
/**
* JSON
*/
public final static String GTASK_JSON_SOURCE_LIST = "source_list"; public final static String GTASK_JSON_SOURCE_LIST = "source_list";
/**
* JSON
*/
public final static String GTASK_JSON_TASKS = "tasks"; public final static String GTASK_JSON_TASKS = "tasks";
/**
* JSON
*/
public final static String GTASK_JSON_TYPE = "type"; public final static String GTASK_JSON_TYPE = "type";
/**
* JSON
*/
public final static String GTASK_JSON_TYPE_GROUP = "GROUP"; public final static String GTASK_JSON_TYPE_GROUP = "GROUP";
/**
* JSON
*/
public final static String GTASK_JSON_TYPE_TASK = "TASK"; public final static String GTASK_JSON_TYPE_TASK = "TASK";
/**
* JSON
*/
public final static String GTASK_JSON_USER = "user"; public final static String GTASK_JSON_USER = "user";
/**
* MIUI
*/
public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]"; public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]";
/**
*
*/
public final static String FOLDER_DEFAULT = "Default"; public final static String FOLDER_DEFAULT = "Default";
/**
*
*/
public final static String FOLDER_CALL_NOTE = "Call_Note"; public final static String FOLDER_CALL_NOTE = "Call_Note";
/**
*
*/
public final static String FOLDER_META = "METADATA"; public final static String FOLDER_META = "METADATA";
/**
* Google ID
*/
public final static String META_HEAD_GTASK_ID = "meta_gid"; 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_NOTE = "meta_note";
/**
*
*/
public final static String META_HEAD_DATA = "meta_data"; 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,8 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
package net.micode.notes.tool; package net.micode.notes.tool;
import android.content.Context; import android.content.Context;
@ -24,43 +22,28 @@ import android.preference.PreferenceManager;
import net.micode.notes.R; import net.micode.notes.R;
import net.micode.notes.ui.NotesPreferenceActivity; import net.micode.notes.ui.NotesPreferenceActivity;
/** // 资源解析器类
* 便
*/
public class ResourceParser { 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 YELLOW = 0; // 黄色 public static final int GREEN = 3;
public static final int BLUE = 1; // 蓝色 public static final int RED = 4;
public static final int WHITE = 2; // 白色
public static final int GREEN = 3; // 绿色
public static final int RED = 4; // 红色
/**
* ID
*/
public static final int BG_DEFAULT_COLOR = YELLOW; public static final int BG_DEFAULT_COLOR = YELLOW;
/** public static final int TEXT_SMALL = 0;
* public static final int TEXT_MEDIUM = 1;
*/ public static final int TEXT_LARGE = 2;
public static final int TEXT_SMALL = 0; // 小 public static final int TEXT_SUPER = 3;
public static final int TEXT_MEDIUM = 1; // 中
public static final int TEXT_LARGE = 2; // 大
public static final int TEXT_SUPER = 3; // 超大
/**
* ID
*/
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
/** // 备忘录背景资源类
* 便便
*/
public static class NoteBgResources { public static class NoteBgResources {
private final static int[] BG_EDIT_RESOURCES = new int[]{ private final static int [] BG_EDIT_RESOURCES = new int [] {
R.drawable.edit_yellow, R.drawable.edit_yellow,
R.drawable.edit_blue, R.drawable.edit_blue,
R.drawable.edit_white, R.drawable.edit_white,
@ -68,7 +51,7 @@ public class ResourceParser {
R.drawable.edit_red R.drawable.edit_red
}; };
private final static int[] BG_EDIT_TITLE_RESOURCES = new int[]{ private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] {
R.drawable.edit_title_yellow, R.drawable.edit_title_yellow,
R.drawable.edit_title_blue, R.drawable.edit_title_blue,
R.drawable.edit_title_white, R.drawable.edit_title_white,
@ -76,30 +59,18 @@ public class ResourceParser {
R.drawable.edit_title_red R.drawable.edit_title_red
}; };
/** // 获取备忘录背景资源
* 便ID
* @param id ID
* @return ID
*/
public static int getNoteBgResource(int id) { public static int getNoteBgResource(int id) {
return BG_EDIT_RESOURCES[id]; return BG_EDIT_RESOURCES[id];
} }
/** // 获取备忘录标题背景资源
* 便ID
* @param id ID
* @return ID
*/
public static int getNoteTitleBgResource(int id) { public static int getNoteTitleBgResource(int id) {
return BG_EDIT_TITLE_RESOURCES[id]; return BG_EDIT_TITLE_RESOURCES[id];
} }
} }
/** // 获取默认背景ID
* ID
* @param context
* @return ID
*/
public static int getDefaultBgId(Context context) { public static int getDefaultBgId(Context context) {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean( if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) { NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
@ -109,11 +80,9 @@ public class ResourceParser {
} }
} }
/** // 备忘录项目背景资源类
* 便便
*/
public static class NoteItemBgResources { public static class NoteItemBgResources {
private final static int[] BG_FIRST_RESOURCES = new int[]{ private final static int [] BG_FIRST_RESOURCES = new int [] {
R.drawable.list_yellow_up, R.drawable.list_yellow_up,
R.drawable.list_blue_up, R.drawable.list_blue_up,
R.drawable.list_white_up, R.drawable.list_white_up,
@ -121,7 +90,7 @@ public class ResourceParser {
R.drawable.list_red_up R.drawable.list_red_up
}; };
private final static int[] BG_NORMAL_RESOURCES = new int[]{ private final static int [] BG_NORMAL_RESOURCES = new int [] {
R.drawable.list_yellow_middle, R.drawable.list_yellow_middle,
R.drawable.list_blue_middle, R.drawable.list_blue_middle,
R.drawable.list_white_middle, R.drawable.list_white_middle,
@ -129,15 +98,15 @@ public class ResourceParser {
R.drawable.list_red_middle R.drawable.list_red_middle
}; };
private final static int[] BG_LAST_RESOURCES = new int[]{ private final static int [] BG_LAST_RESOURCES = new int [] {
R.drawable.list_yellow_down, R.drawable.list_yellow_down,
R.drawable.list_blue_down, R.drawable.list_blue_down,
R.drawable.list_white_down, R.drawable.list_white_down,
R.drawable.list_green_down, R.drawable.list_green_down,
R.drawable.list_red_down R.drawable.list_red_down,
}; };
private final static int[] BG_SINGLE_RESOURCES = new int[]{ private final static int [] BG_SINGLE_RESOURCES = new int [] {
R.drawable.list_yellow_single, R.drawable.list_yellow_single,
R.drawable.list_blue_single, R.drawable.list_blue_single,
R.drawable.list_white_single, R.drawable.list_white_single,
@ -145,73 +114,48 @@ public class ResourceParser {
R.drawable.list_red_single R.drawable.list_red_single
}; };
/** // 获取备忘录第一个背景资源
* 便ID
* @param id ID
* @return ID
*/
public static int getNoteBgFirstRes(int id) { public static int getNoteBgFirstRes(int id) {
return BG_FIRST_RESOURCES[id]; return BG_FIRST_RESOURCES[id];
} }
/** // 获取备忘录最后一个背景资源
* 便ID
* @param id ID
* @return ID
*/
public static int getNoteBgLastRes(int id) { public static int getNoteBgLastRes(int id) {
return BG_LAST_RESOURCES[id]; return BG_LAST_RESOURCES[id];
} }
/** // 获取备忘录单独背景资源
* 便ID
* @param id ID
* @return ID
*/
public static int getNoteBgSingleRes(int id) { public static int getNoteBgSingleRes(int id) {
return BG_SINGLE_RESOURCES[id]; return BG_SINGLE_RESOURCES[id];
} }
/** // 获取备忘录正常背景资源
* 便ID
* @param id ID
* @return ID
*/
public static int getNoteBgNormalRes(int id) { public static int getNoteBgNormalRes(int id) {
return BG_NORMAL_RESOURCES[id]; return BG_NORMAL_RESOURCES[id];
} }
/** // 获取文件夹背景资源
* ID
* @return ID
*/
public static int getFolderBgRes() { public static int getFolderBgRes() {
return R.drawable.list_folder; return R.drawable.list_folder;
} }
} }
/** // 小部件背景资源类
*
*/
public static class WidgetBgResources { public static class WidgetBgResources {
private final static int[] BG_2X_RESOURCES = new int[]{ private final static int [] BG_2X_RESOURCES = new int [] {
R.drawable.widget_2x_yellow, R.drawable.widget_2x_yellow,
R.drawable.widget_2x_blue, R.drawable.widget_2x_blue,
R.drawable.widget_2x_white, R.drawable.widget_2x_white,
R.drawable.widget_2x_green, R.drawable.widget_2x_green,
R.drawable.widget_2x_red R.drawable.widget_2x_red,
}; };
/** // 获取2x小部件背景资源
* 2xID
* @param id ID
* @return ID
*/
public static int getWidget2xBgResource(int id) { public static int getWidget2xBgResource(int id) {
return BG_2X_RESOURCES[id]; return BG_2X_RESOURCES[id];
} }
private final static int[] BG_4X_RESOURCES = new int[]{ private final static int [] BG_4X_RESOURCES = new int [] {
R.drawable.widget_4x_yellow, R.drawable.widget_4x_yellow,
R.drawable.widget_4x_blue, R.drawable.widget_4x_blue,
R.drawable.widget_4x_white, R.drawable.widget_4x_white,
@ -219,43 +163,35 @@ public class ResourceParser {
R.drawable.widget_4x_red R.drawable.widget_4x_red
}; };
/** // 获取4x小部件背景资源
* 4xID
* @param id ID
* @return ID
*/
public static int getWidget4xBgResource(int id) { public static int getWidget4xBgResource(int id) {
return BG_4X_RESOURCES[id]; return BG_4X_RESOURCES[id];
} }
} }
/** // 文本外观资源类
*
*/
public static class TextAppearanceResources { public static class TextAppearanceResources {
private final static int[] TEXTAPPEARANCE_RESOURCES = new int[]{ private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
R.style.TextAppearanceNormal, R.style.TextAppearanceNormal,
R.style.TextAppearanceMedium, R.style.TextAppearanceMedium,
R.style.TextAppearanceLarge, R.style.TextAppearanceLarge,
R.style.TextAppearanceSuper R.style.TextAppearanceSuper
}; };
/** // 获取文本外观资源
* ID
* @param id ID
* @return ID
*/
public static int getTexAppearanceResource(int 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}
*/
if (id >= TEXTAPPEARANCE_RESOURCES.length) { if (id >= TEXTAPPEARANCE_RESOURCES.length) {
return TEXTAPPEARANCE_RESOURCES[BG_DEFAULT_FONT_SIZE]; return BG_DEFAULT_FONT_SIZE;
} }
return TEXTAPPEARANCE_RESOURCES[id]; return TEXTAPPEARANCE_RESOURCES[id];
} }
/** // 获取资源大小
*
* @return
*/
public static int getResourcesSize() { public static int getResourcesSize() {
return TEXTAPPEARANCE_RESOURCES.length; return TEXTAPPEARANCE_RESOURCES.length;
} }

Loading…
Cancel
Save