更新tool包注释

master
田艳 2 years ago
parent 22978f08aa
commit 8943a6ce11

@ -36,309 +36,393 @@ import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
/**
*/
public class BackupUtils { public class BackupUtils {
private static final String TAG = "BackupUtils";
// Singleton stuff // 日志标签
private static BackupUtils sInstance; private static final String TAG = "BackupUtils";
public static synchronized BackupUtils getInstance(Context context) { // 单例实例
if (sInstance == null) { private static BackupUtils sInstance;
sInstance = new BackupUtils(context);
} /**
return sInstance;
}
@param context
/** @return
* Following states are signs to represents backup or restore */
* status public static synchronized BackupUtils getInstance(Context context) {
*/ if (sInstance == null) {
// Currently, the sdcard is not mounted sInstance = new BackupUtils(context);
public static final int STATE_SD_CARD_UNMOUONTED = 0; }
// The backup file not exist return sInstance;
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 // 当前SD卡未挂载
public static final int STATE_SUCCESS = 4; public static final int STATE_SD_CARD_UNMOUONTED = 0;
// 备份文件不存在
private TextExport mTextExport; public static final int STATE_BACKUP_FILE_NOT_EXIST = 1;
// 数据格式不正确,可能被其他程序改变
private BackupUtils(Context context) { public static final int STATE_DATA_DESTROIED = 2;
mTextExport = new TextExport(context); // 运行时异常导致备份或还原失败
} public static final int STATE_SYSTEM_ERROR = 3;
// 备份或还原成功
private static boolean externalStorageAvailable() { public static final int STATE_SUCCESS = 4;
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); // 文本导出对象
} private TextExport mTextExport;
public int exportToText() { /**
return mTextExport.exportToText();
}
@param context
public String getExportedTextFileName() { */
return mTextExport.mFileName; private BackupUtils(Context context) {
} mTextExport = new TextExport(context);
}
public String getExportedTextFileDir() { /**
return mTextExport.mFileDirectory;
}
@return
private static class TextExport { */
private static final String[] NOTE_PROJECTION = { private static boolean externalStorageAvailable() {
NoteColumns.ID, return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
NoteColumns.MODIFIED_DATE, }
NoteColumns.SNIPPET, /**
NoteColumns.TYPE
};
@return
private static final int NOTE_COLUMN_ID = 0; */
public int exportToText() {
private static final int NOTE_COLUMN_MODIFIED_DATE = 1; return mTextExport.exportToText();
}
private static final int NOTE_COLUMN_SNIPPET = 2; /**
private static final String[] DATA_PROJECTION = {
DataColumns.CONTENT, @return
DataColumns.MIME_TYPE, */
DataColumns.DATA1, public String getExportedTextFileName() {
DataColumns.DATA2, return mTextExport.mFileName;
DataColumns.DATA3, }
DataColumns.DATA4, /**
};
private static final int DATA_COLUMN_CONTENT = 0; @return
*/
private static final int DATA_COLUMN_MIME_TYPE = 1; public String getExportedTextFileDir() {
return mTextExport.mFileDirectory;
private static final int DATA_COLUMN_CALL_DATE = 2; }
}
private static final int DATA_COLUMN_PHONE_NUMBER = 4; /**
private final String [] TEXT_FORMAT; Note
private static final int FORMAT_FOLDER_NAME = 0; */
private static final int FORMAT_NOTE_DATE = 1; private static class TextExport {
private static final int FORMAT_NOTE_CONTENT = 2;
// 定义查询Note时需要使用的列的名字
private Context mContext; private static final String[] NOTE_PROJECTION = {
private String mFileName; NoteColumns.ID,
private String mFileDirectory; NoteColumns.MODIFIED_DATE,
NoteColumns.SNIPPET,
public TextExport(Context context) { NoteColumns.TYPE
TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note); };
mContext = context;
mFileName = ""; // 定义查询结果中各列的索引
mFileDirectory = ""; 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 String getFormat(int id) {
return TEXT_FORMAT[id]; // 定义查询Data时需要使用的列的名字
} private static final String[] DATA_PROJECTION = {
DataColumns.CONTENT,
/** DataColumns.MIME_TYPE,
* Export the folder identified by folder id to text DataColumns.DATA1,
*/ DataColumns.DATA2,
private void exportFolderToText(String folderId, PrintStream ps) { DataColumns.DATA3,
// Query notes belong to this folder DataColumns.DATA4,
Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI, };
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.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( private final String [] TEXT_FORMAT;
mContext.getString(R.string.format_datetime_mdhm),
notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); // 相关变量
// Query data belong to this note private Context mContext;
String noteId = notesCursor.getString(NOTE_COLUMN_ID); private String mFileName;
exportNoteToText(noteId, ps); private String mFileDirectory;
} while (notesCursor.moveToNext());
} /**
notesCursor.close();
}
}
@param context
/** */
* Export note identified by id to a print stream public TextExport(Context context) {
*/ // 获取文本格式数组
private void exportNoteToText(String noteId, PrintStream ps) { TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note);
Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI,
DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] { mContext = context;
noteId mFileName = "";
}, null); mFileDirectory = "";
if (dataCursor != null) { }
if (dataCursor.moveToFirst()) {
do { /**
String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE);
if (DataConstants.CALL_NOTE.equals(mimeType)) {
// Print phone number @param id
String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER); @return
long callDate = dataCursor.getLong(DATA_COLUMN_CALL_DATE); */
String location = dataCursor.getString(DATA_COLUMN_CONTENT); private String getFormat(int id) {
return TEXT_FORMAT[id];
if (!TextUtils.isEmpty(phoneNumber)) { }
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), /**
phoneNumber));
} idnote
// Print call date @param folderId id
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat @param ps PrintStream
.format(mContext.getString(R.string.format_datetime_mdhm), */
callDate))); private void exportFolderToText(String folderId, PrintStream ps) {
// Print call attachment location // 查询属于指定文件夹的note
if (!TextUtils.isEmpty(location)) { Cursor notesCursor = mContext.getContentResolver().query(
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), Notes.CONTENT_NOTE_URI,
location)); NOTE_PROJECTION,
} NoteColumns.PARENT_ID + "=?",
} else if (DataConstants.NOTE.equals(mimeType)) { new String[] { folderId },
String content = dataCursor.getString(DATA_COLUMN_CONTENT); null);
if (!TextUtils.isEmpty(content)) { if (notesCursor != null) {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), if (notesCursor.moveToFirst()) {
content)); do {
} // 输出note的最后修改日期
} ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
} while (dataCursor.moveToNext()); mContext.getString(R.string.format_datetime_mdhm),
} notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
dataCursor.close(); // 查询属于指定note的data
} String noteId = notesCursor.getString(NOTE_COLUMN_ID);
// print a line separator between note exportNoteToText(noteId, ps);
try { } while (notesCursor.moveToNext());
ps.write(new byte[] { }
Character.LINE_SEPARATOR, Character.LETTER_NUMBER notesCursor.close();
}); }
} catch (IOException e) { }
Log.e(TAG, e.toString());
} /**
}
idnote
/** @param noteId noteid
* Note will be exported as text which is user readable @param ps PrintStream
*/ */
public int exportToText() { private void exportNoteToText(String noteId, PrintStream ps) {
if (!externalStorageAvailable()) { Cursor dataCursor = mContext.getContentResolver().query(
Log.d(TAG, "Media was not mounted"); Notes.CONTENT_DATA_URI,
return STATE_SD_CARD_UNMOUONTED; DATA_PROJECTION,
} DataColumns.NOTE_ID + "=?",
new String[] { noteId },
PrintStream ps = getExportToTextPrintStream(); null);
if (ps == null) { if (dataCursor != null) {
Log.e(TAG, "get print stream error"); if (dataCursor.moveToFirst()) {
return STATE_SYSTEM_ERROR; do {
} String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE);
// First export folder and its notes if (DataConstants.CALL_NOTE.equals(mimeType)) {
Cursor folderCursor = mContext.getContentResolver().query( // 如果是Call Note则输出电话号码、通话日期和附件位置
Notes.CONTENT_NOTE_URI, String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER);
NOTE_PROJECTION, long callDate = dataCursor.getLong(DATA_COLUMN_CALL_DATE);
"(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND " String location = dataCursor.getString(DATA_COLUMN_CONTENT);
+ NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR "
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null); // 如果电话号码不为空,则输出
if (!TextUtils.isEmpty(phoneNumber)) {
if (folderCursor != null) { ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
if (folderCursor.moveToFirst()) { phoneNumber));
do { }
// Print folder's name // 输出通话日期
String folderName = ""; ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat
if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) { .format(mContext.getString(R.string.format_datetime_mdhm),
folderName = mContext.getString(R.string.call_record_folder_name); callDate)));
} else { // 如果附件位置不为空,则输出
folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET); if (!TextUtils.isEmpty(location)) {
} ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
if (!TextUtils.isEmpty(folderName)) { location));
ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName)); }
} } else if (DataConstants.NOTE.equals(mimeType)) {
String folderId = folderCursor.getString(NOTE_COLUMN_ID); // 如果是普通Note则输出内容
exportFolderToText(folderId, ps); String content = dataCursor.getString(DATA_COLUMN_CONTENT);
} while (folderCursor.moveToNext()); if (!TextUtils.isEmpty(content)) {
} ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
folderCursor.close(); content));
} }
}
// Export notes in root's folder } while (dataCursor.moveToNext());
Cursor noteCursor = mContext.getContentResolver().query( }
Notes.CONTENT_NOTE_URI, dataCursor.close();
NOTE_PROJECTION, }
NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID // 在不同note之间输出一个空行
+ "=0", null, null); try {
ps.write(new byte[] { Character.LINE_SEPARATOR, Character.LETTER_NUMBER });
if (noteCursor != null) { } catch (IOException e) {
if (noteCursor.moveToFirst()) { Log.e(TAG, e.toString());
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); note
exportNoteToText(noteId, ps);
} while (noteCursor.moveToNext()); @return
} */
noteCursor.close(); public int exportToText() {
} if (!externalStorageAvailable()) {
ps.close(); // 检查外部存储是否挂载,未挂载则返回错误
Log.d(TAG, "Media was not mounted");
return STATE_SUCCESS; return STATE_SD_CARD_UNMOUONTED;
} }
/** // 获取输出流
* Get a print stream pointed to the file {@generateExportedTextFile} PrintStream ps = getExportToTextPrintStream();
*/ if (ps == null) {
private PrintStream getExportToTextPrintStream() { Log.e(TAG, "get print stream error");
File file = generateFileMountedOnSDcard(mContext, R.string.file_path, return STATE_SYSTEM_ERROR;
R.string.file_name_txt_format); }
if (file == null) {
Log.e(TAG, "create file to exported failed"); // 首先导出各个文件夹及其子note
return null; Cursor folderCursor = mContext.getContentResolver().query(
} Notes.CONTENT_NOTE_URI,
mFileName = file.getName(); NOTE_PROJECTION,
mFileDirectory = mContext.getString(R.string.file_path); "(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND "
PrintStream ps = null; + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR "
try { + NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER,
FileOutputStream fos = new FileOutputStream(file); null,
ps = new PrintStream(fos); null);
} catch (FileNotFoundException e) { if (folderCursor != null) {
e.printStackTrace(); if (folderCursor.moveToFirst()) {
return null; do {
} catch (NullPointerException e) { // 输出文件夹的名称
e.printStackTrace(); String folderName = "";
return null; if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) {
} folderName = mContext.getString(R.string.call_record_folder_name);
return ps; } else {
} folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET);
} }
if (!TextUtils.isEmpty(folderName)) {
/** ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName));
* Generate the text file to store imported data }
*/ String folderId = folderCursor.getString(NOTE_COLUMN_ID);
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) { exportFolderToText(folderId, ps);
StringBuilder sb = new StringBuilder(); } while (folderCursor.moveToNext());
sb.append(Environment.getExternalStorageDirectory()); }
sb.append(context.getString(filePathResId)); folderCursor.close();
File filedir = new File(sb.toString()); }
sb.append(context.getString(
fileNameFormatResId, // 导出Root文件夹中的note
DateFormat.format(context.getString(R.string.format_date_ymd), Cursor noteCursor = mContext.getContentResolver().query(
System.currentTimeMillis()))); Notes.CONTENT_NOTE_URI,
File file = new File(sb.toString()); NOTE_PROJECTION,
NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID
try { + "=0",
if (!filedir.exists()) { null,
filedir.mkdir(); null);
} if (noteCursor != null) {
if (!file.exists()) { if (noteCursor.moveToFirst()) {
file.createNewFile(); do {
} // 输出note的最后修改日期
return file; ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
} catch (SecurityException e) { mContext.getString(R.string.format_datetime_mdhm),
e.printStackTrace(); noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
} catch (IOException e) { // 查询属于指定note的data
e.printStackTrace(); String noteId = noteCursor.getString(NOTE_COLUMN_ID);
} exportNoteToText(noteId, ps);
} while (noteCursor.moveToNext());
return null; }
} noteCursor.close();
}
ps.close();
return STATE_SUCCESS;
}
/**
SD
@return PrintStream
*/
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;
}
}
/**
*/
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
// 使用StringBuilder的效率更高
StringBuilder sb = new StringBuilder();
// 获取SD卡目录并添加文件路径
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;
} }

@ -36,260 +36,269 @@ import java.util.HashSet;
public class DataUtils { public class DataUtils {
public static final String TAG = "DataUtils"; public static final String TAG = "DataUtils"; //静态常量,日志标记
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) { //批量删除笔记,返回操作成功与否的布尔值
if (ids == null) { public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) {
Log.d(TAG, "the ids is null"); if (ids == null) { //如果id集合为空记录日志并返回true
return true; Log.d(TAG, "the ids is null");
} return true;
if (ids.size() == 0) { }
Log.d(TAG, "no id is in the hashset"); if (ids.size() == 0) { //如果集合中没有id记录日志并返回true
return true; Log.d(TAG, "no id is in the hashset");
} return true;
}
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); //创建操作列表
for (long id : ids) { ArrayList operationList = new ArrayList();
if(id == Notes.ID_ROOT_FOLDER) { //遍历id集合为每个id创建一个对应的删除操作并添加到操作列表中
Log.e(TAG, "Don't delete system folder root"); for (long id : ids) {
continue; if(id == Notes.ID_ROOT_FOLDER) { //如果是系统文件夹根目录,记录日志并跳过
} Log.e(TAG, "Don't delete system folder root");
ContentProviderOperation.Builder builder = ContentProviderOperation continue;
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); }
operationList.add(builder.build()); ContentProviderOperation.Builder builder = ContentProviderOperation
} .newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
try { operationList.add(builder.build());
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); }
if (results == null || results.length == 0 || results[0] == null) { try { //调用applyBatch方法执行操作
Log.d(TAG, "delete notes failed, ids:" + ids.toString()); ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
return false; //检查是否操作成功如不成功记录日志并返回false成功返回true
} if (results == null || results.length == 0 || results[0] == null) {
return true; Log.d(TAG, "delete notes failed, ids:" + ids.toString());
} catch (RemoteException e) { return false;
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); }
} catch (OperationApplicationException e) { return true;
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); } catch (RemoteException e) { //捕获异常并记录日志返回false
} Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
return false; } catch (OperationApplicationException e) { //同上
} Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
}
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) { return false;
ContentValues values = new ContentValues(); }
values.put(NoteColumns.PARENT_ID, desFolderId); //移动某个笔记到指定文件夹
values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId); public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
values.put(NoteColumns.LOCAL_MODIFIED, 1); //设置更新值
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); ContentValues values = new ContentValues();
} values.put(NoteColumns.PARENT_ID, desFolderId);
values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId);
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids, values.put(NoteColumns.LOCAL_MODIFIED, 1);
long folderId) { resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
if (ids == null) { }
Log.d(TAG, "the ids is null"); //批量移动笔记到指定文件夹
return true; public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids, long folderId) {
} if (ids == null) { //同上判断id集合是否合法
Log.d(TAG, "the ids is null");
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); return true;
for (long id : ids) { }
ContentProviderOperation.Builder builder = ContentProviderOperation ArrayList operationList = new ArrayList();
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); //遍历id集合为每个id创建一个对应的更新操作添加到操作列表中
builder.withValue(NoteColumns.PARENT_ID, folderId); for (long id : ids) {
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1); ContentProviderOperation.Builder builder = ContentProviderOperation
operationList.add(builder.build()); .newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
} builder.withValue(NoteColumns.PARENT_ID, folderId);
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);
try { operationList.add(builder.build());
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); }
if (results == null || results.length == 0 || results[0] == null) { try { //同上,批量执行操作,并检查是否成功
Log.d(TAG, "delete notes failed, ids:" + ids.toString()); ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
return false; if (results == null || results.length == 0 || results[0] == null) {
} Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return true; return false;
} catch (RemoteException e) { }
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); return true;
} catch (OperationApplicationException e) { } catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} } catch (OperationApplicationException e) {
return false; Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} }
return false;
/** }
* Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}} //获取用户文件夹数量(除系统文件夹)
*/ 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_FOLER)},
new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)}, null);
null); int count = 0;
if(cursor != null) { //如果返回的游标不为空
int count = 0; if(cursor.moveToFirst()) {
if(cursor != null) { try {
if(cursor.moveToFirst()) { count = cursor.getInt(0);
try { } catch (IndexOutOfBoundsException e) {
count = cursor.getInt(0); Log.e(TAG, "get folder count failed:" + e.toString());
} catch (IndexOutOfBoundsException e) { } finally {
Log.e(TAG, "get folder count failed:" + e.toString()); cursor.close();
} finally { }
cursor.close(); }
} }
} return count;
} }
return count; //判断指定类型笔记是否在数据库中可见(不在回收站)
} public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) { null,
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
null, new String [] {String.valueOf(type)},
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER, null);
new String [] {String.valueOf(type)}, boolean exist = false;
null); if (cursor != null) {
if (cursor.getCount() > 0) {
boolean exist = false; exist = true;
if (cursor != null) { }
if (cursor.getCount() > 0) { cursor.close();
exist = true; }
} return exist;
cursor.close(); }
} //判断指定id的笔记是否存在于数据库中
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);
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) { boolean exist = false;
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), if (cursor != null) {
null, null, null, null); if (cursor.getCount() > 0) {
exist = true;
boolean exist = false; }
if (cursor != null) { cursor.close();
if (cursor.getCount() > 0) { }
exist = true; return exist;
} }
cursor.close(); //判断指定id的数据是否存在于数据库中
} public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
return exist; Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
} null, null, null, null);
boolean exist = false;
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) { if (cursor != null) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), if (cursor.getCount() > 0) {
null, null, null, null); exist = true;
}
boolean exist = false; cursor.close();
if (cursor != null) { }
if (cursor.getCount() > 0) { return exist;
exist = true; }
} //判断指定文件夹名称是否已存在于已有的文件夹名称中
cursor.close(); public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
} Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
return exist; NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + " AND " + NoteColumns.SNIPPET + "=?",
} new String[] { name }, null);
boolean exist = false;
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) { if(cursor != null) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null, if(cursor.getCount() > 0) {
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + exist = true;
" AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + }
" AND " + NoteColumns.SNIPPET + "=?", cursor.close();
new String[] { name }, null); }
boolean exist = false; return exist;
if(cursor != null) { }
if(cursor.getCount() > 0) { //获取某个文件夹内的所有笔记的小部件属性
exist = true; public static HashSet getFolderNoteWidget(ContentResolver resolver, long folderId) {
} Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
cursor.close(); new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
} NoteColumns.PARENT_ID + "=?",
return exist; new String[] { String.valueOf(folderId) },
} null);
HashSet set = null;
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) { if (c != null) {
Cursor c = resolver.query(Notes.CONTENT_NOTE_URI, if (c.moveToFirst()) {
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE }, set = new HashSet();
NoteColumns.PARENT_ID + "=?", do {
new String[] { String.valueOf(folderId) }, try {
null); AppWidgetAttribute widget = new AppWidgetAttribute();
widget.widgetId = c.getInt(0);
HashSet<AppWidgetAttribute> set = null; widget.widgetType = c.getInt(1);
if (c != null) { set.add(widget);
if (c.moveToFirst()) { } catch (IndexOutOfBoundsException e) {
set = new HashSet<AppWidgetAttribute>(); Log.e(TAG, e.toString());
do { }
try { } while (c.moveToNext());
AppWidgetAttribute widget = new AppWidgetAttribute(); }
widget.widgetId = c.getInt(0); c.close();
widget.widgetType = c.getInt(1); }
set.add(widget); return set;
} catch (IndexOutOfBoundsException e) { }
Log.e(TAG, e.toString()); // 获取通话笔记中的电话号码
} public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
} while (c.moveToNext()); // 构建查询参数
} Cursor cursor = resolver.query(
c.close(); Notes.CONTENT_DATA_URI, // 数据URI
} new String[]{CallNote.PHONE_NUMBER}, // 返回的列
return set; // 查询条件
} CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
// 查询参数
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) { new String[]{String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE},
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, null // 排序
new String [] { CallNote.PHONE_NUMBER }, );
CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?", if (cursor != null && cursor.moveToFirst()) {
new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE }, try {
null); return cursor.getString(0); // 返回电话号码
} catch (IndexOutOfBoundsException e) {
if (cursor != null && cursor.moveToFirst()) { Log.e(TAG, "获取电话号码失败 " + e.toString());
try { } finally {
return cursor.getString(0); cursor.close();
} catch (IndexOutOfBoundsException e) { }
Log.e(TAG, "Get call number fails " + e.toString()); }
} finally { return ""; // 没查到电话号码,返回空字符串
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) { // 根据电话号码和通话时间获取通话笔记的ID
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
new String [] { NoteColumns.SNIPPET }, // 构建查询参数
NoteColumns.ID + "=?", Cursor cursor = resolver.query(
new String [] { String.valueOf(noteId)}, Notes.CONTENT_DATA_URI, // 数据URI
null); 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); // 返回通话笔记的ID
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "获取通话笔记ID失败 " + e.toString());
}
}
cursor.close();
}
return 0; // 没查到通话笔记返回0
}
if (cursor != null) { // 根据笔记ID获取笔记片段
String snippet = ""; public static String getSnippetById(ContentResolver resolver, long noteId) {
if (cursor.moveToFirst()) { // 构建查询参数
snippet = cursor.getString(0); Cursor cursor = resolver.query(
} Notes.CONTENT_NOTE_URI, // 笔记URI
cursor.close(); new String[]{NoteColumns.SNIPPET}, // 返回的列
return snippet; // 查询条件
} NoteColumns.ID + "=?",
throw new IllegalArgumentException("Note is not found with id: " + noteId); // 查询参数
} 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("未找到ID为" + noteId + "的笔记");
}
public static String getFormattedSnippet(String snippet) { // 获取格式化后的笔记片段
if (snippet != null) { public static String getFormattedSnippet(String snippet) {
snippet = snippet.trim(); if (snippet != null) {
int index = snippet.indexOf('\n'); // 去掉首尾空格
if (index != -1) { snippet = snippet.trim();
snippet = snippet.substring(0, index); // 找到第一个换行符
} int index = snippet.indexOf('\n');
} if (index != -1) {
return snippet; snippet = snippet.substring(0, index); // 截取第一个换行符之前的片段
} }
}
return snippet;
} }

@ -17,97 +17,63 @@
package net.micode.notes.tool; package net.micode.notes.tool;
public class GTaskStringUtils { public class GTaskStringUtils {
// Google Tasks JSON中的键
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_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 = "action_type"; 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_CREATE = "create"; public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; // 更新动作
public final static String GTASK_JSON_CREATOR_ID = "creator_id"; // 创建者id
public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; // 子实体
public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; // 客户端版本
public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; public final static String GTASK_JSON_COMPLETED = "completed"; // 完成标志
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_DELETED = "deleted"; // 删除标志
public final static String GTASK_JSON_CREATOR_ID = "creator_id"; public final static String GTASK_JSON_DEST_LIST = "dest_list"; // 目标列表
public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; // 目标父节点
public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; // 目标父节点类型
public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta"; // 实体差异
public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; // 实体类型
public final static String GTASK_JSON_GET_DELETED = "get_deleted"; // 获取删除的实体
public final static String GTASK_JSON_COMPLETED = "completed"; public final static String GTASK_JSON_ID = "id"; // 实体id
public final static String GTASK_JSON_INDEX = "index"; // 序号
public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; // 最后修改时间
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; // 最新同步时间点
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; public final static String GTASK_JSON_LIST_ID = "list_id"; // 列表id
public final static String GTASK_JSON_LISTS = "lists"; // 列表
public final static String GTASK_JSON_DELETED = "deleted"; public final static String GTASK_JSON_NAME = "name"; // 名称
public final static String GTASK_JSON_NEW_ID = "new_id"; // 新的实体id
public final static String GTASK_JSON_DEST_LIST = "dest_list"; public final static String GTASK_JSON_NOTES = "notes"; // 备注
public final static String GTASK_JSON_PARENT_ID = "parent_id"; // 父节点id
public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; // 前置兄弟节点id
public final static String GTASK_JSON_RESULTS = "results"; // 结果
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; public final static String GTASK_JSON_SOURCE_LIST = "source_list"; // 源列表
public final static String GTASK_JSON_TASKS = "tasks"; // 任务
public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta"; public final static String GTASK_JSON_TYPE = "type"; // 类型
public final static String GTASK_JSON_TYPE_GROUP = "GROUP"; // 分组类型
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; public final static String GTASK_JSON_TYPE_TASK = "TASK"; // 任务类型
public final static String GTASK_JSON_USER = "user"; // 用户
public final static String GTASK_JSON_GET_DELETED = "get_deleted";
// MIUI备忘录文件夹前缀
public final static String GTASK_JSON_ID = "id"; public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]";
public final static String GTASK_JSON_INDEX = "index"; // 默认文件夹名
public final static String FOLDER_DEFAULT = "Default";
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified";
// 呼叫备忘录文件夹名
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; public final static String FOLDER_CALL_NOTE = "Call_Note";
public final static String GTASK_JSON_LIST_ID = "list_id"; // 元数据文件夹名
public final static String FOLDER_META = "METADATA";
public final static String GTASK_JSON_LISTS = "lists";
// 元数据键名
public final static String GTASK_JSON_NAME = "name"; public final static String META_HEAD_GTASK_ID = "meta_gid"; // Google Tasks id
public final static String META_HEAD_NOTE = "meta_note"; // 备注
public final static String GTASK_JSON_NEW_ID = "new_id"; public final static String META_HEAD_DATA = "meta_data"; // 数据
public final static String GTASK_JSON_NOTES = "notes"; // 元数据备注名
public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE"; // 不要更新和删除的元数据备注
public final static String GTASK_JSON_PARENT_ID = "parent_id"; }
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id";
public final static String GTASK_JSON_RESULTS = "results";
public final static String GTASK_JSON_SOURCE_LIST = "source_list";
public final static String GTASK_JSON_TASKS = "tasks";
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_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";
}

@ -22,160 +22,200 @@ 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 YELLOW = 0;
public static final int WHITE = 2; public static final int BLUE = 1;
public static final int GREEN = 3; public static final int WHITE = 2;
public static final int RED = 4; 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 BG_DEFAULT_COLOR = YELLOW;
public static final int TEXT_MEDIUM = 1; public static final int TEXT_SMALL = 0;
public static final int TEXT_LARGE = 2; public static final int TEXT_MEDIUM = 1;
public static final int TEXT_SUPER = 3; public static final int TEXT_LARGE = 2;
public static final int TEXT_SUPER = 3;
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; 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,
R.drawable.edit_blue, */
R.drawable.edit_white, public static class NoteBgResources {
R.drawable.edit_green,
R.drawable.edit_red //编辑背景资源
}; private final static int [] BG_EDIT_RESOURCES = new int [] {
R.drawable.edit_yellow,
private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] { R.drawable.edit_blue,
R.drawable.edit_title_yellow, R.drawable.edit_white,
R.drawable.edit_title_blue, R.drawable.edit_green,
R.drawable.edit_title_white, R.drawable.edit_red
R.drawable.edit_title_green, };
R.drawable.edit_title_red
}; //编辑标题背景资源
private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] {
public static int getNoteBgResource(int id) { R.drawable.edit_title_yellow,
return BG_EDIT_RESOURCES[id]; R.drawable.edit_title_blue,
} R.drawable.edit_title_white,
R.drawable.edit_title_green,
public static int getNoteTitleBgResource(int id) { R.drawable.edit_title_red
return BG_EDIT_TITLE_RESOURCES[id]; };
}
} //获取背景资源
public static int getNoteBgResource(int id) {
public static int getDefaultBgId(Context context) { return BG_EDIT_RESOURCES[id];
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean( }
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length); //获取标题背景资源
} else { public static int getNoteTitleBgResource(int id) {
return BG_DEFAULT_COLOR; return BG_EDIT_TITLE_RESOURCES[id];
} }
}
}
public static class NoteItemBgResources {
private final static int [] BG_FIRST_RESOURCES = new int [] { /**
R.drawable.list_yellow_up,
R.drawable.list_blue_up,
R.drawable.list_white_up, */
R.drawable.list_green_up, public static class NoteItemBgResources {
R.drawable.list_red_up
}; //列表项第一个背景资源
private final static int [] BG_FIRST_RESOURCES = new int [] {
private final static int [] BG_NORMAL_RESOURCES = new int [] { R.drawable.list_yellow_up,
R.drawable.list_yellow_middle, R.drawable.list_blue_up,
R.drawable.list_blue_middle, R.drawable.list_white_up,
R.drawable.list_white_middle, R.drawable.list_green_up,
R.drawable.list_green_middle, R.drawable.list_red_up
R.drawable.list_red_middle };
};
//列表项中间背景资源
private final static int [] BG_LAST_RESOURCES = new int [] { private final static int [] BG_NORMAL_RESOURCES = new int [] {
R.drawable.list_yellow_down, R.drawable.list_yellow_middle,
R.drawable.list_blue_down, R.drawable.list_blue_middle,
R.drawable.list_white_down, R.drawable.list_white_middle,
R.drawable.list_green_down, R.drawable.list_green_middle,
R.drawable.list_red_down, R.drawable.list_red_middle
}; };
private final static int [] BG_SINGLE_RESOURCES = new int [] { //列表项最后一个背景资源
R.drawable.list_yellow_single, private final static int [] BG_LAST_RESOURCES = new int [] {
R.drawable.list_blue_single, R.drawable.list_yellow_down,
R.drawable.list_white_single, R.drawable.list_blue_down,
R.drawable.list_green_single, R.drawable.list_white_down,
R.drawable.list_red_single R.drawable.list_green_down,
}; R.drawable.list_red_down
};
public static int getNoteBgFirstRes(int id) {
return BG_FIRST_RESOURCES[id]; //单选列表项背景资源
} private final static int [] BG_SINGLE_RESOURCES = new int [] {
R.drawable.list_yellow_single,
public static int getNoteBgLastRes(int id) { R.drawable.list_blue_single,
return BG_LAST_RESOURCES[id]; R.drawable.list_white_single,
} R.drawable.list_green_single,
R.drawable.list_red_single
public static int getNoteBgSingleRes(int id) { };
return BG_SINGLE_RESOURCES[id];
} //获取列表项第一个背景资源
public static int getNoteBgFirstRes(int id) {
public static int getNoteBgNormalRes(int id) { return BG_FIRST_RESOURCES[id];
return BG_NORMAL_RESOURCES[id]; }
}
//获取列表项最后一个背景资源
public static int getFolderBgRes() { public static int getNoteBgLastRes(int id) {
return R.drawable.list_folder; return BG_LAST_RESOURCES[id];
} }
}
//获取单选列表项背景资源
public static class WidgetBgResources { public static int getNoteBgSingleRes(int id) {
private final static int [] BG_2X_RESOURCES = new int [] { return BG_SINGLE_RESOURCES[id];
R.drawable.widget_2x_yellow, }
R.drawable.widget_2x_blue,
R.drawable.widget_2x_white, //获取列表项中间背景资源
R.drawable.widget_2x_green, public static int getNoteBgNormalRes(int id) {
R.drawable.widget_2x_red, return BG_NORMAL_RESOURCES[id];
}; }
public static int getWidget2xBgResource(int id) { //获取文件夹背景资源
return BG_2X_RESOURCES[id]; public static int getFolderBgRes() {
} return R.drawable.list_folder;
}
private final static int [] BG_4X_RESOURCES = new int [] {
R.drawable.widget_4x_yellow,
R.drawable.widget_4x_blue,
R.drawable.widget_4x_white,
R.drawable.widget_4x_green,
R.drawable.widget_4x_red
};
public static int getWidget4xBgResource(int id) {
return BG_4X_RESOURCES[id];
}
}
public static class TextAppearanceResources {
private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
R.style.TextAppearanceNormal,
R.style.TextAppearanceMedium,
R.style.TextAppearanceLarge,
R.style.TextAppearanceSuper
};
public static int getTexAppearanceResource(int id) {
/**
* HACKME: Fix bug of store the resource id in shared preference.
* The id may larger than the length of resources, in this case,
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
*/
if (id >= TEXTAPPEARANCE_RESOURCES.length) {
return BG_DEFAULT_FONT_SIZE;
}
return TEXTAPPEARANCE_RESOURCES[id];
}
public static int getResourcesSize() {
return TEXTAPPEARANCE_RESOURCES.length;
}
}
} }
/**
*/
public static class WidgetBgResources {
//2x桌面小部件背景资源
private final static int [] BG_2X_RESOURCES = new int [] {
R.drawable.widget_2x_yellow,
R.drawable.widget_2x_blue,
R.drawable.widget_2x_white,
R.drawable.widget_2x_green,
R.drawable.widget_2x_red
};
//获取2x桌面小部件背景资源
public static int getWidget2xBgResource(int id) {
return BG_2X_RESOURCES[id];
}
//4x桌面小部件背景资源
private final static int [] BG_4X_RESOURCES = new int [] {
R.drawable.widget_4x_yellow,
R.drawable.widget_4x_blue,
R.drawable.widget_4x_white,
R.drawable.widget_4x_green,
R.drawable.widget_4x_red
};
//获取4x桌面小部件背景资源
public static int getWidget4xBgResource(int id) {
return BG_4X_RESOURCES[id];
}
}
/**
*/
public static class TextAppearanceResources {
//文字外观资源
private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
R.style.TextAppearanceNormal,
R.style.TextAppearanceMedium,
R.style.TextAppearanceLarge,
R.style.TextAppearanceSuper
};
//获取文字外观资源
public static int getTexAppearanceResource(int id) {
/**
* HACKME: id
* id{@link ResourceParser#BG_DEFAULT_FONT_SIZE}
*/
if (id >= TEXTAPPEARANCE_RESOURCES.length) {
return BG_DEFAULT_FONT_SIZE;
}
return TEXTAPPEARANCE_RESOURCES[id];
}
//获取资源大小
public static int getResourcesSize() {
return TEXTAPPEARANCE_RESOURCES.length;
}
}
}
Loading…
Cancel
Save