ruiguifeng 8 months ago
commit 13b26cd4ee

@ -32,105 +32,143 @@ import net.micode.notes.data.Notes.TextNote;
import net.micode.notes.tool.ResourceParser.NoteBgResources; import net.micode.notes.tool.ResourceParser.NoteBgResources;
/**
*
*/
public class WorkingNote { public class WorkingNote {
// Note for the working note // 笔记对象
private Note mNote; private Note mNote;
// Note Id // 笔记ID
private long mNoteId; private long mNoteId;
// Note content // 笔记内容
private String mContent; private String mContent;
// Note mode // 笔记模式
private int mMode; private int mMode;
// 笔记提醒日期
private long mAlertDate; private long mAlertDate;
// 笔记最后修改日期
private long mModifiedDate; private long mModifiedDate;
// 笔记背景颜色ID
private int mBgColorId; private int mBgColorId;
// 笔记小部件ID
private int mWidgetId; private int mWidgetId;
// 笔记小部件类型
private int mWidgetType; private int mWidgetType;
// 笔记所属文件夹ID
private long mFolderId; private long mFolderId;
// 上下文对象,用于访问应用的资源和类
private Context mContext; private Context mContext;
// 日志标签,用于日志输出
private static final String TAG = "WorkingNote"; private static final String TAG = "WorkingNote";
// 标记笔记是否已删除
private boolean mIsDeleted; private boolean mIsDeleted;
// 笔记设置更改监听器
private NoteSettingChangedListener mNoteSettingStatusListener; private NoteSettingChangedListener mNoteSettingStatusListener;
/**
*
*/
public static final String[] DATA_PROJECTION = new String[] { public static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID, DataColumns.ID, // 数据ID
DataColumns.CONTENT, DataColumns.CONTENT, // 数据内容
DataColumns.MIME_TYPE, DataColumns.MIME_TYPE, // 数据MIME类型
DataColumns.DATA1, DataColumns.DATA1, // 数据字段1
DataColumns.DATA2, DataColumns.DATA2, // 数据字段2
DataColumns.DATA3, DataColumns.DATA3, // 数据字段3
DataColumns.DATA4, DataColumns.DATA4 // 数据字段4
}; };
/**
*
*/
public static final String[] NOTE_PROJECTION = new String[] { public static final String[] NOTE_PROJECTION = new String[] {
NoteColumns.PARENT_ID, NoteColumns.PARENT_ID, // 笔记父ID所属文件夹ID
NoteColumns.ALERTED_DATE, NoteColumns.ALERTED_DATE, // 笔记提醒日期
NoteColumns.BG_COLOR_ID, NoteColumns.BG_COLOR_ID, // 笔记背景颜色ID
NoteColumns.WIDGET_ID, NoteColumns.WIDGET_ID, // 笔记小部件ID
NoteColumns.WIDGET_TYPE, NoteColumns.WIDGET_TYPE, // 笔记小部件类型
NoteColumns.MODIFIED_DATE NoteColumns.MODIFIED_DATE // 笔记最后修改日期
}; };
private static final int DATA_ID_COLUMN = 0; /**
*
private static final int DATA_CONTENT_COLUMN = 1; */
private static final int DATA_ID_COLUMN = 0; // 数据ID列索引
private static final int DATA_MIME_TYPE_COLUMN = 2; private static final int DATA_CONTENT_COLUMN = 1; // 数据内容列索引
private static final int DATA_MIME_TYPE_COLUMN = 2; // 数据MIME类型列索引
private static final int DATA_MODE_COLUMN = 3; private static final int DATA_MODE_COLUMN = 3; // 数据模式列索引
private static final int NOTE_PARENT_ID_COLUMN = 0; // 笔记父ID列索引
private static final int NOTE_PARENT_ID_COLUMN = 0; private static final int NOTE_ALERTED_DATE_COLUMN = 1; // 笔记提醒日期列索引
private static final int NOTE_BG_COLOR_ID_COLUMN = 2; // 笔记背景颜色ID列索引
private static final int NOTE_ALERTED_DATE_COLUMN = 1; private static final int NOTE_WIDGET_ID_COLUMN = 3; // 笔记小部件ID列索引
private static final int NOTE_WIDGET_TYPE_COLUMN = 4; // 笔记小部件类型列索引
private static final int NOTE_BG_COLOR_ID_COLUMN = 2; private static final int NOTE_MODIFIED_DATE_COLUMN = 5; // 笔记最后修改日期列索引
}
private static final int NOTE_WIDGET_ID_COLUMN = 3;
private static final int NOTE_WIDGET_TYPE_COLUMN = 4;
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
// New note construct
private WorkingNote(Context context, long folderId) { private WorkingNote(Context context, long folderId) {
// 初始化上下文对象,用于后续访问应用的资源和类
mContext = context; mContext = context;
// 初始化提醒日期为0表示没有设置提醒
mAlertDate = 0; mAlertDate = 0;
// 初始化最后修改日期为当前时间戳
mModifiedDate = System.currentTimeMillis(); mModifiedDate = System.currentTimeMillis();
// 设置笔记所属的文件夹ID
mFolderId = folderId; mFolderId = folderId;
// 创建一个新的Note对象用于存储笔记的详细信息
mNote = new Note(); mNote = new Note();
// 初始化笔记ID为0表示这是一个新笔记尚未保存到数据库
mNoteId = 0; mNoteId = 0;
// 标记笔记为未删除状态
mIsDeleted = false; mIsDeleted = false;
// 初始化笔记模式为0具体模式根据应用需求定义
mMode = 0; mMode = 0;
// 设置小部件类型为无效类型,表示这个笔记还没有关联的小部件
mWidgetType = Notes.TYPE_WIDGET_INVALIDE; mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
} }
// Existing note construct // Existing note construct
private WorkingNote(Context context, long noteId, long folderId) { private WorkingNote(Context context, long noteId, long folderId) {
// 初始化上下文对象,用于后续访问应用的资源和类
mContext = context; mContext = context;
// 设置笔记ID
mNoteId = noteId; mNoteId = noteId;
// 设置笔记所属的文件夹ID
mFolderId = folderId; mFolderId = folderId;
// 标记笔记为未删除状态
mIsDeleted = false; mIsDeleted = false;
// 创建一个新的Note对象用于存储笔记的详细信息
mNote = new Note(); mNote = new Note();
// 加载笔记的详细信息
loadNote(); loadNote();
} }
/**
*
*/
private void loadNote() { private void loadNote() {
// 根据笔记ID查询笔记的详细信息
Cursor cursor = mContext.getContentResolver().query( Cursor cursor = mContext.getContentResolver().query(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null, ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), // 构建笔记的内容URI
null, null); NOTE_PROJECTION, // 查询需要的列
null, // 查询条件
null, // 查询参数
null); // 排序参数
// 如果查询结果不为空
if (cursor != null) { if (cursor != null) {
// 如果查询结果至少有一条数据
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
// 从查询结果中获取笔记的详细信息并设置到成员变量
mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN); mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);
mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN); mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN);
mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN); mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN);
@ -138,84 +176,104 @@ public class WorkingNote {
mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN); mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN);
mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN); mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
} }
cursor.close(); cursor.close(); // 关闭游标
} else { } else {
// 如果查询结果为空,记录错误日志并抛出异常
Log.e(TAG, "No note with id:" + mNoteId); Log.e(TAG, "No note with id:" + mNoteId);
throw new IllegalArgumentException("Unable to find note with id " + mNoteId); throw new IllegalArgumentException("Unable to find note with id " + mNoteId);
} }
// 加载笔记的数据内容
loadNoteData(); loadNoteData();
} }
private void loadNoteData() { private void loadNoteData() {
// 通过内容解析器查询笔记数据URI获取与当前笔记ID关联的数据
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION, Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
DataColumns.NOTE_ID + "=?", new String[] { DataColumns.NOTE_ID + "=?", new String[] {
String.valueOf(mNoteId) String.valueOf(mNoteId) // 查询参数当前笔记的ID
}, null); }, null);
// 如果查询结果不为空
if (cursor != null) { if (cursor != null) {
// 如果查询结果至少有一条数据
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
// 遍历查询结果
do { do {
// 获取数据项的MIME类型
String type = cursor.getString(DATA_MIME_TYPE_COLUMN); String type = cursor.getString(DATA_MIME_TYPE_COLUMN);
// 根据MIME类型处理数据
if (DataConstants.NOTE.equals(type)) { if (DataConstants.NOTE.equals(type)) {
// 如果是普通笔记类型,设置笔记的内容和模式
mContent = cursor.getString(DATA_CONTENT_COLUMN); mContent = cursor.getString(DATA_CONTENT_COLUMN);
mMode = cursor.getInt(DATA_MODE_COLUMN); mMode = cursor.getInt(DATA_MODE_COLUMN);
mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN)); mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN));
} else if (DataConstants.CALL_NOTE.equals(type)) { } else if (DataConstants.CALL_NOTE.equals(type)) {
// 如果是通话笔记类型设置通话数据ID
mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN)); mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN));
} else { } else {
// 如果遇到未知的笔记类型,记录日志
Log.d(TAG, "Wrong note type with type:" + type); Log.d(TAG, "Wrong note type with type:" + type);
} }
} while (cursor.moveToNext()); } while (cursor.moveToNext()); // 移动到下一条数据
} }
cursor.close(); cursor.close(); // 关闭游标
} else { } else {
// 如果查询结果为空,记录错误日志并抛出异常
Log.e(TAG, "No data with id:" + mNoteId); Log.e(TAG, "No data with id:" + mNoteId);
throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId); throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId);
} }
} }
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId, public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,int widgetType, int defaultBgColorId) {
int widgetType, int defaultBgColorId) { WorkingNote note = new WorkingNote(context, folderId); // 创建一个新的WorkingNote实例
WorkingNote note = new WorkingNote(context, folderId); note.setBgColorId(defaultBgColorId); // 设置笔记的背景颜色ID
note.setBgColorId(defaultBgColorId); note.setWidgetId(widgetId); // 设置笔记的小部件ID
note.setWidgetId(widgetId); note.setWidgetType(widgetType); // 设置笔记的小部件类型
note.setWidgetType(widgetType); return note; // 返回新创建的笔记实例
return note;
} }
public static WorkingNote load(Context context, long id) { public static WorkingNote load(Context context, long id) {
return new WorkingNote(context, id, 0); return new WorkingNote(context, id, 0); // 创建并返回一个新的WorkingNote实例
} }
public synchronized boolean saveNote() { public synchronized boolean saveNote() {
// 检查笔记是否值得保存
if (isWorthSaving()) { if (isWorthSaving()) {
// 如果笔记在数据库中不存在
if (!existInDatabase()) { if (!existInDatabase()) {
// 尝试获取一个新的笔记ID
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) { if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
Log.e(TAG, "Create new note fail with id:" + mNoteId); Log.e(TAG, "Create new note fail with id:" + mNoteId); // 如果创建失败,记录错误日志
return false; return false; // 返回false
} }
} }
// 同步笔记到数据库
mNote.syncNote(mContext, mNoteId); mNote.syncNote(mContext, mNoteId);
/** /**
* Update widget content if there exist any widget of this note *
*/ */
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mWidgetType != Notes.TYPE_WIDGET_INVALIDE
&& mNoteSettingStatusListener != null) { && mNoteSettingStatusListener != null) {
mNoteSettingStatusListener.onWidgetChanged(); mNoteSettingStatusListener.onWidgetChanged(); // 通知小部件更改
} }
return true; return true; // 返回true表示保存成功
} else { } else {
return false; return false; // 如果笔记不值得保存返回false
} }
} }
/**
* ID0
*/
public boolean existInDatabase() { public boolean existInDatabase() {
return mNoteId > 0; return mNoteId > 0;
} }
/**
*
* @return falsetrue
*/
private boolean isWorthSaving() { private boolean isWorthSaving() {
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent)) if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|| (existInDatabase() && !mNote.isLocalModified())) { || (existInDatabase() && !mNote.isLocalModified())) {
@ -225,10 +283,16 @@ public class WorkingNote {
} }
} }
/**
*
*/
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
mNoteSettingStatusListener = l; mNoteSettingStatusListener = l;
} }
/**
*
*/
public void setAlertDate(long date, boolean set) { public void setAlertDate(long date, boolean set) {
if (date != mAlertDate) { if (date != mAlertDate) {
mAlertDate = date; mAlertDate = date;
@ -239,14 +303,20 @@ public class WorkingNote {
} }
} }
/**
*
*/
public void markDeleted(boolean mark) { public void markDeleted(boolean mark) {
mIsDeleted = mark; mIsDeleted = mark;
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) { && mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) {
mNoteSettingStatusListener.onWidgetChanged(); mNoteSettingStatusListener.onWidgetChanged();
} }
} }
/**
* ID
*/
public void setBgColorId(int id) { public void setBgColorId(int id) {
if (id != mBgColorId) { if (id != mBgColorId) {
mBgColorId = id; mBgColorId = id;
@ -257,6 +327,9 @@ public class WorkingNote {
} }
} }
/**
*
*/
public void setCheckListMode(int mode) { public void setCheckListMode(int mode) {
if (mMode != mode) { if (mMode != mode) {
if (mNoteSettingStatusListener != null) { if (mNoteSettingStatusListener != null) {
@ -267,6 +340,9 @@ public class WorkingNote {
} }
} }
/**
*
*/
public void setWidgetType(int type) { public void setWidgetType(int type) {
if (type != mWidgetType) { if (type != mWidgetType) {
mWidgetType = type; mWidgetType = type;
@ -274,6 +350,9 @@ public class WorkingNote {
} }
} }
/**
* ID
*/
public void setWidgetId(int id) { public void setWidgetId(int id) {
if (id != mWidgetId) { if (id != mWidgetId) {
mWidgetId = id; mWidgetId = id;
@ -281,6 +360,9 @@ public class WorkingNote {
} }
} }
/**
*
*/
public void setWorkingText(String text) { public void setWorkingText(String text) {
if (!TextUtils.equals(mContent, text)) { if (!TextUtils.equals(mContent, text)) {
mContent = text; mContent = text;
@ -288,80 +370,120 @@ public class WorkingNote {
} }
} }
/**
*
*/
public void convertToCallNote(String phoneNumber, long callDate) { public void convertToCallNote(String phoneNumber, long callDate) {
mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate)); mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate));
mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber); mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber);
mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER)); mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER));
} }
/**
*
*/
public boolean hasClockAlert() { public boolean hasClockAlert() {
return (mAlertDate > 0 ? true : false); return (mAlertDate > 0 ? true : false);
} }
/**
*
*/
public String getContent() { public String getContent() {
return mContent; return mContent;
} }
/**
*
*/
public long getAlertDate() { public long getAlertDate() {
return mAlertDate; return mAlertDate;
} }
/**
*
*/
public long getModifiedDate() { public long getModifiedDate() {
return mModifiedDate; return mModifiedDate;
} }
/**
* ID
*/
public int getBgColorResId() { public int getBgColorResId() {
return NoteBgResources.getNoteBgResource(mBgColorId); return NoteBgResources.getNoteBgResource(mBgColorId);
} }
/**
* ID
*/
public int getBgColorId() { public int getBgColorId() {
return mBgColorId; return mBgColorId;
} }
/**
* ID
*/
public int getTitleBgResId() { public int getTitleBgResId() {
return NoteBgResources.getNoteTitleBgResource(mBgColorId); return NoteBgResources.getNoteTitleBgResource(mBgColorId);
} }
/**
*
*/
public int getCheckListMode() { public int getCheckListMode() {
return mMode; return mMode;
} }
/**
* ID
*/
public long getNoteId() { public long getNoteId() {
return mNoteId; return mNoteId;
} }
/**
* ID
*/
public long getFolderId() { public long getFolderId() {
return mFolderId; return mFolderId;
} }
/**
* ID
*/
public int getWidgetId() { public int getWidgetId() {
return mWidgetId; return mWidgetId;
} }
/**
*
*/
public int getWidgetType() { public int getWidgetType() {
return mWidgetType; return mWidgetType;
} }
/**
*
*/
public interface NoteSettingChangedListener { public interface NoteSettingChangedListener {
/** /**
* Called when the background color of current note has just changed *
*/ */
void onBackgroundColorChanged(); void onBackgroundColorChanged();
/** /**
* Called when user set clock *
*/ */
void onClockAlertChanged(long date, boolean set); void onClockAlertChanged(long date, boolean set);
/** /**
* Call when user create note from widget *
*/ */
void onWidgetChanged(); void onWidgetChanged();
/** /**
* Call when switch between check list mode and normal mode *
* @param oldMode is previous mode before change
* @param newMode is new mode
*/ */
void onCheckListModeChanged(int oldMode, int newMode); void onCheckListModeChanged(int oldMode, int newMode);
} }

@ -37,123 +37,190 @@ import java.io.PrintStream;
public class BackupUtils { public class BackupUtils {
/**
*
*/
private static final String TAG = "BackupUtils"; private static final String TAG = "BackupUtils";
// Singleton stuff // Singleton stuff
/**
* BackupUtils
*/
private static BackupUtils sInstance; private static BackupUtils sInstance;
/**
* BackupUtils
* @param context 访
* @return BackupUtils
*/
public static synchronized BackupUtils getInstance(Context context) { public static synchronized BackupUtils getInstance(Context context) {
if (sInstance == null) { if (sInstance == null) {
sInstance = new BackupUtils(context); sInstance = new BackupUtils(context); // 如果实例不存在,则创建一个新的实例。
} }
return sInstance; return sInstance; // 返回单例对象。
} }
/** /**
* Following states are signs to represents backup or restore *
* status
*/ */
// Currently, the sdcard is not mounted // Currently, the sdcard is not mounted
public static final int STATE_SD_CARD_UNMOUONTED = 0; public static final int STATE_SD_CARD_UNMOUONTED = 0; // SD卡未挂载。
// The backup file not exist // The backup file not exist
public static final int STATE_BACKUP_FILE_NOT_EXIST = 1; public static final int STATE_BACKUP_FILE_NOT_EXIST = 1; // 备份文件不存在。
// The data is not well formated, may be changed by other programs // The data is not well formated, may be changed by other programs
public static final int STATE_DATA_DESTROIED = 2; public static final int STATE_DATA_DESTROIED = 2; // 数据格式不正确,可能被其他程序修改。
// Some run-time exception which causes restore or backup fails // Some run-time exception which causes restore or backup fails
public static final int STATE_SYSTEM_ERROR = 3; public static final int STATE_SYSTEM_ERROR = 3; // 运行时异常导致备份或恢复失败。
// Backup or restore success // Backup or restore success
public static final int STATE_SUCCESS = 4; public static final int STATE_SUCCESS = 4; // 备份或恢复成功。
/**
* TextExport
*/
private TextExport mTextExport; private TextExport mTextExport;
/**
* BackupUtils
* @param context 访
*/
private BackupUtils(Context context) { private BackupUtils(Context context) {
mTextExport = new TextExport(context); mTextExport = new TextExport(context); // 初始化TextExport对象。
} }
/**
*
* @return truefalse
*/
private static boolean externalStorageAvailable() { private static boolean externalStorageAvailable() {
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); // 检查外部存储状态是否为已挂载。
} }
/**
*
* @return
*/
public int exportToText() { public int exportToText() {
return mTextExport.exportToText(); return mTextExport.exportToText(); // 调用TextExport对象的exportToText方法。
} }
/**
*
* @return
*/
public String getExportedTextFileName() { public String getExportedTextFileName() {
return mTextExport.mFileName; return mTextExport.mFileName; // 返回TextExport对象的文件名。
} }
/**
*
* @return
*/
public String getExportedTextFileDir() { public String getExportedTextFileDir() {
return mTextExport.mFileDirectory; return mTextExport.mFileDirectory; // 返回TextExport对象的文件目录。
} }
/**
*
*/
private static class TextExport { private static class TextExport {
private static final String[] NOTE_PROJECTION = { /**
NoteColumns.ID, *
NoteColumns.MODIFIED_DATE, */
NoteColumns.SNIPPET, private static final String[] NOTE_PROJECTION = {
NoteColumns.TYPE NoteColumns.ID, // 笔记ID
}; NoteColumns.MODIFIED_DATE, // 最后修改日期
NoteColumns.SNIPPET, // 笔记摘要
private static final int NOTE_COLUMN_ID = 0; NoteColumns.TYPE // 笔记类型
};
private static final int NOTE_COLUMN_MODIFIED_DATE = 1;
private static final int NOTE_COLUMN_SNIPPET = 2;
private static final String[] DATA_PROJECTION = {
DataColumns.CONTENT,
DataColumns.MIME_TYPE,
DataColumns.DATA1,
DataColumns.DATA2,
DataColumns.DATA3,
DataColumns.DATA4,
};
private static final int DATA_COLUMN_CONTENT = 0;
private static final int DATA_COLUMN_MIME_TYPE = 1; /**
* NOTE_PROJECTION
*/
private static final int NOTE_COLUMN_ID = 0; // 笔记ID列索引
private static final int NOTE_COLUMN_MODIFIED_DATE = 1; // 最后修改日期列索引
private static final int NOTE_COLUMN_SNIPPET = 2; // 笔记摘要列索引
private static final int NOTE_COLUMN_TYPE = 3; // 笔记类型列索引
private static final int DATA_COLUMN_CALL_DATE = 2; /**
*
*/
private static final String[] DATA_PROJECTION = {
DataColumns.CONTENT, // 数据内容
DataColumns.MIME_TYPE, // 数据MIME类型
DataColumns.DATA1, // 数据字段1
DataColumns.DATA2, // 数据字段2
DataColumns.DATA3, // 数据字段3
DataColumns.DATA4 // 数据字段4
};
private static final int DATA_COLUMN_PHONE_NUMBER = 4; /**
* DATA_PROJECTION
*/
private static final int DATA_COLUMN_CONTENT = 0; // 数据内容列索引
private static final int DATA_COLUMN_MIME_TYPE = 1; // 数据MIME类型列索引
private static final int DATA_COLUMN_CALL_DATE = 2; // 通话日期列索引注意这里应该是DATA3因为DATA2和DATA3的索引被占用了
private static final int DATA_COLUMN_PHONE_NUMBER = 4; // 电话号码列索引注意这里应该是DATA4因为DATA4的索引被占用了
private final String [] TEXT_FORMAT; /**
private static final int FORMAT_FOLDER_NAME = 0; *
private static final int FORMAT_NOTE_DATE = 1; */
private static final int FORMAT_NOTE_CONTENT = 2; private final String[] TEXT_FORMAT; // 导出文本的格式数组
private static final int FORMAT_FOLDER_NAME = 0; // 文件夹名称格式索引
private static final int FORMAT_NOTE_DATE = 1; // 笔记日期格式索引
private static final int FORMAT_NOTE_CONTENT = 2; // 笔记内容格式索引
private Context mContext; /**
private String mFileName; * 访
private String mFileDirectory; */
private Context mContext;
/**
*
*/
private String mFileName;
/**
*
*/
private String mFileDirectory;
public TextExport(Context context) { /**
TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note); * TextExport
mContext = context; * @param context 访
mFileName = ""; */
mFileDirectory = ""; public TextExport(Context context) {
} TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note); // 从资源文件中获取导出文本的格式
mContext = context; // 初始化上下文对象
mFileName = ""; // 初始化文件名为空
mFileDirectory = ""; // 初始化文件目录为空
}
private String getFormat(int id) { /**
return TEXT_FORMAT[id]; * ID
} * @param id ID
* @return
*/
private String getFormat(int id) {
return TEXT_FORMAT[id]; // 返回TEXT_FORMAT数组中对应ID的格式字符串
}
}
/** /**
* Export the folder identified by folder id to text * Export the folder identified by folder id to text
*/ */
private void exportFolderToText(String folderId, PrintStream ps) { private void exportFolderToText(String folderId, PrintStream ps) {
// Query notes belong to this folder // 查询属于该文件夹的笔记
Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI, Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] { NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] {
folderId folderId
}, null); }, null);
if (notesCursor != null) { if (notesCursor != null) {
if (notesCursor.moveToFirst()) { if (notesCursor.moveToFirst()) {
do { do {
// Print note's last modified date // 打印笔记的最后修改日期
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm), mContext.getString(R.string.format_datetime_mdhm),
notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
// Query data belong to this note // 查询属于该笔记的数据
String noteId = notesCursor.getString(NOTE_COLUMN_ID); String noteId = notesCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps); exportNoteToText(noteId, ps);
} while (notesCursor.moveToNext()); } while (notesCursor.moveToNext());
@ -161,35 +228,37 @@ public class BackupUtils {
notesCursor.close(); notesCursor.close();
} }
} }
/** /**
* Export note identified by id to a print stream * IDPrintStream
* @param noteId ID
* @param ps PrintStream
*/ */
private void exportNoteToText(String noteId, PrintStream ps) { private void exportNoteToText(String noteId, PrintStream ps) {
Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI,
DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] { DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] {
noteId noteId
}, null); }, null);
if (dataCursor != null) { if (dataCursor != null) {
if (dataCursor.moveToFirst()) { if (dataCursor.moveToFirst()) {
do { do {
String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE); String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE);
if (DataConstants.CALL_NOTE.equals(mimeType)) { if (DataConstants.CALL_NOTE.equals(mimeType)) {
// Print phone number // 打印电话号码
String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER); String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER);
long callDate = dataCursor.getLong(DATA_COLUMN_CALL_DATE); long callDate = dataCursor.getLong(DATA_COLUMN_CALL_DATE);
String location = dataCursor.getString(DATA_COLUMN_CONTENT); String location = dataCursor.getString(DATA_COLUMN_CONTENT);
if (!TextUtils.isEmpty(phoneNumber)) { if (!TextUtils.isEmpty(phoneNumber)) {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
phoneNumber)); phoneNumber));
} }
// Print call date // 打印通话日期
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat
.format(mContext.getString(R.string.format_datetime_mdhm), .format(mContext.getString(R.string.format_datetime_mdhm),
callDate))); callDate)));
// Print call attachment location // 打印通话附件位置
if (!TextUtils.isEmpty(location)) { if (!TextUtils.isEmpty(location)) {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
location)); location));
@ -205,7 +274,7 @@ public class BackupUtils {
} }
dataCursor.close(); dataCursor.close();
} }
// print a line separator between note // 在笔记之间打印一个分隔符
try { try {
ps.write(new byte[] { ps.write(new byte[] {
Character.LINE_SEPARATOR, Character.LETTER_NUMBER Character.LINE_SEPARATOR, Character.LETTER_NUMBER
@ -219,126 +288,129 @@ public class BackupUtils {
* Note will be exported as text which is user readable * Note will be exported as text which is user readable
*/ */
public int exportToText() { public int exportToText() {
// 检查外部存储是否可用
if (!externalStorageAvailable()) { if (!externalStorageAvailable()) {
Log.d(TAG, "Media was not mounted"); Log.d(TAG, "Media was not mounted"); // 如果外部存储不可用,则记录日志
return STATE_SD_CARD_UNMOUONTED; return STATE_SD_CARD_UNMOUONTED; // 返回SD卡未挂载的状态码
} }
// 获取用于导出文本的PrintStream对象
PrintStream ps = getExportToTextPrintStream(); PrintStream ps = getExportToTextPrintStream();
if (ps == null) { if (ps == null) {
Log.e(TAG, "get print stream error"); Log.e(TAG, "get print stream error"); // 如果获取PrintStream失败则记录错误日志
return STATE_SYSTEM_ERROR; return STATE_SYSTEM_ERROR; // 返回系统错误的状态码
} }
// First export folder and its notes // 首先导出文件夹及其笔记
Cursor folderCursor = mContext.getContentResolver().query( Cursor folderCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI, Notes.CONTENT_NOTE_URI, // 笔记内容URI
NOTE_PROJECTION, NOTE_PROJECTION, // 查询需要的列
"(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND " "(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR "
+ NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR " + NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, // 查询条件
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null); null, // 查询参数
null); // 排序参数
if (folderCursor != null) { if (folderCursor != null) {
if (folderCursor.moveToFirst()) { if (folderCursor.moveToFirst()) {
do { do {
// Print folder's name // 打印文件夹名称
String folderName = ""; String folderName = "";
if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) { if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) {
folderName = mContext.getString(R.string.call_record_folder_name); folderName = mContext.getString(R.string.call_record_folder_name); // 获取通话记录文件夹名称
} else { } else {
folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET); folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET); // 获取普通文件夹名称
} }
if (!TextUtils.isEmpty(folderName)) { if (!TextUtils.isEmpty(folderName)) {
ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName)); ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName)); // 按照格式打印文件夹名称
} }
String folderId = folderCursor.getString(NOTE_COLUMN_ID); String folderId = folderCursor.getString(NOTE_COLUMN_ID);
exportFolderToText(folderId, ps); exportFolderToText(folderId, ps); // 导出文件夹内容
} while (folderCursor.moveToNext()); } while (folderCursor.moveToNext());
} }
folderCursor.close(); folderCursor.close();
} }
// Export notes in root's folder // 导出根文件夹中的笔记
Cursor noteCursor = mContext.getContentResolver().query( Cursor noteCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI, Notes.CONTENT_NOTE_URI, // 笔记内容URI
NOTE_PROJECTION, NOTE_PROJECTION, // 查询需要的列
NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID NoteColumns.TYPE + "=" + Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID + "=0", // 查询条件,选择根文件夹中的笔记
+ "=0", null, null); null, // 查询参数
null); // 排序参数
if (noteCursor != null) { if (noteCursor != null) {
if (noteCursor.moveToFirst()) { if (noteCursor.moveToFirst()) {
do { do {
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm), mContext.getString(R.string.format_datetime_mdhm), // 格式化笔记最后修改日期
noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
// Query data belong to this note // 查询属于该笔记的数据
String noteId = noteCursor.getString(NOTE_COLUMN_ID); String noteId = noteCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps); exportNoteToText(noteId, ps); // 导出笔记内容
} while (noteCursor.moveToNext()); } while (noteCursor.moveToNext());
} }
noteCursor.close(); noteCursor.close();
} }
ps.close(); ps.close(); // 关闭PrintStream对象
return STATE_SUCCESS; return STATE_SUCCESS; // 返回成功的状态码
} }
/** /**
* Get a print stream pointed to the file {@generateExportedTextFile} * Get a print stream pointed to the file {@generateExportedTextFile}
*/ */
private PrintStream getExportToTextPrintStream() { private PrintStream getExportToTextPrintStream() {
// 在SD卡上生成用于导出的文件
File file = generateFileMountedOnSDcard(mContext, R.string.file_path, File file = generateFileMountedOnSDcard(mContext, R.string.file_path,
R.string.file_name_txt_format); R.string.file_name_txt_format);
if (file == null) { if (file == null) {
Log.e(TAG, "create file to exported failed"); Log.e(TAG, "create file to exported failed"); // 如果文件创建失败,则记录错误日志
return null; return null; // 返回null
} }
mFileName = file.getName(); mFileName = file.getName(); // 设置导出文件的文件名
mFileDirectory = mContext.getString(R.string.file_path); mFileDirectory = mContext.getString(R.string.file_path); // 设置导出文件的目录
PrintStream ps = null; PrintStream ps = null; // 初始化PrintStream对象
try { try {
FileOutputStream fos = new FileOutputStream(file); FileOutputStream fos = new FileOutputStream(file); // 创建文件输出流
ps = new PrintStream(fos); ps = new PrintStream(fos); // 创建PrintStream对象
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace(); // 如果发生文件未找到异常,则打印堆栈跟踪
return null; return null; // 返回null
} catch (NullPointerException e) { } catch (NullPointerException e) {
e.printStackTrace(); e.printStackTrace(); // 如果发生空指针异常,则打印堆栈跟踪
return null; return null; // 返回null
} }
return ps; return ps; // 返回PrintStream对象
} }
}
/**
/** * SD
* Generate the text file to store imported data */
*/ private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) { StringBuilder sb = new StringBuilder(); // 初始化StringBuilder对象
StringBuilder sb = new StringBuilder(); sb.append(Environment.getExternalStorageDirectory()); // 追加外部存储目录
sb.append(Environment.getExternalStorageDirectory()); sb.append(context.getString(filePathResId)); // 追加文件路径
sb.append(context.getString(filePathResId)); File filedir = new File(sb.toString()); // 创建文件目录对象
File filedir = new File(sb.toString()); sb.append(context.getString( // 追加文件名
sb.append(context.getString( fileNameFormatResId,
fileNameFormatResId, DateFormat.format(context.getString(R.string.format_date_ymd), // 使用日期格式化文件名
DateFormat.format(context.getString(R.string.format_date_ymd), System.currentTimeMillis()))); // 使用当前时间戳
System.currentTimeMillis()))); File file = new File(sb.toString()); // 创建文件对象
File file = new File(sb.toString());
try {
try { if (!filedir.exists()) { // 如果文件目录不存在,则创建目录
if (!filedir.exists()) { filedir.mkdir();
filedir.mkdir(); }
} if (!file.exists()) { // 如果文件不存在,则创建文件
if (!file.exists()) { file.createNewFile();
file.createNewFile(); }
return file; // 返回文件对象
} catch (SecurityException e) {
e.printStackTrace(); // 如果发生安全异常,则打印堆栈跟踪
} catch (IOException e) {
e.printStackTrace(); // 如果发生IO异常则打印堆栈跟踪
} }
return file;
} catch (SecurityException e) { return null; // 如果发生异常则返回null
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
} }
} }

@ -35,95 +35,158 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
/**
*
*/
public class DataUtils { public class DataUtils {
/**
*
*/
public static final String TAG = "DataUtils"; public static final String TAG = "DataUtils";
/**
*
* ID
*
* @param resolver ContentResolver访
* @param ids ID
* @return trueID/nullfalse
*/
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) { public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
// 如果传入的ID集合为null记录日志并返回true视为无操作
if (ids == null) { if (ids == null) {
Log.d(TAG, "the ids is null"); Log.d(TAG, "the ids is null");
return true; return true;
} }
// 如果ID集合大小为0即没有ID需要删除记录日志并返回true
if (ids.size() == 0) { if (ids.size() == 0) {
Log.d(TAG, "no id is in the hashset"); Log.d(TAG, "no id is in the hashset");
return true; return true;
} }
// 创建操作列表,用于批量操作
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
// 遍历ID集合为每个ID创建一个删除操作
for (long id : ids) { for (long id : ids) {
// 检查是否为根文件夹ID如果是则跳过删除
if(id == Notes.ID_ROOT_FOLDER) { if(id == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Don't delete system folder root"); Log.e(TAG, "Don't delete system folder root");
continue; continue;
} }
// 创建删除操作的构建器,并添加到操作列表
ContentProviderOperation.Builder builder = ContentProviderOperation ContentProviderOperation.Builder builder = ContentProviderOperation
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); .newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
operationList.add(builder.build()); operationList.add(builder.build());
} }
try { try {
// 执行批量操作
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
// 如果结果为空或结果数组长度为0或结果数组第一个元素为null记录日志并返回false
if (results == null || results.length == 0 || results[0] == null) { if (results == null || results.length == 0 || results[0] == null) {
Log.d(TAG, "delete notes failed, ids:" + ids.toString()); Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false; return false;
} }
// 如果批量操作成功返回true
return true; return true;
} catch (RemoteException 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) { } catch (OperationApplicationException e) {
// 捕获并记录操作应用异常
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} }
// 如果发生异常返回false
return false; return false;
} }
/**
*
*
* @param resolver ContentResolver访
* @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对象用于存储需要更新的值
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
// 更新笔记的父文件夹ID为新的目标文件夹ID
values.put(NoteColumns.PARENT_ID, desFolderId); values.put(NoteColumns.PARENT_ID, desFolderId);
// 记录笔记原始的父文件夹ID
values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId); values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId);
// 标记笔记为本地修改值为1
values.put(NoteColumns.LOCAL_MODIFIED, 1); values.put(NoteColumns.LOCAL_MODIFIED, 1);
// 更新指定笔记的记录
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
} }
/**
*
* ID
*
* @param resolver ContentResolver访
* @param ids ID
* @param folderId ID
* @return trueID/nullfalse
*/
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids, public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
long folderId) { long folderId) {
// 如果传入的ID集合为null记录日志并返回true视为无操作
if (ids == null) { if (ids == null) {
Log.d(TAG, "the ids is null"); Log.d(TAG, "the ids is null");
return true; return true;
} }
// 创建操作列表,用于批量操作
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
// 遍历ID集合为每个ID创建一个更新操作
for (long id : ids) { for (long id : ids) {
// 创建更新操作的构建器并设置新的父文件夹ID和本地修改标记
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);
// 如果结果为空或结果数组长度为0或结果数组第一个元素为null记录日志并返回false
if (results == null || results.length == 0 || results[0] == null) { if (results == null || results.length == 0 || results[0] == null) {
Log.d(TAG, "delete notes failed, ids:" + ids.toString()); Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false; return false;
} }
// 如果批量操作成功返回true
return true; return true;
} catch (RemoteException 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) { } catch (OperationApplicationException e) {
// 捕获并记录操作应用异常
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} }
// 如果发生异常返回false
return false; return false;
} }
}
/** /**
* Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}} * 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; int count = 0;
if(cursor != null) { // 如果游标不为空,移动到第一行并获取计数
if(cursor.moveToFirst()) { if (cursor != null) {
if (cursor.moveToFirst()) {
try { try {
count = cursor.getInt(0); count = cursor.getInt(0);
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
@ -136,11 +199,20 @@ public class DataUtils {
return count; return count;
} }
/**
*
* ID
*
* @param resolver ContentResolver访
* @param noteId ID
* @param type
* @return truefalse
*/
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_FOLER, 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;
@ -153,6 +225,13 @@ public class DataUtils {
return exist; return exist;
} }
/**
* ID
*
* @param resolver ContentResolver访
* @param noteId ID
* @return IDtruefalse
*/
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);
@ -167,37 +246,72 @@ public class DataUtils {
return exist; return exist;
} }
/**
* ID
* ID
*
* @param resolver ContentResolver访
* @param dataId ID
* @return IDtruefalse
*/
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) { public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
// 构建查询获取特定数据ID的记录
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) {
// 如果游标计数大于0表示记录存在
if (cursor.getCount() > 0) { if (cursor.getCount() > 0) {
exist = true; exist = true;
} }
// 关闭游标,释放资源
cursor.close(); cursor.close();
} }
// 返回是否存在的结果
return exist; return exist;
} }
/**
*
*
*
* @param resolver ContentResolver访
* @param name
* @return truefalse
*/
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_FOLER + " 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.getCount() > 0) { if (cursor != null) {
// 如果游标计数大于0表示文件夹已存在
if (cursor.getCount() > 0) {
exist = true; exist = true;
} }
// 关闭游标,释放资源
cursor.close(); cursor.close();
} }
// 返回文件夹是否存在的结果
return exist; return exist;
} }
/**
*
*
*
* @param resolver ContentResolver访
* @param folderId ID
* @return HashSetIDnull
*/
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) { public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
// 构建查询获取特定文件夹ID下所有笔记的小部件属性
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 + "=?",
@ -205,7 +319,9 @@ public class DataUtils {
null); null);
HashSet<AppWidgetAttribute> set = null; HashSet<AppWidgetAttribute> set = null;
// 如果查询结果的游标不为空,处理查询结果
if (c != null) { if (c != null) {
// 如果游标有数据创建HashSet集合并填充数据
if (c.moveToFirst()) { if (c.moveToFirst()) {
set = new HashSet<AppWidgetAttribute>(); set = new HashSet<AppWidgetAttribute>();
do { do {
@ -219,77 +335,140 @@ public class DataUtils {
} }
} while (c.moveToNext()); } while (c.moveToNext());
} }
// 关闭游标,释放资源
c.close(); c.close();
} }
// 返回小部件属性集合
return set; return set;
} }
/**
* ID
* ID
* ID
*
* @param resolver ContentResolver访
* @param noteId ID
* @return ID
*/
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) { public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
// 构建查询获取特定笔记ID的通话记录号码
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
* 0
*
* @param resolver ContentResolver访
* @param phoneNumber
* @param callDate
* @return ID0
*/
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) { public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
// 构建查询获取特定电话号码和通话日期的笔记ID
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) {
// 如果游标有数据移动到第一行并获取笔记ID
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
try { try {
// 返回获取到的笔记ID
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(); cursor.close();
} }
// 如果未找到符合条件的笔记或查询过程中发生错误返回0
return 0; return 0;
} }
/**
* ID
* ID
* IDIllegalArgumentException
*
* @param resolver ContentResolver访
* @param noteId ID
* @return ID
* @throws IllegalArgumentException ID
*/
public static String getSnippetById(ContentResolver resolver, long noteId) { public static String getSnippetById(ContentResolver resolver, long noteId) {
// 构建查询获取特定笔记ID的摘要字段
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);
// 初始化摘要字符串
String snippet = "";
// 如果查询结果的游标不为空,处理查询结果
if (cursor != null) { if (cursor != null) {
String snippet = ""; // 如果游标有数据,移动到第一行并获取摘要
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
snippet = cursor.getString(0); snippet = cursor.getString(0);
} }
// 关闭游标,释放资源
cursor.close(); cursor.close();
// 返回获取到的摘要
return snippet; return snippet;
} }
// 如果游标为null表示查询失败或未找到对应的笔记抛出异常
throw new IllegalArgumentException("Note is not found with id: " + noteId); throw new IllegalArgumentException("Note is not found with id: " + noteId);
} }
/**
*
*
*
* @param snippet
* @return
*/
public static String getFormattedSnippet(String snippet) { public static String getFormattedSnippet(String snippet) {
// 如果传入的摘要不为null则进行处理
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);
} }
} }
// 返回处理后的摘要字符串如果原始摘要为null则返回null
return snippet; return snippet;
} }
} }

@ -14,100 +14,75 @@
* limitations under the License. * limitations under the License.
*/ */
package net.micode.notes.tool; package net.micode.notes.tool;
public class GTaskStringUtils { /**
* GoogleGTask
public final static String GTASK_JSON_ACTION_ID = "action_id"; * GTask JSON使
*/
public final static String GTASK_JSON_ACTION_LIST = "action_list"; public class GTaskStringUtils {
public final static String GTASK_JSON_ACTION_TYPE = "action_type"; // GTask JSON动作类型常量
public final static String GTASK_JSON_ACTION_ID = "action_id"; // 动作ID
public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; 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_GETALL = "get_all";
// GTask JSON动作类型具体值
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_GETALL = "get_all"; // 获取全部动作
public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; // 移动动作
public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; // 更新动作
public final static String GTASK_JSON_CREATOR_ID = "creator_id";
// GTask JSON其他常量
public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; public final static String GTASK_JSON_CREATOR_ID = "creator_id"; // 创建者ID
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_CLIENT_VERSION = "client_version"; // 客户端版本
public final static String GTASK_JSON_COMPLETED = "completed"; // 完成状态
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_DEFAULT_LIST_ID = "default_list_id"; // 默认列表ID
public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; public final static String GTASK_JSON_DELETED = "deleted"; // 删除标志
public final static String GTASK_JSON_DEST_LIST = "dest_list"; // 目标列表
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; // 目标父节点
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; // 目标父节点类型
public final static String GTASK_JSON_DELETED = "deleted"; public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta"; // 实体变化
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; // 实体类型
public final static String GTASK_JSON_DEST_LIST = "dest_list"; public final static String GTASK_JSON_GET_DELETED = "get_deleted"; // 获取已删除项
public final static String GTASK_JSON_ID = "id"; // ID
public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; public final static String GTASK_JSON_INDEX = "index"; // 索引
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; // 最后修改时间
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; // 最新同步点
public final static String GTASK_JSON_LIST_ID = "list_id"; // 列表ID
public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta"; public final static String GTASK_JSON_LISTS = "lists"; // 列表
public final static String GTASK_JSON_NAME = "name"; // 名称
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; public final static String GTASK_JSON_NEW_ID = "new_id"; // 新ID
public final static String GTASK_JSON_NOTES = "notes"; // 笔记
public final static String GTASK_JSON_GET_DELETED = "get_deleted"; public final static String GTASK_JSON_PARENT_ID = "parent_id"; // 父节点ID
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; // 前一个兄弟节点ID
public final static String GTASK_JSON_ID = "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_INDEX = "index"; public final static String GTASK_JSON_TASKS = "tasks"; // 任务
public final static String GTASK_JSON_TYPE = "type"; // 类型
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; public final static String GTASK_JSON_TYPE_GROUP = "GROUP"; // 组类型
public final static String GTASK_JSON_TYPE_TASK = "TASK"; // 任务类型
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; public final static String GTASK_JSON_USER = "user"; // 用户
public final static String GTASK_JSON_LIST_ID = "list_id"; // MIUI笔记文件夹前缀
public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]";
public final static String GTASK_JSON_LISTS = "lists";
// 默认文件夹名称
public final static String GTASK_JSON_NAME = "name"; public final static String FOLDER_DEFAULT = "Default";
public final static String GTASK_JSON_NEW_ID = "new_id"; // 通话笔记文件夹名称
public final static String FOLDER_CALL_NOTE = "Call_Note";
public final static String GTASK_JSON_NOTES = "notes";
// 元数据文件夹名称
public final static String GTASK_JSON_PARENT_ID = "parent_id"; public final static String FOLDER_META = "METADATA";
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; // 元数据头部常量
public final static String META_HEAD_GTASK_ID = "meta_gid"; // GTask ID
public final static String GTASK_JSON_RESULTS = "results"; public final static String META_HEAD_NOTE = "meta_note"; // 笔记
public final static String META_HEAD_DATA = "meta_data"; // 数据
public final static String GTASK_JSON_SOURCE_LIST = "source_list";
// 特殊笔记名称,用于存储元数据
public final static String GTASK_JSON_TASKS = "tasks"; public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE";
}
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";
}

@ -14,6 +14,9 @@
* 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,47 +27,85 @@ import net.micode.notes.ui.NotesPreferenceActivity;
public class ResourceParser { public class ResourceParser {
/**
*
*/
public static final int YELLOW = 0; public static final int YELLOW = 0;
public static final int BLUE = 1; public static final int BLUE = 1;
public static final int WHITE = 2; public static final int WHITE = 2;
public static final int GREEN = 3; public static final int GREEN = 3;
public static final int RED = 4; public static final int RED = 4;
/**
*
*/
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_SMALL = 0;
public static final int TEXT_MEDIUM = 1; public static final int TEXT_MEDIUM = 1;
public static final int TEXT_LARGE = 2; public static final int TEXT_LARGE = 2;
public static final int TEXT_SUPER = 3; 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 { public static class NoteBgResources {
/**
* id
* id
*/
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, // 编辑状态下白色主题的笔记背景
R.drawable.edit_green, R.drawable.edit_green, // 编辑状态下绿色主题的笔记背景
R.drawable.edit_red R.drawable.edit_red // 编辑状态下红色主题的笔记背景
}; };
/**
* id
* id
*/
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, // 编辑状态下白色主题的笔记标题背景
R.drawable.edit_title_green, R.drawable.edit_title_green, // 编辑状态下绿色主题的笔记标题背景
R.drawable.edit_title_red R.drawable.edit_title_red // 编辑状态下红色主题的笔记标题背景
}; };
/**
*
* @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];
} }
/**
*
* @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
* @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)) {
@ -74,60 +115,105 @@ public class ResourceParser {
} }
} }
/**
*
*/
public static class NoteItemBgResources { public static class NoteItemBgResources {
/**
* id
* id
*/
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, // 白色主题的列表第一个笔记项背景
R.drawable.list_green_up, R.drawable.list_green_up, // 绿色主题的列表第一个笔记项背景
R.drawable.list_red_up R.drawable.list_red_up // 红色主题的列表第一个笔记项背景
}; };
/**
* id
* id
*/
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, // 白色主题的列表中间笔记项背景
R.drawable.list_green_middle, R.drawable.list_green_middle, // 绿色主题的列表中间笔记项背景
R.drawable.list_red_middle R.drawable.list_red_middle // 红色主题的列表中间笔记项背景
}; };
/**
* id
* id
*/
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 // 红色主题的列表最后一个笔记项背景
}; };
/**
* id
* id
*/
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, // 白色主题的单个笔记项背景
R.drawable.list_green_single, R.drawable.list_green_single, // 绿色主题的单个笔记项背景
R.drawable.list_red_single R.drawable.list_red_single // 红色主题的单个笔记项背景
}; };
/**
*
* @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];
} }
/**
*
* @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];
} }
/**
*
* @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];
} }
/**
*
* @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];
} }
/**
*
* @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,
@ -137,6 +223,11 @@ public class ResourceParser {
R.drawable.widget_2x_red, R.drawable.widget_2x_red,
}; };
/**
* 2x
* @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];
} }
@ -149,11 +240,19 @@ public class ResourceParser {
R.drawable.widget_4x_red R.drawable.widget_4x_red
}; };
/**
* 4x
* @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,
@ -162,11 +261,16 @@ public class ResourceParser {
R.style.TextAppearanceSuper R.style.TextAppearanceSuper
}; };
/**
*
* @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. * HACKME: idbug
* The id may larger than the length of resources, in this case, * id
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE} * {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
*/ */
if (id >= TEXTAPPEARANCE_RESOURCES.length) { if (id >= TEXTAPPEARANCE_RESOURCES.length) {
return BG_DEFAULT_FONT_SIZE; return BG_DEFAULT_FONT_SIZE;
@ -174,8 +278,12 @@ public class ResourceParser {
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