Compare commits

..

33 Commits

Author SHA1 Message Date
Martin 04da31d145 修正了泛读报告
6 days ago
Martin 1325be7d44 就上课时提出的各种问题对开源软件质量分析报告进行了修改
6 days ago
pjao9fvxr 9547bcc71c Merge pull request '提交代码质量分析报告' (#11) from zhouzexin_branch into master
7 days ago
gy fb98c8d98e 修改文档
7 days ago
pjao9fvxr a1f870b87f Merge pull request '提交代码质量分析报告' (#10) from zhouzexin_branch into master
1 week ago
gy 89f08a4de8 提交质量分析报告
1 week ago
pjao9fvxr c48d9f1341 Merge pull request '增加代码注释' (#9) from zhouzexin_branch into master
3 weeks ago
gy 646cac45ba 对model包中的WorkingNote类进行了注释分析
3 weeks ago
gy e128c20223 对gtask.exception/NetworkFailureException.java进行了注释修改
3 weeks ago
gy d27eb46500 对gtask.exception/ActionFailureException.java进行了代码注释,对其中的功能进行了理解
3 weeks ago
pjao9fvxr 545d46901c Merge pull request '对部分类进行了注释分析' (#8) from zhouzexin_branch into master
3 weeks ago
gy d2b571eee4 对gtask.data包下的代码进行了注释分析
3 weeks ago
pvexk5qol 140f328934 Merge pull request '在报告文档中增添了代码标注部分' (#7) from caoweiqiong_branch into master
3 weeks ago
Martin 5c37bf3f34 在报告文档中增添了代码标注部分
3 weeks ago
pjao9fvxr 8d009c04ed Merge pull request '增加代码注释' (#6) from zhouzexin_branch into master
3 weeks ago
gy 584750e580 对NotesDatabaseHelper与NotesProvider两个类进行了注释与分析
3 weeks ago
pvexk5qol 37c476bed4 Merge pull request '对部分类进行了注释' (#5) from caoweiqiong_branch into master
3 weeks ago
Martin 24aabefac1 更新了前一次的泛读报告
3 weeks ago
gy e9a8d63f3d 修改了NoteEditActivity类的注释与修改
3 weeks ago
Martin a7250d6b94 对部分类进行了注释
3 weeks ago
gy c73bf0e5ee 完成了notes类的代码注释与分析
3 weeks ago
Martin 56617b60ca 对部分类进行了注释
3 weeks ago
gy 9ec8fa98f2 完成了contact类的代码注释
3 weeks ago
gy 925975e8e8 修改了泛读报告
1 month ago
gy 17803fb6d9 添加了一些注释,主要学习了data包中的类的库的调用,以及学习ui包中部分类的方法的使用
1 month ago
Martin 22011f33eb 将最新版合并到我的分支中
1 month ago
gy 0ed0f45767 修改结构
1 month ago
gy a9f987985e 修改部分文件
1 month ago
gy 8c20af0fb2 Merge branch 'master' of https://bdgit.educoder.net/pjao9fvxr/Notes-Xiaomi into zhouzexin_branch
1 month ago
pvexk5qol 43e3c9d550 Merge pull request '第二周泛读报告更新' (#1) from a_branch into master
2 months ago
Martin 37e6648353 更新了泛读报告
2 months ago
gy 8ddb91e912 进行了小米便签的部分代码的阅读,并做了备注
2 months ago
gy d20d4d65fa 把不是我的文件删除,并且备注了模版
2 months ago

Binary file not shown.

@ -25,10 +25,16 @@ import android.util.Log;
import java.util.HashMap;
/**
*
*/
public class Contact {
// 联系人缓存,避免重复查询
private static HashMap<String, String> sContactCache;
// 日志标签
private static final String TAG = "Contact";
// 查询联系人的SQL条件用于通过电话号码查找联系人
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,6 +42,12 @@ public class Contact {
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
/**
*
* @param context
* @param phoneNumber
* @return null
*/
public static String getContact(Context context, String phoneNumber) {
if(sContactCache == null) {
sContactCache = new HashMap<String, String>();

@ -17,6 +17,10 @@
package net.micode.notes.data;
import android.net.Uri;
/**
* URI
* IDIntent
*/
public class Notes {
public static final String AUTHORITY = "micode_notes";
public static final String TAG = "Notes";

@ -27,21 +27,34 @@ import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns;
/**
* SQLite
*
*/
public class NotesDatabaseHelper extends SQLiteOpenHelper {
// 数据库名称
private static final String DB_NAME = "note.db";
// 数据库版本号
private static final int DB_VERSION = 4;
/**
*
*/
public interface TABLE {
// 笔记表名
public static final String NOTE = "note";
// 数据内容表名
public static final String DATA = "data";
}
// 日志标签
private static final String TAG = "NotesDatabaseHelper";
// 单例实例
private static NotesDatabaseHelper mInstance;
// 创建笔记表的SQL语句
private static final String CREATE_NOTE_TABLE_SQL =
"CREATE TABLE " + TABLE.NOTE + "(" +
NoteColumns.ID + " INTEGER PRIMARY KEY," +
@ -63,6 +76,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +
")";
// 创建数据内容表的SQL语句
private static final String CREATE_DATA_TABLE_SQL =
"CREATE TABLE " + TABLE.DATA + "(" +
DataColumns.ID + " INTEGER PRIMARY KEY," +
@ -78,6 +92,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +
")";
// 为数据内容表的note_id字段创建索引的SQL语句
private static final String CREATE_DATA_NOTE_ID_INDEX_SQL =
"CREATE INDEX IF NOT EXISTS note_id_index ON " +
TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";
@ -206,10 +221,18 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
" END";
/**
*
* @param context
*/
public NotesDatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
/**
*
* @param db SQLite
*/
public void createNoteTable(SQLiteDatabase db) {
db.execSQL(CREATE_NOTE_TABLE_SQL);
reCreateNoteTableTriggers(db);
@ -217,6 +240,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
Log.d(TAG, "note table has been created");
}
/**
*
* @param db SQLite
*/
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,6 +262,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER);
}
/**
*
* @param db SQLite
*/
private void createSystemFolder(SQLiteDatabase db) {
ContentValues values = new ContentValues();
@ -270,6 +301,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.insert(TABLE.NOTE, null, values);
}
/**
*
* @param db SQLite
*/
public void createDataTable(SQLiteDatabase db) {
db.execSQL(CREATE_DATA_TABLE_SQL);
reCreateDataTableTriggers(db);
@ -277,6 +312,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
Log.d(TAG, "data table has been created");
}
/**
*
* @param db SQLite
*/
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 +326,11 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER);
}
/**
*
* @param context
* @return NotesDatabaseHelper
*/
static synchronized NotesDatabaseHelper getInstance(Context context) {
if (mInstance == null) {
mInstance = new NotesDatabaseHelper(context);
@ -294,12 +338,22 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
return mInstance;
}
/**
*
* @param db SQLite
*/
@Override
public void onCreate(SQLiteDatabase db) {
createNoteTable(db);
createDataTable(db);
}
/**
*
* @param db SQLite
* @param oldVersion
* @param newVersion
*/
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
boolean reCreateTriggers = false;
@ -333,6 +387,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
}
/**
* 2
* @param db SQLite
*/
private void upgradeToV2(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE);
db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA);
@ -340,6 +398,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
createDataTable(db);
}
/**
* 3
* @param db SQLite
*/
private void upgradeToV3(SQLiteDatabase db) {
// drop unused triggers
db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_insert");
@ -355,6 +417,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.insert(TABLE.NOTE, null, values);
}
/**
* 4
* @param db SQLite
*/
private void upgradeToV4(SQLiteDatabase db) {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION
+ " INTEGER NOT NULL DEFAULT 0");

@ -35,20 +35,27 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
/**
* ContentProvider
*
*/
public class NotesProvider extends ContentProvider {
// Uri匹配器用于解析不同的请求URI
private static final UriMatcher mMatcher;
// 数据库助手实例
private NotesDatabaseHelper mHelper;
// 日志标签
private static final String TAG = "NotesProvider";
private static final int URI_NOTE = 1;
private static final int URI_NOTE_ITEM = 2;
private static final int URI_DATA = 3;
private static final int URI_DATA_ITEM = 4;
private static final int URI_SEARCH = 5;
private static final int URI_SEARCH_SUGGEST = 6;
// Uri匹配规则常量
private static final int URI_NOTE = 1; // 所有笔记
private static final int URI_NOTE_ITEM = 2; // 单个笔记
private static final int URI_DATA = 3; // 所有数据内容
private static final int URI_DATA_ITEM = 4; // 单个数据内容
private static final int URI_SEARCH = 5; // 搜索
private static final int URI_SEARCH_SUGGEST = 6; // 搜索建议
static {
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
@ -65,6 +72,7 @@ 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.
*/
// 搜索结果的投影列定义
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 + ","
@ -73,18 +81,33 @@ public class NotesProvider extends ContentProvider {
+ "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
+ "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
// 搜索笔记内容的SQL查询语句
private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION
+ " FROM " + TABLE.NOTE
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
/**
* ContentProvider
* @return true
*/
@Override
public boolean onCreate() {
mHelper = NotesDatabaseHelper.getInstance(getContext());
return true;
}
/**
*
* @param uri URI
* @param projection
* @param selection
* @param selectionArgs
* @param sortOrder
* @return Cursor
* @throws IllegalArgumentException URI
*/
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
@ -147,6 +170,13 @@ public class NotesProvider extends ContentProvider {
return c;
}
/**
*
* @param uri URI
* @param values
* @return URI
* @throws IllegalArgumentException URI
*/
@Override
public Uri insert(Uri uri, ContentValues values) {
SQLiteDatabase db = mHelper.getWritableDatabase();
@ -181,6 +211,14 @@ public class NotesProvider extends ContentProvider {
return ContentUris.withAppendedId(uri, insertedId);
}
/**
*
* @param uri URI
* @param selection
* @param selectionArgs
* @return
* @throws IllegalArgumentException URI
*/
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int count = 0;
@ -227,6 +265,15 @@ public class NotesProvider extends ContentProvider {
return count;
}
/**
*
* @param uri URI
* @param values
* @param selection
* @param selectionArgs
* @return
* @throws IllegalArgumentException URI
*/
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
int count = 0;
@ -267,10 +314,21 @@ public class NotesProvider extends ContentProvider {
return count;
}
/**
*
* @param selection
* @return
*/
private String parseSelection(String selection) {
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
}
/**
*
* @param id ID-1
* @param selection
* @param selectionArgs
*/
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
StringBuilder sql = new StringBuilder(120);
sql.append("UPDATE ");
@ -296,6 +354,11 @@ public class NotesProvider extends ContentProvider {
mHelper.getWritableDatabase().execSQL(sql.toString());
}
/**
* URIMIME
* @param uri URI
* @return MIME
*/
@Override
public String getType(Uri uri) {
// TODO Auto-generated method stub

@ -25,11 +25,22 @@ import org.json.JSONException;
import org.json.JSONObject;
/**
* Task
* Google Task
*/
public class MetaData extends Task {
// 日志标签
private final static String TAG = MetaData.class.getSimpleName();
// 关联的Google Task ID
private String mRelatedGid = null;
/**
*
* @param gid Google Task ID
* @param metaInfo JSON
*/
public void setMeta(String gid, JSONObject metaInfo) {
try {
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
@ -40,15 +51,27 @@ public class MetaData extends Task {
setName(GTaskStringUtils.META_NOTE_NAME);
}
/**
* Google Task ID
* @return Google Task ID
*/
public String getRelatedGid() {
return mRelatedGid;
}
/**
*
* @return nulltrue
*/
@Override
public boolean isWorthSaving() {
return getNotes() != null;
}
/**
* JSON
* @param js JSON
*/
@Override
public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js);
@ -63,17 +86,33 @@ public class MetaData extends Task {
}
}
/**
* JSON
* @param js JSON
* @throws IllegalAccessError
*/
@Override
public void setContentByLocalJSON(JSONObject js) {
// this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
}
/**
* JSON
* @return JSON
* @throws IllegalAccessError
*/
@Override
public JSONObject getLocalJSONFromContent() {
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
}
/**
*
* @param c
* @return
* @throws IllegalAccessError
*/
@Override
public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called");

@ -20,33 +20,53 @@ import android.database.Cursor;
import org.json.JSONObject;
/**
*
* TaskTaskListGoogle Tasks
*/
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;
// Google Task唯一标识符
private String mGid;
// 节点名称
private String mName;
// 最后修改时间
private long mLastModified;
// 是否已删除
private boolean mDeleted;
/**
*
*/
public Node() {
mGid = null;
mName = "";
@ -54,46 +74,105 @@ public abstract class Node {
mDeleted = false;
}
/**
* JSON
* @param actionId ID
* @return JSON
*/
public abstract JSONObject getCreateAction(int actionId);
/**
* JSON
* @param actionId ID
* @return JSON
*/
public abstract JSONObject getUpdateAction(int actionId);
/**
* JSON
* @param js JSON
*/
public abstract void setContentByRemoteJSON(JSONObject js);
/**
* JSON
* @param js JSON
*/
public abstract void setContentByLocalJSON(JSONObject js);
/**
* JSON
* @return JSON
*/
public abstract JSONObject getLocalJSONFromContent();
/**
*
* @param c
* @return
*/
public abstract int getSyncAction(Cursor c);
/**
* Google Task
* @param gid Google Task ID
*/
public void setGid(String gid) {
this.mGid = gid;
}
/**
*
* @param name
*/
public void setName(String name) {
this.mName = name;
}
/**
*
* @param lastModified
*/
public void setLastModified(long lastModified) {
this.mLastModified = lastModified;
}
/**
*
* @param deleted
*/
public void setDeleted(boolean deleted) {
this.mDeleted = deleted;
}
/**
* Google Task
* @return Google Task ID
*/
public String getGid() {
return this.mGid;
}
/**
*
* @return
*/
public String getName() {
return this.mName;
}
/**
*
* @return
*/
public long getLastModified() {
return this.mLastModified;
}
/**
*
* @return
*/
public boolean getDeleted() {
return this.mDeleted;
}

@ -35,42 +35,66 @@ import org.json.JSONException;
import org.json.JSONObject;
/**
*
* ContentResolver
*/
public class SqlData {
// 日志标签
private static final String TAG = SqlData.class.getSimpleName();
// 无效ID常量
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
};
// 投影数组中ID列的索引
public static final int DATA_ID_COLUMN = 0;
// 投影数组中MIME类型列的索引
public static final int DATA_MIME_TYPE_COLUMN = 1;
// 投影数组中内容列的索引
public static final int DATA_CONTENT_COLUMN = 2;
// 投影数组中DATA1列的索引
public static final int DATA_CONTENT_DATA_1_COLUMN = 3;
// 投影数组中DATA3列的索引
public static final int DATA_CONTENT_DATA_3_COLUMN = 4;
// 内容解析器
private ContentResolver mContentResolver;
// 是否为创建操作
private boolean mIsCreate;
// 数据ID
private long mDataId;
// 数据MIME类型
private String mDataMimeType;
// 数据内容
private String mDataContent;
// 数据内容DATA1字段
private long mDataContentData1;
// 数据内容DATA3字段
private String mDataContentData3;
// 差异数据值,用于记录需要更新的字段
private ContentValues mDiffDataValues;
/**
*
* @param context
*/
public SqlData(Context context) {
mContentResolver = context.getContentResolver();
mIsCreate = true;
@ -82,6 +106,11 @@ public class SqlData {
mDiffDataValues = new ContentValues();
}
/**
*
* @param context
* @param c
*/
public SqlData(Context context, Cursor c) {
mContentResolver = context.getContentResolver();
mIsCreate = false;
@ -89,6 +118,10 @@ public class SqlData {
mDiffDataValues = new ContentValues();
}
/**
*
* @param c
*/
private void loadFromCursor(Cursor c) {
mDataId = c.getLong(DATA_ID_COLUMN);
mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);
@ -97,6 +130,11 @@ public class SqlData {
mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);
}
/**
* JSON
* @param js JSON
* @throws JSONException JSON
*/
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 +168,11 @@ public class SqlData {
mDataContentData3 = dataContentData3;
}
/**
* JSON
* @return JSON
* @throws JSONException JSON
*/
public JSONObject getContent() throws JSONException {
if (mIsCreate) {
Log.e(TAG, "it seems that we haven't created this in database yet");
@ -144,6 +187,13 @@ public class SqlData {
return js;
}
/**
*
* @param noteId ID
* @param validateVersion
* @param version
* @throws ActionFailureException
*/
public void commit(long noteId, boolean validateVersion, long version) {
if (mIsCreate) {
@ -183,6 +233,10 @@ public class SqlData {
mIsCreate = false;
}
/**
* ID
* @return ID
*/
public long getId() {
return mDataId;
}

@ -38,11 +38,18 @@ import org.json.JSONObject;
import java.util.ArrayList;
/**
*
* ContentResolver
*/
public class SqlNote {
// 日志标签
private static final String TAG = SqlNote.class.getSimpleName();
// 无效ID常量
private static final int INVALID_ID = -99999;
// 笔记查询投影数组
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,
@ -52,76 +59,115 @@ public class SqlNote {
NoteColumns.VERSION
};
// 投影数组中ID列的索引
public static final int ID_COLUMN = 0;
// 投影数组中提醒日期列的索引
public static final int ALERTED_DATE_COLUMN = 1;
// 投影数组中背景颜色ID列的索引
public static final int BG_COLOR_ID_COLUMN = 2;
// 投影数组中创建日期列的索引
public static final int CREATED_DATE_COLUMN = 3;
// 投影数组中是否有附件列的索引
public static final int HAS_ATTACHMENT_COLUMN = 4;
// 投影数组中修改日期列的索引
public static final int MODIFIED_DATE_COLUMN = 5;
// 投影数组中笔记数量列的索引
public static final int NOTES_COUNT_COLUMN = 6;
// 投影数组中父ID列的索引
public static final int PARENT_ID_COLUMN = 7;
// 投影数组中摘要列的索引
public static final int SNIPPET_COLUMN = 8;
// 投影数组中类型列的索引
public static final int TYPE_COLUMN = 9;
// 投影数组中小组件ID列的索引
public static final int WIDGET_ID_COLUMN = 10;
// 投影数组中小组件类型列的索引
public static final int WIDGET_TYPE_COLUMN = 11;
// 投影数组中同步ID列的索引
public static final int SYNC_ID_COLUMN = 12;
// 投影数组中本地修改标记列的索引
public static final int LOCAL_MODIFIED_COLUMN = 13;
// 投影数组中原始父ID列的索引
public static final int ORIGIN_PARENT_ID_COLUMN = 14;
// 投影数组中Google Task ID列的索引
public static final int GTASK_ID_COLUMN = 15;
// 投影数组中版本列的索引
public static final int VERSION_COLUMN = 16;
// 上下文对象
private Context mContext;
// 内容解析器
private ContentResolver mContentResolver;
// 是否为创建操作
private boolean mIsCreate;
// 笔记ID
private long mId;
// 提醒日期
private long mAlertDate;
// 背景颜色ID
private int mBgColorId;
// 创建日期
private long mCreatedDate;
// 是否有附件01
private int mHasAttachment;
// 修改日期
private long mModifiedDate;
// 父文件夹ID
private long mParentId;
// 笔记摘要
private String mSnippet;
// 笔记类型(文件夹或笔记)
private int mType;
// 小组件ID
private int mWidgetId;
// 小组件类型
private int mWidgetType;
// 原始父文件夹ID
private long mOriginParent;
// 版本号
private long mVersion;
// 差异笔记值,用于记录需要更新的字段
private ContentValues mDiffNoteValues;
// 数据内容列表
private ArrayList<SqlData> mDataList;
/**
*
* @param context
*/
public SqlNote(Context context) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -143,6 +189,11 @@ public class SqlNote {
mDataList = new ArrayList<SqlData>();
}
/**
*
* @param context
* @param c
*/
public SqlNote(Context context, Cursor c) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -154,6 +205,11 @@ public class SqlNote {
mDiffNoteValues = new ContentValues();
}
/**
* ID
* @param context
* @param id ID
*/
public SqlNote(Context context, long id) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -163,9 +219,12 @@ public class SqlNote {
if (mType == Notes.TYPE_NOTE)
loadDataContent();
mDiffNoteValues = new ContentValues();
}
/**
* ID
* @param id ID
*/
private void loadFromCursor(long id) {
Cursor c = null;
try {
@ -185,6 +244,10 @@ public class SqlNote {
}
}
/**
*
* @param c
*/
private void loadFromCursor(Cursor c) {
mId = c.getLong(ID_COLUMN);
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
@ -200,6 +263,9 @@ public class SqlNote {
mVersion = c.getLong(VERSION_COLUMN);
}
/**
*
*/
private void loadDataContent() {
Cursor c = null;
mDataList.clear();
@ -226,6 +292,11 @@ public class SqlNote {
}
}
/**
* JSON
* @param js JSON
* @return
*/
public boolean setContent(JSONObject js) {
try {
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
@ -359,6 +430,10 @@ public class SqlNote {
return true;
}
/**
* JSON
* @return JSONnull
*/
public JSONObject getContent() {
try {
JSONObject js = new JSONObject();
@ -407,39 +482,76 @@ public class SqlNote {
return null;
}
/**
* ID
* @param id ID
*/
public void setParentId(long id) {
mParentId = id;
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
}
/**
* Google Task ID
* @param gid Google Task ID
*/
public void setGtaskId(String gid) {
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
}
/**
* ID
* @param syncId ID
*/
public void setSyncId(long syncId) {
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
}
/**
*
*/
public void resetLocalModified() {
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
}
/**
* ID
* @return ID
*/
public long getId() {
return mId;
}
/**
* ID
* @return ID
*/
public long getParentId() {
return mParentId;
}
/**
*
* @return
*/
public String getSnippet() {
return mSnippet;
}
/**
*
* @return
*/
public boolean isNoteType() {
return mType == Notes.TYPE_NOTE;
}
/**
*
* @param validateVersion
* @throws ActionFailureException
* @throws IllegalStateException ID
*/
public void commit(boolean validateVersion) {
if (mIsCreate) {
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {

@ -32,19 +32,32 @@ import org.json.JSONException;
import org.json.JSONObject;
/**
* Google TasksNode
*
*/
public class Task extends Node {
// 日志标签
private static final String TAG = Task.class.getSimpleName();
// 任务是否已完成
private boolean mCompleted;
// 任务的详细说明
private String mNotes;
// 任务的元信息JSON对象
private JSONObject mMetaInfo;
// 前一个兄弟任务(用于排序)
private Task mPriorSibling;
// 父任务列表
private TaskList mParent;
/**
*
*/
public Task() {
super();
mCompleted = false;
@ -54,6 +67,12 @@ public class Task extends Node {
mMetaInfo = null;
}
/**
* JSON
* @param actionId ID
* @return JSON
* @throws ActionFailureException JSON
*/
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
@ -103,6 +122,12 @@ public class Task extends Node {
return js;
}
/**
* JSON
* @param actionId ID
* @return JSON
* @throws ActionFailureException JSON
*/
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
@ -135,6 +160,11 @@ public class Task extends Node {
return js;
}
/**
* JSON
* @param js JSON
* @throws ActionFailureException JSON
*/
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
@ -175,6 +205,10 @@ public class Task extends Node {
}
}
/**
* JSON
* @param js JSON
*/
public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)
|| !js.has(GTaskStringUtils.META_HEAD_DATA)) {
@ -204,6 +238,10 @@ public class Task extends Node {
}
}
/**
* JSON
* @return JSONnull
*/
public JSONObject getLocalJSONFromContent() {
String name = getName();
try {
@ -247,6 +285,10 @@ public class Task extends Node {
}
}
/**
*
* @param metaData
*/
public void setMetaInfo(MetaData metaData) {
if (metaData != null && metaData.getNotes() != null) {
try {
@ -258,6 +300,11 @@ public class Task extends Node {
}
}
/**
*
* @param c
* @return SYNC_ACTION_NONESYNC_ACTION_UPDATE_REMOTE
*/
public int getSyncAction(Cursor c) {
try {
JSONObject noteInfo = null;
@ -311,39 +358,75 @@ public class Task extends Node {
return SYNC_ACTION_ERROR;
}
/**
*
* @return
*/
public boolean isWorthSaving() {
return mMetaInfo != null || (getName() != null && getName().trim().length() > 0)
|| (getNotes() != null && getNotes().trim().length() > 0);
}
/**
*
* @param completed
*/
public void setCompleted(boolean completed) {
this.mCompleted = completed;
}
/**
*
* @param notes
*/
public void setNotes(String notes) {
this.mNotes = notes;
}
/**
*
* @param priorSibling
*/
public void setPriorSibling(Task priorSibling) {
this.mPriorSibling = priorSibling;
}
/**
*
* @param parent
*/
public void setParent(TaskList parent) {
this.mParent = parent;
}
/**
*
* @return
*/
public boolean getCompleted() {
return this.mCompleted;
}
/**
*
* @return
*/
public String getNotes() {
return this.mNotes;
}
/**
*
* @return
*/
public Task getPriorSibling() {
return this.mPriorSibling;
}
/**
*
* @return
*/
public TaskList getParent() {
return this.mParent;
}

@ -30,19 +30,36 @@ import org.json.JSONObject;
import java.util.ArrayList;
/**
* Google TasksNode
*
*
*/
public class TaskList extends Node {
// 日志标签
private static final String TAG = TaskList.class.getSimpleName();
// 任务列表的索引位置
private int mIndex;
// 任务列表中的子任务集合
private ArrayList<Task> mChildren;
/**
*
*/
public TaskList() {
super();
mChildren = new ArrayList<Task>();
mIndex = 1;
}
/**
* JSON
* @param actionId ID
* @return JSON
* @throws ActionFailureException JSON
*/
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
@ -74,6 +91,12 @@ public class TaskList extends Node {
return js;
}
/**
* JSON
* @param actionId ID
* @return JSON
* @throws ActionFailureException JSON
*/
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
@ -103,6 +126,11 @@ public class TaskList extends Node {
return js;
}
/**
* JSON
* @param js JSON
* @throws ActionFailureException JSON
*/
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
@ -129,6 +157,10 @@ public class TaskList extends Node {
}
}
/**
* JSON
* @param js JSON
*/
public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) {
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
@ -157,6 +189,10 @@ public class TaskList extends Node {
}
}
/**
* JSON
* @return JSONnull
*/
public JSONObject getLocalJSONFromContent() {
try {
JSONObject js = new JSONObject();
@ -183,6 +219,11 @@ public class TaskList extends Node {
}
}
/**
*
* @param c
* @return SYNC_ACTION_NONESYNC_ACTION_UPDATE_REMOTE
*/
public int getSyncAction(Cursor c) {
try {
if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
@ -216,10 +257,19 @@ public class TaskList extends Node {
return SYNC_ACTION_ERROR;
}
/**
*
* @return
*/
public int getChildTaskCount() {
return mChildren.size();
}
/**
*
* @param task
* @return
*/
public boolean addChildTask(Task task) {
boolean ret = false;
if (task != null && !mChildren.contains(task)) {
@ -234,6 +284,12 @@ public class TaskList extends Node {
return ret;
}
/**
*
* @param task
* @param index
* @return
*/
public boolean addChildTask(Task task, int index) {
if (index < 0 || index > mChildren.size()) {
Log.e(TAG, "add child task: invalid index");
@ -260,6 +316,11 @@ public class TaskList extends Node {
return true;
}
/**
*
* @param task
* @return
*/
public boolean removeChildTask(Task task) {
boolean ret = false;
int index = mChildren.indexOf(task);
@ -281,6 +342,12 @@ public class TaskList extends Node {
return ret;
}
/**
*
* @param task
* @param index
* @return
*/
public boolean moveChildTask(Task task, int index) {
if (index < 0 || index >= mChildren.size()) {
@ -299,6 +366,11 @@ public class TaskList extends Node {
return (removeChildTask(task) && addChildTask(task, index));
}
/**
* Google Task ID
* @param gid Google Task ID
* @return null
*/
public Task findChildTaskByGid(String gid) {
for (int i = 0; i < mChildren.size(); i++) {
Task t = mChildren.get(i);
@ -309,10 +381,20 @@ public class TaskList extends Node {
return null;
}
/**
*
* @param task
* @return
*/
public int getChildTaskIndex(Task task) {
return mChildren.indexOf(task);
}
/**
*
* @param index
* @return null
*/
public Task getChildTaskByIndex(int index) {
if (index < 0 || index >= mChildren.size()) {
Log.e(TAG, "getTaskByIndex: invalid index");
@ -321,6 +403,11 @@ public class TaskList extends Node {
return mChildren.get(index);
}
/**
* Google Task IDfindChildTaskByGid
* @param gid Google Task ID
* @return null
*/
public Task getChilTaskByGid(String gid) {
for (Task task : mChildren) {
if (task.getGid().equals(gid))
@ -329,14 +416,26 @@ public class TaskList extends Node {
return null;
}
/**
*
* @return
*/
public ArrayList<Task> getChildTaskList() {
return this.mChildren;
}
/**
*
* @param index
*/
public void setIndex(int index) {
this.mIndex = index;
}
/**
*
* @return
*/
public int getIndex() {
return this.mIndex;
}

@ -16,17 +16,34 @@
package net.micode.notes.gtask.exception;
/**
* Google Tasks
* Google Tasks
*/
public class ActionFailureException extends RuntimeException {
// 序列化版本UID
private static final long serialVersionUID = 4425249765923293627L;
/**
*
*/
public ActionFailureException() {
super();
}
/**
*
* @param paramString
*/
public ActionFailureException(String paramString) {
super(paramString);
}
/**
*
* @param paramString
* @param paramThrowable
*/
public ActionFailureException(String paramString, Throwable paramThrowable) {
super(paramString, paramThrowable);
}

@ -16,17 +16,34 @@
package net.micode.notes.gtask.exception;
/**
* Google Tasks
* Google Tasks
*/
public class NetworkFailureException extends Exception {
// 序列化版本UID
private static final long serialVersionUID = 2107610287180234136L;
/**
*
*/
public NetworkFailureException() {
super();
}
/**
*
* @param paramString
*/
public NetworkFailureException(String paramString) {
super(paramString);
}
/**
*
* @param paramString
* @param paramThrowable
*/
public NetworkFailureException(String paramString, Throwable paramThrowable) {
super(paramString, paramThrowable);
}

@ -29,22 +29,44 @@ import net.micode.notes.ui.NotesListActivity;
import net.micode.notes.ui.NotesPreferenceActivity;
/**
* Google Tasks
* AsyncTaskGoogle Tasks
*
*/
public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
// 同步通知的ID
private static int GTASK_SYNC_NOTIFICATION_ID = 5234235;
/**
*
*
*/
public interface OnCompleteListener {
/**
*
*/
void onComplete();
}
// 上下文对象
private Context mContext;
// 通知管理器
private NotificationManager mNotifiManager;
// Google Task管理器实例
private GTaskManager mTaskManager;
// 完成监听器
private OnCompleteListener mOnCompleteListener;
/**
*
* @param context
* @param listener
*/
public GTaskASyncTask(Context context, OnCompleteListener listener) {
mContext = context;
mOnCompleteListener = listener;
@ -53,16 +75,28 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
mTaskManager = GTaskManager.getInstance();
}
/**
*
*/
public void cancelSync() {
mTaskManager.cancelSync();
}
/**
*
* @param message
*/
public void publishProgess(String message) {
publishProgress(new String[] {
message
});
}
/**
*
* @param tickerId ID
* @param content
*/
private void showNotification(int tickerId, String content) {
Notification notification = new Notification(R.drawable.notification, mContext
.getString(tickerId), System.currentTimeMillis());
@ -82,6 +116,11 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);
}
/**
*
* @param unused 使
* @return
*/
@Override
protected Integer doInBackground(Void... unused) {
publishProgess(mContext.getString(R.string.sync_progress_login, NotesPreferenceActivity
@ -89,6 +128,10 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
return mTaskManager.sync(mContext, this);
}
/**
*
* @param progress
*/
@Override
protected void onProgressUpdate(String... progress) {
showNotification(R.string.ticker_syncing, progress[0]);
@ -97,6 +140,10 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
}
}
/**
*
* @param result
*/
@Override
protected void onPostExecute(Integer result) {
if (result == GTaskManager.STATE_SUCCESS) {

@ -61,35 +61,58 @@ import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
/**
* Google Tasks
* Google Tasks
*
*/
public class GTaskClient {
// 日志标签
private static final String TAG = GTaskClient.class.getSimpleName();
// Google Tasks基础URL
private static final String GTASK_URL = "https://mail.google.com/tasks/";
// Google Tasks GET请求URL
private static final String GTASK_GET_URL = "https://mail.google.com/tasks/ig";
// Google Tasks POST请求URL
private static final String GTASK_POST_URL = "https://mail.google.com/tasks/r/ig";
// 单例实例
private static GTaskClient mInstance = null;
// HTTP客户端实例
private DefaultHttpClient mHttpClient;
// 当前使用的GET请求URL
private String mGetUrl;
// 当前使用的POST请求URL
private String mPostUrl;
// 客户端版本号
private long mClientVersion;
// 是否已登录
private boolean mLoggedin;
// 上次登录时间
private long mLastLoginTime;
// 操作ID计数器
private int mActionId;
// 登录的Google账户
private Account mAccount;
// 更新操作的JSON数组
private JSONArray mUpdateArray;
/**
*
*
*/
private GTaskClient() {
mHttpClient = null;
mGetUrl = GTASK_GET_URL;
@ -102,6 +125,10 @@ public class GTaskClient {
mUpdateArray = null;
}
/**
*
* @return GTaskClient
*/
public static synchronized GTaskClient getInstance() {
if (mInstance == null) {
mInstance = new GTaskClient();
@ -109,15 +136,20 @@ public class GTaskClient {
return mInstance;
}
/**
* Google Tasks
* GoogleTasks
* @param activity Activity
* @return
*/
public boolean login(Activity activity) {
// we suppose that the cookie would expire after 5 minutes
// then we need to re-login
// 假设Cookie 5分钟后过期需要重新登录
final long interval = 1000 * 60 * 5;
if (mLastLoginTime + interval < System.currentTimeMillis()) {
mLoggedin = false;
}
// need to re-login after account switch
// 切换账户后需要重新登录
if (mLoggedin
&& !TextUtils.equals(getSyncAccount().name, NotesPreferenceActivity
.getSyncAccountName(activity))) {
@ -136,7 +168,7 @@ public class GTaskClient {
return false;
}
// login with custom domain if necessary
// 必要时使用自定义域名登录
if (!(mAccount.name.toLowerCase().endsWith("gmail.com") || mAccount.name.toLowerCase()
.endsWith("googlemail.com"))) {
StringBuilder url = new StringBuilder(GTASK_URL).append("a/");
@ -151,7 +183,7 @@ public class GTaskClient {
}
}
// try to login with google official url
// 尝试使用Google官方URL登录
if (!mLoggedin) {
mGetUrl = GTASK_GET_URL;
mPostUrl = GTASK_POST_URL;
@ -164,6 +196,12 @@ public class GTaskClient {
return true;
}
/**
* Google
* @param activity Activity
* @param invalidateToken 使
* @return null
*/
private String loginGoogleAccount(Activity activity, boolean invalidateToken) {
String authToken;
AccountManager accountManager = AccountManager.get(activity);
@ -189,7 +227,7 @@ public class GTaskClient {
return null;
}
// get the token now
// 获取认证令牌
AccountManagerFuture<Bundle> accountManagerFuture = accountManager.getAuthToken(account,
"goanna_mobile", null, activity, null, null);
try {
@ -207,10 +245,16 @@ public class GTaskClient {
return authToken;
}
/**
* Google Tasks
* 使
* @param activity Activity
* @param authToken Google
* @return
*/
private boolean tryToLoginGtask(Activity activity, String authToken) {
if (!loginGtask(authToken)) {
// maybe the auth token is out of date, now let's invalidate the
// token and try again
// 认证令牌可能已过期,使令牌失效并重新尝试
authToken = loginGoogleAccount(activity, true);
if (authToken == null) {
Log.e(TAG, "login google account failed");
@ -225,6 +269,12 @@ public class GTaskClient {
return true;
}
/**
* 使Google Tasks
* HTTPCookie
* @param authToken Google
* @return
*/
private boolean loginGtask(String authToken) {
int timeoutConnection = 10000;
int timeoutSocket = 15000;
@ -236,14 +286,14 @@ public class GTaskClient {
mHttpClient.setCookieStore(localBasicCookieStore);
HttpProtocolParams.setUseExpectContinue(mHttpClient.getParams(), false);
// login gtask
// 登录Google Tasks
try {
String loginUrl = mGetUrl + "?auth=" + authToken;
HttpGet httpGet = new HttpGet(loginUrl);
HttpResponse response = null;
response = mHttpClient.execute(httpGet);
// get the cookie now
// 获取认证Cookie
List<Cookie> cookies = mHttpClient.getCookieStore().getCookies();
boolean hasAuthCookie = false;
for (Cookie cookie : cookies) {
@ -255,7 +305,7 @@ public class GTaskClient {
Log.w(TAG, "it seems that there is no auth cookie");
}
// get the client version
// 获取客户端版本
String resString = getResponseContent(response.getEntity());
String jsBegin = "_setup(";
String jsEnd = ")}</script>";
@ -272,7 +322,7 @@ public class GTaskClient {
e.printStackTrace();
return false;
} catch (Exception e) {
// simply catch all exceptions
// 捕获所有异常
Log.e(TAG, "httpget gtask_url failed");
return false;
}
@ -280,10 +330,20 @@ public class GTaskClient {
return true;
}
/**
* ID
* ID
* @return ID
*/
private int getActionId() {
return mActionId++;
}
/**
* HTTP POST
* URL
* @return HttpPost
*/
private HttpPost createHttpPost() {
HttpPost httpPost = new HttpPost(mPostUrl);
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
@ -291,6 +351,13 @@ public class GTaskClient {
return httpPost;
}
/**
* HTTP
* gzipdeflate
* @param entity HTTP
* @return
* @throws IOException
*/
private String getResponseContent(HttpEntity entity) throws IOException {
String contentEncoding = null;
if (entity.getContentEncoding() != null) {
@ -323,6 +390,13 @@ public class GTaskClient {
}
}
/**
* POST
* Google Tasks
* @param js JSON
* @return JSON
* @throws NetworkFailureException
*/
private JSONObject postRequest(JSONObject js) throws NetworkFailureException {
if (!mLoggedin) {
Log.e(TAG, "please login first");
@ -336,7 +410,7 @@ public class GTaskClient {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, "UTF-8");
httpPost.setEntity(entity);
// execute the post
// 执行POST请求
HttpResponse response = mHttpClient.execute(httpPost);
String jsString = getResponseContent(response.getEntity());
return new JSONObject(jsString);
@ -360,6 +434,12 @@ public class GTaskClient {
}
}
/**
*
* Google Tasks
* @param task
* @throws NetworkFailureException
*/
public void createTask(Task task) throws NetworkFailureException {
commitUpdate();
try {
@ -373,7 +453,7 @@ public class GTaskClient {
// client_version
jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
// post
// 发送请求
JSONObject jsResponse = postRequest(jsPost);
JSONObject jsResult = (JSONObject) jsResponse.getJSONArray(
GTaskStringUtils.GTASK_JSON_RESULTS).get(0);
@ -386,6 +466,12 @@ public class GTaskClient {
}
}
/**
*
* Google Tasks
* @param tasklist
* @throws NetworkFailureException
*/
public void createTaskList(TaskList tasklist) throws NetworkFailureException {
commitUpdate();
try {
@ -396,10 +482,10 @@ public class GTaskClient {
actionList.put(tasklist.getCreateAction(getActionId()));
jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList);
// client version
// client_version
jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
// post
// 发送请求
JSONObject jsResponse = postRequest(jsPost);
JSONObject jsResult = (JSONObject) jsResponse.getJSONArray(
GTaskStringUtils.GTASK_JSON_RESULTS).get(0);
@ -412,6 +498,11 @@ public class GTaskClient {
}
}
/**
*
* Google Tasks
* @throws NetworkFailureException
*/
public void commitUpdate() throws NetworkFailureException {
if (mUpdateArray != null) {
try {
@ -433,10 +524,17 @@ public class GTaskClient {
}
}
/**
*
*
* 10
* @param node
* @throws NetworkFailureException
*/
public void addUpdateNode(Node node) throws NetworkFailureException {
if (node != null) {
// too many update items may result in an error
// set max to 10 items
// 过多的更新项可能导致错误
// 最大设置为10项
if (mUpdateArray != null && mUpdateArray.length() > 10) {
commitUpdate();
}
@ -447,6 +545,14 @@ public class GTaskClient {
}
}
/**
*
*
* @param task
* @param preParent
* @param curParent
* @throws NetworkFailureException
*/
public void moveTask(Task task, TaskList preParent, TaskList curParent)
throws NetworkFailureException {
commitUpdate();
@ -461,14 +567,13 @@ public class GTaskClient {
action.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, getActionId());
action.put(GTaskStringUtils.GTASK_JSON_ID, task.getGid());
if (preParent == curParent && task.getPriorSibling() != null) {
// put prioring_sibing_id only if moving within the tasklist and
// it is not the first one
// 只有在同一任务列表内移动且不是第一个任务时才设置prior_sibling_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);
@ -486,6 +591,12 @@ public class GTaskClient {
}
}
/**
*
*
* @param node
* @throws NetworkFailureException
*/
public void deleteNode(Node node) throws NetworkFailureException {
commitUpdate();
try {
@ -509,6 +620,12 @@ public class GTaskClient {
}
}
/**
*
* Google Tasks
* @return JSON
* @throws NetworkFailureException
*/
public JSONArray getTaskLists() throws NetworkFailureException {
if (!mLoggedin) {
Log.e(TAG, "please login first");
@ -547,6 +664,13 @@ public class GTaskClient {
}
}
/**
*
* Google Tasks
* @param listGid GID
* @return JSON
* @throws NetworkFailureException
*/
public JSONArray getTaskList(String listGid) throws NetworkFailureException {
commitUpdate();
try {
@ -575,10 +699,18 @@ public class GTaskClient {
}
}
/**
*
* @return 使Google
*/
public Account getSyncAccount() {
return mAccount;
}
/**
*
*
*/
public void resetUpdateArray() {
mUpdateArray = null;
}

@ -48,45 +48,73 @@ import java.util.Iterator;
import java.util.Map;
/**
* Google Tasks
* Google Tasks
*
*/
public class GTaskManager {
// 日志标签
private static final String TAG = GTaskManager.class.getSimpleName();
// 同步状态:成功
public static final int STATE_SUCCESS = 0;
// 同步状态:网络错误
public static final int STATE_NETWORK_ERROR = 1;
// 同步状态:内部错误
public static final int STATE_INTERNAL_ERROR = 2;
// 同步状态:同步进行中
public static final int STATE_SYNC_IN_PROGRESS = 3;
// 同步状态:同步已取消
public static final int STATE_SYNC_CANCELLED = 4;
// 单例实例
private static GTaskManager mInstance = null;
// 用于获取认证令牌的Activity实例
private Activity mActivity;
// 应用上下文
private Context mContext;
// 内容解析器
private ContentResolver mContentResolver;
// 是否正在同步
private boolean mSyncing;
// 是否取消同步
private boolean mCancelled;
// Google Tasks列表映射表
private HashMap<String, TaskList> mGTaskListHashMap;
// Google Tasks节点映射表
private HashMap<String, Node> mGTaskHashMap;
// 元数据映射表
private HashMap<String, MetaData> mMetaHashMap;
// 元数据列表
private TaskList mMetaList;
// 本地删除ID集合
private HashSet<Long> mLocalDeleteIdMap;
// GID到本地ID的映射表
private HashMap<String, Long> mGidToNid;
// 本地ID到GID的映射表
private HashMap<Long, String> mNidToGid;
/**
*
*
*/
private GTaskManager() {
mSyncing = false;
mCancelled = false;
@ -99,6 +127,10 @@ public class GTaskManager {
mNidToGid = new HashMap<Long, String>();
}
/**
*
* @return GTaskManager
*/
public static synchronized GTaskManager getInstance() {
if (mInstance == null) {
mInstance = new GTaskManager();
@ -106,11 +138,23 @@ public class GTaskManager {
return mInstance;
}
/**
* Activity
* Google
* @param activity Activity
*/
public synchronized void setActivityContext(Activity activity) {
// used for getting authtoken
mActivity = activity;
}
/**
*
* Google Tasks
* @param context
* @param asyncTask
* @return
*/
public int sync(Context context, GTaskASyncTask asyncTask) {
if (mSyncing) {
Log.d(TAG, "Sync is in progress");
@ -168,6 +212,11 @@ public class GTaskManager {
return mCancelled ? STATE_SYNC_CANCELLED : STATE_SUCCESS;
}
/**
* Google Tasks
*
* @throws NetworkFailureException
*/
private void initGTaskList() throws NetworkFailureException {
if (mCancelled)
return;
@ -247,6 +296,11 @@ public class GTaskManager {
}
}
/**
*
*
* @throws NetworkFailureException
*/
private void syncContent() throws NetworkFailureException {
int syncType;
Cursor c = null;
@ -351,6 +405,11 @@ public class GTaskManager {
}
/**
*
*
* @throws NetworkFailureException
*/
private void syncFolder() throws NetworkFailureException {
Cursor c = null;
String gid;
@ -476,6 +535,14 @@ public class GTaskManager {
GTaskClient.getInstance().commitUpdate();
}
/**
*
*
* @param syncType
* @param node Google Tasks
* @param c
* @throws NetworkFailureException
*/
private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -522,6 +589,12 @@ public class GTaskManager {
}
}
/**
*
* Google Tasks
* @param node Google Tasks
* @throws NetworkFailureException
*/
private void addLocalNode(Node node) throws NetworkFailureException {
if (mCancelled) {
return;
@ -596,6 +669,13 @@ public class GTaskManager {
updateRemoteMeta(node.getGid(), sqlNote);
}
/**
*
* 使Google Tasks
* @param node Google Tasks
* @param c
* @throws NetworkFailureException
*/
private void updateLocalNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -619,6 +699,13 @@ public class GTaskManager {
updateRemoteMeta(node.getGid(), sqlNote);
}
/**
*
* Google Tasks
* @param node Google Tasks
* @param c
* @throws NetworkFailureException
*/
private void addRemoteNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -692,6 +779,13 @@ public class GTaskManager {
mNidToGid.put(sqlNote.getId(), n.getGid());
}
/**
*
* 使Google Tasks
* @param node Google Tasks
* @param c
* @throws NetworkFailureException
*/
private void updateRemoteNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -730,6 +824,13 @@ public class GTaskManager {
sqlNote.commit(true);
}
/**
*
* Google Tasks
* @param gid Google TasksID
* @param sqlNote
* @throws NetworkFailureException
*/
private void updateRemoteMeta(String gid, SqlNote sqlNote) throws NetworkFailureException {
if (sqlNote != null && sqlNote.isNoteType()) {
MetaData metaData = mMetaHashMap.get(gid);
@ -746,6 +847,11 @@ public class GTaskManager {
}
}
/**
* ID
* ID
* @throws NetworkFailureException
*/
private void refreshLocalSyncId() throws NetworkFailureException {
if (mCancelled) {
return;
@ -790,10 +896,18 @@ public class GTaskManager {
}
}
/**
*
* @return
*/
public String getSyncAccount() {
return GTaskClient.getInstance().getSyncAccount().name;
}
/**
*
*
*/
public void cancelSync() {
mCancelled = true;
}

@ -23,25 +23,43 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
/**
* Google Tasks
* Google Tasks
* 广
*/
public class GTaskSyncService extends Service {
// 同步操作类型的额外参数名称
public final static String ACTION_STRING_NAME = "sync_action_type";
// 启动同步操作的类型值
public final static int ACTION_START_SYNC = 0;
// 取消同步操作的类型值
public final static int ACTION_CANCEL_SYNC = 1;
// 无效操作的类型值
public final static int ACTION_INVALID = 2;
// 同步服务广播的名称
public final static String GTASK_SERVICE_BROADCAST_NAME = "net.micode.notes.gtask.remote.gtask_sync_service";
// 广播中同步状态的额外参数名称
public final static String GTASK_SERVICE_BROADCAST_IS_SYNCING = "isSyncing";
// 广播中同步进度的额外参数名称
public final static String GTASK_SERVICE_BROADCAST_PROGRESS_MSG = "progressMsg";
// 同步任务实例
private static GTaskASyncTask mSyncTask = null;
// 当前同步进度消息
private static String mSyncProgress = "";
/**
*
*
*/
private void startSync() {
if (mSyncTask == null) {
mSyncTask = new GTaskASyncTask(this, new GTaskASyncTask.OnCompleteListener() {
@ -56,17 +74,33 @@ public class GTaskSyncService extends Service {
}
}
/**
*
*
*/
private void cancelSync() {
if (mSyncTask != null) {
mSyncTask.cancelSync();
}
}
/**
*
* null
*/
@Override
public void onCreate() {
mSyncTask = null;
}
/**
*
*
* @param intent
* @param flags
* @param startId ID
* @return
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Bundle bundle = intent.getExtras();
@ -86,6 +120,10 @@ public class GTaskSyncService extends Service {
return super.onStartCommand(intent, flags, startId);
}
/**
*
*
*/
@Override
public void onLowMemory() {
if (mSyncTask != null) {
@ -93,10 +131,20 @@ public class GTaskSyncService extends Service {
}
}
/**
*
* null
* @param intent
* @return IBinder
*/
public IBinder onBind(Intent intent) {
return null;
}
/**
* 广
* @param msg
*/
public void sendBroadcast(String msg) {
mSyncProgress = msg;
Intent intent = new Intent(GTASK_SERVICE_BROADCAST_NAME);
@ -105,6 +153,10 @@ public class GTaskSyncService extends Service {
sendBroadcast(intent);
}
/**
*
* @param activity Activity
*/
public static void startSync(Activity activity) {
GTaskManager.getInstance().setActivityContext(activity);
Intent intent = new Intent(activity, GTaskSyncService.class);
@ -112,16 +164,28 @@ public class GTaskSyncService extends Service {
activity.startService(intent);
}
/**
*
* @param context
*/
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);
}
/**
*
* @return
*/
public static boolean isSyncing() {
return mSyncTask != null;
}
/**
*
* @return
*/
public static String getProgressString() {
return mSyncProgress;
}

@ -34,12 +34,25 @@ import net.micode.notes.data.Notes.TextNote;
import java.util.ArrayList;
/**
*
* ContentResolver
*/
public class Note {
// 日志标签
private static final String TAG = "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
* ID
* @param context
* @param folderId ID
* @return ID
* @throws IllegalStateException
*/
public static synchronized long getNewNoteId(Context context, long folderId) {
// Create a new note in the database
@ -65,41 +78,82 @@ public class Note {
return noteId;
}
/**
*
*/
public Note() {
mNoteDiffValues = new ContentValues();
mNoteData = new NoteData();
}
/**
*
* @param key
* @param value
*/
public void setNoteValue(String key, String value) {
mNoteDiffValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
/**
*
* @param key
* @param value
*/
public void setTextData(String key, String value) {
mNoteData.setTextData(key, value);
}
/**
* ID
* @param id ID
*/
public void setTextDataId(long id) {
mNoteData.setTextDataId(id);
}
/**
* ID
* @return ID
*/
public long getTextDataId() {
return mNoteData.mTextDataId;
}
/**
* ID
* @param id ID
*/
public void setCallDataId(long id) {
mNoteData.setCallDataId(id);
}
/**
*
* @param key
* @param value
*/
public void setCallData(String key, String value) {
mNoteData.setCallData(key, value);
}
/**
*
* @return truefalse
*/
public boolean isLocalModified() {
return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified();
}
/**
* ContentResolver
* @param context
* @param noteId ID
* @return truefalse
* @throws IllegalArgumentException ID
*/
public boolean syncNote(Context context, long noteId) {
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId);
@ -110,15 +164,14 @@ public class Note {
}
/**
* 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
* {@link NoteColumns#LOCAL_MODIFIED}{@link NoteColumns#MODIFIED_DATE}
* 使
*/
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();
@ -130,17 +183,29 @@ public class Note {
return true;
}
/**
*
*
*/
private class NoteData {
// 日志标签
private static final String TAG = "NoteData";
// 文本数据ID
private long mTextDataId;
// 文本数据内容的变更值
private ContentValues mTextDataValues;
// 通话记录数据ID
private long mCallDataId;
// 通话记录数据内容的变更值
private ContentValues mCallDataValues;
private static final String TAG = "NoteData";
/**
*
*/
public NoteData() {
mTextDataValues = new ContentValues();
mCallDataValues = new ContentValues();
@ -148,10 +213,19 @@ public class Note {
mCallDataId = 0;
}
/**
*
* @return truefalse
*/
boolean isLocalModified() {
return mTextDataValues.size() > 0 || mCallDataValues.size() > 0;
}
/**
* ID
* @param id ID
* @throws IllegalArgumentException ID
*/
void setTextDataId(long id) {
if(id <= 0) {
throw new IllegalArgumentException("Text data id should larger than 0");
@ -159,6 +233,11 @@ public class Note {
mTextDataId = id;
}
/**
* ID
* @param id ID
* @throws IllegalArgumentException ID
*/
void setCallDataId(long id) {
if (id <= 0) {
throw new IllegalArgumentException("Call data id should larger than 0");
@ -166,21 +245,38 @@ public class Note {
mCallDataId = id;
}
/**
*
* @param key
* @param value
*/
void setCallData(String key, String value) {
mCallDataValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
/**
*
* @param key
* @param value
*/
void setTextData(String key, String value) {
mTextDataValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
/**
* ContentResolver
* @param context
* @param noteId ID
* @return Urinull
* @throws IllegalArgumentException ID
*/
Uri pushIntoContentResolver(Context context, long noteId) {
/**
* Check for safety
*
*/
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId);
@ -192,6 +288,7 @@ public class Note {
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);
@ -203,6 +300,7 @@ public class Note {
return null;
}
} else {
// 更新已有文本数据
builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mTextDataId));
builder.withValues(mTextDataValues);
@ -214,6 +312,7 @@ public class Note {
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);
@ -225,6 +324,7 @@ public class Note {
return null;
}
} else {
// 更新已有通话记录数据
builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mCallDataId));
builder.withValues(mCallDataValues);
@ -233,6 +333,7 @@ public class Note {
mCallDataValues.clear();
}
// 执行批量操作
if (operationList.size() > 0) {
try {
ContentProviderResult[] results = context.getContentResolver().applyBatch(

@ -32,36 +32,57 @@ import net.micode.notes.data.Notes.TextNote;
import net.micode.notes.tool.ResourceParser.NoteBgResources;
/**
*
* Note
*
*/
public class WorkingNote {
// Note for the working note
// 日志标签
private static final String TAG = "WorkingNote";
// 上下文对象
private Context mContext;
// 内部Note对象用于实际数据操作
private Note mNote;
// Note Id
// 笔记ID
private long mNoteId;
// Note content
// 笔记内容
private String mContent;
// Note mode
// 笔记模式(如普通模式、检查列表模式)
private int mMode;
// 提醒日期
private long mAlertDate;
// 最后修改日期
private long mModifiedDate;
// 背景颜色ID
private int mBgColorId;
// 小组件ID
private int mWidgetId;
// 小组件类型
private int mWidgetType;
// 文件夹ID
private long mFolderId;
private Context mContext;
private static final String TAG = "WorkingNote";
// 是否已删除
private boolean mIsDeleted;
// 笔记设置变化监听器
private NoteSettingChangedListener mNoteSettingStatusListener;
/**
*
*/
public static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID,
DataColumns.CONTENT,
@ -72,6 +93,9 @@ public class WorkingNote {
DataColumns.DATA4,
};
/**
*
*/
public static final String[] NOTE_PROJECTION = new String[] {
NoteColumns.PARENT_ID,
NoteColumns.ALERTED_DATE,
@ -81,27 +105,41 @@ public class WorkingNote {
NoteColumns.MODIFIED_DATE
};
// DATA_PROJECTION中ID列的索引
private static final int DATA_ID_COLUMN = 0;
// DATA_PROJECTION中内容列的索引
private static final int DATA_CONTENT_COLUMN = 1;
// DATA_PROJECTION中MIME类型列的索引
private static final int DATA_MIME_TYPE_COLUMN = 2;
// DATA_PROJECTION中模式列的索引
private static final int DATA_MODE_COLUMN = 3;
// NOTE_PROJECTION中父ID列的索引
private static final int NOTE_PARENT_ID_COLUMN = 0;
// NOTE_PROJECTION中提醒日期列的索引
private static final int NOTE_ALERTED_DATE_COLUMN = 1;
// NOTE_PROJECTION中背景颜色ID列的索引
private static final int NOTE_BG_COLOR_ID_COLUMN = 2;
// NOTE_PROJECTION中小组件ID列的索引
private static final int NOTE_WIDGET_ID_COLUMN = 3;
// NOTE_PROJECTION中小组件类型列的索引
private static final int NOTE_WIDGET_TYPE_COLUMN = 4;
// NOTE_PROJECTION中修改日期列的索引
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
// New note construct
/**
*
* @param context
* @param folderId ID
*/
private WorkingNote(Context context, long folderId) {
mContext = context;
mAlertDate = 0;
@ -114,7 +152,12 @@ public class WorkingNote {
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
}
// Existing note construct
/**
*
* @param context
* @param noteId ID
* @param folderId ID
*/
private WorkingNote(Context context, long noteId, long folderId) {
mContext = context;
mNoteId = noteId;
@ -124,6 +167,10 @@ public class WorkingNote {
loadNote();
}
/**
*
* @throws IllegalArgumentException ID
*/
private void loadNote() {
Cursor cursor = mContext.getContentResolver().query(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null,
@ -146,6 +193,10 @@ public class WorkingNote {
loadNoteData();
}
/**
*
* @throws IllegalArgumentException ID
*/
private void loadNoteData() {
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
DataColumns.NOTE_ID + "=?", new String[] {
@ -174,6 +225,15 @@ public class WorkingNote {
}
}
/**
*
* @param context
* @param folderId ID
* @param widgetId ID
* @param widgetType
* @param defaultBgColorId ID
* @return
*/
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
int widgetType, int defaultBgColorId) {
WorkingNote note = new WorkingNote(context, folderId);
@ -183,10 +243,21 @@ public class WorkingNote {
return note;
}
/**
* ID
* @param context
* @param id ID
* @return
*/
public static WorkingNote load(Context context, long id) {
return new WorkingNote(context, id, 0);
}
/**
*
* 线线
* @return truefalse
*/
public synchronized boolean saveNote() {
if (isWorthSaving()) {
if (!existInDatabase()) {
@ -212,10 +283,18 @@ public class WorkingNote {
}
}
/**
*
* @return truefalse
*/
public boolean existInDatabase() {
return mNoteId > 0;
}
/**
*
* @return truefalse
*/
private boolean isWorthSaving() {
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|| (existInDatabase() && !mNote.isLocalModified())) {
@ -225,10 +304,19 @@ public class WorkingNote {
}
}
/**
*
* @param l
*/
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
mNoteSettingStatusListener = l;
}
/**
*
* @param date
* @param set
*/
public void setAlertDate(long date, boolean set) {
if (date != mAlertDate) {
mAlertDate = date;
@ -239,6 +327,10 @@ public class WorkingNote {
}
}
/**
*
* @param mark truefalse
*/
public void markDeleted(boolean mark) {
mIsDeleted = mark;
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
@ -247,6 +339,10 @@ public class WorkingNote {
}
}
/**
* ID
* @param id ID
*/
public void setBgColorId(int id) {
if (id != mBgColorId) {
mBgColorId = id;
@ -257,6 +353,10 @@ public class WorkingNote {
}
}
/**
*
* @param mode 01
*/
public void setCheckListMode(int mode) {
if (mMode != mode) {
if (mNoteSettingStatusListener != null) {
@ -267,6 +367,10 @@ public class WorkingNote {
}
}
/**
*
* @param type
*/
public void setWidgetType(int type) {
if (type != mWidgetType) {
mWidgetType = type;
@ -274,6 +378,10 @@ public class WorkingNote {
}
}
/**
* ID
* @param id ID
*/
public void setWidgetId(int id) {
if (id != mWidgetId) {
mWidgetId = id;
@ -281,6 +389,10 @@ public class WorkingNote {
}
}
/**
*
* @param text
*/
public void setWorkingText(String text) {
if (!TextUtils.equals(mContent, text)) {
mContent = text;
@ -288,80 +400,139 @@ public class WorkingNote {
}
}
/**
*
* @param phoneNumber
* @param 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));
}
/**
*
* @return truefalse
*/
public boolean hasClockAlert() {
return (mAlertDate > 0 ? true : false);
}
/**
*
* @return
*/
public String getContent() {
return mContent;
}
/**
*
* @return
*/
public long getAlertDate() {
return mAlertDate;
}
/**
*
* @return
*/
public long getModifiedDate() {
return mModifiedDate;
}
/**
* ID
* @return ID
*/
public int getBgColorResId() {
return NoteBgResources.getNoteBgResource(mBgColorId);
}
/**
* ID
* @return ID
*/
public int getBgColorId() {
return mBgColorId;
}
/**
* ID
* @return ID
*/
public int getTitleBgResId() {
return NoteBgResources.getNoteTitleBgResource(mBgColorId);
}
/**
*
* @return 01
*/
public int getCheckListMode() {
return mMode;
}
/**
* ID
* @return ID
*/
public long getNoteId() {
return mNoteId;
}
/**
* ID
* @return ID
*/
public long getFolderId() {
return mFolderId;
}
/**
* ID
* @return ID
*/
public int getWidgetId() {
return mWidgetId;
}
/**
*
* @return
*/
public int getWidgetType() {
return mWidgetType;
}
/**
*
*
*/
public interface NoteSettingChangedListener {
/**
* Called when the background color of current note has just changed
*
*/
void onBackgroundColorChanged();
/**
* Called when user set clock
*
* @param date
* @param set
*/
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
*
* @param oldMode
* @param newMode
*/
void onCheckListModeChanged(int oldMode, int newMode);
}

@ -36,11 +36,21 @@ import java.io.IOException;
import java.io.PrintStream;
/**
*
* SD
*/
public class BackupUtils {
// 日志标签
private static final String TAG = "BackupUtils";
// Singleton stuff
private static BackupUtils sInstance;
/**
* BackupUtils
* @param context
* @return BackupUtils
*/
public static synchronized BackupUtils getInstance(Context context) {
if (sInstance == null) {
sInstance = new BackupUtils(context);
@ -65,26 +75,54 @@ public class BackupUtils {
private TextExport mTextExport;
/**
* BackupUtils
* TextExport
* @param context
*/
private BackupUtils(Context context) {
mTextExport = new TextExport(context);
}
/**
* SD
* @return SDtruefalse
*/
private static boolean externalStorageAvailable() {
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}
/**
*
* @return
* STATE_SD_CARD_UNMOUONTED - SD
* STATE_SYSTEM_ERROR -
* STATE_SUCCESS -
*/
public int exportToText() {
return mTextExport.exportToText();
}
/**
*
* @return
*/
public String getExportedTextFileName() {
return mTextExport.mFileName;
}
/**
*
* @return
*/
public String getExportedTextFileDir() {
return mTextExport.mFileDirectory;
}
/**
*
*
*/
private static class TextExport {
private static final String[] NOTE_PROJECTION = {
NoteColumns.ID,
@ -125,6 +163,10 @@ public class BackupUtils {
private String mFileName;
private String mFileDirectory;
/**
*
* @param context
*/
public TextExport(Context context) {
TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note);
mContext = context;
@ -132,12 +174,19 @@ public class BackupUtils {
mFileDirectory = "";
}
/**
* ID
* @param id ID
* @return
*/
private String getFormat(int id) {
return TEXT_FORMAT[id];
}
/**
* Export the folder identified by folder id to text
* ID
* @param folderId ID
* @param ps
*/
private void exportFolderToText(String folderId, PrintStream ps) {
// Query notes belong to this folder
@ -163,7 +212,9 @@ public class BackupUtils {
}
/**
* Export note identified by id to a print stream
* ID
* @param noteId ID
* @param ps
*/
private void exportNoteToText(String noteId, PrintStream ps) {
Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI,
@ -216,7 +267,11 @@ public class BackupUtils {
}
/**
* Note will be exported as text which is user readable
*
* @return
* STATE_SD_CARD_UNMOUONTED - SD
* STATE_SYSTEM_ERROR -
* STATE_SUCCESS -
*/
public int exportToText() {
if (!externalStorageAvailable()) {
@ -283,7 +338,8 @@ public class BackupUtils {
}
/**
* Get a print stream pointed to the file {@generateExportedTextFile}
*
* @return null
*/
private PrintStream getExportToTextPrintStream() {
File file = generateFileMountedOnSDcard(mContext, R.string.file_path,
@ -310,7 +366,11 @@ public class BackupUtils {
}
/**
* Generate the text file to store imported data
* SD
* @param context
* @param filePathResId ID
* @param fileNameFormatResId ID
* @return null
*/
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
StringBuilder sb = new StringBuilder();

@ -35,8 +35,19 @@ import java.util.ArrayList;
import java.util.HashSet;
/**
*
*
*/
public class DataUtils {
// 日志标签
public static final String TAG = "DataUtils";
/**
*
* @param resolver
* @param ids ID
* @return truefalse
*/
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
if (ids == null) {
Log.d(TAG, "the ids is null");
@ -72,6 +83,13 @@ public class DataUtils {
return false;
}
/**
*
* @param resolver
* @param id ID
* @param srcFolderId ID
* @param desFolderId ID
*/
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
ContentValues values = new ContentValues();
values.put(NoteColumns.PARENT_ID, desFolderId);
@ -80,6 +98,13 @@ public class DataUtils {
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
}
/**
*
* @param resolver
* @param ids ID
* @param folderId ID
* @return truefalse
*/
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
long folderId) {
if (ids == null) {
@ -112,7 +137,9 @@ public class DataUtils {
}
/**
* Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}}
*
* @param resolver
* @return
*/
public static int getUserFolderCount(ContentResolver resolver) {
Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
@ -136,6 +163,13 @@ public class DataUtils {
return count;
}
/**
* ID
* @param resolver
* @param noteId ID
* @param type
* @return truefalse
*/
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null,
@ -153,6 +187,12 @@ public class DataUtils {
return exist;
}
/**
* ID
* @param resolver
* @param noteId ID
* @return truefalse
*/
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null);
@ -167,6 +207,12 @@ public class DataUtils {
return exist;
}
/**
* ID
* @param resolver
* @param dataId ID
* @return truefalse
*/
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
null, null, null, null);
@ -181,6 +227,12 @@ public class DataUtils {
return exist;
}
/**
*
* @param resolver
* @param name
* @return truefalse
*/
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
@ -197,6 +249,12 @@ public class DataUtils {
return exist;
}
/**
*
* @param resolver
* @param folderId ID
* @return null
*/
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 },
@ -224,6 +282,12 @@ public class DataUtils {
return set;
}
/**
* ID
* @param resolver
* @param noteId ID
* @return
*/
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.PHONE_NUMBER },
@ -243,6 +307,13 @@ public class DataUtils {
return "";
}
/**
* ID
* @param resolver
* @param phoneNumber
* @param callDate
* @return ID0
*/
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.NOTE_ID },
@ -264,6 +335,13 @@ public class DataUtils {
return 0;
}
/**
* ID
* @param resolver
* @param noteId ID
* @return
* @throws IllegalArgumentException ID
*/
public static String getSnippetById(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
new String [] { NoteColumns.SNIPPET },
@ -282,6 +360,11 @@ public class DataUtils {
throw new IllegalArgumentException("Note is not found with id: " + noteId);
}
/**
*
* @param snippet
* @return
*/
public static String getFormattedSnippet(String snippet) {
if (snippet != null) {
snippet = snippet.trim();

@ -16,98 +16,147 @@
package net.micode.notes.tool;
/**
* GoogleGoogleJSON
*/
public class GTaskStringUtils {
// JSON操作ID
public final static String GTASK_JSON_ACTION_ID = "action_id";
// JSON操作列表
public final static String GTASK_JSON_ACTION_LIST = "action_list";
// JSON操作类型
public final static String GTASK_JSON_ACTION_TYPE = "action_type";
// JSON创建操作类型
public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create";
// JSON获取全部操作类型
public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all";
// JSON移动操作类型
public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move";
// JSON更新操作类型
public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update";
// JSON创建者ID
public final static String GTASK_JSON_CREATOR_ID = "creator_id";
// JSON子实体
public final static String GTASK_JSON_CHILD_ENTITY = "child_entity";
// JSON客户端版本
public final static String GTASK_JSON_CLIENT_VERSION = "client_version";
// JSON完成状态
public final static String GTASK_JSON_COMPLETED = "completed";
// JSON当前列表ID
public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id";
// JSON默认列表ID
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id";
// JSON删除状态
public final static String GTASK_JSON_DELETED = "deleted";
// JSON目标列表
public final static String GTASK_JSON_DEST_LIST = "dest_list";
// JSON目标父项
public final static String GTASK_JSON_DEST_PARENT = "dest_parent";
// JSON目标父项类型
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type";
// JSON实体变更
public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta";
// JSON实体类型
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type";
// JSON获取已删除项目
public final static String GTASK_JSON_GET_DELETED = "get_deleted";
// JSON ID
public final static String GTASK_JSON_ID = "id";
// JSON索引
public final static String GTASK_JSON_INDEX = "index";
// JSON最后修改时间
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified";
// JSON最新同步点
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point";
// JSON列表ID
public final static String GTASK_JSON_LIST_ID = "list_id";
// JSON列表集合
public final static String GTASK_JSON_LISTS = "lists";
// JSON名称
public final static String GTASK_JSON_NAME = "name";
// JSON新ID
public final static String GTASK_JSON_NEW_ID = "new_id";
// JSON笔记内容
public final static String GTASK_JSON_NOTES = "notes";
// JSON父项ID
public final static String GTASK_JSON_PARENT_ID = "parent_id";
// JSON前一个兄弟项ID
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id";
// JSON结果集合
public final static String GTASK_JSON_RESULTS = "results";
// JSON源列表
public final static String GTASK_JSON_SOURCE_LIST = "source_list";
// JSON任务集合
public final static String GTASK_JSON_TASKS = "tasks";
// JSON类型
public final static String GTASK_JSON_TYPE = "type";
// JSON群组类型
public final static String GTASK_JSON_TYPE_GROUP = "GROUP";
// JSON任务类型
public final static String GTASK_JSON_TYPE_TASK = "TASK";
// JSON用户
public final static String GTASK_JSON_USER = "user";
// MIUI文件夹前缀
public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]";
// 默认文件夹
public final static String FOLDER_DEFAULT = "Default";
// 通话记录文件夹
public final static String FOLDER_CALL_NOTE = "Call_Note";
// 元数据文件夹
public final static String FOLDER_META = "METADATA";
// 元数据Google任务ID头
public final static String META_HEAD_GTASK_ID = "meta_gid";
// 元数据笔记头
public final static String META_HEAD_NOTE = "meta_note";
// 元数据数据头
public final static String META_HEAD_DATA = "meta_data";
// 元数据笔记名称
public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE";
}

@ -22,24 +22,43 @@ import android.preference.PreferenceManager;
import net.micode.notes.R;
import net.micode.notes.ui.NotesPreferenceActivity;
/**
*
*
*/
public class ResourceParser {
// 背景颜色常量 - 黄色
public static final int YELLOW = 0;
// 背景颜色常量 - 蓝色
public static final int BLUE = 1;
// 背景颜色常量 - 白色
public static final int WHITE = 2;
// 背景颜色常量 - 绿色
public static final int GREEN = 3;
// 背景颜色常量 - 红色
public static final int RED = 4;
// 默认背景颜色
public static final int 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,
@ -48,6 +67,7 @@ public class ResourceParser {
R.drawable.edit_red
};
// 编辑界面标题栏背景资源数组
private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] {
R.drawable.edit_title_yellow,
R.drawable.edit_title_blue,
@ -56,15 +76,30 @@ public class ResourceParser {
R.drawable.edit_title_red
};
/**
*
* @param id ID
* @return ID
*/
public static int getNoteBgResource(int id) {
return BG_EDIT_RESOURCES[id];
}
/**
*
* @param id ID
* @return ID
*/
public static int getNoteTitleBgResource(int id) {
return BG_EDIT_TITLE_RESOURCES[id];
}
}
/**
* ID
* @param context
* @return ID
*/
public static int getDefaultBgId(Context context) {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
@ -74,7 +109,11 @@ public class ResourceParser {
}
}
/**
*
*/
public static class NoteItemBgResources {
// 列表项第一个元素的背景资源数组
private final static int [] BG_FIRST_RESOURCES = new int [] {
R.drawable.list_yellow_up,
R.drawable.list_blue_up,
@ -83,6 +122,7 @@ public class ResourceParser {
R.drawable.list_red_up
};
// 列表项中间元素的背景资源数组
private final static int [] BG_NORMAL_RESOURCES = new int [] {
R.drawable.list_yellow_middle,
R.drawable.list_blue_middle,
@ -91,6 +131,7 @@ public class ResourceParser {
R.drawable.list_red_middle
};
// 列表项最后一个元素的背景资源数组
private final static int [] BG_LAST_RESOURCES = new int [] {
R.drawable.list_yellow_down,
R.drawable.list_blue_down,
@ -99,6 +140,7 @@ public class ResourceParser {
R.drawable.list_red_down,
};
// 列表项单独元素的背景资源数组
private final static int [] BG_SINGLE_RESOURCES = new int [] {
R.drawable.list_yellow_single,
R.drawable.list_blue_single,
@ -107,28 +149,56 @@ public class ResourceParser {
R.drawable.list_red_single
};
/**
*
* @param id ID
* @return ID
*/
public static int getNoteBgFirstRes(int id) {
return BG_FIRST_RESOURCES[id];
}
/**
*
* @param id ID
* @return ID
*/
public static int getNoteBgLastRes(int id) {
return BG_LAST_RESOURCES[id];
}
/**
*
* @param id ID
* @return ID
*/
public static int getNoteBgSingleRes(int id) {
return BG_SINGLE_RESOURCES[id];
}
/**
*
* @param id ID
* @return ID
*/
public static int getNoteBgNormalRes(int id) {
return BG_NORMAL_RESOURCES[id];
}
/**
*
* @return ID
*/
public static int getFolderBgRes() {
return R.drawable.list_folder;
}
}
/**
*
*/
public static class WidgetBgResources {
// 2x尺寸小部件的背景资源数组
private final static int [] BG_2X_RESOURCES = new int [] {
R.drawable.widget_2x_yellow,
R.drawable.widget_2x_blue,
@ -137,10 +207,16 @@ public class ResourceParser {
R.drawable.widget_2x_red,
};
/**
* 2x
* @param id ID
* @return ID
*/
public static int getWidget2xBgResource(int id) {
return BG_2X_RESOURCES[id];
}
// 4x尺寸小部件的背景资源数组
private final static int [] BG_4X_RESOURCES = new int [] {
R.drawable.widget_4x_yellow,
R.drawable.widget_4x_blue,
@ -149,12 +225,21 @@ public class ResourceParser {
R.drawable.widget_4x_red
};
/**
* 4x
* @param id ID
* @return ID
*/
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,
@ -162,6 +247,11 @@ public class ResourceParser {
R.style.TextAppearanceSuper
};
/**
*
* @param id ID
* @return ID
*/
public static int getTexAppearanceResource(int id) {
/**
* HACKME: Fix bug of store the resource id in shared preference.
@ -174,6 +264,10 @@ public class ResourceParser {
return TEXTAPPEARANCE_RESOURCES[id];
}
/**
*
* @return
*/
public static int getResourcesSize() {
return TEXTAPPEARANCE_RESOURCES.length;
}

@ -40,13 +40,26 @@ import net.micode.notes.tool.DataUtils;
import java.io.IOException;
/**
*
*
*
*/
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
// 笔记ID
private long mNoteId;
// 笔记摘要内容
private String mSnippet;
// 笔记摘要的最大显示长度
private static final int SNIPPET_PREW_MAX_LEN = 60;
// 媒体播放器,用于播放闹钟声音
MediaPlayer mPlayer;
@Override
/**
*
* @param savedInstanceState
*/
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
@ -83,11 +96,19 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
}
}
/**
*
* @return truefalse
*/
private boolean isScreenOn() {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
return pm.isScreenOn();
}
/**
*
*
*/
private void playAlarmSound() {
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
@ -105,20 +126,20 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
mPlayer.setLooping(true);
mPlayer.start();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
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.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle(R.string.app_name);
@ -130,6 +151,11 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
dialog.show().setOnDismissListener(this);
}
/**
*
* @param dialog
* @param which ID
*/
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_NEGATIVE:
@ -143,11 +169,18 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
}
}
/**
*
* @param dialog
*/
public void onDismiss(DialogInterface dialog) {
stopAlarmSound();
finish();
}
/**
*
*/
private void stopAlarmSound() {
if (mPlayer != null) {
mPlayer.stop();

@ -28,19 +28,33 @@ 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;
/**
* 广
* @param context
* @param intent 广
*/
@Override
public void onReceive(Context context, Intent intent) {
long currentDate = System.currentTimeMillis();
// 查询所有设置了提醒时间且提醒时间尚未到达的笔记
Cursor c = context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
PROJECTION,
NoteColumns.ALERTED_DATE + ">? AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE,
@ -50,6 +64,7 @@ public class AlarmInitReceiver extends BroadcastReceiver {
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)));

@ -20,11 +20,24 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
/**
* 广广
* 广广
* AlarmAlertActivity
*/
public class AlarmReceiver extends BroadcastReceiver {
/**
* 广
* @param context
* @param intent 广
*/
@Override
public void onReceive(Context context, Intent intent) {
// 将广播意图的目标类设置为AlarmAlertActivity
intent.setClass(context, AlarmAlertActivity.class);
// 添加新任务标志确保在非Activity上下文环境中也能启动活动
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// 启动闹钟提醒活动
context.startActivity(intent);
}
}

@ -28,6 +28,11 @@ import android.view.View;
import android.widget.FrameLayout;
import android.widget.NumberPicker;
/**
*
* AM/PM1224
*
*/
public class DateTimePicker extends FrameLayout {
private static final boolean DEFAULT_ENABLE_STATE = true;
@ -158,39 +163,72 @@ public class DateTimePicker extends FrameLayout {
}
};
/**
*
*/
public interface OnDateTimeChangedListener {
/**
*
* @param view
* @param year
* @param month
* @param dayOfMonth
* @param hourOfDay 24
* @param minute
*/
void onDateTimeChanged(DateTimePicker view, int year, int month,
int dayOfMonth, int hourOfDay, int minute);
}
/**
* 使
* @param context
*/
public DateTimePicker(Context context) {
this(context, System.currentTimeMillis());
}
/**
* 使
* @param context
* @param date
*/
public DateTimePicker(Context context, long date) {
this(context, date, DateFormat.is24HourFormat(context));
}
/**
* 使
* @param context
* @param date
* @param is24HourView 使24
*/
public DateTimePicker(Context context, long date, boolean is24HourView) {
super(context);
mDate = Calendar.getInstance();
mInitialising = true;
// 判断当前时间是上午还是下午
mIsAm = getCurrentHourOfDay() >= HOURS_IN_HALF_DAY;
// 加载布局文件
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);
@ -198,19 +236,21 @@ public class DateTimePicker extends FrameLayout {
mAmPmSpinner.setDisplayedValues(stringsForAmPm);
mAmPmSpinner.setOnValueChangedListener(mOnAmPmChangedListener);
// update controls to initial state
// 更新控件到初始状态
updateDateControl();
updateHourControl();
updateAmPmControl();
// 设置时间格式12小时制或24小时制
set24HourView(is24HourView);
// set to current time
// 设置初始日期时间
setCurrentDate(date);
// 设置控件是否可用
setEnabled(isEnabled());
// set the content descriptions
// 设置内容描述
mInitialising = false;
}
@ -348,6 +388,10 @@ public class DateTimePicker extends FrameLayout {
return mDate.get(Calendar.HOUR_OF_DAY);
}
/**
*
* @return 121-12240-23
*/
private int getCurrentHour() {
if (mIs24HourView){
return getCurrentHourOfDay();
@ -434,30 +478,47 @@ public class DateTimePicker extends FrameLayout {
updateAmPmControl();
}
/**
*
* "MM.dd EEEE"
*/
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();
}
/**
* /
* 24AM/PM12
*/
private void updateAmPmControl() {
if (mIs24HourView) {
mAmPmSpinner.setVisibility(View.GONE);
} else {
// 根据当前是上午还是下午设置选中状态
int index = mIsAm ? Calendar.AM : Calendar.PM;
mAmPmSpinner.setValue(index);
mAmPmSpinner.setVisibility(View.VISIBLE);
}
}
/**
*
* 240-23121-12
*/
private void updateHourControl() {
if (mIs24HourView) {
mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW);

@ -29,59 +29,113 @@ import android.content.DialogInterface.OnClickListener;
import android.text.format.DateFormat;
import android.text.format.DateUtils;
/**
*
* DateTimePicker
* 1224
*/
public class DateTimePickerDialog extends AlertDialog implements OnClickListener {
// 当前选择的日期时间
private Calendar mDate = Calendar.getInstance();
// 是否使用24小时制显示
private boolean mIs24HourView;
// 日期时间设置监听器
private OnDateTimeSetListener mOnDateTimeSetListener;
// 日期时间选择器控件
private DateTimePicker mDateTimePicker;
/**
*
*/
public interface OnDateTimeSetListener {
/**
*
* @param dialog
* @param date
*/
void OnDateTimeSet(AlertDialog dialog, long date);
}
/**
* 使
* @param context
* @param 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);
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());
}
/**
* 使24
* @param is24HourView 使24
*/
public void set24HourView(boolean is24HourView) {
mIs24HourView = is24HourView;
}
/**
*
* @param callBack
*/
public void setOnDateTimeSetListener(OnDateTimeSetListener callBack) {
mOnDateTimeSetListener = callBack;
}
/**
*
* @param date
*/
private void updateTitle(long date) {
int flag =
// 设置日期时间格式为显示年、月、日、时、分
int flag =
DateUtils.FORMAT_SHOW_YEAR |
DateUtils.FORMAT_SHOW_DATE |
DateUtils.FORMAT_SHOW_TIME;
// 设置时间格式为24小时制或12小时制
flag |= mIs24HourView ? DateUtils.FORMAT_24HOUR : DateUtils.FORMAT_24HOUR;
// 格式化日期时间并设置为对话框标题
setTitle(DateUtils.formatDateTime(this.getContext(), date, flag));
}
/**
*
* @param arg0
* @param arg1
*/
public void onClick(DialogInterface arg0, int arg1) {
// 如果设置了监听器,则调用监听器的方法
if (mOnDateTimeSetListener != null) {
mOnDateTimeSetListener.OnDateTimeSet(this, mDate.getTimeInMillis());
}

@ -27,17 +27,36 @@ import android.widget.PopupMenu.OnMenuItemClickListener;
import net.micode.notes.R;
/**
*
* AndroidPopupMenu
*
*/
public class DropdownMenu {
// 下拉菜单的按钮
private Button mButton;
// 弹出式菜单
private PopupMenu mPopupMenu;
// 菜单对象
private Menu mMenu;
/**
*
* @param context
* @param button
* @param menuId ID
*/
public DropdownMenu(Context context, Button button, int menuId) {
mButton = button;
// 设置按钮的背景为下拉图标
mButton.setBackgroundResource(R.drawable.dropdown_icon);
// 创建弹出式菜单
mPopupMenu = new PopupMenu(context, mButton);
// 获取菜单对象
mMenu = mPopupMenu.getMenu();
// 从资源文件中加载菜单
mPopupMenu.getMenuInflater().inflate(menuId, mMenu);
// 设置按钮的点击监听器,点击时显示下拉菜单
mButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mPopupMenu.show();
@ -45,16 +64,29 @@ public class DropdownMenu {
});
}
/**
*
* @param listener
*/
public void setOnDropdownMenuItemClickListener(OnMenuItemClickListener listener) {
if (mPopupMenu != null) {
mPopupMenu.setOnMenuItemClickListener(listener);
}
}
/**
* ID
* @param id ID
* @return null
*/
public MenuItem findItem(int id) {
return mMenu.findItem(id);
}
/**
*
* @param title
*/
public void setTitle(CharSequence title) {
mButton.setText(title);
}

@ -29,49 +29,96 @@ import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
/**
*
* CursorAdapter
*
*/
public class FoldersListAdapter extends CursorAdapter {
// 数据库查询的列投影
public static final String [] PROJECTION = {
NoteColumns.ID,
NoteColumns.SNIPPET
};
// ID列的索引
public static final int ID_COLUMN = 0;
// 文件夹名称列的索引
public static final int NAME_COLUMN = 1;
/**
*
* @param context
* @param c Cursor
*/
public FoldersListAdapter(Context context, Cursor c) {
super(context, c);
// TODO Auto-generated constructor stub
}
/**
*
* @param context
* @param cursor Cursor
* @param parent
* @return
*/
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new FolderListItem(context);
}
/**
*
* @param view
* @param context
* @param cursor Cursor
*/
@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);
}
}
/**
*
* @param context
* @param position
* @return
*/
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 {
// 显示文件夹名称的TextView
private TextView mName;
/**
*
* @param context
*/
public FolderListItem(Context context) {
super(context);
// 加载文件夹列表项布局
inflate(context, R.layout.folder_list_item, this);
// 获取文件夹名称TextView
mName = (TextView) findViewById(R.id.tv_folder_name);
}
/**
*
* @param name
*/
public void bind(String name) {
mName.setText(name);
}

@ -72,18 +72,44 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* NoteEditActivity - 便
* 便便
*
*
*
*
* - 便
* -
* -
* -
* -
* - 便
* - 便 widget
*
*
* - {@link #mWorkingNote} - 便
* - {@link #mNoteEditor} - 便
* - {@link #mNoteBgColorSelector} -
* - {@link #mFontSizeSelector} -
*/
public class NoteEditActivity extends Activity implements OnClickListener,
NoteSettingChangedListener, OnTextViewChangeListener {
/**
* HeadViewHolder - 便
* 便UI访
*/
private class HeadViewHolder {
public TextView tvModified;
public ImageView ivAlertIcon;
public TextView tvAlertDate;
public ImageView ibSetBgColor;
public TextView tvModified; // 修改日期文本视图
public ImageView ivAlertIcon; // 提醒图标
public TextView tvAlertDate; // 提醒日期文本视图
public ImageView ibSetBgColor; // 设置背景颜色按钮
}
/**
* IDID
*
*/
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
static {
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
@ -93,6 +119,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sBgSelectorBtnsMap.put(R.id.iv_bg_white, ResourceParser.WHITE);
}
/**
* IDID
*
*/
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
static {
sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select);
@ -102,6 +132,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sBgSelectorSelectionMap.put(ResourceParser.WHITE, R.id.iv_bg_white_select);
}
/**
* IDID
*
*/
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
static {
sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE);
@ -110,6 +144,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sFontSizeBtnsMap.put(R.id.ll_font_super, ResourceParser.TEXT_SUPER);
}
/**
* IDID
*
*/
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();
static {
sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select);
@ -118,36 +156,29 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SUPER, R.id.iv_super_select);
}
private static final String TAG = "NoteEditActivity";
private HeadViewHolder mNoteHeaderHolder;
private View mHeadViewPanel;
private View mNoteBgColorSelector;
private View mFontSizeSelector;
private EditText mNoteEditor;
private View mNoteEditorPanel;
private static final String TAG = "NoteEditActivity"; // 日志标签
private WorkingNote mWorkingNote;
private HeadViewHolder mNoteHeaderHolder; // 便签头部视图持有者
private View mHeadViewPanel; // 便签头部面板
private View mNoteBgColorSelector; // 背景颜色选择器视图
private View mFontSizeSelector; // 字体大小选择器视图
private EditText mNoteEditor; // 便签内容编辑器
private View mNoteEditorPanel; // 便签编辑器面板
private WorkingNote mWorkingNote; // 工作便签实例
private SharedPreferences mSharedPrefs; // 共享偏好设置
private int mFontSizeId; // 当前字体大小ID
private SharedPreferences mSharedPrefs;
private int mFontSizeId;
private static final String PREFERENCE_FONT_SIZE = "pref_font_size"; // 字体大小偏好键
private static final String PREFERENCE_FONT_SIZE = "pref_font_size";
private static final int SHORTCUT_ICON_TITLE_MAX_LEN = 10; // 快捷方式图标标题最大长度
private static final int SHORTCUT_ICON_TITLE_MAX_LEN = 10;
public static final String TAG_CHECKED = String.valueOf('\u221A'); // 待办事项已完成标记
public static final String TAG_UNCHECKED = String.valueOf('\u25A1'); // 待办事项未完成标记
public static final String TAG_CHECKED = String.valueOf('\u221A');
public static final String TAG_UNCHECKED = String.valueOf('\u25A1');
private LinearLayout mEditTextList; // 便签编辑列表容器
private LinearLayout mEditTextList;
private String mUserQuery;
private Pattern mPattern;
private String mUserQuery; // 用户搜索查询词
private Pattern mPattern; // 搜索查询词的正则表达式模式
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -179,6 +210,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
}
/**
*
* Intent便便便
* @param intent Intent
* @return
*/
private boolean initActivityState(Intent intent) {
/**
* If the user specified the {@link Intent#ACTION_VIEW} but not provided with id,
@ -268,6 +305,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
initNoteScreen();
}
/**
* 便
* 便
* 便
*/
private void initNoteScreen() {
mNoteEditor.setTextAppearance(this, TextAppearanceResources
.getTexAppearanceResource(mFontSizeId));
@ -349,6 +391,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return super.dispatchTouchEvent(ev);
}
/**
*
*
* @param view
* @param ev
* @return
*/
private boolean inRangeOfView(View view, MotionEvent ev) {
int []location = new int[2];
view.getLocationOnScreen(location);
@ -363,6 +412,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return true;
}
/**
*
*
*/
private void initResources() {
mHeadViewPanel = findViewById(R.id.note_title);
mNoteHeaderHolder = new HeadViewHolder();
@ -425,6 +478,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
setResult(RESULT_OK, intent);
}
/**
*
* UI
*
* @param v
*/
public void onClick(View v) {
int id = v.getId();
if (id == R.id.btn_set_bg_color) {
@ -452,6 +511,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
}
/**
*
*
* 便
*/
@Override
public void onBackPressed() {
if(clearSettingState()) {
@ -462,6 +526,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
super.onBackPressed();
}
/**
*
*
* @return
*/
private boolean clearSettingState() {
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE) {
mNoteBgColorSelector.setVisibility(View.GONE);
@ -473,6 +542,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return false;
}
/**
*
* 便
*/
public void onBackgroundColorChanged() {
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
View.VISIBLE);
@ -553,6 +626,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return true;
}
/**
* 便
* 便
*/
private void setReminder() {
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
@ -574,6 +651,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
context.startActivity(intent);
}
/**
* 便
* 便NoteEditActivity便
*/
private void createNewNote() {
// Firstly, save current editing notes
saveNote();
@ -586,6 +667,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
startActivity(intent);
}
/**
* 便
* 便
*/
private void deleteCurrentNote() {
if (mWorkingNote.existInDatabase()) {
HashSet<Long> ids = new HashSet<Long>();
@ -608,10 +693,21 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mWorkingNote.markDeleted(true);
}
/**
*
* Google
* @return
*/
private boolean isSyncMode() {
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
}
/**
*
* 便
* @param date
* @param set
*/
public void onClockAlertChanged(long date, boolean set) {
/**
* User could set clock to an unsaved note, so before setting the
@ -642,10 +738,20 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
}
/**
*
* 便
*/
public void onWidgetChanged() {
updateWidget();
}
/**
*
*
* @param index
* @param text
*/
public void onEditTextDelete(int index, String text) {
int childCount = mEditTextList.getChildCount();
if (childCount == 1) {
@ -672,6 +778,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
edit.setSelection(length);
}
/**
*
*
* @param index
* @param text
*/
public void onEditTextEnter(int index, String text) {
/**
* Should not happen, check for debug
@ -691,6 +803,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
}
/**
*
* 便
* @param text 便
*/
private void switchToListMode(String text) {
mEditTextList.removeAllViews();
String[] items = text.split("\n");
@ -708,6 +825,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mEditTextList.setVisibility(View.VISIBLE);
}
/**
*
* 便
* @param fullText 便
* @param userQuery
* @return Spannable
*/
private Spannable getHighlightQueryResult(String fullText, String userQuery) {
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
if (!TextUtils.isEmpty(userQuery)) {
@ -725,6 +849,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return spannable;
}
/**
*
*
* @param item
* @param index
* @return
*/
private View getListItem(String item, int index) {
View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null);
final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
@ -756,6 +887,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return view;
}
/**
*
*
*
* @param index
* @param hasText
*/
public void onTextChange(int index, boolean hasText) {
if (index >= mEditTextList.getChildCount()) {
Log.e(TAG, "Wrong index, should not happen");
@ -768,6 +906,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
}
/**
*
* 便
*
* @param oldMode
* @param newMode
*/
public void onCheckListModeChanged(int oldMode, int newMode) {
if (newMode == TextNote.MODE_CHECK_LIST) {
switchToListMode(mNoteEditor.getText().toString());
@ -782,6 +927,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
}
/**
*
* 便
* WorkingNote
*
* @return
*/
private boolean getWorkingText() {
boolean hasChecked = false;
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
@ -805,28 +957,32 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return hasChecked;
}
/**
* 便
*
* 便便
* 便/便
* 便
* 便
* 使{@link #RESULT_OK}/
* @return 便
*/
private boolean saveNote() {
getWorkingText();
boolean saved = mWorkingNote.saveNote();
if (saved) {
/**
* There are two modes from List view to edit view, open one note,
* create/edit a node. Opening node requires to the original
* position in the list when back from edit view, while creating a
* new node requires to the top of the list. This code
* {@link #RESULT_OK} is used to identify the create/edit state
*/
setResult(RESULT_OK);
}
return saved;
}
/**
* 便
* 便便访
* 便
*/
private void sendToDesktop() {
/**
* Before send message to home, we should make sure that current
* editing note is exists in databases. So, for new note, firstly
* save it
*/
// 发送到桌面之前,确保当前编辑的便签已存在于数据库中
if (!mWorkingNote.existInDatabase()) {
saveNote();
}
@ -846,16 +1002,19 @@ public class NoteEditActivity extends Activity implements OnClickListener,
showToast(R.string.info_note_enter_desktop);
sendBroadcast(sender);
} else {
/**
* There is the condition that user has input nothing (the note is
* not worthy saving), we have no note id, remind the user that he
* should input something
*/
// 用户未输入任何内容便签不值得保存没有便签ID
Log.e(TAG, "Send to desktop error");
showToast(R.string.error_note_empty_for_send_to_desktop);
}
}
/**
*
* 便
*
* @param content 便
* @return
*/
private String makeShortcutIconTitle(String content) {
content = content.replace(TAG_CHECKED, "");
content = content.replace(TAG_UNCHECKED, "");

@ -37,16 +37,31 @@ import net.micode.notes.R;
import java.util.HashMap;
import java.util.Map;
/**
* 便
* EditText
* NoteEditActivity
*/
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:" ;
/** 链接协议与对应操作资源ID的映射表 */
private static final Map<String, Integer> sSchemaActionResMap = new HashMap<String, Integer>();
/** 初始化链接协议与操作资源ID的映射关系 */
static {
sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel);
sSchemaActionResMap.put(SCHEME_HTTP, R.string.note_link_web);
@ -54,7 +69,8 @@ public class NoteEditText extends EditText {
}
/**
* Call by the {@link NoteEditActivity} to delete or add edit text
*
* {@link NoteEditActivity}
*/
public interface OnTextViewChangeListener {
/**
@ -75,35 +91,64 @@ public class NoteEditText extends EditText {
void onTextChange(int index, boolean hasText);
}
/** 编辑框变化监听器实例 */
private OnTextViewChangeListener mOnTextViewChangeListener;
/**
*
* @param context
*/
public NoteEditText(Context context) {
super(context, null);
mIndex = 0;
}
/**
*
* @param index
*/
public void setIndex(int index) {
mIndex = index;
}
/**
*
* @param listener
*/
public void setOnTextViewChangeListener(OnTextViewChangeListener listener) {
mOnTextViewChangeListener = listener;
}
/**
*
* @param context
* @param attrs
*/
public NoteEditText(Context context, AttributeSet attrs) {
super(context, attrs, android.R.attr.editTextStyle);
}
/**
*
* @param context
* @param attrs
* @param defStyle
*/
public NoteEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
/**
*
*
* @param event
* @return
*/
@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();
@ -111,6 +156,7 @@ public class NoteEditText extends EditText {
x += getScrollX();
y += getScrollY();
// 根据坐标获取对应的行和偏移量,并设置光标位置
Layout layout = getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
@ -121,15 +167,24 @@ public class NoteEditText extends EditText {
return super.onTouchEvent(event);
}
/**
*
*
* @param keyCode
* @param event
* @return
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_ENTER:
// 如果设置了监听器则不处理回车键按下事件由onKeyUp处理
if (mOnTextViewChangeListener != null) {
return false;
}
break;
case KeyEvent.KEYCODE_DEL:
// 记录删除键按下前的光标位置
mSelectionStartBeforeDelete = getSelectionStart();
break;
default:
@ -138,10 +193,19 @@ public class NoteEditText extends EditText {
return super.onKeyDown(keyCode, event);
}
/**
*
*
*
* @param keyCode
* @param event
* @return
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch(keyCode) {
case KeyEvent.KEYCODE_DEL:
// 处理删除键释放事件,如果光标在开头且不是第一个编辑框,则删除当前编辑框
if (mOnTextViewChangeListener != null) {
if (0 == mSelectionStartBeforeDelete && mIndex != 0) {
mOnTextViewChangeListener.onEditTextDelete(mIndex, getText().toString());
@ -152,10 +216,14 @@ public class NoteEditText extends EditText {
}
break;
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");
@ -167,29 +235,47 @@ public class NoteEditText extends EditText {
return super.onKeyUp(keyCode, event);
}
/**
*
*
* @param focused
* @param direction
* @param previouslyFocusedRect
*/
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if (mOnTextViewChangeListener != null) {
if (!focused && TextUtils.isEmpty(getText())) {
// 失去焦点且文本为空,通知监听器
mOnTextViewChangeListener.onTextChange(mIndex, false);
} else {
// 获得焦点或文本不为空,通知监听器
mOnTextViewChangeListener.onTextChange(mIndex, true);
}
}
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
/**
*
*
* @param menu
*/
@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);
// 获取选择区域内的URLSpan
final URLSpan[] urls = ((Spanned) getText()).getSpans(min, max, URLSpan.class);
if (urls.length == 1) {
// 根据链接协议获取对应的操作资源ID
int defaultResId = 0;
for(String schema: sSchemaActionResMap.keySet()) {
if(urls[0].getURL().indexOf(schema) >= 0) {
@ -198,14 +284,16 @@ public class NoteEditText extends EditText {
}
}
// 如果没有匹配的协议,则使用默认操作
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;
}

@ -26,7 +26,16 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.tool.DataUtils;
/**
* 便
* Cursor便访便
* 便
*/
public class NoteItemData {
/**
*
* Notes
*/
static final String [] PROJECTION = new String [] {
NoteColumns.ID,
NoteColumns.ALERTED_DATE,
@ -42,40 +51,77 @@ public class NoteItemData {
NoteColumns.WIDGET_TYPE,
};
/** ID列索引 */
private static final int ID_COLUMN = 0;
/** 提醒日期列索引 */
private static final int ALERTED_DATE_COLUMN = 1;
/** 背景颜色ID列索引 */
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;
/** 父文件夹ID列索引 */
private static final int PARENT_ID_COLUMN = 7;
/** 摘要文本列索引 */
private static final int SNIPPET_COLUMN = 8;
/** 便签类型列索引 */
private static final int TYPE_COLUMN = 9;
/** 小部件ID列索引 */
private static final int WIDGET_ID_COLUMN = 10;
/** 小部件类型列索引 */
private static final int WIDGET_TYPE_COLUMN = 11;
/** 便签ID */
private long mId;
/** 提醒日期 */
private long mAlertDate;
/** 背景颜色ID */
private int mBgColorId;
/** 创建日期 */
private long mCreatedDate;
/** 是否有附件 */
private boolean mHasAttachment;
/** 修改日期 */
private long mModifiedDate;
/** 便签数量(文件夹使用) */
private int mNotesCount;
/** 父文件夹ID */
private long mParentId;
/** 便签摘要文本 */
private String mSnippet;
/** 便签类型 */
private int mType;
/** 小部件ID */
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;
/**
*
* Cursor便
* @param context
* @param cursor Cursor
*/
public NoteItemData(Context context, Cursor cursor) {
mId = cursor.getLong(ID_COLUMN);
mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN);
@ -86,6 +132,7 @@ public class NoteItemData {
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);
@ -93,6 +140,7 @@ public class NoteItemData {
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
mPhoneNumber = "";
// 如果是通话记录便签,获取电话号码和联系人信息
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {
mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId);
if (!TextUtils.isEmpty(mPhoneNumber)) {
@ -106,9 +154,15 @@ public class NoteItemData {
if (mName == null) {
mName = "";
}
// 检查便签在列表中的位置状态
checkPostion(cursor);
}
/**
* 便
* 便便
* @param cursor Cursor
*/
private void checkPostion(Cursor cursor) {
mIsLastItem = cursor.isLast() ? true : false;
mIsFirstItem = cursor.isFirst() ? true : false;
@ -116,17 +170,21 @@ public class NoteItemData {
mIsMultiNotesFollowingFolder = false;
mIsOneNoteFollowingFolder = false;
// 检查是否为文件夹下的便签
if (mType == Notes.TYPE_NOTE && !mIsFirstItem) {
int position = cursor.getPosition();
if (cursor.moveToPrevious()) {
// 检查前一项是否为文件夹
if (cursor.getInt(TYPE_COLUMN) == Notes.TYPE_FOLDER
|| cursor.getInt(TYPE_COLUMN) == Notes.TYPE_SYSTEM) {
// 检查是否为文件夹下的多个便签之一
if (cursor.getCount() > (position + 1)) {
mIsMultiNotesFollowingFolder = true;
} else {
mIsOneNoteFollowingFolder = true;
}
}
// 恢复Cursor位置
if (!cursor.moveToNext()) {
throw new IllegalStateException("cursor move to previous but can't move back");
}
@ -134,90 +192,179 @@ public class NoteItemData {
}
}
/**
* 便
* @return 便
*/
public boolean isOneFollowingFolder() {
return mIsOneNoteFollowingFolder;
}
/**
* 便
* @return 便
*/
public boolean isMultiFollowingFolder() {
return mIsMultiNotesFollowingFolder;
}
/**
*
* @return
*/
public boolean isLast() {
return mIsLastItem;
}
/**
*
* @return
*/
public String getCallName() {
return mName;
}
/**
*
* @return
*/
public boolean isFirst() {
return mIsFirstItem;
}
/**
*
* @return
*/
public boolean isSingle() {
return mIsOnlyOneItem;
}
/**
* 便ID
* @return 便ID
*/
public long getId() {
return mId;
}
/**
*
* @return
*/
public long getAlertDate() {
return mAlertDate;
}
/**
*
* @return
*/
public long getCreatedDate() {
return mCreatedDate;
}
/**
*
* @return
*/
public boolean hasAttachment() {
return mHasAttachment;
}
/**
*
* @return
*/
public long getModifiedDate() {
return mModifiedDate;
}
/**
* ID
* @return ID
*/
public int getBgColorId() {
return mBgColorId;
}
/**
* ID
* @return ID
*/
public long getParentId() {
return mParentId;
}
/**
* 便使
* @return 便
*/
public int getNotesCount() {
return mNotesCount;
}
/**
* IDgetParentId
* @return ID
*/
public long getFolderId () {
return mParentId;
}
/**
* 便
* @return 便
*/
public int getType() {
return mType;
}
/**
*
* @return
*/
public int getWidgetType() {
return mWidgetType;
}
/**
* ID
* @return ID
*/
public int getWidgetId() {
return mWidgetId;
}
/**
* 便
* @return 便
*/
public String getSnippet() {
return mSnippet;
}
/**
*
* @return
*/
public boolean hasAlert() {
return (mAlertDate > 0);
}
/**
* 便
* @return 便
*/
public boolean isCallRecord() {
return (mParentId == Notes.ID_CALL_RECORD_FOLDER && !TextUtils.isEmpty(mPhoneNumber));
}
/**
* Cursor便
* @param cursor Cursor
* @return 便
*/
public static int getNoteType(Cursor cursor) {
return cursor.getInt(TYPE_COLUMN);
}

@ -78,85 +78,119 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
/**
* NotesListActivity - 便
* 便便
* MVCController
*
*
* - 便
* -
* - 便
* -
* - Google Tasks
* - 便
* - Widget
*
*
* - 使AsyncQueryHandlerUI
* - ActionMode
* - ListEditState
* - ContentResolverNotesProvider访
* -
*/
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 static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0; // 查询文件夹内便签列表的令牌
private static final int FOLDER_LIST_QUERY_TOKEN = 1; // 查询文件夹列表的令牌
// 文件夹上下文菜单ID常量
private static final int MENU_FOLDER_DELETE = 0; // 删除文件夹菜单ID
private static final int MENU_FOLDER_VIEW = 1; // 查看文件夹内容菜单ID
private static final int MENU_FOLDER_CHANGE_NAME = 2; // 重命名文件夹菜单ID
// SharedPreferences键名常量
private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction"; // 首次使用引导标记
/**
* ListEditState -
*
* UI
*/
private enum ListEditState {
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
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 ListEditState mState; // 当前列表编辑状态
private BackgroundQueryHandler mBackgroundQueryHandler; // 后台查询处理器
private NotesListAdapter mNotesListAdapter; // 便签列表适配器
private ListView mNotesListView; // 便签列表视图
private Button mAddNewNote; // 新建便签按钮
private boolean mDispatch; // 触摸事件分发标记
private int mOriginY; // 触摸事件原始Y坐标
private int mDispatchY; // 触摸事件分发Y坐标
private TextView mTitleBar; // 标题栏视图
private long mCurrentFolderId; // 当前文件夹ID
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)";
+ NoteColumns.NOTES_COUNT + ">0)"; // 根文件夹查询条件
private final static int REQUEST_CODE_OPEN_NODE = 102;
private final static int REQUEST_CODE_NEW_NODE = 103;
// Activity请求码常量
private final static int REQUEST_CODE_OPEN_NODE = 102; // 打开便签的请求码
private final static int REQUEST_CODE_NEW_NODE = 103; // 新建便签的请求码
/**
* Activity
* 使
* @param savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.note_list);
initResources();
setContentView(R.layout.note_list); // 设置布局文件
initResources(); // 初始化资源
/**
* Insert an introduction when user firstly use this application
* 使
*/
setAppInfoFromRawRes();
}
/**
* Activity
* 便便
* @param requestCode
* @param resultCode
* @param data
*/
@Override
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 {
super.onActivityResult(requestCode, resultCode, data);
}
}
/**
* 使
* raw便
* SharedPreferences
*/
private void setAppInfoFromRawRes() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
@ -184,7 +218,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@ -203,12 +236,20 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
/**
* Activity
* 便
*/
@Override
protected void onStart() {
super.onStart();
startAsyncNotesListQuery();
}
/**
*
* UI
*/
private void initResources() {
mContentResolver = this.getContentResolver();
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
@ -231,10 +272,15 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mModeCallBack = new ModeCallback();
}
/**
* ModeCallback -
* ListView.MultiChoiceModeListenerOnMenuItemClickListener
* 便
*/
private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
private DropdownMenu mDropDownMenu;
private ActionMode mActionMode;
private MenuItem mMoveMenu;
private DropdownMenu mDropDownMenu; // 下拉菜单组件,用于选择全部/取消选择
private ActionMode mActionMode; // 当前的操作模式实例
private MenuItem mMoveMenu; // 移动菜单项,根据条件显示或隐藏
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
getMenuInflater().inflate(R.menu.note_list_options, menu);
@ -286,26 +332,62 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
/**
*
*
* @param mode
* @param menu
* @return falsetrue
*/
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}
/**
*
*
* onMenuItemClickListener
* @param mode
* @param item
* @return falsetrue
*/
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// TODO Auto-generated method stub
return false;
}
/**
*
*
* -
* -
* - 便
* @param mode
*/
public void onDestroyActionMode(ActionMode mode) {
mNotesListAdapter.setChoiceMode(false);
mNotesListView.setLongClickable(true);
mAddNewNote.setVisibility(View.VISIBLE);
}
/**
*
* onDestroyActionMode
*/
public void finishActionMode() {
mActionMode.finish();
}
/**
*
*
*
* @param mode
* @param position
* @param id ID
* @param checked
*/
public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
boolean checked) {
mNotesListAdapter.setCheckedItem(position, checked);
@ -346,6 +428,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
/**
* NewNoteOnTouchListener - 便
* UI
* 便
*/
private class NewNoteOnTouchListener implements OnTouchListener {
public boolean onTouch(View v, MotionEvent event) {
@ -408,6 +495,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
};
/**
* 便
* ID使BackgroundQueryHandler线
* UI线onQueryComplete
*/
private void startAsyncNotesListQuery() {
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
: NORMAL_SELECTION;
@ -417,6 +509,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
}
/**
* BackgroundQueryHandler -
* AsyncQueryHandler线UI线
* tokenUI
*/
private final class BackgroundQueryHandler extends AsyncQueryHandler {
public BackgroundQueryHandler(ContentResolver contentResolver) {
super(contentResolver);
@ -426,9 +523,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
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 {
@ -441,6 +540,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
/**
*
* 便
* 使FoldersListAdapter
*
* @param cursor
*/
private void showFolderListMenu(Cursor cursor) {
AlertDialog.Builder builder = new AlertDialog.Builder(NotesListActivity.this);
builder.setTitle(R.string.menu_title_select_folder);
@ -462,6 +568,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
builder.show();
}
/**
* 便
* NoteEditActivity便
* ID
* 便便
*/
private void createNewNote() {
Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
@ -469,6 +581,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
}
/**
* 便
* 使线UI线
*
* - 便
* - 便
* 退
*/
private void batchDelete() {
new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() {
protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) {
@ -506,6 +626,15 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}.execute();
}
/**
*
*
* -
* -
*
*
* @param folderId ID
*/
private void deleteFolder(long folderId) {
if (folderId == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Wrong folder id, should not happen " + folderId);
@ -533,6 +662,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
/**
* 便
* NoteEditActivity便
* 便ID
* @param data 便
*/
private void openNode(NoteItemData data) {
Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_VIEW);
@ -540,6 +675,15 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
}
/**
*
* IDID便
*
* - CALL_RECORD_FOLDER便
* - SUB_FOLDER
*
* @param data
*/
private void openFolder(NoteItemData data) {
mCurrentFolderId = data.getId();
startAsyncNotesListQuery();
@ -557,6 +701,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mTitleBar.setVisibility(View.VISIBLE);
}
/**
*
* OnClickListenerUI
* 便
* @param v
*/
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_new_note:
@ -567,6 +717,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
/**
*
*
*/
private void showSoftInput() {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
@ -574,11 +728,25 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
/**
*
*
* @param view
*/
private void hideSoftInput(View view) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
/**
*
*
* - "创建文件夹"
* - "重命名文件夹"
*
*
* @param create truefalse
*/
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);
@ -664,6 +832,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
});
}
/**
*
*
* - SUB_FOLDER
* - CALL_RECORD_FOLDER便
* - NOTE_LIST退
*/
@Override
public void onBackPressed() {
switch (mState) {
@ -688,6 +863,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
/**
*
* ID广
* 2x4x
* @param appWidgetId ID
* @param appWidgetType 2x4x
*/
private void updateWidget(int appWidgetId, int appWidgetType) {
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
if (appWidgetType == Notes.TYPE_WIDGET_2X) {
@ -707,6 +889,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
setResult(RESULT_OK, intent);
}
/**
*
*
* -
* -
* -
*/
private final OnCreateContextMenuListener mFolderOnCreateContextMenuListener = new OnCreateContextMenuListener() {
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
if (mFocusNoteDataItem != null) {
@ -718,6 +907,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
};
/**
*
*
*
* @param menu
*/
@Override
public void onContextMenuClosed(Menu menu) {
if (mNotesListView != null) {
@ -726,6 +921,15 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
super.onContextMenuClosed(menu);
}
/**
*
*
* -
* -
* -
* @param item
* @return truefalse
*/
@Override
public boolean onContextItemSelected(MenuItem item) {
if (mFocusNoteDataItem == null) {
@ -760,6 +964,16 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true;
}
/**
*
*
* - NOTE_LIST
* - SUB_FOLDER
* - CALL_RECORD_FOLDER
*
* @param menu
* @return true
*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear();
@ -778,6 +992,18 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true;
}
/**
*
*
* -
* - 便
* - Google Tasks
* -
* - 便
* -
* @param item
* @return truefalse
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -818,12 +1044,25 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true;
}
/**
*
* 便
* @return true
*/
@Override
public boolean onSearchRequested() {
startSearch(null, false, null /* appData */, false);
return true;
}
/**
* 便
* 使BackupUtils线便SD
*
* - SD
* -
* -
*/
private void exportNoteToText() {
final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this);
new AsyncTask<Void, Void, Integer>() {
@ -866,21 +1105,39 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}.execute();
}
/**
*
* SharedPreferencesGoogle Tasks
* @return truefalse
*/
private boolean isSyncMode() {
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
}
/**
*
*
*
*/
private void startPreferenceActivity() {
Activity from = getParent() != null ? getParent() : this;
Intent intent = new Intent(from, NotesPreferenceActivity.class);
from.startActivityIfNeeded(intent, -1);
}
/**
* OnListItemClickListener -
* 便
* - 便
* - 便
*/
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();
@ -890,6 +1147,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return;
}
// 根据当前列表状态和项目类型执行不同操作
switch (mState) {
case NOTE_LIST:
if (item.getType() == Notes.TYPE_FOLDER
@ -917,6 +1175,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
/**
*
*
* 便
*
*/
private void startQueryDestinationFolders() {
String selection = NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>? AND " + NoteColumns.ID + "<>?";
selection = (mState == ListEditState.NOTE_LIST) ? selection:
@ -935,6 +1199,18 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
NoteColumns.MODIFIED_DATE + " DESC");
}
/**
*
*
* - 便便
* -
*
* @param parent
* @param view
* @param position
* @param id ID
* @return false
*/
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (view instanceof NotesListItem) {
mFocusNoteDataItem = ((NotesListItem) view).getItemData();

@ -31,18 +31,39 @@ import java.util.HashSet;
import java.util.Iterator;
/**
* NotesListAdapter - 便
* CursorAdapter便
* 便
*
*
* - NotesListItem
* -
* - 便
* - ID
* -
*/
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;
private static final String TAG = "NotesListAdapter"; // 日志标签
private Context mContext; // 上下文环境
private HashMap<Integer, Boolean> mSelectedIndex; // 记录选中项目的位置映射
private int mNotesCount; // 普通便签的数量
private boolean mChoiceMode; // 是否处于多选模式
/**
* AppWidgetAttribute -
* ID便
*/
public static class AppWidgetAttribute {
public int widgetId;
public int widgetType;
public int widgetId; // 小部件ID
public int widgetType; // 小部件类型
};
/**
* - 便
*
* @param context
*/
public NotesListAdapter(Context context) {
super(context, null);
mSelectedIndex = new HashMap<Integer, Boolean>();
@ -50,11 +71,26 @@ public class NotesListAdapter extends CursorAdapter {
mNotesCount = 0;
}
/**
* - NotesListItem
* NotesListItem
* @param context
* @param cursor
* @param parent
* @return
*/
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new NotesListItem(context);
}
/**
* - NotesListItem
* NoteItemDataNotesListItem
* @param view
* @param context
* @param cursor
*/
@Override
public void bindView(View view, Context context, Cursor cursor) {
if (view instanceof NotesListItem) {
@ -64,20 +100,41 @@ public class NotesListAdapter extends CursorAdapter {
}
}
/**
* -
*
* @param position
* @param checked
*/
public void setCheckedItem(final int position, final boolean checked) {
mSelectedIndex.put(position, checked);
notifyDataSetChanged();
}
/**
*
*
* @return truefalse
*/
public boolean isInChoiceMode() {
return mChoiceMode;
}
/**
* -
*
* @param mode truefalse
*/
public void setChoiceMode(boolean mode) {
mSelectedIndex.clear();
mChoiceMode = mode;
}
/**
* / - 便
* 便
* @param checked truefalse
*/
public void selectAll(boolean checked) {
Cursor cursor = getCursor();
for (int i = 0; i < getCount(); i++) {
@ -89,6 +146,11 @@ public class NotesListAdapter extends CursorAdapter {
}
}
/**
* ID
* IDID
* @return ID
*/
public HashSet<Long> getSelectedItemIds() {
HashSet<Long> itemSet = new HashSet<Long>();
for (Integer position : mSelectedIndex.keySet()) {
@ -105,6 +167,11 @@ public class NotesListAdapter extends CursorAdapter {
return itemSet;
}
/**
*
* ID
* @return null
*/
public HashSet<AppWidgetAttribute> getSelectedWidget() {
HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>();
for (Integer position : mSelectedIndex.keySet()) {
@ -128,6 +195,11 @@ public class NotesListAdapter extends CursorAdapter {
return itemSet;
}
/**
*
*
* @return
*/
public int getSelectedCount() {
Collection<Boolean> values = mSelectedIndex.values();
if (null == values) {
@ -143,11 +215,22 @@ public class NotesListAdapter extends CursorAdapter {
return count;
}
/**
*
* 便
* @return true便false
*/
public boolean isAllSelected() {
int checkedCount = getSelectedCount();
return (checkedCount != 0 && checkedCount == mNotesCount);
}
/**
*
*
* @param position
* @return truefalse
*/
public boolean isSelectedItem(final int position) {
if (null == mSelectedIndex.get(position)) {
return false;
@ -155,18 +238,31 @@ public class NotesListAdapter extends CursorAdapter {
return mSelectedIndex.get(position);
}
/**
* - 便
* 便
*/
@Override
protected void onContentChanged() {
super.onContentChanged();
calcNotesCount();
}
/**
* -
* 便
* @param cursor
*/
@Override
public void changeCursor(Cursor cursor) {
super.changeCursor(cursor);
calcNotesCount();
}
/**
* 便 - 便
* 便
*/
private void calcNotesCount() {
mNotesCount = 0;
for (int i = 0; i < getCount(); i++) {

@ -30,14 +30,32 @@ import net.micode.notes.tool.DataUtils;
import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
/**
* NotesListItem - 便
* LinearLayout便便
* 便便便UI
*
*
*
* - 便便UI
* -
* - 便
* - 便ID
* - 便
*/
public class NotesListItem extends LinearLayout {
private ImageView mAlert;
private TextView mTitle;
private TextView mTime;
private TextView mCallName;
private NoteItemData mItemData;
private CheckBox mCheckBox;
private ImageView mAlert; // 提醒图标,显示便签的提醒状态
private TextView mTitle; // 便签标题,显示便签的核心内容
private TextView mTime; // 时间文本,显示便签的修改时间
private TextView mCallName; // 通话记录名称,仅用于通话记录便签
private NoteItemData mItemData; // 当前列表项绑定的便签数据
private CheckBox mCheckBox; // 复选框,用于多选模式
/**
* - 便
* UI
* @param context
*/
public NotesListItem(Context context) {
super(context);
inflate(context, R.layout.note_item, this);
@ -48,7 +66,17 @@ public class NotesListItem extends LinearLayout {
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
}
/**
* 便
* 便
* 便便
* @param context
* @param data 便
* @param choiceMode
* @param checked
*/
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);
@ -57,6 +85,8 @@ public class NotesListItem extends LinearLayout {
}
mItemData = data;
// 处理通话记录文件夹的特殊显示
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
mCallName.setVisibility(View.GONE);
mAlert.setVisibility(View.VISIBLE);
@ -64,7 +94,9 @@ public class NotesListItem extends LinearLayout {
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) {
}
// 处理通话记录便签的特殊显示
else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) {
mCallName.setVisibility(View.VISIBLE);
mCallName.setText(data.getCallName());
mTitle.setTextAppearance(context,R.style.TextAppearanceSecondaryItem);
@ -75,7 +107,9 @@ public class NotesListItem extends LinearLayout {
} else {
mAlert.setVisibility(View.GONE);
}
} else {
}
// 处理普通便签和文件夹的显示
else {
mCallName.setVisibility(View.GONE);
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);
@ -94,13 +128,24 @@ public class NotesListItem extends LinearLayout {
}
}
}
// 设置便签的修改时间(相对时间格式)
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));
// 设置背景样式
setBackground(data);
}
/**
*
* 便ID
* 便使便
* @param data 便ID
*/
private void setBackground(NoteItemData data) {
int id = data.getBgColorId();
// 为普通便签设置背景
if (data.getType() == Notes.TYPE_NOTE) {
if (data.isSingle() || data.isOneFollowingFolder()) {
setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id));
@ -111,11 +156,18 @@ public class NotesListItem extends LinearLayout {
} else {
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id));
}
} else {
}
// 为文件夹设置背景
else {
setBackgroundResource(NoteItemBgResources.getFolderBgRes());
}
}
/**
* 便
* NoteItemData便
* @return 便
*/
public NoteItemData getItemData() {
return mItemData;
}

@ -48,27 +48,48 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.gtask.remote.GTaskSyncService;
/**
* NotesPreferenceActivity - 便
* PreferenceActivity
* Google
* 广UI
*
*
* - Google
* -
* -
* -
*/
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;
private boolean mHasAddedAccount;
private PreferenceCategory mAccountCategory; // 账户设置分类
private GTaskReceiver mReceiver; // Google任务同步广播接收器
private Account[] mOriAccounts; // 原始账户列表
private boolean mHasAddedAccount; // 是否已添加新账户标记
/**
* Activity
* 广
*
* @param icicle
*/
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
@ -88,6 +109,11 @@ public class NotesPreferenceActivity extends PreferenceActivity {
getListView().addHeaderView(header, null, true);
}
/**
* Activity
*
* UI
*/
@Override
protected void onResume() {
super.onResume();
@ -116,6 +142,10 @@ public class NotesPreferenceActivity extends PreferenceActivity {
refreshUI();
}
/**
* Activity
* 广
*/
@Override
protected void onDestroy() {
if (mReceiver != null) {
@ -124,6 +154,11 @@ public class NotesPreferenceActivity extends PreferenceActivity {
super.onDestroy();
}
/**
*
*
*
*/
private void loadAccountPreference() {
mAccountCategory.removeAll();
@ -133,16 +168,17 @@ public class NotesPreferenceActivity extends PreferenceActivity {
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.makeText(NotesPreferenceActivity.this,
R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT)
.show();
@ -154,12 +190,18 @@ public class NotesPreferenceActivity extends PreferenceActivity {
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) {
@ -167,6 +209,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
});
} else {
// 未同步,显示立即同步按钮
syncButton.setText(getString(R.string.preferences_button_sync_immediately));
syncButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
@ -174,9 +217,10 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
});
}
// 根据是否已设置账户启用或禁用同步按钮
syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this)));
// set last sync time
// 设置最后同步时间或同步进度
if (GTaskSyncService.isSyncing()) {
lastSyncTimeView.setText(GTaskSyncService.getProgressString());
lastSyncTimeView.setVisibility(View.VISIBLE);
@ -193,14 +237,24 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
}
/**
*
* UI
*/
private void refreshUI() {
loadAccountPreference();
loadSyncButton();
}
/**
*
* Google
*
*/
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));
@ -213,9 +267,11 @@ public class NotesPreferenceActivity extends PreferenceActivity {
Account[] accounts = getGoogleAccounts();
String defAccount = getSyncAccountName(this);
// 保存当前账户列表和状态
mOriAccounts = accounts;
mHasAddedAccount = false;
// 如果有可用账户,显示单选列表
if (accounts.length > 0) {
CharSequence[] items = new CharSequence[accounts.length];
final CharSequence[] itemMapping = items;
@ -230,6 +286,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
dialogBuilder.setSingleChoiceItems(items, checkedItem,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// 设置选择的账户并刷新UI
setSyncAccount(itemMapping[which].toString());
dialog.dismiss();
refreshUI();
@ -237,10 +294,12 @@ public class NotesPreferenceActivity extends PreferenceActivity {
});
}
// 添加新账户视图
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;
@ -254,9 +313,15 @@ public class NotesPreferenceActivity extends PreferenceActivity {
});
}
/**
*
*
*
*/
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,
@ -265,6 +330,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
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),
@ -273,21 +339,35 @@ public class NotesPreferenceActivity extends PreferenceActivity {
dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
// 更改账户
showSelectAccountAlertDialog();
} else if (which == 1) {
// 删除账户
removeSyncAccount();
refreshUI();
}
// which == 2 为取消操作,不做处理
}
});
dialogBuilder.show();
}
/**
* Google
* AccountManagerGoogle
* @return Google
*/
private Account[] getGoogleAccounts() {
AccountManager accountManager = AccountManager.get(this);
return accountManager.getAccountsByType("com.google");
}
/**
*
*
* 线便Google
* @param account Google
*/
private void setSyncAccount(String account) {
if (!getSyncAccountName(this).equals(account)) {
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
@ -318,6 +398,11 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
}
/**
*
*
* 线便Google
*/
private void removeSyncAccount() {
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
@ -340,12 +425,24 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}).start();
}
/**
*
* Google
* @param context
* @return
*/
public static String getSyncAccountName(Context context) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
Context.MODE_PRIVATE);
return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
}
/**
*
*
* @param context
* @param time
*/
public static void setLastSyncTime(Context context, long time) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
Context.MODE_PRIVATE);
@ -354,12 +451,22 @@ public class NotesPreferenceActivity extends PreferenceActivity {
editor.commit();
}
/**
*
*
* @param context
* @return 0
*/
public static long getLastSyncTime(Context context) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
Context.MODE_PRIVATE);
return settings.getLong(PREFERENCE_LAST_SYNC_TIME, 0);
}
/**
* Google广
* Google广
*/
private class GTaskReceiver extends BroadcastReceiver {
@Override
@ -374,6 +481,12 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
}
/**
*
* Home便
* @param item
* @return
*/
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:

@ -32,19 +32,42 @@ import net.micode.notes.tool.ResourceParser;
import net.micode.notes.ui.NoteEditActivity;
import net.micode.notes.ui.NotesListActivity;
/**
* NoteWidgetProvider - 便
* AppWidgetProvider便
* 便
*
*
*
* -
* - 便
* -
* -
* -
*/
public abstract class NoteWidgetProvider extends AppWidgetProvider {
/** 数据库查询的投影列用于获取便签的ID、背景色ID和内容摘要 */
public static final String [] PROJECTION = new String [] {
NoteColumns.ID,
NoteColumns.BG_COLOR_ID,
NoteColumns.SNIPPET
};
/** 投影列索引 - 便签ID */
public static final int COLUMN_ID = 0;
/** 投影列索引 - 背景色ID */
public static final int COLUMN_BG_COLOR_ID = 1;
/** 投影列索引 - 内容摘要 */
public static final int COLUMN_SNIPPET = 2;
private static final String TAG = "NoteWidgetProvider";
private static final String TAG = "NoteWidgetProvider"; // 日志标签
/**
* -
* 便ID
* @param context
* @param appWidgetIds ID
*/
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
ContentValues values = new ContentValues();
@ -57,6 +80,13 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
}
}
/**
* 便
* ID便便
* @param context
* @param widgetId ID
* @return 便
*/
private Cursor getNoteWidgetInfo(Context context, int widgetId) {
return context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
PROJECTION,
@ -65,10 +95,25 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
null);
}
/**
* -
* 使
* @param context
* @param appWidgetManager
* @param appWidgetIds ID
*/
protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
update(context, appWidgetManager, appWidgetIds, false);
}
/**
* -
*
* @param context
* @param appWidgetManager
* @param appWidgetIds ID
* @param privacyMode
*/
private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds,
boolean privacyMode) {
for (int i = 0; i < appWidgetIds.length; i++) {
@ -124,9 +169,25 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
}
}
/**
* ID -
* IDID
* @param bgId ID
* @return ID
*/
protected abstract int getBgResourceId(int bgId);
/**
* ID -
* ID
* @return ID
*/
protected abstract int getLayoutId();
/**
* -
*
* @return
*/
protected abstract int getWidgetType();
}

@ -24,22 +24,50 @@ import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
/**
* NoteWidgetProvider_2x - 2x便
* NoteWidgetProvider2x便
* 2x
*/
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
/**
* - 2x
* onUpdateupdate
* @param context
* @param appWidgetManager
* @param appWidgetIds ID
*/
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds);
}
/**
* ID - 2x
* 2xID
* @return 2xID
*/
@Override
protected int getLayoutId() {
return R.layout.widget_2x;
}
/**
* ID - 2x
* ID2xID
* @param bgId ID
* @return 2xID
*/
@Override
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
}
/**
* - 2x
* 2x
* @return 2x
*/
@Override
protected int getWidgetType() {
return Notes.TYPE_WIDGET_2X;

@ -24,21 +24,44 @@ import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
/**
* 4x便
* NoteWidgetProvider4x
*/
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
/**
* update
* @param context
* @param appWidgetManager
* @param appWidgetIds ID
*/
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds);
}
/**
* 4xID
* @return 4xID
*/
protected int getLayoutId() {
return R.layout.widget_4x;
}
/**
* ID4xID
* @param bgId ID
* @return 4xID
*/
@Override
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId);
}
/**
* 4x
* @return 4xNotes.TYPE_WIDGET_4X
*/
@Override
protected int getWidgetType() {
return Notes.TYPE_WIDGET_4X;

Loading…
Cancel
Save