已提交注释过的代码文件,李彤:tool包,肖左己:gtask包

main
xiaozuoji 1 year ago
parent a672f5900f
commit d2fd46255f

@ -26,29 +26,48 @@ import org.json.JSONObject;
public class MetaData extends Task {
/*
* TAG
* getSimpleName ()
*/
private final static String TAG = MetaData.class.getSimpleName();
private String mRelatedGid = null;
/*
*
* JSONObjectput ()TasksetNotes ()setName ()
*/
public void setMeta(String gid, JSONObject metaInfo) {
/*
* metaInfojsonobject
* message what why
*/
try {
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) {
}
catch (JSONException e) {
Log.e(TAG, "failed to put related gid");
}
setNotes(metaInfo.toString());
setName(GTaskStringUtils.META_NOTE_NAME);
}
/*
* Gid
*/
public String getRelatedGid() {
return mRelatedGid;
}
/*
*
*/
@Override
public boolean isWorthSaving() {
return getNotes() != null;
}
/*
* 使json
* TasksetContentByRemoteJSON ()
*/
@Override
public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js);
@ -62,18 +81,24 @@ public class MetaData extends Task {
}
}
}
/*
* 使json
*/
@Override
public void setContentByLocalJSON(JSONObject js) {
// this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
}
/*
* json
*/
@Override
public JSONObject getLocalJSONFromContent() {
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
}
/*
*
*/
@Override
public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called");

@ -20,82 +20,84 @@ import android.database.Cursor;
import org.json.JSONObject;
/**
* Node
*/
public abstract class Node {
public static final int SYNC_ACTION_NONE = 0;
public static final int SYNC_ACTION_NONE = 0; //无同步动作
public static final int SYNC_ACTION_ADD_REMOTE = 1;
public static final int SYNC_ACTION_ADD_REMOTE = 1; //远程添加同步
public static final int SYNC_ACTION_ADD_LOCAL = 2;
public static final int SYNC_ACTION_ADD_LOCAL = 2; //本地添加同步
public static final int SYNC_ACTION_DEL_REMOTE = 3;
public static final int SYNC_ACTION_DEL_REMOTE = 3; //远程删除同步
public static final int SYNC_ACTION_DEL_LOCAL = 4;
public static final int SYNC_ACTION_DEL_LOCAL = 4; //本地删除同步
public static final int SYNC_ACTION_UPDATE_REMOTE = 5;
public static final int SYNC_ACTION_UPDATE_REMOTE = 5; //远程跟新同步
public static final int SYNC_ACTION_UPDATE_LOCAL = 6;
public static final int SYNC_ACTION_UPDATE_LOCAL = 6; //本地更新同步
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7; //跟新冲突同步
public static final int SYNC_ACTION_ERROR = 8;
public static final int SYNC_ACTION_ERROR = 8; //同步错误
private String mGid;
private String mName;
private long mLastModified;
private long mLastModified; //上次修改时间
private boolean mDeleted;
private boolean mDeleted; //是否删除
public Node() {
public Node() { //初始化node
mGid = null;
mName = "";
mLastModified = 0;
mDeleted = false;
}
//方法jsonobject
public abstract JSONObject getCreateAction(int actionId); //返回创建动作
public abstract JSONObject getCreateAction(int actionId);
public abstract JSONObject getUpdateAction(int actionId);
public abstract JSONObject getUpdateAction(int actionId); //返回更新动作
public abstract void setContentByRemoteJSON(JSONObject js);
public abstract void setContentByRemoteJSON(JSONObject js); //远端设置目录
public abstract void setContentByLocalJSON(JSONObject js);
public abstract void setContentByLocalJSON(JSONObject js); //本地json设置目录
public abstract JSONObject getLocalJSONFromContent();
public abstract JSONObject getLocalJSONFromContent(); //从目录得到本地json消息
public abstract int getSyncAction(Cursor c);
public abstract int getSyncAction(Cursor c); //用cursor得到同步动作
public void setGid(String gid) {
this.mGid = gid;
}
} //设置Gid
public void setName(String name) {
this.mName = name;
}
} //设置名字
public void setLastModified(long lastModified) {
this.mLastModified = lastModified;
}
this.mLastModified = lastModified; } //设置最后的调整
public void setDeleted(boolean deleted) {
this.mDeleted = deleted;
}
} //设置删除标志
public String getGid() {
return this.mGid;
}
} //得到Gid
public String getName() {
return this.mName;
}
} //得到名字
public long getLastModified() {
return this.mLastModified;
}
} //得到最后调整时间
public boolean getDeleted() {
return this.mDeleted;
}
} //得到删除标志
}

@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* 便
*/
package net.micode.notes.gtask.data;
import android.content.ContentResolver;
@ -36,41 +38,52 @@ import org.json.JSONObject;
public class SqlData {
/*
* TAG
* getSimpleName ()
*/
private static final String TAG = SqlData.class.getSimpleName();
private static final int INVALID_ID = -99999;
/*
* NotesDataColumn
*/
public static final String[] PROJECTION_DATA = new String[] {
DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1,
DataColumns.DATA3
};
//sql表中5列的编号
public static final int DATA_ID_COLUMN = 0; //ID号
public static final int DATA_ID_COLUMN = 0;
public static final int DATA_MIME_TYPE_COLUMN = 1;
public static final int DATA_MIME_TYPE_COLUMN = 1; //MIME类型
public static final int DATA_CONTENT_COLUMN = 2;
public static final int DATA_CONTENT_COLUMN = 2; //内容
public static final int DATA_CONTENT_DATA_1_COLUMN = 3;
public static final int DATA_CONTENT_DATA_1_COLUMN = 3; //DATA_1内容
public static final int DATA_CONTENT_DATA_3_COLUMN = 4;
public static final int DATA_CONTENT_DATA_3_COLUMN = 4; //DATA_3内容
private ContentResolver mContentResolver;
private ContentResolver mContentResolver; //文本处理(系统库)
private boolean mIsCreate;
private boolean mIsCreate; //表征是否创建
private long mDataId;
private long mDataId; //数据ID
private String mDataMimeType;
private String mDataMimeType; //数据的MIME系统类型
private String mDataContent;
private String mDataContent; //数据内容
private long mDataContentData1;
private long mDataContentData1; //数据内容数据1
private String mDataContentData3;
private String mDataContentData3; //数据内容数据3
private ContentValues mDiffDataValues;
/*
*
* mContentResolverContentProvider
* mIsCreate
*/
public SqlData(Context context) {
mContentResolver = context.getContentResolver();
mIsCreate = true;
@ -81,14 +94,21 @@ public class SqlData {
mDataContentData3 = "";
mDiffDataValues = new ContentValues();
}
/*
*
* mContentResolverContentProvider
* mIsCreate
*/
public SqlData(Context context, Cursor c) {
mContentResolver = context.getContentResolver();
mIsCreate = false;
loadFromCursor(c);
mDiffDataValues = new ContentValues();
}
/*
*
*
*/
private void loadFromCursor(Cursor c) {
mDataId = c.getLong(DATA_ID_COLUMN);
mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);
@ -96,7 +116,9 @@ public class SqlData {
mDataContentData1 = c.getLong(DATA_CONTENT_DATA_1_COLUMN);
mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);
}
/*
*
*/
public void setContent(JSONObject js) throws JSONException {
long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID;
if (mIsCreate || mDataId != dataId) {
@ -129,21 +151,25 @@ public class SqlData {
}
mDataContentData3 = dataContentData3;
}
/*
*
*/
public JSONObject getContent() throws JSONException {
if (mIsCreate) {
Log.e(TAG, "it seems that we haven't created this in database yet");
return null;
}
JSONObject js = new JSONObject();
js.put(DataColumns.ID, mDataId);
js.put(DataColumns.MIME_TYPE, mDataMimeType);
js.put(DataColumns.CONTENT, mDataContent);
} //如果还没创建那就抛出异常
JSONObject js = new JSONObject(); //新建json数据结构
js.put(DataColumns.ID, mDataId); //添加目录ID和数据ID
js.put(DataColumns.MIME_TYPE, mDataMimeType); //添加目录MIME系统类型
js.put(DataColumns.CONTENT, mDataContent); //添加目录内容和数据内容
js.put(DataColumns.DATA1, mDataContentData1);
js.put(DataColumns.DATA3, mDataContentData3);
return js;
}
/*
* commit
*/
public void commit(long noteId, boolean validateVersion, long version) {
if (mIsCreate) {
@ -182,7 +208,7 @@ public class SqlData {
mDiffDataValues.clear();
mIsCreate = false;
}
//获取ID
public long getId() {
return mDataId;
}

@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* note
*/
package net.micode.notes.gtask.data;
import android.appwidget.AppWidgetManager;
@ -39,10 +41,14 @@ import java.util.ArrayList;
public class SqlNote {
/*
* TAG
* getSimpleName ()
*/
private static final String TAG = SqlNote.class.getSimpleName();
private static final int INVALID_ID = -99999;
private static final int INVALID_ID = -99999; //设置无效ID为-99999
//NoteColumns 的17个预设常量ID
public static final String[] PROJECTION_NOTE = new String[] {
NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID,
NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE,
@ -51,7 +57,7 @@ public class SqlNote {
NoteColumns.LOCAL_MODIFIED, NoteColumns.ORIGIN_PARENT_ID, NoteColumns.GTASK_ID,
NoteColumns.VERSION
};
//这里是对Column的17个常量id编号
public static final int ID_COLUMN = 0;
public static final int ALERTED_DATE_COLUMN = 1;
@ -121,7 +127,7 @@ public class SqlNote {
private ContentValues mDiffNoteValues;
private ArrayList<SqlData> mDataList;
//构造函数SqlNote参数为context上下文
public SqlNote(Context context) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -142,18 +148,18 @@ public class SqlNote {
mDiffNoteValues = new ContentValues();
mDataList = new ArrayList<SqlData>();
}
//构造函数参数为context上下文和cursor指针
public SqlNote(Context context, Cursor c) {
mContext = context;
mContentResolver = context.getContentResolver();
mIsCreate = false;
loadFromCursor(c);
loadFromCursor(c); //从指针处加载
mDataList = new ArrayList<SqlData>();
if (mType == Notes.TYPE_NOTE)
loadDataContent();
loadDataContent(); //加载数据内容
mDiffNoteValues = new ContentValues();
}
//用column号构造函数
public SqlNote(Context context, long id) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -165,7 +171,7 @@ public class SqlNote {
mDiffNoteValues = new ContentValues();
}
//从指针处加载的实现方法
private void loadFromCursor(long id) {
Cursor c = null;
try {
@ -184,7 +190,7 @@ public class SqlNote {
c.close();
}
}
//从光标下获得数据
private void loadFromCursor(Cursor c) {
mId = c.getLong(ID_COLUMN);
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
@ -199,7 +205,7 @@ public class SqlNote {
mWidgetType = c.getInt(WIDGET_TYPE_COLUMN);
mVersion = c.getLong(VERSION_COLUMN);
}
//从光标下获取数据并加载到数据库
private void loadDataContent() {
Cursor c = null;
mDataList.clear();
@ -225,7 +231,7 @@ public class SqlNote {
c.close();
}
}
//通过json数据结构设置content用于共享数据
public boolean setContent(JSONObject js) {
try {
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
@ -358,7 +364,7 @@ public class SqlNote {
}
return true;
}
//获取content机制提供的数据并加载到note中
public JSONObject getContent() {
try {
JSONObject js = new JSONObject();
@ -407,39 +413,40 @@ public class SqlNote {
return null;
}
//给当前id设置父id
public void setParentId(long id) {
mParentId = id;
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
}
//用Gid设置GtaskID
public void setGtaskId(String gid) {
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
}
//用同步ID设置SyncId
public void setSyncId(long syncId) {
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
}
//重置本地改动
public void resetLocalModified() {
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
}
//获取ID
public long getId() {
return mId;
}
//获取父ID
public long getParentId() {
return mParentId;
}
//显示可显示的内容
public String getSnippet() {
return mSnippet;
}
//表征是否是便签类
public boolean isNoteType() {
return mType == Notes.TYPE_NOTE;
}
//把修改内容添加到数据库中
public void commit(boolean validateVersion) {
if (mIsCreate) {
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {

@ -35,22 +35,22 @@ import org.json.JSONObject;
public class Task extends Node {
private static final String TAG = Task.class.getSimpleName();
private boolean mCompleted;
private boolean mCompleted; //表征是否完成
private String mNotes;
private String mNotes; //note的名字
private JSONObject mMetaInfo;
private JSONObject mMetaInfo; //元数据信息以json结构
private Task mPriorSibling;
private Task mPriorSibling; //最优先兄弟任务(同级别)
private TaskList mParent;
private TaskList mParent; //所在任务列表指针
public Task() {
super();
mCompleted = false;
mNotes = null;
mPriorSibling = null;
mParent = null;
mPriorSibling = null; //TaskList中当前Task前面的Task的指针
mParent = null; //当前Task所在的TaskList
mMetaInfo = null;
}
@ -58,17 +58,17 @@ public class Task extends Node {
JSONObject js = new JSONObject();
try {
// action_type
// action_type,添加动作类型
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE);
// action_id
// action_id添加动作ID
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
// index
// index,添加索引
js.put(GTaskStringUtils.GTASK_JSON_INDEX, mParent.getChildTaskIndex(this));
// entity_delta
// entity_delta 实体改动
JSONObject entity = new JSONObject();
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null");
@ -102,22 +102,22 @@ public class Task extends Node {
return js;
}
//功能:获得更新动作
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
try {
// action_type
// action_type,动作类型
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE);
// action_id
// action_id动作ID
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
// id
js.put(GTaskStringUtils.GTASK_JSON_ID, getGid());
// entity_delta
// entity_delta,实体改变
JSONObject entity = new JSONObject();
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
if (getNotes() != null) {
@ -134,36 +134,36 @@ public class Task extends Node {
return js;
}
//功能通过远程json结构设置内容
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
// id
// 设置ID
if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
}
// last_modified
// 设置最终改动
if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) {
setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED));
}
// name
// 设置名字
if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) {
setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME));
}
// notes
// 设置便签
if (js.has(GTaskStringUtils.GTASK_JSON_NOTES)) {
setNotes(js.getString(GTaskStringUtils.GTASK_JSON_NOTES));
}
// deleted
// 设置删除便签
if (js.has(GTaskStringUtils.GTASK_JSON_DELETED)) {
setDeleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_DELETED));
}
// completed
// 表征设置完成
if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) {
setCompleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_COMPLETED));
}
@ -171,10 +171,10 @@ public class Task extends Node {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new ActionFailureException("fail to get task content from jsonobject");
}
} //捕捉并抛出异常
}
}
//功能用本地json文件设置内容
public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)
|| !js.has(GTaskStringUtils.META_HEAD_DATA)) {
@ -201,11 +201,11 @@ public class Task extends Node {
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
}
} //捕获并抛出异常
}
//从content机制获取本地json文件
public JSONObject getLocalJSONFromContent() {
String name = getName();
String name = getName(); //获取名字
try {
if (mMetaInfo == null) {
// new task created from web
@ -214,10 +214,10 @@ public class Task extends Node {
return null;
}
JSONObject js = new JSONObject();
JSONObject note = new JSONObject();
JSONArray dataArray = new JSONArray();
JSONObject data = new JSONObject();
JSONObject js = new JSONObject(); //新建json对象并用数据库中column相应字段表示
JSONObject note = new JSONObject(); //新建note的json对象并用数据库中column相应字段表示
JSONArray dataArray = new JSONArray(); //新建data向量json对象并用数据库中column相应字段表示
JSONObject data = new JSONObject(); //新建data的json对象并用数据库中column相应字段表示、
data.put(DataColumns.CONTENT, name);
dataArray.put(data);
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
@ -225,8 +225,7 @@ public class Task extends Node {
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
return js;
} else {
// synced task
JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); // task机制同步
JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
for (int i = 0; i < dataArray.length(); i++) {
@ -244,60 +243,60 @@ public class Task extends Node {
Log.e(TAG, e.toString());
e.printStackTrace();
return null;
}
} //捕获并抛出异常
}
//设置元数据信息
public void setMetaInfo(MetaData metaData) {
if (metaData != null && metaData.getNotes() != null) {
try {
mMetaInfo = new JSONObject(metaData.getNotes());
mMetaInfo = new JSONObject(metaData.getNotes()); //如果没有元数据为空那么新建json元数据对象
} catch (JSONException e) {
Log.w(TAG, e.toString());
mMetaInfo = null;
}
} //否则抛出异常
}
}
//获取同步动作
public int getSyncAction(Cursor c) {
try {
JSONObject noteInfo = null;
if (mMetaInfo != null && mMetaInfo.has(GTaskStringUtils.META_HEAD_NOTE)) {
noteInfo = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
}
} //如果元数据信息不为空那么通过json机制获取
if (noteInfo == null) {
Log.w(TAG, "it seems that note meta has been deleted");
return SYNC_ACTION_UPDATE_REMOTE;
}
} //如果便签信息为空那么抛出异常并返回远程代码
if (!noteInfo.has(NoteColumns.ID)) {
Log.w(TAG, "remote note id seems to be deleted");
return SYNC_ACTION_UPDATE_LOCAL;
}
} //如果便签信息没有ID那么抛出异常并且返回本地代码
// validate the note id now
if (c.getLong(SqlNote.ID_COLUMN) != noteInfo.getLong(NoteColumns.ID)) {
Log.w(TAG, "note id doesn't match");
return SYNC_ACTION_UPDATE_LOCAL;
}
} //如果数据库中ID——column不正确那么抛出异常并返回本地同步代码
if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
// there is no local update
// 说明没有本地更新
if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
// no update both side
// 两边都没有改动
return SYNC_ACTION_NONE;
} else {
// apply remote to local
// 从远端申请到本地
return SYNC_ACTION_UPDATE_LOCAL;
}
} else {
// validate gtask id
// 使能Gtask ID
if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) {
Log.e(TAG, "gtask id doesn't match");
return SYNC_ACTION_ERROR;
}
if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
// local modification only
// 只能在本地修改
return SYNC_ACTION_UPDATE_REMOTE;
} else {
return SYNC_ACTION_UPDATE_CONFLICT;
@ -306,7 +305,7 @@ public class Task extends Node {
} catch (Exception e) {
Log.e(TAG, e.toString());
e.printStackTrace();
}
} //抛出异常并且捕获
return SYNC_ACTION_ERROR;
}

@ -1,4 +1,4 @@
/*
/**
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -35,71 +35,80 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
public class BackupUtils {
private static final String TAG = "BackupUtils";
// Singleton stuff
// Singleton stuff:即单例模式,确保一个类中只有一个实例且此实例可以被全局访问
private static BackupUtils sInstance;
// 获取BackupUtils的单例实例
public static synchronized BackupUtils getInstance(Context context) {
if (sInstance == null) {
sInstance = new BackupUtils(context);
}
// 如果sInstance为null则创建一个新的BackupUtils对象并将其赋值给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当前SD卡未挂载
// 定义备份和还原状态常量
public static final int STATE_SD_CARD_UNMOUONTED = 0;
// The backup file not exist
// The backup file not exist:备份数据不存在
public static final int STATE_BACKUP_FILE_NOT_EXIST = 1;
// The data is not well formated, may be changed by other programs
// 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
// Some run-time exception which causes restore or backup fails:程序运行时异常导致备份或者还原操作失败
public static final int STATE_SYSTEM_ERROR = 3;
// Backup or restore success
// Backup or restore success:备份或者还原操作成功
public static final int STATE_SUCCESS = 4;
private TextExport mTextExport;
// 声明一个TextExport对象mTextExport实现对象信息的导出
private BackupUtils(Context context) {
mTextExport = new TextExport(context);
// 创建一个TextExport对象并将其赋值给mTextExport
}
private static boolean externalStorageAvailable() {
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
// 检查外存是否可用如果可用则返回true否则返回false
}
public int exportToText() {
return mTextExport.exportToText();
// 调用TextExport对象的exportToText方法并返回结果
}
public String getExportedTextFileName() {
return mTextExport.mFileName;
// 获取导出对象的名字
}
public String getExportedTextFileDir() {
return mTextExport.mFileDirectory;
// 获取导出对象的目录
}
private static class TextExport {
// 定义一个常量数组用于从ContentProvider中获取特定的便签信息
private static final String[] NOTE_PROJECTION = {
NoteColumns.ID,
NoteColumns.MODIFIED_DATE,
NoteColumns.SNIPPET,
NoteColumns.TYPE
NoteColumns.ID, //便签标识符
NoteColumns.MODIFIED_DATE, //便签的修改日期
NoteColumns.SNIPPET, //便签摘要
NoteColumns.TYPE //便签类型
};
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 String[] DATA_PROJECTION = {
// 定义了一个包含数据列的投影数组
DataColumns.CONTENT,
DataColumns.MIME_TYPE,
DataColumns.DATA1,
@ -108,55 +117,70 @@ public class BackupUtils {
DataColumns.DATA4,
};
private static final int DATA_COLUMN_CONTENT = 0;
private static final int DATA_COLUMN_CONTENT = 0; // 数据内容列的索引
private static final int DATA_COLUMN_MIME_TYPE = 1;
private static final int DATA_COLUMN_MIME_TYPE = 1; //数据的媒体类型
private static final int DATA_COLUMN_CALL_DATE = 2;
private static final int DATA_COLUMN_CALL_DATE = 2; // 通话日期列的索引
private static final int DATA_COLUMN_PHONE_NUMBER = 4;
private static final int DATA_COLUMN_PHONE_NUMBER = 4; // 电话号码列的索引
private final String [] TEXT_FORMAT;
private static final int FORMAT_FOLDER_NAME = 0;
private static final int FORMAT_NOTE_DATE = 1;
private static final int FORMAT_NOTE_CONTENT = 2;
private final String [] TEXT_FORMAT; // 文本格式数组
private static final int FORMAT_FOLDER_NAME = 0; // 文件夹名称的格式索引
private static final int FORMAT_NOTE_DATE = 1; // 备注日期的格式索引
private static final int FORMAT_NOTE_CONTENT = 2; // 备注内容的格式索引
private Context mContext;
private String mFileName;
private String mFileDirectory;
private Context mContext; //文本
private String mFileName; //文件名
private String mFileDirectory; //文件目录
public TextExport(Context context) {
TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note);
// 从资源中获取字符串数组并将其赋值给TEXT_FORMAT成员变量
mContext = context;
// 将传入的Context对象赋值给mContext成员变量
mFileName = "";
// 将mFileName成员变量初始化为空字符串
mFileDirectory = "";
// 将mFileDirectory成员变量初始化为空字符串
}
private String getFormat(int id) {
return TEXT_FORMAT[id];
}
} // 根据传入的id参数从TEXT_FORMAT数组中获取对应索引位置的字符串格式化模板
/////////////////////////////////////////
/**
* Export the folder identified by folder id to text
*/
private void exportFolderToText(String folderId, PrintStream ps) {
// Query notes belong to this folder
// Query notes belong to this folder通过查询parent id是文件夹id的note来选出制定ID文件夹下的Note
Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] {
folderId
}, null);
if (notesCursor != null) {
/*
notesCursor
使mContext.getContentResolver()ContentResolver
ContentResolverquery()
Notes.CONTENT_NOTE_URIURI"Notes"URI
NOTE_PROJECTION
NoteColumns.PARENT_ID + "=?""NoteColumns.PARENT_ID"
new String[] { folderId }"folderId"
null
notesCursor
*/
if (notesCursor != null) { // 如果查询结果不为空
if (notesCursor.moveToFirst()) {
do {
// Print note's last modified date
// Print note's last modified date// 打印笔记的最后修改日期
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm),
notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
// Query data belong to this note
// Query data belong to this note// 查询属于该笔记的数据
String noteId = notesCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps);
} while (notesCursor.moveToNext());
} while (notesCursor.moveToNext()); // 遍历结果集中的每一行数据
}
notesCursor.close();
}
@ -164,13 +188,25 @@ public class BackupUtils {
/**
* Export note identified by id to a print stream
* ID
*/
private void exportNoteToText(String noteId, PrintStream ps) {
Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI,
DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] {
noteId
}, null);
/*
exportNoteToTextnoteIdPrintStreamps
dataCursor
使mContext.getContentResolver()ContentResolver
ContentResolverquery()
Notes.CONTENT_DATA_URIURI"Notes"DATA_URI
DATA_PROJECTION
DataColumns.NOTE_ID + "=?""DataColumns.NOTE_ID"
new String[] { noteId }"noteId"
null
dataCursor
*/
if (dataCursor != null) {
if (dataCursor.moveToFirst()) {
do {
@ -185,16 +221,17 @@ public class BackupUtils {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
phoneNumber));
}
// Print call date
// Print call date:打印电话号码
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat
.format(mContext.getString(R.string.format_datetime_mdhm),
callDate)));
// Print call attachment location
// Print call attachment location:打印附件位置
if (!TextUtils.isEmpty(location)) {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
location));
}
} else if (DataConstants.NOTE.equals(mimeType)) {
//获取笔记内容
String content = dataCursor.getString(DATA_COLUMN_CONTENT);
if (!TextUtils.isEmpty(content)) {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
@ -211,25 +248,27 @@ public class BackupUtils {
Character.LINE_SEPARATOR, Character.LETTER_NUMBER
});
} catch (IOException e) {
Log.e(TAG, e.toString());
Log.e(TAG, e.toString()); //日志输出打印异常信息
}
}
/**
* Note will be exported as text which is user readable
*
*/
public int exportToText() {
// 检查外部存储是否可用
if (!externalStorageAvailable()) {
Log.d(TAG, "Media was not mounted");
return STATE_SD_CARD_UNMOUONTED;
}
// 获取导出到文本的打印流
PrintStream ps = getExportToTextPrintStream();
if (ps == null) {
Log.e(TAG, "get print stream error");
return STATE_SYSTEM_ERROR;
}
// First export folder and its notes
// First export folder and its notes:首先导出文件夹及其笔记
Cursor folderCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
@ -240,7 +279,7 @@ public class BackupUtils {
if (folderCursor != null) {
if (folderCursor.moveToFirst()) {
do {
// Print folder's name
// Print folder's name:打印文件夹名称
String folderName = "";
if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) {
folderName = mContext.getString(R.string.call_record_folder_name);
@ -251,18 +290,33 @@ public class BackupUtils {
ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName));
}
String folderId = folderCursor.getString(NOTE_COLUMN_ID);
//导出文件夹中的笔记
exportFolderToText(folderId, ps);
} while (folderCursor.moveToNext());
}
folderCursor.close();
}
// Export notes in root's folder
// Export notes in root's folder:导出根文件夹中的笔记
Cursor noteCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID
+ "=0", null, null);
/*
noteCursor
使mContext.getContentResolver()ContentResolver
ContentResolverquery()
Notes.CONTENT_NOTE_URIURI"Notes"NOTE_URI
NOTE_PROJECTION
NoteColumns.TYPE + "=" + Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID + "=0""NoteColumns.TYPE""Notes.TYPE_NOTE""NoteColumns.PARENT_ID"0
null
null
"AND"
NoteColumns.TYPE + "=" + Notes.TYPE_NOTE "Notes.TYPE_NOTE"
NoteColumns.PARENT_ID + "=0" ID0
noteCursor
*/
if (noteCursor != null) {
if (noteCursor.moveToFirst()) {
@ -284,8 +338,10 @@ public class BackupUtils {
/**
* Get a print stream pointed to the file {@generateExportedTextFile}
*
*/
private PrintStream getExportToTextPrintStream() {
// 生成将要导出的文件路径和名称
File file = generateFileMountedOnSDcard(mContext, R.string.file_path,
R.string.file_name_txt_format);
if (file == null) {
@ -296,6 +352,7 @@ public class BackupUtils {
mFileDirectory = mContext.getString(R.string.file_path);
PrintStream ps = null;
try {
// 创建输出流并返回打印流
FileOutputStream fos = new FileOutputStream(file);
ps = new PrintStream(fos);
} catch (FileNotFoundException e) {
@ -311,22 +368,31 @@ public class BackupUtils {
/**
* Generate the text file to store imported data
* ID
*/
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
// 创建一个StringBuilder来构建文件路径
StringBuilder sb = new StringBuilder();
// 将外部存储路径添加到StringBuilder中
sb.append(Environment.getExternalStorageDirectory());
// 将文件路径的资源ID转换为实际路径添加到StringBuilder中
sb.append(context.getString(filePathResId));
// 创建表示文件夹的File对象
File filedir = new File(sb.toString());
// 添加文件名和格式到StringBuilder中
sb.append(context.getString(
fileNameFormatResId,
DateFormat.format(context.getString(R.string.format_date_ymd),
System.currentTimeMillis())));
// 创建表示文件的File对象
File file = new File(sb.toString());
try {
// 检查文件夹是否存在,不存在则创建
if (!filedir.exists()) {
filedir.mkdir();
}
// 检查文件是否存在,不存在则创建
if (!file.exists()) {
file.createNewFile();
}

@ -34,9 +34,23 @@ import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
import java.util.ArrayList;
import java.util.HashSet;
/**
* DataUtils
*
* ContentResolver
*
* @version 1.0
* @since 2023-12-24 */
public class DataUtils {
public static final String TAG = "DataUtils";
/**
*
*
* @param resolver Android访
* @param ids ID
* @see {@link Notes} Notes
* @return
*/
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
if (ids == null) {
Log.d(TAG, "the ids is null");
@ -71,7 +85,15 @@ public class DataUtils {
}
return false;
}
/**
*
*
* @param resolver Android访
* @param id ID
* @param srcFolderId ID
* @param desFolderId ID
* @see {@link Notes} Notes
*/
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
ContentValues values = new ContentValues();
values.put(NoteColumns.PARENT_ID, desFolderId);
@ -79,7 +101,14 @@ public class DataUtils {
values.put(NoteColumns.LOCAL_MODIFIED, 1);
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
}
/**
*
*
* @param resolver ContentResolver
* @param ids IDHashSet
* @param folderId ID
* @return
*/
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
long folderId) {
if (ids == null) {
@ -112,7 +141,11 @@ public class DataUtils {
}
/**
* Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}}
* {@link Notes#TYPE_SYSTEM}
*
* @param resolver ContentResolver
* @see {@link Notes}
* @return
*/
public static int getUserFolderCount(ContentResolver resolver) {
Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
@ -135,7 +168,14 @@ public class DataUtils {
}
return count;
}
/**
*
*
* @param resolver ContentResolver
* @param noteId ID
* @param type
* @return
*/
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null,
@ -152,7 +192,13 @@ public class DataUtils {
}
return exist;
}
/**
*
*
* @param resolver ContentResolver
* @param noteId ID
* @return
*/
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null);
@ -166,7 +212,13 @@ public class DataUtils {
}
return exist;
}
/**
*
*
* @param resolver ContentResolver
* @param dataId ID
* @return
*/
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
null, null, null, null);
@ -180,7 +232,13 @@ public class DataUtils {
}
return exist;
}
/**
*
*
* @param resolver ContentResolver
* @param name
* @return
*/
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
@ -196,7 +254,13 @@ public class DataUtils {
}
return exist;
}
/**
*
*
* @param resolver ContentResolver
* @param folderId ID
* @return
*/
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
@ -223,7 +287,13 @@ public class DataUtils {
}
return set;
}
/**
* ID
*
* @param resolver ContentResolver
* @param noteId ID
* @return
*/
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.PHONE_NUMBER },
@ -242,7 +312,14 @@ public class DataUtils {
}
return "";
}
/**
* ID
*
* @param resolver ContentResolver
* @param phoneNumber
* @param callDate
* @return ID0
*/
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.NOTE_ID },
@ -263,7 +340,14 @@ public class DataUtils {
}
return 0;
}
/**
* ID
*
* @param resolver ContentResolver
* @param noteId ID
* @return
* @throws IllegalArgumentException ID
*/
public static String getSnippetById(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
new String [] { NoteColumns.SNIPPET },
@ -281,7 +365,12 @@ public class DataUtils {
}
throw new IllegalArgumentException("Note is not found with id: " + noteId);
}
/**
*
*
* @param snippet
* @return
*/
public static String getFormattedSnippet(String snippet) {
if (snippet != null) {
snippet = snippet.trim();

@ -18,96 +18,142 @@ package net.micode.notes.tool;
public class GTaskStringUtils {
// 表示 GTask JSON 数据中的 action_id 字段。
public final static String GTASK_JSON_ACTION_ID = "action_id";
// 表示 GTask JSON 数据中的 action_list 字段。
public final static String GTASK_JSON_ACTION_LIST = "action_list";
// 表示 GTask JSON 数据中的 action_type 字段。
public final static String GTASK_JSON_ACTION_TYPE = "action_type";
// 表示 GTask JSON 数据中的 action_type 字段的取值为 "create"。
public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create";
// 表示 GTask JSON 数据中的 action_type 字段的取值为 "get_all"。
public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all";
// 表示 GTask JSON 数据中的 action_type 字段的取值为 "move"。
public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move";
// 表示 GTask JSON 数据中的 action_type 字段的取值为 "update"。
public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update";
// 表示 GTask JSON 数据中的 creator_id 字段。
public final static String GTASK_JSON_CREATOR_ID = "creator_id";
// 表示 GTask JSON 数据中的 child_entity 字段。
public final static String GTASK_JSON_CHILD_ENTITY = "child_entity";
// 表示 GTask JSON 数据中的 client_version 字段。
public final static String GTASK_JSON_CLIENT_VERSION = "client_version";
// 表示 GTask JSON 数据中的 completed 字段。
public final static String GTASK_JSON_COMPLETED = "completed";
// 表示 GTask JSON 数据中的 current_list_id 字段。
public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id";
// 表示 GTask JSON 数据中的 default_list_id 字段。
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id";
// 表示 GTask JSON 数据中的 deleted 字段。
public final static String GTASK_JSON_DELETED = "deleted";
// 表示 GTask JSON 数据中的 dest_list 字段。
public final static String GTASK_JSON_DEST_LIST = "dest_list";
// 表示 GTask JSON 数据中的 dest_parent 字段。
public final static String GTASK_JSON_DEST_PARENT = "dest_parent";
// 表示 GTask JSON 数据中的 dest_parent_type 字段。
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type";
// 表示 GTask JSON 数据中的 entity_delta 字段。
public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta";
// 表示 GTask JSON 数据中的 entity_type 字段。
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type";
// 表示 GTask JSON 数据中的 get_deleted 字段。
public final static String GTASK_JSON_GET_DELETED = "get_deleted";
// 表示 GTask JSON 数据中的 id 字段。
public final static String GTASK_JSON_ID = "id";
// 表示 GTask JSON 数据中的 index 字段。
public final static String GTASK_JSON_INDEX = "index";
// 表示 GTask JSON 数据中的 last_modified 字段。
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified";
// 表示 GTask JSON 数据中的 latest_sync_point 字段。
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point";
// 表示 GTask JSON 数据中的 list_id 字段。
public final static String GTASK_JSON_LIST_ID = "list_id";
// 表示 GTask JSON 数据中的 lists 字段。
public final static String GTASK_JSON_LISTS = "lists";
// 表示 GTask JSON 数据中的 name 字段。
public final static String GTASK_JSON_NAME = "name";
// 表示 GTask JSON 数据中的 new_id 字段。
public final static String GTASK_JSON_NEW_ID = "new_id";
// 表示 GTask JSON 数据中的 notes 字段。
public final static String GTASK_JSON_NOTES = "notes";
// 表示 GTask JSON 数据中的 parent_id 字段。
public final static String GTASK_JSON_PARENT_ID = "parent_id";
// 表示 GTask JSON 数据中的 prior_sibling_id 字段。
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id";
// 表示 GTask JSON 数据中的 results 字段。
public final static String GTASK_JSON_RESULTS = "results";
// 表示 GTask JSON 数据中的 source_list 字段。
public final static String GTASK_JSON_SOURCE_LIST = "source_list";
// 表示 GTask JSON 数据中的 tasks 字段。
public final static String GTASK_JSON_TASKS = "tasks";
// 表示 GTask JSON 数据中的 type 字段。
public final static String GTASK_JSON_TYPE = "type";
// 表示 GTask JSON 数据中的 type 字段的取值为 "GROUP"。
public final static String GTASK_JSON_TYPE_GROUP = "GROUP";
// 表示 GTask JSON 数据中的 type 字段的取值为 "TASK"。
public final static String GTASK_JSON_TYPE_TASK = "TASK";
// 表示 GTask JSON 数据中的 user 字段。
public final static String GTASK_JSON_USER = "user";
// 表示 MIUI 笔记应用程序文件夹的前缀。
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";
// 表示元数据中的 gtask_id 字段。
public final static String META_HEAD_GTASK_ID = "meta_gid";
// 表示元数据中的 note 字段。
public final static String META_HEAD_NOTE = "meta_note";
// 表示元数据中的 data 字段。
public final static String META_HEAD_DATA = "meta_data";
// 表示元数据笔记的名称。
public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE";
}

@ -24,158 +24,273 @@ import net.micode.notes.ui.NotesPreferenceActivity;
public class ResourceParser {
public static final int YELLOW = 0;
public static final int BLUE = 1;
public static final int WHITE = 2;
public static final int GREEN = 3;
public static final int RED = 4;
public static final int YELLOW = 0; // 表示黄色整数值为0。
public static final int BLUE = 1; // 表示蓝色整数值为1。
public static final int WHITE = 2; // 表示白色整数值为2。
public static final int GREEN = 3; // 表示绿色整数值为3。
public static final int RED = 4; // 表示红色整数值为4。
public static final int BG_DEFAULT_COLOR = YELLOW;
public static final int BG_DEFAULT_COLOR = YELLOW; // 使用YELLOW常量表示默认的背景颜色。
public static final int TEXT_SMALL = 0;
public static final int TEXT_MEDIUM = 1;
public static final int TEXT_LARGE = 2;
public static final int TEXT_SUPER = 3;
public static final int TEXT_SMALL = 0; // 表示小号文本大小整数值为0。
public static final int TEXT_MEDIUM = 1; // 表示中号文本大小整数值为1。
public static final int TEXT_LARGE = 2; // 表示大号文本大小整数值为2。
public static final int TEXT_SUPER = 3; // 表示超大号文本大小整数值为3。
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; // 使用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,
R.drawable.edit_green,
R.drawable.edit_red
/**
*
*/
private final static int[] BG_EDIT_RESOURCES = new int[]{
R.drawable.edit_yellow, // 黄色编辑背景资源
R.drawable.edit_blue, // 蓝色编辑背景资源
R.drawable.edit_white, // 白色编辑背景资源
R.drawable.edit_green, // 绿色编辑背景资源
R.drawable.edit_red // 红色编辑背景资源
};
private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] {
R.drawable.edit_title_yellow,
R.drawable.edit_title_blue,
R.drawable.edit_title_white,
R.drawable.edit_title_green,
R.drawable.edit_title_red
/**
*
*/
private final static int[] BG_EDIT_TITLE_RESOURCES = new int[]{
R.drawable.edit_title_yellow, // 黄色编辑标题背景资源
R.drawable.edit_title_blue, // 蓝色编辑标题背景资源
R.drawable.edit_title_white, // 白色编辑标题背景资源
R.drawable.edit_title_green, // 绿色编辑标题背景资源
R.drawable.edit_title_red // 红色编辑标题背景资源
};
/**
* id
*
* @param id id
* @return id
*/
public static int getNoteBgResource(int id) {
return BG_EDIT_RESOURCES[id];
}
/**
* id
*
* @param id id
* @return id
*/
public static int getNoteTitleBgResource(int id) {
return BG_EDIT_TITLE_RESOURCES[id];
}
}
/**
* ID
*
* @param context
* @return ID
*/
public static int getDefaultBgId(Context context) {
// 检查是否已设置自定义背景颜色
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
// 如果已设置自定义背景颜色,则返回随机选择的编辑背景资源 ID
return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length);
} else {
// 如果未设置自定义背景颜色,则返回默认的背景颜色 ID
return BG_DEFAULT_COLOR;
}
}
/**
*
*/
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,
R.drawable.list_red_up
/**
*
*/
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, // 绿色列表项第一行背景资源
R.drawable.list_red_up // 红色列表项第一行背景资源
};
private final static int [] BG_NORMAL_RESOURCES = new int [] {
R.drawable.list_yellow_middle,
R.drawable.list_blue_middle,
R.drawable.list_white_middle,
R.drawable.list_green_middle,
R.drawable.list_red_middle
/**
*
*/
private final static int[] BG_NORMAL_RESOURCES = new int[]{
R.drawable.list_yellow_middle, // 黄色列表项普通行背景资源
R.drawable.list_blue_middle, // 蓝色列表项普通行背景资源
R.drawable.list_white_middle, // 白色列表项普通行背景资源
R.drawable.list_green_middle, // 绿色列表项普通行背景资源
R.drawable.list_red_middle // 红色列表项普通行背景资源
};
private final static int [] BG_LAST_RESOURCES = new int [] {
R.drawable.list_yellow_down,
R.drawable.list_blue_down,
R.drawable.list_white_down,
R.drawable.list_green_down,
R.drawable.list_red_down,
/**
*
*/
private final static int[] BG_LAST_RESOURCES = new int[]{
R.drawable.list_yellow_down, // 黄色列表项最后一行背景资源
R.drawable.list_blue_down, // 蓝色列表项最后一行背景资源
R.drawable.list_white_down, // 白色列表项最后一行背景资源
R.drawable.list_green_down, // 绿色列表项最后一行背景资源
R.drawable.list_red_down // 红色列表项最后一行背景资源
};
private final static int [] BG_SINGLE_RESOURCES = new int [] {
R.drawable.list_yellow_single,
R.drawable.list_blue_single,
R.drawable.list_white_single,
R.drawable.list_green_single,
R.drawable.list_red_single
/**
*
*/
private final static int[] BG_SINGLE_RESOURCES = new int[]{
R.drawable.list_yellow_single, // 黄色列表项单行背景资源
R.drawable.list_blue_single, // 蓝色列表项单行背景资源
R.drawable.list_white_single, // 白色列表项单行背景资源
R.drawable.list_green_single, // 绿色列表项单行背景资源
R.drawable.list_red_single // 红色列表项单行背景资源
};
/**
* ID
*
* @param id ID
* @return ID
*/
public static int getNoteBgFirstRes(int id) {
return BG_FIRST_RESOURCES[id];
}
/**
* ID
*
* @param id ID
* @return ID
*/
public static int getNoteBgLastRes(int id) {
return BG_LAST_RESOURCES[id];
}
/**
* ID
*
* @param id ID
* @return ID
*/
public static int getNoteBgSingleRes(int id) {
return BG_SINGLE_RESOURCES[id];
}
/**
* ID
*
* @param id ID
* @return ID
*/
public static int getNoteBgNormalRes(int id) {
return BG_NORMAL_RESOURCES[id];
}
/**
*
*
* @return
*/
public static int getFolderBgRes() {
return R.drawable.list_folder;
}
}
/**
*
*/
public static class WidgetBgResources {
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
*/
private final static int[] BG_2X_RESOURCES = new int[]{
R.drawable.widget_2x_yellow, // 黄色2x小部件背景资源
R.drawable.widget_2x_blue, // 蓝色2x小部件背景资源
R.drawable.widget_2x_white, // 白色2x小部件背景资源
R.drawable.widget_2x_green, // 绿色2x小部件背景资源
R.drawable.widget_2x_red // 红色2x小部件背景资源
};
/**
* ID 2x
*
* @param id ID2x
* @return ID 2x
*/
public static int getWidget2xBgResource(int id) {
return BG_2X_RESOURCES[id];
}
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
*/
private final static int[] BG_4X_RESOURCES = new int[]{
R.drawable.widget_4x_yellow, // 黄色4x小部件背景资源
R.drawable.widget_4x_blue, // 蓝色4x小部件背景资源
R.drawable.widget_4x_white, // 白色4x小部件背景资源
R.drawable.widget_4x_green, // 绿色4x小部件背景资源
R.drawable.widget_4x_red // 红色4x小部件背景资源
};
/**
* ID 4x
*
* @param id ID4x
* @return ID 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
/**
*
*/
private final static int[] TEXTAPPEARANCE_RESOURCES = new int[]{
R.style.TextAppearanceNormal, // 普通文本外观资源
R.style.TextAppearanceMedium, // 中等文本外观资源
R.style.TextAppearanceLarge, // 大号文本外观资源
R.style.TextAppearanceSuper // 超大号文本外观资源
};
/**
* ID
*
* @param id ID
* @return ID
*/
public static int getTexAppearanceResource(int id) {
/**
* HACKME: Fix bug of store the resource id in shared preference.
* The id may larger than the length of resources, in this case,
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
* HACKME: ID bug
* ID BG_DEFAULT_FONT_SIZE
*/
if (id >= TEXTAPPEARANCE_RESOURCES.length) {
return BG_DEFAULT_FONT_SIZE;
return BG_DEFAULT_FONT_SIZE; // 这里需要定义 BG_DEFAULT_FONT_SIZE
}
return TEXTAPPEARANCE_RESOURCES[id];
}
/**
*
*
* @return
*/
public static int getResourcesSize() {
return TEXTAPPEARANCE_RESOURCES.length;
}
}
}

Loading…
Cancel
Save