Update NoteEditActivity.java

wuji_branch
pi7yb2crf 8 months ago
parent 86791ded6d
commit 457809684e

@ -291,111 +291,161 @@ public class NoteEditActivity extends Activity implements OnClickListener,
ResourceParser.getDefaultBgId(this));
// 解析通话记录笔记
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);
if (callDate != 0 && phoneNumber != null) {
if (TextUtils.isEmpty(phoneNumber)) {
Log.w(TAG, "The call record number is null");
}
long noteId = 0;
if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(),
phoneNumber, callDate)) > 0) {
mWorkingNote = WorkingNote.load(this, noteId);
if (mWorkingNote == null) {
Log.e(TAG, "load call note failed with note id" + noteId);
finish();
return false;
}
} else {
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId,
widgetType, bgResId);
mWorkingNote.convertToCallNote(phoneNumber, callDate);
}
} else {
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType,
bgResId);
}
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
} else {
Log.e(TAG, "Intent not specified action, should not support");
// 从传入的 Intent 中获取电话号码
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
// 从传入的 Intent 中获取通话日期,若不存在则返回默认值 0
long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);
// 如果通话日期不为 0 且电话号码不为 null
if (callDate!= 0 && phoneNumber!= null) {
// 如果电话号码为空字符串
if (TextUtils.isEmpty(phoneNumber)) {
// 打印警告日志,提示通话记录号码为空
Log.w(TAG, "The call record number is null");
}
// 初始化笔记 ID 为 0
long noteId = 0;
// 通过电话号码和通话日期从内容解析器中获取笔记 ID
// 如果获取到的笔记 ID 大于 0
if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(),
phoneNumber, callDate)) > 0) {
// 根据笔记 ID 加载工作笔记
mWorkingNote = WorkingNote.load(this, noteId);
// 如果加载的工作笔记为 null
if (mWorkingNote == null) {
// 打印错误日志,提示加载通话笔记失败
Log.e(TAG, "load call note failed with note id" + noteId);
// 结束当前活动
finish();
// 返回 false 表示操作失败
return false;
}
mWorkingNote.setOnSettingStatusChangedListener(this);
return true;
} else {
// 创建一个空笔记
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId,
widgetType, bgResId);
// 将空笔记转换为通话笔记
mWorkingNote.convertToCallNote(phoneNumber, callDate);
}
} else {
// 创建一个空笔记
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType,
bgResId);
}
// 设置窗口的软键盘模式,调整布局大小并使其可见
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
} else {
// 打印错误日志,提示 Intent 未指定支持的操作
Log.e(TAG, "Intent not specified action, should not support");
// 结束当前活动
finish();
// 返回 false 表示操作失败
return false;
}
// 为工作笔记设置状态改变监听器
mWorkingNote.setOnSettingStatusChangedListener(this);
// 返回 true 表示操作成功
return true;
}
/**
* onResume
*/
@Override
protected void onResume() {
super.onResume();
initNoteScreen();
}
/**
* initNoteScreen
*/
private void initNoteScreen() {
mNoteEditor.setTextAppearance(this, TextAppearanceResources
.getTexAppearanceResource(mFontSizeId));
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
switchToListMode(mWorkingNote.getContent());
} else {
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
mNoteEditor.setSelection(mNoteEditor.getText().length());
}
for (Integer id : sBgSelectorSelectionMap.keySet()) {
findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);
}
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
| DateUtils.FORMAT_SHOW_YEAR));
/**
* onResume
*/
// 重写 onResume 方法
@Override
protected void onResume() {
// 调用父类的 onResume 方法
super.onResume();
// 初始化笔记屏幕
initNoteScreen();
}
/**
* TODO: Add the menu for setting alert. Currently disable it because the DateTimePicker
* is not ready
*/
showAlertHeader();
/**
* initNoteScreen
*/
// 定义初始化笔记屏幕的方法
private void initNoteScreen() {
// 设置笔记编辑器的文本外观
mNoteEditor.setTextAppearance(this, TextAppearanceResources
.getTexAppearanceResource(mFontSizeId));
// 如果工作笔记的清单模式为列表模式
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
// 切换到列表模式并设置内容
switchToListMode(mWorkingNote.getContent());
} else {
// 获取高亮显示查询结果后的文本内容
// 并设置到笔记编辑器中
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
// 将光标移动到文本末尾
mNoteEditor.setSelection(mNoteEditor.getText().length());
}
/**
* showAlertHeader
*/
private void showAlertHeader() {
if (mWorkingNote.hasClockAlert()) {
long time = System.currentTimeMillis();
if (time > mWorkingNote.getAlertDate()) {
mNoteHeaderHolder.tvAlertDate.setText(R.string.note_alert_expired);
} else {
mNoteHeaderHolder.tvAlertDate.setText(DateUtils.getRelativeTimeSpanString(
mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS));
}
mNoteHeaderHolder.tvAlertDate.setVisibility(View.VISIBLE);
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.VISIBLE);
} else {
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
};
// 遍历背景选择器选中状态映射的键集
for (Integer id : sBgSelectorSelectionMap.keySet()) {
// 获取对应键的视图并设置为不可见
findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);
}
// 设置头部视图面板的背景资源
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
| DateUtils.FORMAT_SHOW_YEAR));
/**
* onNewIntent Intent
* TODO: Add the menu for setting alert. Currently disable it because the DateTimePicker
* is not ready
*/
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
initActivityState(intent);
// 显示提醒头部
showAlertHeader();
}
/**
* showAlertHeader
*/
// 定义显示提醒头部的方法
private void showAlertHeader() {
// 如果工作笔记设置了提醒
if (mWorkingNote.hasClockAlert()) {
// 获取当前系统时间
long time = System.currentTimeMillis();
// 如果当前时间大于提醒日期
if (time > mWorkingNote.getAlertDate()) {
// 设置提醒日期文本为提醒已过期
mNoteHeaderHolder.tvAlertDate.setText(R.string.note_alert_expired);
} else {
// 设置提醒日期文本为相对时间跨度字符串
mNoteHeaderHolder.tvAlertDate.setText(DateUtils.getRelativeTimeSpanString(
mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS));
}
// 设置提醒日期文本视图为可见
mNoteHeaderHolder.tvAlertDate.setVisibility(View.VISIBLE);
// 设置提醒图标视图为可见
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.VISIBLE);
} else {
// 设置提醒日期文本视图为不可见
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
// 设置提醒图标视图为不可见
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
}
}
/**
* onNewIntent Intent
*/
// 重写 onNewIntent 方法
@Override
protected void onNewIntent(Intent intent) {
// 调用父类的 onNewIntent 方法
super.onNewIntent(intent);
// 重新初始化活动状态
initActivityState(intent);
}
/**
* onSaveInstanceState 便
*/
@ -820,7 +870,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
int index = 0;
for (String item : items) {
if(!TextUtils.isEmpty(item)) {
mEditTextList.addView(getListItem(item, index));
mEditTextList.addView(getListItem(item, index)
index++;
}
}

Loading…
Cancel
Save