@ -61,7 +61,7 @@ public class WorkingNote {
private boolean mIsDeleted ;
private boolean mIsDeleted ;
private NoteSettingChangedListener mNoteSettingStatusListener ;
private NoteSettingChangedListener mNoteSettingStatusListener ;
// 声明 DATA_PROJECTION字符串数组
public static final String [ ] DATA_PROJECTION = new String [ ] {
public static final String [ ] DATA_PROJECTION = new String [ ] {
DataColumns . ID ,
DataColumns . ID ,
DataColumns . CONTENT ,
DataColumns . CONTENT ,
@ -71,7 +71,9 @@ public class WorkingNote {
DataColumns . DATA3 ,
DataColumns . DATA3 ,
DataColumns . DATA4 ,
DataColumns . DATA4 ,
} ;
} ;
/ * *
* // 声明 NOTE_PROJECTION字符串数组
* /
public static final String [ ] NOTE_PROJECTION = new String [ ] {
public static final String [ ] NOTE_PROJECTION = new String [ ] {
NoteColumns . PARENT_ID ,
NoteColumns . PARENT_ID ,
NoteColumns . ALERTED_DATE ,
NoteColumns . ALERTED_DATE ,
@ -124,11 +126,17 @@ public class WorkingNote {
loadNote ( ) ;
loadNote ( ) ;
}
}
/ * *
* 加 载 Note
* 通 过 数 据 库 调 用 query 函 数 找 到 第 一 个 条 目
* /
private void loadNote ( ) {
private void loadNote ( ) {
Cursor cursor = mContext . getContentResolver ( ) . query (
Cursor cursor = mContext . getContentResolver ( ) . query (
ContentUris . withAppendedId ( Notes . CONTENT_NOTE_URI , mNoteId ) , NOTE_PROJECTION , null ,
ContentUris . withAppendedId ( Notes . CONTENT_NOTE_URI , mNoteId ) , NOTE_PROJECTION , null ,
null , null ) ;
null , null ) ;
/ * *
* 若 存 在 , 储 存 相 应 信 息
* /
if ( cursor ! = null ) {
if ( cursor ! = null ) {
if ( cursor . moveToFirst ( ) ) {
if ( cursor . moveToFirst ( ) ) {
mFolderId = cursor . getLong ( NOTE_PARENT_ID_COLUMN ) ;
mFolderId = cursor . getLong ( NOTE_PARENT_ID_COLUMN ) ;
@ -139,6 +147,9 @@ public class WorkingNote {
mModifiedDate = cursor . getLong ( NOTE_MODIFIED_DATE_COLUMN ) ;
mModifiedDate = cursor . getLong ( NOTE_MODIFIED_DATE_COLUMN ) ;
}
}
cursor . close ( ) ;
cursor . close ( ) ;
/ * *
* 不 存 在 , 报 错
* /
} else {
} else {
Log . e ( TAG , "No note with id:" + mNoteId ) ;
Log . e ( TAG , "No note with id:" + mNoteId ) ;
throw new IllegalArgumentException ( "Unable to find note with id " + mNoteId ) ;
throw new IllegalArgumentException ( "Unable to find note with id " + mNoteId ) ;
@ -146,6 +157,10 @@ public class WorkingNote {
loadNoteData ( ) ;
loadNoteData ( ) ;
}
}
/ * *
* 加 载 Notedata
* /
private void loadNoteData ( ) {
private void loadNoteData ( ) {
Cursor cursor = mContext . getContentResolver ( ) . query ( Notes . CONTENT_DATA_URI , DATA_PROJECTION ,
Cursor cursor = mContext . getContentResolver ( ) . query ( Notes . CONTENT_DATA_URI , DATA_PROJECTION ,
DataColumns . NOTE_ID + "=?" , new String [ ] {
DataColumns . NOTE_ID + "=?" , new String [ ] {
@ -153,7 +168,13 @@ public class WorkingNote {
} , null ) ;
} , null ) ;
if ( cursor ! = null ) {
if ( cursor ! = null ) {
/ * *
* 查 到 信 息 不 为 空
* /
if ( cursor . moveToFirst ( ) ) {
if ( cursor . moveToFirst ( ) ) {
/ * *
* 查 看 第 一 项 是 否 存 在
* /
do {
do {
String type = cursor . getString ( DATA_MIME_TYPE_COLUMN ) ;
String type = cursor . getString ( DATA_MIME_TYPE_COLUMN ) ;
if ( DataConstants . NOTE . equals ( type ) ) {
if ( DataConstants . NOTE . equals ( type ) ) {
@ -166,6 +187,9 @@ public class WorkingNote {
Log . d ( TAG , "Wrong note type with type:" + type ) ;
Log . d ( TAG , "Wrong note type with type:" + type ) ;
}
}
} while ( cursor . moveToNext ( ) ) ;
} while ( cursor . moveToNext ( ) ) ;
/ * *
* 查 阅 所 有 项 , 直 到 为 空
* /
}
}
cursor . close ( ) ;
cursor . close ( ) ;
} else {
} else {
@ -174,9 +198,22 @@ public class WorkingNote {
}
}
}
}
/ * *
* 创 建 空 的 Note
* 传 参 : context , 文 件 夹 id , widget , 背 景 颜 色
* @param context
* @param folderId
* @param widgetId
* @param widgetType
* @param defaultBgColorId
* @return
* /
public static WorkingNote createEmptyNote ( Context context , long folderId , int widgetId ,
public static WorkingNote createEmptyNote ( Context context , long folderId , int widgetId ,
int widgetType , int defaultBgColorId ) {
int widgetType , int defaultBgColorId ) {
WorkingNote note = new WorkingNote ( context , folderId ) ;
WorkingNote note = new WorkingNote ( context , folderId ) ;
/ * *
* 设 定 相 关 属 性
* /
note . setBgColorId ( defaultBgColorId ) ;
note . setBgColorId ( defaultBgColorId ) ;
note . setWidgetId ( widgetId ) ;
note . setWidgetId ( widgetId ) ;
note . setWidgetType ( widgetType ) ;
note . setWidgetType ( widgetType ) ;
@ -186,10 +223,19 @@ public class WorkingNote {
public static WorkingNote load ( Context context , long id ) {
public static WorkingNote load ( Context context , long id ) {
return new WorkingNote ( context , id , 0 ) ;
return new WorkingNote ( context , id , 0 ) ;
}
}
/ * *
* 保 存 note
* /
public synchronized boolean saveNote ( ) {
public synchronized boolean saveNote ( ) {
if ( isWorthSaving ( ) ) {
if ( isWorthSaving ( ) ) {
/ * *
* 是 否 值 得 保 存
* /
if ( ! existInDatabase ( ) ) {
if ( ! existInDatabase ( ) ) {
/ * *
* 是 否 存 在 数 据 中
* /
if ( ( mNoteId = Note . getNewNoteId ( mContext , mFolderId ) ) = = 0 ) {
if ( ( mNoteId = Note . getNewNoteId ( mContext , mFolderId ) ) = = 0 ) {
Log . e ( TAG , "Create new note fail with id:" + mNoteId ) ;
Log . e ( TAG , "Create new note fail with id:" + mNoteId ) ;
return false ;
return false ;
@ -211,12 +257,23 @@ public class WorkingNote {
return false ;
return false ;
}
}
}
}
/ * *
* 是 否 在 数 据 库 中 存 在
* /
public boolean existInDatabase ( ) {
public boolean existInDatabase ( ) {
return mNoteId > 0 ;
return mNoteId > 0 ;
}
}
/ * *
* 是 否 值 得 保 存
* @return
* /
private boolean isWorthSaving ( ) {
private boolean isWorthSaving ( ) {
/ * *
* 被 删 除 , 或 ( 不 在 数 据 库 中 内 容 为 空 ) , 或 本 地 已 保 存 过
* /
if ( mIsDeleted | | ( ! existInDatabase ( ) & & TextUtils . isEmpty ( mContent ) )
if ( mIsDeleted | | ( ! existInDatabase ( ) & & TextUtils . isEmpty ( mContent ) )
| | ( existInDatabase ( ) & & ! mNote . isLocalModified ( ) ) ) {
| | ( existInDatabase ( ) & & ! mNote . isLocalModified ( ) ) ) {
return false ;
return false ;
@ -225,10 +282,22 @@ public class WorkingNote {
}
}
}
}
/ * *
* 设 置 mNoteSettingStatusListener
* @param l
* /
public void setOnSettingStatusChangedListener ( NoteSettingChangedListener l ) {
public void setOnSettingStatusChangedListener ( NoteSettingChangedListener l ) {
mNoteSettingStatusListener = l ;
mNoteSettingStatusListener = l ;
}
}
/ * *
* 设 置 AlertDate
* 若 mAlertDate 与 data 不 同 , 则 更 改 mAlertDate 并 设 定 NoteValue
* @param date
* @param set
* /
public void setAlertDate ( long date , boolean set ) {
public void setAlertDate ( long date , boolean set ) {
if ( date ! = mAlertDate ) {
if ( date ! = mAlertDate ) {
mAlertDate = date ;
mAlertDate = date ;
@ -239,7 +308,15 @@ public class WorkingNote {
}
}
}
}
/ * *
* 设 定 删 除 标 记
* @param mark
* /
public void markDeleted ( boolean mark ) {
public void markDeleted ( boolean mark ) {
/ * *
* 设 定 标 记
* /
mIsDeleted = mark ;
mIsDeleted = mark ;
if ( mWidgetId ! = AppWidgetManager . INVALID_APPWIDGET_ID
if ( mWidgetId ! = AppWidgetManager . INVALID_APPWIDGET_ID
& & mWidgetType ! = Notes . TYPE_WIDGET_INVALIDE & & mNoteSettingStatusListener ! = null ) {
& & mWidgetType ! = Notes . TYPE_WIDGET_INVALIDE & & mNoteSettingStatusListener ! = null ) {
@ -247,6 +324,11 @@ public class WorkingNote {
}
}
}
}
/ * *
* 设 定 背 景 颜 色
* @param id
* /
public void setBgColorId ( int id ) {
public void setBgColorId ( int id ) {
if ( id ! = mBgColorId ) {
if ( id ! = mBgColorId ) {
mBgColorId = id ;
mBgColorId = id ;
@ -257,6 +339,10 @@ public class WorkingNote {
}
}
}
}
/ * *
* 设 定 检 查 列 表 模 式
* @param mode
* /
public void setCheckListMode ( int mode ) {
public void setCheckListMode ( int mode ) {
if ( mMode ! = mode ) {
if ( mMode ! = mode ) {
if ( mNoteSettingStatusListener ! = null ) {
if ( mNoteSettingStatusListener ! = null ) {
@ -267,6 +353,12 @@ public class WorkingNote {
}
}
}
}
/ * *
* // 设定WidgetType
* // 参数: type
* @param type
* /
public void setWidgetType ( int type ) {
public void setWidgetType ( int type ) {
if ( type ! = mWidgetType ) {
if ( type ! = mWidgetType ) {
mWidgetType = type ;
mWidgetType = type ;
@ -274,6 +366,10 @@ public class WorkingNote {
}
}
}
}
/ * *
* 设 定 widgetid
* @param id
* /
public void setWidgetId ( int id ) {
public void setWidgetId ( int id ) {
if ( id ! = mWidgetId ) {
if ( id ! = mWidgetId ) {
mWidgetId = id ;
mWidgetId = id ;
@ -281,12 +377,20 @@ public class WorkingNote {
}
}
}
}
/ * *
* 调 用 Note 的 setNoteValue 方 法 更 改 WidgetId
* @param text
* /
public void setWorkingText ( String text ) {
public void setWorkingText ( String text ) {
if ( ! TextUtils . equals ( mContent , text ) ) {
if ( ! TextUtils . equals ( mContent , text ) ) {
mContent = text ;
mContent = text ;
mNote . setTextData ( DataColumns . CONTENT , mContent ) ;
mNote . setTextData ( DataColumns . CONTENT , mContent ) ;
}
}
}
}
/ * *
* 调 用 Note 的 setTextData 方 法 更 改 WorkingText
* /
public void convertToCallNote ( String phoneNumber , long callDate ) {
public void convertToCallNote ( String phoneNumber , long callDate ) {
mNote . setCallData ( CallNote . CALL_DATE , String . valueOf ( callDate ) ) ;
mNote . setCallData ( CallNote . CALL_DATE , String . valueOf ( callDate ) ) ;
@ -294,54 +398,115 @@ public class WorkingNote {
mNote . setNoteValue ( NoteColumns . PARENT_ID , String . valueOf ( Notes . ID_CALL_RECORD_FOLDER ) ) ;
mNote . setNoteValue ( NoteColumns . PARENT_ID , String . valueOf ( Notes . ID_CALL_RECORD_FOLDER ) ) ;
}
}
/ * *
* 判 断 是 否 有 时 钟 题 型
* @return
* /
public boolean hasClockAlert ( ) {
public boolean hasClockAlert ( ) {
return ( mAlertDate > 0 ? true : false ) ;
return ( mAlertDate > 0 ? true : false ) ;
}
}
/ * *
* 获 取 Content
* @return
* /
public String getContent ( ) {
public String getContent ( ) {
return mContent ;
return mContent ;
}
}
/ * *
* 获 取 AlertDate
* @return
* /
public long getAlertDate ( ) {
public long getAlertDate ( ) {
return mAlertDate ;
return mAlertDate ;
}
}
/ * *
* 获 取 ModifiedDate
* @return
* /
public long getModifiedDate ( ) {
public long getModifiedDate ( ) {
return mModifiedDate ;
return mModifiedDate ;
}
}
/ * *
* 获 取 背 景 颜 色 来 源 id
* @return
* /
public int getBgColorResId ( ) {
public int getBgColorResId ( ) {
return NoteBgResources . getNoteBgResource ( mBgColorId ) ;
return NoteBgResources . getNoteBgResource ( mBgColorId ) ;
}
}
/ * *
* 获 取 背 景 颜 色 id
* @return
* /
public int getBgColorId ( ) {
public int getBgColorId ( ) {
return mBgColorId ;
return mBgColorId ;
}
}
/ * *
* 获 取 标 题 背 景 颜 色 id
* @return
* /
public int getTitleBgResId ( ) {
public int getTitleBgResId ( ) {
return NoteBgResources . getNoteTitleBgResource ( mBgColorId ) ;
return NoteBgResources . getNoteTitleBgResource ( mBgColorId ) ;
}
}
/ * *
* 获 取 CheckListMode
* @return
* /
public int getCheckListMode ( ) {
public int getCheckListMode ( ) {
return mMode ;
return mMode ;
}
}
/ * *
* 获 取 便 签 id
* @return
* /
public long getNoteId ( ) {
public long getNoteId ( ) {
return mNoteId ;
return mNoteId ;
}
}
/ * *
* 获 取 文 件 夹 id
* @return
* /
public long getFolderId ( ) {
public long getFolderId ( ) {
return mFolderId ;
return mFolderId ;
}
}
/ * *
* 获 取 文 件 夹 id
* @return
* /
public int getWidgetId ( ) {
public int getWidgetId ( ) {
return mWidgetId ;
return mWidgetId ;
}
}
/ * *
* 获 取 WidgetId
* @return
* /
public int getWidgetType ( ) {
public int getWidgetType ( ) {
return mWidgetType ;
return mWidgetType ;
}
}
/ * *
* 获 取 WidgetType
* /
public interface NoteSettingChangedListener {
public interface NoteSettingChangedListener {
/ * *
/ * *
* Called when the background color of current note has just changed
* Called when the background color of current note has just changed