|
|
|
|
@ -43,9 +43,13 @@ import android.view.MotionEvent;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
|
import android.view.WindowManager;
|
|
|
|
|
import android.text.Editable;
|
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
|
import android.widget.CompoundButton;
|
|
|
|
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.app.Dialog;
|
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
@ -150,6 +154,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
private LinearLayout mEditTextList; // 清单模式下的编辑列表容器
|
|
|
|
|
private String mUserQuery; // 搜索查询词(用于高亮显示)
|
|
|
|
|
private Pattern mPattern; // 搜索高亮正则表达式模式
|
|
|
|
|
private TextView mWordCountView; // 字数统计显示控件
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
@ -192,32 +197,33 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
mWorkingNote = null;
|
|
|
|
|
|
|
|
|
|
// 处理查看笔记的意图
|
|
|
|
|
if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
|
|
|
|
|
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
|
|
|
|
|
mUserQuery = "";
|
|
|
|
|
|
|
|
|
|
// 处理从搜索结果打开的情况
|
|
|
|
|
if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {
|
|
|
|
|
noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
|
|
|
|
|
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);
|
|
|
|
|
}
|
|
|
|
|
if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
|
|
|
|
|
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
|
|
|
|
|
mUserQuery = "";
|
|
|
|
|
|
|
|
|
|
// 处理从搜索结果打开的情况
|
|
|
|
|
if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {
|
|
|
|
|
noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
|
|
|
|
|
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查笔记是否存在
|
|
|
|
|
if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) {
|
|
|
|
|
Intent jump = new Intent(this, NotesListActivity.class);
|
|
|
|
|
startActivity(jump);
|
|
|
|
|
showToast(R.string.error_note_not_exist);
|
|
|
|
|
finish();
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
// 加载笔记
|
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);
|
|
|
|
|
if (mWorkingNote == null) {
|
|
|
|
|
Log.e(TAG, "load note failed with note id" + noteId);
|
|
|
|
|
// 检查笔记是否存在
|
|
|
|
|
// 对于回收站中的便签,使用existInNoteDatabase而不是visibleInNoteDatabase
|
|
|
|
|
if (!DataUtils.existInNoteDatabase(getContentResolver(), noteId)) {
|
|
|
|
|
Intent jump = new Intent(this, NotesListActivity.class);
|
|
|
|
|
startActivity(jump);
|
|
|
|
|
showToast(R.string.error_note_not_exist);
|
|
|
|
|
finish();
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
// 加载笔记
|
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);
|
|
|
|
|
if (mWorkingNote == null) {
|
|
|
|
|
Log.e(TAG, "load note failed with note id" + noteId);
|
|
|
|
|
finish();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 隐藏软键盘
|
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
|
|
|
|
|
@ -299,6 +305,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
// 普通模式,显示内容并高亮搜索词
|
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
|
mNoteEditor.setSelection(mNoteEditor.getText().length());
|
|
|
|
|
// 更新字数统计
|
|
|
|
|
updateWordCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 隐藏所有背景选择指示器
|
|
|
|
|
@ -318,6 +326,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
// 显示提醒信息
|
|
|
|
|
showAlertHeader();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -438,6 +447,26 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
|
|
|
|
|
// 初始化字数统计控件
|
|
|
|
|
mWordCountView = (TextView) findViewById(R.id.tv_word_count);
|
|
|
|
|
// 设置文本变化监听器
|
|
|
|
|
mNoteEditor.addTextChangedListener(new TextWatcher() {
|
|
|
|
|
@Override
|
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
|
// 文本变化前的处理,暂不需要
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
|
// 文本变化时更新字数统计
|
|
|
|
|
updateWordCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
|
// 文本变化后的处理,暂不需要
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ -450,6 +479,47 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
clearSettingState(); // 清除设置状态
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新字数统计显示
|
|
|
|
|
*/
|
|
|
|
|
private void updateWordCount() {
|
|
|
|
|
if (mWordCountView != null) {
|
|
|
|
|
String content = getCurrentNoteContent();
|
|
|
|
|
int wordCount = DataUtils.getTotalWordCount(content);
|
|
|
|
|
mWordCountView.setText(getString(R.string.note_word_count, wordCount));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前便签的内容,根据不同模式选择不同的获取方式
|
|
|
|
|
* @return 当前便签的内容
|
|
|
|
|
*/
|
|
|
|
|
private String getCurrentNoteContent() {
|
|
|
|
|
StringBuilder content = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
// 检查当前模式
|
|
|
|
|
if (mNoteEditor.getVisibility() == View.VISIBLE) {
|
|
|
|
|
// 普通模式,直接获取编辑框内容
|
|
|
|
|
content.append(mNoteEditor.getText().toString());
|
|
|
|
|
} else if (mEditTextList.getVisibility() == View.VISIBLE) {
|
|
|
|
|
// 清单模式,收集所有列表项的内容
|
|
|
|
|
for (int i = 0; i < mEditTextList.getChildCount(); i++) {
|
|
|
|
|
View itemView = mEditTextList.getChildAt(i);
|
|
|
|
|
EditText editText = (EditText) itemView.findViewById(R.id.et_edit_text);
|
|
|
|
|
if (editText != null && !TextUtils.isEmpty(editText.getText())) {
|
|
|
|
|
// 添加当前列表项的内容
|
|
|
|
|
content.append(editText.getText().toString());
|
|
|
|
|
// 添加换行符,保持原有格式
|
|
|
|
|
if (i < mEditTextList.getChildCount() - 1) {
|
|
|
|
|
content.append("\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return content.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新桌面小部件
|
|
|
|
|
*/
|
|
|
|
|
@ -573,6 +643,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
} else {
|
|
|
|
|
menu.findItem(R.id.menu_delete_remind).setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据便签的置顶状态设置菜单项标题
|
|
|
|
|
MenuItem pinItem = menu.findItem(R.id.menu_pin_note);
|
|
|
|
|
if (pinItem != null) {
|
|
|
|
|
if (mWorkingNote.isPinned()) {
|
|
|
|
|
pinItem.setTitle(R.string.menu_unpin_note);
|
|
|
|
|
} else {
|
|
|
|
|
pinItem.setTitle(R.string.menu_pin_note);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -597,15 +677,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
getWorkingText();
|
|
|
|
|
sendTo(this, mWorkingNote.getContent());
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_send_to_desktop: // 发送到桌面
|
|
|
|
|
sendToDesktop();
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_alert: // 设置提醒
|
|
|
|
|
setReminder();
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_delete_remind: // 删除提醒
|
|
|
|
|
mWorkingNote.setAlertDate(0, false);
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_pin_note: // 置顶/取消置顶
|
|
|
|
|
mWorkingNote.setPinned(!mWorkingNote.isPinned());
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
@ -681,15 +761,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
} else {
|
|
|
|
|
Log.d(TAG, "Wrong note id, should not happen");
|
|
|
|
|
}
|
|
|
|
|
// 根据同步模式决定删除方式
|
|
|
|
|
if (!isSyncMode()) {
|
|
|
|
|
if (!DataUtils.batchDeleteNotes(getContentResolver(), ids)) {
|
|
|
|
|
Log.e(TAG, "Delete Note error");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!DataUtils.batchMoveToFolder(getContentResolver(), ids, Notes.ID_TRASH_FOLER)) {
|
|
|
|
|
Log.e(TAG, "Move notes to trash folder error, should not happens");
|
|
|
|
|
}
|
|
|
|
|
// 所有模式下,都将删除的笔记移动到回收站
|
|
|
|
|
if (!DataUtils.batchMoveToFolder(getContentResolver(), ids, Notes.ID_TRASH_FOLER)) {
|
|
|
|
|
Log.e(TAG, "Move notes to trash folder error, should not happens");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mWorkingNote.markDeleted(true);
|
|
|
|
|
@ -773,6 +847,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
edit.append(text);
|
|
|
|
|
edit.requestFocus();
|
|
|
|
|
edit.setSelection(length);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -798,6 +873,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
|
|
|
|
.setIndex(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -822,6 +899,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
mNoteEditor.setVisibility(View.GONE); // 隐藏普通编辑框
|
|
|
|
|
mEditTextList.setVisibility(View.VISIBLE); // 显示清单列表
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -877,6 +956,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
item = item.substring(TAG_UNCHECKED.length(), item.length()).trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
edit.setOnTextViewChangeListener(this); // 设置文本变化监听
|
|
|
|
|
edit.setIndex(index); // 设置项目索引
|
|
|
|
|
edit.setText(getHighlightQueryResult(item, mUserQuery)); // 设置文本(支持高亮)
|
|
|
|
|
@ -897,6 +977,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
} else {
|
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
// 更新字数统计
|
|
|
|
|
updateWordCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -917,6 +999,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
mEditTextList.setVisibility(View.GONE);
|
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新字数统计
|
|
|
|
|
updateWordCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -1003,6 +1088,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成快捷方式图标标题
|
|
|
|
|
*/
|
|
|
|
|
|