对部分类进行了注释 #5

Merged
pvexk5qol merged 4 commits from caoweiqiong_branch into master 3 weeks 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>();

@ -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;
}

@ -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;
}

@ -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(

@ -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