Compare commits

...

45 Commits

Author SHA1 Message Date
pkjy9bv5t e18ae286bb Merge pull request '文档' (#19) from su_branch into main
2 years ago
STRIV1 6470e130d1 1
2 years ago
STRIV1 d27bff7b39 文档
2 years ago
STRIV1 9d7401b01b 注释
2 years ago
STRIV1 fcba4a819e 1
2 years ago
STRIV1 af30a970a5 1
2 years ago
prmw2qx5j daf8db6e87 Merge pull request '1' (#15) from xia_branch into main
2 years ago
brook f716b94f1e 1
2 years ago
STRIV1 158a673006 注释
2 years ago
STRIV1 155d0f59db 1
2 years ago
prmw2qx5j 5a9b11dbf1 1
2 years ago
brook 7a6e77b5af 1
2 years ago
prmw2qx5j 46519fc572 1
2 years ago
pfuxnwlgc 4e1feafae0 Merge pull request '精读' (#10) from develop into Master
2 years ago
pfuxnwlgc 0f091d4f41 Merge pull request 'ui包新增类' (#9) from develop into main
2 years ago
prmw2qx5j 6d7b66f39f Delete 'doc/~$模板-开源软件泛读、标注和维护报告文档.docx'
2 years ago
prmw2qx5j d01a4fb86a 质量分报告
2 years ago
brook c5d457e679 1
2 years ago
pfuxnwlgc fc12ea5e31 Merge pull request 'ui包部分精读' (#7) from develop into main
2 years ago
pfuxnwlgc 166444c13a Merge pull request 'NoteEditText 精读完毕' (#6) from develop into main
2 years ago
pfuxnwlgc c01d839827 Merge pull request 'NoteEditActivity 类 精读完毕' (#5) from develop into main
2 years ago
pfuxnwlgc eca2e81161 Merge pull request 'NoteEditActivity精读' (#4) from develop into main
2 years ago
prmw2qx5j 4ce50a9387 Merge pull request 'gtask中data' (#3) from xia_branch into main
2 years ago
brook 60a672a037 modified
2 years ago
brook 04a9cdd10b 课件
2 years ago
brook 01844c955f Merge branch 'develop' of https://bdgit.educoder.net/pfuxnwlgc/git-test into xia_branch
2 years ago
brook dc1b1e9221 Merge branch 'main' of https://bdgit.educoder.net/pfuxnwlgc/git-test into xia_branch
2 years ago
Ryuki 218b5ec359 doc
2 years ago
Ryuki a3fa1e87ec doc
2 years ago
brook 18e40d5795 1
2 years ago
pfuxnwlgc 8b5c391787 Merge pull request '1' (#2) from develop into main
2 years ago
pfuxnwlgc cb00d824cc Delete '.gradle/8.0/checksums/checksums.lock'
2 years ago
pfuxnwlgc e2b9b197e6 Delete 'gradlew'
2 years ago
brook b1ed93660a 1
2 years ago
brook c9a46d7fa7 1
2 years ago
prmw2qx5j d79324abcb Update MetaData.java
2 years ago
prmw2qx5j cd23cc9c19 Update MetaData.java
2 years ago
brook d025c48105 1
2 years ago
brook 796555d7a3 11
2 years ago
brook 194f8e6bd8 Merge branch 'main' of https://bdgit.educoder.net/pfuxnwlgc/git-test into xia_branch
2 years ago
brook 179e51b7aa up
2 years ago
brook 2e904a7d58 de
2 years ago
brook de942dbacc Merge branch 'xia_branch' of https://bdgit.educoder.net/pfuxnwlgc/git-test into xia_branch
2 years ago
brook 75bc262206 11
2 years ago
pfuxnwlgc 34333510e6 Merge pull request 'src insert' (#1) from develop into main
2 years ago

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -26,29 +26,54 @@ 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) {
try {
//对函数块进行注释
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
/*
* metaInfojsonobject
*/
} 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);
@ -58,6 +83,9 @@ public class MetaData extends Task {
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
} catch (JSONException e) {
Log.w(TAG, "failed to get related gid");
/*
*
*/
mRelatedGid = null;
}
}
@ -69,14 +97,33 @@ public class MetaData extends Task {
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,32 +20,38 @@ import android.database.Cursor;
import org.json.JSONObject;
/*
*
* abstract
*/
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() {
mGid = null;

@ -14,8 +14,21 @@
* limitations under the License.
*/
/*
* Description便sqlnotedatanote
* SqlData
*/
package net.micode.notes.gtask.data;
/*
*
*
*
* Made By CuiCan
*/
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
@ -36,15 +49,30 @@ import org.json.JSONObject;
public class SqlData {
/*
* TAG
* getSimpleName ()
*/
private static final String TAG = SqlData.class.getSimpleName();
private static final int INVALID_ID = -99999;
private static final int INVALID_ID = -99999;//为mDataId置初始值-99999
/*
* NotesDataColumn
*/
// 集合了interface DataColumns中所有SF常量
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;
public static final int DATA_MIME_TYPE_COLUMN = 1;
@ -56,7 +84,7 @@ public class SqlData {
public static final int DATA_CONTENT_DATA_3_COLUMN = 4;
private ContentResolver mContentResolver;
//判断是否直接用Content生成是为true否则为false
private boolean mIsCreate;
private long mDataId;
@ -71,6 +99,13 @@ public class SqlData {
private ContentValues mDiffDataValues;
/*
*
* mContentResolverContentProvider
* mIsCreate
*/
public SqlData(Context context) {
mContentResolver = context.getContentResolver();
mIsCreate = true;
@ -82,6 +117,13 @@ public class SqlData {
mDiffDataValues = new ContentValues();
}
/*
*
* mContentResolverContentProvider
* mIsCreate
*/
public SqlData(Context context, Cursor c) {
mContentResolver = context.getContentResolver();
mIsCreate = false;
@ -89,6 +131,12 @@ public class SqlData {
mDiffDataValues = new ContentValues();
}
/*
*
*
*/
private void loadFromCursor(Cursor c) {
mDataId = c.getLong(DATA_ID_COLUMN);
mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);
@ -97,7 +145,13 @@ public class SqlData {
mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);
}
/*
*
*/
public void setContent(JSONObject js) throws JSONException {
//如果传入的JSONObject对象中有DataColumns.ID这一项则设置否则设为INVALID_ID
long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID;
if (mIsCreate || mDataId != dataId) {
mDiffDataValues.put(DataColumns.ID, dataId);
@ -130,11 +184,18 @@ 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对象。并将相关数据放入其中并返回。
JSONObject js = new JSONObject();
js.put(DataColumns.ID, mDataId);
js.put(DataColumns.MIME_TYPE, mDataMimeType);
@ -143,7 +204,9 @@ public class SqlData {
js.put(DataColumns.DATA3, mDataContentData3);
return js;
}
/*
* commit
*/
public void commit(long noteId, boolean validateVersion, long version) {
if (mIsCreate) {
@ -183,6 +246,12 @@ public class SqlData {
mIsCreate = false;
}
/*
* id
*
*/
public long getId() {
return mDataId;
}

@ -13,7 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Description便sqldatanotedata
* SqlDataSqlNote
*/
package net.micode.notes.gtask.data;
import android.appwidget.AppWidgetManager;
@ -37,12 +40,21 @@ import org.json.JSONObject;
import java.util.ArrayList;
/*
*
*
*/
public class SqlNote {
private static final String TAG = SqlNote.class.getSimpleName();
/*
* TAG
* getSimpleName ()
*/
private static final int INVALID_ID = -99999;
// 集合了interface NoteColumns中所有SF常量17个
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 +63,7 @@ public class SqlNote {
NoteColumns.LOCAL_MODIFIED, NoteColumns.ORIGIN_PARENT_ID, NoteColumns.GTASK_ID,
NoteColumns.VERSION
};
//以下设置17个列的编号
public static final int ID_COLUMN = 0;
public static final int ALERTED_DATE_COLUMN = 1;
@ -85,7 +97,7 @@ public class SqlNote {
public static final int GTASK_ID_COLUMN = 15;
public static final int VERSION_COLUMN = 16;
//以下定义了17个内部的变量其中12个可以由content中获得5个需要初始化为0或者new
private Context mContext;
private ContentResolver mContentResolver;
@ -121,7 +133,12 @@ public class SqlNote {
private ContentValues mDiffNoteValues;
private ArrayList<SqlData> mDataList;
/*
*
* mIsCreate
*/
//构造函数只有context对所有的变量进行初始化
public SqlNote(Context context) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -129,9 +146,9 @@ public class SqlNote {
mId = INVALID_ID;
mAlertDate = 0;
mBgColorId = ResourceParser.getDefaultBgId(context);
mCreatedDate = System.currentTimeMillis();
mCreatedDate = System.currentTimeMillis();//调用系统函数获得创建时间
mHasAttachment = 0;
mModifiedDate = System.currentTimeMillis();
mModifiedDate = System.currentTimeMillis();//最后一次修改时间初始化为创建时间
mParentId = 0;
mSnippet = "";
mType = Notes.TYPE_NOTE;
@ -142,6 +159,12 @@ public class SqlNote {
mDiffNoteValues = new ContentValues();
mDataList = new ArrayList<SqlData>();
}
/*
*
* mIsCreate
*/
//构造函数有context和一个数据库的cursor多数变量通过cursor指向的一条记录直接进行初始化
public SqlNote(Context context, Cursor c) {
mContext = context;
@ -153,7 +176,10 @@ public class SqlNote {
loadDataContent();
mDiffNoteValues = new ContentValues();
}
/*
*
* mIsCreate
*/
public SqlNote(Context context, long id) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -173,9 +199,10 @@ public class SqlNote {
new String[] {
String.valueOf(id)
}, null);
if (c != null) {
if (c != null) {//通过id获得对应的ContentResolver中的cursor
c.moveToNext();
loadFromCursor(c);
loadFromCursor(c);//然后加载数据进行初始化,这样函数
//SqlNote(Context context, long id)与SqlNote(Context context, long id)的实现方式基本相同
} else {
Log.w(TAG, "loadFromCursor: cursor = null");
}
@ -184,8 +211,11 @@ public class SqlNote {
c.close();
}
}
/*
*
*/
private void loadFromCursor(Cursor c) {
//直接从一条记录中的获得以下变量的初始值
mId = c.getLong(ID_COLUMN);
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
mBgColorId = c.getInt(BG_COLOR_ID_COLUMN);
@ -199,7 +229,9 @@ public class SqlNote {
mWidgetType = c.getInt(WIDGET_TYPE_COLUMN);
mVersion = c.getLong(VERSION_COLUMN);
}
/*
* content
* */
private void loadDataContent() {
Cursor c = null;
mDataList.clear();
@ -225,7 +257,8 @@ public class SqlNote {
c.close();
}
}
/*
* content*/
public boolean setContent(JSONObject js) {
try {
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
@ -359,6 +392,8 @@ public class SqlNote {
return true;
}
/*
* contentnote*/
public JSONObject getContent() {
try {
JSONObject js = new JSONObject();
@ -406,40 +441,49 @@ public class SqlNote {
}
return null;
}
/*
* idid*/
public void setParentId(long id) {
mParentId = id;
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
}
/*
* idGtaskid*/
public void setGtaskId(String gid) {
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
}
/*
* idid*/
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;
}
/*
* idid*/
public long getParentId() {
return mParentId;
}
/*
* 便*/
public String getSnippet() {
return mSnippet;
}
/*
* 便*/
public boolean isNoteType() {
return mType == Notes.TYPE_NOTE;
}
/*
* commit*/
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 JSONObject mMetaInfo;
private JSONObject mMetaInfo;//将在实例中存储数据的类型
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;
}

@ -31,11 +31,11 @@ import java.util.ArrayList;
public class TaskList extends Node {
private static final String TAG = TaskList.class.getSimpleName();
private static final String TAG = TaskList.class.getSimpleName();//tag标记
private int mIndex;
private int mIndex;//当前TaskList的指针
private ArrayList<Task> mChildren;
private ArrayList<Task> mChildren;//类中主要的保存数据的单元用来实现一个以Task为元素的ArrayList
public TaskList() {
super();
@ -43,6 +43,7 @@ public class TaskList extends Node {
mIndex = 1;
}
//生成并返回一个包含了一定数据的JSONObject实体
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
@ -74,6 +75,8 @@ public class TaskList extends Node {
return js;
}
//生成并返回一个包含了一定数据的JSONObject实体
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
@ -216,6 +219,8 @@ public class TaskList extends Node {
return SYNC_ACTION_ERROR;
}
//功能获得TaskList的大小即mChildren的大小
public int getChildTaskCount() {
return mChildren.size();
}
@ -233,7 +238,7 @@ public class TaskList extends Node {
}
return ret;
}
//功能:在当前任务表的指定位置添加新的任务
public boolean addChildTask(Task task, int index) {
if (index < 0 || index > mChildren.size()) {
Log.e(TAG, "add child task: invalid index");
@ -260,6 +265,7 @@ public class TaskList extends Node {
return true;
}
// 功能删除TaskList中的一个Task
public boolean removeChildTask(Task task) {
boolean ret = false;
int index = mChildren.indexOf(task);
@ -281,6 +287,7 @@ public class TaskList extends Node {
return ret;
}
//功能将当前TaskList中含有的某个Task移到index位置
public boolean moveChildTask(Task task, int index) {
if (index < 0 || index >= mChildren.size()) {
@ -298,7 +305,10 @@ public class TaskList extends Node {
return true;
return (removeChildTask(task) && addChildTask(task, index));
}
//利用已实现好的功能完成当下功能;
// 功能按gid寻找Task
public Task findChildTaskByGid(String gid) {
for (int i = 0; i < mChildren.size(); i++) {
Task t = mChildren.get(i);
@ -308,11 +318,13 @@ public class TaskList extends Node {
}
return null;
}
//功能返回指定Task的index
public int getChildTaskIndex(Task task) {
return mChildren.indexOf(task);
}
//功能返回指定index的Task
public Task getChildTaskByIndex(int index) {
if (index < 0 || index >= mChildren.size()) {
Log.e(TAG, "getTaskByIndex: invalid index");
@ -321,6 +333,8 @@ public class TaskList extends Node {
return mChildren.get(index);
}
//功能返回指定index的Task
public Task getChilTaskByGid(String gid) {
for (Task task : mChildren) {
if (task.getGid().equals(gid))

@ -14,14 +14,24 @@
* limitations under the License.
*/
// 支持小米便签运行过程中的运行异常处理
package net.micode.notes.gtask.exception;
public class ActionFailureException extends RuntimeException {
private static final long serialVersionUID = 4425249765923293627L;
/*
* serialVersionUIDjava
* serialVersionUID
*/
public ActionFailureException() {
super();
}
/*
* JAVA使superthis.
* new
*/
public ActionFailureException(String paramString) {
super(paramString);

@ -13,11 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Description便
*/
package net.micode.notes.gtask.exception;
public class NetworkFailureException extends Exception {
private static final long serialVersionUID = 2107610287180234136L;
// serialVersionUID作用是序列化时保持版本的兼容性即在版本升级时反序列化仍保持对象的唯一性。
/*
* JAVA使superthis.
* new
*/
public NetworkFailureException() {
super();

@ -28,6 +28,13 @@ import net.micode.notes.R;
import net.micode.notes.ui.NotesListActivity;
import net.micode.notes.ui.NotesPreferenceActivity;
/*GTask
*
* private void showNotification(int tickerId, String content)
* protected Integer doInBackground(Void... unused) 线
* protected void onProgressUpdate(String... progress) 使 线
* protected void onPostExecute(Integer result) Handler UI使doInBackground UI
*/
public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
@ -57,7 +64,7 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
mTaskManager.cancelSync();
}
public void publishProgess(String message) {
public void publishProgess(String message) {// 发布进度单位系统将会调用onProgressUpdate()方法更新这些值
publishProgress(new String[] {
message
});
@ -66,30 +73,29 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
private void showNotification(int tickerId, String content) {
Notification notification = new Notification(R.drawable.notification, mContext
.getString(tickerId), System.currentTimeMillis());
notification.defaults = Notification.DEFAULT_LIGHTS;
notification.defaults = Notification.DEFAULT_LIGHTS;// 调用系统自带灯光
notification.flags = Notification.FLAG_AUTO_CANCEL;
PendingIntent pendingIntent;
if (tickerId != R.string.ticker_success) {
pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext,
NotesPreferenceActivity.class), 0);
NotesPreferenceActivity.class), 0);//如果同步不成功那么从系统取得一个用于启动一个NotesPreferenceActivity的PendingIntent对象
} else {
pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext,
NotesListActivity.class), 0);
NotesListActivity.class), 0);//如果同步成功那么从系统取得一个用于启动一个NotesListActivity的PendingIntent对象
}
notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content,
pendingIntent);
mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);
// notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content,
// pendingIntent);
mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);//通过NotificationManager对象的notify方法来执行一个notification的消息
}
@Override
// @Override
protected Integer doInBackground(Void... unused) {
publishProgess(mContext.getString(R.string.sync_progress_login, NotesPreferenceActivity
.getSyncAccountName(mContext)));
return mTaskManager.sync(mContext, this);
return mTaskManager.sync(mContext, this); //进行后台同步具体操作
}
@Override
// @Override
protected void onProgressUpdate(String... progress) {
showNotification(R.string.ticker_syncing, progress[0]);
if (mContext instanceof GTaskSyncService) {
@ -97,8 +103,8 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
}
}
@Override
protected void onPostExecute(Integer result) {
//@Override
protected void onPostExecute(Integer result) {//用于在执行完后台任务后更新UI,显示结果
if (result == GTaskManager.STATE_SUCCESS) {
showNotification(R.string.ticker_success, mContext.getString(
R.string.success_sync_account, mTaskManager.getSyncAccount()));

@ -60,7 +60,10 @@ import java.util.zip.GZIPInputStream;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
/*
* GTASKGTASK
* 使accountManager JSONObject HttpParams authToken Gid
*/
public class GTaskClient {
private static final String TAG = GTaskClient.class.getSimpleName();
@ -102,6 +105,10 @@ public class GTaskClient {
mUpdateArray = null;
}
/*
* 使 getInstance()
* mInstance
*/
public static synchronized GTaskClient getInstance() {
if (mInstance == null) {
mInstance = new GTaskClient();

@ -87,9 +87,9 @@ public class GTaskManager {
private HashMap<Long, String> mNidToGid;
private GTaskManager() {
mSyncing = false;
mCancelled = false;
private GTaskManager() { //对象初始化函数
mSyncing = false; //正在同步,flase代表未执行
mCancelled = false; //全局标识flase代表可以执行
mGTaskListHashMap = new HashMap<String, TaskList>();
mGTaskHashMap = new HashMap<String, Node>();
mMetaHashMap = new HashMap<String, MetaData>();
@ -113,7 +113,7 @@ public class GTaskManager {
public int sync(Context context, GTaskASyncTask asyncTask) {
if (mSyncing) {
Log.d(TAG, "Sync is in progress");
Log.d(TAG, "Sync is in progress");//创建日志文件调试信息debug
return STATE_SYNC_IN_PROGRESS;
}
mContext = context;
@ -128,7 +128,7 @@ public class GTaskManager {
mNidToGid.clear();
try {
GTaskClient client = GTaskClient.getInstance();
GTaskClient client = GTaskClient.getInstance();//getInstance即为创建一个实例,client--客户机
client.resetUpdateArray();
// login google task
@ -140,7 +140,7 @@ public class GTaskManager {
// get the task list from google
asyncTask.publishProgess(mContext.getString(R.string.sync_progress_init_list));
initGTaskList();
initGTaskList(); //获取Google上的JSONtasklist转为本地TaskList
// do content sync work
asyncTask.publishProgess(mContext.getString(R.string.sync_progress_syncing));
@ -168,12 +168,17 @@ public class GTaskManager {
return mCancelled ? STATE_SYNC_CANCELLED : STATE_SUCCESS;
}
/*
*GtaskListGoogleJSONtasklistTaskList
*mMetaListmGTaskListHashMapmGTaskHashMap
*/
private void initGTaskList() throws NetworkFailureException {
if (mCancelled)
return;
GTaskClient client = GTaskClient.getInstance();
try {
JSONArray jsTaskLists = client.getTaskLists();
JSONArray jsTaskLists = client.getTaskLists(); //getInstance即为创建一个实例client应指远端客户机
// init meta list first
mMetaList = null;
@ -247,6 +252,8 @@ public class GTaskManager {
}
}
//功能:本地内容同步操作
private void syncContent() throws NetworkFailureException {
int syncType;
Cursor c = null;

@ -42,6 +42,8 @@ public class GTaskSyncService extends Service {
private static String mSyncProgress = "";
////开始一个同步的工作
private void startSync() {
if (mSyncTask == null) {
mSyncTask = new GTaskASyncTask(this, new GTaskASyncTask.OnCompleteListener() {
@ -65,13 +67,14 @@ public class GTaskSyncService extends Service {
@Override
public void onCreate() {
mSyncTask = null;
}
}///初始化一个service
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Bundle bundle = intent.getExtras();
if (bundle != null && bundle.containsKey(ACTION_STRING_NAME)) {
switch (bundle.getInt(ACTION_STRING_NAME, ACTION_INVALID)) {
//两种情况,开始同步或者取消同步
case ACTION_START_SYNC:
startSync();
break;
@ -81,7 +84,7 @@ public class GTaskSyncService extends Service {
default:
break;
}
return START_STICKY;
return START_STICKY;//等待新的intent来是这个service继续运行
}
return super.onStartCommand(intent, flags, startId);
}

@ -42,11 +42,11 @@ public class Note {
* Create a new note id for adding a new note to databases
*/
public static synchronized long getNewNoteId(Context context, long folderId) {
// Create a new note in the database
//为给定文件夹生成新的笔记ID
ContentValues values = new ContentValues();
long createdTime = System.currentTimeMillis();
values.put(NoteColumns.CREATED_DATE, createdTime);
values.put(NoteColumns.MODIFIED_DATE, createdTime);
values.put(NoteColumns.CREATED_DATE, createdTime);//创建日期
values.put(NoteColumns.MODIFIED_DATE, createdTime);//修改日期
values.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
values.put(NoteColumns.LOCAL_MODIFIED, 1);
values.put(NoteColumns.PARENT_ID, folderId);
@ -71,6 +71,7 @@ public class Note {
}
public void setNoteValue(String key, String value) {
//此方法设置笔记的值,标记为本地修改
mNoteDiffValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
@ -79,11 +80,12 @@ public class Note {
public void setTextData(String key, String value) {
mNoteData.setTextData(key, value);
}
//为笔记设置文本数据。
public void setTextDataId(long id) {
mNoteData.setTextDataId(id);
}
//setTextDataId、getTextDataId、setCallDataId、setCallData 这些方法处理与笔记相关的文本和通话信息的ID和数据的设置和获取。
public long getTextDataId() {
return mNoteData.mTextDataId;
}
@ -99,7 +101,7 @@ public class Note {
public boolean isLocalModified() {
return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified();
}
//根据值和数据的差异检查笔记是否具有本地修改。
public boolean syncNote(Context context, long noteId) {
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId);
@ -108,6 +110,8 @@ public class Note {
if (!isLocalModified()) {
return true;
}
//尝试将笔记与提供的上下文和笔记ID同步。
//如果笔记ID小于或等于0或者没有本地修改则返回true。
/**
* In theory, once data changed, the note should be updated on {@link NoteColumns#LOCAL_MODIFIED} and
@ -147,17 +151,19 @@ public class Note {
mTextDataId = 0;
mCallDataId = 0;
}
//初始化 mTextDataValues 和 mCallDataValues 为 ContentValues 对象,用于存储文本数据和通话数据。
//初始化 mTextDataId 和 mCallDataId 为 0。
boolean isLocalModified() {
return mTextDataValues.size() > 0 || mCallDataValues.size() > 0;
}
//检查文本或通话数据是否有本地修改
void setTextDataId(long id) {
if(id <= 0) {
throw new IllegalArgumentException("Text data id should larger than 0");
}
mTextDataId = id;
}
//设置文本数据的ID如果提供的ID小于等于0报告异常
void setCallDataId(long id) {
if (id <= 0) {
@ -165,52 +171,57 @@ public class Note {
}
mCallDataId = id;
}
//设置通话数据的键值对,并标记笔记为本地修改,更新修改日期
void setCallData(String key, String value) {
mCallDataValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
//设置文本数据的键值对,并标记笔记为本地修改,更新修改日期
void setTextData(String key, String value) {
mTextDataValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
//将数据推送到ContentResolver的方法
Uri pushIntoContentResolver(Context context, long noteId) {
/**
* Check for safety
*/
//检查noteID的有效性如果小于等于0抛出IllegalArgumentException
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId);
}
//用于保存ContentProvider操作列表
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
ContentProviderOperation.Builder builder = null;
//处理文本数据的操作
if(mTextDataValues.size() > 0) {
//设置文本数据的关联noteID
mTextDataValues.put(DataColumns.NOTE_ID, noteId);
// 如果mTextDataId为0表示需要插入新的文本数据
if (mTextDataId == 0) {
mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE);
//插入数据并获取新的Uri
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mTextDataValues);
try {
// 解析Uri中的数据获取新插入数据的id并设置给mTextDataId
setTextDataId(Long.valueOf(uri.getPathSegments().get(1)));
} catch (NumberFormatException e) {
// 插入数据失败,记录错误日志并清空数据
Log.e(TAG, "Insert new text data fail with noteId" + noteId);
mTextDataValues.clear();
return null;
}
} else {
// mTextDataId不为0表示需要更新已存在的文本数据
builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mTextDataId));
builder.withValues(mTextDataValues);
operationList.add(builder.build());
}
// 清空文本数据,以便下一次使用
mTextDataValues.clear();
}
// 处理通话数据的操作,逻辑类似于文本数据
if(mCallDataValues.size() > 0) {
mCallDataValues.put(DataColumns.NOTE_ID, noteId);
if (mCallDataId == 0) {
@ -232,17 +243,20 @@ public class Note {
}
mCallDataValues.clear();
}
// 如果有待执行的操作将它们应用到ContentResolver
if (operationList.size() > 0) {
try {
ContentProviderResult[] results = context.getContentResolver().applyBatch(
Notes.AUTHORITY, operationList);
// 返回插入或更新后的笔记的Uri如果操作失败则返回null
return (results == null || results.length == 0 || results[0] == null) ? null
: ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId);
} catch (RemoteException e) {
// 捕获远程异常并记录错误日志
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
return null;
} catch (OperationApplicationException e) {
// 捕获操作应用异常并记录错误日志
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
return null;
}
@ -251,3 +265,5 @@ public class Note {
}
}
}

@ -128,9 +128,11 @@ public class WorkingNote {
Cursor cursor = mContext.getContentResolver().query(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null,
null, null);
// 检查查询结果是否为空
if (cursor != null) {
// 移动到查询结果的第一行(如果有多行数据)
if (cursor.moveToFirst()) {
// 从查询结果中获取笔记的相关信息并存储到相应的成员变量中
mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);
mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN);
mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN);
@ -138,37 +140,49 @@ public class WorkingNote {
mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN);
mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
}
// 关闭查询结果的游标
cursor.close();
} else {
// 如果查询结果为空,则输出错误日志并抛出异常
Log.e(TAG, "No note with id:" + mNoteId);
throw new IllegalArgumentException("Unable to find note with id " + mNoteId);
}
// 调用loadNoteData()方法加载笔记的其他数据
loadNoteData();
}
private void loadNoteData() {
// 通过内容解析器(ContentResolver)查询笔记的数据信息
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
DataColumns.NOTE_ID + "=?", new String[] {
String.valueOf(mNoteId)
}, null);
// 检查查询结果是否为空
if (cursor != null) {
// 移动到查询结果的第一行(如果有多行数据)
if (cursor.moveToFirst()) {
do {
// 获取数据类型
String type = cursor.getString(DATA_MIME_TYPE_COLUMN);
// 根据数据类型进行不同的处理
if (DataConstants.NOTE.equals(type)) {
// 如果是笔记类型的数据,获取内容和模式,并设置到相应的成员变量中
mContent = cursor.getString(DATA_CONTENT_COLUMN);
mMode = cursor.getInt(DATA_MODE_COLUMN);
mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN));
} else if (DataConstants.CALL_NOTE.equals(type)) {
// 如果是通话笔记类型的数据设置通话数据ID到相应的成员变量中
mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN));
} else {
// 如果是未知类型的数据,输出调试信息
Log.d(TAG, "Wrong note type with type:" + type);
}
} while (cursor.moveToNext());
}
// 关闭查询结果的游标
cursor.close();
} else {
// 如果查询结果为空,则输出错误日志并抛出异常
Log.e(TAG, "No data with id:" + mNoteId);
throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId);
}
@ -188,27 +202,32 @@ public class WorkingNote {
}
public synchronized boolean saveNote() {
// 检查笔记是否值得保存
if (isWorthSaving()) {
// 检查笔记是否存在于数据库中
if (!existInDatabase()) {
// 如果笔记在数据库中不存在尝试创建一个新的笔记ID
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
// 如果创建新的笔记ID失败输出错误日志并返回保存失败
Log.e(TAG, "Create new note fail with id:" + mNoteId);
return false;
}
}
// 同步笔记信息到数据库中
mNote.syncNote(mContext, mNoteId);
/**
* Update widget content if there exist any widget of this note
*/
// 如果存在与该笔记相关的小部件,并且小部件类型有效,并且存在小部件设置状态监听器,则通知小部件内容已更改
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE
&& mNoteSettingStatusListener != null) {
mNoteSettingStatusListener.onWidgetChanged();
}
return true;
return true;//保存成功
} else {
return false;
return false;//保存失败
}
}
@ -230,38 +249,55 @@ public class WorkingNote {
}
public void setAlertDate(long date, boolean set) {
// 检查传入的日期是否与当前提醒日期不同
if (date != mAlertDate) {
// 如果不同,更新当前提醒日期为传入的日期,并通过 mNote 对象将更新后的提醒日期同步到数据库中
mAlertDate = date;
mNote.setNoteValue(NoteColumns.ALERTED_DATE, String.valueOf(mAlertDate));
}
// 检查是否存在笔记设置状态监听器
if (mNoteSettingStatusListener != null) {
// 如果存在,调用监听器的 onClockAlertChanged 方法,通知提醒日期已更改,并传递新的日期和开关状态
mNoteSettingStatusListener.onClockAlertChanged(date, set);
}
}
public void markDeleted(boolean mark) {
// 将笔记的删除状态更新为传入的标记值
mIsDeleted = mark;
// 检查是否存在与该笔记相关的小部件,并且小部件类型有效,并且存在笔记设置状态监听器
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) {
// 如果条件满足,调用监听器的 onWidgetChanged 方法,通知小部件内容已更改
mNoteSettingStatusListener.onWidgetChanged();
}
}
public void setBgColorId(int id) {
// 检查传入的颜色ID是否与当前背景颜色ID不同
if (id != mBgColorId) {
// 如果不同更新当前背景颜色ID为传入的颜色ID
mBgColorId = id;
// 检查是否存在笔记设置状态监听器
if (mNoteSettingStatusListener != null) {
// 如果存在,调用监听器的 onBackgroundColorChanged 方法,通知背景颜色已更改
mNoteSettingStatusListener.onBackgroundColorChanged();
}
// 通过 mNote 对象将更新后的背景颜色ID同步到数据库中
mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id));
}
}
public void setCheckListMode(int mode) {
if (mMode != mode) {
// 如果不同,更新当前模式为传入的模式
// 检查是否存在笔记设置状态监听器
if (mNoteSettingStatusListener != null) {
// 如果存在,调用监听器的 onCheckListModeChanged 方法,通知检查清单模式已更改,并传递旧模式和新模式
mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode);
}
// 将当前模式更新为传入的模式,并通过 mNote 对象将更新后的模式同步到数据库中
mMode = mode;
mNote.setTextData(TextNote.MODE, String.valueOf(mMode));
}
@ -275,15 +311,23 @@ public class WorkingNote {
}
public void setWidgetId(int id) {
// 检查传入的小部件类型是否与当前小部件类型不同
if (id != mWidgetId) {
// 如果不同,更新当前小部件类型为传入的小部件类型
mWidgetId = id;
// 通过 mNote 对象将更新后的小部件类型同步到数据库中
mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId));
}
}
public void setWorkingText(String text) {
// 检查传入的文本内容是否与当前内容不同
if (!TextUtils.equals(mContent, text)) {
// 如果不同,更新当前内容为传入的文本内容
mContent = text;
// 通过 mNote 对象将更新后的文本内容同步到数据库中
mNote.setTextData(DataColumns.CONTENT, mContent);
}
}

@ -1,18 +1,3 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.tool;
@ -38,7 +23,7 @@ import java.io.PrintStream;
public class BackupUtils {
private static final String TAG = "BackupUtils";
// Singleton stuff
// 单例模式
private static BackupUtils sInstance;
public static synchronized BackupUtils getInstance(Context context) {
@ -52,15 +37,15 @@ public class BackupUtils {
* Following states are signs to represents backup or restore
* status
*/
// Currently, the sdcard is not mounted
// 当前SD卡未挂载
public static final int STATE_SD_CARD_UNMOUONTED = 0;
// The backup file not exist
// 备份文件不存在
public static final int STATE_BACKUP_FILE_NOT_EXIST = 1;
// The data is not well formated, may be changed by other programs
//数据格式不正确,可能已被其他程序更改
public static final int STATE_DATA_DESTROIED = 2;
// Some run-time exception which causes restore or backup fails
// 一些运行时异常导致还原或备份失败
public static final int STATE_SYSTEM_ERROR = 3;
// Backup or restore success
// 备份或者还原成功
public static final int STATE_SUCCESS = 4;
private TextExport mTextExport;
@ -137,10 +122,10 @@ public class BackupUtils {
}
/**
* Export the folder identified by folder id to text
* id
*/
private void exportFolderToText(String folderId, PrintStream ps) {
// Query notes belong to this folder
// 查询属于此文件夹的便签
Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] {
folderId
@ -149,11 +134,11 @@ public class BackupUtils {
if (notesCursor != null) {
if (notesCursor.moveToFirst()) {
do {
// Print note's last modified date
// 打印便签的最后修改日期
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm),
notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
// Query data belong to this note
// 查询属于此便签的数据
String noteId = notesCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps);
} while (notesCursor.moveToNext());
@ -163,7 +148,7 @@ 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,
@ -176,7 +161,7 @@ public class BackupUtils {
do {
String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE);
if (DataConstants.CALL_NOTE.equals(mimeType)) {
// Print phone number
// 打印电话号码
String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER);
long callDate = dataCursor.getLong(DATA_COLUMN_CALL_DATE);
String location = dataCursor.getString(DATA_COLUMN_CONTENT);
@ -185,11 +170,11 @@ public class BackupUtils {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
phoneNumber));
}
// Print call date
// 打印通话日期
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat
.format(mContext.getString(R.string.format_datetime_mdhm),
callDate)));
// Print call attachment location
// 打印通话附件位置
if (!TextUtils.isEmpty(location)) {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
location));
@ -205,7 +190,7 @@ public class BackupUtils {
}
dataCursor.close();
}
// print a line separator between note
// 在便签之间打印一行分隔符
try {
ps.write(new byte[] {
Character.LINE_SEPARATOR, Character.LETTER_NUMBER
@ -240,7 +225,7 @@ public class BackupUtils {
if (folderCursor != null) {
if (folderCursor.moveToFirst()) {
do {
// Print folder's name
// 打印文件夹的名称
String folderName = "";
if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) {
folderName = mContext.getString(R.string.call_record_folder_name);
@ -270,7 +255,7 @@ public class BackupUtils {
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm),
noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
// Query data belong to this note
// 查询数据属于此
String noteId = noteCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps);
} while (noteCursor.moveToNext());
@ -283,7 +268,7 @@ public class BackupUtils {
}
/**
* Get a print stream pointed to the file {@generateExportedTextFile}
* {@generateExportedTextFile}
*/
private PrintStream getExportToTextPrintStream() {
File file = generateFileMountedOnSDcard(mContext, R.string.file_path,
@ -310,7 +295,7 @@ public class BackupUtils {
}
/**
* Generate the text file to store imported data
*
*/
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
StringBuilder sb = new StringBuilder();

@ -37,39 +37,49 @@ import java.util.HashSet;
public class DataUtils {
public static final String TAG = "DataUtils";
// 批量删除笔记的静态方法
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
// 检查传入的笔记ID集合是否为空
if (ids == null) {
Log.d(TAG, "the ids is null");
return true;
return true;// 如果为空,返回删除成功
}
// 检查传入的笔记ID集合是否为空
if (ids.size() == 0) {
Log.d(TAG, "no id is in the hashset");
return true;
return true;// 如果为空,返回删除成功
}
// 创建一个操作列表,用于存储批量操作的删除操作
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
// 遍历传入的笔记ID集合为每个ID创建一个删除操作并添加到操作列表中
for (long id : ids) {
// 检查是否为系统文件夹的ID如果是跳过不删除
if(id == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Don't delete system folder root");
continue;
}
// 创建删除操作的构建器
ContentProviderOperation.Builder builder = ContentProviderOperation
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
// 将删除操作添加到操作列表中
operationList.add(builder.build());
}
try {
// 应用批量操作,删除笔记
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
// 检查批量操作结果是否为空或第一个结果是否为空
if (results == null || results.length == 0 || results[0] == null) {
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false;
return false;// 如果为空,返回删除失败
}
return true;
return true;// 返回删除成功
} catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} catch (OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
}
return false;
return false;// 返回删除失败
}
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
@ -82,27 +92,34 @@ public class DataUtils {
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
long folderId) {
// 检查传入的笔记ID集合是否为空
if (ids == null) {
Log.d(TAG, "the ids is null");
return true;
return true;// 如果为空,返回移动成功
}
// 创建一个操作列表,用于存储批量操作的更新操作
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
// 遍历传入的笔记ID集合为每个ID创建一个更新操作并设置新的父文件夹ID和本地修改标志
for (long id : ids) {
// 创建更新操作的构建器
ContentProviderOperation.Builder builder = ContentProviderOperation
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
// 设置更新操作的值包括新的父文件夹ID和本地修改标志
builder.withValue(NoteColumns.PARENT_ID, folderId);
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);
// 将更新操作添加到操作列表中
operationList.add(builder.build());
}
try {
// 应用批量操作更新笔记的父文件夹ID和本地修改标志
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
// 检查批量操作结果是否为空或第一个结果是否为空
if (results == null || results.length == 0 || results[0] == null) {
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false;
return false;// 如果为空,返回移动失败
}
return true;
return true;// 返回移动成功
} catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} catch (OperationApplicationException e) {
@ -115,89 +132,108 @@ public class DataUtils {
* Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}}
*/
public static int getUserFolderCount(ContentResolver resolver) {
// 查询用户文件夹的数量
Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { "COUNT(*)" },
// 查询条件类型为文件夹且父文件夹ID不是回收站文件夹ID
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?",
new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)},
null);
int count = 0;
if(cursor != null) {
// 如果查询结果非空,移动到第一行
if(cursor.moveToFirst()) {
try {
// 获取查询结果中的文件夹数量
count = cursor.getInt(0);
} catch (IndexOutOfBoundsException e) {
// 捕获异常,输出错误日志
Log.e(TAG, "get folder count failed:" + e.toString());
} finally {
// 关闭游标
cursor.close();
}
}
}
return count;
return count;// 返回文件夹数量
}
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
// 查询指定笔记ID的可见性
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null,
// 查询条件类型为指定类型且父文件夹ID不是回收站文件夹ID
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
new String [] {String.valueOf(type)},
null);
boolean exist = false;
if (cursor != null) {
// 如果查询结果非空检查结果数量是否大于0表示存在
if (cursor.getCount() > 0) {
exist = true;
}
// 关闭游标
cursor.close();
}
return exist;
return exist;// 返回是否存在
}
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
// 查询指定笔记ID是否存在于笔记数据库中
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null);
boolean exist = false;
if (cursor != null) {
// 如果查询结果非空检查结果数量是否大于0表示存在
if (cursor.getCount() > 0) {
exist = true;
}
// 关闭游标
cursor.close();
}
return exist;
return exist;// 返回是否存在
}
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
// 查询指定数据ID是否存在于数据数据库中
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
null, null, null, null);
boolean exist = false;
if (cursor != null) {
// 如果查询结果非空检查结果数量是否大于0表示存在
if (cursor.getCount() > 0) {
exist = true;
}
cursor.close();
}
return exist;
return exist;// 返回是否存在
}
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
// 查询是否存在具有指定名称的可见文件夹
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
// 查询条件类型为文件夹、父文件夹ID不是回收站文件夹ID、且摘要等于指定名称
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
" AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER +
" AND " + NoteColumns.SNIPPET + "=?",
new String[] { name }, null);
boolean exist = false;
if(cursor != null) {
// 如果查询结果非空检查结果数量是否大于0表示存在
if(cursor.getCount() > 0) {
exist = true;
}
cursor.close();
}
return exist;
return exist; // 返回是否存在
}
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
// 查询指定文件夹ID下的笔记小部件信息
Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
NoteColumns.PARENT_ID + "=?",
@ -206,25 +242,30 @@ public class DataUtils {
HashSet<AppWidgetAttribute> set = null;
if (c != null) {
// 如果查询结果非空,移动到第一行
if (c.moveToFirst()) {
set = new HashSet<AppWidgetAttribute>();
do {
try {
// 创建 AppWidgetAttribute 对象获取小部件ID和小部件类型添加到集合中
AppWidgetAttribute widget = new AppWidgetAttribute();
widget.widgetId = c.getInt(0);
widget.widgetType = c.getInt(1);
set.add(widget);
} catch (IndexOutOfBoundsException e) {
// 捕获异常,输出错误日志
Log.e(TAG, e.toString());
}
} while (c.moveToNext());
}
c.close();
}
return set;
return set;// 返回包含小部件信息的集合
}
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
// 查询指定笔记ID对应的通话笔记的电话号码
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.PHONE_NUMBER },
CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
@ -233,17 +274,20 @@ public class DataUtils {
if (cursor != null && cursor.moveToFirst()) {
try {
// 获取查询结果中的电话号码
return cursor.getString(0);
} catch (IndexOutOfBoundsException e) {
// 捕获异常,输出错误日志
Log.e(TAG, "Get call number fails " + e.toString());
} finally {
cursor.close();
}
}
return "";
return "";// 如果查询结果为空,返回空字符串
}
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
// 查询指定电话号码和通话日期对应的通话笔记的笔记ID
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.NOTE_ID },
CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
@ -252,19 +296,24 @@ public class DataUtils {
null);
if (cursor != null) {
// 如果查询结果非空,移动到第一行
if (cursor.moveToFirst()) {
try {
// 获取查询结果中的笔记ID
return cursor.getLong(0);
} catch (IndexOutOfBoundsException e) {
// 捕获异常,输出错误日志
Log.e(TAG, "Get call note id fails " + e.toString());
}
}
cursor.close();
}
return 0;
return 0; // 如果查询结果为空返回0
}
public static String getSnippetById(ContentResolver resolver, long noteId) {
// 查询指定笔记ID的摘要信息
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
new String [] { NoteColumns.SNIPPET },
NoteColumns.ID + "=?",
@ -272,17 +321,20 @@ public class DataUtils {
null);
if (cursor != null) {
// 如果查询结果非空,移动到第一行
String snippet = "";
if (cursor.moveToFirst()) {
// 获取查询结果中的摘要信息
snippet = cursor.getString(0);
}
cursor.close();
return snippet;
return snippet;// 返回摘要信息
}
throw new IllegalArgumentException("Note is not found with id: " + noteId);
}
public static String getFormattedSnippet(String snippet) {
// 格式化摘要信息:去除首尾空格,并截取首个换行符之前的内容
if (snippet != null) {
snippet = snippet.trim();
int index = snippet.indexOf('\n');
@ -290,6 +342,7 @@ public class DataUtils {
snippet = snippet.substring(0, index);
}
}
return snippet;
return snippet;// 返回格式化后的摘要信息
}
}

@ -66,15 +66,19 @@ public class ResourceParser {
}
public static int getDefaultBgId(Context context) {
// 获取默认背景ID
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,

Loading…
Cancel
Save