@ -63,6 +63,7 @@ import net.micode.notes.tool.ResourceParser.TextAppearanceResources;
import net.micode.notes.ui.DateTimePickerDialog.OnDateTimeSetListener ;
import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener ;
import net.micode.notes.widget.NoteWidgetProvider_2x ;
import net.micode.notes.widget.NoteWidgetProvider_3x ;
import net.micode.notes.widget.NoteWidgetProvider_4x ;
import java.util.HashMap ;
@ -83,8 +84,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
public ImageView ibSetBgColor ;
}
// HeadViewHolder类定义了一组视图, 用于在列表或网格中显示信息。这些视图包括一个TextView用于显示修改信息, 一个ImageView用于显示警报图标, 另一个TextView用于显示警报日期, 还有一个ImageView用于选择背景颜色。
private static final Map < Integer , Integer > sBgSelectorBtnsMap = new HashMap < Integer , Integer > ( ) ;
static {
sBgSelectorBtnsMap . put ( R . id . iv_bg_yellow , ResourceParser . YELLOW ) ;
sBgSelectorBtnsMap . put ( R . id . iv_bg_red , ResourceParser . RED ) ;
@ -94,6 +97,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
private static final Map < Integer , Integer > sBgSelectorSelectionMap = new HashMap < Integer , Integer > ( ) ;
static {
sBgSelectorSelectionMap . put ( ResourceParser . YELLOW , R . id . iv_bg_yellow_select ) ;
sBgSelectorSelectionMap . put ( ResourceParser . RED , R . id . iv_bg_red_select ) ;
@ -101,8 +105,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sBgSelectorSelectionMap . put ( ResourceParser . GREEN , R . id . iv_bg_green_select ) ;
sBgSelectorSelectionMap . put ( ResourceParser . WHITE , R . id . iv_bg_white_select ) ;
}
// sBgSelectorBtnsMap是一个HashMap, 将用于选择背景颜色的ImageView视图的资源ID映射到整数值, 这些整数值在ResourceParser类中定义。同样, sBgSelectorSelectionMap将整数值映射到所选ImageView视图的资源ID。
private static final Map < Integer , Integer > sFontSizeBtnsMap = new HashMap < Integer , Integer > ( ) ;
static {
sFontSizeBtnsMap . put ( R . id . ll_font_large , ResourceParser . TEXT_LARGE ) ;
sFontSizeBtnsMap . put ( R . id . ll_font_small , ResourceParser . TEXT_SMALL ) ;
@ -111,12 +117,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
private static final Map < Integer , Integer > sFontSelectorSelectionMap = new HashMap < Integer , Integer > ( ) ;
static {
sFontSelectorSelectionMap . put ( ResourceParser . TEXT_LARGE , R . id . iv_large_select ) ;
sFontSelectorSelectionMap . put ( ResourceParser . TEXT_SMALL , R . id . iv_small_select ) ;
sFontSelectorSelectionMap . put ( ResourceParser . TEXT_MEDIUM , R . id . iv_medium_select ) ;
sFontSelectorSelectionMap . put ( ResourceParser . TEXT_SUPER , R . id . iv_super_select ) ;
}
// sFontSizeBtnsMap将用于选择字体大小的LinearLayout视图的资源ID映射到整数值, 而sFontSelectorSelectionMap将整数值映射到所选ImageView视图的资源ID。
private static final String TAG = "NoteEditActivity" ;
@ -184,10 +192,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
* If the user specified the { @link Intent # ACTION_VIEW } but not provided with id ,
* then jump to the NotesListActivity
* /
mWorkingNote = null ;
// 果用户指定了 Intent.ACTION_VIEW 动作但没有提供ID, 则跳转到 NotesListActivity
mWorkingNote = null ; //在方法中, 首先将mWorkingNote设置为null。然后, 根据传入的Intent的动作(action)进行选择。
if ( TextUtils . equals ( Intent . ACTION_VIEW , intent . getAction ( ) ) ) {
// Intent中获取笔记ID
long noteId = intent . getLongExtra ( Intent . EXTRA_UID , 0 ) ;
// 将用户查询字符串设置为空
mUserQuery = "" ;
// 如果Intent包含了搜索结果的额外数据, 则从额外数据中获取笔记ID, 并将用户查询字符串设置为搜索管理器中的用户查询字符串
/ * *
* Starting from the searched result
@ -197,6 +209,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mUserQuery = intent . getStringExtra ( SearchManager . USER_QUERY ) ;
}
// 如果笔记在笔记数据库中不存在,则跳转到 NotesListActivity 并显示错误信息的Toast, 最后结束 Activity 并返回 false
if ( ! DataUtils . visibleInNoteDatabase ( getContentResolver ( ) , noteId , Notes . TYPE_NOTE ) ) {
Intent jump = new Intent ( this , NotesListActivity . class ) ;
startActivity ( jump ) ;
@ -204,6 +217,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
finish ( ) ;
return false ;
} else {
// 加载笔记
mWorkingNote = WorkingNote . load ( this , noteId ) ;
if ( mWorkingNote = = null ) {
Log . e ( TAG , "load note failed with note id" + noteId ) ;
@ -211,11 +225,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return false ;
}
}
// 如果该Intent的动作(action)为Intent.ACTION_VIEW, 则从该Intent中获取笔记的ID(noteId)。如果该Intent还包含了一个搜索结果(Search)的额外数据(extra data key), 则将noteId从额外数据中获取, 并将用户查询字符串(mUserQuery)设置为搜索管理器中的用户查询字符串(SearchManager.USER_QUERY)。如果noteId在笔记数据库中不存在, 则将Activity转到NotesListActivity, 并显示一个错误信息的Toast, 最后结束Activity并返回false。如果noteId在笔记数据库中存在, 则加载该笔记的工作副本(mWorkingNote), 如果加载失败, 则结束Activity并返回false。
getWindow ( ) . setSoftInputMode (
WindowManager . LayoutParams . SOFT_INPUT_STATE_HIDDEN
| WindowManager . LayoutParams . SOFT_INPUT_ADJUST_RESIZE ) ;
} else if ( TextUtils . equals ( Intent . ACTION_INSERT_OR_EDIT , intent . getAction ( ) ) ) {
// New note
} else if ( TextUtils . equals ( Intent . ACTION_INSERT_OR_EDIT , intent . getAction ( ) ) ) {
// New note 如果用户指定了 Intent.ACTION_INSERT_OR_EDIT 动作, 则获取笔记ID, 如果笔记ID存在, 则加载笔记, 否则, 创建一个新的笔记
long folderId = intent . getLongExtra ( Notes . INTENT_EXTRA_FOLDER_ID , 0 ) ;
int widgetId = intent . getIntExtra ( Notes . INTENT_EXTRA_WIDGET_ID ,
AppWidgetManager . INVALID_APPWIDGET_ID ) ;
@ -269,20 +284,26 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
private void initNoteScreen ( ) {
// 使用mFontSizeId设置笔记编辑器的文本外观。
mNoteEditor . setTextAppearance ( this , TextAppearanceResources
. getTexAppearanceResource ( mFontSizeId ) ) ;
// 如果mWorkingNote的CheckListMode为TextNote.MODE_CHECK_LIST, 则将编辑器转换为列表模式。
if ( mWorkingNote . getCheckListMode ( ) = = TextNote . MODE_CHECK_LIST ) {
switchToListMode ( mWorkingNote . getContent ( ) ) ;
} else {
// 如果mWorkingNote的CheckListMode不是TextNote.MODE_CHECK_LIST, 则在编辑器中显示笔记内容, 并使用mUserQuery高亮显示查询结果。
mNoteEditor . setText ( getHighlightQueryResult ( mWorkingNote . getContent ( ) , mUserQuery ) ) ;
mNoteEditor . setSelection ( mNoteEditor . getText ( ) . length ( ) ) ;
}
// 隐藏背景选择器中所有不在sBgSelectorSelectionMap中的ID的视图。
for ( Integer id : sBgSelectorSelectionMap . keySet ( ) ) {
findViewById ( sBgSelectorSelectionMap . get ( id ) ) . setVisibility ( View . GONE ) ;
}
// 设置mHeadViewPanel和mNoteEditorPanel的背景颜色为mWorkingNote的标题背景ID和背景颜色ID。
mHeadViewPanel . setBackgroundResource ( mWorkingNote . getTitleBgResId ( ) ) ;
mNoteEditorPanel . setBackgroundResource ( mWorkingNote . getBgColorResId ( ) ) ;
// 在标题栏中显示修改日期。
mNoteHeaderHolder . tvModified . setText ( DateUtils . formatDateTime ( this ,
mWorkingNote . getModifiedDate ( ) , DateUtils . FORMAT_SHOW_DATE
| DateUtils . FORMAT_NUMERIC_DATE | DateUtils . FORMAT_SHOW_TIME
@ -296,6 +317,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
private void showAlertHeader ( ) {
// 如果mWorkingNote具有闹钟提醒, 则检查当前时间是否超过提醒时间, 如果超过, 则在标题栏中显示“note_alert_expired”文本; 否则, 在标题栏中显示相对时间。
if ( mWorkingNote . hasClockAlert ( ) ) {
long time = System . currentTimeMillis ( ) ;
if ( time > mWorkingNote . getAlertDate ( ) ) {
@ -304,12 +326,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mNoteHeaderHolder . tvAlertDate . setText ( DateUtils . getRelativeTimeSpanString (
mWorkingNote . getAlertDate ( ) , time , DateUtils . MINUTE_IN_MILLIS ) ) ;
}
// 将标题栏中的提醒日期文本和提醒图标设置为可见。
mNoteHeaderHolder . tvAlertDate . setVisibility ( View . VISIBLE ) ;
mNoteHeaderHolder . ivAlertIcon . setVisibility ( View . VISIBLE ) ;
} else {
// 如果mWorkingNote没有闹钟提醒, 则将标题栏中的提醒日期文本和提醒图标设置为不可见。
mNoteHeaderHolder . tvAlertDate . setVisibility ( View . GONE ) ;
mNoteHeaderHolder . ivAlertIcon . setVisibility ( View . GONE ) ;
} ;
}
;
}
@Override
@ -321,7 +346,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
@Override
protected void onSaveInstanceState ( Bundle outState ) {
super . onSaveInstanceState ( outState ) ;
/ * *
/ *
* For new note without note id , we should firstly save it to
* generate a id . If the editing note is not worth saving , there
* is no id which is equivalent to create new note
@ -335,31 +360,36 @@ public class NoteEditActivity extends Activity implements OnClickListener,
@Override
public boolean dispatchTouchEvent ( MotionEvent ev ) {
// 如果笔记背景颜色选择器可见, 并且触摸事件不在笔记背景颜色选择器范围内, 则隐藏笔记背景颜色选择器并返回true。
if ( mNoteBgColorSelector . getVisibility ( ) = = View . VISIBLE
& & ! inRangeOfView ( mNoteBgColorSelector , ev ) ) {
mNoteBgColorSelector . setVisibility ( View . GONE ) ;
return true ;
}
// 如果字体大小选择器可见, 并且触摸事件不在字体大小选择器范围内, 则隐藏字体大小选择器并返回true。
if ( mFontSizeSelector . getVisibility ( ) = = View . VISIBLE
& & ! inRangeOfView ( mFontSizeSelector , ev ) ) {
mFontSizeSelector . setVisibility ( View . GONE ) ;
return true ;
}
// 返回父类的dispatchTouchEvent方法。
return super . dispatchTouchEvent ( ev ) ;
}
private boolean inRangeOfView ( View view , MotionEvent ev ) {
int [ ] location = new int [ 2 ] ;
// 获取视图在屏幕上的位置。
int [ ] location = new int [ 2 ] ;
view . getLocationOnScreen ( location ) ;
int x = location [ 0 ] ;
int y = location [ 1 ] ;
// 如果触摸事件的x坐标小于视图的x坐标、大于视图的宽度和x坐标之和、y坐标小于视图的y坐标、或大于视图的高度和y坐标之和, 则返回false, 否则返回true。
if ( ev . getX ( ) < x
| | ev . getX ( ) > ( x + view . getWidth ( ) )
| | ev . getY ( ) < y
| | ev . getY ( ) > ( y + view . getHeight ( ) ) ) {
return false ;
}
return false ;
}
return true ;
}
@ -383,15 +413,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
for ( int id : sFontSizeBtnsMap . keySet ( ) ) {
View view = findViewById ( id ) ;
view . setOnClickListener ( this ) ;
} ;
}
;
mSharedPrefs = PreferenceManager . getDefaultSharedPreferences ( this ) ;
mFontSizeId = mSharedPrefs . getInt ( PREFERENCE_FONT_SIZE , ResourceParser . BG_DEFAULT_FONT_SIZE ) ;
/ * *
/ *
* HACKME : Fix bug of store the resource id in shared preference .
* The id may larger than the length of resources , in this case ,
* return the { @link ResourceParser # BG_DEFAULT_FONT_SIZE }
* /
if ( mFontSizeId > = TextAppearanceResources . getResourcesSize ( ) ) {
if ( mFontSizeId > = TextAppearanceResources . getResourcesSize ( ) ) {
mFontSizeId = ResourceParser . BG_DEFAULT_FONT_SIZE ;
}
mEditTextList = ( LinearLayout ) findViewById ( R . id . note_edit_list ) ;
@ -400,37 +431,40 @@ public class NoteEditActivity extends Activity implements OnClickListener,
@Override
protected void onPause ( ) {
super . onPause ( ) ;
if ( saveNote ( ) ) {
if ( saveNote ( ) ) {
Log . d ( TAG , "Note data was saved with length:" + mWorkingNote . getContent ( ) . length ( ) ) ;
}
clearSettingState ( ) ;
}
} //onPause()方法在活动即将暂停时被调用。如果有任何更改,它会保存当前笔记,并清除任何设置状态。
private void updateWidget ( ) {
Intent intent = new Intent ( AppWidgetManager . ACTION_APPWIDGET_UPDATE ) ;
if ( mWorkingNote . getWidgetType ( ) = = Notes . TYPE_WIDGET_2X ) {
intent . setClass ( this , NoteWidgetProvider_2x . class ) ;
} else if ( mWorkingNote . getWidgetType ( ) = = Notes . TYPE_WIDGET_3X ) {
intent . setClass ( this , NoteWidgetProvider_3x . class ) ;
} else if ( mWorkingNote . getWidgetType ( ) = = Notes . TYPE_WIDGET_4X ) {
intent . setClass ( this , NoteWidgetProvider_4x . class ) ;
} else {
Log . e ( TAG , "Uns pported widget type") ;
Log . e ( TAG , "Uns u pported widget type") ;
return ;
}
intent . putExtra ( AppWidgetManager . EXTRA_APPWIDGET_IDS , new int [ ] {
mWorkingNote . getWidgetId ( )
intent . putExtra ( AppWidgetManager . EXTRA_APPWIDGET_IDS , new int [ ] {
mWorkingNote . getWidgetId ( )
} ) ;
sendBroadcast ( intent ) ;
setResult ( RESULT_OK , intent ) ;
}
} //updateWidget()方法更新与当前笔记相关联的小部件。它创建一个意图, 并根据笔记的小部件类型设置相应的小部件提供程序类。然后它发送一个广播, 带有小部件ID以更新小部件。
public void onClick ( View v ) {
int id = v . getId ( ) ;
if ( id = = R . id . btn_set_bg_color ) {
mNoteBgColorSelector . setVisibility ( View . VISIBLE ) ;
findViewById ( sBgSelectorSelectionMap . get ( mWorkingNote . getBgColorId ( ) ) ) . setVisibility (
- View . VISIBLE ) ;
- View . VISIBLE ) ;
} else if ( sBgSelectorBtnsMap . containsKey ( id ) ) {
findViewById ( sBgSelectorSelectionMap . get ( mWorkingNote . getBgColorId ( ) ) ) . setVisibility (
View . GONE ) ;
@ -450,17 +484,17 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
mFontSizeSelector . setVisibility ( View . GONE ) ;
}
}
} //onClick()方法处理UI中各种按钮的点击事件。当单击相应的按钮时, 它会显示颜色选择器或字体大小选择器。它还根据所选选项更新笔记的字体大小或背景颜色。
@Override
public void onBackPressed ( ) {
if ( clearSettingState ( ) ) {
if ( clearSettingState ( ) ) {
return ;
}
saveNote ( ) ;
super . onBackPressed ( ) ;
}
} //onBackPressed()方法在按下返回按钮时被调用。它检查当前是否有任何设置状态处于活动状态,并清除它。然后它保存当前笔记并调用超类实现。
private boolean clearSettingState ( ) {
if ( mNoteBgColorSelector . getVisibility ( ) = = View . VISIBLE ) {
@ -471,14 +505,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return true ;
}
return false ;
}
} //clearSettingState()方法检查当前是否有任何设置状态处于活动状态,并清除它。
public void onBackgroundColorChanged ( ) {
findViewById ( sBgSelectorSelectionMap . get ( mWorkingNote . getBgColorId ( ) ) ) . setVisibility (
View . VISIBLE ) ;
mNoteEditorPanel . setBackgroundResource ( mWorkingNote . getBgColorResId ( ) ) ;
mHeadViewPanel . setBackgroundResource ( mWorkingNote . getTitleBgResId ( ) ) ;
}
} //onBackgroundColorChanged()方法在选择新的背景颜色时被调用。它更新笔记的背景颜色,并更新颜色选择器的颜色。
@Override
public boolean onPrepareOptionsMenu ( Menu menu ) {
@ -503,7 +537,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
menu . findItem ( R . id . menu_delete_remind ) . setVisible ( false ) ;
}
return true ;
}
} //onFontSizeChanged()方法在选择新的字体大小时被调用。它更新笔记的字体大小,并更新字体大小选择器的值。
@Override
public boolean onOptionsItemSelected ( MenuItem item ) {
@ -557,7 +591,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
DateTimePickerDialog d = new DateTimePickerDialog ( this , System . currentTimeMillis ( ) ) ;
d . setOnDateTimeSetListener ( new OnDateTimeSetListener ( ) {
public void OnDateTimeSet ( AlertDialog dialog , long date ) {
mWorkingNote . setAlertDate ( date , true ) ;
mWorkingNote . setAlertDate ( date , true ) ;
}
} ) ;
d . show ( ) ;
@ -572,7 +606,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
intent . putExtra ( Intent . EXTRA_TEXT , info ) ;
intent . setType ( "text/plain" ) ;
context . startActivity ( intent ) ;
}
} //sendTo(Context context, String info)方法创建一个新的意图, 并使用Intent.EXTRA_TEXT将信息作为文本传递。它的目的是启动共享对话框, 让用户分享笔记的内容。
private void createNewNote ( ) {
// Firstly, save current editing notes
@ -584,7 +619,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
intent . setAction ( Intent . ACTION_INSERT_OR_EDIT ) ;
intent . putExtra ( Notes . INTENT_EXTRA_FOLDER_ID , mWorkingNote . getFolderId ( ) ) ;
startActivity ( intent ) ;
}
} //createNewNote()方法保存当前正在编辑的笔记, 然后启动一个新的NoteEditActivity以创建一个新的笔记。通过设置Intent.ACTION_INSERT_OR_EDIT和Notes.INTENT_EXTRA_FOLDER_ID, 该方法指示NoteEditActivity启动以插入或编辑笔记, 并指定所选文件夹的ID。
private void deleteCurrentNote ( ) {
if ( mWorkingNote . existInDatabase ( ) ) {
@ -606,11 +641,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
}
mWorkingNote . markDeleted ( true ) ;
}
} //deleteCurrentNote()方法删除当前笔记。如果该笔记已存储在数据库中,则将其从数据库中删除。如果应用程序处于同步模式下,则将其移动到垃圾文件夹中,而不是永久删除。无论是删除还是移动,该方法都会将当前笔记标记为已删除。
private boolean isSyncMode ( ) {
return NotesPreferenceActivity . getSyncAccountName ( this ) . trim ( ) . length ( ) > 0 ;
}
} //isSyncMode()方法检查应用程序是否处于同步模式。如果已经选择了同步帐户, 则返回true。否则, 返回false。
public void onClockAlertChanged ( long date , boolean set ) {
/ * *
@ -626,7 +661,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
PendingIntent pendingIntent = PendingIntent . getBroadcast ( this , 0 , intent , 0 ) ;
AlarmManager alarmManager = ( ( AlarmManager ) getSystemService ( ALARM_SERVICE ) ) ;
showAlertHeader ( ) ;
if ( ! set ) {
if ( ! set ) {
alarmManager . cancel ( pendingIntent ) ;
} else {
alarmManager . set ( AlarmManager . RTC_WAKEUP , date , pendingIntent ) ;
@ -645,6 +680,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
public void onWidgetChanged ( ) {
updateWidget ( ) ;
}
// onWidgetChanged()方法会在小部件更改时被调用。它会调用updateWidget()方法来更新小部件。
public void onEditTextDelete ( int index , String text ) {
int childCount = mEditTextList . getChildCount ( ) ;
@ -659,7 +695,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mEditTextList . removeViewAt ( index ) ;
NoteEditText edit = null ;
if ( index = = 0 ) {
if ( index = = 0 ) {
edit = ( NoteEditText ) mEditTextList . getChildAt ( 0 ) . findViewById (
R . id . et_edit_text ) ;
} else {
@ -671,12 +707,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
edit . requestFocus ( ) ;
edit . setSelection ( length ) ;
}
// onEditTextDelete(int index, String text)方法会在删除NoteEditText视图时被调用。该方法首先检查是否只有一个NoteEditText视图存在, 如果是则直接返回。然后, 该方法会将所有后续视图的索引递减1。接下来, 该方法会删除指定索引处的NoteEditText视图, 并将其文本追加到前一个视图的文本中, 以便将文本合并到一个视图中。最后, 该方法将焦点设置在前一个视图中, 并将光标移动到文本末尾。
public void onEditTextEnter ( int index , String text ) {
/ * *
* Should not happen , check for debug
* /
if ( index > mEditTextList . getChildCount ( ) ) {
if ( index > mEditTextList . getChildCount ( ) ) {
Log . e ( TAG , "Index out of mEditTextList boundrary, should not happen" ) ;
}
@ -696,7 +733,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
String [ ] items = text . split ( "\n" ) ;
int index = 0 ;
for ( String item : items ) {
if ( ! TextUtils . isEmpty ( item ) ) {
if ( ! TextUtils . isEmpty ( item ) ) {
mEditTextList . addView ( getListItem ( item , index ) ) ;
index + + ;
}
@ -707,6 +744,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mNoteEditor . setVisibility ( View . GONE ) ;
mEditTextList . setVisibility ( View . VISIBLE ) ;
}
// switchToListMode(String text)方法用于切换到清单模式。该方法首先清除所有视图, 然后将文本根据换行符分隔为多个条目, 并将每个条目添加到mEditTextList中。同时, 该方法会添加一个新的空条目, 以便用户可以在列表末尾添加新的条目。最后, 该方法会将焦点设置在最后一个条目上, 并将编辑器视图隐藏, 将列表视图显示。
private Spannable getHighlightQueryResult ( String fullText , String userQuery ) {
SpannableString spannable = new SpannableString ( fullText = = null ? "" : fullText ) ;
@ -724,6 +762,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
return spannable ;
}
// getHighlightQueryResult(String fullText, String userQuery)方法用于标记在搜索查询中匹配的文本。该方法将返回一个Spannable对象, 其中查询匹配的文本会被高亮显示。
private View getListItem ( String item , int index ) {
View view = LayoutInflater . from ( this ) . inflate ( R . layout . note_edit_list_item , null ) ;
@ -755,18 +794,20 @@ public class NoteEditActivity extends Activity implements OnClickListener,
edit . setText ( getHighlightQueryResult ( item , mUserQuery ) ) ;
return view ;
}
// getListItem(String item, int index)方法用于获取一个清单视图。该方法将从R.layout.note_edit_list_item文件中充气视图。在充气视图之后, 该方法会将文本添加到NoteEditText视图中, 并将复选框设置为选中或未选中状态。如果条目已选中, 则文本将具有删除线。最后, 该方法将返回该视图。
public void onTextChange ( int index , boolean hasText ) {
if ( index > = mEditTextList . getChildCount ( ) ) {
Log . e ( TAG , "Wrong index, should not happen" ) ;
return ;
}
if ( hasText ) {
if ( hasText ) {
mEditTextList . getChildAt ( index ) . findViewById ( R . id . cb_edit_item ) . setVisibility ( View . VISIBLE ) ;
} else {
mEditTextList . getChildAt ( index ) . findViewById ( R . id . cb_edit_item ) . setVisibility ( View . GONE ) ;
}
}
// onTextChange(int index, boolean hasText)方法用于在清单视图中标记是否有文本。如果hasText为true, 则将显示复选框; 否则, 将隐藏复选框。
public void onCheckListModeChanged ( int oldMode , int newMode ) {
if ( newMode = = TextNote . MODE_CHECK_LIST ) {
@ -781,6 +822,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mNoteEditor . setVisibility ( View . VISIBLE ) ;
}
}
// onCheckListModeChanged(int oldMode, int newMode)方法用于在清单模式和文本编辑模式之间切换。如果新模式为清单模式,则将文本转换为清单视图;否则,将清单视图转换为文本编辑视图。
private boolean getWorkingText ( ) {
boolean hasChecked = false ;
@ -804,6 +846,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
return hasChecked ;
}
// getWorkingText()方法用于获取当前工作文本。如果当前模式为清单模式,则将所有条目合并为一个字符串,并添加检查框状态。否则,将返回当前编辑器文本。
private boolean saveNote ( ) {
getWorkingText ( ) ;