|
|
|
|
@ -46,6 +46,9 @@ import android.view.View.OnClickListener;
|
|
|
|
|
import android.view.WindowManager;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
import android.util.TypedValue;
|
|
|
|
|
import android.widget.CompoundButton;
|
|
|
|
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
@ -172,6 +175,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
/** 笔记编辑面板 */
|
|
|
|
|
private View mNoteEditorPanel;
|
|
|
|
|
|
|
|
|
|
/** 字符统计显示文本框 */
|
|
|
|
|
private TextView mTvCharCount;
|
|
|
|
|
|
|
|
|
|
/** 工作笔记对象,用于处理笔记数据 */
|
|
|
|
|
private WorkingNote mWorkingNote;
|
|
|
|
|
|
|
|
|
|
@ -350,6 +356,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(htmlContent, mUserQuery));
|
|
|
|
|
mNoteEditor.setSelection(mNoteEditor.getText().length());
|
|
|
|
|
}
|
|
|
|
|
// 初始化字符统计显示
|
|
|
|
|
updateCharCount();
|
|
|
|
|
for (Integer id : sBgSelectorSelectionMap.keySet()) {
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
@ -480,7 +488,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
mNoteHeaderHolder.ibSetBgColor = (ImageButton) findViewById(R.id.btn_set_bg_color);
|
|
|
|
|
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
|
|
|
|
|
mNoteEditor = (NoteEditText) findViewById(R.id.note_edit_view);
|
|
|
|
|
mNoteEditor.setOnTextViewChangeListener(this);
|
|
|
|
|
mNoteEditorPanel = findViewById(R.id.sv_note_edit);
|
|
|
|
|
mTvCharCount = (TextView) findViewById(R.id.tv_char_count);
|
|
|
|
|
mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector);
|
|
|
|
|
for (int id : sBgSelectorBtnsMap.keySet()) {
|
|
|
|
|
ImageView iv = (ImageView) findViewById(id);
|
|
|
|
|
@ -768,6 +778,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
case R.id.menu_unlock:
|
|
|
|
|
showPasswordDialogForUnlock();
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_change_password:
|
|
|
|
|
showChangePasswordDialog();
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_note_template:
|
|
|
|
|
openTemplateSelector();
|
|
|
|
|
break;
|
|
|
|
|
@ -812,23 +825,41 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
/**
|
|
|
|
|
* 显示密码输入对话框用于锁定笔记
|
|
|
|
|
* <p>
|
|
|
|
|
* 该方法用于显示一个密码输入对话框,让用户输入密码来锁定当前编辑的笔记
|
|
|
|
|
* 该方法用于显示一个密码输入对话框,让用户输入密码和密码提示来锁定当前编辑的笔记
|
|
|
|
|
* </p>
|
|
|
|
|
*/
|
|
|
|
|
private void showPasswordDialogForLock() {
|
|
|
|
|
// 创建布局并添加密码输入框
|
|
|
|
|
LinearLayout layout = new LinearLayout(this);
|
|
|
|
|
layout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
layout.setPadding(60, 40, 60, 40);
|
|
|
|
|
layout.setPadding(60, 40, 60, 40);
|
|
|
|
|
// 设置子视图间距
|
|
|
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
|
|
params.setMargins(0, 0, 0, 20); // 底部外边距作为间距
|
|
|
|
|
|
|
|
|
|
final EditText passwordEditText = new EditText(this);
|
|
|
|
|
passwordEditText.setHint(R.string.hint_enter_password);
|
|
|
|
|
passwordEditText.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
|
|
|
|
layout.addView(passwordEditText);
|
|
|
|
|
|
|
|
|
|
// 添加密码提示输入框
|
|
|
|
|
final EditText hintEditText = new EditText(this);
|
|
|
|
|
hintEditText.setHint(R.string.hint_enter_password_hint);
|
|
|
|
|
layout.addView(hintEditText);
|
|
|
|
|
|
|
|
|
|
new AlertDialog.Builder(this)
|
|
|
|
|
.setTitle(R.string.dialog_enter_password)
|
|
|
|
|
.setView(passwordEditText)
|
|
|
|
|
.setView(layout)
|
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
String password = passwordEditText.getText().toString();
|
|
|
|
|
String hint = hintEditText.getText().toString();
|
|
|
|
|
if (!TextUtils.isEmpty(password)) {
|
|
|
|
|
lockCurrentNote(password);
|
|
|
|
|
lockCurrentNote(password, hint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
@ -843,13 +874,50 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
* </p>
|
|
|
|
|
*/
|
|
|
|
|
private void showPasswordDialogForUnlock() {
|
|
|
|
|
// 查询当前笔记的密码提示
|
|
|
|
|
String[] projection = {NoteColumns.LOCK_HINT};
|
|
|
|
|
String selection = NoteColumns.ID + "=?";
|
|
|
|
|
String[] selectionArgs = {String.valueOf(mWorkingNote.getNoteId())};
|
|
|
|
|
|
|
|
|
|
Cursor cursor = getContentResolver().query(Notes.CONTENT_NOTE_URI, projection, selection, selectionArgs, null);
|
|
|
|
|
String lockHint = null;
|
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
|
lockHint = cursor.getString(0);
|
|
|
|
|
cursor.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建布局并添加密码输入框
|
|
|
|
|
LinearLayout layout = new LinearLayout(this);
|
|
|
|
|
layout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
layout.setPadding(60, 40, 60, 40);
|
|
|
|
|
|
|
|
|
|
// 创建布局参数,用于设置子视图间距
|
|
|
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
|
|
params.setMargins(0, 0, 0, 20); // 底部外边距作为间距
|
|
|
|
|
|
|
|
|
|
final EditText passwordEditText = new EditText(this);
|
|
|
|
|
passwordEditText.setHint(R.string.hint_enter_password);
|
|
|
|
|
passwordEditText.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
|
|
|
|
layout.addView(passwordEditText, params);
|
|
|
|
|
|
|
|
|
|
// 如果有密码提示,显示提示信息
|
|
|
|
|
if (!TextUtils.isEmpty(lockHint)) {
|
|
|
|
|
TextView hintTextView = new TextView(this);
|
|
|
|
|
hintTextView.setText(getString(R.string.password_hint_prefix) + lockHint);
|
|
|
|
|
hintTextView.setTextColor(getResources().getColor(R.color.secondary_text_dark));
|
|
|
|
|
hintTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
|
|
|
|
|
// 提示文本不需要底部间距
|
|
|
|
|
LinearLayout.LayoutParams hintParams = new LinearLayout.LayoutParams(
|
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
|
|
layout.addView(hintTextView, hintParams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new AlertDialog.Builder(this)
|
|
|
|
|
.setTitle(R.string.dialog_enter_password)
|
|
|
|
|
.setView(passwordEditText)
|
|
|
|
|
.setView(layout)
|
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
@ -866,17 +934,20 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
/**
|
|
|
|
|
* 锁定当前笔记
|
|
|
|
|
* <p>
|
|
|
|
|
* 该方法用于锁定当前编辑的笔记,更新其锁定状态、密码和锁定类型
|
|
|
|
|
* 该方法用于锁定当前编辑的笔记,更新其锁定状态、密码、密码提示和锁定类型
|
|
|
|
|
* </p>
|
|
|
|
|
* @param password 用于锁定的密码
|
|
|
|
|
* @param hint 用于帮助记忆密码的提示
|
|
|
|
|
*/
|
|
|
|
|
private void lockCurrentNote(String password) {
|
|
|
|
|
private void lockCurrentNote(String password, String hint) {
|
|
|
|
|
// 设置锁定状态为1(已锁定)
|
|
|
|
|
mWorkingNote.setNoteValue(NoteColumns.IS_LOCKED, "1");
|
|
|
|
|
// 设置加密后的密码
|
|
|
|
|
mWorkingNote.setNoteValue(NoteColumns.LOCK_PASSWORD, encryptPassword(password));
|
|
|
|
|
// 设置锁定类型为笔记类型
|
|
|
|
|
mWorkingNote.setNoteValue(NoteColumns.LOCK_TYPE, String.valueOf(Notes.LOCK_TYPE_NOTE));
|
|
|
|
|
// 设置密码提示
|
|
|
|
|
mWorkingNote.setNoteValue(NoteColumns.LOCK_HINT, hint);
|
|
|
|
|
// 保存笔记
|
|
|
|
|
saveNote();
|
|
|
|
|
// 显示提示信息
|
|
|
|
|
@ -941,6 +1012,97 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return password; // 加密失败时返回原始密码
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示修改密码对话框
|
|
|
|
|
* <p>
|
|
|
|
|
* 该方法用于显示一个修改密码对话框,让用户输入旧密码、新密码和新的密码提示
|
|
|
|
|
* </p>
|
|
|
|
|
*/
|
|
|
|
|
private void showChangePasswordDialog() {
|
|
|
|
|
// 创建布局并添加输入框
|
|
|
|
|
LinearLayout layout = new LinearLayout(this);
|
|
|
|
|
layout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
layout.setPadding(60, 40, 60, 40);
|
|
|
|
|
|
|
|
|
|
// 创建布局参数,用于设置子视图间距
|
|
|
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
|
|
params.setMargins(0, 0, 0, 20); // 底部外边距作为间距
|
|
|
|
|
|
|
|
|
|
// 旧密码输入框
|
|
|
|
|
final EditText oldPasswordEditText = new EditText(this);
|
|
|
|
|
oldPasswordEditText.setHint(R.string.hint_enter_password);
|
|
|
|
|
oldPasswordEditText.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
|
|
|
|
layout.addView(oldPasswordEditText, params);
|
|
|
|
|
|
|
|
|
|
// 新密码输入框
|
|
|
|
|
final EditText newPasswordEditText = new EditText(this);
|
|
|
|
|
newPasswordEditText.setHint(R.string.hint_enter_password);
|
|
|
|
|
newPasswordEditText.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
|
|
|
|
layout.addView(newPasswordEditText, params);
|
|
|
|
|
|
|
|
|
|
// 新密码提示输入框
|
|
|
|
|
final EditText newHintEditText = new EditText(this);
|
|
|
|
|
newHintEditText.setHint(R.string.hint_enter_password_hint);
|
|
|
|
|
layout.addView(newHintEditText);
|
|
|
|
|
|
|
|
|
|
new AlertDialog.Builder(this)
|
|
|
|
|
.setTitle(R.string.menu_change_password)
|
|
|
|
|
.setView(layout)
|
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
String oldPassword = oldPasswordEditText.getText().toString();
|
|
|
|
|
String newPassword = newPasswordEditText.getText().toString();
|
|
|
|
|
String newHint = newHintEditText.getText().toString();
|
|
|
|
|
if (!TextUtils.isEmpty(oldPassword) && !TextUtils.isEmpty(newPassword)) {
|
|
|
|
|
changePassword(oldPassword, newPassword, newHint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
|
.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改密码
|
|
|
|
|
* <p>
|
|
|
|
|
* 该方法用于修改当前笔记的密码,需要验证旧密码,验证通过后更新新密码和密码提示
|
|
|
|
|
* </p>
|
|
|
|
|
* @param oldPassword 旧密码
|
|
|
|
|
* @param newPassword 新密码
|
|
|
|
|
* @param newHint 新的密码提示
|
|
|
|
|
*/
|
|
|
|
|
private void changePassword(String oldPassword, String newPassword, String newHint) {
|
|
|
|
|
// 使用ContentResolver直接查询数据库获取加密密码
|
|
|
|
|
String[] projection = {NoteColumns.LOCK_PASSWORD};
|
|
|
|
|
String selection = NoteColumns.ID + "=?";
|
|
|
|
|
String[] selectionArgs = {String.valueOf(mWorkingNote.getNoteId())};
|
|
|
|
|
|
|
|
|
|
Cursor cursor = getContentResolver().query(Notes.CONTENT_NOTE_URI, projection, selection, selectionArgs, null);
|
|
|
|
|
String encryptedPassword = null;
|
|
|
|
|
|
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
|
encryptedPassword = cursor.getString(0);
|
|
|
|
|
cursor.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 验证旧密码是否正确
|
|
|
|
|
if (encryptedPassword != null && encryptedPassword.equals(encryptPassword(oldPassword))) {
|
|
|
|
|
// 旧密码正确,更新新密码和密码提示
|
|
|
|
|
mWorkingNote.setNoteValue(NoteColumns.LOCK_PASSWORD, encryptPassword(newPassword));
|
|
|
|
|
mWorkingNote.setNoteValue(NoteColumns.LOCK_HINT, newHint);
|
|
|
|
|
// 保存笔记
|
|
|
|
|
saveNote();
|
|
|
|
|
// 显示提示信息
|
|
|
|
|
Toast.makeText(this, getString(R.string.message_password_changed), Toast.LENGTH_SHORT).show();
|
|
|
|
|
} else {
|
|
|
|
|
// 旧密码错误,显示错误信息
|
|
|
|
|
Toast.makeText(this, getString(R.string.error_wrong_password), Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建新笔记
|
|
|
|
|
@ -1229,6 +1391,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
} else {
|
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
// 更新字符统计
|
|
|
|
|
updateCharCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 当文本内容变化时,更新字符统计
|
|
|
|
|
*/
|
|
|
|
|
public void onContentChange() {
|
|
|
|
|
updateCharCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -1382,6 +1553,45 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
showToast(resId, Toast.LENGTH_SHORT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 计算字符串中的有效字符数(不包括空格、换行符等空白字符)
|
|
|
|
|
* @param text 要计算的字符串
|
|
|
|
|
* @return 有效字符数
|
|
|
|
|
*/
|
|
|
|
|
private int countValidCharacters(String text) {
|
|
|
|
|
if (TextUtils.isEmpty(text)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
// 去除所有空白字符后计算长度
|
|
|
|
|
return text.replaceAll("\\s", "").length();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新字符统计显示
|
|
|
|
|
*/
|
|
|
|
|
private void updateCharCount() {
|
|
|
|
|
int charCount = 0;
|
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
|
// 列表模式:遍历所有列表项
|
|
|
|
|
for (int i = 0; i < mEditTextList.getChildCount(); i++) {
|
|
|
|
|
View view = mEditTextList.getChildAt(i);
|
|
|
|
|
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
|
if (!TextUtils.isEmpty(edit.getText())) {
|
|
|
|
|
charCount += countValidCharacters(edit.getText().toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 普通文本模式:直接计算编辑框内容
|
|
|
|
|
if (!TextUtils.isEmpty(mNoteEditor.getText())) {
|
|
|
|
|
charCount = countValidCharacters(mNoteEditor.getText().toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 更新显示
|
|
|
|
|
if (mTvCharCount != null) {
|
|
|
|
|
mTvCharCount.setText(charCount + " 字符");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 打开模板选择页面
|
|
|
|
|
* <p>
|
|
|
|
|
|