Compare commits

...

57 Commits

Author SHA1 Message Date
xht 5bdc181c48 ok
2 years ago
xht 9e4afe7168 final_test
2 years ago
xht 1418a5047b final_test
2 years ago
xht a83f2f7e43 final_test
2 years ago
xht 8172d00a5b final_test
2 years ago
xht 69cc59937a final_test
2 years ago
xht 0212331369 final_test
2 years ago
xht 534508b629 final_test
2 years ago
xht 6e17588858 final_test
2 years ago
xht 9581d56448 final_test
2 years ago
xht 82f5b8fa47 final_test
2 years ago
xht 3607666a2b final_test
2 years ago
xht 42b53f0879 final_test
2 years ago
xht 0083298a08 update
2 years ago
xht 0558f33544 之前有问题,更新后的
2 years ago
xht 993f3fb597 update
2 years ago
xht 97ff1fe357 update
2 years ago
xht 4b911e56eb update
2 years ago
xht f3fcda04fc update
2 years ago
xht c554d755b1 Merge branch 'master' of https://bdgit.educoder.net/pas3pu8wc/first_project
2 years ago
xht 1ed2e33c5f update
2 years ago
xht ae6f00a106 update
2 years ago
pas3pu8wc d5eee82b3b Delete 'src/mi_and_login/README.md'
2 years ago
xht 17aa3f6da7 update
2 years ago
xht 0f2d253df0 update
2 years ago
pas3pu8wc 816c281867 Update README.md
2 years ago
xht bc0304c8f8 update
2 years ago
xht d757c0fde7 update_readme
2 years ago
xht 94215d4d16 update
2 years ago
xht f645c4d47a Merge branch 'master' of https://bdgit.educoder.net/pas3pu8wc/first_project
2 years ago
xht dcac7f8052 update
2 years ago
pas3pu8wc ea73108e0a Update README.md
2 years ago
xht 39c1c6cc96 update
2 years ago
xht 064404aa59 update
2 years ago
xht d59b9e80da update
2 years ago
xht b0f8ddea06 update
2 years ago
xht a511a39adc update
2 years ago
xht d3cc9859d3 update
2 years ago
xht a3c12cb18e update
2 years ago
xht d4b2717423 update
2 years ago
xht 29305c56d4 update
2 years ago
xht 0dca71c15f update
2 years ago
xht 4b45ecb9c9 体系结构设计
2 years ago
xht 7ffb735427 逻辑视图和物理视图
2 years ago
xht 9aca58f1f3 用例描述
2 years ago
xht d65b9eddee 分析类图和顺序图
2 years ago
xht f203221b1f 更新后
2 years ago
xht 0188406e03 精读
2 years ago
xht d736042150 123
2 years ago
xht cae25eae73 Merge branch 'master' of https://bdgit.educoder.net/pas3pu8wc/first_project
2 years ago
xht 69b268d540 小米便签开源代码的泛读报告.docx
2 years ago
xht d7a4b07e5b 123
2 years ago
pas3pu8wc 7d0184b8bd ADD file via upload
2 years ago
xGastly 9f1d5d89ed Merge branch 'xax_branch' of https://bdgit.educoder.net/pas3pu8wc/first_project into xax_branch
2 years ago
xGastly 885f51b266 123
2 years ago
pr4oj3fui 1fccc45843 ADD file via upload
2 years ago
pr4oj3fui 4e2bab290e ADD file via upload
2 years ago

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Binary file not shown.

@ -0,0 +1,255 @@
/*
* 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.model;
import android.content.ContentProviderOperation; // 批量的更新。插入。删除数据
import android.content.ContentProviderResult; // 操作的结果
import android.content.ContentUris; // 用于添加和获取Uri后面的ID
import android.content.ContentValues; // 一种用来存储基本数据类型的存储机制
import android.content.Context; // 需要用该类来弄清楚调用者的实例
import android.content.OperationApplicationException; // 操作应用程序容错
import android.net.Uri; // 表示待操作的数据
import android.os.RemoteException; // 远程容错
import android.util.Log; // 输出日志。比如说出错。警告等
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.CallNote;
import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.Notes.TextNote;
import java.util.ArrayList;
//笔记类
public class Note {
private ContentValues mNoteDiffValues;
private NoteData mNoteData;
private static final String TAG = "Note";
/**
* Create a new note id for adding a new note to databases
*/
public static synchronized long getNewNoteId(Context context, long folderId) {
// 在数据库中创建一个新笔记
ContentValues values = new ContentValues();
long createdTime = System.currentTimeMillis();
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); // 将数据写入数据库表格
Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values);
// ContentResolver()主要实现外部应用对ContentProvider中的数据
// 进行添加。删除。修改和查询操作
long noteId = 0;
try {
noteId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString());
noteId = 0;
} // try—catch 异常处理
if (noteId == -1) {
throw new IllegalStateException("Wrong note id:" + noteId);
}
return noteId;
}
// 定义两个变量用来储存便签的数据,一个是储存便签属性、一个是储存便签内容
public Note() {
mNoteDiffValues = new ContentValues();
mNoteData = new NoteData();
}
// 设置数据库表格的标签属性数据
public void setNoteValue(String key, String value) {
mNoteDiffValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
// 设置数据库表格的标签文本内容的数据
public void setTextData(String key, String value) {
mNoteData.setTextData(key, value);
}
// 设置文本数据ID
public void setTextDataId(long id) {
mNoteData.setTextDataId(id);
}
// 得到文本数据的ID
public long getTextDataId() {
return mNoteData.mTextDataId;
}
// 设置电话号码数据的ID
public void setCallDataId(long id) {
mNoteData.setCallDataId(id);
}
// 得到电话号码数据的ID
public void setCallData(String key, String value) {
mNoteData.setCallData(key, value);
}
// 判断是否是本地修改
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);
}
if (!isLocalModified()) {
return true;
}
/**
* In theory, once data changed, the note should be updated on {@link NoteColumns#LOCAL_MODIFIED} and
* {@link NoteColumns#MODIFIED_DATE}. For data safety, though update note fails, we also update the
* note data info
*/
if (context.getContentResolver().update(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), mNoteDiffValues, null,
null) == 0) {
Log.e(TAG, "Update note error, should not happen");
// Do not return, fall through
}
mNoteDiffValues.clear();
if (mNoteData.isLocalModified()
&& (mNoteData.pushIntoContentResolver(context, noteId) == null)) {
return false;
}
return true;
}
// 定义一个基本的便签内容的数据类、主要包含文本数据和电话号码数据
private class NoteData {
private long mTextDataId;
private ContentValues mTextDataValues;// 文本数据
private long mCallDataId;
private ContentValues mCallDataValues;// 电话号码数据
private static final String TAG = "NoteData";
// 下面是上述几个方法的具体实现
public NoteData() {
mTextDataValues = new ContentValues();
mCallDataValues = new ContentValues();
mTextDataId = 0;
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;
}
void setCallDataId(long id) {
if (id <= 0) {
throw new IllegalArgumentException("Call data id should larger than 0");
}
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());
}
//下面方法的作用是将新的数据通过Uri的操作存储到数据库
Uri pushIntoContentResolver(Context context, long noteId) {
/**
* Check for safety
*/
//判断数据是否合法
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId);
}
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
ContentProviderOperation.Builder builder = null;
//把文本数据存入DataColumns
if(mTextDataValues.size() > 0) {
mTextDataValues.put(DataColumns.NOTE_ID, noteId);
if (mTextDataId == 0) {
mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE);
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mTextDataValues);
try {
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 {
builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mTextDataId));
builder.withValues(mTextDataValues);
operationList.add(builder.build());
}
mTextDataValues.clear();
}
//把电话号码数据存入DataColumns
if(mCallDataValues.size() > 0) {
mCallDataValues.put(DataColumns.NOTE_ID, noteId);
if (mCallDataId == 0) {
mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE);
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mCallDataValues);
try {
setCallDataId(Long.valueOf(uri.getPathSegments().get(1)));
} catch (NumberFormatException e) {
Log.e(TAG, "Insert new call data fail with noteId" + noteId);
mCallDataValues.clear();
return null;
}
} else {
builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mCallDataId));
builder.withValues(mCallDataValues);
operationList.add(builder.build());
}
mCallDataValues.clear();
}
//存储过程中的异常处理
if (operationList.size() > 0) {
try {
ContentProviderResult[] results = context.getContentResolver().applyBatch(
Notes.AUTHORITY, operationList);
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;
}
}
return null;
}
}
}

@ -0,0 +1,390 @@
/*
* 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.model;
import android.appwidget.AppWidgetManager;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.text.TextUtils;
import android.util.Log;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.CallNote;
import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.Notes.TextNote;
import net.micode.notes.tool.ResourceParser.NoteBgResources;
public class WorkingNote {
// Note for the working note
private Note mNote;
// Note Id
private long mNoteId;
// Note content
private String mContent;
// Note mode
private int mMode;
private long mAlertDate;
private long mModifiedDate;
private int mBgColorId;
private int mWidgetId;
private int mWidgetType;
private long mFolderId;
private Context mContext;
private static final String TAG = "WorkingNote";
private boolean mIsDeleted;
private NoteSettingChangedListener mNoteSettingStatusListener;
// 声明 DATA_PROJECTION字符串数组
public static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID,
DataColumns.CONTENT,
DataColumns.MIME_TYPE,
DataColumns.DATA1,
DataColumns.DATA2,
DataColumns.DATA3,
DataColumns.DATA4,
};
// 声明 NOTE_PROJECTION字符串数组
public static final String[] NOTE_PROJECTION = new String[] {
NoteColumns.PARENT_ID,
NoteColumns.ALERTED_DATE,
NoteColumns.BG_COLOR_ID,
NoteColumns.WIDGET_ID,
NoteColumns.WIDGET_TYPE,
NoteColumns.MODIFIED_DATE
};
private static final int DATA_ID_COLUMN = 0;
private static final int DATA_CONTENT_COLUMN = 1;
private static final int DATA_MIME_TYPE_COLUMN = 2;
private static final int DATA_MODE_COLUMN = 3;
private static final int NOTE_PARENT_ID_COLUMN = 0;
private static final int NOTE_ALERTED_DATE_COLUMN = 1;
private static final int NOTE_BG_COLOR_ID_COLUMN = 2;
private static final int NOTE_WIDGET_ID_COLUMN = 3;
private static final int NOTE_WIDGET_TYPE_COLUMN = 4;
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
// New note construct
private WorkingNote(Context context, long folderId) {
mContext = context;
mAlertDate = 0;
mModifiedDate = System.currentTimeMillis();
mFolderId = folderId;
mNote = new Note();
mNoteId = 0;
mIsDeleted = false;
mMode = 0;
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
}
// Existing note construct
// WorkingNote的构造函数
private WorkingNote(Context context, long noteId, long folderId) {
mContext = context;
mNoteId = noteId;
mFolderId = folderId;
mIsDeleted = false;
mNote = new Note();
loadNote();
}
// 加载Note
// 通过数据库调用query函数找到第一个条目
private void loadNote() {
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);
mWidgetType = cursor.getInt(NOTE_WIDGET_TYPE_COLUMN);
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();
}
// 加载NoteData
private void loadNoteData() {
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)) {
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);
}
}
// 创建空的Note
// 传参context文件夹idwidget背景颜色
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
int widgetType, int defaultBgColorId) {
WorkingNote note = new WorkingNote(context, folderId);
note.setBgColorId(defaultBgColorId);
note.setWidgetId(widgetId);
note.setWidgetType(widgetType);
return note;
}
// 保存Note
public static WorkingNote load(Context context, long id) {
return new WorkingNote(context, id, 0);
}
public synchronized boolean saveNote() {
// 是否值得保存
if (isWorthSaving()) {
// 是否存在数据库中
if (!existInDatabase()) {
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
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;
} else {
return false;
}
}
// 是否在数据库中存在
public boolean existInDatabase() {
return mNoteId > 0;
}
// 是否值得保存
private boolean isWorthSaving() {
// 被删除,或(不在数据库中 内容为空),或 本地已保存过
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|| (existInDatabase() && !mNote.isLocalModified())) {
return false;
} else {
return true;
}
}
// 设置mNoteSettingStatusListener
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
mNoteSettingStatusListener = l;
}
// 设置AlertDate
// 若 mAlertDate与data不同则更改mAlertDate并设定NoteValue
public void setAlertDate(long date, boolean set) {
if (date != mAlertDate) {
mAlertDate = date;
mNote.setNoteValue(NoteColumns.ALERTED_DATE, String.valueOf(mAlertDate));
}
if (mNoteSettingStatusListener != null) {
mNoteSettingStatusListener.onClockAlertChanged(date, set);
}
}
// 设定删除标记
public void markDeleted(boolean mark) {
// 设定标记
mIsDeleted = mark;
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) {
mNoteSettingStatusListener.onWidgetChanged();
}
}
// 设定背景颜色
public void setBgColorId(int id) {
if (id != mBgColorId) {
mBgColorId = id;
if (mNoteSettingStatusListener != null) {
mNoteSettingStatusListener.onBackgroundColorChanged();
}
mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id));
}
}
// 设定检查列表模式
// 参数mode
public void setCheckListMode(int mode) {
if (mMode != mode) {
if (mNoteSettingStatusListener != null) {
mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode);
}
mMode = mode;
mNote.setTextData(TextNote.MODE, String.valueOf(mMode));
}
}
// 设定WidgetType
// 参数type
public void setWidgetType(int type) {
if (type != mWidgetType) {
mWidgetType = type;
mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType));
}
}
// 设定WidgetId
// 参数id
public void setWidgetId(int id) {
if (id != mWidgetId) {
mWidgetId = id;
mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId));
}
}
// 设定WorkingTex
// 参数更改的text
public void setWorkingText(String text) {
if (!TextUtils.equals(mContent, text)) {
mContent = text;
mNote.setTextData(DataColumns.CONTENT, mContent);
}
}
// 转变mNote的CallData及CallNote信息
// 参数String phoneNumber, long callDate
public void convertToCallNote(String phoneNumber, long callDate) {
mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate));
mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber);
mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER));
}
// 判断是否有时钟题型
public boolean hasClockAlert() {
return (mAlertDate > 0 ? true : false);
}
// 获取Content
public String getContent() {
return mContent;
}
// 获取AlertDate
public long getAlertDate() {
return mAlertDate;
}
// 获取ModifiedDate
public long getModifiedDate() {
return mModifiedDate;
}
// 获取背景颜色来源id
public int getBgColorResId() {
return NoteBgResources.getNoteBgResource(mBgColorId);
}
// 获取背景颜色id
public int getBgColorId() {
return mBgColorId;
}
// 获取标题背景颜色id
public int getTitleBgResId() {
return NoteBgResources.getNoteTitleBgResource(mBgColorId);
}
// 获取CheckListMode
public int getCheckListMode() {
return mMode;
}
// 获取便签id
public long getNoteId() {
return mNoteId;
}
// 获取文件夹id
public long getFolderId() {
return mFolderId;
}
// 获取WidgetId
public int getWidgetId() {
return mWidgetId;
}
// 获取WidgetType
public int getWidgetType() {
return mWidgetType;
}
// 创建接口 NoteSettingChangedListener,便签更新监视
// 为NoteEditActivity提供接口
// 提供函数有
public interface NoteSettingChangedListener {
/**
* Called when the background color of current note has just changed
*/
void onBackgroundColorChanged();
/**
* Called when user set clock
*/
void onClockAlertChanged(long date, boolean set);
/**
* Call when user create note from widget
*/
void onWidgetChanged();
/**
* Call when switch between check list mode and normal mode
* @param oldMode is previous mode before change
* @param newMode is new mode
*/
void onCheckListModeChanged(int oldMode, int newMode);
}
}

@ -0,0 +1,364 @@
/*
* 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;
import android.content.Context;
import android.database.Cursor;
import android.os.Environment;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Log;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
public class BackupUtils {
private static final String TAG = "BackupUtils";
// Singleton stuff
private static BackupUtils sInstance;
/**synchronized ,线线A
,线BC D()
使synchronized线BC D线A,,,
synchronized synchronized
*/
public static synchronized BackupUtils getInstance(Context context) {
if (sInstance == null) {
//如果当前备份不存在,则新声明一个
sInstance = new BackupUtils(context);
}
return sInstance;
}
/**
* 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;
private BackupUtils(Context context) {
mTextExport = new TextExport(context);
}
// 外部储存功能是否可用
private static boolean externalStorageAvailable() {
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}
public int exportToText() {
return mTextExport.exportToText();
}
public String getExportedTextFileName() {
return mTextExport.mFileName;
}
public String getExportedTextFileDir() {
return mTextExport.mFileDirectory;
}
private static class TextExport {
private static final String[] NOTE_PROJECTION = {
NoteColumns.ID,
NoteColumns.MODIFIED_DATE,
NoteColumns.SNIPPET,
NoteColumns.TYPE
};
private static final int NOTE_COLUMN_ID = 0;
private static final int NOTE_COLUMN_MODIFIED_DATE = 1;
private static final int NOTE_COLUMN_SNIPPET = 2;
private static final String[] DATA_PROJECTION = {
DataColumns.CONTENT,
DataColumns.MIME_TYPE,
DataColumns.DATA1,
DataColumns.DATA2,
DataColumns.DATA3,
DataColumns.DATA4,
};
private static final int DATA_COLUMN_CONTENT = 0;
private static final int DATA_COLUMN_MIME_TYPE = 1;
private static final int DATA_COLUMN_CALL_DATE = 2;
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 Context mContext;
private String mFileName;
private String mFileDirectory;
public TextExport(Context context) {
TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note);
mContext = context;
mFileName = "";
mFileDirectory = "";
}
// 获取文本的组成部分
private String getFormat(int id) {
return TEXT_FORMAT[id];
}
/**
* Export the folder identified by folder id to text
*/
private void exportFolderToText(String folderId, PrintStream ps) {
// 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) {
if (notesCursor.moveToFirst()) {
do {
// Print note's last modified date
// ps里面保存有这份note的日期
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);
// 将文件导出到text
exportNoteToText(noteId, ps);
} while (notesCursor.moveToNext());
}
notesCursor.close();
}
}
/**
* Export note identified by id to a print stream
*/
private void exportNoteToText(String noteId, PrintStream ps) {
Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI,
DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] {
noteId
}, null);
// 利用光标来扫描内容区别为callnote和note两种靠ps.printline两种
if (dataCursor != null) {
if (dataCursor.moveToFirst()) {
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);
//判断是否为空字符
if (!TextUtils.isEmpty(phoneNumber)) {
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));
}
} 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),
content));
}
}
} while (dataCursor.moveToNext());
}
dataCursor.close();
}
// print a line separator between note
try {
ps.write(new byte[] {
Character.LINE_SEPARATOR, Character.LETTER_NUMBER
});
} catch (IOException e) {
Log.e(TAG, e.toString());
}
}
/**
* Note will be exported as text which is user readable
*/
//总函数调用上面的exportFolder和exportNote
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
// 导出文件夹,就是导出里面包含的便签
Cursor folderCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
"(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND "
+ NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR "
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null);
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);
} else {
folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET);
}
if (!TextUtils.isEmpty(folderName)) {
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
// 将根目录里的便签导出(由于不属于任何文件夹,因此无法通过文件夹导出来实现这一部分便签的导出)
Cursor noteCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID
+ "=0", null, null);
if (noteCursor != null) {
if (noteCursor.moveToFirst()) {
do {
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm),
noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
// Query data belong to this note
String noteId = noteCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps);
} while (noteCursor.moveToNext());
}
noteCursor.close();
}
ps.close();
return STATE_SUCCESS;
}
/**
* 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) {
Log.e(TAG, "create file to exported failed");
return null;
}
mFileName = file.getName();
mFileDirectory = mContext.getString(R.string.file_path);
PrintStream ps = null;
try {
FileOutputStream fos = new FileOutputStream(file);
//将ps输出流输出到特定的文件目的就是导出到文件而不是直接输出
ps = new PrintStream(fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
} catch (NullPointerException e) {
e.printStackTrace();
return null;
}
return ps;
}
}
/**
* Generate the text file to store imported data
*/
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
StringBuilder sb = new StringBuilder();
//外部SD卡的存储路径
sb.append(Environment.getExternalStorageDirectory());
//文件的存储路径
sb.append(context.getString(filePathResId));
//filedir应该就是用来存储路径信息
File filedir = new File(sb.toString());
sb.append(context.getString(
fileNameFormatResId,
DateFormat.format(context.getString(R.string.format_date_ymd),
System.currentTimeMillis())));
File file = new File(sb.toString());
//如果这些文件不存在,则新建
try {
if (!filedir.exists()) {
filedir.mkdir();
}
if (!file.exists()) {
file.createNewFile();
}
return file;
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,312 @@
/*
* 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;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.OperationApplicationException;
import android.database.Cursor;
import android.os.RemoteException;
import android.util.Log;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.CallNote;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
import java.util.ArrayList;
import java.util.HashSet;
public class DataUtils {
public static final String TAG = "DataUtils";
//直接删除多个笔记
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
if (ids == null) {
Log.d(TAG, "the ids is null");
return true;
}
if (ids.size() == 0) {
Log.d(TAG, "no id is in the hashset");
return true;
}
//提供一个任务列表
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
for (long id : ids) {
//如果发现是根文件夹,则不删除
if(id == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Don't delete system folder root");
continue;
}
//用newDelete实现删除功能
ContentProviderOperation.Builder builder = ContentProviderOperation
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
operationList.add(builder.build());
}
try {
//主机名或叫Authority用于唯一标识这个ContentProvider外部调用者可以根据这个标识来找到它。
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 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;
}
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
ContentValues values = new ContentValues();
values.put(NoteColumns.PARENT_ID, desFolderId);
values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId);
values.put(NoteColumns.LOCAL_MODIFIED, 1);
//对需要移动的便签进行数据更新然后用update实现
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
}
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
long folderId) {
if (ids == null) {
Log.d(TAG, "the ids is null");
return true;
}
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
//将ids里包含的每一列的数据逐次加入到operationList中等待最后的批量处理
for (long id : ids) {
//通过withAppendedId方法为该Uri加上ID
ContentProviderOperation.Builder builder = ContentProviderOperation
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
builder.withValue(NoteColumns.PARENT_ID, folderId);
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);
operationList.add(builder.build());
}
try {
//applyBatch一次性处理一个操作列表
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 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;
}
/**
* 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(*)" },
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?",
//筛选条件源文件不为trash folder
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;
}
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
//通过withAppendedId方法为该Uri加上ID
//查询条件type符合且不属于垃圾文件夹
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null,
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
new String [] {String.valueOf(type)},
null);
boolean exist = false;
if (cursor != null) {
//用getcount函数判断cursor是否为空
if (cursor.getCount() > 0) {
exist = true;
}
cursor.close();
}
return exist;
}
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null);
boolean exist = false;
if (cursor != null) {
if (cursor.getCount() > 0) {
exist = true;
}
cursor.close();
}
return exist;
}
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
null, null, null, null);
//通过名字查询文件是否存在
boolean exist = false;
if (cursor != null) {
if (cursor.getCount() > 0) {
exist = true;
}
cursor.close();
}
return exist;
}
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
//查询条件父ID是传入的folderId;
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
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) {
if(cursor.getCount() > 0) {
exist = true;
}
cursor.close();
}
return exist;
}
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 },
NoteColumns.PARENT_ID + "=?",
new String[] { String.valueOf(folderId) },
null);
HashSet<AppWidgetAttribute> set = null;
if (c != null) {
if (c.moveToFirst()) {
set = new HashSet<AppWidgetAttribute>();
do {
try {
AppWidgetAttribute widget = new AppWidgetAttribute();
//0对应的NoteColumns.WIDGET_ID
widget.widgetId = c.getInt(0);
//1对应的NoteColumns.WIDGET_TYPE
widget.widgetType = c.getInt(1);
set.add(widget);
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, e.toString());
}
} while (c.moveToNext());//查询下一条
}
c.close();
}
return set;
}
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.PHONE_NUMBER },
CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE },
null);
//通过数据库操作查询条件是callDate和phoneNumber匹配传入参数的值
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 "";
}
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.NOTE_ID },
CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
+ CallNote.PHONE_NUMBER + ",?)",
new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber },
null);
if (cursor != null) {
if (cursor.moveToFirst()) {
try {
return cursor.getLong(0);
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call note id fails " + e.toString());
}
}
cursor.close();
}
return 0;
}
public static String getSnippetById(ContentResolver resolver, long noteId) {
//查询条件noteId
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
new String [] { NoteColumns.SNIPPET },
NoteColumns.ID + "=?",
new String [] { String.valueOf(noteId)},
null);
if (cursor != null) {
String snippet = "";
if (cursor.moveToFirst()) {
snippet = cursor.getString(0);
}
cursor.close();
return snippet;
}
throw new IllegalArgumentException("Note is not found with id: " + noteId);
}
//对字符串进行格式处理,将字符串两头的空格去掉,同时将换行符去掉
public static String getFormattedSnippet(String snippet) {
if (snippet != null) {
snippet = snippet.trim();
int index = snippet.indexOf('\n');
if (index != -1) {
snippet = snippet.substring(0, index);
}
}
return snippet;
}
}

@ -0,0 +1,113 @@
/*
* 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.
*/
//简介定义了很多的静态字符串目的就是为了提供jsonObject中相应字符串的"key"。把这些静态的定义单独写到了一个类里面,方便查看
package net.micode.notes.tool;
//这个类就是定义了一堆static string实际就是为jsonObject提供Key把这些定义全部写到一个类里方便查看管理
public class GTaskStringUtils {
public final static String GTASK_JSON_ACTION_ID = "action_id";
public final static String GTASK_JSON_ACTION_LIST = "action_list";
public final static String GTASK_JSON_ACTION_TYPE = "action_type";
public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create";
public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all";
public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move";
public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update";
public final static String GTASK_JSON_CREATOR_ID = "creator_id";
public final static String GTASK_JSON_CHILD_ENTITY = "child_entity";
public final static String GTASK_JSON_CLIENT_VERSION = "client_version";
public final static String GTASK_JSON_COMPLETED = "completed";
public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id";
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id";
public final static String GTASK_JSON_DELETED = "deleted";
public final static String GTASK_JSON_DEST_LIST = "dest_list";
public final static String GTASK_JSON_DEST_PARENT = "dest_parent";
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type";
public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta";
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type";
public final static String GTASK_JSON_GET_DELETED = "get_deleted";
public final static String GTASK_JSON_ID = "id";
public final static String GTASK_JSON_INDEX = "index";
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified";
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point";
public final static String GTASK_JSON_LIST_ID = "list_id";
public final static String GTASK_JSON_LISTS = "lists";
public final static String GTASK_JSON_NAME = "name";
public final static String GTASK_JSON_NEW_ID = "new_id";
public final static String GTASK_JSON_NOTES = "notes";
public final static String GTASK_JSON_PARENT_ID = "parent_id";
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id";
public final static String GTASK_JSON_RESULTS = "results";
public final static String GTASK_JSON_SOURCE_LIST = "source_list";
public final static String GTASK_JSON_TASKS = "tasks";
public final static String GTASK_JSON_TYPE = "type";
public final static String GTASK_JSON_TYPE_GROUP = "GROUP";
public final static String GTASK_JSON_TYPE_TASK = "TASK";
public final static String GTASK_JSON_USER = "user";
public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]";
public final static String FOLDER_DEFAULT = "Default";
public final static String FOLDER_CALL_NOTE = "Call_Note";
public final static String FOLDER_META = "METADATA";
public final static String META_HEAD_GTASK_ID = "meta_gid";
public final static String META_HEAD_NOTE = "meta_note";
public final static String META_HEAD_DATA = "meta_data";
public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE";
}

@ -0,0 +1,196 @@
/*
* 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;
import android.content.Context;
import android.preference.PreferenceManager;
import net.micode.notes.R;
import net.micode.notes.ui.NotesPreferenceActivity;
/*使
* R.java
* R.id
* R.drawable 使
* R.layout
* R.menu
* R.String
* R.style 使
* idgetXXX
*
*
* @BG_DEFAULT_COLOR
* BG_DEFAULT_FONT_SIZE
*/
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 BG_DEFAULT_COLOR = YELLOW;
public static final int TEXT_SMALL = 0;
public static final int TEXT_MEDIUM = 1;
public static final int TEXT_LARGE = 2;
public static final int TEXT_SUPER = 3;
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
public static class NoteBgResources {
private final static int [] BG_EDIT_RESOURCES = new int [] {
R.drawable.edit_yellow,
R.drawable.edit_blue,
R.drawable.edit_white,
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
};
public static int getNoteBgResource(int id) {
return BG_EDIT_RESOURCES[id];
}
public static int getNoteTitleBgResource(int id) {
return BG_EDIT_TITLE_RESOURCES[id];
}
}
public static int getDefaultBgId(Context context) {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length);
} else {
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_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_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
};
public static int getNoteBgFirstRes(int id) {
return BG_FIRST_RESOURCES[id];
}
public static int getNoteBgLastRes(int id) {
return BG_LAST_RESOURCES[id];
}
public static int getNoteBgSingleRes(int id) {
return BG_SINGLE_RESOURCES[id];
}
public static int getNoteBgNormalRes(int id) {
return BG_NORMAL_RESOURCES[id];
}
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,
};
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
};
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
};
//这里有一个容错的函数防止输入的id大于资源总量若如此则自动返回默认的设置结果
public static int getTexAppearanceResource(int id) {
/**
* HACKME: Fix bug of store the resource id in shared preference.
* The id may larger than the length of resources, in this case,
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
*/
if (id >= TEXTAPPEARANCE_RESOURCES.length) {
return BG_DEFAULT_FONT_SIZE;
}
return TEXTAPPEARANCE_RESOURCES[id];
}
public static int getResourcesSize() {
return TEXTAPPEARANCE_RESOURCES.length;
}
}
}

@ -0,0 +1,142 @@
/*
* 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.widget;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.util.Log;
import android.widget.RemoteViews;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.tool.ResourceParser;
import net.micode.notes.ui.NoteEditActivity;
import net.micode.notes.ui.NotesListActivity;
public abstract class NoteWidgetProvider extends AppWidgetProvider {
public static final String [] PROJECTION = new String [] {
NoteColumns.ID,
NoteColumns.BG_COLOR_ID,
NoteColumns.SNIPPET
};
public static final int COLUMN_ID = 0; // 标签栏编号
public static final int COLUMN_BG_COLOR_ID = 1; // 背景颜色编号
public static final int COLUMN_SNIPPET = 2; // 便签片段
private static final String TAG = "NoteWidgetProvider";
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
ContentValues values = new ContentValues();
values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
// 修改删除的路径位置
for (int i = 0; i < appWidgetIds.length; i++) {
context.getContentResolver().update(Notes.CONTENT_NOTE_URI,
values,
NoteColumns.WIDGET_ID + "=?",
new String[] { String.valueOf(appWidgetIds[i])});
}
}
// 修改删除的路径位置
private Cursor getNoteWidgetInfo(Context context, int widgetId) {
return context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
PROJECTION,
// 用ID来筛选同时要是存在于未被删除的文件夹中
NoteColumns.WIDGET_ID + "=? AND " + NoteColumns.PARENT_ID + "<>?",
new String[] { String.valueOf(widgetId), String.valueOf(Notes.ID_TRASH_FOLER) },
null);
}
// 用updata函数来实现小米便签挂件appWidgetlds信息的返回与更新
protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
update(context, appWidgetManager, appWidgetIds, false);
}
// 更新widget的信息方法
private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds,
boolean privacyMode) {
// 每添加一个widget就会进行一次循环更新widget操作
for (int i = 0; i < appWidgetIds.length; i++) {
if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) {
int bgId = ResourceParser.getDefaultBgId(context);
String snippet = "";
Intent intent = new Intent(context, NoteEditActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(Notes.INTENT_EXTRA_WIDGET_ID, appWidgetIds[i]);
intent.putExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, getWidgetType());
Cursor c = getNoteWidgetInfo(context, appWidgetIds[i]);
/* cursor.moveToFirst
cursor.moveToFirst()truefalse
*/
if (c != null && c.moveToFirst()) {
// 返回cursor中的行数。
if (c.getCount() > 1) {
Log.e(TAG, "Multiple message with same widget id:" + appWidgetIds[i]);
c.close();
return;
}
snippet = c.getString(COLUMN_SNIPPET);
bgId = c.getInt(COLUMN_BG_COLOR_ID);
intent.putExtra(Intent.EXTRA_UID, c.getLong(COLUMN_ID));
intent.setAction(Intent.ACTION_VIEW);
} else {
snippet = context.getResources().getString(R.string.widget_havenot_content);
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
}
if (c != null) {
c.close();
}
// RemoteViews可以展示一个layout显示的viewset方法更新内容支持有限的布局和控件。这里主要是获取对应视图
RemoteViews rv = new RemoteViews(context.getPackageName(), getLayoutId());
// 根据图片资源设置图片
rv.setImageViewResource(R.id.widget_bg_image, getBgResourceId(bgId));
intent.putExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, bgId);
/**
* Generate the pending intent to start host for the widget
*/
PendingIntent pendingIntent = null;
// 判定是否是私密模式
if (privacyMode) {
rv.setTextViewText(R.id.widget_text,
context.getString(R.string.widget_under_visit_mode));
pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], new Intent(
context, NotesListActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
} else {
rv.setTextViewText(R.id.widget_text, snippet);
pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
// 窗口服务部件
rv.setOnClickPendingIntent(R.id.widget_text, pendingIntent);
// 更新widget信息
appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
}
}
}
// 从背景资源中获取当前应用ID
protected abstract int getBgResourceId(int bgId);
// 获取部局ID
protected abstract int getLayoutId();
// 获取挂件的类型即2x2型或者4x4型
protected abstract int getWidgetType();
}

@ -0,0 +1,51 @@
/*
* 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.widget;
// 导入各种类
import android.appwidget.AppWidgetManager;
import android.content.Context;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
// 继承了NoteWidgetProvider类定义了2*2大小的窗口并对部分函数进行重载
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
@Override
// 更新窗口
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds);
}
@Override
// 返回2*2窗口布局
protected int getLayoutId() {
return R.layout.widget_2x;
}
@Override
// 获取背景id
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
}
@Override
// 获取widget类型
protected int getWidgetType() {
return Notes.TYPE_WIDGET_2X;
}
}

@ -0,0 +1,49 @@
/*
* 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.widget;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
// 继承了NoteWidgetProvider类定义了4*4大小的窗口并对部分函数进行重载
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
@Override
// 对窗口更新进行重载
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds);
}
// 返回4*4窗口布局
protected int getLayoutId() {
return R.layout.widget_4x;
}
@Override
// 获取背景id
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId);
}
@Override
// 获取widget类型
protected int getWidgetType() {
return Notes.TYPE_WIDGET_4X;
}
}

@ -0,0 +1,241 @@
/*
* 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.ui;
import android.content.Context;
import android.database.Cursor;
import android.text.TextUtils;
import net.micode.notes.data.Contact;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.tool.DataUtils;
public class NoteItemData {
static final String [] PROJECTION = new String [] {
NoteColumns.ID,
NoteColumns.ALERTED_DATE,
NoteColumns.BG_COLOR_ID,
NoteColumns.CREATED_DATE,
NoteColumns.HAS_ATTACHMENT,
NoteColumns.MODIFIED_DATE,
NoteColumns.NOTES_COUNT,
NoteColumns.PARENT_ID,
NoteColumns.SNIPPET,
NoteColumns.TYPE,
NoteColumns.WIDGET_ID,
NoteColumns.WIDGET_TYPE,
};
//常量标记
private static final int ID_COLUMN = 0;
private static final int ALERTED_DATE_COLUMN = 1;
private static final int BG_COLOR_ID_COLUMN = 2;
private static final int CREATED_DATE_COLUMN = 3;
private static final int HAS_ATTACHMENT_COLUMN = 4;
private static final int MODIFIED_DATE_COLUMN = 5;
private static final int NOTES_COUNT_COLUMN = 6;
private static final int PARENT_ID_COLUMN = 7;
private static final int SNIPPET_COLUMN = 8;
private static final int TYPE_COLUMN = 9;
private static final int WIDGET_ID_COLUMN = 10;
private static final int WIDGET_TYPE_COLUMN = 11;
//变量定义
private long mId;
private long mAlertDate;
private int mBgColorId;
private long mCreatedDate;
private boolean mHasAttachment;
private long mModifiedDate;
private int mNotesCount;
private long mParentId;
private String mSnippet;
private int mType;
private int mWidgetId;
private int mWidgetType;
private String mName;
private String mPhoneNumber;
private boolean mIsLastItem;
private boolean mIsFirstItem;
private boolean mIsOnlyOneItem;
private boolean mIsOneNoteFollowingFolder;
private boolean mIsMultiNotesFollowingFolder;
//初始化NoteItemData利用光标获取信息
public NoteItemData(Context context, Cursor cursor) {
//getxxx形式的函数作用为转换格式
mId = cursor.getLong(ID_COLUMN);
mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN);
mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN);
mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN);
mHasAttachment = (cursor.getInt(HAS_ATTACHMENT_COLUMN) > 0) ? true : false;
mModifiedDate = cursor.getLong(MODIFIED_DATE_COLUMN);
mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN);
mParentId = cursor.getLong(PARENT_ID_COLUMN);
mSnippet = cursor.getString(SNIPPET_COLUMN);
mSnippet = mSnippet.replace(NoteEditActivity.TAG_CHECKED, "").replace(
NoteEditActivity.TAG_UNCHECKED, "");
mType = cursor.getInt(TYPE_COLUMN);
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN);
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
//将电话号码信息初始化
mPhoneNumber = "";
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {
mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId);
if (!TextUtils.isEmpty(mPhoneNumber)) {
//若mphonenumber里有符合条件的字符串则用contart功能连接
mName = Contact.getContact(context, mPhoneNumber);
if (mName == null) {
mName = mPhoneNumber;
}
}
}
if (mName == null) {
mName = "";
}
checkPostion(cursor);
}
//根据鼠标的位置设置标记
private void checkPostion(Cursor cursor) {
mIsLastItem = cursor.isLast() ? true : false;
mIsFirstItem = cursor.isFirst() ? true : false;
mIsOnlyOneItem = (cursor.getCount() == 1);
//初始化“多重子文件”和“单一子文件”两个标记
mIsMultiNotesFollowingFolder = false;
mIsOneNoteFollowingFolder = false;
//定义上述两个标记
if (mType == Notes.TYPE_NOTE && !mIsFirstItem) {
//若是note格式且不是第一个元素
int position = cursor.getPosition();
if (cursor.moveToPrevious()) {
//获取光标位置后,看上一行
if (cursor.getInt(TYPE_COLUMN) == Notes.TYPE_FOLDER
|| cursor.getInt(TYPE_COLUMN) == Notes.TYPE_SYSTEM) {
//若光标满足系统或note格式
if (cursor.getCount() > (position + 1)) {
//若是数据行数大于但前位置+1则设置成正确
mIsMultiNotesFollowingFolder = true;
} else {
//否则单一文件夹标记为true
mIsOneNoteFollowingFolder = true;
}
}
if (!cursor.moveToNext()) {
//若不能再往下走则报错
throw new IllegalStateException("cursor move to previous but can't move back");
}
}
}
}
//获取标记
public boolean isOneFollowingFolder() {
return mIsOneNoteFollowingFolder;
}
public boolean isMultiFollowingFolder() {
return mIsMultiNotesFollowingFolder;
}
public boolean isLast() {
return mIsLastItem;
}
public String getCallName() {
return mName;
}
public boolean isFirst() {
return mIsFirstItem;
}
public boolean isSingle() {
return mIsOnlyOneItem;
}
public long getId() {
return mId;
}
public long getAlertDate() {
return mAlertDate;
}
public long getCreatedDate() {
return mCreatedDate;
}
public boolean hasAttachment() {
return mHasAttachment;
}
public long getModifiedDate() {
return mModifiedDate;
}
public int getBgColorId() {
return mBgColorId;
}
public long getParentId() {
return mParentId;
}
public int getNotesCount() {
return mNotesCount;
}
public long getFolderId () {
return mParentId;
}
public int getType() {
return mType;
}
public int getWidgetType() {
return mWidgetType;
}
public int getWidgetId() {
return mWidgetId;
}
public String getSnippet() {
return mSnippet;
}
public boolean hasAlert() {
return (mAlertDate > 0);
}
//若数据父id为保存至文件夹模式的id且满足电话号码单元不为空则isCallRecord为true
public boolean isCallRecord() {
return (mParentId == Notes.ID_CALL_RECORD_FOLDER && !TextUtils.isEmpty(mPhoneNumber));
}
public static int getNoteType(Cursor cursor) {
return cursor.getInt(TYPE_COLUMN);
}
}

@ -0,0 +1,984 @@
/*
* 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.ui;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.appwidget.AppWidgetManager;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.ActionMode;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Display;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnCreateContextMenuListener;
import android.view.View.OnTouchListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.gtask.remote.GTaskSyncService;
import net.micode.notes.model.WorkingNote;
import net.micode.notes.tool.BackupUtils;
import net.micode.notes.tool.DataUtils;
import net.micode.notes.tool.ResourceParser;
import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
import net.micode.notes.widget.NoteWidgetProvider_2x;
import net.micode.notes.widget.NoteWidgetProvider_4x;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
//主界面打开APP即展现此界面
public class NotesListActivity extends Activity implements OnClickListener, OnItemLongClickListener {
private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0;
private static final int FOLDER_LIST_QUERY_TOKEN = 1;
private static final int MENU_FOLDER_DELETE = 0;
private static final int MENU_FOLDER_VIEW = 1;
private static final int MENU_FOLDER_CHANGE_NAME = 2;
private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction";
private enum ListEditState {
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
};
private ListEditState mState;
private BackgroundQueryHandler mBackgroundQueryHandler;
private NotesListAdapter mNotesListAdapter;
private ListView mNotesListView;
private Button mAddNewNote;
private boolean mDispatch;
private int mOriginY;
private int mDispatchY;
private TextView mTitleBar;
private long mCurrentFolderId;
private ContentResolver mContentResolver;
private ModeCallback mModeCallBack;
private static final String TAG = "NotesListActivity";
public static final int NOTES_LISTVIEW_SCROLL_RATE = 30;
private NoteItemData mFocusNoteDataItem;
private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?";
private static final String ROOT_FOLDER_SELECTION = "(" + NoteColumns.TYPE + "<>"
+ Notes.TYPE_SYSTEM + " AND " + NoteColumns.PARENT_ID + "=?)" + " OR ("
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER + " AND "
+ NoteColumns.NOTES_COUNT + ">0)";
private final static int REQUEST_CODE_OPEN_NODE = 102;
private final static int REQUEST_CODE_NEW_NODE = 103;
@Override
//创建类
protected void onCreate(Bundle savedInstanceState) {
//调用父类的onCreate函数
super.onCreate(savedInstanceState);
setContentView(R.layout.note_list);
initResources();
/**
* Insert an introduction when user firstly use this application
*/
setAppInfoFromRawRes();
}
@Override
//返回一些子模块完成的数据交给主Activity处理
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK
//若结果值和要求值符合要求
&& (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) {
mNotesListAdapter.changeCursor(null);
} else {
//调用Activity的onActivityResult
super.onActivityResult(requestCode, resultCode, data);
}
}
private void setAppInfoFromRawRes() {
// Android平台给我们提供了一个SharedPreferences类它是一个轻量级的存储类特别适合用于保存软件配置参数
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
StringBuilder sb = new StringBuilder();
InputStream in = null;
try {
//把资源文件放到应用程序的/raw/raw下那么就可以在应用中使用getResources获取资源后,以openRawResource方法不带后缀的资源文件名打开这个文件
in = getResources().openRawResource(R.raw.introduction);
if (in != null) {
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
char [] buf = new char[1024]; //自行定义的数值
int len = 0;
while ((len = br.read(buf)) > 0) {
sb.append(buf, 0, len);
}
} else {
Log.e(TAG, "Read introduction file error");
return;
}
} catch (IOException e) {
e.printStackTrace();
return;
} finally {
if(in != null) {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//创建空的WorkingNote
WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER,
AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE,
ResourceParser.RED);
note.setWorkingText(sb.toString());
if (note.saveNote()) {
//更新保存note的信息
sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit();
} else {
Log.e(TAG, "Save introduction note error");
return;
}
}
}
@Override
protected void onStart() {
super.onStart();
startAsyncNotesListQuery();
}
//初始化资源
private void initResources() {
mContentResolver = this.getContentResolver(); //获取应用程序的数据,得到类似数据表的信息
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
//findViewById 是安卓编程的定位函数,主要是引用.R文件里的引用名
mNotesListView = (ListView) findViewById(R.id.notes_list); //绑定XML中的ListView作为Item的容器
mNotesListView.addFooterView(LayoutInflater.from(this).inflate(R.layout.note_list_footer, null),
null, false);
mNotesListView.setOnItemClickListener(new OnListItemClickListener());
mNotesListView.setOnItemLongClickListener(this);
mNotesListAdapter = new NotesListAdapter(this);
mNotesListView.setAdapter(mNotesListAdapter);
mAddNewNote = (Button) findViewById(R.id.btn_new_note); //在activity中要获取该按钮
mAddNewNote.setOnClickListener(this);
mAddNewNote.setOnTouchListener(new NewNoteOnTouchListener());
mDispatch = false;
mDispatchY = 0;
mOriginY = 0;
mTitleBar = (TextView) findViewById(R.id.tv_title_bar);
mState = ListEditState.NOTE_LIST;
mModeCallBack = new ModeCallback();
}
//从ListView.MultiChoiceModeListener和OnMenuItemClickListener继承
private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
private DropdownMenu mDropDownMenu;
private ActionMode mActionMode;
private MenuItem mMoveMenu;
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
getMenuInflater().inflate(R.menu.note_list_options, menu);
menu.findItem(R.id.delete).setOnMenuItemClickListener(this);
mMoveMenu = menu.findItem(R.id.move);
if (mFocusNoteDataItem.getParentId() == Notes.ID_CALL_RECORD_FOLDER
|| DataUtils.getUserFolderCount(mContentResolver) == 0) {
mMoveMenu.setVisible(false);
} else {
mMoveMenu.setVisible(true);
mMoveMenu.setOnMenuItemClickListener(this);
}
mActionMode = mode;
mNotesListAdapter.setChoiceMode(true);
mNotesListView.setLongClickable(false);
mAddNewNote.setVisibility(View.GONE);
View customView = LayoutInflater.from(NotesListActivity.this).inflate(
R.layout.note_list_dropdown_menu, null);
mode.setCustomView(customView);
mDropDownMenu = new DropdownMenu(NotesListActivity.this,
(Button) customView.findViewById(R.id.selection_menu),
R.menu.note_list_dropdown);
mDropDownMenu.setOnDropdownMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){
public boolean onMenuItemClick(MenuItem item) {
mNotesListAdapter.selectAll(!mNotesListAdapter.isAllSelected());
updateMenu();
return true;
}
});
return true;
}
//更新菜单
private void updateMenu() {
int selectedCount = mNotesListAdapter.getSelectedCount();
// Update dropdown menu
String format = getResources().getString(R.string.menu_select_title, selectedCount);
mDropDownMenu.setTitle(format); //更改标题
MenuItem item = mDropDownMenu.findItem(R.id.action_select_all);
if (item != null) {
if (mNotesListAdapter.isAllSelected()) {
item.setChecked(true);
item.setTitle(R.string.menu_deselect_all);
} else {
item.setChecked(false);
item.setTitle(R.string.menu_select_all);
}
}
}
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// TODO Auto-generated method stub
return false;
}
public void onDestroyActionMode(ActionMode mode) {
mNotesListAdapter.setChoiceMode(false);
mNotesListView.setLongClickable(true);
mAddNewNote.setVisibility(View.VISIBLE);
}
public void finishActionMode() {
mActionMode.finish();
}
public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
boolean checked) {
mNotesListAdapter.setCheckedItem(position, checked);
updateMenu();
}
public boolean onMenuItemClick(MenuItem item) {
if (mNotesListAdapter.getSelectedCount() == 0) {
Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none),
Toast.LENGTH_SHORT).show();
return true;
}
switch (item.getItemId()) {
case R.id.delete:
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
builder.setTitle(getString(R.string.alert_title_delete));
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setMessage(getString(R.string.alert_message_delete_notes,
mNotesListAdapter.getSelectedCount()));
builder.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
batchDelete();
}
});
builder.setNegativeButton(android.R.string.cancel, null);
builder.show();
break;
case R.id.move:
startQueryDestinationFolders();
break;
default:
return false;
}
return true;
}
}
private class NewNoteOnTouchListener implements OnTouchListener {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
Display display = getWindowManager().getDefaultDisplay();
int screenHeight = display.getHeight();
int newNoteViewHeight = mAddNewNote.getHeight();
int start = screenHeight - newNoteViewHeight;
int eventY = start + (int) event.getY();
/**
* Minus TitleBar's height
*/
if (mState == ListEditState.SUB_FOLDER) {
eventY -= mTitleBar.getHeight();
start -= mTitleBar.getHeight();
}
/**
* HACKME:When click the transparent part of "New Note" button, dispatch
* the event to the list view behind this button. The transparent part of
* "New Note" button could be expressed by formula y=-0.12x+94Unit:pixel
* and the line top of the button. The coordinate based on left of the "New
* Note" button. The 94 represents maximum height of the transparent part.
* Notice that, if the background of the button changes, the formula should
* also change. This is very bad, just for the UI designer's strong requirement.
*/
if (event.getY() < (event.getX() * (-0.12) + 94)) {
View view = mNotesListView.getChildAt(mNotesListView.getChildCount() - 1
- mNotesListView.getFooterViewsCount());
if (view != null && view.getBottom() > start
&& (view.getTop() < (start + 94))) {
mOriginY = (int) event.getY();
mDispatchY = eventY;
event.setLocation(event.getX(), mDispatchY);
mDispatch = true;
return mNotesListView.dispatchTouchEvent(event);
}
}
break;
}
case MotionEvent.ACTION_MOVE: {
if (mDispatch) {
mDispatchY += (int) event.getY() - mOriginY;
event.setLocation(event.getX(), mDispatchY);
return mNotesListView.dispatchTouchEvent(event);
}
break;
}
default: {
if (mDispatch) {
event.setLocation(event.getX(), mDispatchY);
mDispatch = false;
return mNotesListView.dispatchTouchEvent(event);
}
break;
}
}
return false;
}
};
private void startAsyncNotesListQuery() {
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
: NORMAL_SELECTION;
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] {
String.valueOf(mCurrentFolderId)
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
}
private final class BackgroundQueryHandler extends AsyncQueryHandler {
public BackgroundQueryHandler(ContentResolver contentResolver) {
super(contentResolver);
}
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
switch (token) {
case FOLDER_NOTE_LIST_QUERY_TOKEN:
mNotesListAdapter.changeCursor(cursor);
break;
case FOLDER_LIST_QUERY_TOKEN:
if (cursor != null && cursor.getCount() > 0) {
showFolderListMenu(cursor);
} else {
Log.e(TAG, "Query folder failed");
}
break;
default:
return;
}
}
}
private void showFolderListMenu(Cursor cursor) {
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
builder.setTitle(R.string.menu_title_select_folder);
final FoldersListAdapter adapter = new FoldersListAdapter(this, cursor);
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
DataUtils.batchMoveToFolder(mContentResolver,
mNotesListAdapter.getSelectedItemIds(), adapter.getItemId(which));
Toast.makeText(
NotesListActivity.this,
getString(R.string.format_move_notes_to_folder,
mNotesListAdapter.getSelectedCount(),
adapter.getFolderName(NotesListActivity.this, which)),
Toast.LENGTH_SHORT).show();
mModeCallBack.finishActionMode();
}
});
builder.show();
}
private void createNewNote() {
Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mCurrentFolderId);
this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
}
private void batchDelete() {
new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() {
protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) {
HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget();
if (!isSyncMode()) {
// if not synced, delete notes directly
if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter
.getSelectedItemIds())) {
} else {
Log.e(TAG, "Delete notes error, should not happens");
}
} else {
// in sync mode, we'll move the deleted note into the trash
// folder
if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter
.getSelectedItemIds(), Notes.ID_TRASH_FOLER)) {
Log.e(TAG, "Move notes to trash folder error, should not happens");
}
}
return widgets;
}
@Override
protected void onPostExecute(HashSet<AppWidgetAttribute> widgets) {
if (widgets != null) {
for (AppWidgetAttribute widget : widgets) {
if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& widget.widgetType != Notes.TYPE_WIDGET_INVALIDE) {
updateWidget(widget.widgetId, widget.widgetType);
}
}
}
mModeCallBack.finishActionMode();
}
}.execute();
}
private void deleteFolder(long folderId) {
if (folderId == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Wrong folder id, should not happen " + folderId);
return;
}
HashSet<Long> ids = new HashSet<Long>();
ids.add(folderId);
HashSet<AppWidgetAttribute> widgets = DataUtils.getFolderNoteWidget(mContentResolver,
folderId);
if (!isSyncMode()) {
// if not synced, delete folder directly
DataUtils.batchDeleteNotes(mContentResolver, ids);
} else {
// in sync mode, we'll move the deleted folder into the trash folder
DataUtils.batchMoveToFolder(mContentResolver, ids, Notes.ID_TRASH_FOLER);
}
if (widgets != null) {
for (AppWidgetAttribute widget : widgets) {
if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& widget.widgetType != Notes.TYPE_WIDGET_INVALIDE) {
updateWidget(widget.widgetId, widget.widgetType);
}
}
}
}
private void openNode(NoteItemData data) {
Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(Intent.EXTRA_UID, data.getId());
this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
}
private void openFolder(NoteItemData data) {
mCurrentFolderId = data.getId();
startAsyncNotesListQuery();
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
mState = ListEditState.CALL_RECORD_FOLDER;
mAddNewNote.setVisibility(View.GONE);
} else {
mState = ListEditState.SUB_FOLDER;
}
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
mTitleBar.setText(R.string.call_record_folder_name);
} else {
mTitleBar.setText(data.getSnippet());
}
mTitleBar.setVisibility(View.VISIBLE);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_new_note:
createNewNote();
break;
default:
break;
}
}
private void showSoftInput() {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
}
private void hideSoftInput(View view) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
private void showCreateOrModifyFolderDialog(final boolean create) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
final EditText etName = (EditText) view.findViewById(R.id.et_foler_name);
showSoftInput();
if (!create) {
if (mFocusNoteDataItem != null) {
etName.setText(mFocusNoteDataItem.getSnippet());
builder.setTitle(getString(R.string.menu_folder_change_name));
} else {
Log.e(TAG, "The long click data item is null");
return;
}
} else {
etName.setText("");
builder.setTitle(this.getString(R.string.menu_create_folder));
}
builder.setPositiveButton(android.R.string.ok, null);
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
hideSoftInput(etName);
}
});
final Dialog dialog = builder.setView(view).show();
final Button positive = (Button)dialog.findViewById(android.R.id.button1);
positive.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
hideSoftInput(etName);
String name = etName.getText().toString();
if (DataUtils.checkVisibleFolderName(mContentResolver, name)) {
Toast.makeText(NotesListActivity.this, getString(R.string.folder_exist, name),
Toast.LENGTH_LONG).show();
etName.setSelection(0, etName.length());
return;
}
if (!create) {
if (!TextUtils.isEmpty(name)) {
ContentValues values = new ContentValues();
values.put(NoteColumns.SNIPPET, name);
values.put(NoteColumns.TYPE, Notes.TYPE_FOLDER);
values.put(NoteColumns.LOCAL_MODIFIED, 1);
mContentResolver.update(Notes.CONTENT_NOTE_URI, values, NoteColumns.ID
+ "=?", new String[] {
String.valueOf(mFocusNoteDataItem.getId())
});
}
} else if (!TextUtils.isEmpty(name)) {
ContentValues values = new ContentValues();
values.put(NoteColumns.SNIPPET, name);
values.put(NoteColumns.TYPE, Notes.TYPE_FOLDER);
mContentResolver.insert(Notes.CONTENT_NOTE_URI, values);
}
dialog.dismiss();
}
});
if (TextUtils.isEmpty(etName.getText())) {
positive.setEnabled(false);
}
/**
* When the name edit text is null, disable the positive button
*/
etName.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (TextUtils.isEmpty(etName.getText())) {
positive.setEnabled(false);
} else {
positive.setEnabled(true);
}
}
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
}
/* (non-Javadoc)
* @see android.app.Activity#onBackPressed()
*
*/
@Override
public void onBackPressed() {
switch (mState) {
case SUB_FOLDER:
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
mState = ListEditState.NOTE_LIST;
startAsyncNotesListQuery();
mTitleBar.setVisibility(View.GONE);
break;
case CALL_RECORD_FOLDER:
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
mState = ListEditState.NOTE_LIST;
mAddNewNote.setVisibility(View.VISIBLE);
mTitleBar.setVisibility(View.GONE);
startAsyncNotesListQuery();
break;
case NOTE_LIST:
super.onBackPressed();
break;
default:
break;
}
}
//根据不同类型的weight更新插件通过intent传送数据
private void updateWidget(int appWidgetId, int appWidgetType) {
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
if (appWidgetType == Notes.TYPE_WIDGET_2X) {
intent.setClass(this, NoteWidgetProvider_2x.class);
} else if (appWidgetType == Notes.TYPE_WIDGET_4X) {
intent.setClass(this, NoteWidgetProvider_4x.class);
} else {
Log.e(TAG, "Unspported widget type");
return;
}
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
appWidgetId
});
sendBroadcast(intent);
setResult(RESULT_OK, intent);
}
//声明监听器,建立菜单,包括名称,视图,删除操作,更改名称操作
private final OnCreateContextMenuListener mFolderOnCreateContextMenuListener = new OnCreateContextMenuListener() {
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
if (mFocusNoteDataItem != null) {
menu.setHeaderTitle(mFocusNoteDataItem.getSnippet());
menu.add(0, MENU_FOLDER_VIEW, 0, R.string.menu_folder_view);
menu.add(0, MENU_FOLDER_DELETE, 0, R.string.menu_folder_delete);
menu.add(0, MENU_FOLDER_CHANGE_NAME, 0, R.string.menu_folder_change_name);
}
}
};
@Override
public void onContextMenuClosed(Menu menu) {
if (mNotesListView != null) {
mNotesListView.setOnCreateContextMenuListener(null);
}
super.onContextMenuClosed(menu);
}
//针对menu中不同的选择进行不同的处理
@Override
public boolean onContextItemSelected(MenuItem item) {
if (mFocusNoteDataItem == null) {
Log.e(TAG, "The long click data item is null");
return false;
}
switch (item.getItemId()) {
case MENU_FOLDER_VIEW:
openFolder(mFocusNoteDataItem); //打开对应文件
break;
case MENU_FOLDER_DELETE:
AlertDialog.Builder builder = new AlertDialog.Builder(this); //设置确认是否删除的对话框
builder.setTitle(getString(R.string.alert_title_delete));
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setMessage(getString(R.string.alert_message_delete_folder));
builder.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
deleteFolder(mFocusNoteDataItem.getId());
}
});
builder.setNegativeButton(android.R.string.cancel, null);
builder.show(); //显示对话框
break;
case MENU_FOLDER_CHANGE_NAME:
showCreateOrModifyFolderDialog(false);
break;
default:
break;
}
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear();
if (mState == ListEditState.NOTE_LIST) {
getMenuInflater().inflate(R.menu.note_list, menu);
// set sync or sync_cancel
menu.findItem(R.id.menu_sync).setTitle(
GTaskSyncService.isSyncing() ? R.string.menu_sync_cancel : R.string.menu_sync);
} else if (mState == ListEditState.SUB_FOLDER) {
getMenuInflater().inflate(R.menu.sub_folder, menu);
} else if (mState == ListEditState.CALL_RECORD_FOLDER) {
getMenuInflater().inflate(R.menu.call_record_folder, menu);
} else {
Log.e(TAG, "Wrong state:" + mState);
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_new_folder: {
showCreateOrModifyFolderDialog(true);
break;
}
case R.id.menu_export_text: {
exportNoteToText();
break;
}
case R.id.menu_sync: {
if (isSyncMode()) {
if (TextUtils.equals(item.getTitle(), getString(R.string.menu_sync))) {
GTaskSyncService.startSync(this);
} else {
GTaskSyncService.cancelSync(this);
}
} else {
startPreferenceActivity();
}
break;
}
case R.id.menu_setting: {
startPreferenceActivity();
break;
}
case R.id.menu_new_note: {
createNewNote();
break;
}
case R.id.menu_search:
onSearchRequested();
break;
default:
break;
}
return true;
}
//直接调用startSearch函数
@Override
public boolean onSearchRequested() {
startSearch(null, false, null /* appData */, false);
return true;
}
//实现将便签导出到文本的功能
private void exportNoteToText() {
final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this);
new AsyncTask<Void, Void, Integer>() {
@Override
protected Integer doInBackground(Void... unused) {
return backup.exportToText();
}
@Override
protected void onPostExecute(Integer result) {
if (result == BackupUtils.STATE_SD_CARD_UNMOUONTED) {
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
builder.setTitle(NotesListActivity.this
.getString(R.string.failed_sdcard_export));
builder.setMessage(NotesListActivity.this
.getString(R.string.error_sdcard_unmounted));
builder.setPositiveButton(android.R.string.ok, null);
builder.show();
} else if (result == BackupUtils.STATE_SUCCESS) {
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
builder.setTitle(NotesListActivity.this
.getString(R.string.success_sdcard_export));
builder.setMessage(NotesListActivity.this.getString(
R.string.format_exported_file_location, backup
.getExportedTextFileName(), backup.getExportedTextFileDir()));
builder.setPositiveButton(android.R.string.ok, null);
builder.show();
} else if (result == BackupUtils.STATE_SYSTEM_ERROR) {
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
builder.setTitle(NotesListActivity.this
.getString(R.string.failed_sdcard_export));
builder.setMessage(NotesListActivity.this
.getString(R.string.error_sdcard_export));
builder.setPositiveButton(android.R.string.ok, null);
builder.show();
}
}
}.execute();
}
//判断是否正在同步
private boolean isSyncMode() {
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
}
//跳转到preferenceActivity界面
private void startPreferenceActivity() {
Activity from = getParent() != null ? getParent() : this;
Intent intent = new Intent(from, NotesPreferenceActivity.class);
from.startActivityIfNeeded(intent, -1);
}
//实现对便签列表项的点击事件
private class OnListItemClickListener implements OnItemClickListener {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (view instanceof NotesListItem) {
NoteItemData item = ((NotesListItem) view).getItemData();
if (mNotesListAdapter.isInChoiceMode()) {
if (item.getType() == Notes.TYPE_NOTE) {
position = position - mNotesListView.getHeaderViewsCount();
mModeCallBack.onItemCheckedStateChanged(null, position, id,
!mNotesListAdapter.isSelectedItem(position));
}
return;
}
switch (mState) {
case NOTE_LIST:
if (item.getType() == Notes.TYPE_FOLDER
|| item.getType() == Notes.TYPE_SYSTEM) {
openFolder(item);
} else if (item.getType() == Notes.TYPE_NOTE) {
openNode(item);
} else {
Log.e(TAG, "Wrong note type in NOTE_LIST");
}
break;
case SUB_FOLDER:
case CALL_RECORD_FOLDER:
if (item.getType() == Notes.TYPE_NOTE) {
openNode(item);
} else {
Log.e(TAG, "Wrong note type in SUB_FOLDER");
}
break;
default:
break;
}
}
}
}
//查询目标文件
private void startQueryDestinationFolders() {
String selection = NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>? AND " + NoteColumns.ID + "<>?";
selection = (mState == ListEditState.NOTE_LIST) ? selection:
"(" + selection + ") OR (" + NoteColumns.ID + "=" + Notes.ID_ROOT_FOLDER + ")";
mBackgroundQueryHandler.startQuery(FOLDER_LIST_QUERY_TOKEN,
null,
Notes.CONTENT_NOTE_URI,
FoldersListAdapter.PROJECTION,
selection,
new String[] {
String.valueOf(Notes.TYPE_FOLDER),
String.valueOf(Notes.ID_TRASH_FOLER),
String.valueOf(mCurrentFolderId)
},
NoteColumns.MODIFIED_DATE + " DESC");
}
/*
*便ActionModeContextMenu
*/
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (view instanceof NotesListItem) {
mFocusNoteDataItem = ((NotesListItem) view).getItemData();
if (mFocusNoteDataItem.getType() == Notes.TYPE_NOTE && !mNotesListAdapter.isInChoiceMode()) {
if (mNotesListView.startActionMode(mModeCallBack) != null) {
mModeCallBack.onItemCheckedStateChanged(null, position, id, true);
mNotesListView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
} else {
Log.e(TAG, "startActionMode fails");
}
} else if (mFocusNoteDataItem.getType() == Notes.TYPE_FOLDER) {
mNotesListView.setOnCreateContextMenuListener(mFolderOnCreateContextMenuListener);
}
}
return false;
}
}

@ -0,0 +1,217 @@
/*
* 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.ui;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import net.micode.notes.data.Notes;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
/*便CursorAdaptercursorListView
* NotesListAdapter便
*/
public class NotesListAdapter extends CursorAdapter {
private static final String TAG = "NotesListAdapter";
private Context mContext;
private HashMap<Integer, Boolean> mSelectedIndex;
private int mNotesCount;//便签数
private boolean mChoiceMode;//选择模式标记
//桌面weight的属性包括编号和类型
public static class AppWidgetAttribute {
public int widgetId;
public int widgetType;
};
//函数功能:初始化便签链接器
//函数实现:根据传进来的内容设置相关变量
public NotesListAdapter(Context context) {
super(context, null); //父类对象置空
mSelectedIndex = new HashMap<Integer, Boolean>();//新建选项下的hash表
mContext = context;
mNotesCount = 0;
}
//函数功能:新建一个视图来存储光标所指向的数据
//函数实现使用兄弟类NotesListItem新建一个项目选项
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new NotesListItem(context);
}
//函数功能:将已经存在的视图和鼠标指向的数据进行捆绑
@Override
public void bindView(View view, Context context, Cursor cursor) {
if (view instanceof NotesListItem) {
//若view是NotesListItem的一个实例
//则新建一个项目选项并且用bind跟将view和鼠标内容便签数据捆绑在一起
NoteItemData itemData = new NoteItemData(context, cursor);
((NotesListItem) view).bind(context, itemData, mChoiceMode,
isSelectedItem(cursor.getPosition()));
}
}
//函数功能:设置勾选框
public void setCheckedItem(final int position, final boolean checked) {
mSelectedIndex.put(position, checked);//根据定位和是否勾选设置下标
notifyDataSetChanged();//在修改后刷新activity
}
//函数功能:判断单选按钮是否勾选
public boolean isInChoiceMode() {
return mChoiceMode;
}
//函数功能:设置单项选项框
//函数实现重置下标并且根据参数mode设置选项
public void setChoiceMode(boolean mode) {
mSelectedIndex.clear();
mChoiceMode = mode;
}
//函数功能:选择全部选项
public void selectAll(boolean checked) {
Cursor cursor = getCursor();//获取光标位置
for (int i = 0; i < getCount(); i++) {
if (cursor.moveToPosition(i)) {
if (NoteItemData.getNoteType(cursor) == Notes.TYPE_NOTE) {
setCheckedItem(i, checked);
}
}
} //遍历所有光标可用的位置在判断为便签类型之后勾选单项框
}
//函数功能:建立选择项的下标列表
public HashSet<Long> getSelectedItemIds() {
HashSet<Long> itemSet = new HashSet<Long>();//建立hash表
for (Integer position : mSelectedIndex.keySet()) {
//遍历所有的关键
if (mSelectedIndex.get(position) == true) {
//若光标位置可用
Long id = getItemId(position);
if (id == Notes.ID_ROOT_FOLDER) {
//原文件不需要添加
Log.d(TAG, "Wrong item id, should not happen");
} else {
itemSet.add(id);
}
}
}
return itemSet;
}
//函数功能建立桌面Widget的选项表
public HashSet<AppWidgetAttribute> getSelectedWidget() {
HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>();
for (Integer position : mSelectedIndex.keySet()) {
if (mSelectedIndex.get(position) == true) {
Cursor c = (Cursor) getItem(position);
if (c != null) {
//光标位置可用的话就建立新的Widget属性并编辑下标和类型最后添加到选项集中
AppWidgetAttribute widget = new AppWidgetAttribute();
NoteItemData item = new NoteItemData(mContext, c);
widget.widgetId = item.getWidgetId();
widget.widgetType = item.getWidgetType();
itemSet.add(widget);
/**
* Don't close cursor here, only the adapter could close it
*/
} else {
Log.e(TAG, "Invalid cursor");
return null;
}
}
}
return itemSet;
}
//函数功能:获取选项个数
public int getSelectedCount() {
Collection<Boolean> values = mSelectedIndex.values();//首先获取选项下标的值
if (null == values) {
return 0;
}
Iterator<Boolean> iter = values.iterator();
int count = 0;//初始化叠加器
while (iter.hasNext()) {
if (true == iter.next()) {
//若value值为真计数+1
count++;
}
}
return count;
}
//函数功能:判断是否全部选中
public boolean isAllSelected() {
int checkedCount = getSelectedCount();
return (checkedCount != 0 && checkedCount == mNotesCount);//获取选项数看是否等于便签的个数
}
//函数功能:判断是否为选项表
//函数实现:通过传递的下标来确定
public boolean isSelectedItem(final int position) {
if (null == mSelectedIndex.get(position)) {
return false;
}
return mSelectedIndex.get(position);
}
//函数功能在activity内容发生局部变动的时候回调该函数计算便签的数量
@Override
protected void onContentChanged() {
super.onContentChanged();
calcNotesCount();
}
@Override
//函数功能在activity光标发生局部变动的时候回调该函数计算便签的数量
public void changeCursor(Cursor cursor) {
super.changeCursor(cursor);
//执行基类函数
calcNotesCount();
}
//计算便签数量
private void calcNotesCount() {
mNotesCount = 0;
for (int i = 0; i < getCount(); i++) {
//获取总数时,同时遍历
Cursor c = (Cursor) getItem(i);
if (c != null) {
if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) {
//若该位置不为空并且文本类型为便签就+1
mNotesCount++;
}
} else {
//否则报错
Log.e(TAG, "Invalid cursor");
return;
}
}
}
}

@ -0,0 +1,134 @@
/*
* 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.ui;
import android.content.Context;
import android.text.format.DateUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.tool.DataUtils;
import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
//创建便签列表项目选项
public class NotesListItem extends LinearLayout {
private ImageView mAlert; //闹钟图片
private TextView mTitle; //标题
private TextView mTime; //时间
private TextView mCallName;
private NoteItemData mItemData; //标签数据
private CheckBox mCheckBox; //打勾框
//初始化基本信息
public NotesListItem(Context context) {
super(context); //super()的主要作用是调整调用父类构造函数的顺序
inflate(context, R.layout.note_item, this);//Inflate可用于将一个xml中定义的布局控件找出来,这里的xml是rlayout
//findViewById用于从contentView中查找指定ID的View转换出来的形式根据需要而定
mAlert = (ImageView) findViewById(R.id.iv_alert_icon);
mTitle = (TextView) findViewById(R.id.tv_title);
mTime = (TextView) findViewById(R.id.tv_time);
mCallName = (TextView) findViewById(R.id.tv_name);
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
}
//根据data的属性对各个控件的属性的控制主要是可见性Visibility内容setText格式setTextAppearance
public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {
if (choiceMode && data.getType() == Notes.TYPE_NOTE) {
mCheckBox.setVisibility(View.VISIBLE); //设置可见行为为可见
mCheckBox.setChecked(checked); //格子打勾
} else {
mCheckBox.setVisibility(View.GONE);
}
mItemData = data;
//设置控件属性一共三种情况由data的id和父id是否与保存到文件夹的id一致来决定
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
mCallName.setVisibility(View.GONE);
mAlert.setVisibility(View.VISIBLE);
//设置该textview的style
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);
//settext为设置内容
mTitle.setText(context.getString(R.string.call_record_folder_name)
+ context.getString(R.string.format_folder_files_count, data.getNotesCount()));
mAlert.setImageResource(R.drawable.call_record);
} else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) {
mCallName.setVisibility(View.VISIBLE);
mCallName.setText(data.getCallName());
mTitle.setTextAppearance(context,R.style.TextAppearanceSecondaryItem);
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));
//关于闹钟的设置
if (data.hasAlert()) {
mAlert.setImageResource(R.drawable.clock); //设置图片来源
mAlert.setVisibility(View.VISIBLE);
} else {
mAlert.setVisibility(View.GONE);
}
} else {
mCallName.setVisibility(View.GONE);
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);
//设置title格式
if (data.getType() == Notes.TYPE_FOLDER) {
mTitle.setText(data.getSnippet()
+ context.getString(R.string.format_folder_files_count,
data.getNotesCount()));
mAlert.setVisibility(View.GONE);
} else {
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));
if (data.hasAlert()) {
mAlert.setImageResource(R.drawable.clock);
mAlert.setVisibility(View.VISIBLE);
} else {
mAlert.setVisibility(View.GONE);
}
}
}
//设置内容获取相关时间从data里编辑的日期中获取
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));
setBackground(data);
}
//根据data的文件属性来设置背景
private void setBackground(NoteItemData data) {
int id = data.getBgColorId();
//若是note型文件则一4种情况对于4种不同情况的背景来源
if (data.getType() == Notes.TYPE_NOTE) {
//单个数据并且只有一个子文件夹
if (data.isSingle() || data.isOneFollowingFolder()) {
setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id));
} else if (data.isLast()) {//是最后一个数据
setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id));
} else if (data.isFirst() || data.isMultiFollowingFolder()) {//是一个数据并有多个子文件夹
setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id));
} else {
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id));
}
} else {
//若不是note直接调用文件夹的背景来源
setBackgroundResource(NoteItemBgResources.getFolderBgRes());
}
}
public NoteItemData getItemData() {
return mItemData;
}
}

@ -0,0 +1,474 @@
/*
* 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.ui;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.gtask.remote.GTaskSyncService;
/*NotesPreferenceActivity便
*PreferenceActivityActivity
*/
public class NotesPreferenceActivity extends PreferenceActivity {
//优先名
public static final String PREFERENCE_NAME = "notes_preferences";
//同步账号
public static final String PREFERENCE_SYNC_ACCOUNT_NAME = "pref_key_account_name";
//同步时间
public static final String PREFERENCE_LAST_SYNC_TIME = "pref_last_sync_time";
public static final String PREFERENCE_SET_BG_COLOR_KEY = "pref_key_bg_random_appear";
//同步密码
private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key";
//本地密码
private static final String AUTHORITIES_FILTER_KEY = "authorities";
//账户分组
private PreferenceCategory mAccountCategory;
//同步任务接收器
private GTaskReceiver mReceiver;
//账户
private Account[] mOriAccounts;
//账户的hash标记
private boolean mHasAddedAccount;
@Override
/*activity
*Bundle icicle activity
*/
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);//先执行父类的创建函数
/* using the app icon for navigation */
getActionBar().setDisplayHomeAsUpEnabled(true);//给左上角的图标加上一个返回的图标
addPreferencesFromResource(R.xml.preferences);//添加xml来源并显示xml
mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);//根据同步账户关键码来初始化分组
mReceiver = new GTaskReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME);
registerReceiver(mReceiver, filter);//初始化同步组件
mOriAccounts = null;
//获取listvivewListView的作用:用于列出所有选择
View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null);
//在listview组件上方添加其他组件
getListView().addHeaderView(header, null, true);
}
@Override
//函数功能activity交互功能的实现用于接受用户的输入
protected void onResume() {
//先执行父类的交互实现
super.onResume();
// need to set sync account automatically if user has added a new
// account
if (mHasAddedAccount) {
//若用户新加了账户,则自动设置同步账户
Account[] accounts = getGoogleAccounts();//获取谷歌同步账户
if (mOriAccounts != null && accounts.length > mOriAccounts.length) {
//若原账户不为空且当前账户有添加
for (Account accountNew : accounts) {
boolean found = false;
for (Account accountOld : mOriAccounts) {
if (TextUtils.equals(accountOld.name, accountNew.name)) {
//更新账户
found = true;
break;
}
}
if (!found) {
//若没有找到旧帐户,则同步账户中就只添加新账户
setSyncAccount(accountNew.name);
break;
}
}
}
}
refreshUI();//刷新标签界面
}
@Override
//函数功能销毁一个activity
protected void onDestroy() {
if (mReceiver != null) {
unregisterReceiver(mReceiver);//注销接收器
}
super.onDestroy();//执行父类的销毁动作
}
//函数功能:重新设置账户信息
private void loadAccountPreference() {
mAccountCategory.removeAll();
//销毁所有分组
Preference accountPref = new Preference(this);
//建立首选项
final String defaultAccount = getSyncAccountName(this);
accountPref.setTitle(getString(R.string.preferences_account_title));
accountPref.setSummary(getString(R.string.preferences_account_summary));
//设置首选项的大标题和小标题
accountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
//建立监听器
if (!GTaskSyncService.isSyncing()) {
if (TextUtils.isEmpty(defaultAccount)) {
// the first time to set account
//若是第一次建立账户,则显示选择账户提示框
showSelectAccountAlertDialog();
} else {
// if the account has already been set, we need to promp
// user about the risk
//若是已经建立,则显示修改对话框并进行修改操作
showChangeAccountConfirmAlertDialog();
}
} else {
//若在没有同步的情况下则在toast中显示不能修改
Toast.makeText(NotesPreferenceActivity.this,
R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT)
.show();
}
return true;
}
});
//根据新建首选项编辑新的账户分组
mAccountCategory.addPreference(accountPref);
}
//函数功能:设置按键的状态和最后同步的时间
private void loadSyncButton() {
Button syncButton = (Button) findViewById(R.id.preference_sync_button);
//获取同步按钮控件和最终同步时间的的窗口
TextView lastSyncTimeView = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
// set button state
// 设置按钮的状态
if (GTaskSyncService.isSyncing()) {
//若是在同步的状态下
syncButton.setText(getString(R.string.preferences_button_sync_cancel));
syncButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
GTaskSyncService.cancelSync(NotesPreferenceActivity.this);
}
});//设置按钮显示的文本为“取消同步”以及监听器
} else {
syncButton.setText(getString(R.string.preferences_button_sync_immediately));
syncButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
GTaskSyncService.startSync(NotesPreferenceActivity.this);
}
});//若是不同步则设置按钮显示的文本为“立即同步”以及对应监听器
}
//设置按键可用还是不可用
syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this)));
// set last sync time
// 设置最终同步时间
if (GTaskSyncService.isSyncing()) {
//若是在同步的情况下
lastSyncTimeView.setText(GTaskSyncService.getProgressString());
lastSyncTimeView.setVisibility(View.VISIBLE);
// 根据当前同步服务器设置时间显示框的文本以及可见性
} else {
//若是非同步情况
long lastSyncTime = getLastSyncTime(this);
if (lastSyncTime != 0) {
lastSyncTimeView.setText(getString(R.string.preferences_last_sync_time,
DateFormat.format(getString(R.string.preferences_last_sync_time_format),
lastSyncTime)));
lastSyncTimeView.setVisibility(View.VISIBLE);
//则根据最后同步时间的信息来编辑时间显示框的文本内容和可见性
} else {
//若时间为空直接设置为不可见状态
lastSyncTimeView.setVisibility(View.GONE);
}
}
}
/*
*
*/
private void refreshUI() {
loadAccountPreference();
loadSyncButton();
}
/*
*
*/
private void showSelectAccountAlertDialog() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
//创建一个新的对话框
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
titleTextView.setText(getString(R.string.preferences_dialog_select_account_title));
TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
subtitleTextView.setText(getString(R.string.preferences_dialog_select_account_tips));
//设置标题以及子标题的内容
dialogBuilder.setCustomTitle(titleView);
dialogBuilder.setPositiveButton(null, null);
//设置对话框的自定义标题建立一个YES的按钮
Account[] accounts = getGoogleAccounts();
String defAccount = getSyncAccountName(this);
//设置对话框的自定义标题建立一个YES的按钮
mOriAccounts = accounts;
mHasAddedAccount = false;
if (accounts.length > 0) {
//若账户不为空
CharSequence[] items = new CharSequence[accounts.length];
final CharSequence[] itemMapping = items;
int checkedItem = -1;
int index = 0;
for (Account account : accounts) {
if (TextUtils.equals(account.name, defAccount)) {
checkedItem = index;
//在账户列表中查询到所需账户
}
items[index++] = account.name;
}
dialogBuilder.setSingleChoiceItems(items, checkedItem,
//在对话框建立一个单选的复选框
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
setSyncAccount(itemMapping[which].toString());
dialog.dismiss();//取消对话框
refreshUI();
}//设置点击后执行的事件,包括检录新同步账户和刷新标签界面
});
}
View addAccountView = LayoutInflater.from(this).inflate(R.layout.add_account_text, null);
dialogBuilder.setView(addAccountView);
//给新加账户对话框设置自定义样式
final AlertDialog dialog = dialogBuilder.show();
//显示对话框
addAccountView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mHasAddedAccount = true;//将新加账户的hash置true
Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
//建立网络建立组件
intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] {
"gmail-ls"
});
//跳回上一个选项
startActivityForResult(intent, -1);
dialog.dismiss();
}
});//建立新加账户对话框的监听器
}
//函数功能:显示账户选择对话框和相关账户操作
private void showChangeAccountConfirmAlertDialog() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
//创建一个新的对话框
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
titleTextView.setText(getString(R.string.preferences_dialog_change_account_title,
getSyncAccountName(this)));
TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
//根据同步修改的账户信息设置标题以及子标题的内容
subtitleTextView.setText(getString(R.string.preferences_dialog_change_account_warn_msg));
//设置对话框的自定义标题
dialogBuilder.setCustomTitle(titleView);
//定义一些标记字符串
CharSequence[] menuItemArray = new CharSequence[] {
getString(R.string.preferences_menu_change_account),
getString(R.string.preferences_menu_remove_account),
getString(R.string.preferences_menu_cancel)
};
dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() {
//设置对话框要显示的一个list用于显示几个命令时,即changeremovecancel
public void onClick(DialogInterface dialog, int which) {//按键功能由which来决定
if (which == 0) {
//进入账户选择对话框
showSelectAccountAlertDialog();
} else if (which == 1) {
//删除账户并且跟新便签界面
removeSyncAccount();
refreshUI();
}
}
});
dialogBuilder.show();//显示对话框
}
/*
*
*/
private Account[] getGoogleAccounts() {
AccountManager accountManager = AccountManager.get(this);
return accountManager.getAccountsByType("com.google");
}
//函数功能:设置同步账户
private void setSyncAccount(String account) {
if (!getSyncAccountName(this).equals(account)) {
//假如该账号不在同步账号列表中
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();//编辑共享的首选项
if (account != null) {
editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, account);
} else {
editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
}//将该账号加入到首选项中
editor.commit();//提交修改的数据
// clean up last sync time
setLastSyncTime(this, 0);
//将最后同步时间清零
// clean up local gtask related info
new Thread(new Runnable() {
public void run() {
ContentValues values = new ContentValues();
values.put(NoteColumns.GTASK_ID, "");
values.put(NoteColumns.SYNC_ID, 0);
getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
}
}).start(); //重置当地同步任务的信息
//将toast的文本信息置为“设置账户成功”并显示出来
Toast.makeText(NotesPreferenceActivity.this,
getString(R.string.preferences_toast_success_set_accout, account),
Toast.LENGTH_SHORT).show();
}
}
//函数功能:删除同步账户
private void removeSyncAccount() {
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
//设置共享首选项
if (settings.contains(PREFERENCE_SYNC_ACCOUNT_NAME)) {
//假如当前首选项中有账户就删除
editor.remove(PREFERENCE_SYNC_ACCOUNT_NAME);
}
if (settings.contains(PREFERENCE_LAST_SYNC_TIME)) {
editor.remove(PREFERENCE_LAST_SYNC_TIME);
//删除当前首选项中有账户时间
}
//提交更新后的数据
editor.commit();
// clean up local gtask related info
new Thread(new Runnable() {
public void run() {
ContentValues values = new ContentValues();
values.put(NoteColumns.GTASK_ID, "");
values.put(NoteColumns.SYNC_ID, 0);
getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
}
}).start();//重置当地同步任务的信息
}
/*
*
*/
public static String getSyncAccountName(Context context) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
Context.MODE_PRIVATE);
return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
}
//函数功能:设置最终同步的时间
public static void setLastSyncTime(Context context, long time) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
//从共享首选项中找到相关账户并获取其编辑器
editor.putLong(PREFERENCE_LAST_SYNC_TIME, time);
editor.commit();
//编辑最终同步时间并提交更新
}
/*
*
*/
public static long getLastSyncTime(Context context) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
Context.MODE_PRIVATE);
return settings.getLong(PREFERENCE_LAST_SYNC_TIME, 0);
}
/*
*BroadcastReceiver
*/
private class GTaskReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
refreshUI();
if (intent.getBooleanExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_IS_SYNCING, false)) {
//获取随广播而来的Intent中的同步服务的数据
TextView syncStatus = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
syncStatus.setText(intent
.getStringExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_PROGRESS_MSG));
//通过获取的数据在设置系统的状态
}
}
}
/*
*
*:MenuItem
*/
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
//根据选项的id选择这里只有一个主页
case android.R.id.home:
Intent intent = new Intent(this, NotesListActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
//在主页情况下在创建连接组件intent发出清空的信号并开始一个相应的activity
default:
return false;
}
}
}

@ -0,0 +1,204 @@
/*
* 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.
*/
import android.app.Activity; //创建显示窗口
import android.app.AlertDialog; //
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.PowerManager;
import android.provider.Settings;
import android.view.Window;
import android.view.WindowManager;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.tool.DataUtils;
import net.micode.notes.ui.NoteEditActivity;
import java.io.IOException;
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
private long mNoteId; //从数据库中获取便签的ID号
private String mSnippet;//闹钟提示时出现的文本片段
private static final int SNIPPET_PREW_MAX_LEN = 60; //文本最大值
MediaPlayer mPlayer;
@Override
//onCreate的作用是创建view、将数据绑定到list等等
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Bundle类型的数据与Map的数据类型类似都是以key-value的形式存储数据的
//savedInstanceState方法是用来保存Activity的状态的
requestWindowFeature(Window.FEATURE_NO_TITLE);
//界面显示-无标题
final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
//在手机锁屏后如果到了闹钟提示时间,点亮屏幕
if (!isScreenOn()) {
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
//保持窗口点亮
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
//将窗体点亮
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
//允许窗体点亮时锁屏
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
}
Intent intent = getIntent(); //获取一个整数
try {
//对ID进行初始化操作
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1));
//根据ID从数据库中获取指定的标签内容
//this.getContentResolver()是实现数据共享,存储实例
mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);
//判断mSnippet是否符合标准长度
mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0,
SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info)
: mSnippet;
} catch (IllegalArgumentException e) {
e.printStackTrace(); //在命令行打印异常信息在程序中出错的位置及原因
return;
}
mPlayer = new MediaPlayer(); //初始化
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
showActionDialog(); //弹出对话框
playAlarmSound(); //闹钟提示音激发
} else {
finish(); //完成闹钟动作
}
}
//判断屏幕是否锁屏,调用系统函数判断,最后返回值是布尔类型
private boolean isScreenOn() {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
return pm.isScreenOn();
}
//闹钟提示音激发
private void playAlarmSound() {
//调用系统的铃声管理URI得到闹钟提示音
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
int silentModeStreams = Settings.System.getInt(getContentResolver(),
Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) {
mPlayer.setAudioStreamType(silentModeStreams);
} else {
mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
}
try {
//方法setDataSource(Context context, Uri uri)
//解释:无返回值,设置多媒体数据来源【根据 Uri】
mPlayer.setDataSource(this, url);
//准备同步
mPlayer.prepare();
//设置是否循环播放
mPlayer.setLooping(true);
//开始播放
mPlayer.start();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
//e.printStackTrace()函数功能是抛出异常, 还将显示出更深的调用信息
//System.out.println(e),这个方法打印出异常,并且输出在哪里出现的异常
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void showActionDialog() {
//AlertDialog的构造方法全部是Protected的
//所以不能直接通过new一个AlertDialog来创建出一个AlertDialog。
//要创建一个AlertDialog就要用到AlertDialog.Builder中的create()方法
//如这里的dialog就是新建了一个AlertDialog
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
//为对话框设置标题
dialog.setTitle(R.string.app_name);
//为对话框设置内容
dialog.setMessage(mSnippet);
//给对话框添加"Yes"按钮
dialog.setPositiveButton(R.string.notealert_ok, this);
//对话框添加"No"按钮
if (isScreenOn()) {
dialog.setNegativeButton(R.string.notealert_enter, this);
}
dialog.show().setOnDismissListener(this);
}
public void onClick(DialogInterface dialog, int which) {
//用which来选择click后下一步的操作
switch (which) {
//这是取消操作
case DialogInterface.BUTTON_NEGATIVE:
//实现两个类间的数据传输
Intent intent = new Intent(this, NoteEditActivity.class);
//设置动作属性
intent.setAction(Intent.ACTION_VIEW);
//实现key-value对
//EXTRA_UID为keymNoteId为键
intent.putExtra(Intent.EXTRA_UID, mNoteId);
//开始动作
startActivity(intent);
break;
//这是确定操作
default:
break;
}
}
public void onDismiss(DialogInterface dialog) {
//忽略
stopAlarmSound();
//完成该动作
finish();
}
private void stopAlarmSound() {
if (mPlayer != null) {
//停止播放
mPlayer.stop();
mPlayer.release();
//释放MediaPlayer对象
mPlayer = null;
}
}
}

@ -0,0 +1,75 @@
/*
* 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.ui;
import android.app.AlarmManager; //对系统闹钟服务的接口
import android.app.PendingIntent;//获取闹钟通知信息
import android.content.BroadcastReceiver;//接受来自系统和应用的广播并对其进行响应的组件
import android.content.ContentUris;//用来处理“content”的约束uri对象
import android.content.Context;//翻译上下文环境
import android.content.Intent;//解决应用的各项组件之间的通讯
import android.database.Cursor;//数据库的游标操作
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
public class AlarmInitReceiver extends BroadcastReceiver {
//创建对象用例
private static final String [] PROJECTION = new String [] {
NoteColumns.ID,
NoteColumns.ALERTED_DATE
};
//对数据库的操作调用标签ID和闹钟时间
private static final int COLUMN_ID = 0;
private static final int COLUMN_ALERTED_DATE = 1;
//重写onReceive函数
//onReceive是广播的程序执行接收器
@Override
public void onReceive(Context context, Intent intent) {
//System.currentTimeMillis()产生一个当前的毫秒
//这个毫秒从1970年1月1日0时起的毫秒数
long currentDate = System.currentTimeMillis();
//Cursor在这里的作用是通过过查找数据库中的标签内容找到和当前系统时间相等的标签
Cursor c = context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
PROJECTION,
NoteColumns.ALERTED_DATE + ">? AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE,
new String[] { String.valueOf(currentDate) },
null);
//这里是根据数据库里的闹钟时间创建了一个闹钟机制
// 下面的代码主要表现了其中一种创建闹钟机制如新建Intent、PendingIntent以及AlarmManager等
if (c != null) {
if (c.moveToFirst()) {
do {
long alertDate = c.getLong(COLUMN_ALERTED_DATE);
Intent sender = new Intent(context, AlarmReceiver.class);
sender.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, c.getLong(COLUMN_ID)));
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, 0);
AlarmManager alermManager = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
alermManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent);
} while (c.moveToNext());
}
c.close();
}
}
}

@ -0,0 +1,33 @@
/*
* 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.ui;
import android.content.BroadcastReceiver; //接受来自系统和应用的广播并对其进行响应的组件
import android.content.Context; //翻译上下文环境
import android.content.Intent; //解决应用的各项组件之间的通讯
//这个类是实现alarm这个功能最接近用户层的包
//具体的作用还要深究setClass和addFlags
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//启动AlarmAlertActivity
intent.setClass(context, AlarmAlertActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}

@ -0,0 +1,570 @@
/*
* 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.ui;
import java.text.DateFormatSymbols; //用于封装可本地化的日期格式数据的公共类
import java.util.Calendar; //操作日历字段,及其指定的特殊事件字段的转换提供了方法
import net.micode.notes.R;
import android.content.Context; //翻译上下文环境
import android.text.format.DateFormat; //实验/日期的格式化抽象子类
import android.view.View; //以矩形的方式显示在屏幕上,用户界面控件的基础
import android.widget.FrameLayout; //一种框架布局方式
import android.widget.NumberPicker; //预定好的数字控件
public class DateTimePicker extends FrameLayout {
//FrameLayout是布局模板之一
//FrameLayout是布局模板之一
private static final boolean DEFAULT_ENABLE_STATE = true;
private static final int HOURS_IN_HALF_DAY = 12;
private static final int HOURS_IN_ALL_DAY = 24;
private static final int DAYS_IN_ALL_WEEK = 7;
private static final int DATE_SPINNER_MIN_VAL = 0;
private static final int DATE_SPINNER_MAX_VAL = DAYS_IN_ALL_WEEK - 1;
private static final int HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW = 0;
private static final int HOUR_SPINNER_MAX_VAL_24_HOUR_VIEW = 23;
private static final int HOUR_SPINNER_MIN_VAL_12_HOUR_VIEW = 1;
private static final int HOUR_SPINNER_MAX_VAL_12_HOUR_VIEW = 12;
private static final int MINUT_SPINNER_MIN_VAL = 0;
private static final int MINUT_SPINNER_MAX_VAL = 59;
private static final int AMPM_SPINNER_MIN_VAL = 0;
private static final int AMPM_SPINNER_MAX_VAL = 1;
//初始化控件
//NumberPicker是数字选择器
//这里定义的四个变量全部是在设置闹钟时需要选择的变量(如日期、时、分、上午或者下午)
private final NumberPicker mDateSpinner;
private final NumberPicker mHourSpinner;
private final NumberPicker mMinuteSpinner;
private final NumberPicker mAmPmSpinner;
//定义了Calendar类型的变量mDate用于操作时间
private Calendar mDate;
private String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK];
private boolean mIsAm;
private boolean mIs24HourView;
private boolean mIsEnabled = DEFAULT_ENABLE_STATE;
private boolean mInitialising;
private OnDateTimeChangedListener mOnDateTimeChangedListener;
//OnValueChangeListener这是时间改变监听器这里主要是对日期的监听
//将现在日期的值传递给mDate
// updateDateControl()是同步操作
// onDateTimeChanged()是当事件发生改变时发出信号,并传递事件
private NumberPicker.OnValueChangeListener mOnDateChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mDate.add(Calendar.DAY_OF_YEAR, newVal - oldVal);
updateDateControl();
onDateTimeChanged();
}
};
//对小时Hour的监听
private NumberPicker.OnValueChangeListener mOnHourChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
boolean isDateChanged = false;
//声明一个Calendar的变量cal,便于后续的操作
Calendar cal = Calendar.getInstance();
if (!mIs24HourView) {
//这里是对于12小时制时晚上11点和12点交替时对日期的更改
if (!mIsAm && oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY) {
cal.setTimeInMillis(mDate.getTimeInMillis());
cal.add(Calendar.DAY_OF_YEAR, 1);
isDateChanged = true;
}
//这里是对于12小时制时凌晨11点和12点交替时对日期的更改
else if (mIsAm && oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) {
cal.setTimeInMillis(mDate.getTimeInMillis());
cal.add(Calendar.DAY_OF_YEAR, -1);
isDateChanged = true;
}
//这里是对于12小时制时中午11点和12点交替时对AM和PM的更改
if (oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY ||
oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) {
mIsAm = !mIsAm;
updateAmPmControl();
}
}
else {
//这里是对于24小时制时晚上11点和12点交替时对日期的更改
if (oldVal == HOURS_IN_ALL_DAY - 1 && newVal == 0) {
cal.setTimeInMillis(mDate.getTimeInMillis());
cal.add(Calendar.DAY_OF_YEAR, 1);
isDateChanged = true;
}
//这里是对于12小时制时凌晨11点和12点交替时对日期的更改
else if (oldVal == 0 && newVal == HOURS_IN_ALL_DAY - 1) {
cal.setTimeInMillis(mDate.getTimeInMillis());
cal.add(Calendar.DAY_OF_YEAR, -1);
isDateChanged = true;
}
}
//通过数字选择器对newHour的赋值
int newHour = mHourSpinner.getValue() % HOURS_IN_HALF_DAY + (mIsAm ? 0 : HOURS_IN_HALF_DAY);
//通过set函数将新的Hour值传给mDate
mDate.set(Calendar.HOUR_OF_DAY, newHour);
//时间选择对话框
onDateTimeChanged();
if (isDateChanged) {
setCurrentYear(cal.get(Calendar.YEAR));
setCurrentMonth(cal.get(Calendar.MONTH));
setCurrentDay(cal.get(Calendar.DAY_OF_MONTH));
}
}
};
private NumberPicker.OnValueChangeListener mOnMinuteChangedListener = new NumberPicker.OnValueChangeListener() {
//这里是对 分钟Minute改变的监听
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
int minValue = mMinuteSpinner.getMinValue();
int maxValue = mMinuteSpinner.getMaxValue();
//设置offset作为小时改变的一个记录数据
int offset = 0;
//如果原值为59新值为0则offset加1
if (oldVal == maxValue && newVal == minValue) {
offset += 1;
}
//如果原值为0新值为59则offset减1
else if (oldVal == minValue && newVal == maxValue) {
offset -= 1;
}
if (offset != 0) {
mDate.add(Calendar.HOUR_OF_DAY, offset);
mHourSpinner.setValue(getCurrentHour());
updateDateControl();
int newHour = getCurrentHourOfDay();
if (newHour >= HOURS_IN_HALF_DAY) {
mIsAm = false;
updateAmPmControl();
} else {
mIsAm = true;
updateAmPmControl();
}
}
mDate.set(Calendar.MINUTE, newVal);
onDateTimeChanged();
}
};
private NumberPicker.OnValueChangeListener mOnAmPmChangedListener = new NumberPicker.OnValueChangeListener() {
//对AM和PM的监听
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mIsAm = !mIsAm;
if (mIsAm) {
mDate.add(Calendar.HOUR_OF_DAY, -HOURS_IN_HALF_DAY);
} else {
mDate.add(Calendar.HOUR_OF_DAY, HOURS_IN_HALF_DAY);
}
// updateDateControl()是同步操作
// onDateTimeChanged()是当事件发生改变时发出信号,并传递事件
updateAmPmControl();
onDateTimeChanged();
}
};
//系统时间接口
public interface OnDateTimeChangedListener {
void onDateTimeChanged(DateTimePicker view, int year, int month,
int dayOfMonth, int hourOfDay, int minute);
}
//通过对数据库的访问,获取当前的系统时间
public DateTimePicker(Context context) {
this(context, System.currentTimeMillis());
}
//上面函数的得到的是一个天文数字1970至今的秒数需要DateFormat将其变得有意义
public DateTimePicker(Context context, long date) {
this(context, date, DateFormat.is24HourFormat(context));
}
public DateTimePicker(Context context, long date, boolean is24HourView) {
super(context);
//获取系统时间
mDate = Calendar.getInstance();
mInitialising = true;
mIsAm = getCurrentHourOfDay() >= HOURS_IN_HALF_DAY;
//如果当前Activity里用到别的layout比如对话框layout
//还要设置这个layout上的其他组件的内容就必须用inflate()方法先将对话框的layout找出来
//然后再用findViewById()找到它上面的其它组件
inflate(context, R.layout.datetime_picker, this);
mDateSpinner = (NumberPicker) findViewById(R.id.date);
mDateSpinner.setMinValue(DATE_SPINNER_MIN_VAL);
mDateSpinner.setMaxValue(DATE_SPINNER_MAX_VAL);
mDateSpinner.setOnValueChangedListener(mOnDateChangedListener);
mHourSpinner = (NumberPicker) findViewById(R.id.hour);
mHourSpinner.setOnValueChangedListener(mOnHourChangedListener);
mMinuteSpinner = (NumberPicker) findViewById(R.id.minute);
mMinuteSpinner.setMinValue(MINUT_SPINNER_MIN_VAL);
mMinuteSpinner.setMaxValue(MINUT_SPINNER_MAX_VAL);
mMinuteSpinner.setOnLongPressUpdateInterval(100);
mMinuteSpinner.setOnValueChangedListener(mOnMinuteChangedListener);
String[] stringsForAmPm = new DateFormatSymbols().getAmPmStrings();
mAmPmSpinner = (NumberPicker) findViewById(R.id.amPm);
mAmPmSpinner.setMinValue(AMPM_SPINNER_MIN_VAL);
mAmPmSpinner.setMaxValue(AMPM_SPINNER_MAX_VAL);
mAmPmSpinner.setDisplayedValues(stringsForAmPm);
mAmPmSpinner.setOnValueChangedListener(mOnAmPmChangedListener);
// update controls to initial state
updateDateControl();
updateHourControl();
updateAmPmControl();
set24HourView(is24HourView);
// set to current time
setCurrentDate(date);
setEnabled(isEnabled());
// set the content descriptions
mInitialising = false;
}
//下面的代码通过原程序的注释已经比较清晰,另外可以通过函数名来判断
//下面的各函数主要是对上面代码引用到的各函数功能的实现
@Override
public void setEnabled(boolean enabled) {
if (mIsEnabled == enabled) {
return;
}
super.setEnabled(enabled);
mDateSpinner.setEnabled(enabled);
mMinuteSpinner.setEnabled(enabled);
mHourSpinner.setEnabled(enabled);
mAmPmSpinner.setEnabled(enabled);
mIsEnabled = enabled;
}
//实现函数——得到当前的秒数
@Override
public boolean isEnabled() {
return mIsEnabled;
}
/**
* Get the current date in millis
*
* @return the current date in millis
*/
public long getCurrentDateInTimeMillis() {
return mDate.getTimeInMillis();
}
/**
* Set the current date
*
* @param date The current date in millis
*/
//实现函数功能——设置当前的时间,参数是各详细的变量
public void setCurrentDate(long date) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(date);
setCurrentDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH),
cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE));
}
/**
* Set the current date
*
* @param year The current year
* @param month The current month
* @param dayOfMonth The current dayOfMonth
* @param hourOfDay The current hourOfDay
* @param minute The current minute
*/
public void setCurrentDate(int year, int month,
int dayOfMonth, int hourOfDay, int minute) {
setCurrentYear(year);
setCurrentMonth(month);
setCurrentDay(dayOfMonth);
setCurrentHour(hourOfDay);
setCurrentMinute(minute);
}
/**
* Get current year
*
* @return The current year
*/
//得到year值
public int getCurrentYear() {
return mDate.get(Calendar.YEAR);
}
/**
* Set current year
*
* @param year The current year
*/
//建立year值
public void setCurrentYear(int year) {
if (!mInitialising && year == getCurrentYear()) {
return;
}
mDate.set(Calendar.YEAR, year);
updateDateControl();
onDateTimeChanged();
}
/**
* Get current month in the year
*
* @return The current month in the year
*/
//获取month值
public int getCurrentMonth() {
return mDate.get(Calendar.MONTH);
}
/**
* Set current month in the year
*
* @param month The month in the year
*/
//建立month值
public void setCurrentMonth(int month) {
if (!mInitialising && month == getCurrentMonth()) {
return;
}
mDate.set(Calendar.MONTH, month);
updateDateControl();
onDateTimeChanged();
}
/**
* Get current day of the month
*
* @return The day of the month
*/
//获取day值
public int getCurrentDay() {
return mDate.get(Calendar.DAY_OF_MONTH);
}
/**
* Set current day of the month
*
* @param dayOfMonth The day of the month
*/
//建立day值
public void setCurrentDay(int dayOfMonth) {
if (!mInitialising && dayOfMonth == getCurrentDay()) {
return;
}
mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateDateControl();
onDateTimeChanged();
}
/**
* Get current hour in 24 hour mode, in the range (0~23)
* @return The current hour in 24 hour mode
*/
//获取当前hour值
public int getCurrentHourOfDay() {
return mDate.get(Calendar.HOUR_OF_DAY);
}
//获取hour值
private int getCurrentHour() {
if (mIs24HourView){
return getCurrentHourOfDay();
} else {
int hour = getCurrentHourOfDay();
if (hour > HOURS_IN_HALF_DAY) {
return hour - HOURS_IN_HALF_DAY;
} else {
return hour == 0 ? HOURS_IN_HALF_DAY : hour;
}
}
}
/**
* Set current hour in 24 hour mode, in the range (0~23)
*
* @param hourOfDay
*/
//建立hour值
public void setCurrentHour(int hourOfDay) {
if (!mInitialising && hourOfDay == getCurrentHourOfDay()) {
return;
}
mDate.set(Calendar.HOUR_OF_DAY, hourOfDay);
if (!mIs24HourView) {
if (hourOfDay >= HOURS_IN_HALF_DAY) {
mIsAm = false;
if (hourOfDay > HOURS_IN_HALF_DAY) {
hourOfDay -= HOURS_IN_HALF_DAY;
}
} else {
mIsAm = true;
if (hourOfDay == 0) {
hourOfDay = HOURS_IN_HALF_DAY;
}
}
updateAmPmControl();
}
mHourSpinner.setValue(hourOfDay);
onDateTimeChanged();
}
/**
* Get currentMinute
*
* @return The Current Minute
*/
//获取minute值
public int getCurrentMinute() {
return mDate.get(Calendar.MINUTE);
}
/**
* Set current minute
*/
//建立minute值
public void setCurrentMinute(int minute) {
if (!mInitialising && minute == getCurrentMinute()) {
return;
}
mMinuteSpinner.setValue(minute);
mDate.set(Calendar.MINUTE, minute);
onDateTimeChanged();
}
/**
* @return true if this is in 24 hour view else false.
*/
public boolean is24HourView () {
return mIs24HourView;
}
/**
* Set whether in 24 hour or AM/PM mode.
*
* @param is24HourView True for 24 hour mode. False for AM/PM mode.
*/
public void set24HourView(boolean is24HourView) {
if (mIs24HourView == is24HourView) {
return;
}
mIs24HourView = is24HourView;
mAmPmSpinner.setVisibility(is24HourView ? View.GONE : View.VISIBLE);
int hour = getCurrentHourOfDay();
updateHourControl();
setCurrentHour(hour);
updateAmPmControl();
}
//建立星期几的算法
private void updateDateControl() {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(mDate.getTimeInMillis());
cal.add(Calendar.DAY_OF_YEAR, -DAYS_IN_ALL_WEEK / 2 - 1);
mDateSpinner.setDisplayedValues(null);
for (int i = 0; i < DAYS_IN_ALL_WEEK; ++i) {
cal.add(Calendar.DAY_OF_YEAR, 1);
mDateDisplayValues[i] = (String) DateFormat.format("MM.dd EEEE", cal);
}
mDateSpinner.setDisplayedValues(mDateDisplayValues);
mDateSpinner.setValue(DAYS_IN_ALL_WEEK / 2);
mDateSpinner.invalidate();
}
//建立AM,PM的算法
private void updateAmPmControl() {
if (mIs24HourView) {
mAmPmSpinner.setVisibility(View.GONE);
} else {
int index = mIsAm ? Calendar.AM : Calendar.PM;
mAmPmSpinner.setValue(index);
mAmPmSpinner.setVisibility(View.VISIBLE);
}
}
//建立小时的算法
private void updateHourControl() {
if (mIs24HourView) {
mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW);
mHourSpinner.setMaxValue(HOUR_SPINNER_MAX_VAL_24_HOUR_VIEW);
} else {
mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_12_HOUR_VIEW);
mHourSpinner.setMaxValue(HOUR_SPINNER_MAX_VAL_12_HOUR_VIEW);
}
}
/**
* Set the callback that indicates the 'Set' button has been pressed.
* @param callback the callback, if null will do nothing
*/
public void setOnDateTimeChangedListener(OnDateTimeChangedListener callback) {
mOnDateTimeChangedListener = callback;
}
private void onDateTimeChanged() {
if (mOnDateTimeChangedListener != null) {
mOnDateTimeChangedListener.onDateTimeChanged(this, getCurrentYear(),
getCurrentMonth(), getCurrentDay(), getCurrentHourOfDay(), getCurrentMinute());
}
}
}

@ -0,0 +1,120 @@
/*
* 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.ui;
//前面几个UI包注释了这几个头文件的内容
import java.util.Calendar;
import net.micode.notes.R;
import net.micode.notes.ui.DateTimePicker;
import net.micode.notes.ui.DateTimePicker.OnDateTimeChangedListener;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface; //取消对话框的构造器运行
import android.content.DialogInterface.OnClickListener;
import android.text.format.DateFormat;
import android.text.format.DateUtils;
public class DateTimePickerDialog extends AlertDialog implements OnClickListener {
//创建一个Calendar类型的变量 mDate方便时间的操作
private Calendar mDate = Calendar.getInstance();
private boolean mIs24HourView;
//声明一个时间日期滚动选择控件 mOnDateTimeSetListener
private OnDateTimeSetListener mOnDateTimeSetListener;
//DateTimePicker控件控件一般用于让用户可以从日期列表中选择单个值。
//运行时,单击控件边上的下拉箭头,会显示为两个部分:一个下拉列表,一个用于选择日期的
private DateTimePicker mDateTimePicker;
public interface OnDateTimeSetListener {
void OnDateTimeSet(AlertDialog dialog, long date);
}
//对该界面对话框的实例化
public DateTimePickerDialog(Context context, long date) {
//对数据库的操作
super(context);
mDateTimePicker = new DateTimePicker(context);
//添加一个子视图
setView(mDateTimePicker);
mDateTimePicker.setOnDateTimeChangedListener(new OnDateTimeChangedListener() {
public void onDateTimeChanged(DateTimePicker view, int year, int month,
int dayOfMonth, int hourOfDay, int minute) {
//将视图中的各选项设置为系统当前时间
mDate.set(Calendar.YEAR, year);
mDate.set(Calendar.MONTH, month);
mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
mDate.set(Calendar.HOUR_OF_DAY, hourOfDay);
mDate.set(Calendar.MINUTE, minute);
updateTitle(mDate.getTimeInMillis());
}
});
//得到系统时间
mDate.setTimeInMillis(date);
//将秒数设置为0
mDate.set(Calendar.SECOND, 0);
mDateTimePicker.setCurrentDate(mDate.getTimeInMillis());
//设置两个按钮
setButton(context.getString(R.string.datetime_dialog_ok), this);
setButton2(context.getString(R.string.datetime_dialog_cancel), (OnClickListener)null);
set24HourView(DateFormat.is24HourFormat(this.getContext()));
//时间标准化打印
updateTitle(mDate.getTimeInMillis());
}
public void set24HourView(boolean is24HourView) {
mIs24HourView = is24HourView;
}
//将时间日期滚动选择控件实例化
public void setOnDateTimeSetListener(OnDateTimeSetListener callBack) {
mOnDateTimeSetListener = callBack;
}
//android开发中常见日期管理工具类API——DateUtils按照上下午显示时间
private void updateTitle(long date) {
int flag =
DateUtils.FORMAT_SHOW_YEAR |
DateUtils.FORMAT_SHOW_DATE |
DateUtils.FORMAT_SHOW_TIME;
flag |= mIs24HourView ? DateUtils.FORMAT_24HOUR : DateUtils.FORMAT_24HOUR;
setTitle(DateUtils.formatDateTime(this.getContext(), date, flag));
}
//第一个参数arg0是接收到点击事件的对话框
//第二个参数arg1是该对话框上的按钮
public void onClick(DialogInterface arg0, int arg1) {
if (mOnDateTimeSetListener != null) {
mOnDateTimeSetListener.OnDateTimeSet(this, mDate.getTimeInMillis());
}
}
}

@ -0,0 +1,72 @@
/*
* 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.ui;
import android.content.Context;
import android.view.Menu; //菜单组件
import android.view.MenuItem; //菜单通用项
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import net.micode.notes.R;
public class DropdownMenu {
private Button mButton;
//声明一个下拉菜单
private PopupMenu mPopupMenu;
private Menu mMenu;
public DropdownMenu(Context context, Button button, int menuId) {
mButton = button;
mButton.setBackgroundResource(R.drawable.dropdown_icon);
//设置这个view的背景
mPopupMenu = new PopupMenu(context, mButton);
mMenu = mPopupMenu.getMenu();
//MenuInflater是用来实例化Menu目录下的Menu布局文件
//根据ID来确认menu的内容选项
mPopupMenu.getMenuInflater().inflate(menuId, mMenu);
mButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mPopupMenu.show();
}
});
}
//设置菜单的监听
public void setOnDropdownMenuItemClickListener(OnMenuItemClickListener listener) {
if (mPopupMenu != null) {
mPopupMenu.setOnMenuItemClickListener(listener);
}
}
//对于菜单选项的初始化,根据索引搜索菜单需要的选项
public MenuItem findItem(int id) {
return mMenu.findItem(id);
}
//布局文件,设置标题
public void setTitle(CharSequence title) {
mButton.setText(title);
}
}

@ -0,0 +1,93 @@
/*
* 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.ui;
import android.content.Context;
import android.database.Cursor;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
//CursorAdapter是Cursor和ListView的接口
//FoldersListAdapter继承了CursorAdapter的类
//主要作用是便签数据库和用户的交互
//这里就是用folder文件夹的形式展现给用户
public class FoldersListAdapter extends CursorAdapter {
//调用数据库中便签的ID和片段
public static final String [] PROJECTION = {
NoteColumns.ID,
NoteColumns.SNIPPET
};
public static final int ID_COLUMN = 0;
public static final int NAME_COLUMN = 1;
//数据库操作
public FoldersListAdapter(Context context, Cursor c) {
super(context, c);
// TODO Auto-generated constructor stub
}
//将各个布局文件绑定起来
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new FolderListItem(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
if (view instanceof FolderListItem) {
String folderName = (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context
.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
((FolderListItem) view).bind(folderName);
}
}
//根据数据库中标签的ID得到标签的各项内容
public String getFolderName(Context context, int position) {
Cursor cursor = (Cursor) getItem(position);
return (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context
.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
}
private class FolderListItem extends LinearLayout {
private TextView mName;
public FolderListItem(Context context) {
//操作数据库
super(context);
//根据布局文件的名字等信息将其找出来
inflate(context, R.layout.folder_list_item, this);
mName = (TextView) findViewById(R.id.tv_folder_name);
}
public void bind(String name) {
mName.setText(name);
}
}
}

@ -0,0 +1,292 @@
/*
* 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.ui;
import android.content.Context;
import android.graphics.Rect;
import android.text.Layout;
import android.text.Selection;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.URLSpan;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.MotionEvent;
import android.widget.EditText;
import net.micode.notes.R;
import java.util.HashMap;
import java.util.Map;
//继承edittext设置便签设置文本框
public class NoteEditText extends EditText {
private static final String TAG = "NoteEditText";
private int mIndex;
private int mSelectionStartBeforeDelete;
private static final String SCHEME_TEL = "tel:" ;
private static final String SCHEME_HTTP = "http:" ;
private static final String SCHEME_EMAIL = "mailto:" ;
//建立一个字符和整数的hash表用于链接电话网站还有邮箱
private static final Map<String, Integer> sSchemaActionResMap = new HashMap<String, Integer>();
static {
sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel);
sSchemaActionResMap.put(SCHEME_HTTP, R.string.note_link_web);
sSchemaActionResMap.put(SCHEME_EMAIL, R.string.note_link_email);
}
/**
* Call by the {@link NoteEditActivity} to delete or add edit text
*/
//在NoteEditActivity中删除或添加文本的操作可以看做是一个文本是否被变的标记英文注释已说明
public interface OnTextViewChangeListener {
/**
* Delete current edit text when {@link KeyEvent#KEYCODE_DEL} happens
* and the text is null
*/
//处理删除按键时的操作
void onEditTextDelete(int index, String text);
/**
* Add edit text after current edit text when {@link KeyEvent#KEYCODE_ENTER}
* happen
*/
//处理进入按键时的操作
void onEditTextEnter(int index, String text);
/**
* Hide or show item option when text change
*/
void onTextChange(int index, boolean hasText);
}
private OnTextViewChangeListener mOnTextViewChangeListener;
//根据context设置文本
public NoteEditText(Context context) {
//用super引用父类变量
super(context, null);
mIndex = 0;
}
//设置当前光标
public void setIndex(int index) {
mIndex = index;
}
//初始化文本修改标记
public void setOnTextViewChangeListener(OnTextViewChangeListener listener) {
mOnTextViewChangeListener = listener;
}
//AttributeSet用于维护便签动态变化的属性
//初始化便签
public NoteEditText(Context context, AttributeSet attrs) {
super(context, attrs, android.R.attr.editTextStyle);
}
// 根据defstyle自动初始化
public NoteEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
//view里的函数处理手机屏幕的所有事件
/*event
*/
//重写了需要处理屏幕被按下的事件
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
//更新当前坐标值
int x = (int) event.getX();
int y = (int) event.getY();
x -= getTotalPaddingLeft();
y -= getTotalPaddingTop();
x += getScrollX();
y += getScrollY();
//用布局控件layout根据x,y的新值设置新的位置
Layout layout = getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
//更新光标新的位置
Selection.setSelection(getText(), off);
break;
}
return super.onTouchEvent(event);
}
/*
*
*
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
//根据按键的 Unicode 编码值来处理
switch (keyCode) {
//“进入”按键
case KeyEvent.KEYCODE_ENTER:
if (mOnTextViewChangeListener != null) {
return false;
}
break;
//“删除”按键
case KeyEvent.KEYCODE_DEL:
mSelectionStartBeforeDelete = getSelectionStart();
break;
default:
break;
}
//继续执行父类的其他点击事件
return super.onKeyDown(keyCode, event);
}
/*
*
*
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
//根据按键的 Unicode 编码值来处理有删除和进入2种操作
switch(keyCode) {
case KeyEvent.KEYCODE_DEL:
//若是被修改过
if (mOnTextViewChangeListener != null) {
//若之前有被修改并且文档不为空
if (0 == mSelectionStartBeforeDelete && mIndex != 0) {
//利用上文OnTextViewChangeListener对KEYCODE_DEL按键情况的删除函数进行删除
mOnTextViewChangeListener.onEditTextDelete(mIndex, getText().toString());
return true;
}
}
//其他情况报错,文档的改动监听器并没有建立
else {
Log.d(TAG, "OnTextViewChangeListener was not seted");
}
break;
//同上也是分为监听器是否建立2种情况
case KeyEvent.KEYCODE_ENTER:
if (mOnTextViewChangeListener != null) {
//获取当前位置
int selectionStart = getSelectionStart();
//获取当前文本
String text = getText().subSequence(selectionStart, length()).toString();
//根据获取的文本设置当前文本
setText(getText().subSequence(0, selectionStart));
mOnTextViewChangeListener.onEditTextEnter(mIndex + 1, text);
}
//其他情况报错,文档的改动监听器并没有建立
else {
Log.d(TAG, "OnTextViewChangeListener was not seted");
}
break;
default:
break;
}
//继续执行父类的其他按键弹起的事件
return super.onKeyUp(keyCode, event);
}
@Override
/*
*
*
* focusedViewFocusedtruefalse
direction
RectViewnull
*/
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
//若监听器已经建立
if (mOnTextViewChangeListener != null) {
//获取到焦点并且文本不为空
if (!focused && TextUtils.isEmpty(getText())) {
//mOnTextViewChangeListener子函数置false隐藏事件选项
mOnTextViewChangeListener.onTextChange(mIndex, false);
} else {
//mOnTextViewChangeListener子函数置true显示事件选项
mOnTextViewChangeListener.onTextChange(mIndex, true);
}
}
//继续执行父类的其他焦点变化的事件
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
/*
*
*
*/
@Override
protected void onCreateContextMenu(ContextMenu menu) {
//有文本存在
if (getText() instanceof Spanned) {
//获取文本开始和结尾位置
int selStart = getSelectionStart();
int selEnd = getSelectionEnd();
//获取开始到结尾的最大值和最小值
int min = Math.min(selStart, selEnd);
int max = Math.max(selStart, selEnd);
//设置url的信息的范围值
final URLSpan[] urls = ((Spanned) getText()).getSpans(min, max, URLSpan.class);
if (urls.length == 1) {
int defaultResId = 0;
//获取计划表中所有的key值
for(String schema: sSchemaActionResMap.keySet()) {
//若url可以添加则在添加后将defaultResId置为key所映射的值
if(urls[0].getURL().indexOf(schema) >= 0) {
defaultResId = sSchemaActionResMap.get(schema);
break;
}
}
//defaultResId == 0则说明url并没有添加任何东西所以置为连接其他SchemaActionResMap的值
if (defaultResId == 0) {
defaultResId = R.string.note_link_other;
}
//建立菜单
menu.add(0, 0, 0, defaultResId).setOnMenuItemClickListener(
//新建按键监听器
new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
// goto a new intent
//根据相应的文本设置菜单的按键
urls[0].onClick(NoteEditText.this);
return true;
}
});
}
}
//继续执行父类的其他菜单创建的事件
super.onCreateContextMenu(menu);
}
}

@ -26,9 +26,11 @@ import android.util.Log;
import java.util.HashMap;
public class Contact {
// 建立
private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact";
// 来电显示选择
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
+ ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
+ " AND " + Data.RAW_CONTACT_ID + " IN "
@ -36,17 +38,21 @@ public class Contact {
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
// 获得连接
public static String getContact(Context context, String phoneNumber) {
// 哈希表为空新建哈希表
if(sContactCache == null) {
sContactCache = new HashMap<String, String>();
}
// 在哈希表中查找电话号码
if(sContactCache.containsKey(phoneNumber)) {
return sContactCache.get(phoneNumber);
}
String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
// 建立一个用户
Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI,
new String [] { Phone.DISPLAY_NAME },
@ -54,6 +60,8 @@ public class Contact {
new String[] { phoneNumber },
null);
// 添加任务
if (cursor != null && cursor.moveToFirst()) {
try {
String name = cursor.getString(0);

@ -30,16 +30,29 @@ public class Notes {
* {@link Notes#ID_TEMPARAY_FOLDER } is for notes belonging no folder
* {@link Notes#ID_CALL_RECORD_FOLDER} is to store call records
*/
public static final int ID_ROOT_FOLDER = 0;
public static final int ID_TEMPARAY_FOLDER = -1;
public static final int ID_CALL_RECORD_FOLDER = -2;
// id是系统文件夹的标识符
public static final int ID_ROOT_FOLDER = 0;// 标识默认文件夹
public static final int ID_TEMPARAY_FOLDER = -1;// 标识不属于文件夹的笔记
public static final int ID_CALL_RECORD_FOLDER = -2;// 用于存储通话记录
public static final int ID_TRASH_FOLER = -3;
// 通知日期
public static final String INTENT_EXTRA_ALERT_DATE = "net.micode.notes.alert_date";
// 背景颜色id
public static final String INTENT_EXTRA_BACKGROUND_ID = "net.micode.notes.background_color_id";
// 小部件id
public static final String INTENT_EXTRA_WIDGET_ID = "net.micode.notes.widget_id";
// 小部件类型
public static final String INTENT_EXTRA_WIDGET_TYPE = "net.micode.notes.widget_type";
// 文件id
public static final String INTENT_EXTRA_FOLDER_ID = "net.micode.notes.folder_id";
// 调用日期
public static final String INTENT_EXTRA_CALL_DATE = "net.micode.notes.call_date";
public static final int TYPE_WIDGET_INVALIDE = -1;
@ -54,36 +67,47 @@ public class Notes {
/**
* Uri to query all notes and folders
*/
// 查询所有笔记和文件夹
public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note");
/**
* Uri to query data
*/
// 查询数据
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
// NoteColumns 接口用于创建数据库
public interface NoteColumns {
/**
* The unique ID for a row
* <P> Type: INTEGER (long) </P>
*/
// 对于一行唯一的ID
public static final String ID = "_id";
/**
* The parent's id for note or folder
* <P> Type: INTEGER (long) </P>
*/
// 笔记或文件夹的父级id
public static final String PARENT_ID = "parent_id";
/**
* Created data for note or folder
* <P> Type: INTEGER (long) </P>
*/
// 创建数据对于便签和文件
public static final String CREATED_DATE = "created_date";
/**
* Latest modified date
* <P> Type: INTEGER (long) </P>
*/
// 最新修改日期
public static final String MODIFIED_DATE = "modified_date";
@ -91,30 +115,43 @@ public class Notes {
* Alert date
* <P> Type: INTEGER (long) </P>
*/
// 警报日期
public static final String ALERTED_DATE = "alert_date";
/**
* Folder's name or text content of note
* <P> Type: TEXT </P>
*/
// 文件夹的名称或注意的文本内容
public static final String SNIPPET = "snippet";
/**
* Note's widget id
* <P> Type: INTEGER (long) </P>
*/
// 便签的小部件ID
public static final String WIDGET_ID = "widget_id";
/**
* Note's widget type
* <P> Type: INTEGER (long) </P>
*/
// 便签的小部件类型
public static final String WIDGET_TYPE = "widget_type";
/**
* Note's background color's id
* <P> Type: INTEGER (long) </P>
*/
// 便签的背景颜色ID
public static final String BG_COLOR_ID = "bg_color_id";
/**
@ -122,86 +159,120 @@ public class Notes {
* note, it has at least one attachment
* <P> Type: INTEGER </P>
*/
// 对于文本笔记,它没有附件,对于多媒体笔记,它至少有一个附件
public static final String HAS_ATTACHMENT = "has_attachment";
/**
* Folder's count of notes
* <P> Type: INTEGER (long) </P>
*/
// 文件夹的注释计数
public static final String NOTES_COUNT = "notes_count";
/**
* The file type: folder or note
* <P> Type: INTEGER </P>
*/
// 文件类型
public static final String TYPE = "type";
/**
* The last sync id
* <P> Type: INTEGER (long) </P>
*/
// 最终同步id
public static final String SYNC_ID = "sync_id";
/**
* Sign to indicate local modified or not
* <P> Type: INTEGER </P>
*/
// 表示本地是否修改
public static final String LOCAL_MODIFIED = "local_modified";
/**
* Original parent id before moving into temporary folder
* <P> Type : INTEGER </P>
*/
// 表示移动到临时文件夹前的原始父id
public static final String ORIGIN_PARENT_ID = "origin_parent_id";
/**
* The gtask id
* <P> Type : TEXT </P>
*/
// 表示gtask id
public static final String GTASK_ID = "gtask_id";
/**
* The version code
* <P> Type : INTEGER (long) </P>
*/
// 表示版本代码
public static final String VERSION = "version";
}
// 定义接口DataColumns 存储数据库数据
public interface DataColumns {
/**
* The unique ID for a row
* <P> Type: INTEGER (long) </P>
*/
// 对于一行唯一的ID
public static final String ID = "_id";
/**
* The MIME type of the item represented by this row.
* <P> Type: Text </P>
*/
// 表示项目的MIME类型
public static final String MIME_TYPE = "mime_type";
/**
* The reference id to note that this data belongs to
* <P> Type: INTEGER (long) </P>
*/
// 指明便签id的所属
public static final String NOTE_ID = "note_id";
/**
* Created data for note or folder
* <P> Type: INTEGER (long) </P>
*/
// 创建数据便签和文件夹
public static final String CREATED_DATE = "created_date";
/**
* Latest modified date
* <P> Type: INTEGER (long) </P>
*/
// 最新修改信息
public static final String MODIFIED_DATE = "modified_date";
/**
* Data's content
* <P> Type: TEXT </P>
*/
// 数据正文
public static final String CONTENT = "content";
@ -210,6 +281,8 @@ public class Notes {
* integer data type
* <P> Type: INTEGER </P>
*/
// 泛型数据类,用于整形数据
public static final String DATA1 = "data1";
/**
@ -217,6 +290,8 @@ public class Notes {
* integer data type
* <P> Type: INTEGER </P>
*/
// 泛型数据类用于整形数据同data1
public static final String DATA2 = "data2";
/**
@ -224,6 +299,8 @@ public class Notes {
* TEXT data type
* <P> Type: TEXT </P>
*/
// 泛型数据类,用于文本型数据
public static final String DATA3 = "data3";
/**
@ -231,6 +308,8 @@ public class Notes {
* TEXT data type
* <P> Type: TEXT </P>
*/
// 泛型数据类,用于文本型数据
public static final String DATA4 = "data4";
/**
@ -238,15 +317,20 @@ public class Notes {
* TEXT data type
* <P> Type: TEXT </P>
*/
// 泛型数据类,用于文本型数据
public static final String DATA5 = "data5";
}
// TextNote 需要使用使用implements调用DataColumns接口
public static final class TextNote implements DataColumns {
/**
* Mode to indicate the text in check list mode or not
* <P> Type: Integer 1:check list mode 0: normal mode </P>
*/
public static final String MODE = DATA1;
// 使用泛型数据类型查找是否处于列表模式
public static final String MODE = DATA2;
public static final int MODE_CHECK_LIST = 1;
@ -257,17 +341,22 @@ public class Notes {
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");
}
// CallNote 使用implements调用DataColumns接口
public static final class CallNote implements DataColumns {
/**
* Call date for this record
* <P> Type: INTEGER (long) </P>
*/
// 记录呼叫的日期
public static final String CALL_DATE = DATA1;
/**
* Phone number for this record
* <P> Type: TEXT </P>
*/
// 记录呼叫号码
public static final String PHONE_NUMBER = DATA3;
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note";

@ -26,7 +26,7 @@ import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns;
// NotesDatabaseHelper 继承 SQLiteOpenHelper 对数据库各种框架的完善
public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "note.db";
@ -85,6 +85,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Increase folder's note count when move note to the folder
*/
// 增加文件夹的笔记计数时,移动笔记到文件夹
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_update "+
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
@ -97,6 +98,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Decrease folder's note count when move note from folder
*/
// 从文件夹移动笔记时减少文件夹的笔记数
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_update " +
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
@ -110,6 +112,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Increase folder's note count when insert new note to the folder
*/
// 增加文件夹的笔记计数时,插入新的笔记到文件夹
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_insert " +
" AFTER INSERT ON " + TABLE.NOTE +
@ -122,6 +125,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Decrease folder's note count when delete note from the folder
*/
// 从文件夹中删除笔记时,减少文件夹的笔记计数
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_delete " +
" AFTER DELETE ON " + TABLE.NOTE +
@ -135,6 +139,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Update note's content when insert data with type {@link DataConstants#NOTE}
*/
// 当插入带有类型的数据时,更新注释的内容
private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER =
"CREATE TRIGGER update_note_content_on_insert " +
" AFTER INSERT ON " + TABLE.DATA +
@ -148,6 +153,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Update note's content when data with {@link DataConstants#NOTE} type has changed
*/
// 当数据类型发生变化时,更新注释的内容
private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER update_note_content_on_update " +
" AFTER UPDATE ON " + TABLE.DATA +
@ -161,6 +168,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Update note's content when data with {@link DataConstants#NOTE} type has deleted
*/
// 当类型的数据被删除时,更新注释的内容
private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER =
"CREATE TRIGGER update_note_content_on_delete " +
" AFTER delete ON " + TABLE.DATA +
@ -174,6 +183,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Delete datas belong to note which has been deleted
*/
// 删除数据属于已删除的备注
private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER =
"CREATE TRIGGER delete_data_on_delete " +
" AFTER DELETE ON " + TABLE.NOTE +
@ -185,6 +196,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Delete notes belong to folder which has been deleted
*/
// 删除笔记属于已删除的文件夹
private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER =
"CREATE TRIGGER folder_delete_notes_on_delete " +
" AFTER DELETE ON " + TABLE.NOTE +
@ -196,6 +209,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Move notes belong to folder which has been moved to trash folder
*/
// 移动笔记属于已移动到垃圾文件夹的文件夹
private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER =
"CREATE TRIGGER folder_move_notes_on_trash " +
" AFTER UPDATE ON " + TABLE.NOTE +
@ -206,10 +221,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
" END";
// 构造函数
public NotesDatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
// 创建笔记数据库
public void createNoteTable(SQLiteDatabase db) {
db.execSQL(CREATE_NOTE_TABLE_SQL);
reCreateNoteTableTriggers(db);
@ -217,6 +234,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
Log.d(TAG, "note table has been created");
}
// 重新创建笔记触发器
private void reCreateNoteTableTriggers(SQLiteDatabase db) {
db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update");
db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_update");
@ -235,12 +253,15 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER);
}
// 创建系统文件夹
private void createSystemFolder(SQLiteDatabase db) {
ContentValues values = new ContentValues();
/**
* call record foler for call notes
*/
// 通话记录记录器
values.put(NoteColumns.ID, Notes.ID_CALL_RECORD_FOLDER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
db.insert(TABLE.NOTE, null, values);
@ -248,6 +269,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* root folder which is default folder
*/
// 创建根文件夹
values.clear();
values.put(NoteColumns.ID, Notes.ID_ROOT_FOLDER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
@ -256,6 +279,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* temporary folder which is used for moving note
*/
// 创建用于移动笔记的临时文件夹
values.clear();
values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
@ -264,12 +289,15 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* create trash folder
*/
// 创建垃圾文件夹
values.clear();
values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
db.insert(TABLE.NOTE, null, values);
}
// 创建数据的数据库
public void createDataTable(SQLiteDatabase db) {
db.execSQL(CREATE_DATA_TABLE_SQL);
reCreateDataTableTriggers(db);
@ -277,6 +305,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
Log.d(TAG, "data table has been created");
}
// 重新创建数据数据库的触发器
private void reCreateDataTableTriggers(SQLiteDatabase db) {
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_insert");
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_update");
@ -287,6 +316,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER);
}
// 静态同步锁 保证进程获取资源的稳定性
static synchronized NotesDatabaseHelper getInstance(Context context) {
if (mInstance == null) {
mInstance = new NotesDatabaseHelper(context);
@ -294,35 +325,42 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
return mInstance;
}
@Override
@Override // 用于指定方法重写
// 创建两个数据库
public void onCreate(SQLiteDatabase db) {
createNoteTable(db);
createDataTable(db);
}
@Override
// 更新数据库信息
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
boolean reCreateTriggers = false;
boolean skipV2 = false;
if (oldVersion == 1) {
// 更新至V2
upgradeToV2(db);
skipV2 = true; // this upgrade including the upgrade from v2 to v3
oldVersion++;
}
if (oldVersion == 2 && !skipV2) {
// 更新至V3
upgradeToV3(db);
reCreateTriggers = true;
oldVersion++;
}
if (oldVersion == 3) {
// 更新至V4
upgradeToV4(db);
oldVersion++;
}
if (reCreateTriggers) {
// 触发触发器
reCreateNoteTableTriggers(db);
reCreateDataTableTriggers(db);
}
@ -333,6 +371,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
}
// 更新V2的操作
private void upgradeToV2(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE);
db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA);
@ -340,6 +379,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
createDataTable(db);
}
// 更新V3的操作
private void upgradeToV3(SQLiteDatabase db) {
// drop unused triggers
db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_insert");
@ -355,6 +395,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.insert(TABLE.NOTE, null, values);
}
// 更新至V4的操作
private void upgradeToV4(SQLiteDatabase db) {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION
+ " INTEGER NOT NULL DEFAULT 0");

@ -35,6 +35,8 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
// NotesProvider 继承 ContentProvider
// ContentProvider 管理 Android 以结构化方式存放的数据,以相对安全的方式封装数据
public class NotesProvider extends ContentProvider {
private static final UriMatcher mMatcher;
@ -50,6 +52,8 @@ public class NotesProvider extends ContentProvider {
private static final int URI_SEARCH = 5;
private static final int URI_SEARCH_SUGGEST = 6;
// 添加URI 让URI工具类解析路径字符串
static {
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
@ -65,6 +69,8 @@ public class NotesProvider extends ContentProvider {
* x'0A' represents the '\n' character in sqlite. For title and content in the search result,
* we will trim '\n' and white space in order to show more information.
*/
// x'0A'表示sqlite中的'\n'字符。对于搜索结果中的标题和内容,我们将删去'\n'和空白以显示更多信息。
private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + ","
+ NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + ","
+ "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_1 + ","
@ -79,12 +85,14 @@ public class NotesProvider extends ContentProvider {
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
// 创建数据库帮助类
@Override
public boolean onCreate() {
mHelper = NotesDatabaseHelper.getInstance(getContext());
return true;
}
// 查找给定路径
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
@ -93,19 +101,23 @@ public class NotesProvider extends ContentProvider {
String id = null;
switch (mMatcher.match(uri)) {
case URI_NOTE:
// 当匹配结果是1的时候 查询便签信息
c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null,
sortOrder);
break;
case URI_NOTE_ITEM:
// 当匹配结果是2的时候 查询便签信息 获取id
id = uri.getPathSegments().get(1);
c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs, null, null, sortOrder);
break;
case URI_DATA:
// 当匹配结果是3的时候 查询数据信息
c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null,
sortOrder);
break;
case URI_DATA_ITEM:
// 当匹配结果是4的时候 查询数据
id = uri.getPathSegments().get(1);
c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs, null, null, sortOrder);
@ -147,6 +159,7 @@ public class NotesProvider extends ContentProvider {
return c;
}
// 该方法使用SQLiteOpenHelper实例打开一个可写的SQLiteDatabase并根据Uri参数将数据插入到表中。如果插入成功则返回所插入数据的Uri。
@Override
public Uri insert(Uri uri, ContentValues values) {
SQLiteDatabase db = mHelper.getWritableDatabase();
@ -181,7 +194,9 @@ public class NotesProvider extends ContentProvider {
return ContentUris.withAppendedId(uri, insertedId);
}
@Override
// 使用SQLiteOpenHelper实例打开一个可写的SQLiteDatabase并根据Uri、selection和selectionArgs参数从表中删除数据。如果删除成功它将返回受影响的行数。
public int delete(Uri uri, String selection, String[] selectionArgs) {
int count = 0;
String id = null;
@ -200,6 +215,7 @@ public class NotesProvider extends ContentProvider {
*/
long noteId = Long.valueOf(id);
if (noteId <= 0) {
// 如果编号是小于等于0的那么就放到垃圾桶里
break;
}
count = db.delete(TABLE.NOTE,
@ -234,6 +250,7 @@ public class NotesProvider extends ContentProvider {
SQLiteDatabase db = mHelper.getWritableDatabase();
boolean updateData = false;
switch (mMatcher.match(uri)) {
// 如果Uri与URI_NOTE或URI_NOTE_ITEM匹配该方法增加注释版本然后更新TABLE。
case URI_NOTE:
increaseNoteVersion(-1, selection, selectionArgs);
count = db.update(TABLE.NOTE, values, selection, selectionArgs);
@ -244,6 +261,8 @@ public class NotesProvider extends ContentProvider {
count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs);
break;
// 如果Uri与URI_DATA或URI_DATA_ITEM匹配则更新该表。
case URI_DATA:
count = db.update(TABLE.DATA, values, selection, selectionArgs);
updateData = true;
@ -267,10 +286,12 @@ public class NotesProvider extends ContentProvider {
return count;
}
// 解析选择
private String parseSelection(String selection) {
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
}
// 更新便签版本
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
StringBuilder sql = new StringBuilder(120);
sql.append("UPDATE ");
@ -296,8 +317,10 @@ public class NotesProvider extends ContentProvider {
mHelper.getWritableDatabase().execSQL(sql.toString());
}
// getType方法返回与给定Uri关联的数据的MIME类型。
@Override
public String getType(Uri uri) {
// 自动生成的方法存根
// TODO Auto-generated method stub
return null;
}

@ -24,12 +24,14 @@ import net.micode.notes.tool.GTaskStringUtils;
import org.json.JSONException;
import org.json.JSONObject;
// MetaData 继承 Task
public class MetaData extends Task {
private final static String TAG = MetaData.class.getSimpleName();
private String mRelatedGid = null;
// setMeta方法以String gid和JSONObject metaInfo作为参数并将gid作为属性添加到metaInfo JSON对象键为GTaskStringUtils
public void setMeta(String gid, JSONObject metaInfo) {
try {
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
@ -40,15 +42,20 @@ public class MetaData extends Task {
setName(GTaskStringUtils.META_NOTE_NAME);
}
// 返回mRelatedGid成员变量的值
public String getRelatedGid() {
return mRelatedGid;
}
// 指示任务的注释是否为非空
@Override
public boolean isWorthSaving() {
return getNotes() != null;
}
// 如果任务的注释是非空的它会尝试将它们解析为JSON对象并提取与GTaskStringUtils相关的值。META_HEAD_GTASK_ID关键。
// 如果成功它将mRelatedGid成员变量设置为该值。如果不成功它将记录一条警告消息并将mRelatedGid设置为null
@Override
public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js);
@ -63,6 +70,8 @@ public class MetaData extends Task {
}
}
// 带有指示不应该调用它们的消息
@Override
public void setContentByLocalJSON(JSONObject js) {
// this function should not be called
@ -78,5 +87,4 @@ public class MetaData extends Task {
public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
}
}

@ -20,23 +20,33 @@ import android.database.Cursor;
import org.json.JSONObject;
// 定义节点类
public abstract class Node {
// 不进行同步
public static final int SYNC_ACTION_NONE = 0;
// 增添信息同步至云端
public static final int SYNC_ACTION_ADD_REMOTE = 1;
// 增添信息同步至本地
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_LOCAL = 4;
// 更新信息同步至云端
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_CONFLICT = 7;
// 同步错误
public static final int SYNC_ACTION_ERROR = 8;
private String mGid;

@ -40,6 +40,7 @@ public class SqlData {
private static final int INVALID_ID = -99999;
// 用于访问某种数据库或数据结构中的数据的列名或键
public static final String[] PROJECTION_DATA = new String[] {
DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1,
DataColumns.DATA3
@ -71,6 +72,11 @@ public class SqlData {
private ContentValues mDiffDataValues;
/*
* SQLitemDataIdID,
* mDataMimeTypemDataContentmDataContentData1mDataContentData3
*/
public SqlData(Context context) {
mContentResolver = context.getContentResolver();
mIsCreate = true;
@ -82,6 +88,7 @@ public class SqlData {
mDiffDataValues = new ContentValues();
}
// 构造函数用于获取ContentProvider提供的数据
public SqlData(Context context, Cursor c) {
mContentResolver = context.getContentResolver();
mIsCreate = false;
@ -89,6 +96,8 @@ 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,6 +106,9 @@ public class SqlData {
mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);
}
// 接受一个JSONObject作为参数该参数表示要存储在数据库中的数据。该方法解析JSONObject并设置SqlData对象的相应成员变量。
// 如果SqlData对象是新的或者数据ID已更改该方法将ID添加到mDiffDataValues对象。
public void setContent(JSONObject js) throws JSONException {
long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID;
if (mIsCreate || mDataId != dataId) {
@ -130,6 +142,8 @@ public class SqlData {
mDataContentData3 = dataContentData3;
}
// 创建一个新的JSONObject并将SqlData对象的成员变量设置为JSONObject的键值对。
// 该方法返回结果的JSONObject。如果SqlData对象是新的则该方法返回null
public JSONObject getContent() throws JSONException {
if (mIsCreate) {
Log.e(TAG, "it seems that we haven't created this in database yet");
@ -144,6 +158,8 @@ public class SqlData {
return js;
}
// 提交修改,并保存至数据库
public void commit(long noteId, boolean validateVersion, long version) {
if (mIsCreate) {

@ -1,17 +1,6 @@
/*
* 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.
* Description便sqldatanotedata
* SqlDataSqlNote
*/
package net.micode.notes.gtask.data;
@ -42,7 +31,7 @@ public class SqlNote {
private static final String TAG = SqlNote.class.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 +40,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 +74,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,16 +110,23 @@ public class SqlNote {
private ContentValues mDiffNoteValues;
private ArrayList<SqlData> mDataList;
/*
*
* mIsCreate
*/
// 构造函数只有context对所有的变量进行初始化
public SqlNote(Context context) {
// 获取context程序间共享数据
mContext = context;
mContentResolver = context.getContentResolver();
mIsCreate = true;
mId = INVALID_ID;
mAlertDate = 0;
mBgColorId = ResourceParser.getDefaultBgId(context);
//调用系统函数获得创建时间
mCreatedDate = System.currentTimeMillis();
mHasAttachment = 0;
//最后一次修改时间初始化为创建时间
mModifiedDate = System.currentTimeMillis();
mParentId = 0;
mSnippet = "";
@ -139,11 +135,18 @@ public class SqlNote {
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
mOriginParent = 0;
mVersion = 0;
// 新建一个NoteValues值用来记录改变的values
mDiffNoteValues = new ContentValues();
// 新建一个data的列表
mDataList = new ArrayList<SqlData>();
}
/*
*
* mIsCreate
*/
//构造函数有context和一个数据库的cursor多数变量通过cursor指向的一条记录直接进行初始化
public SqlNote(Context context, Cursor c) {
// 将mIsCreate定义为False作为标识以id为参数运行loadFromCursor函数
mContext = context;
mContentResolver = context.getContentResolver();
mIsCreate = false;
@ -153,7 +156,10 @@ public class SqlNote {
loadDataContent();
mDiffNoteValues = new ContentValues();
}
/*
*
* mIsCreate
*/
public SqlNote(Context context, long id) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -165,16 +171,19 @@ public class SqlNote {
mDiffNoteValues = new ContentValues();
}
// 功能描述通过id从光标处加载数据
private void loadFromCursor(long id) {
Cursor c = null;
try {
// 通过id获得对应的ContentResolver中的cursor
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",
new String[] {
String.valueOf(id)
String.valueOf(id)
}, null);
if (c != null) {
c.moveToNext();
//然后加载数据进行初始化,这样函数
//SqlNote(Context context, long id)与SqlNote(Context context, long id)的实现方式基本相同
loadFromCursor(c);
} else {
Log.w(TAG, "loadFromCursor: cursor = null");
@ -184,7 +193,7 @@ public class SqlNote {
c.close();
}
}
// 功能描述:通过游标从光标处加载数据
private void loadFromCursor(Cursor c) {
mId = c.getLong(ID_COLUMN);
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
@ -199,14 +208,15 @@ public class SqlNote {
mWidgetType = c.getInt(WIDGET_TYPE_COLUMN);
mVersion = c.getLong(VERSION_COLUMN);
}
// 功能描述通过content机制获取共享数据并加载到数据库当前游标处
private void loadDataContent() {
Cursor c = null;
mDataList.clear();
// 获取ID对应content内容
try {
c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA,
"(note_id=?)", new String[] {
String.valueOf(mId)
String.valueOf(mId)
}, null);
if (c != null) {
if (c.getCount() == 0) {
@ -218,6 +228,7 @@ public class SqlNote {
mDataList.add(data);
}
} else {
// 该ID在content中无对应的cursor
Log.w(TAG, "loadDataContent: cursor = null");
}
} finally {
@ -225,7 +236,7 @@ public class SqlNote {
c.close();
}
}
// 设置通过content机制用于共享的数据信息
public boolean setContent(JSONObject js) {
try {
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
@ -235,6 +246,7 @@ public class SqlNote {
// for folder we can only update the snnipet and type
String snippet = note.has(NoteColumns.SNIPPET) ? note
.getString(NoteColumns.SNIPPET) : "";
// 如果没有创建或者该摘要没有匹配原摘要则将其加入解析器
if (mIsCreate || !mSnippet.equals(snippet)) {
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
}
@ -247,27 +259,28 @@ public class SqlNote {
}
mType = type;
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) {
// 获取便签提示日期
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID;
if (mIsCreate || mId != id) {
mDiffNoteValues.put(NoteColumns.ID, id);
}
mId = id;
// 获取数据的提醒日期
long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note
.getLong(NoteColumns.ALERTED_DATE) : 0;
if (mIsCreate || mAlertDate != alertDate) {
mDiffNoteValues.put(NoteColumns.ALERTED_DATE, alertDate);
}
mAlertDate = alertDate;
// 获取数据的背景颜色
int bgColorId = note.has(NoteColumns.BG_COLOR_ID) ? note
.getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext);
if (mIsCreate || mBgColorId != bgColorId) {
mDiffNoteValues.put(NoteColumns.BG_COLOR_ID, bgColorId);
}
mBgColorId = bgColorId;
// 对创建日期操作
long createDate = note.has(NoteColumns.CREATED_DATE) ? note
.getLong(NoteColumns.CREATED_DATE) : System.currentTimeMillis();
if (mIsCreate || mCreatedDate != createDate) {
@ -281,14 +294,15 @@ public class SqlNote {
mDiffNoteValues.put(NoteColumns.HAS_ATTACHMENT, hasAttachment);
}
mHasAttachment = hasAttachment;
// 获取数据的修改日期
long modifiedDate = note.has(NoteColumns.MODIFIED_DATE) ? note
.getLong(NoteColumns.MODIFIED_DATE) : System.currentTimeMillis();
// 如果只是通过上下文对note进行数据库操作或者该修改日期与原修改日期不相同
if (mIsCreate || mModifiedDate != modifiedDate) {
mDiffNoteValues.put(NoteColumns.MODIFIED_DATE, modifiedDate);
}
mModifiedDate = modifiedDate;
// 获取数据的父节点ID
long parentId = note.has(NoteColumns.PARENT_ID) ? note
.getLong(NoteColumns.PARENT_ID) : 0;
if (mIsCreate || mParentId != parentId) {
@ -298,6 +312,7 @@ public class SqlNote {
String snippet = note.has(NoteColumns.SNIPPET) ? note
.getString(NoteColumns.SNIPPET) : "";
// 如果只是通过上下文对note进行数据库操作或者该文本片段与原文本片段不相同
if (mIsCreate || !mSnippet.equals(snippet)) {
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
}
@ -316,12 +331,13 @@ public class SqlNote {
mDiffNoteValues.put(NoteColumns.WIDGET_ID, widgetId);
}
mWidgetId = widgetId;
// 获取数据的小部件种类
int widgetType = note.has(NoteColumns.WIDGET_TYPE) ? note
.getInt(NoteColumns.WIDGET_TYPE) : Notes.TYPE_WIDGET_INVALIDE;
if (mIsCreate || mWidgetType != widgetType) {
mDiffNoteValues.put(NoteColumns.WIDGET_TYPE, widgetType);
}
// 将该小部件种类覆盖原小部件种类
mWidgetType = widgetType;
long originParent = note.has(NoteColumns.ORIGIN_PARENT_ID) ? note
@ -330,7 +346,7 @@ public class SqlNote {
mDiffNoteValues.put(NoteColumns.ORIGIN_PARENT_ID, originParent);
}
mOriginParent = originParent;
// 遍历 dataArray查找 id 为 dataId 的数据
for (int i = 0; i < dataArray.length(); i++) {
JSONObject data = dataArray.getJSONObject(i);
SqlData sqlData = null;
@ -343,11 +359,13 @@ public class SqlNote {
}
}
// 如果数据库数据没有进行更新,就根据上下文创建一个数据库数据,并添加到数据列表中
if (sqlData == null) {
sqlData = new SqlData(mContext);
mDataList.add(sqlData);
}
// 最后为数据库数据进行设置
sqlData.setContent(data);
}
}
@ -358,7 +376,7 @@ public class SqlNote {
}
return true;
}
// 获取content机制提供的数据并加载到note中
public JSONObject getContent() {
try {
JSONObject js = new JSONObject();
@ -369,6 +387,7 @@ public class SqlNote {
}
JSONObject note = new JSONObject();
//类型为note时
if (mType == Notes.TYPE_NOTE) {
note.put(NoteColumns.ID, mId);
note.put(NoteColumns.ALERTED_DATE, mAlertDate);
@ -384,7 +403,9 @@ public class SqlNote {
note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent);
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
// 获取数据库数据,并存入数组中
JSONArray dataArray = new JSONArray();
// 将note中的data全部存入JSONArray中
for (SqlData sqlData : mDataList) {
JSONObject data = sqlData.getContent();
if (data != null) {
@ -401,17 +422,18 @@ public class SqlNote {
return js;
} catch (JSONException e) {
// 捕获json类型异常显示错误打印堆栈痕迹
Log.e(TAG, e.toString());
e.printStackTrace();
}
return null;
}
// 给当前id设置父id
public void setParentId(long id) {
mParentId = id;
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
}
// 给当前id设置Gtaskid
public void setGtaskId(String gid) {
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
}
@ -419,27 +441,27 @@ public class SqlNote {
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的父id
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)) {
@ -450,6 +472,7 @@ public class SqlNote {
try {
mId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) {
// 捕获异常转换出错显示错误“获取note的id出现错误”
Log.e(TAG, "Get note id error :" + e.toString());
throw new ActionFailureException("create note failed");
}
@ -463,25 +486,28 @@ public class SqlNote {
}
}
} else {
// 如果该便签ID是无效ID报错没有这个便签
if (mId <= 0 && mId != Notes.ID_ROOT_FOLDER && mId != Notes.ID_CALL_RECORD_FOLDER) {
Log.e(TAG, "No such note");
throw new IllegalStateException("Try to update note with invalid id");
}
if (mDiffNoteValues.size() > 0) {
// 更新版本:版本升级一个等级
mVersion ++;
int result = 0;
if (!validateVersion) {
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
+ NoteColumns.ID + "=?)", new String[] {
String.valueOf(mId)
String.valueOf(mId)
});
} else {
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
+ NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)",
+ NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)",
new String[] {
String.valueOf(mId), String.valueOf(mVersion)
});
}
// 如果内容解析器没有更新,那么报错:没有更新,或许用户在同步时进行更新
if (result == 0) {
Log.w(TAG, "there is no update. maybe user updates note when syncing");
}
@ -495,11 +521,14 @@ public class SqlNote {
}
// refresh local info
// 更新本地信息
loadFromCursor(mId);
if (mType == Notes.TYPE_NOTE)
loadDataContent();
// 清空,回到初始化状态
mDiffNoteValues.clear();
// 改变数据库构造模式
mIsCreate = false;
}
}
}

@ -54,6 +54,7 @@ public class Task extends Node {
mMetaInfo = null;
}
// 创建行动
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
@ -103,21 +104,26 @@ public class Task extends Node {
return js;
}
// 表示具有给定actionId的任务的更新操作。它包括操作类型、操作ID和实体δ
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
try {
// action_type
// 行动方式
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE);
// action_id
// 行动方式
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
// id
js.put(GTaskStringUtils.GTASK_JSON_ID, getGid());
// entity_delta
// 实体δ
JSONObject entity = new JSONObject();
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
if (getNotes() != null) {
@ -135,6 +141,8 @@ public class Task extends Node {
return js;
}
// 基于从Google Tasks API接收到的JSON对象设置任务的内容。它解析JSON对象并相应地设置任务属性
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
@ -175,6 +183,9 @@ public class Task extends Node {
}
}
// 于在应用程序中本地存储的JSON对象设置任务的内容。
// 预期JSON对象具有特定的格式包括一个笔记和数据数组。该方法解析JSON对象并根据具有“note” MIME类型的第一个数据项设置任务名称
public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)
|| !js.has(GTaskStringUtils.META_HEAD_DATA)) {
@ -204,6 +215,9 @@ public class Task extends Node {
}
}
//该方法创建一个JSON对象其中包含笔记的内容和元数据可以是本地创建的新笔记也可以是已与远程服务器同步的笔记。
// 如果注释是新的它会创建一个新的JSON对象并将注释的内容添加到该对象中。
// 如果之前已经同步过该笔记它将使用新内容更新JSON对象。该方法返回结果JSON对象如果有错误则返回null
public JSONObject getLocalJSONFromContent() {
String name = getName();
try {
@ -247,6 +261,8 @@ public class Task extends Node {
}
}
// 该方法设置注释的元数据。元数据作为元数据对象传递然后转换为JSON对象并存储在mMetaInfo实例变量中。
public void setMetaInfo(MetaData metaData) {
if (metaData != null && metaData.getNotes() != null) {
try {
@ -258,6 +274,13 @@ public class Task extends Node {
}
}
// 该方法根据注释的本地和远程状态确定需要对其采取的同步操作。
// SYNC_ACTION_NONE:不需要同步操作,因为两边都没有更新。
// SYNC_ACTION_UPDATE_REMOTE:使用本地更改更新远程服务器。
// SYNC_ACTION_UPDATE_LOCAL:使用来自远程服务器的更改更新本地注释。
// SYNC_ACTION_UPDATE_CONFLICT:双方都有冲突的更新,因此需要解决同步问题。
// SYNC_ACTION_ERROR:在确定同步操作时发生错误
public int getSyncAction(Cursor c) {
try {
JSONObject noteInfo = null;
@ -311,6 +334,9 @@ public class Task extends Node {
return SYNC_ACTION_ERROR;
}
/*
*/
public boolean isWorthSaving() {
return mMetaInfo != null || (getName() != null && getName().trim().length() > 0)
|| (getNotes() != null && getNotes().trim().length() > 0);

@ -37,12 +37,15 @@ public class TaskList extends Node {
private ArrayList<Task> mChildren;
// 构造函数
public TaskList() {
super();
mChildren = new ArrayList<Task>();
mIndex = 1;
}
// 创建一个动作
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
@ -74,6 +77,10 @@ public class TaskList extends Node {
return js;
}
/*
JSON
actionIdJSONObjectJSONObjectIDIDJSON
*/
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
@ -103,6 +110,9 @@ public class TaskList extends Node {
return js;
}
// 远程JSON对象设置任务列表的内容。
// 它接受JSONObject作为参数并从中提取ID、最后修改的时间戳和任务列表的名称。如果JSON对象中缺少这些字段中的任何一个则抛出JSONException。
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
@ -129,6 +139,10 @@ public class TaskList extends Node {
}
}
/*
JSONJSONObject
*/
public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) {
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
@ -157,6 +171,11 @@ public class TaskList extends Node {
}
}
/*
JSON
JSONObjectJSONObjectJSONObject
*/
public JSONObject getLocalJSONFromContent() {
try {
JSONObject js = new JSONObject();
@ -183,6 +202,13 @@ public class TaskList extends Node {
}
}
/*
Cursor
SYNC_ACTION_NONE
SYNC_ACTION_UPDATE_LOCAL
gtask IDIDSYNC_ACTION_UPDATE_REMOTE
SYNC_ACTION_ERROR
*/
public int getSyncAction(Cursor c) {
try {
if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
@ -216,10 +242,15 @@ public class TaskList extends Node {
return SYNC_ACTION_ERROR;
}
// 返回当前任务拥有的子任务的数量。
public int getChildTaskCount() {
return mChildren.size();
}
/*
truefalse
*/
public boolean addChildTask(Task task) {
boolean ret = false;
if (task != null && !mChildren.contains(task)) {
@ -234,6 +265,12 @@ public class TaskList extends Node {
return ret;
}
/*
false
truefalse
*/
public boolean addChildTask(Task task, int index) {
if (index < 0 || index > mChildren.size()) {
Log.e(TAG, "add child task: invalid index");
@ -260,6 +297,13 @@ public class TaskList extends Node {
return true;
}
/*
false
truefalse
*/
public boolean removeChildTask(Task task) {
boolean ret = false;
int index = mChildren.indexOf(task);
@ -281,6 +325,7 @@ public class TaskList extends Node {
return ret;
}
// 将子任务移动到子任务列表中的新位置。
public boolean moveChildTask(Task task, int index) {
if (index < 0 || index >= mChildren.size()) {
@ -299,6 +344,7 @@ public class TaskList extends Node {
return (removeChildTask(task) && addChildTask(task, index));
}
// 查找具有特定GID(全局标识符)的子任务并返回它
public Task findChildTaskByGid(String gid) {
for (int i = 0; i < mChildren.size(); i++) {
Task t = mChildren.get(i);
@ -309,10 +355,12 @@ public class TaskList extends Node {
return null;
}
//返回子任务列表中子任务的索引。
public int getChildTaskIndex(Task task) {
return mChildren.indexOf(task);
}
// 返回指定索引的子任务。如果索引无效则返回null。
public Task getChildTaskByIndex(int index) {
if (index < 0 || index >= mChildren.size()) {
Log.e(TAG, "getTaskByIndex: invalid index");
@ -321,6 +369,8 @@ public class TaskList extends Node {
return mChildren.get(index);
}
// 返回具有特定GID的子任务。
// 如果没有找到任务则返回null。
public Task getChilTaskByGid(String gid) {
for (Task task : mChildren) {
if (task.getGid().equals(gid))
@ -329,6 +379,7 @@ public class TaskList extends Node {
return null;
}
public ArrayList<Task> getChildTaskList() {
return this.mChildren;
}

@ -16,6 +16,8 @@
package net.micode.notes.gtask.exception;
// ActionFailureException 继承 RuntimeException
// 为操作失败的情况,检查异常 显式地捕获或在方法的throws子句中声明
public class ActionFailureException extends RuntimeException {
private static final long serialVersionUID = 4425249765923293627L;

@ -16,17 +16,21 @@
package net.micode.notes.gtask.exception;
//
public class NetworkFailureException extends Exception {
private static final long serialVersionUID = 2107610287180234136L;
// 这是一个默认构造函数,调用父类的默认构造函数
public NetworkFailureException() {
super();
}
// 该构造函数接受一个字符串参数,表示与异常关联的错误消息
public NetworkFailureException(String paramString) {
super(paramString);
}
// 该构造函数接受两个参数:表示错误消息的字符串和表示异常原因的Throwable对象
public NetworkFailureException(String paramString, Throwable paramThrowable) {
super(paramString, paramThrowable);
}

@ -45,6 +45,8 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
private OnCompleteListener mOnCompleteListener;
// 构造函数,初始化
public GTaskASyncTask(Context context, OnCompleteListener listener) {
mContext = context;
mOnCompleteListener = listener;
@ -53,16 +55,21 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
mTaskManager = GTaskManager.getInstance();
}
// 调用mTaskManager对象的cancelSync()方法来取消同步任务mTaskManager对象是GTaskManager的实例
public void cancelSync() {
mTaskManager.cancelSync();
}
// 通过调用AsyncTask的publishProgress()方法来发布同步任务的进度
public void publishProgess(String message) {
publishProgress(new String[] {
message
});
}
// 同步期间向用户显示通知
private void showNotification(int tickerId, String content) {
Notification notification = new Notification(R.drawable.notification, mContext
.getString(tickerId), System.currentTimeMillis());
@ -81,6 +88,8 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);
}
// 在后台执行同步任务
@Override
protected Integer doInBackground(Void... unused) {
publishProgess(mContext.getString(R.string.sync_progress_login, NotesPreferenceActivity
@ -88,6 +97,7 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
return mTaskManager.sync(mContext, this);
}
// 同步过程中更新通知消息
@Override
protected void onProgressUpdate(String... progress) {
showNotification(R.string.ticker_syncing, progress[0]);
@ -96,6 +106,7 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
}
}
// 在后台同步任务完成时被调用
@Override
protected void onPostExecute(Integer result) {
if (result == GTaskManager.STATE_SUCCESS) {

@ -64,10 +64,13 @@ import java.util.zip.InflaterInputStream;
public class GTaskClient {
private static final String TAG = GTaskClient.class.getSimpleName();
// Gtask 一般请求的URL
private static final String GTASK_URL = "https://mail.google.com/tasks/";
// Gtask get请求的URL
private static final String GTASK_GET_URL = "https://mail.google.com/tasks/ig";
// Gtask post请求的URL
private static final String GTASK_POST_URL = "https://mail.google.com/tasks/r/ig";
private static GTaskClient mInstance = null;
@ -90,6 +93,8 @@ public class GTaskClient {
private JSONArray mUpdateArray;
// 构造函数,初始化各个变量
private GTaskClient() {
mHttpClient = null;
mGetUrl = GTASK_GET_URL;
@ -102,6 +107,7 @@ public class GTaskClient {
mUpdateArray = null;
}
// 提供与Google任务交互的方法
public static synchronized GTaskClient getInstance() {
if (mInstance == null) {
mInstance = new GTaskClient();
@ -109,6 +115,9 @@ public class GTaskClient {
return mInstance;
}
// 检查用户是否已经登录使用
// loginGoogleAccount()方法登录,该方法返回身份验证令牌。
// 然后如果用户有自定义域名该方法尝试使用用户的自定义域名登录如果失败则尝试使用Google官方网址登录
public boolean login(Activity activity) {
// we suppose that the cookie would expire after 5 minutes
// then we need to re-login
@ -164,6 +173,7 @@ public class GTaskClient {
return true;
}
// 使用AccountManager类登录Google账户
private String loginGoogleAccount(Activity activity, boolean invalidateToken) {
String authToken;
AccountManager accountManager = AccountManager.get(activity);
@ -207,6 +217,7 @@ public class GTaskClient {
return authToken;
}
// 可能认证令牌已经过期,现在让我们使令牌无效并重试
private boolean tryToLoginGtask(Activity activity, String authToken) {
if (!loginGtask(authToken)) {
// maybe the auth token is out of date, now let's invalidate the
@ -225,6 +236,7 @@ public class GTaskClient {
return true;
}
// HttpClient类来登录Google任务
private boolean loginGtask(String authToken) {
int timeoutConnection = 10000;
int timeoutSocket = 15000;
@ -284,6 +296,7 @@ public class GTaskClient {
return mActionId++;
}
// 创建Http服务
private HttpPost createHttpPost() {
HttpPost httpPost = new HttpPost(mPostUrl);
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
@ -291,6 +304,7 @@ public class GTaskClient {
return httpPost;
}
// 获取http请求并且错误时抛出请求错误异常
private String getResponseContent(HttpEntity entity) throws IOException {
String contentEncoding = null;
if (entity.getContentEncoding() != null) {
@ -323,6 +337,8 @@ public class GTaskClient {
}
}
// 获取post请求错误时抛出网络异常请求
private JSONObject postRequest(JSONObject js) throws NetworkFailureException {
if (!mLoggedin) {
Log.e(TAG, "please login first");
@ -360,6 +376,8 @@ public class GTaskClient {
}
}
// 创建task请求错误时抛出网络错误异常
public void createTask(Task task) throws NetworkFailureException {
commitUpdate();
try {
@ -386,6 +404,8 @@ public class GTaskClient {
}
}
// 创建tasklist请求错误时抛出网络错误异常
public void createTaskList(TaskList tasklist) throws NetworkFailureException {
commitUpdate();
try {
@ -412,6 +432,8 @@ public class GTaskClient {
}
}
// 提交更新请求,抛出网络错误异常
public void commitUpdate() throws NetworkFailureException {
if (mUpdateArray != null) {
try {
@ -433,6 +455,8 @@ public class GTaskClient {
}
}
// 添加更新节点,网络错误抛出异常
public void addUpdateNode(Node node) throws NetworkFailureException {
if (node != null) {
// too many update items may result in an error
@ -447,6 +471,8 @@ public class GTaskClient {
}
}
// 移动task操作
public void moveTask(Task task, TaskList preParent, TaskList curParent)
throws NetworkFailureException {
commitUpdate();
@ -463,18 +489,23 @@ public class GTaskClient {
if (preParent == curParent && task.getPriorSibling() != null) {
// put prioring_sibing_id only if moving within the tasklist and
// it is not the first one
// 只有在任务列表中移动时才放置prioring_sibing_id而且它不是第一个
action.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, task.getPriorSibling());
}
action.put(GTaskStringUtils.GTASK_JSON_SOURCE_LIST, preParent.getGid());
action.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT, curParent.getGid());
if (preParent != curParent) {
// put the dest_list only if moving between tasklists
// 只有在任务列表之间移动时才放置dest_list
action.put(GTaskStringUtils.GTASK_JSON_DEST_LIST, curParent.getGid());
}
actionList.put(action);
jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList);
// client_version
// 客户端版本
jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
postRequest(jsPost);
@ -486,6 +517,8 @@ public class GTaskClient {
}
}
// 删除节点操作,当网络错误时抛出异常
public void deleteNode(Node node) throws NetworkFailureException {
commitUpdate();
try {
@ -498,6 +531,8 @@ public class GTaskClient {
jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList);
// client_version
// 客户端版本
jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
postRequest(jsPost);
@ -509,6 +544,9 @@ public class GTaskClient {
}
}
// 它首先检查用户是否已登录,如果没有则抛出异常。
// 然后它向一个URL发送HTTP GET请求以检索一个字符串响应
public JSONArray getTaskLists() throws NetworkFailureException {
if (!mLoggedin) {
Log.e(TAG, "please login first");
@ -547,6 +585,8 @@ public class GTaskClient {
}
}
// 构造一个表示POST请求的JSONObject包括要在任务列表上执行的操作数组并将此请求发送到服务器
public JSONArray getTaskList(String listGid) throws NetworkFailureException {
commitUpdate();
try {
@ -575,11 +615,13 @@ public class GTaskClient {
}
}
// 该方法返回与该类实例关联的帐户对象
public Account getSyncAccount() {
return mAccount;
}
// 该方法将更新数组重置为null
public void resetUpdateArray() {
mUpdateArray = null;
}
}
}

@ -87,6 +87,8 @@ public class GTaskManager {
private HashMap<Long, String> mNidToGid;
// 构造函数,初始化变量
private GTaskManager() {
mSyncing = false;
mCancelled = false;
@ -99,6 +101,7 @@ public class GTaskManager {
mNidToGid = new HashMap<Long, String>();
}
public static synchronized GTaskManager getInstance() {
if (mInstance == null) {
mInstance = new GTaskManager();
@ -106,11 +109,15 @@ public class GTaskManager {
return mInstance;
}
// 用于获取authtoken
public synchronized void setActivityContext(Activity activity) {
// used for getting authtoken
mActivity = activity;
}
// 调用来启动同步过程。
// 它以Context对象和GTaskASyncTask对象作为参数。Context对象用于获取ContentResolver对象GTaskASyncTask对象用于报告同步进程的进度。
public int sync(Context context, GTaskASyncTask asyncTask) {
if (mSyncing) {
Log.d(TAG, "Sync is in progress");
@ -139,10 +146,12 @@ public class GTaskManager {
}
// get the task list from google
// 获取task信息从google中
asyncTask.publishProgess(mContext.getString(R.string.sync_progress_init_list));
initGTaskList();
// do content sync work
// 进行同步操作
asyncTask.publishProgess(mContext.getString(R.string.sync_progress_syncing));
syncContent();
} catch (NetworkFailureException e) {
@ -168,6 +177,12 @@ public class GTaskManager {
return mCancelled ? STATE_SYNC_CANCELLED : STATE_SUCCESS;
}
/*
initGTaskList()使GTaskClientgetTaskLists()
*/
private void initGTaskList() throws NetworkFailureException {
if (mCancelled)
return;
@ -247,6 +262,14 @@ public class GTaskManager {
}
}
/*
ID
*/
private void syncContent() throws NetworkFailureException {
int syncType;
Cursor c = null;
@ -351,6 +374,15 @@ public class GTaskManager {
}
/*
()
IDIDID
()()
ID
*/
private void syncFolder() throws NetworkFailureException {
Cursor c = null;
String gid;
@ -476,6 +508,10 @@ public class GTaskManager {
GTaskClient.getInstance().commitUpdate();
}
/*
syncTypeswitch
*/
private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -522,6 +558,13 @@ public class GTaskManager {
}
}
/*
mCancelledmCancelledfalseNodeSqlNote
NodeTaskListidSqlNote
SqlNoteJSONparentIdNotes.ID_ROOT_FOLDER
*/
private void addLocalNode(Node node) throws NetworkFailureException {
if (mCancelled) {
return;
@ -596,6 +639,7 @@ public class GTaskManager {
updateRemoteMeta(node.getGid(), sqlNote);
}
// 基本用途同addLocalNode一样只是并不是添加而是更新
private void updateLocalNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -619,6 +663,12 @@ public class GTaskManager {
updateRemoteMeta(node.getGid(), sqlNote);
}
/*
"Cursor"使Tasks API
SqlNoteGTaskID
*/
private void addRemoteNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -692,6 +742,11 @@ public class GTaskManager {
mNidToGid.put(sqlNote.getId(), n.getGid());
}
/*
"Cursor"使Tasks APINodeSqlNote
SqlNote
*/
private void updateRemoteNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -730,6 +785,13 @@ public class GTaskManager {
sqlNote.commit(true);
}
/*
SqlNote
mMetaHashMapHashMapgidMetaData
MetaDataSqlNote使GTaskClientMetaData
MetaDataMetaDataSqlNoteMetaDatamMetaHashMap使GTaskClient
NetworkFailureException
*/
private void updateRemoteMeta(String gid, SqlNote sqlNote) throws NetworkFailureException {
if (sqlNote != null && sqlNote.isNoteType()) {
MetaData metaData = mMetaHashMap.get(gid);
@ -746,6 +808,10 @@ public class GTaskManager {
}
}
/*
mCancelledtrue
HashMap(mGTaskHashMap, mgtasklistthashmapmMetaHashMap)使initGTaskList()GTaskList
*/
private void refreshLocalSyncId() throws NetworkFailureException {
if (mCancelled) {
return;
@ -790,10 +856,13 @@ public class GTaskManager {
}
}
// 该方法检索GTaskClient对象使用的同步帐户的名称。
public String getSyncAccount() {
return GTaskClient.getInstance().getSyncAccount().name;
}
// 该方法将mCancelled标志设置为true该标志可用于取消同步进程。
public void cancelSync() {
mCancelled = true;
}

@ -42,6 +42,8 @@ public class GTaskSyncService extends Service {
private static String mSyncProgress = "";
// 使用 GTaskASyncTask 实例启动同步任务,它是一个单独的类,用于在后台执行同步
private void startSync() {
if (mSyncTask == null) {
mSyncTask = new GTaskASyncTask(this, new GTaskASyncTask.OnCompleteListener() {
@ -56,17 +58,22 @@ public class GTaskSyncService extends Service {
}
}
// 取消同步任务,如果它当前正在运行
private void cancelSync() {
if (mSyncTask != null) {
mSyncTask.cancelSync();
}
}
// mSyncTask 字段初始化为 null
@Override
public void onCreate() {
mSyncTask = null;
}
// 通过检查 ACTION_STRING_NAME 额外字段并执行适当的操作来处理传入的广播意图
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Bundle bundle = intent.getExtras();
@ -86,6 +93,8 @@ public class GTaskSyncService extends Service {
return super.onStartCommand(intent, flags, startId);
}
// 在系统内存不足时取消同步任务
@Override
public void onLowMemory() {
if (mSyncTask != null) {
@ -93,10 +102,13 @@ public class GTaskSyncService extends Service {
}
}
public IBinder onBind(Intent intent) {
return null;
}
// 发送具有当前同步进度和状态的广播意图
public void sendBroadcast(String msg) {
mSyncProgress = msg;
Intent intent = new Intent(GTASK_SERVICE_BROADCAST_NAME);
@ -105,6 +117,7 @@ public class GTaskSyncService extends Service {
sendBroadcast(intent);
}
// 开始同步
public static void startSync(Activity activity) {
GTaskManager.getInstance().setActivityContext(activity);
Intent intent = new Intent(activity, GTaskSyncService.class);
@ -112,16 +125,20 @@ public class GTaskSyncService extends Service {
activity.startService(intent);
}
// 取消同步
public static void cancelSync(Context context) {
Intent intent = new Intent(context, GTaskSyncService.class);
intent.putExtra(GTaskSyncService.ACTION_STRING_NAME, GTaskSyncService.ACTION_CANCEL_SYNC);
context.startService(intent);
}
// 正在同步
public static boolean isSyncing() {
return mSyncTask != null;
}
// 获取进度
public static String getProgressString() {
return mSyncProgress;
}

@ -1,96 +0,0 @@
#Sat Mar 18 10:49:27 GMT+08:00 2023
net.micode.notes.app-main-7\:/drawable-hdpi/font_super.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_font_super.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/call_record.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_call_record.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/new_note_normal.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_new_note_normal.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/edit_yellow.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_edit_yellow.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/edit_title_green.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_edit_title_green.9.png.flat
net.micode.notes.app-main-7\:/menu/sub_folder.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\menu_sub_folder.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/edit_title_yellow.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_edit_title_yellow.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/font_small.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_font_small.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/widget_2x_white.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_widget_2x_white.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/edit_white.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_edit_white.9.png.flat
net.micode.notes.app-main-7\:/layout/account_dialog_title.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\layout_account_dialog_title.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/widget_4x_green.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_widget_4x_green.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_blue_down.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_blue_down.9.png.flat
net.micode.notes.app-main-7\:/color/secondary_text_dark.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\color_secondary_text_dark.xml.flat
net.micode.notes.app-main-7\:/layout/dialog_edit_text.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\layout_dialog_edit_text.xml.flat
net.micode.notes.app-main-7\:/layout/widget_4x.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\layout_widget_4x.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_yellow_middle.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_yellow_middle.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/menu_delete.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_menu_delete.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/clock.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_clock.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/font_normal.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_font_normal.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/dropdown_icon.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_dropdown_icon.9.png.flat
net.micode.notes.app-main-7\:/layout/note_edit.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\layout_note_edit.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/edit_green.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_edit_green.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_green_single.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_green_single.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_white_single.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_white_single.9.png.flat
net.micode.notes.app-main-7\:/raw-zh-rCN/introduction=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\raw-zh-rCN_introduction.flat
net.micode.notes.app-main-7\:/drawable-hdpi/widget_2x_green.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_widget_2x_green.png.flat
net.micode.notes.app-main-7\:/xml/preferences.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\xml_preferences.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_red_single.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_red_single.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/delete.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_delete.png.flat
net.micode.notes.app-main-7\:/menu/call_record_folder.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\menu_call_record_folder.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/widget_2x_red.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_widget_2x_red.png.flat
net.micode.notes.app-main-7\:/layout/widget_2x.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\layout_widget_2x.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/menu_move.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_menu_move.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_green_down.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_green_down.9.png.flat
net.micode.notes.app-main-7\:/layout/note_edit_list_item.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\layout_note_edit_list_item.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/widget_2x_blue.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_widget_2x_blue.png.flat
net.micode.notes.app-main-7\:/layout/add_account_text.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\layout_add_account_text.xml.flat
net.micode.notes.app-main-7\:/xml/widget_4x_info.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\xml_widget_4x_info.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/font_size_selector_bg.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_font_size_selector_bg.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/selected.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_selected.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/search_result.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_search_result.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/widget_4x_white.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_widget_4x_white.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_blue_middle.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_blue_middle.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_green_middle.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_green_middle.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_white_down.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_white_down.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_blue_single.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_blue_single.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/font_large.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_font_large.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_yellow_up.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_yellow_up.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_red_middle.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_red_middle.9.png.flat
net.micode.notes.app-main-7\:/layout/settings_header.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\layout_settings_header.xml.flat
net.micode.notes.app-main-7\:/menu/note_list.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\menu_note_list.xml.flat
net.micode.notes.app-main-7\:/menu/call_note_edit.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\menu_call_note_edit.xml.flat
net.micode.notes.app-main-7\:/drawable/new_note.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable_new_note.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/edit_red.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_edit_red.9.png.flat
net.micode.notes.app-main-7\:/layout/note_list.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\layout_note_list.xml.flat
net.micode.notes.app-main-7\:/color/primary_text_dark.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\color_primary_text_dark.xml.flat
net.micode.notes.app-main-7\:/layout/datetime_picker.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\layout_datetime_picker.xml.flat
net.micode.notes.app-main-7\:/raw/introduction=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\raw_introduction.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_yellow_single.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_yellow_single.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/widget_4x_yellow.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_widget_4x_yellow.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/widget_4x_red.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_widget_4x_red.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/title_alert.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_title_alert.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_red_down.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_red_down.9.png.flat
net.micode.notes.app-main-7\:/menu/note_list_options.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\menu_note_list_options.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/widget_2x_yellow.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_widget_2x_yellow.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/icon_app.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_icon_app.png.flat
net.micode.notes.app-main-7\:/layout/note_item.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\layout_note_item.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_background.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_background.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/edit_title_red.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_edit_title_red.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/title_bar_bg.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_title_bar_bg.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_footer_bg.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_footer_bg.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/new_note_pressed.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_new_note_pressed.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_green_up.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_green_up.9.png.flat
net.micode.notes.app-main-7\:/layout/note_list_dropdown_menu.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\layout_note_list_dropdown_menu.xml.flat
net.micode.notes.app-main-7\:/layout/note_list_footer.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\layout_note_list_footer.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_red_up.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_red_up.9.png.flat
net.micode.notes.app-main-7\:/menu/note_list_dropdown.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\menu_note_list_dropdown.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_white_up.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_white_up.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/edit_title_blue.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_edit_title_blue.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/bg_color_btn_mask.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_bg_color_btn_mask.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/edit_blue.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_edit_blue.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/bg_btn_set_color.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_bg_btn_set_color.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/edit_title_white.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_edit_title_white.9.png.flat
net.micode.notes.app-main-7\:/xml/searchable.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\xml_searchable.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/notification.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_notification.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_blue_up.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_blue_up.9.png.flat
net.micode.notes.app-main-7\:/xml/widget_2x_info.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\xml_widget_2x_info.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/note_edit_color_selector_panel.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_note_edit_color_selector_panel.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_white_middle.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_white_middle.9.png.flat
net.micode.notes.app-main-7\:/layout/folder_list_item.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\layout_folder_list_item.xml.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_folder.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_folder.9.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/widget_4x_blue.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_widget_4x_blue.png.flat
net.micode.notes.app-main-7\:/drawable-hdpi/list_yellow_down.9.png=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\drawable-hdpi_list_yellow_down.9.png.flat
net.micode.notes.app-main-7\:/menu/note_edit.xml=D\:\\Notes-master1\\app\\build\\intermediates\\merged_res\\debug\\menu_note_edit.xml.flat

@ -1,169 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:ns1="urn:oasis:names:tc:xliff:document:1.2">
<string-array name="format_for_exported_note">
<item>-%s</item>
<item>--%s</item>
<item>--%s</item>
<item>--%s</item>
</string-array>
<string-array name="menu_share_ways">
<item>Messaging</item>
<item>Email</item>
</string-array>
<color name="user_query_highlight">#335b5b5b</color>
<dimen name="text_font_size_large">26sp</dimen>
<dimen name="text_font_size_medium">20sp</dimen>
<dimen name="text_font_size_normal">17sp</dimen>
<dimen name="text_font_size_small">14sp</dimen>
<dimen name="text_font_size_super">33sp</dimen>
<plurals name="search_results_title">
<item quantity="one"><ns1:g example="1" id="number">%1$s</ns1:g> result for \"<ns1:g example="???" id="search">%2$s</ns1:g>\"</item>
<item quantity="other"><ns1:g example="15" id="number">%1$s</ns1:g> results for \"<ns1:g example="???" id="search">%2$s</ns1:g>\"</item>
</plurals>
<string name="alert_message_delete_folder">Confirm to delete folder and its notes?</string>
<string name="alert_message_delete_note">Confirm to delete this note?</string>
<string name="alert_message_delete_notes">Confirm to delete the selected %d notes?</string>
<string name="alert_title_delete">Delete selected notes</string>
<string name="app_name">Notes</string>
<string name="app_widget2x2">Notes 2x2</string>
<string name="app_widget4x4">Notes 4x4</string>
<string name="button_delete">Delete</string>
<string name="call_record_folder_name">Call notes</string>
<string name="datetime_dialog_cancel">cancel</string>
<string name="datetime_dialog_ok">set</string>
<string name="delete_remind_time_message">Delete reminder successfully</string>
<string name="error_note_empty_for_clock">Sorry, can not set clock on empty note</string>
<string name="error_note_empty_for_send_to_desktop">Sorry, can not send and empty note to home</string>
<string name="error_note_not_exist">The note is not exist</string>
<string name="error_sdcard_export">Export failed, please check SD card</string>
<string name="error_sdcard_unmounted">SD card busy, not available now</string>
<string name="error_sync_cancelled">Sync is canceled</string>
<string name="error_sync_internal">Sync failed, internal error occurs</string>
<string name="error_sync_network">Sync failed, please check network and account settings</string>
<string name="failed_sdcard_export">Export fail</string>
<string name="file_name_txt_format">notes_%s.txt</string>
<string name="file_path">/MIUI/notes/</string>
<string name="folder_exist">The folder %1$s exist, please rename</string>
<string name="format_date_ymd">yyyyMMdd</string>
<string name="format_datetime_mdhm">MMMd kk:mm</string>
<string name="format_exported_file_location">Export text file (%1$s) to SD (%2$s) directory</string>
<string name="format_folder_files_count">(%d)</string>
<string name="format_move_notes_to_folder">Have moved selected %1$d notes to %2$s folder</string>
<string name="hint_foler_name">Input name</string>
<string name="info_note_enter_desktop">Note added to home</string>
<string name="menu_alert">Remind me</string>
<string name="menu_create_folder">New Folder</string>
<string name="menu_delete">Delete</string>
<string name="menu_deselect_all">Deselect all</string>
<string name="menu_export_text">Export text</string>
<string name="menu_folder_change_name">Change folder name</string>
<string name="menu_folder_delete">Delete folder</string>
<string name="menu_folder_view">View folder</string>
<string name="menu_font_large">Large</string>
<string name="menu_font_normal">Medium</string>
<string name="menu_font_size">Font size</string>
<string name="menu_font_small">Small</string>
<string name="menu_font_super">Super</string>
<string name="menu_list_mode">Enter check list</string>
<string name="menu_move">Move to folder</string>
<string name="menu_move_parent_folder">Parent folder</string>
<string name="menu_normal_mode">Leave check list</string>
<string name="menu_remove_remind">Delete reminder</string>
<string name="menu_search">Search</string>
<string name="menu_select_all">Select all</string>
<string name="menu_select_none">Nothing selected, the operation is invalid</string>
<string name="menu_select_title">%d selected</string>
<string name="menu_send_to_desktop">Send to home</string>
<string name="menu_setting">Settings</string>
<string name="menu_share">Share</string>
<string name="menu_sync">Sync</string>
<string name="menu_sync_cancel">Cancel syncing</string>
<string name="menu_title_select_folder">Select folder</string>
<string name="note_alert_expired">Expired</string>
<string name="note_link_email">Send email</string>
<string name="note_link_other">Open map</string>
<string name="note_link_tel">Call</string>
<string name="note_link_web">Browse web</string>
<string name="notealert_enter">Take a look</string>
<string name="notealert_ok">Got it</string>
<string name="notelist_menu_new">Add note</string>
<string name="notelist_string_info">...</string>
<string name="preferences_account_summary">Sync notes with google task</string>
<string name="preferences_account_title">Sync account</string>
<string name="preferences_add_account">Add account</string>
<string name="preferences_bg_random_appear_title">New note background color random</string>
<string name="preferences_button_sync_cancel">Cancel syncing</string>
<string name="preferences_button_sync_immediately">Sync immediately</string>
<string name="preferences_dialog_change_account_title">Current account %1$s</string>
<string name="preferences_dialog_change_account_warn_msg">All sync related information will be deleted, which may result in duplicated items sometime</string>
<string name="preferences_dialog_select_account_tips">Please select a google account. Local notes will be synced with google task.</string>
<string name="preferences_dialog_select_account_title">Sync notes</string>
<string name="preferences_last_sync_time">Last sync time %1$s</string>
<string name="preferences_last_sync_time_format">yyyy-MM-dd hh:mm:ss</string>
<string name="preferences_menu_cancel">Cancel</string>
<string name="preferences_menu_change_account">Change sync account</string>
<string name="preferences_menu_remove_account">Remove sync account</string>
<string name="preferences_title">Settings</string>
<string name="preferences_toast_cannot_change_account">Cannot change the account because sync is in progress</string>
<string name="preferences_toast_success_set_accout">%1$s has been set as the sync account</string>
<string name="search">Notes</string>
<string name="search_hint">Search notes</string>
<string name="search_label">Searching Notes</string>
<string name="search_setting_description">Text in your notes</string>
<string name="set_remind_time_message">Set reminder</string>
<string name="success_sdcard_export">Export successful</string>
<string name="success_sync_account">Sync is successful with account %1$s</string>
<string name="sync_progress_init_list">Getting remote note list...</string>
<string name="sync_progress_login">Logging into %1$s...</string>
<string name="sync_progress_syncing">Synchronize local notes with Google Task...</string>
<string name="ticker_cancel">Sync is canceled</string>
<string name="ticker_fail">Sync is failed</string>
<string name="ticker_success">Sync is successful</string>
<string name="ticker_syncing">Syncing notes...</string>
<string name="widget_havenot_content">No associated note found, click to create associated note.</string>
<string name="widget_under_visit_mode">Privacy modecan not see note content</string>
<style name="HighlightTextAppearancePrimary">
<item name="android:textSize">@dimen/text_font_size_normal</item>
<item name="android:textColor">@color/primary_text_dark</item>
</style>
<style name="HighlightTextAppearanceSecondary">
<item name="android:textSize">@dimen/text_font_size_small</item>
<item name="android:textColor">@color/secondary_text_dark</item>
</style>
<style name="NoteActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:displayOptions"/>
<item name="android:visibility">gone</item>
</style>
<style name="NoteTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/NoteActionBarStyle</item>
</style>
<style name="TextAppearanceLarge">
<item name="android:textSize">@dimen/text_font_size_large</item>
<item name="android:textColorLink">#0000ff</item>
</style>
<style name="TextAppearanceMedium">
<item name="android:textSize">@dimen/text_font_size_medium</item>
<item name="android:textColorLink">#0000ff</item>
</style>
<style name="TextAppearanceNormal">
<item name="android:textSize">@dimen/text_font_size_normal</item>
<item name="android:textColorLink">#0000ff</item>
</style>
<style name="TextAppearancePrimaryItem">
<item name="android:textSize">@dimen/text_font_size_normal</item>
<item name="android:textColor">@color/primary_text_dark</item>
</style>
<style name="TextAppearanceSecondaryItem">
<item name="android:textSize">@dimen/text_font_size_small</item>
<item name="android:textColor">@color/secondary_text_dark</item>
</style>
<style name="TextAppearanceSuper">
<item name="android:textSize">@dimen/text_font_size_super</item>
<item name="android:textColorLink">#0000ff</item>
</style>
<style name="TextAppearanceUnderMenuIcon">
<item name="android:textSize">@dimen/text_font_size_normal</item>
<item name="android:textColor">@android:color/black</item>
</style>
</resources>

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<merger version="3"><dataSet config="main" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="D:\Notes-master1\app\src\main\assets"/><source path="D:\Notes-master1\app\build\intermediates\shader_assets\debug\out"/></dataSet><dataSet config="debug" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="D:\Notes-master1\app\src\debug\assets"/></dataSet></merger>

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<merger version="3"><dataSet config="main" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="D:\Notes-master1\app\src\main\jniLibs"/></dataSet><dataSet config="debug" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="D:\Notes-master1\app\src\debug\jniLibs"/></dataSet></merger>

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<merger version="3"><dataSet config="main" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="D:\Notes-master1\app\src\main\shaders"/></dataSet><dataSet config="debug" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="D:\Notes-master1\app\src\debug\shaders"/></dataSet></merger>

@ -1,4 +0,0 @@
#Sat Mar 18 11:16:59 GMT+08:00 2023
base.0=D\:\\Notes-master1\\app\\build\\intermediates\\dex\\debug\\mergeDexDebug\\classes.dex
renamed.0=classes.dex
path.0=classes.dex

@ -1,273 +0,0 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!--
3 Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16-->
17<manifest xmlns:android="http://schemas.android.com/apk/res/android"
18 package="net.micode.notes"
19 android:versionCode="1"
20 android:versionName="0.1" >
21
22 <uses-sdk
22-->D:\Notes-master1\app\src\main\AndroidManifest.xml:23:5-44
23 android:minSdkVersion="14"
23-->D:\Notes-master1\app\src\main\AndroidManifest.xml:23:15-41
24 android:targetSdkVersion="14" />
24-->D:\Notes-master1\app\src\main\AndroidManifest.xml:23:5-44
25
26 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
26-->D:\Notes-master1\app\src\main\AndroidManifest.xml:25:5-81
26-->D:\Notes-master1\app\src\main\AndroidManifest.xml:25:22-78
27 <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
27-->D:\Notes-master1\app\src\main\AndroidManifest.xml:26:5-88
27-->D:\Notes-master1\app\src\main\AndroidManifest.xml:26:22-85
28 <uses-permission android:name="android.permission.INTERNET" />
28-->D:\Notes-master1\app\src\main\AndroidManifest.xml:27:5-67
28-->D:\Notes-master1\app\src\main\AndroidManifest.xml:27:22-64
29 <uses-permission android:name="android.permission.READ_CONTACTS" />
29-->D:\Notes-master1\app\src\main\AndroidManifest.xml:28:5-72
29-->D:\Notes-master1\app\src\main\AndroidManifest.xml:28:22-69
30 <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
30-->D:\Notes-master1\app\src\main\AndroidManifest.xml:29:5-74
30-->D:\Notes-master1\app\src\main\AndroidManifest.xml:29:22-71
31 <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
31-->D:\Notes-master1\app\src\main\AndroidManifest.xml:30:5-80
31-->D:\Notes-master1\app\src\main\AndroidManifest.xml:30:22-77
32 <uses-permission android:name="android.permission.GET_ACCOUNTS" />
32-->D:\Notes-master1\app\src\main\AndroidManifest.xml:31:5-71
32-->D:\Notes-master1\app\src\main\AndroidManifest.xml:31:22-68
33 <uses-permission android:name="android.permission.USE_CREDENTIALS" />
33-->D:\Notes-master1\app\src\main\AndroidManifest.xml:32:5-74
33-->D:\Notes-master1\app\src\main\AndroidManifest.xml:32:22-71
34 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
34-->D:\Notes-master1\app\src\main\AndroidManifest.xml:33:5-81
34-->D:\Notes-master1\app\src\main\AndroidManifest.xml:33:22-78
35
36 <application
36-->D:\Notes-master1\app\src\main\AndroidManifest.xml:35:5-149:19
37 android:debuggable="true"
38 android:icon="@drawable/icon_app"
38-->D:\Notes-master1\app\src\main\AndroidManifest.xml:36:9-42
39 android:label="@string/app_name"
39-->D:\Notes-master1\app\src\main\AndroidManifest.xml:37:9-41
40 android:testOnly="true" >
41 <activity
41-->D:\Notes-master1\app\src\main\AndroidManifest.xml:38:9-51:20
42 android:name="net.micode.notes.ui.NotesListActivity"
42-->D:\Notes-master1\app\src\main\AndroidManifest.xml:39:13-49
43 android:configChanges="keyboardHidden|orientation|screenSize"
43-->D:\Notes-master1\app\src\main\AndroidManifest.xml:40:13-74
44 android:label="@string/app_name"
44-->D:\Notes-master1\app\src\main\AndroidManifest.xml:41:13-45
45 android:launchMode="singleTop"
45-->D:\Notes-master1\app\src\main\AndroidManifest.xml:42:13-43
46 android:theme="@style/NoteTheme"
46-->D:\Notes-master1\app\src\main\AndroidManifest.xml:43:13-45
47 android:uiOptions="splitActionBarWhenNarrow"
47-->D:\Notes-master1\app\src\main\AndroidManifest.xml:44:13-57
48 android:windowSoftInputMode="adjustPan" >
48-->D:\Notes-master1\app\src\main\AndroidManifest.xml:45:13-52
49 <intent-filter>
49-->D:\Notes-master1\app\src\main\AndroidManifest.xml:47:13-50:29
50 <action android:name="android.intent.action.MAIN" />
50-->D:\Notes-master1\app\src\main\AndroidManifest.xml:48:17-69
50-->D:\Notes-master1\app\src\main\AndroidManifest.xml:48:25-66
51
52 <category android:name="android.intent.category.LAUNCHER" />
52-->D:\Notes-master1\app\src\main\AndroidManifest.xml:49:17-77
52-->D:\Notes-master1\app\src\main\AndroidManifest.xml:49:27-74
53 </intent-filter>
54 </activity>
55 <activity
55-->D:\Notes-master1\app\src\main\AndroidManifest.xml:53:9-81:20
56 android:name="net.micode.notes.ui.NoteEditActivity"
56-->D:\Notes-master1\app\src\main\AndroidManifest.xml:54:13-48
57 android:configChanges="keyboardHidden|orientation|screenSize"
57-->D:\Notes-master1\app\src\main\AndroidManifest.xml:55:13-74
58 android:launchMode="singleTop"
58-->D:\Notes-master1\app\src\main\AndroidManifest.xml:56:13-43
59 android:theme="@style/NoteTheme" >
59-->D:\Notes-master1\app\src\main\AndroidManifest.xml:57:13-45
60 <intent-filter>
60-->D:\Notes-master1\app\src\main\AndroidManifest.xml:59:13-64:29
61 <action android:name="android.intent.action.VIEW" />
61-->D:\Notes-master1\app\src\main\AndroidManifest.xml:60:17-69
61-->D:\Notes-master1\app\src\main\AndroidManifest.xml:60:25-66
62
63 <category android:name="android.intent.category.DEFAULT" />
63-->D:\Notes-master1\app\src\main\AndroidManifest.xml:61:17-76
63-->D:\Notes-master1\app\src\main\AndroidManifest.xml:61:27-73
64
65 <data android:mimeType="vnd.android.cursor.item/text_note" />
65-->D:\Notes-master1\app\src\main\AndroidManifest.xml:62:17-78
65-->D:\Notes-master1\app\src\main\AndroidManifest.xml:62:23-75
66 <data android:mimeType="vnd.android.cursor.item/call_note" />
66-->D:\Notes-master1\app\src\main\AndroidManifest.xml:62:17-78
66-->D:\Notes-master1\app\src\main\AndroidManifest.xml:62:23-75
67 </intent-filter>
68 <intent-filter>
68-->D:\Notes-master1\app\src\main\AndroidManifest.xml:66:13-71:29
69 <action android:name="android.intent.action.INSERT_OR_EDIT" />
69-->D:\Notes-master1\app\src\main\AndroidManifest.xml:67:17-79
69-->D:\Notes-master1\app\src\main\AndroidManifest.xml:67:25-76
70
71 <category android:name="android.intent.category.DEFAULT" />
71-->D:\Notes-master1\app\src\main\AndroidManifest.xml:61:17-76
71-->D:\Notes-master1\app\src\main\AndroidManifest.xml:61:27-73
72
73 <data android:mimeType="vnd.android.cursor.item/text_note" />
73-->D:\Notes-master1\app\src\main\AndroidManifest.xml:62:17-78
73-->D:\Notes-master1\app\src\main\AndroidManifest.xml:62:23-75
74 <data android:mimeType="vnd.android.cursor.item/call_note" />
74-->D:\Notes-master1\app\src\main\AndroidManifest.xml:62:17-78
74-->D:\Notes-master1\app\src\main\AndroidManifest.xml:62:23-75
75 </intent-filter>
76 <intent-filter>
76-->D:\Notes-master1\app\src\main\AndroidManifest.xml:73:13-76:29
77 <action android:name="android.intent.action.SEARCH" />
77-->D:\Notes-master1\app\src\main\AndroidManifest.xml:74:17-71
77-->D:\Notes-master1\app\src\main\AndroidManifest.xml:74:25-68
78
79 <category android:name="android.intent.category.DEFAULT" />
79-->D:\Notes-master1\app\src\main\AndroidManifest.xml:61:17-76
79-->D:\Notes-master1\app\src\main\AndroidManifest.xml:61:27-73
80 </intent-filter>
81
82 <meta-data
82-->D:\Notes-master1\app\src\main\AndroidManifest.xml:78:13-80:54
83 android:name="android.app.searchable"
83-->D:\Notes-master1\app\src\main\AndroidManifest.xml:79:17-54
84 android:resource="@xml/searchable" />
84-->D:\Notes-master1\app\src\main\AndroidManifest.xml:80:17-51
85 </activity>
86
87 <provider
87-->D:\Notes-master1\app\src\main\AndroidManifest.xml:83:9-86:43
88 android:name="net.micode.notes.data.NotesProvider"
88-->D:\Notes-master1\app\src\main\AndroidManifest.xml:84:13-63
89 android:authorities="micode_notes"
89-->D:\Notes-master1\app\src\main\AndroidManifest.xml:85:13-47
90 android:multiprocess="true" />
90-->D:\Notes-master1\app\src\main\AndroidManifest.xml:86:13-40
91
92 <receiver
92-->D:\Notes-master1\app\src\main\AndroidManifest.xml:88:9-100:20
93 android:name="net.micode.notes.widget.NoteWidgetProvider_2x"
93-->D:\Notes-master1\app\src\main\AndroidManifest.xml:89:13-57
94 android:label="@string/app_widget2x2" >
94-->D:\Notes-master1\app\src\main\AndroidManifest.xml:90:13-50
95 <intent-filter>
95-->D:\Notes-master1\app\src\main\AndroidManifest.xml:91:13-95:29
96 <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
96-->D:\Notes-master1\app\src\main\AndroidManifest.xml:92:17-84
96-->D:\Notes-master1\app\src\main\AndroidManifest.xml:92:25-81
97 <action android:name="android.appwidget.action.APPWIDGET_DELETED" />
97-->D:\Notes-master1\app\src\main\AndroidManifest.xml:93:17-85
97-->D:\Notes-master1\app\src\main\AndroidManifest.xml:93:25-82
98 <action android:name="android.intent.action.PRIVACY_MODE_CHANGED" />
98-->D:\Notes-master1\app\src\main\AndroidManifest.xml:94:17-85
98-->D:\Notes-master1\app\src\main\AndroidManifest.xml:94:25-82
99 </intent-filter>
100
101 <meta-data
101-->D:\Notes-master1\app\src\main\AndroidManifest.xml:97:13-99:58
102 android:name="android.appwidget.provider"
102-->D:\Notes-master1\app\src\main\AndroidManifest.xml:98:17-58
103 android:resource="@xml/widget_2x_info" />
103-->D:\Notes-master1\app\src\main\AndroidManifest.xml:99:17-55
104 </receiver>
105 <receiver
105-->D:\Notes-master1\app\src\main\AndroidManifest.xml:101:9-114:20
106 android:name="net.micode.notes.widget.NoteWidgetProvider_4x"
106-->D:\Notes-master1\app\src\main\AndroidManifest.xml:102:13-57
107 android:label="@string/app_widget4x4" >
107-->D:\Notes-master1\app\src\main\AndroidManifest.xml:103:13-50
108 <intent-filter>
108-->D:\Notes-master1\app\src\main\AndroidManifest.xml:91:13-95:29
109 <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
109-->D:\Notes-master1\app\src\main\AndroidManifest.xml:92:17-84
109-->D:\Notes-master1\app\src\main\AndroidManifest.xml:92:25-81
110 <action android:name="android.appwidget.action.APPWIDGET_DELETED" />
110-->D:\Notes-master1\app\src\main\AndroidManifest.xml:93:17-85
110-->D:\Notes-master1\app\src\main\AndroidManifest.xml:93:25-82
111 <action android:name="android.intent.action.PRIVACY_MODE_CHANGED" />
111-->D:\Notes-master1\app\src\main\AndroidManifest.xml:94:17-85
111-->D:\Notes-master1\app\src\main\AndroidManifest.xml:94:25-82
112 </intent-filter>
113
114 <meta-data
114-->D:\Notes-master1\app\src\main\AndroidManifest.xml:97:13-99:58
115 android:name="android.appwidget.provider"
115-->D:\Notes-master1\app\src\main\AndroidManifest.xml:98:17-58
116 android:resource="@xml/widget_4x_info" />
116-->D:\Notes-master1\app\src\main\AndroidManifest.xml:99:17-55
117 </receiver>
118 <receiver android:name="net.micode.notes.ui.AlarmInitReceiver" >
118-->D:\Notes-master1\app\src\main\AndroidManifest.xml:116:9-120:20
118-->D:\Notes-master1\app\src\main\AndroidManifest.xml:116:19-55
119 <intent-filter>
119-->D:\Notes-master1\app\src\main\AndroidManifest.xml:117:13-119:29
120 <action android:name="android.intent.action.BOOT_COMPLETED" />
120-->D:\Notes-master1\app\src\main\AndroidManifest.xml:118:17-79
120-->D:\Notes-master1\app\src\main\AndroidManifest.xml:118:25-76
121 </intent-filter>
122 </receiver>
123 <receiver
123-->D:\Notes-master1\app\src\main\AndroidManifest.xml:122:9-125:20
124 android:name="net.micode.notes.ui.AlarmReceiver"
124-->D:\Notes-master1\app\src\main\AndroidManifest.xml:123:13-61
125 android:process=":remote" >
125-->D:\Notes-master1\app\src\main\AndroidManifest.xml:124:13-38
126 </receiver>
127
128 <activity
128-->D:\Notes-master1\app\src\main\AndroidManifest.xml:127:9-132:20
129 android:name="net.micode.notes.ui.AlarmAlertActivity"
129-->D:\Notes-master1\app\src\main\AndroidManifest.xml:128:13-50
130 android:label="@string/app_name"
130-->D:\Notes-master1\app\src\main\AndroidManifest.xml:129:13-45
131 android:launchMode="singleInstance"
131-->D:\Notes-master1\app\src\main\AndroidManifest.xml:130:13-48
132 android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar" >
132-->D:\Notes-master1\app\src\main\AndroidManifest.xml:131:13-75
133 </activity>
134 <activity
134-->D:\Notes-master1\app\src\main\AndroidManifest.xml:134:9-139:20
135 android:name="net.micode.notes.ui.NotesPreferenceActivity"
135-->D:\Notes-master1\app\src\main\AndroidManifest.xml:135:13-71
136 android:label="@string/preferences_title"
136-->D:\Notes-master1\app\src\main\AndroidManifest.xml:136:13-54
137 android:launchMode="singleTop"
137-->D:\Notes-master1\app\src\main\AndroidManifest.xml:137:13-43
138 android:theme="@android:style/Theme.Holo.Light" >
138-->D:\Notes-master1\app\src\main\AndroidManifest.xml:138:13-60
139 </activity>
140
141 <service
141-->D:\Notes-master1\app\src\main\AndroidManifest.xml:141:9-144:19
142 android:name="net.micode.notes.gtask.remote.GTaskSyncService"
142-->D:\Notes-master1\app\src\main\AndroidManifest.xml:142:13-74
143 android:exported="false" >
143-->D:\Notes-master1\app\src\main\AndroidManifest.xml:143:13-37
144 </service>
145
146 <meta-data
146-->D:\Notes-master1\app\src\main\AndroidManifest.xml:146:9-148:52
147 android:name="android.app.default_searchable"
147-->D:\Notes-master1\app\src\main\AndroidManifest.xml:147:13-58
148 android:value=".ui.NoteEditActivity" />
148-->D:\Notes-master1\app\src\main\AndroidManifest.xml:148:13-49
149 </application>
150
151</manifest>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save