WorkingNote注释

ice
karlsilver 2 months ago
parent 828603b9e9
commit 4082ffef9a

@ -31,37 +31,40 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.Notes.TextNote;
import net.micode.notes.tool.ResourceParser.NoteBgResources;
/**
* WorkingNote 便便
*/
public class WorkingNote {
// Note for the working note
// 便签对象,用于管理便签的具体数据
private Note mNote;
// Note Id
// 便签的 ID
private long mNoteId;
// Note content
// 便签的内容
private String mContent;
// Note mode
// 便签的模式
private int mMode;
// 便签的提醒日期
private long mAlertDate;
// 便签的修改日期
private long mModifiedDate;
// 便签的背景颜色 ID
private int mBgColorId;
// 便签小部件的 ID
private int mWidgetId;
// 便签小部件的类型
private int mWidgetType;
// 便签所属文件夹的 ID
private long mFolderId;
// 上下文对象,用于访问系统服务和资源
private Context mContext;
// 日志标签,用于在日志中标识该类的信息
private static final String TAG = "WorkingNote";
// 标记便签是否被删除
private boolean mIsDeleted;
// 便签设置更改监听器,用于监听便签设置的变化
private NoteSettingChangedListener mNoteSettingStatusListener;
// 用于查询便签数据的投影,指定需要查询的列
public static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID,
DataColumns.CONTENT,
@ -72,6 +75,7 @@ public class WorkingNote {
DataColumns.DATA4,
};
// 用于查询便签信息的投影,指定需要查询的列
public static final String[] NOTE_PROJECTION = new String[] {
NoteColumns.PARENT_ID,
NoteColumns.ALERTED_DATE,
@ -81,27 +85,32 @@ public class WorkingNote {
NoteColumns.MODIFIED_DATE
};
// DATA_PROJECTION 中 ID 列的索引
private static final int DATA_ID_COLUMN = 0;
// DATA_PROJECTION 中内容列的索引
private static final int DATA_CONTENT_COLUMN = 1;
// DATA_PROJECTION 中 MIME 类型列的索引
private static final int DATA_MIME_TYPE_COLUMN = 2;
// DATA_PROJECTION 中模式列的索引
private static final int DATA_MODE_COLUMN = 3;
// NOTE_PROJECTION 中父文件夹 ID 列的索引
private static final int NOTE_PARENT_ID_COLUMN = 0;
// NOTE_PROJECTION 中提醒日期列的索引
private static final int NOTE_ALERTED_DATE_COLUMN = 1;
// NOTE_PROJECTION 中背景颜色 ID 列的索引
private static final int NOTE_BG_COLOR_ID_COLUMN = 2;
// NOTE_PROJECTION 中小部件 ID 列的索引
private static final int NOTE_WIDGET_ID_COLUMN = 3;
// NOTE_PROJECTION 中小部件类型列的索引
private static final int NOTE_WIDGET_TYPE_COLUMN = 4;
// NOTE_PROJECTION 中修改日期列的索引
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
// New note construct
/**
* 便
* @param context
* @param folderId 便 ID
*/
private WorkingNote(Context context, long folderId) {
mContext = context;
mAlertDate = 0;
@ -114,7 +123,12 @@ public class WorkingNote {
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
}
// Existing note construct
/**
* 便
* @param context
* @param noteId 便 ID
* @param folderId 便 ID
*/
private WorkingNote(Context context, long noteId, long folderId) {
mContext = context;
mNoteId = noteId;
@ -124,29 +138,45 @@ public class WorkingNote {
loadNote();
}
/**
* 便便便
*/
private void loadNote() {
// 查询便签的基本信息
Cursor cursor = mContext.getContentResolver().query(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null,
null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
// 获取便签所属文件夹的 ID
mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);
// 获取便签的背景颜色 ID
mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN);
// 获取便签小部件的 ID
mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN);
// 获取便签小部件的类型
mWidgetType = cursor.getInt(NOTE_WIDGET_TYPE_COLUMN);
// 获取便签的提醒日期
mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN);
// 获取便签的修改日期
mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
}
cursor.close();
} else {
// 若未查询到便签信息,记录错误日志并抛出异常
Log.e(TAG, "No note with id:" + mNoteId);
throw new IllegalArgumentException("Unable to find note with id " + mNoteId);
}
// 加载便签的数据
loadNoteData();
}
/**
* 便便
*/
private void loadNoteData() {
// 查询便签的数据
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
DataColumns.NOTE_ID + "=?", new String[] {
String.valueOf(mNoteId)
@ -155,25 +185,40 @@ public class WorkingNote {
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
// 获取便签数据的 MIME 类型
String type = cursor.getString(DATA_MIME_TYPE_COLUMN);
if (DataConstants.NOTE.equals(type)) {
// 若为文本便签类型,获取便签的内容和模式
mContent = cursor.getString(DATA_CONTENT_COLUMN);
mMode = cursor.getInt(DATA_MODE_COLUMN);
// 设置文本数据的 ID
mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN));
} else if (DataConstants.CALL_NOTE.equals(type)) {
// 若为通话便签类型,设置通话数据的 ID
mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN));
} else {
// 若为其他类型,记录日志
Log.d(TAG, "Wrong note type with type:" + type);
}
} while (cursor.moveToNext());
}
cursor.close();
} else {
// 若未查询到便签数据,记录错误日志并抛出异常
Log.e(TAG, "No data with id:" + mNoteId);
throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId);
}
}
/**
* 便
* @param context
* @param folderId 便 ID
* @param widgetId 便 ID
* @param widgetType 便
* @param defaultBgColorId 便 ID
* @return 便
*/
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
int widgetType, int defaultBgColorId) {
WorkingNote note = new WorkingNote(context, folderId);
@ -183,23 +228,35 @@ public class WorkingNote {
return note;
}
/**
* 便
* @param context
* @param id 便 ID
* @return 便
*/
public static WorkingNote load(Context context, long id) {
return new WorkingNote(context, id, 0);
}
/**
* 便
* @return true false
*/
public synchronized boolean saveNote() {
if (isWorthSaving()) {
if (!existInDatabase()) {
// 若便签不存在于数据库中,创建新的便签 ID
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
// 若创建失败,记录错误日志并返回 false
Log.e(TAG, "Create new note fail with id:" + mNoteId);
return false;
}
}
// 同步便签信息到数据库
mNote.syncNote(mContext, mNoteId);
/**
* Update widget content if there exist any widget of this note
* 便
*/
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE
@ -212,10 +269,18 @@ public class WorkingNote {
}
}
/**
* 便
* @return true false
*/
public boolean existInDatabase() {
return mNoteId > 0;
}
/**
* 便
* @return true false
*/
private boolean isWorthSaving() {
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|| (existInDatabase() && !mNote.isLocalModified())) {
@ -225,10 +290,19 @@ public class WorkingNote {
}
}
/**
* 便
* @param l
*/
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
mNoteSettingStatusListener = l;
}
/**
* 便
* @param date
* @param set
*/
public void setAlertDate(long date, boolean set) {
if (date != mAlertDate) {
mAlertDate = date;
@ -239,6 +313,10 @@ public class WorkingNote {
}
}
/**
* 便
* @param mark
*/
public void markDeleted(boolean mark) {
mIsDeleted = mark;
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
@ -247,6 +325,10 @@ public class WorkingNote {
}
}
/**
* 便 ID
* @param id ID
*/
public void setBgColorId(int id) {
if (id != mBgColorId) {
mBgColorId = id;
@ -257,6 +339,10 @@ public class WorkingNote {
}
}
/**
* 便
* @param mode
*/
public void setCheckListMode(int mode) {
if (mMode != mode) {
if (mNoteSettingStatusListener != null) {
@ -267,6 +353,10 @@ public class WorkingNote {
}
}
/**
* 便
* @param type
*/
public void setWidgetType(int type) {
if (type != mWidgetType) {
mWidgetType = type;
@ -274,6 +364,10 @@ public class WorkingNote {
}
}
/**
* 便 ID
* @param id ID
*/
public void setWidgetId(int id) {
if (id != mWidgetId) {
mWidgetId = id;
@ -281,6 +375,10 @@ public class WorkingNote {
}
}
/**
* 便
* @param text
*/
public void setWorkingText(String text) {
if (!TextUtils.equals(mContent, text)) {
mContent = text;
@ -288,80 +386,138 @@ public class WorkingNote {
}
}
/**
* 便便
* @param phoneNumber
* @param callDate
*/
public void convertToCallNote(String phoneNumber, long callDate) {
mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate));
mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber);
mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER));
}
/**
* 便
* @return true false
*/
public boolean hasClockAlert() {
return (mAlertDate > 0 ? true : false);
}
/**
* 便
* @return 便
*/
public String getContent() {
return mContent;
}
/**
* 便
* @return 便
*/
public long getAlertDate() {
return mAlertDate;
}
/**
* 便
* @return 便
*/
public long getModifiedDate() {
return mModifiedDate;
}
/**
* 便 ID
* @return 便 ID
*/
public int getBgColorResId() {
return NoteBgResources.getNoteBgResource(mBgColorId);
}
/**
* 便 ID
* @return 便 ID
*/
public int getBgColorId() {
return mBgColorId;
}
/**
* 便 ID
* @return 便 ID
*/
public int getTitleBgResId() {
return NoteBgResources.getNoteTitleBgResource(mBgColorId);
}
/**
* 便
* @return 便
*/
public int getCheckListMode() {
return mMode;
}
/**
* 便 ID
* @return 便 ID
*/
public long getNoteId() {
return mNoteId;
}
/**
* 便 ID
* @return 便 ID
*/
public long getFolderId() {
return mFolderId;
}
/**
* 便 ID
* @return 便 ID
*/
public int getWidgetId() {
return mWidgetId;
}
/**
* 便
* @return 便
*/
public int getWidgetType() {
return mWidgetType;
}
/**
* 便便
*/
public interface NoteSettingChangedListener {
/**
* Called when the background color of current note has just changed
* 便
*/
void onBackgroundColorChanged();
/**
* Called when user set clock
*
* @param date
* @param set
*/
void onClockAlertChanged(long date, boolean set);
/**
* Call when user create note from widget
* 便
*/
void onWidgetChanged();
/**
* Call when switch between check list mode and normal mode
* @param oldMode is previous mode before change
* @param newMode is new mode
* 便
* @param oldMode
* @param newMode
*/
void onCheckListModeChanged(int oldMode, int newMode);
}

Loading…
Cancel
Save