diff --git a/doc/精读报告/model/Note.doc b/doc/精读报告/model/Note.doc new file mode 100644 index 0000000..e340c61 --- /dev/null +++ b/doc/精读报告/model/Note.doc @@ -0,0 +1,253 @@ +/*//单个便签项 + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.micode.notes.model;//包的名称 +import android.content.ContentProviderOperation;//更新、插入、删除数据 +import android.content.ContentProviderResult;//操作结果 +import android.content.ContentUris;//用于添加和获取Uri后面的ID +import android.content.ContentValues;//存储基本数据类型数据 +import android.content.Context;//提供调用者的环境 +import android.content.OperationApplicationException;//操作数据容错 +import android.net.Uri;//远程容错 +import android.os.RemoteException;//远程容错 +import android.util.Log;//输出日志,比如说出错、警告等 + +import net.micode.notes.data.Notes;//以下5行都是对小米便签数据处理的一些数据或操作相关 +import net.micode.notes.data.Notes.CallNote; +import net.micode.notes.data.Notes.DataColumns; +import net.micode.notes.data.Notes.NoteColumns; +import net.micode.notes.data.Notes.TextNote; + +import java.util.ArrayList;//以上全是导入 + + +public class Note {//这个类是用来刻画单个Note的 + private ContentValues mNoteDiffValues;//ContentValues是用于给其他应用调用小米便签的内容的共享数据 + private NoteData mNoteData;//申明一个NoteData变量,用来记录note的一些基本信息 + private static final String TAG = "Note";//软件的名称 + /** + * Create a new note id for adding a new note to databases//创建一个新的便签id,以便把新便签加入数据库 + */ + public static synchronized long getNewNoteId(Context context, long folderId) {//获取新建便签的编号 + // Create a new note in the database + ContentValues values = new ContentValues();//在数据库中新建一个便签文件 + long createdTime = System.currentTimeMillis();//读取当前系统时间 + values.put(NoteColumns.CREATED_DATE, createdTime);//将创建时间和修改时间都更改为当前系统时间 + values.put(NoteColumns.MODIFIED_DATE, createdTime);//更改时间 + values.put(NoteColumns.TYPE, Notes.TYPE_NOTE);//便签类型 + values.put(NoteColumns.LOCAL_MODIFIED, 1);//修改标志置为1 + values.put(NoteColumns.PARENT_ID, folderId);//将数据写入数据库表格 + Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values);//外部应用对ContentProvider中的数据进行添加、删除、修改和查询操作 + + long noteId = 0;//实现外部应用对数据的插入删除等操作 + try {//异常处理 + noteId = Long.valueOf(uri.getPathSegments().get(1));//获取便签的id + } catch (NumberFormatException e) {//异常处理和提示 + Log.e(TAG, "Get note id error :" + e.toString());//获取id错误 + noteId = 0;//获取了错误的id + } + if (noteId == -1) {//块:错误ID,异常处理 + throw new IllegalStateException("Wrong note id:" + noteId);//非法状态时返回出错便签编号 + } + return noteId;//若没有异常,那么返回这个id + } + + public Note() {//定义两个变量用来存储便签的数据,一个是存储便签属性、一个是存储便签内容 + mNoteDiffValues = new ContentValues();//便签属性 + mNoteData = new NoteData();//便签内容 + } + + public void setNoteValue(String key, String value) {//设置数据库表格的标签属性数据 + mNoteDiffValues.put(key, value);//设置key值和对应的value值 + mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);//修改之后标志为1 + mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());//更新修改时间为当前系统时间 + } + + public void setTextData(String key, String value) { + mNoteData.setTextData(key, value); + }//设置数据库表格的标签文本内容的数据 + + public void setTextDataId(long id) { + mNoteData.setTextDataId(id); + }//设置文本数据的ID + + public long getTextDataId() { + return mNoteData.mTextDataId; + }//获取文本数据的id + + public void setCallDataId(long id) { + mNoteData.setCallDataId(id); + }//设置电话号码数据的ID + + public void setCallData(String key, String value) { + mNoteData.setCallData(key, value); + }//得到电话号码数据的ID + + public boolean isLocalModified() {//判断是否是本地修改 + return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified();//相较上次存在修改size()>0 + } + + public boolean syncNote(Context context, long noteId) {//判断便签是否同步 + if (noteId <= 0) {//便签ID不合法时抛出异常 + throw new IllegalArgumentException("Wrong note id:" + noteId);//抛出异常,弹出对话框错误ID并显示错误ID号 + } + + if (!isLocalModified()) {//如果本地没有发现修改,直接返回1,指示已经同步到数据库中 + return true;//返回true + } + + /** + * 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 + */ + 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();//初始化便签特征值 + + if (mNoteData.isLocalModified()//判断未同步 + && (mNoteData.pushIntoContentResolver(context, noteId) == null)) {//如果向内容接收者推送上下文失败,则返回错误 + return false;//否则已经同步成功 + } + + return true;//成功则返回true + } + + private class NoteData {//定义一个基本的便签内容的数据类,主要包含文本数据和电话号码数据 + private long mTextDataId;//文本数据id + + private ContentValues mTextDataValues;//文本数据内容 + + private long mCallDataId;//电话号码数据ID + + private ContentValues mCallDataValues;//电话号码数据内容 + + private static final String TAG = "NoteData";//初始化 + + public NoteData() {// NoteData的构造函数,初始化四个变量 + mTextDataValues = new ContentValues();//初始化一个文本数据,为了储存文本 + mCallDataValues = new ContentValues();//初始化一个电话号码数据,为了储存电话号码 + mTextDataId = 0;//初始化文本数据ID,置为0 + mCallDataId = 0;//初始化电话号码ID,置为0 + } + + boolean isLocalModified() {//下面是上述几个函数的具体实现 + return mTextDataValues.size() > 0 || mCallDataValues.size() > 0; + } + + void setTextDataId(long id) {//设定文本数据id + if(id <= 0) {// id不能小于0 + throw new IllegalArgumentException("Text data id should larger than 0");//id保证大于0 + } + mTextDataId = id;//设定电话号码id + } + + void setCallDataId(long id) {//设置电话号码对应的id + if (id <= 0) {//判断ID是否合法 + throw new IllegalArgumentException("Call data id should larger than 0");//电话号码数据ID应大于0 + } + mCallDataId = id;//设定电话数据 + } + + void setCallData(String key, String value) {//设置电话号码数据内容,并且保存修改时间 + mCallDataValues.put(key, value);//修改之后,将属性值置为1 + mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);//系统修改时间 + mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());//设置修改时间为当前系统时间 + } + + void setTextData(String key, String value) {//设置文本数据 + mTextDataValues.put(key, value);//修改后标志置为1 + mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);//设置修改时间为当前系统时间 + mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());//设置修改时间为当前系统时间 + } + + Uri pushIntoContentResolver(Context context, long noteId) {//下面函数的作用是将新的数据通过Uri的操作存储到数据库 + /** + * Check for safety + */ + if (noteId <= 0) {//保证便器的编号为正数 + throw new IllegalArgumentException("Wrong note id:" + noteId);//判断数据是否合法 + } + + ArrayList operationList = new ArrayList();//数据库操作链表 + ContentProviderOperation.Builder builder = null;//数据库的操作列表 + + if(mTextDataValues.size() > 0) {//把文本数据存入DataColumns + mTextDataValues.put(DataColumns.NOTE_ID, noteId);//设定文本数据的属性 + if (mTextDataId == 0) {//uri插入文本数据 + mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE);//把文本便签的类型填入文本数据库中的对应一行 + Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,//uri内容接收器插入文本数据库,放在Notes.CONTENT_DATA_URI的路径下 + mTextDataValues); + try {//尝试重新给它设置id + setTextDataId(Long.valueOf(uri.getPathSegments().get(1))); + } catch (NumberFormatException e) { + Log.e(TAG, "Insert new text data fail with noteId" + noteId);//插入数据失败 + mTextDataValues.clear();//把电话号码数据存入DataColumns + return null; + } + } else { + builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(//内容提供者的更新操作,因为这个uri对应的数据是已经存在的,所以不需要向上面一样新建,而是更新即可 + Notes.CONTENT_DATA_URI, mTextDataId));//语句: 将uri和id合并后,更新 + builder.withValues(mTextDataValues); + operationList.add(builder.build());//操作队列添加上内容提供者 + } + mTextDataValues.clear();//设定电话号码的属性数据 + } + + if(mCallDataValues.size() > 0) {//对于电话号码的数据也是和文本数据一样的同步处理 + mCallDataValues.put(DataColumns.NOTE_ID, noteId);//写入noteID + if (mCallDataId == 0) {//将电话号码的id设定为uri提供的id + mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE); + Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI, + mCallDataValues); + try {//异常处理 + setCallDataId(Long.valueOf(uri.getPathSegments().get(1))); + } catch (NumberFormatException e) { + Log.e(TAG, "Insert new call data fail with noteId" + noteId);//插入电话号码数据失败 + mCallDataValues.clear(); + return null; + } + } else {//当电话号码不为新建时,更新电话号码ID + builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(//内容提供者的更新操作,这个uri对应的数据是已经存在的,因此进行更新即可 + Notes.CONTENT_DATA_URI, mCallDataId)); + builder.withValues(mCallDataValues); + operationList.add(builder.build());//存储过程中的异常处理 + } + mCallDataValues.clear(); + } + + if (operationList.size() > 0) {//存储过程中如果遇到异常,通过如下进行处理 + try {//抛出远程异常,并写回日志 + ContentProviderResult[] results = context.getContentResolver().applyBatch(//Android源码中对通讯录的操作,应用端使用ContentProvider提供的applyBatch,进行批量处理通讯录的联系人入库 + Notes.AUTHORITY, operationList); + return (results == null || results.length == 0 || results[0] == null) ? null//完成后返回一个URI + : ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId); + } catch (RemoteException e) {//捕捉操作异常并写回日志 + Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));//异常日志 + return null; + } catch (OperationApplicationException e) { + Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));//异常日志 + return null; + } + } + return null; + } + } +} diff --git a/doc/精读报告/model/WorkingNote.doc b/doc/精读报告/model/WorkingNote.doc new file mode 100644 index 0000000..c12e7c7 --- /dev/null +++ b/doc/精读报告/model/WorkingNote.doc @@ -0,0 +1,368 @@ +/*//当前活动便签项 + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.micode.notes.model;//在model包中 + +import android.appwidget.AppWidgetManager;//需要调用的其他类 +import android.content.ContentUris; +import android.content.Context; +import android.database.Cursor;//游标的使用 +import android.text.TextUtils; +import android.util.Log; + +import net.micode.notes.data.Notes;//小米便签操作的整体属性 +import net.micode.notes.data.Notes.CallNote; +import net.micode.notes.data.Notes.DataColumns; +import net.micode.notes.data.Notes.DataConstants; +import net.micode.notes.data.Notes.NoteColumns; +import net.micode.notes.data.Notes.TextNote; +import net.micode.notes.tool.ResourceParser.NoteBgResources; + + +public class WorkingNote {//声明一个workingnote类 + // Note for the working note + private Note mNote;//声明一个Note类型的变量 + // Note Id + private long mNoteId;//声明便签content + // Note content + private String mContent;//声明便签mode + // Note mode + private int mMode;//是否是清单模式 + + private long mAlertDate;//设置闹钟时间 + + private long mModifiedDate;// 最后修改时间 + + private int mBgColorId;//背景颜色ID + + private int mWidgetId;//控件ID + + private int mWidgetType;//桌面挂件的格式 + + private long mFolderId;//便签文件夹ID + + private Context mContext;//当前便签的上下文 + + private static final String TAG = "WorkingNote";//声明 DATA_PROJECTION字符串数组 + + private boolean mIsDeleted;//是否应该被删除 + + private NoteSettingChangedListener mNoteSettingStatusListener;//一个用来监听设置是否有变化的接口 + + public static final String[] DATA_PROJECTION = new String[] {//声明 NOTE_PROJECTION字符串数组 + DataColumns.ID, + DataColumns.CONTENT, + DataColumns.MIME_TYPE, + DataColumns.DATA1, + DataColumns.DATA2, + DataColumns.DATA3, + DataColumns.DATA4, + }; + + public static final String[] NOTE_PROJECTION = new String[] {//保存便签自身属性的字符串数组 + NoteColumns.PARENT_ID, + NoteColumns.ALERTED_DATE, + NoteColumns.BG_COLOR_ID, + NoteColumns.WIDGET_ID, + NoteColumns.WIDGET_TYPE, + NoteColumns.MODIFIED_DATE + }; + + private static final int DATA_ID_COLUMN = 0;//规定每一个数据类型在哪一行 + + private static final int DATA_CONTENT_COLUMN = 1; + + private static final int DATA_MIME_TYPE_COLUMN = 2; + + private static final int DATA_MODE_COLUMN = 3; + + private static final int NOTE_PARENT_ID_COLUMN = 0;//以下6个常量表示便签投影的0-5列 + + private static final int NOTE_ALERTED_DATE_COLUMN = 1; + + private static final int NOTE_BG_COLOR_ID_COLUMN = 2; + + private static final int NOTE_WIDGET_ID_COLUMN = 3; + + private static final int NOTE_WIDGET_TYPE_COLUMN = 4; + + private static final int NOTE_MODIFIED_DATE_COLUMN = 5; + + // New note construct + private WorkingNote(Context context, long folderId) {//该方法初始化类里的各项变量 + mContext = context;//WorkingNote的构造函数 + mAlertDate = 0;//默认提醒日期为0 + mModifiedDate = System.currentTimeMillis();//系统现在的时间,时间的表达格式为当前计算机时间和GMT时间(格林威治时间)1970年1月1号0时0分0秒所差的毫秒数 + mFolderId = folderId;//默认最后一次修改日期为当前时间 + mNote = new Note();//加载一个已存在的便签 + mNoteId = 0;//没有提供id所以默认为0 + mIsDeleted = false; + mMode = 0; + mWidgetType = Notes.TYPE_WIDGET_INVALIDE;//默认是不可见 + } + + // Existing note construct + private WorkingNote(Context context, long noteId, long folderId) {//加载Note + mContext = context;//调用query函数找到第一个条目 + mNoteId = noteId; + mFolderId = folderId; + mIsDeleted = false; + mNote = new Note(); + loadNote();//加载便签 + } + + private void loadNote() {//加载已有的便签 + Cursor cursor = mContext.getContentResolver().query(//存在第一个条目 + ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null, + null, null); + + if (cursor != null) {//通过数据库调用query函数找到第一个条目 + if (cursor.moveToFirst()) {//如果游标移动到第一行 + mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);//存储各项信息 + mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN);//关闭cursor游标 + 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);//未能找到此note,返回异常 + throw new IllegalArgumentException("Unable to find note with id " + mNoteId);//抛出异常,找不到NoteID + } + loadNoteData();//调用方法loadNoteData,导入便签的内容。 + } + + private void loadNoteData() {//加载NoteData + Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION, + DataColumns.NOTE_ID + "=?", new String[] { + String.valueOf(mNoteId) + }, null);//判断信息是否为空 + + if (cursor != null) {//光标存在时,将光标移动到便签的起始位置 + if (cursor.moveToFirst()) {//do while循环将便签数据全部读取出来 + do { + 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); + mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN)); + } else if (DataConstants.CALL_NOTE.equals(type)) {//为电话号码类信息时 存为电话号码 + mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN));//否则,在日志中标志错误类型为note type错误 + } else {//如果类型错误,则提示异常 + Log.d(TAG, "Wrong note type with type:" + type);//再否则就是有错误 + } + } while (cursor.moveToNext());//查阅所有项,直到为空 + } + cursor.close();//查找失败时,在日志中记录错误信息为无法找到id号为mNoteId的便签 + } else {//否则记录异常日志,没有ID为mNoteId的数据 + Log.e(TAG, "No data with id:" + mNoteId);//否则记录异常日志,没有ID为mNoteId的数据 + throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId);//抛出异常 + } + } + + public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,//创建一个新便签的构造函数 + int widgetType, int defaultBgColorId) { + WorkingNote note = new WorkingNote(context, folderId);//根据环境和id创建一个空的便签 + note.setBgColorId(defaultBgColorId);//设定相关属性 + note.setWidgetId(widgetId);//设定widget id + note.setWidgetType(widgetType);//设置窗口类型 + return note; + } + + public static WorkingNote load(Context context, long id) {//导入一个新的正在写入的便签(WorkingNote) + return new WorkingNote(context, id, 0);//返回便签 + } + + public synchronized boolean saveNote() {//保存Note + if (isWorthSaving()) {//是否值得保存 + if (!existInDatabase()) {//是否存在数据库 + if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {//没有成功创建一个便签时,返回出错日志 + Log.e(TAG, "Create new note fail with id:" + mNoteId); + return false; + } + } + + mNote.syncNote(mContext, mNoteId);//同步便签内容及便签id + + /** + * Update widget content if there exist any widget of this note + */ + if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID//判断是否存在widget可以上传 + && mWidgetType != Notes.TYPE_WIDGET_INVALIDE + && mNoteSettingStatusListener != null) { + mNoteSettingStatusListener.onWidgetChanged(); + } + return true; + } else { + return false; + } + } + + public boolean existInDatabase() { + return mNoteId > 0; + }//是否在数据库中存在判断是否在数据库中存储过,直接判定id大小即可 + + private boolean isWorthSaving() {//判断是否需要保存 + if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))//被删除,或(不在数据库中 内容为空),或 本地已保存过 + || (existInDatabase() && !mNote.isLocalModified())) { + return false; + } else { + return true;//其余情况,要保存,返回true + } + } + + public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {//设置常量 + mNoteSettingStatusListener = l; + } + + public void setAlertDate(long date, boolean set) {//设置AlertDate;若 mAlertDate与data不同,则更改mAlertDate并设定NoteValue + if (date != mAlertDate) {//发现date与mAlertDate不一致时,设置mAlertDate为date + mAlertDate = date;//为设置的日期打标签 + mNote.setNoteValue(NoteColumns.ALERTED_DATE, String.valueOf(mAlertDate)); + } + if (mNoteSettingStatusListener != null) {//判断是否为空 + mNoteSettingStatusListener.onClockAlertChanged(date, set); + } + } + + public void markDeleted(boolean mark) {//设定删除标记 + mIsDeleted = mark;//设定标记 + if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID + && mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) {//调用mNoteSettingStatusListener的 onWidgetChanged方法 + mNoteSettingStatusListener.onWidgetChanged(); + } + } + + public void setBgColorId(int id) {//设定背景颜色 + if (id != mBgColorId) {//判断 + mBgColorId = id;//设置背景颜色 + if (mNoteSettingStatusListener != null) { + mNoteSettingStatusListener.onBackgroundColorChanged(); + } + mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id)); + } + } + + public void setCheckListMode(int mode) {//设定检查列表模式 + if (mMode != mode) {//设定一个判断条件 + if (mNoteSettingStatusListener != null) { + mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode);//设定之后更改mMode + } + mMode = mode;//把当前便签蛇者为清单模式的便签 + mNote.setTextData(TextNote.MODE, String.valueOf(mMode));//语句:重设文本数据,改变MODE项 + } + } + + public void setWidgetType(int type) {//设定WidgetType + if (type != mWidgetType) {//设定条件 + mWidgetType = type;//调用Note的setNoteValue方法更改WidgetType + mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType)); + }//调用Note的setNoteValue方法更改WidgetType + } + + public void setWidgetId(int id) {//设定WidgetId + if (id != mWidgetId) {//设定条件 + mWidgetId = id;//调用Note的setNoteValue方法更改WidgetId + mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId)); + }//调用Note的setNoteValue方法更改WidgetId + } + + public void setWorkingText(String text) {//设定WorkingText + if (!TextUtils.equals(mContent, text)) {//判断条件 + mContent = text;//调用Note的setTextData方法更改WorkingText + mNote.setTextData(DataColumns.CONTENT, mContent);//调用Note的setTextData方法更改WorkingText + } + } + + public void convertToCallNote(String phoneNumber, long callDate) {//转变mNote的CallData及CallNote信息 + 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)); + } + + public boolean hasClockAlert() { + return (mAlertDate > 0 ? true : false); + }//判断是否有时钟提醒 + + public String getContent() { + return mContent; + }//获取内容 + + public long getAlertDate() { + return mAlertDate; + }//获取闹钟警戒数据 + + public long getModifiedDate() { + return mModifiedDate; + }//获取修改的数据 + + public int getBgColorResId() { + return NoteBgResources.getNoteBgResource(mBgColorId); + }//获取背景颜色id + + public int getBgColorId() { + return mBgColorId; + }//获取背景颜色id + + public int getTitleBgResId() { + return NoteBgResources.getNoteTitleBgResource(mBgColorId); + }//获取标题背景颜色id + + public int getCheckListMode() { + return mMode; + }//获取CheckListMode + + public long getNoteId() { + return mNoteId; + }//获取便签id + + public long getFolderId() { + return mFolderId; + }//获取文件夹id + + public int getWidgetId() { + return mWidgetId; + }//获取WidgetType + + public int getWidgetType() { + return mWidgetType; + }//创建接口 NoteSettingChangedListener,便签更新监视;为NoteEditActivity提供接口 + + public interface NoteSettingChangedListener {//该类用于侦听关于Note的设置的改变 + /** + * Called when the background color of current note has just changed + */ + void onBackgroundColorChanged();//背景颜色改变按钮 + + /** + * Called when user set clock + */ + 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 + */ + void onCheckListModeChanged(int oldMode, int newMode);//mode的改变按键 + } +}