diff --git a/app/src/main/java/net/micode/notes/data/Contact.java b/app/src/main/java/net/micode/notes/data/Contact.java index d97ac5d..211de96 100644 --- a/app/src/main/java/net/micode/notes/data/Contact.java +++ b/app/src/main/java/net/micode/notes/data/Contact.java @@ -25,6 +25,9 @@ import android.util.Log; import java.util.HashMap; +/** + * 联系人 + */ public class Contact { private static HashMap sContactCache; private static final String TAG = "Contact"; @@ -36,17 +39,21 @@ public class Contact { + " FROM phone_lookup" + " WHERE min_match = '+')"; + /** + * 获取联系人 + */ public static String getContact(Context context, String phoneNumber) { if(sContactCache == null) { sContactCache = new HashMap(); } - + // 查找HashMap中是否已有phoneNumber信息 if(sContactCache.containsKey(phoneNumber)) { return sContactCache.get(phoneNumber); } String selection = CALLER_ID_SELECTION.replace("+", PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); + // 查找数据库中phoneNumber的信息 Cursor cursor = context.getContentResolver().query( Data.CONTENT_URI, new String [] { Phone.DISPLAY_NAME }, @@ -55,6 +62,7 @@ public class Contact { null); if (cursor != null && cursor.moveToFirst()) { + // 找到相关信息 try { String name = cursor.getString(0); sContactCache.put(phoneNumber, name); diff --git a/app/src/main/java/net/micode/notes/data/Notes.java b/app/src/main/java/net/micode/notes/data/Notes.java index f240604..92d2f23 100644 --- a/app/src/main/java/net/micode/notes/data/Notes.java +++ b/app/src/main/java/net/micode/notes/data/Notes.java @@ -165,7 +165,7 @@ public class Notes { *

Type : INTEGER (long)

*/ public static final String VERSION = "version"; - } + } // 这些常量主要是定义便签的属性的 public interface DataColumns { /** diff --git a/app/src/main/java/net/micode/notes/data/NotesProvider.java b/app/src/main/java/net/micode/notes/data/NotesProvider.java index edb0a60..540f9db 100644 --- a/app/src/main/java/net/micode/notes/data/NotesProvider.java +++ b/app/src/main/java/net/micode/notes/data/NotesProvider.java @@ -292,7 +292,7 @@ public class NotesProvider extends ContentProvider { } sql.append(selectString); } - + // execSQL()方法可以执行insert、delete、update和CREATE TABLE之类有更改行为的SQL语句 mHelper.getWritableDatabase().execSQL(sql.toString()); } diff --git a/app/src/main/java/net/micode/notes/gtask/data/Node.java b/app/src/main/java/net/micode/notes/gtask/data/Node.java index 63950e0..040db8c 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/Node.java +++ b/app/src/main/java/net/micode/notes/gtask/data/Node.java @@ -20,6 +20,9 @@ import android.database.Cursor; import org.json.JSONObject; +/** + * 同步操作的基础数据类型,定义了相关指示同步操作的常量 + */ public abstract class Node { public static final int SYNC_ACTION_NONE = 0; diff --git a/app/src/main/java/net/micode/notes/model/Note.java b/app/src/main/java/net/micode/notes/model/Note.java index 6706cf6..53fff0a 100644 --- a/app/src/main/java/net/micode/notes/model/Note.java +++ b/app/src/main/java/net/micode/notes/model/Note.java @@ -49,9 +49,9 @@ public class Note { values.put(NoteColumns.MODIFIED_DATE, createdTime); values.put(NoteColumns.TYPE, Notes.TYPE_NOTE); values.put(NoteColumns.LOCAL_MODIFIED, 1); - values.put(NoteColumns.PARENT_ID, folderId); + values.put(NoteColumns.PARENT_ID, folderId); // 将数据写入数据库表格 Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values); - + //ContentResolver()主要是实现外部应用对ContentProvider中的数据进行添加、删除、修改和查询操作 long noteId = 0; try { noteId = Long.valueOf(uri.getPathSegments().get(1)); @@ -96,6 +96,10 @@ public class Note { mNoteData.setCallData(key, value); } + /** + * 判断是否是本地修改 + * @return boolean + */ public boolean isLocalModified() { return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified(); } @@ -131,6 +135,7 @@ public class Note { } private class NoteData { + // 定义一个基本的便签内容的数据类,主要包含文本数据和电话号码数据 private long mTextDataId; private ContentValues mTextDataValues; diff --git a/app/src/main/java/net/micode/notes/model/WorkingNote.java b/app/src/main/java/net/micode/notes/model/WorkingNote.java index be081e4..4aeb154 100644 --- a/app/src/main/java/net/micode/notes/model/WorkingNote.java +++ b/app/src/main/java/net/micode/notes/model/WorkingNote.java @@ -189,7 +189,9 @@ public class WorkingNote { public synchronized boolean saveNote() { if (isWorthSaving()) { + // 是否值得保存 if (!existInDatabase()) { + // 是否存在数据库中 if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) { Log.e(TAG, "Create new note fail with id:" + mNoteId); return false; diff --git a/app/src/main/java/net/micode/notes/tool/ResourceParser.java b/app/src/main/java/net/micode/notes/tool/ResourceParser.java index 1ad3ad6..b7b1aed 100644 --- a/app/src/main/java/net/micode/notes/tool/ResourceParser.java +++ b/app/src/main/java/net/micode/notes/tool/ResourceParser.java @@ -162,6 +162,9 @@ public class ResourceParser { R.style.TextAppearanceSuper }; + /** + * 这里有一个容错的函数,防止输入的id大于资源总量,若如此,则自动返回默认的设置结果 + */ public static int getTexAppearanceResource(int id) { /** * HACKME: Fix bug of store the resource id in shared preference. diff --git a/app/src/main/java/net/micode/notes/ui/NoteEditText.java b/app/src/main/java/net/micode/notes/ui/NoteEditText.java index 2afe2a8..b884b10 100644 --- a/app/src/main/java/net/micode/notes/ui/NoteEditText.java +++ b/app/src/main/java/net/micode/notes/ui/NoteEditText.java @@ -37,6 +37,9 @@ import net.micode.notes.R; import java.util.HashMap; import java.util.Map; +/** + * 设置便签设置文本框 + */ public class NoteEditText extends EditText { private static final String TAG = "NoteEditText"; private int mIndex; @@ -46,6 +49,7 @@ public class NoteEditText extends EditText { private static final String SCHEME_HTTP = "http:" ; private static final String SCHEME_EMAIL = "mailto:" ; + // 建立一个字符和整数的hash表,用于链接电话,网站,还有邮箱 private static final Map sSchemaActionResMap = new HashMap(); static { sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel); @@ -111,9 +115,11 @@ public class NoteEditText extends EditText { x += getScrollX(); y += getScrollY(); + // 用布局控件layout根据x,y的新值设置新的位置 Layout layout = getLayout(); int line = layout.getLineForVertical(y); int off = layout.getOffsetForHorizontal(line, x); + // 更新光标新的位置 Selection.setSelection(getText(), off); break; } @@ -167,6 +173,9 @@ public class NoteEditText extends EditText { return super.onKeyUp(keyCode, event); } + /** + * 当焦点发生变化时,会自动调用该方法来处理焦点改变的事件 + */ @Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { if (mOnTextViewChangeListener != null) { @@ -179,12 +188,17 @@ public class NoteEditText extends EditText { super.onFocusChanged(focused, direction, previouslyFocusedRect); } + /** + * 生成上下文菜单 + */ @Override protected void onCreateContextMenu(ContextMenu menu) { if (getText() instanceof Spanned) { + // 获取文本开始和结尾位置 int selStart = getSelectionStart(); int selEnd = getSelectionEnd(); + // 获取开始到结尾的最大值和最小值 int min = Math.min(selStart, selEnd); int max = Math.max(selStart, selEnd); @@ -201,7 +215,7 @@ 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) { @@ -212,6 +226,7 @@ public class NoteEditText extends EditText { }); } } + // 继续执行父类的其他菜单创建的事件 super.onCreateContextMenu(menu); } } diff --git a/app/src/main/java/net/micode/notes/ui/NotesListActivity.java b/app/src/main/java/net/micode/notes/ui/NotesListActivity.java index 6db3761..832a07d 100644 --- a/app/src/main/java/net/micode/notes/ui/NotesListActivity.java +++ b/app/src/main/java/net/micode/notes/ui/NotesListActivity.java @@ -209,11 +209,15 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt startAsyncNotesListQuery(); } + /** + * 初始化资源 + */ private void initResources() { - mContentResolver = this.getContentResolver(); + mContentResolver = this.getContentResolver(); // 获取应用程序的数据,得到类似数据表的东西 mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver()); mCurrentFolderId = Notes.ID_ROOT_FOLDER; - mNotesListView = (ListView) findViewById(R.id.notes_list); + // findViewById 是安卓编程的定位函数,主要是引用.R文件里的引用名 + mNotesListView = (ListView) findViewById(R.id.notes_list); // 绑定XML中的ListView,作为Item的容器 mNotesListView.addFooterView(LayoutInflater.from(this).inflate(R.layout.note_list_footer, null), null, false); mNotesListView.setOnItemClickListener(new OnListItemClickListener()); @@ -269,6 +273,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt return true; } + /** + * 更新菜单 + */ private void updateMenu() { int selectedCount = mNotesListAdapter.getSelectedCount(); // Update dropdown menu @@ -805,6 +812,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt return true; } + /** + * 实现将便签导出到文本功能 + */ private void exportNoteToText() { final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this); new AsyncTask() { @@ -857,6 +867,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt from.startActivityIfNeeded(intent, -1); } + /** + * 实现对便签列表项的点击事件(短按) + */ private class OnListItemClickListener implements OnItemClickListener { public void onItemClick(AdapterView parent, View view, int position, long id) { @@ -898,6 +911,9 @@ 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: @@ -916,6 +932,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt NoteColumns.MODIFIED_DATE + " DESC"); } + /** + * 如果长按的是便签,则通过ActionMode菜单实现;如果长按的是文件夹,则通过ContextMenu菜单实现; + * 具体ActionMOde菜单和ContextMenu菜单的详细见精度笔记 + */ public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { if (view instanceof NotesListItem) { mFocusNoteDataItem = ((NotesListItem) view).getItemData();