|
|
|
@ -564,21 +564,36 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Share note to apps that support {@link Intent#ACTION_SEND} action
|
|
|
|
|
* and {@text/plain} type
|
|
|
|
|
* 将指定的文本信息分享到支持 {@link Intent#ACTION_SEND} 操作和 {@text/plain} 类型的应用程序。
|
|
|
|
|
*
|
|
|
|
|
* @param context 上下文对象,用于启动新的 Activity。
|
|
|
|
|
* @param info 要分享的文本信息,将被作为 {@link Intent#EXTRA_TEXT} 传递给目标应用程序。
|
|
|
|
|
*/
|
|
|
|
|
private void sendTo(Context context, String info) {
|
|
|
|
|
// 创建一个新的 Intent,设置操作为 ACTION_SEND,用于分享文本信息
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
|
|
|
|
|
|
// 将要分享的文本信息作为 EXTRA_TEXT 添加到 Intent 中
|
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, info);
|
|
|
|
|
|
|
|
|
|
// 设置 Intent 的 MIME 类型为 text/plain,表示分享的是纯文本
|
|
|
|
|
intent.setType("text/plain");
|
|
|
|
|
|
|
|
|
|
// 启动目标应用程序的 Activity,分享文本信息
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建一个新的笔记。
|
|
|
|
|
* 该函数首先保存当前正在编辑的笔记,然后启动一个新的NoteEditActivity以安全地创建新笔记。
|
|
|
|
|
* 通过调用finish()结束当前Activity,并传递必要的Intent参数来启动新的NoteEditActivity。
|
|
|
|
|
*/
|
|
|
|
|
private void createNewNote() {
|
|
|
|
|
// Firstly, save current editing notes
|
|
|
|
|
// 首先保存当前正在编辑的笔记,确保数据不会丢失
|
|
|
|
|
saveNote();
|
|
|
|
|
|
|
|
|
|
// For safety, start a new NoteEditActivity
|
|
|
|
|
// 结束当前Activity,并启动一个新的NoteEditActivity以创建新笔记
|
|
|
|
|
finish();
|
|
|
|
|
Intent intent = new Intent(this, NoteEditActivity.class);
|
|
|
|
|
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
|
|
|
|
@ -586,25 +601,44 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除当前正在处理的笔记。如果笔记存在于数据库中,则根据同步模式决定是直接删除还是移动到回收站。
|
|
|
|
|
* 如果笔记不存在于数据库中,则仅标记为已删除状态。
|
|
|
|
|
*
|
|
|
|
|
* 该函数首先检查笔记是否存在于数据库中。如果存在,则根据笔记ID决定是否将其添加到待删除的ID集合中。
|
|
|
|
|
* 如果当前不在同步模式,则直接批量删除这些笔记;如果在同步模式,则将笔记移动到回收站。
|
|
|
|
|
* 最后,无论笔记是否存在于数据库中,都会将其标记为已删除状态。
|
|
|
|
|
*/
|
|
|
|
|
private void deleteCurrentNote() {
|
|
|
|
|
// 检查当前笔记是否存在于数据库中
|
|
|
|
|
if (mWorkingNote.existInDatabase()) {
|
|
|
|
|
// 创建一个HashSet来存储待删除的笔记ID
|
|
|
|
|
HashSet<Long> ids = new HashSet<Long>();
|
|
|
|
|
long id = mWorkingNote.getNoteId();
|
|
|
|
|
|
|
|
|
|
// 如果笔记ID不是根文件夹的ID,则将其添加到待删除的ID集合中
|
|
|
|
|
if (id != Notes.ID_ROOT_FOLDER) {
|
|
|
|
|
ids.add(id);
|
|
|
|
|
} else {
|
|
|
|
|
// 如果笔记ID是根文件夹的ID,则记录错误日志
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 无论笔记是否存在于数据库中,都将其标记为已删除状态
|
|
|
|
|
mWorkingNote.markDeleted(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -612,14 +646,27 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理闹钟提醒的更改事件。
|
|
|
|
|
* 根据传入的日期和设置状态,为当前笔记设置或取消闹钟提醒。
|
|
|
|
|
* 如果笔记尚未保存到数据库,则先保存笔记。
|
|
|
|
|
*
|
|
|
|
|
* @param date 闹钟提醒的日期和时间,以毫秒为单位的时间戳
|
|
|
|
|
* @param set 是否设置闹钟提醒,true 表示设置,false 表示取消
|
|
|
|
|
*/
|
|
|
|
|
public void onClockAlertChanged(long date, boolean set) {
|
|
|
|
|
/**
|
|
|
|
|
* User could set clock to an unsaved note, so before setting the
|
|
|
|
|
* alert clock, we should save the note first
|
|
|
|
|
* 如果当前笔记尚未保存到数据库,则先保存笔记。
|
|
|
|
|
* 因为用户可能会为未保存的笔记设置闹钟提醒,所以需要确保笔记已保存。
|
|
|
|
|
*/
|
|
|
|
|
if (!mWorkingNote.existInDatabase()) {
|
|
|
|
|
saveNote();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 如果笔记已保存(即笔记ID大于0),则根据设置状态设置或取消闹钟提醒。
|
|
|
|
|
* 使用 AlarmManager 来管理闹钟,并通过 PendingIntent 触发 AlarmReceiver。
|
|
|
|
|
*/
|
|
|
|
|
if (mWorkingNote.getNoteId() > 0) {
|
|
|
|
|
Intent intent = new Intent(this, AlarmReceiver.class);
|
|
|
|
|
intent.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mWorkingNote.getNoteId()));
|
|
|
|
@ -633,9 +680,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/**
|
|
|
|
|
* There is the condition that user has input nothing (the note is
|
|
|
|
|
* not worthy saving), we have no note id, remind the user that he
|
|
|
|
|
* should input something
|
|
|
|
|
* 如果笔记尚未保存且用户未输入任何内容(笔记不值得保存),
|
|
|
|
|
* 则提醒用户需要输入内容才能设置闹钟提醒。
|
|
|
|
|
*/
|
|
|
|
|
Log.e(TAG, "Clock alert setting error");
|
|
|
|
|
showToast(R.string.error_note_empty_for_clock);
|
|
|
|
@ -646,18 +692,30 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
updateWidget();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理编辑文本删除操作。
|
|
|
|
|
* 当删除某个编辑框时,调整后续编辑框的索引,并将删除的文本内容追加到前一个或后一个编辑框中。
|
|
|
|
|
*
|
|
|
|
|
* @param index 被删除的编辑框的索引
|
|
|
|
|
* @param text 被删除的文本内容
|
|
|
|
|
*/
|
|
|
|
|
public void onEditTextDelete(int index, String text) {
|
|
|
|
|
int childCount = mEditTextList.getChildCount();
|
|
|
|
|
// 如果只有一个编辑框,直接返回,不允许删除
|
|
|
|
|
if (childCount == 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 调整后续编辑框的索引
|
|
|
|
|
for (int i = index + 1; i < childCount; i++) {
|
|
|
|
|
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
|
|
|
|
.setIndex(i - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 移除指定索引的编辑框
|
|
|
|
|
mEditTextList.removeViewAt(index);
|
|
|
|
|
|
|
|
|
|
// 获取前一个或后一个编辑框,并将删除的文本内容追加到其中
|
|
|
|
|
NoteEditText edit = null;
|
|
|
|
|
if(index == 0) {
|
|
|
|
|
edit = (NoteEditText) mEditTextList.getChildAt(0).findViewById(
|
|
|
|
|