|  |  | @ -872,44 +872,53 @@ public class NoteEditActivity extends Activity implements OnClickListener, | 
			
		
	
		
		
			
				
					
					|  |  |  |     //当勾选列表模式发生改变时的回调方法
 |  |  |  |     //当勾选列表模式发生改变时的回调方法
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     public void onCheckListModeChanged(int oldMode, int newMode) { |  |  |  |     public void onCheckListModeChanged(int oldMode, int newMode) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (newMode == TextNote.MODE_CHECK_LIST) { |  |  |  |         if (newMode == TextNote.MODE_CHECK_LIST) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //如果新模式是复选框列表,切换到列表模式
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             switchToListMode(mNoteEditor.getText().toString()); |  |  |  |             switchToListMode(mNoteEditor.getText().toString()); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } else { |  |  |  |         } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //如果不是列表模式,需要将工作文本从列表模式转换回正常文本模式
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (!getWorkingText()) { |  |  |  |             if (!getWorkingText()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 mWorkingNote.setWorkingText(mWorkingNote.getContent().replace(TAG_UNCHECKED + " ", |  |  |  |                 mWorkingNote.setWorkingText(mWorkingNote.getContent().replace(TAG_UNCHECKED + " ", | 
			
		
	
		
		
			
				
					
					|  |  |  |                         "")); |  |  |  |                         "")); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //设置高亮查询结果并将编辑器切换为可见
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery)); |  |  |  |             mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery)); | 
			
		
	
		
		
			
				
					
					|  |  |  |             mEditTextList.setVisibility(View.GONE); |  |  |  |             mEditTextList.setVisibility(View.GONE); | 
			
		
	
		
		
			
				
					
					|  |  |  |             mNoteEditor.setVisibility(View.VISIBLE); |  |  |  |             mNoteEditor.setVisibility(View.VISIBLE); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //从编辑框获取当前的工作文本,并设置对应的工作笔记数据的方法
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private boolean getWorkingText() { |  |  |  |     private boolean getWorkingText() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         boolean hasChecked = false; |  |  |  |         boolean hasChecked = false; | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) { |  |  |  |         if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             StringBuilder sb = new StringBuilder(); |  |  |  |             StringBuilder sb = new StringBuilder();//用于构建最终的工作文本
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             for (int i = 0; i < mEditTextList.getChildCount(); i++) { |  |  |  |             for (int i = 0; i < mEditTextList.getChildCount(); i++) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 View view = mEditTextList.getChildAt(i); |  |  |  |                 View view = mEditTextList.getChildAt(i); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text); |  |  |  |                 NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (!TextUtils.isEmpty(edit.getText())) { |  |  |  |                 if (!TextUtils.isEmpty(edit.getText())) {//跳过空编辑框
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     //如果复选框被勾选,将该项文本添加到工作文本中,并标记为已检查
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (((CheckBox) view.findViewById(R.id.cb_edit_item)).isChecked()) { |  |  |  |                     if (((CheckBox) view.findViewById(R.id.cb_edit_item)).isChecked()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         sb.append(TAG_CHECKED).append(" ").append(edit.getText()).append("\n"); |  |  |  |                         sb.append(TAG_CHECKED).append(" ").append(edit.getText()).append("\n"); | 
			
		
	
		
		
			
				
					
					|  |  |  |                         hasChecked = true; |  |  |  |                         hasChecked = true; | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } else { |  |  |  |                     } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                         //如果未勾选,同样将文本添加到工作文本中,但不进行标记
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                         sb.append(TAG_UNCHECKED).append(" ").append(edit.getText()).append("\n"); |  |  |  |                         sb.append(TAG_UNCHECKED).append(" ").append(edit.getText()).append("\n"); | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //设置笔记的工作文本
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             mWorkingNote.setWorkingText(sb.toString()); |  |  |  |             mWorkingNote.setWorkingText(sb.toString()); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } else { |  |  |  |         } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //如果不在复选框列表模式中,直接从编辑器获取文本
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             mWorkingNote.setWorkingText(mNoteEditor.getText().toString()); |  |  |  |             mWorkingNote.setWorkingText(mNoteEditor.getText().toString()); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         return hasChecked; |  |  |  |         return hasChecked; //返回是否有勾选项的标志
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //保存笔记的方法,该方法会首先获取工作文本,然后保存笔记
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private boolean saveNote() { |  |  |  |     private boolean saveNote() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         getWorkingText(); |  |  |  |         getWorkingText();//获取当前的编辑框文本数据
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         boolean saved = mWorkingNote.saveNote(); |  |  |  |         boolean saved = mWorkingNote.saveNote();//保存笔记,并获取结果
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         if (saved) { |  |  |  |         if (saved) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             /** |  |  |  |             /** | 
			
		
	
		
		
			
				
					
					|  |  |  |              * There are two modes from List view to edit view, open one note, |  |  |  |              * There are two modes from List view to edit view, open one note, | 
			
		
	
	
		
		
			
				
					|  |  | @ -918,11 +927,13 @@ public class NoteEditActivity extends Activity implements OnClickListener, | 
			
		
	
		
		
			
				
					
					|  |  |  |              * new node requires to the top of the list. This code |  |  |  |              * new node requires to the top of the list. This code | 
			
		
	
		
		
			
				
					
					|  |  |  |              * {@link #RESULT_OK} is used to identify the create/edit state |  |  |  |              * {@link #RESULT_OK} is used to identify the create/edit state | 
			
		
	
		
		
			
				
					
					|  |  |  |              */ |  |  |  |              */ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //设置保存成功的结果,以便正确处理返回时的列表位置
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             setResult(RESULT_OK); |  |  |  |             setResult(RESULT_OK); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         return saved; |  |  |  |         return saved;//返回保存是否成功的标志
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private void sendToDesktop() { |  |  |  |     private void sendToDesktop() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         /** |  |  |  |         /** | 
			
		
	
		
		
			
				
					
					|  |  |  |          * Before send message to home, we should make sure that current |  |  |  |          * Before send message to home, we should make sure that current | 
			
		
	
	
		
		
			
				
					|  |  | @ -932,20 +943,29 @@ public class NoteEditActivity extends Activity implements OnClickListener, | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (!mWorkingNote.existInDatabase()) { |  |  |  |         if (!mWorkingNote.existInDatabase()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             saveNote(); |  |  |  |             saveNote(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |         //如果已保存的笔记存在有效的ID,准备创建快捷方式
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         if (mWorkingNote.getNoteId() > 0) { |  |  |  |         if (mWorkingNote.getNoteId() > 0) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             Intent sender = new Intent(); |  |  |  |             Intent sender = new Intent(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //意图指向NoteEditActivity,代表要打开的编辑笔记的组件
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             Intent shortcutIntent = new Intent(this, NoteEditActivity.class); |  |  |  |             Intent shortcutIntent = new Intent(this, NoteEditActivity.class); | 
			
		
	
		
		
			
				
					
					|  |  |  |             shortcutIntent.setAction(Intent.ACTION_VIEW); |  |  |  |             shortcutIntent.setAction(Intent.ACTION_VIEW); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //将笔记ID作为额外的信息附加到意图上
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             shortcutIntent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId()); |  |  |  |             shortcutIntent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //将定义好的编辑笔记的意图作为快捷方式的意图进行设置
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             sender.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); |  |  |  |             sender.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //设置快捷方式的名称
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             sender.putExtra(Intent.EXTRA_SHORTCUT_NAME, |  |  |  |             sender.putExtra(Intent.EXTRA_SHORTCUT_NAME, | 
			
		
	
		
		
			
				
					
					|  |  |  |                     makeShortcutIconTitle(mWorkingNote.getContent())); |  |  |  |                     makeShortcutIconTitle(mWorkingNote.getContent())); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //设置快捷方式图标的资源
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             sender.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, |  |  |  |             sender.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, | 
			
		
	
		
		
			
				
					
					|  |  |  |                     Intent.ShortcutIconResource.fromContext(this, R.drawable.icon_app)); |  |  |  |                     Intent.ShortcutIconResource.fromContext(this, R.drawable.icon_app)); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //避免快捷方式重复,设定"duplicate"为true
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             sender.putExtra("duplicate", true); |  |  |  |             sender.putExtra("duplicate", true); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //设置该动作用于告诉启动器创建一个新的快捷方式
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); |  |  |  |             sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //显示提示已发送到桌面的信息
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             showToast(R.string.info_note_enter_desktop); |  |  |  |             showToast(R.string.info_note_enter_desktop); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //发送广播以创建快捷方式
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             sendBroadcast(sender); |  |  |  |             sendBroadcast(sender); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } else { |  |  |  |         } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |             /** |  |  |  |             /** | 
			
		
	
	
		
		
			
				
					|  |  | @ -953,22 +973,29 @@ public class NoteEditActivity extends Activity implements OnClickListener, | 
			
		
	
		
		
			
				
					
					|  |  |  |              * not worthy saving), we have no note id, remind the user that he |  |  |  |              * not worthy saving), we have no note id, remind the user that he | 
			
		
	
		
		
			
				
					
					|  |  |  |              * should input something |  |  |  |              * should input something | 
			
		
	
		
		
			
				
					
					|  |  |  |              */ |  |  |  |              */ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //如果为输入任何内容,则不存在笔记ID,提示用户输入一些内容
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             Log.e(TAG, "Send to desktop error"); |  |  |  |             Log.e(TAG, "Send to desktop error"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //显示提示错误的消息
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             showToast(R.string.error_note_empty_for_send_to_desktop); |  |  |  |             showToast(R.string.error_note_empty_for_send_to_desktop); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //创建快捷方式时处理笔记内容标题的长度,确保他不会太长
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private String makeShortcutIconTitle(String content) { |  |  |  |     private String makeShortcutIconTitle(String content) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         //删除内容中的已检查和未检查标记
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         content = content.replace(TAG_CHECKED, ""); |  |  |  |         content = content.replace(TAG_CHECKED, ""); | 
			
		
	
		
		
			
				
					
					|  |  |  |         content = content.replace(TAG_UNCHECKED, ""); |  |  |  |         content = content.replace(TAG_UNCHECKED, ""); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         //如果内容的长度超过了快捷方式图表标题的最大长度,就截取前面的部分,否则就使用全部内容
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         return content.length() > SHORTCUT_ICON_TITLE_MAX_LEN ? content.substring(0, |  |  |  |         return content.length() > SHORTCUT_ICON_TITLE_MAX_LEN ? content.substring(0, | 
			
		
	
		
		
			
				
					
					|  |  |  |                 SHORTCUT_ICON_TITLE_MAX_LEN) : content; |  |  |  |                 SHORTCUT_ICON_TITLE_MAX_LEN) : content; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //显示一个短时间长度的Toast消息,具体消息由资源ID指定
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private void showToast(int resId) { |  |  |  |     private void showToast(int resId) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         showToast(resId, Toast.LENGTH_SHORT); |  |  |  |         showToast(resId, Toast.LENGTH_SHORT); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //显示一个Toast消息,可以指定消息的资源ID和持续时间
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private void showToast(int resId, int duration) { |  |  |  |     private void showToast(int resId, int duration) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         Toast.makeText(this, resId, duration).show(); |  |  |  |         Toast.makeText(this, resId, duration).show(); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |