|
|
|
@ -71,19 +71,25 @@ import java.util.Map;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NoteEditActivity 是用于编辑笔记的活动类。它允许用户创建、修改、删除笔记,设置提醒,以及将笔记发送到桌面或分享给他人。
|
|
|
|
|
*/
|
|
|
|
|
public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
NoteSettingChangedListener, OnTextViewChangeListener {
|
|
|
|
|
private class HeadViewHolder {
|
|
|
|
|
public TextView tvModified;
|
|
|
|
|
|
|
|
|
|
public ImageView ivAlertIcon;
|
|
|
|
|
|
|
|
|
|
public TextView tvAlertDate;
|
|
|
|
|
|
|
|
|
|
public ImageView ibSetBgColor;
|
|
|
|
|
/**
|
|
|
|
|
* HeadViewHolder 是一个内部类,用于持有头部的视图组件,如修改日期、提醒图标和日期。
|
|
|
|
|
*/
|
|
|
|
|
private class HeadViewHolder {
|
|
|
|
|
public TextView tvModified; // 显示修改日期的 TextView
|
|
|
|
|
public ImageView ivAlertIcon; // 显示提醒图标的 ImageView
|
|
|
|
|
public TextView tvAlertDate; // 显示提醒日期的 TextView
|
|
|
|
|
public ImageView ibSetBgColor; // 设置背景颜色的 ImageView
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* sBgSelectorBtnsMap 是一个静态的 HashMap,用于将背景颜色选择按钮的 ID 映射到对应的颜色资源 ID。
|
|
|
|
|
*/
|
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
|
static {
|
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
|
|
|
|
@ -93,6 +99,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_white, ResourceParser.WHITE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* sBgSelectorSelectionMap 是一个静态的 HashMap,用于将颜色资源 ID 映射到对应的选中状态按钮的 ID。
|
|
|
|
|
*/
|
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
|
static {
|
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select);
|
|
|
|
@ -102,6 +111,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.WHITE, R.id.iv_bg_white_select);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* sFontSizeBtnsMap 是一个静态的 HashMap,用于将字体大小选择按钮的 ID 映射到对应的字体大小资源 ID。
|
|
|
|
|
*/
|
|
|
|
|
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
|
static {
|
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE);
|
|
|
|
@ -110,6 +122,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_super, ResourceParser.TEXT_SUPER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* sFontSelectorSelectionMap 是一个静态的 HashMap,用于将字体大小资源 ID 映射到对应的选中状态按钮的 ID。
|
|
|
|
|
*/
|
|
|
|
|
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
|
static {
|
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select);
|
|
|
|
@ -118,37 +133,90 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SUPER, R.id.iv_super_select);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TAG 是一个静态常量,用于日志记录。
|
|
|
|
|
*/
|
|
|
|
|
private static final String TAG = "NoteEditActivity";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* mNoteHeaderHolder 是 HeadViewHolder 的实例,用于持有头部的视图组件。
|
|
|
|
|
*/
|
|
|
|
|
private HeadViewHolder mNoteHeaderHolder;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* mHeadViewPanel 是头部的面板视图。
|
|
|
|
|
*/
|
|
|
|
|
private View mHeadViewPanel;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* mNoteBgColorSelector 是用于选择背景颜色的面板视图。
|
|
|
|
|
*/
|
|
|
|
|
private View mNoteBgColorSelector;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* mFontSizeSelector 是用于选择字体大小的面板视图。
|
|
|
|
|
*/
|
|
|
|
|
private View mFontSizeSelector;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* mNoteEditor 是用于编辑笔记内容的 EditText。
|
|
|
|
|
*/
|
|
|
|
|
private EditText mNoteEditor;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* mNoteEditorPanel 是编辑笔记内容的面板视图。
|
|
|
|
|
*/
|
|
|
|
|
private View mNoteEditorPanel;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* mWorkingNote 是当前正在编辑的 WorkingNote 实例。
|
|
|
|
|
*/
|
|
|
|
|
private WorkingNote mWorkingNote;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* mSharedPrefs 是 SharedPreferences 的实例,用于存储用户偏好设置。
|
|
|
|
|
*/
|
|
|
|
|
private SharedPreferences mSharedPrefs;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* mFontSizeId 是当前选中的字体大小资源 ID。
|
|
|
|
|
*/
|
|
|
|
|
private int mFontSizeId;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* PREFERENCE_FONT_SIZE 是存储字体大小偏好设置的键。
|
|
|
|
|
*/
|
|
|
|
|
private static final String PREFERENCE_FONT_SIZE = "pref_font_size";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SHORTCUT_ICON_TITLE_MAX_LEN 是快捷方式图标标题的最大长度。
|
|
|
|
|
*/
|
|
|
|
|
private static final int SHORTCUT_ICON_TITLE_MAX_LEN = 10;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TAG_CHECKED 和 TAG_UNCHECKED 是用于表示复选框状态的标签。
|
|
|
|
|
*/
|
|
|
|
|
public static final String TAG_CHECKED = String.valueOf('\u221A');
|
|
|
|
|
public static final String TAG_UNCHECKED = String.valueOf('\u25A1');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* mEditTextList 是包含多个 NoteEditText 的 LinearLayout,用于编辑列表模式的笔记。
|
|
|
|
|
*/
|
|
|
|
|
private LinearLayout mEditTextList;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* mUserQuery 是用户查询的字符串,用于高亮显示搜索结果。
|
|
|
|
|
*/
|
|
|
|
|
private String mUserQuery;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* mPattern 是用于匹配用户查询的正则表达式模式。
|
|
|
|
|
*/
|
|
|
|
|
private Pattern mPattern;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onCreate 方法是活动的入口点,负责初始化活动状态和资源。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
@ -162,8 +230,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Current activity may be killed when the memory is low. Once it is killed, for another time
|
|
|
|
|
* user load this activity, we should restore the former state
|
|
|
|
|
* onRestoreInstanceState 方法用于恢复活动状态。如果活动被系统杀死并重新创建,则从保存的状态中恢复。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
|
|
|
@ -179,19 +246,18 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* initActivityState 方法用于根据传入的 Intent 初始化活动状态。如果用户指定了 ACTION_VIEW 但未提供 ID,则跳转到 NotesListActivity。
|
|
|
|
|
*
|
|
|
|
|
* @param intent 传入的 Intent
|
|
|
|
|
* @return 如果初始化成功则返回 true,否则返回 false
|
|
|
|
|
*/
|
|
|
|
|
private boolean initActivityState(Intent intent) {
|
|
|
|
|
/**
|
|
|
|
|
* If the user specified the {@link Intent#ACTION_VIEW} but not provided with id,
|
|
|
|
|
* then jump to the NotesListActivity
|
|
|
|
|
*/
|
|
|
|
|
mWorkingNote = null;
|
|
|
|
|
if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
|
|
|
|
|
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
|
|
|
|
|
mUserQuery = "";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Starting from the searched result
|
|
|
|
|
*/
|
|
|
|
|
if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {
|
|
|
|
|
noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
|
|
|
|
|
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);
|
|
|
|
@ -215,7 +281,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
|
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
|
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
|
|
|
|
|
// New note
|
|
|
|
|
// 新笔记
|
|
|
|
|
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
|
|
|
|
|
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
|
|
|
|
|
AppWidgetManager.INVALID_APPWIDGET_ID);
|
|
|
|
@ -224,7 +290,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID,
|
|
|
|
|
ResourceParser.getDefaultBgId(this));
|
|
|
|
|
|
|
|
|
|
// Parse call-record note
|
|
|
|
|
// 解析通话记录笔记
|
|
|
|
|
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
|
|
|
|
|
long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);
|
|
|
|
|
if (callDate != 0 && phoneNumber != null) {
|
|
|
|
@ -262,12 +328,18 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onResume 方法在活动恢复时调用,初始化笔记屏幕。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
initNoteScreen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* initNoteScreen 方法用于初始化笔记屏幕,包括设置文本外观、切换到列表模式或高亮显示查询结果。
|
|
|
|
|
*/
|
|
|
|
|
private void initNoteScreen() {
|
|
|
|
|
mNoteEditor.setTextAppearance(this, TextAppearanceResources
|
|
|
|
|
.getTexAppearanceResource(mFontSizeId));
|
|
|
|
@ -295,6 +367,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
showAlertHeader();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* showAlertHeader 方法用于显示提醒头部的信息。如果设置了提醒,则显示提醒日期,否则隐藏。
|
|
|
|
|
*/
|
|
|
|
|
private void showAlertHeader() {
|
|
|
|
|
if (mWorkingNote.hasClockAlert()) {
|
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
@ -312,20 +387,21 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onNewIntent 方法在活动接收到新的 Intent 时调用,重新初始化活动状态。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
|
initActivityState(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onSaveInstanceState 方法用于保存活动状态,以便在活动被系统杀死后恢复。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
|
/**
|
|
|
|
|
* For new note without note id, we should firstly save it to
|
|
|
|
|
* generate a id. If the editing note is not worth saving, there
|
|
|
|
|
* is no id which is equivalent to create new note
|
|
|
|
|
*/
|
|
|
|
|
if (!mWorkingNote.existInDatabase()) {
|
|
|
|
|
saveNote();
|
|
|
|
|
}
|
|
|
|
@ -333,6 +409,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
Log.d(TAG, "Save working note id: " + mWorkingNote.getNoteId() + " onSaveInstanceState");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* dispatchTouchEvent 方法用于处理触摸事件。当点击区域不在背景颜色选择器或字体大小选择器内时,隐藏选择器。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
|
|
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE
|
|
|
|
@ -349,6 +428,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return super.dispatchTouchEvent(ev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* inRangeOfView 方法用于判断触摸点是否在指定视图的范围内。
|
|
|
|
|
*/
|
|
|
|
|
private boolean inRangeOfView(View view, MotionEvent ev) {
|
|
|
|
|
int []location = new int[2];
|
|
|
|
|
view.getLocationOnScreen(location);
|
|
|
|
@ -358,11 +440,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|| ev.getX() > (x + view.getWidth())
|
|
|
|
|
|| ev.getY() < y
|
|
|
|
|
|| ev.getY() > (y + view.getHeight())) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* initResources 方法用于初始化资源,包括头部视图、背景颜色选择器、字体大小选择器等。
|
|
|
|
|
*/
|
|
|
|
|
private void initResources() {
|
|
|
|
|
mHeadViewPanel = findViewById(R.id.note_title);
|
|
|
|
|
mNoteHeaderHolder = new HeadViewHolder();
|
|
|
|
@ -397,6 +482,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onPause 方法在活动暂停时调用,保存笔记数据并清除设置状态。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onPause() {
|
|
|
|
|
super.onPause();
|
|
|
|
@ -406,6 +494,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
clearSettingState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* updateWidget 方法用于更新小部件。
|
|
|
|
|
*/
|
|
|
|
|
private void updateWidget() {
|
|
|
|
|
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
|
|
|
|
if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {
|
|
|
|
@ -418,19 +509,22 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
|
|
|
|
|
mWorkingNote.getWidgetId()
|
|
|
|
|
mWorkingNote.getWidgetId()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
sendBroadcast(intent);
|
|
|
|
|
setResult(RESULT_OK, intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onClick 方法用于处理点击事件,根据点击的视图 ID 执行不同的操作。
|
|
|
|
|
*/
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
int id = v.getId();
|
|
|
|
|
if (id == R.id.btn_set_bg_color) {
|
|
|
|
|
mNoteBgColorSelector.setVisibility(View.VISIBLE);
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
|
- View.VISIBLE);
|
|
|
|
|
View.VISIBLE);
|
|
|
|
|
} else if (sBgSelectorBtnsMap.containsKey(id)) {
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
|
View.GONE);
|
|
|
|
@ -452,6 +546,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onBackPressed 方法用于处理返回键事件。如果有选择器可见,则隐藏它们,否则调用父类方法。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onBackPressed() {
|
|
|
|
|
if(clearSettingState()) {
|
|
|
|
@ -462,6 +559,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
super.onBackPressed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* clearSettingState 方法用于清除选择器的状态。如果有选择器可见,则隐藏它们并返回 true,否则返回 false。
|
|
|
|
|
*/
|
|
|
|
|
private boolean clearSettingState() {
|
|
|
|
|
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE) {
|
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);
|
|
|
|
@ -473,6 +573,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onBackgroundColorChanged 方法在背景颜色改变时被调用,更新背景颜色选择器的状态和背景视图。
|
|
|
|
|
*/
|
|
|
|
|
public void onBackgroundColorChanged() {
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
|
View.VISIBLE);
|
|
|
|
@ -480,6 +583,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onPrepareOptionsMenu 方法用于准备菜单选项。如果活动正在结束,则返回 true。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
|
if (isFinishing()) {
|
|
|
|
@ -505,6 +611,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onOptionsItemSelected 方法用于处理菜单选项点击事件,根据菜单项 ID 执行不同的操作。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
@ -553,6 +662,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* setReminder 方法用于设置提醒。
|
|
|
|
|
*/
|
|
|
|
|
private void setReminder() {
|
|
|
|
|
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
|
|
|
|
|
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
|
|
|
|
@ -564,8 +676,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Share note to apps that support {@link Intent#ACTION_SEND} action
|
|
|
|
|
* and {@text/plain} type
|
|
|
|
|
* sendTo 方法用于分享笔记内容到支持 ACTION_SEND 和 text/plain 类型的应用。
|
|
|
|
|
*/
|
|
|
|
|
private void sendTo(Context context, String info) {
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
@ -574,11 +685,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* createNewNote 方法用于创建新笔记。首先保存当前编辑的笔记,然后启动一个新的 NoteEditActivity。
|
|
|
|
|
*/
|
|
|
|
|
private void createNewNote() {
|
|
|
|
|
// Firstly, save current editing notes
|
|
|
|
|
// 首先保存当前编辑的笔记
|
|
|
|
|
saveNote();
|
|
|
|
|
|
|
|
|
|
// For safety, start a new NoteEditActivity
|
|
|
|
|
// 为了安全,创建一个新的 NoteEditActivity
|
|
|
|
|
finish();
|
|
|
|
|
Intent intent = new Intent(this, NoteEditActivity.class);
|
|
|
|
|
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
|
|
|
|
@ -586,6 +700,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* deleteCurrentNote 方法用于删除当前笔记。如果笔记存在于数据库中,则删除它。
|
|
|
|
|
*/
|
|
|
|
|
private void deleteCurrentNote() {
|
|
|
|
|
if (mWorkingNote.existInDatabase()) {
|
|
|
|
|
HashSet<Long> ids = new HashSet<Long>();
|
|
|
|
@ -608,15 +725,17 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
mWorkingNote.markDeleted(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* isSyncMode 方法用于判断当前是否为同步模式。
|
|
|
|
|
*/
|
|
|
|
|
private boolean isSyncMode() {
|
|
|
|
|
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onClockAlertChanged 方法在时钟提醒改变时被调用。如果笔记未保存,则先保存笔记,然后设置提醒。
|
|
|
|
|
*/
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
@ -632,20 +751,21 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent);
|
|
|
|
|
}
|
|
|
|
|
} 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onWidgetChanged 方法在笔记小部件改变时被调用,更新小部件。
|
|
|
|
|
*/
|
|
|
|
|
public void onWidgetChanged() {
|
|
|
|
|
updateWidget();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onEditTextDelete 方法在删除编辑文本时被调用,处理删除逻辑。
|
|
|
|
|
*/
|
|
|
|
|
public void onEditTextDelete(int index, String text) {
|
|
|
|
|
int childCount = mEditTextList.getChildCount();
|
|
|
|
|
if (childCount == 1) {
|
|
|
|
@ -672,10 +792,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
edit.setSelection(length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onEditTextEnter 方法在编辑文本进入时被调用,处理进入逻辑。
|
|
|
|
|
*/
|
|
|
|
|
public void onEditTextEnter(int index, String text) {
|
|
|
|
|
/**
|
|
|
|
|
* Should not happen, check for debug
|
|
|
|
|
*/
|
|
|
|
|
if(index > mEditTextList.getChildCount()) {
|
|
|
|
|
Log.e(TAG, "Index out of mEditTextList boundrary, should not happen");
|
|
|
|
|
}
|
|
|
|
@ -691,6 +811,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* switchToListMode 方法用于切换到列表模式,将笔记内容转换为列表。
|
|
|
|
|
*/
|
|
|
|
|
private void switchToListMode(String text) {
|
|
|
|
|
mEditTextList.removeAllViews();
|
|
|
|
|
String[] items = text.split("\n");
|
|
|
|
@ -708,6 +831,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
mEditTextList.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* getHighlightQueryResult 方法用于高亮显示查询结果。
|
|
|
|
|
*/
|
|
|
|
|
private Spannable getHighlightQueryResult(String fullText, String userQuery) {
|
|
|
|
|
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
|
|
|
|
|
if (!TextUtils.isEmpty(userQuery)) {
|
|
|
|
@ -725,6 +851,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return spannable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* getListItem 方法用于获取列表项视图。
|
|
|
|
|
*/
|
|
|
|
|
private View getListItem(String item, int index) {
|
|
|
|
|
View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null);
|
|
|
|
|
final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
@ -756,6 +885,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onTextChange 方法在文本改变时被调用,处理文本变化逻辑。
|
|
|
|
|
*/
|
|
|
|
|
public void onTextChange(int index, boolean hasText) {
|
|
|
|
|
if (index >= mEditTextList.getChildCount()) {
|
|
|
|
|
Log.e(TAG, "Wrong index, should not happen");
|
|
|
|
@ -768,13 +900,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onCheckListModeChanged 方法在列表模式改变时被调用,处理模式变化逻辑。
|
|
|
|
|
*/
|
|
|
|
|
public void onCheckListModeChanged(int oldMode, int newMode) {
|
|
|
|
|
if (newMode == TextNote.MODE_CHECK_LIST) {
|
|
|
|
|
switchToListMode(mNoteEditor.getText().toString());
|
|
|
|
|
} else {
|
|
|
|
|
if (!getWorkingText()) {
|
|
|
|
|
mWorkingNote.setWorkingText(mWorkingNote.getContent().replace(TAG_UNCHECKED + " ",
|
|
|
|
|
""));
|
|
|
|
|
mWorkingNote.setWorkingText(mWorkingNote.getContent().replace(TAG_UNCHECKED + " ", "").trim());
|
|
|
|
|
}
|
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
|
mEditTextList.setVisibility(View.GONE);
|
|
|
|
@ -782,6 +916,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* getWorkingText 方法用于获取当前正在编辑的文本。
|
|
|
|
|
*/
|
|
|
|
|
private boolean getWorkingText() {
|
|
|
|
|
boolean hasChecked = false;
|
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
@ -805,28 +942,30 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return hasChecked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* saveNote 方法用于保存当前编辑的笔记。如果保存成功,则设置结果为 RESULT_OK。
|
|
|
|
|
*
|
|
|
|
|
* @return 如果保存成功则返回 true,否则返回 false
|
|
|
|
|
*/
|
|
|
|
|
private boolean saveNote() {
|
|
|
|
|
getWorkingText();
|
|
|
|
|
boolean saved = mWorkingNote.saveNote();
|
|
|
|
|
if (saved) {
|
|
|
|
|
/**
|
|
|
|
|
* There are two modes from List view to edit view, open one note,
|
|
|
|
|
* create/edit a node. Opening node requires to the original
|
|
|
|
|
* position in the list when back from edit view, while creating a
|
|
|
|
|
* 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} 用于标识创建/编辑状态
|
|
|
|
|
*/
|
|
|
|
|
setResult(RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
return saved;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* sendToDesktop 方法用于将当前笔记发送到桌面作为快捷方式。
|
|
|
|
|
* 在发送之前,确保当前编辑的笔记存在于数据库中。如果笔记不存在,则先保存它。
|
|
|
|
|
*/
|
|
|
|
|
private void sendToDesktop() {
|
|
|
|
|
/**
|
|
|
|
|
* Before send message to home, we should make sure that current
|
|
|
|
|
* editing note is exists in databases. So, for new note, firstly
|
|
|
|
|
* save it
|
|
|
|
|
*/
|
|
|
|
|
if (!mWorkingNote.existInDatabase()) {
|
|
|
|
|
saveNote();
|
|
|
|
|
}
|
|
|
|
@ -847,15 +986,20 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
sendBroadcast(sender);
|
|
|
|
|
} 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
|
|
|
|
|
* 如果用户没有输入任何内容(笔记不值得保存),则没有笔记 ID,提醒用户应该输入一些内容。
|
|
|
|
|
*/
|
|
|
|
|
Log.e(TAG, "Send to desktop error");
|
|
|
|
|
showToast(R.string.error_note_empty_for_send_to_desktop);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* makeShortcutIconTitle 方法用于生成快捷方式图标的标题。
|
|
|
|
|
* 它会移除复选框标签,并截取前 10 个字符作为标题。
|
|
|
|
|
*
|
|
|
|
|
* @param content 笔记内容
|
|
|
|
|
* @return 快捷方式图标标题
|
|
|
|
|
*/
|
|
|
|
|
private String makeShortcutIconTitle(String content) {
|
|
|
|
|
content = content.replace(TAG_CHECKED, "");
|
|
|
|
|
content = content.replace(TAG_UNCHECKED, "");
|
|
|
|
@ -863,11 +1007,22 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
SHORTCUT_ICON_TITLE_MAX_LEN) : content;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* showToast 方法用于显示短时间的 Toast 消息。
|
|
|
|
|
*
|
|
|
|
|
* @param resId 字符串资源 ID
|
|
|
|
|
*/
|
|
|
|
|
private void showToast(int resId) {
|
|
|
|
|
showToast(resId, Toast.LENGTH_SHORT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* showToast 方法用于显示指定时间长度的 Toast 消息。
|
|
|
|
|
*
|
|
|
|
|
* @param resId 字符串资源 ID
|
|
|
|
|
* @param duration Toast 显示的时长
|
|
|
|
|
*/
|
|
|
|
|
private void showToast(int resId, int duration) {
|
|
|
|
|
Toast.makeText(this, resId, duration).show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|