add code comment

main
Peanut_Ono 1 year ago
parent 44ecf90c71
commit d75df90f64

@ -25,6 +25,9 @@ import android.util.Log;
import java.util.HashMap;
/**
*
*/
public class Contact {
private static HashMap<String, String> 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<String, String>();
}
// 查找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);

@ -165,7 +165,7 @@ public class Notes {
* <P> Type : INTEGER (long) </P>
*/
public static final String VERSION = "version";
}
} // 这些常量主要是定义便签的属性的
public interface DataColumns {
/**

@ -292,7 +292,7 @@ public class NotesProvider extends ContentProvider {
}
sql.append(selectString);
}
// execSQL()方法可以执行insert、delete、update和CREATE TABLE之类有更改行为的SQL语句
mHelper.getWritableDatabase().execSQL(sql.toString());
}

@ -20,6 +20,9 @@ import android.database.Cursor;
import org.json.JSONObject;
/**
*
*/
public abstract class Node {
public static final int SYNC_ACTION_NONE = 0;

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

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

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

@ -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<String, Integer> sSchemaActionResMap = new HashMap<String, Integer>();
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);
}
}

@ -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<Void, Void, Integer>() {
@ -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");
}
/**
* 便ActionModeContextMenu
* ActionMOdeContextMenu
*/
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (view instanceof NotesListItem) {
mFocusNoteDataItem = ((NotesListItem) view).getItemData();

Loading…
Cancel
Save