|
|
@ -74,18 +74,26 @@ import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
NoteSettingChangedListener, OnTextViewChangeListener {
|
|
|
|
NoteSettingChangedListener, OnTextViewChangeListener {
|
|
|
|
|
|
|
|
// 定义一个内部类HeadViewHolder,用于保存头部视图的控件
|
|
|
|
private class HeadViewHolder {
|
|
|
|
private class HeadViewHolder {
|
|
|
|
|
|
|
|
// 保存修改日期的TextView
|
|
|
|
public TextView tvModified;
|
|
|
|
public TextView tvModified;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 保存提醒图标的ImageView
|
|
|
|
public ImageView ivAlertIcon;
|
|
|
|
public ImageView ivAlertIcon;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 保存提醒日期的TextView
|
|
|
|
public TextView tvAlertDate;
|
|
|
|
public TextView tvAlertDate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 保存设置背景颜色的ImageView
|
|
|
|
public ImageView ibSetBgColor;
|
|
|
|
public ImageView ibSetBgColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 定义一个静态的Map,用于存储背景选择按钮的ID和对应的颜色值
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
|
|
|
|
// 静态代码块,用于初始化Map
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
|
|
|
|
// 将背景选择按钮的ID和对应的颜色值放入Map中
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_red, ResourceParser.RED);
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_red, ResourceParser.RED);
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_blue, ResourceParser.BLUE);
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_blue, ResourceParser.BLUE);
|
|
|
@ -94,16 +102,24 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
|
|
|
|
// 初始化静态变量sBgSelectorSelectionMap,用于存储背景选择器的资源ID
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
|
|
|
|
// 将ResourceParser.YELLOW对应的资源ID存入sBgSelectorSelectionMap
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select);
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select);
|
|
|
|
|
|
|
|
// 将ResourceParser.RED对应的资源ID存入sBgSelectorSelectionMap
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.RED, R.id.iv_bg_red_select);
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.RED, R.id.iv_bg_red_select);
|
|
|
|
|
|
|
|
// 将ResourceParser.BLUE对应的资源ID存入sBgSelectorSelectionMap
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.BLUE, R.id.iv_bg_blue_select);
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.BLUE, R.id.iv_bg_blue_select);
|
|
|
|
|
|
|
|
// 将ResourceParser.GREEN对应的资源ID存入sBgSelectorSelectionMap
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.GREEN, R.id.iv_bg_green_select);
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.GREEN, R.id.iv_bg_green_select);
|
|
|
|
|
|
|
|
// 将ResourceParser.WHITE对应的资源ID存入sBgSelectorSelectionMap
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.WHITE, R.id.iv_bg_white_select);
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.WHITE, R.id.iv_bg_white_select);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 定义一个静态常量,用于存储字体大小按钮的ID和对应的字体大小
|
|
|
|
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
|
|
|
|
// 将字体大小按钮的ID和对应的字体大小放入Map中
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE);
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE);
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_small, ResourceParser.TEXT_SMALL);
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_small, ResourceParser.TEXT_SMALL);
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_normal, ResourceParser.TEXT_MEDIUM);
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_normal, ResourceParser.TEXT_MEDIUM);
|
|
|
@ -111,6 +127,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
|
|
|
|
// 初始化字体选择器选择映射
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select);
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select);
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SMALL, R.id.iv_small_select);
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SMALL, R.id.iv_small_select);
|
|
|
@ -120,45 +137,67 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "NoteEditActivity";
|
|
|
|
private static final String TAG = "NoteEditActivity";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 头部视图持有者
|
|
|
|
private HeadViewHolder mNoteHeaderHolder;
|
|
|
|
private HeadViewHolder mNoteHeaderHolder;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 头部视图面板
|
|
|
|
private View mHeadViewPanel;
|
|
|
|
private View mHeadViewPanel;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 笔记背景颜色选择器
|
|
|
|
private View mNoteBgColorSelector;
|
|
|
|
private View mNoteBgColorSelector;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 字体大小选择器
|
|
|
|
private View mFontSizeSelector;
|
|
|
|
private View mFontSizeSelector;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 笔记编辑器
|
|
|
|
private EditText mNoteEditor;
|
|
|
|
private EditText mNoteEditor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 笔记编辑器面板
|
|
|
|
private View mNoteEditorPanel;
|
|
|
|
private View mNoteEditorPanel;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 工作中的笔记
|
|
|
|
private WorkingNote mWorkingNote;
|
|
|
|
private WorkingNote mWorkingNote;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 共享偏好设置
|
|
|
|
private SharedPreferences mSharedPrefs;
|
|
|
|
private SharedPreferences mSharedPrefs;
|
|
|
|
|
|
|
|
// 字体大小ID
|
|
|
|
private int mFontSizeId;
|
|
|
|
private int mFontSizeId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 字体大小偏好设置键
|
|
|
|
private static final String PREFERENCE_FONT_SIZE = "pref_font_size";
|
|
|
|
private static final String PREFERENCE_FONT_SIZE = "pref_font_size";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 快捷图标标题最大长度
|
|
|
|
private static final int SHORTCUT_ICON_TITLE_MAX_LEN = 10;
|
|
|
|
private static final int SHORTCUT_ICON_TITLE_MAX_LEN = 10;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 已选中的标签
|
|
|
|
public static final String TAG_CHECKED = String.valueOf('\u221A');
|
|
|
|
public static final String TAG_CHECKED = String.valueOf('\u221A');
|
|
|
|
|
|
|
|
// 未选中的标签
|
|
|
|
public static final String TAG_UNCHECKED = String.valueOf('\u25A1');
|
|
|
|
public static final String TAG_UNCHECKED = String.valueOf('\u25A1');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 编辑文本列表
|
|
|
|
private LinearLayout mEditTextList;
|
|
|
|
private LinearLayout mEditTextList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 用户查询
|
|
|
|
private String mUserQuery;
|
|
|
|
private String mUserQuery;
|
|
|
|
|
|
|
|
// 正则表达式
|
|
|
|
private Pattern mPattern;
|
|
|
|
private Pattern mPattern;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
|
|
|
|
// 重写onCreate方法
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
// 调用父类的onCreate方法
|
|
|
|
this.setContentView(R.layout.note_edit);
|
|
|
|
this.setContentView(R.layout.note_edit);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置当前Activity的布局文件为note_edit.xml
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
|
|
|
|
|
|
|
// 如果savedInstanceState为空且initActivityState方法返回false
|
|
|
|
finish();
|
|
|
|
finish();
|
|
|
|
|
|
|
|
// 结束当前Activity
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
initResources();
|
|
|
|
initResources();
|
|
|
|
|
|
|
|
// 初始化资源
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -166,16 +205,25 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* user load this activity, we should restore the former state
|
|
|
|
* user load this activity, we should restore the former state
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
|
|
|
|
// 重写onRestoreInstanceState方法
|
|
|
|
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
|
|
|
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
|
|
|
super.onRestoreInstanceState(savedInstanceState);
|
|
|
|
super.onRestoreInstanceState(savedInstanceState);
|
|
|
|
|
|
|
|
// 调用父类的onRestoreInstanceState方法
|
|
|
|
if (savedInstanceState != null && savedInstanceState.containsKey(Intent.EXTRA_UID)) {
|
|
|
|
if (savedInstanceState != null && savedInstanceState.containsKey(Intent.EXTRA_UID)) {
|
|
|
|
|
|
|
|
// 如果savedInstanceState不为空且包含Intent.EXTRA_UID键
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
|
|
|
|
// 创建一个Intent对象,并设置Action为Intent.ACTION_VIEW
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, savedInstanceState.getLong(Intent.EXTRA_UID));
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, savedInstanceState.getLong(Intent.EXTRA_UID));
|
|
|
|
|
|
|
|
// 将savedInstanceState中的Intent.EXTRA_UID键对应的值添加到Intent对象中
|
|
|
|
if (!initActivityState(intent)) {
|
|
|
|
if (!initActivityState(intent)) {
|
|
|
|
|
|
|
|
// 如果initActivityState方法返回false
|
|
|
|
finish();
|
|
|
|
finish();
|
|
|
|
|
|
|
|
// 结束当前Activity
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果initActivityState方法返回true
|
|
|
|
Log.d(TAG, "Restoring from killed activity");
|
|
|
|
Log.d(TAG, "Restoring from killed activity");
|
|
|
|
|
|
|
|
// 打印日志,表示从被杀掉的Activity中恢复
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -197,6 +245,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);
|
|
|
|
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if the note exists
|
|
|
|
if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) {
|
|
|
|
if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) {
|
|
|
|
Intent jump = new Intent(this, NotesListActivity.class);
|
|
|
|
Intent jump = new Intent(this, NotesListActivity.class);
|
|
|
|
startActivity(jump);
|
|
|
|
startActivity(jump);
|
|
|
@ -204,6 +253,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
finish();
|
|
|
|
finish();
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Load the note
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);
|
|
|
|
if (mWorkingNote == null) {
|
|
|
|
if (mWorkingNote == null) {
|
|
|
|
Log.e(TAG, "load note failed with note id" + noteId);
|
|
|
|
Log.e(TAG, "load note failed with note id" + noteId);
|
|
|
@ -211,6 +261,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the soft input mode
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
@ -250,6 +301,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
bgResId);
|
|
|
|
bgResId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set the soft input mode
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
|
|
@ -258,6 +310,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
finish();
|
|
|
|
finish();
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the listener for the note
|
|
|
|
mWorkingNote.setOnSettingStatusChangedListener(this);
|
|
|
|
mWorkingNote.setOnSettingStatusChangedListener(this);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -265,24 +318,33 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
super.onResume();
|
|
|
|
|
|
|
|
// Initialize the note screen
|
|
|
|
initNoteScreen();
|
|
|
|
initNoteScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initNoteScreen() {
|
|
|
|
private void initNoteScreen() {
|
|
|
|
|
|
|
|
// Set the text appearance of the note editor
|
|
|
|
mNoteEditor.setTextAppearance(this, TextAppearanceResources
|
|
|
|
mNoteEditor.setTextAppearance(this, TextAppearanceResources
|
|
|
|
.getTexAppearanceResource(mFontSizeId));
|
|
|
|
.getTexAppearanceResource(mFontSizeId));
|
|
|
|
|
|
|
|
// Check if the note is in check list mode
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
|
|
|
|
// Switch to list mode
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Set the text of the note editor
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
|
|
|
|
// Set the selection of the note editor
|
|
|
|
mNoteEditor.setSelection(mNoteEditor.getText().length());
|
|
|
|
mNoteEditor.setSelection(mNoteEditor.getText().length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the visibility of the background selector
|
|
|
|
for (Integer id : sBgSelectorSelectionMap.keySet()) {
|
|
|
|
for (Integer id : sBgSelectorSelectionMap.keySet()) {
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the background of the header and note editor panel
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set the modified date of the note
|
|
|
|
mNoteHeaderHolder.tvModified.setText(DateUtils.formatDateTime(this,
|
|
|
|
mNoteHeaderHolder.tvModified.setText(DateUtils.formatDateTime(this,
|
|
|
|
mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_DATE
|
|
|
|
mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_DATE
|
|
|
|
| DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME
|
|
|
|
| DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME
|
|
|
@ -292,29 +354,42 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* TODO: Add the menu for setting alert. Currently disable it because the DateTimePicker
|
|
|
|
* TODO: Add the menu for setting alert. Currently disable it because the DateTimePicker
|
|
|
|
* is not ready
|
|
|
|
* is not ready
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Show the alert header
|
|
|
|
showAlertHeader();
|
|
|
|
showAlertHeader();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void showAlertHeader() {
|
|
|
|
private void showAlertHeader() {
|
|
|
|
|
|
|
|
// 如果当前笔记设置了提醒
|
|
|
|
if (mWorkingNote.hasClockAlert()) {
|
|
|
|
if (mWorkingNote.hasClockAlert()) {
|
|
|
|
|
|
|
|
// 获取当前时间
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
|
|
|
|
// 如果当前时间大于提醒时间
|
|
|
|
if (time > mWorkingNote.getAlertDate()) {
|
|
|
|
if (time > mWorkingNote.getAlertDate()) {
|
|
|
|
|
|
|
|
// 设置提醒日期为已过期
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setText(R.string.note_alert_expired);
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setText(R.string.note_alert_expired);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 设置提醒日期为相对时间
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setText(DateUtils.getRelativeTimeSpanString(
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setText(DateUtils.getRelativeTimeSpanString(
|
|
|
|
mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS));
|
|
|
|
mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 显示提醒日期
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setVisibility(View.VISIBLE);
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
// 显示提醒图标
|
|
|
|
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.VISIBLE);
|
|
|
|
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 隐藏提醒日期
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
// 隐藏提醒图标
|
|
|
|
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
|
|
|
|
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 重写onNewIntent方法
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
|
|
|
|
// 调用父类的onNewIntent方法
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
|
|
|
|
// 初始化活动状态
|
|
|
|
initActivityState(intent);
|
|
|
|
initActivityState(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -326,64 +401,93 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* generate a id. If the editing note is not worth saving, there
|
|
|
|
* generate a id. If the editing note is not worth saving, there
|
|
|
|
* is no id which is equivalent to create new note
|
|
|
|
* is no id which is equivalent to create new note
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
// 如果当前编辑的笔记没有note id,我们首先应该保存它以生成一个id。如果编辑的笔记不值得保存,那么没有id相当于创建新笔记
|
|
|
|
if (!mWorkingNote.existInDatabase()) {
|
|
|
|
if (!mWorkingNote.existInDatabase()) {
|
|
|
|
saveNote();
|
|
|
|
saveNote();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 将当前编辑的笔记的id保存到Bundle中
|
|
|
|
outState.putLong(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
|
|
|
outState.putLong(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
|
|
|
|
|
|
|
// 打印日志,记录当前编辑的笔记的id
|
|
|
|
Log.d(TAG, "Save working note id: " + mWorkingNote.getNoteId() + " onSaveInstanceState");
|
|
|
|
Log.d(TAG, "Save working note id: " + mWorkingNote.getNoteId() + " onSaveInstanceState");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
|
|
|
|
|
// 如果mNoteBgColorSelector可见且不在mNoteBgColorSelector范围内,则隐藏mNoteBgColorSelector
|
|
|
|
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE
|
|
|
|
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE
|
|
|
|
&& !inRangeOfView(mNoteBgColorSelector, ev)) {
|
|
|
|
&& !inRangeOfView(mNoteBgColorSelector, ev)) {
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果mFontSizeSelector可见且不在mFontSizeSelector范围内,则隐藏mFontSizeSelector
|
|
|
|
if (mFontSizeSelector.getVisibility() == View.VISIBLE
|
|
|
|
if (mFontSizeSelector.getVisibility() == View.VISIBLE
|
|
|
|
&& !inRangeOfView(mFontSizeSelector, ev)) {
|
|
|
|
&& !inRangeOfView(mFontSizeSelector, ev)) {
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 否则,调用父类的dispatchTouchEvent方法
|
|
|
|
return super.dispatchTouchEvent(ev);
|
|
|
|
return super.dispatchTouchEvent(ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean inRangeOfView(View view, MotionEvent ev) {
|
|
|
|
private boolean inRangeOfView(View view, MotionEvent ev) {
|
|
|
|
|
|
|
|
// 获取view在屏幕上的位置
|
|
|
|
int []location = new int[2];
|
|
|
|
int []location = new int[2];
|
|
|
|
view.getLocationOnScreen(location);
|
|
|
|
view.getLocationOnScreen(location);
|
|
|
|
|
|
|
|
// 获取view的x坐标
|
|
|
|
int x = location[0];
|
|
|
|
int x = location[0];
|
|
|
|
|
|
|
|
// 获取view的y坐标
|
|
|
|
int y = location[1];
|
|
|
|
int y = location[1];
|
|
|
|
|
|
|
|
// 判断ev的x坐标是否在view的范围内
|
|
|
|
if (ev.getX() < x
|
|
|
|
if (ev.getX() < x
|
|
|
|
|
|
|
|
// 判断ev的x坐标是否在view的范围内
|
|
|
|
|| ev.getX() > (x + view.getWidth())
|
|
|
|
|| ev.getX() > (x + view.getWidth())
|
|
|
|
|
|
|
|
// 判断ev的y坐标是否在view的范围内
|
|
|
|
|| ev.getY() < y
|
|
|
|
|| ev.getY() < y
|
|
|
|
|
|
|
|
// 判断ev的y坐标是否在view的范围内
|
|
|
|
|| ev.getY() > (y + view.getHeight())) {
|
|
|
|
|| ev.getY() > (y + view.getHeight())) {
|
|
|
|
|
|
|
|
// 如果不在范围内,返回false
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果在范围内,返回true
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initResources() {
|
|
|
|
private void initResources() {
|
|
|
|
|
|
|
|
// 初始化标题栏
|
|
|
|
mHeadViewPanel = findViewById(R.id.note_title);
|
|
|
|
mHeadViewPanel = findViewById(R.id.note_title);
|
|
|
|
|
|
|
|
// 初始化标题栏的ViewHolder
|
|
|
|
mNoteHeaderHolder = new HeadViewHolder();
|
|
|
|
mNoteHeaderHolder = new HeadViewHolder();
|
|
|
|
|
|
|
|
// 初始化标题栏中的修改日期TextView
|
|
|
|
mNoteHeaderHolder.tvModified = (TextView) findViewById(R.id.tv_modified_date);
|
|
|
|
mNoteHeaderHolder.tvModified = (TextView) findViewById(R.id.tv_modified_date);
|
|
|
|
|
|
|
|
// 初始化标题栏中的提醒图标ImageView
|
|
|
|
mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon);
|
|
|
|
mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon);
|
|
|
|
|
|
|
|
// 初始化标题栏中的提醒日期TextView
|
|
|
|
mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);
|
|
|
|
mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);
|
|
|
|
|
|
|
|
// 初始化标题栏中的设置背景颜色按钮ImageView
|
|
|
|
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
|
|
|
|
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
|
|
|
|
|
|
|
|
// 设置设置背景颜色按钮的点击事件
|
|
|
|
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
|
|
|
|
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
|
|
|
|
|
|
|
|
// 初始化笔记编辑框
|
|
|
|
mNoteEditor = (EditText) findViewById(R.id.note_edit_view);
|
|
|
|
mNoteEditor = (EditText) findViewById(R.id.note_edit_view);
|
|
|
|
|
|
|
|
// 初始化笔记编辑框的面板
|
|
|
|
mNoteEditorPanel = findViewById(R.id.sv_note_edit);
|
|
|
|
mNoteEditorPanel = findViewById(R.id.sv_note_edit);
|
|
|
|
|
|
|
|
// 初始化笔记背景颜色选择器
|
|
|
|
mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector);
|
|
|
|
mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector);
|
|
|
|
|
|
|
|
// 遍历背景颜色选择器中的按钮,并设置点击事件
|
|
|
|
for (int id : sBgSelectorBtnsMap.keySet()) {
|
|
|
|
for (int id : sBgSelectorBtnsMap.keySet()) {
|
|
|
|
ImageView iv = (ImageView) findViewById(id);
|
|
|
|
ImageView iv = (ImageView) findViewById(id);
|
|
|
|
iv.setOnClickListener(this);
|
|
|
|
iv.setOnClickListener(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化字体大小选择器
|
|
|
|
mFontSizeSelector = findViewById(R.id.font_size_selector);
|
|
|
|
mFontSizeSelector = findViewById(R.id.font_size_selector);
|
|
|
|
|
|
|
|
// 遍历字体大小选择器中的按钮,并设置点击事件
|
|
|
|
for (int id : sFontSizeBtnsMap.keySet()) {
|
|
|
|
for (int id : sFontSizeBtnsMap.keySet()) {
|
|
|
|
View view = findViewById(id);
|
|
|
|
View view = findViewById(id);
|
|
|
|
view.setOnClickListener(this);
|
|
|
|
view.setOnClickListener(this);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// 获取默认的SharedPreferences
|
|
|
|
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);
|
|
|
|
mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -397,121 +501,176 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
|
|
|
|
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 重写onPause方法
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
protected void onPause() {
|
|
|
|
|
|
|
|
// 调用父类的onPause方法
|
|
|
|
super.onPause();
|
|
|
|
super.onPause();
|
|
|
|
|
|
|
|
// 如果保存笔记数据成功
|
|
|
|
if(saveNote()) {
|
|
|
|
if(saveNote()) {
|
|
|
|
|
|
|
|
// 打印日志,显示笔记数据的长度
|
|
|
|
Log.d(TAG, "Note data was saved with length:" + mWorkingNote.getContent().length());
|
|
|
|
Log.d(TAG, "Note data was saved with length:" + mWorkingNote.getContent().length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 清除设置状态
|
|
|
|
clearSettingState();
|
|
|
|
clearSettingState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void updateWidget() {
|
|
|
|
private void updateWidget() {
|
|
|
|
|
|
|
|
// 创建一个Intent,用于更新AppWidget
|
|
|
|
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
|
|
|
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
|
|
|
|
|
|
|
// 判断当前笔记的Widget类型
|
|
|
|
if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {
|
|
|
|
if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {
|
|
|
|
|
|
|
|
// 如果是2x类型的Widget,设置Intent的Class为NoteWidgetProvider_2x
|
|
|
|
intent.setClass(this, NoteWidgetProvider_2x.class);
|
|
|
|
intent.setClass(this, NoteWidgetProvider_2x.class);
|
|
|
|
} else if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_4X) {
|
|
|
|
} else if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_4X) {
|
|
|
|
|
|
|
|
// 如果是4x类型的Widget,设置Intent的Class为NoteWidgetProvider_4x
|
|
|
|
intent.setClass(this, NoteWidgetProvider_4x.class);
|
|
|
|
intent.setClass(this, NoteWidgetProvider_4x.class);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 如果是其他类型的Widget,输出错误日志并返回
|
|
|
|
Log.e(TAG, "Unspported widget type");
|
|
|
|
Log.e(TAG, "Unspported widget type");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 将当前笔记的WidgetId添加到Intent中
|
|
|
|
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
|
|
|
|
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
|
|
|
|
mWorkingNote.getWidgetId()
|
|
|
|
mWorkingNote.getWidgetId()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 发送广播,更新AppWidget
|
|
|
|
sendBroadcast(intent);
|
|
|
|
sendBroadcast(intent);
|
|
|
|
|
|
|
|
// 设置结果为RESULT_OK
|
|
|
|
setResult(RESULT_OK, intent);
|
|
|
|
setResult(RESULT_OK, intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
// 获取点击的View的id
|
|
|
|
int id = v.getId();
|
|
|
|
int id = v.getId();
|
|
|
|
|
|
|
|
// 如果点击的是设置背景颜色的按钮
|
|
|
|
if (id == R.id.btn_set_bg_color) {
|
|
|
|
if (id == R.id.btn_set_bg_color) {
|
|
|
|
|
|
|
|
// 显示背景颜色选择器
|
|
|
|
mNoteBgColorSelector.setVisibility(View.VISIBLE);
|
|
|
|
mNoteBgColorSelector.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
// 显示当前背景颜色选择器
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
- View.VISIBLE);
|
|
|
|
- View.VISIBLE);
|
|
|
|
|
|
|
|
// 如果点击的是背景颜色选择器中的按钮
|
|
|
|
} else if (sBgSelectorBtnsMap.containsKey(id)) {
|
|
|
|
} else if (sBgSelectorBtnsMap.containsKey(id)) {
|
|
|
|
|
|
|
|
// 隐藏当前背景颜色选择器
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
View.GONE);
|
|
|
|
View.GONE);
|
|
|
|
|
|
|
|
// 设置当前背景颜色
|
|
|
|
mWorkingNote.setBgColorId(sBgSelectorBtnsMap.get(id));
|
|
|
|
mWorkingNote.setBgColorId(sBgSelectorBtnsMap.get(id));
|
|
|
|
|
|
|
|
// 隐藏背景颜色选择器
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
// 如果点击的是字体大小选择器中的按钮
|
|
|
|
} else if (sFontSizeBtnsMap.containsKey(id)) {
|
|
|
|
} else if (sFontSizeBtnsMap.containsKey(id)) {
|
|
|
|
|
|
|
|
// 隐藏当前字体大小选择器
|
|
|
|
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.GONE);
|
|
|
|
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.GONE);
|
|
|
|
|
|
|
|
// 设置当前字体大小
|
|
|
|
mFontSizeId = sFontSizeBtnsMap.get(id);
|
|
|
|
mFontSizeId = sFontSizeBtnsMap.get(id);
|
|
|
|
|
|
|
|
// 保存当前字体大小到SharedPreferences
|
|
|
|
mSharedPrefs.edit().putInt(PREFERENCE_FONT_SIZE, mFontSizeId).commit();
|
|
|
|
mSharedPrefs.edit().putInt(PREFERENCE_FONT_SIZE, mFontSizeId).commit();
|
|
|
|
|
|
|
|
// 显示当前字体大小选择器
|
|
|
|
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
|
|
|
|
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
// 如果当前笔记处于清单模式
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
|
|
|
|
// 获取当前笔记内容
|
|
|
|
getWorkingText();
|
|
|
|
getWorkingText();
|
|
|
|
|
|
|
|
// 切换到清单模式
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
|
|
|
|
// 如果当前笔记不处于清单模式
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 设置当前笔记的字体大小
|
|
|
|
mNoteEditor.setTextAppearance(this,
|
|
|
|
mNoteEditor.setTextAppearance(this,
|
|
|
|
TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
|
|
|
|
TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 隐藏字体大小选择器
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
public void onBackPressed() {
|
|
|
|
|
|
|
|
// 如果清除设置状态成功,则直接返回
|
|
|
|
if(clearSettingState()) {
|
|
|
|
if(clearSettingState()) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 保存笔记
|
|
|
|
saveNote();
|
|
|
|
saveNote();
|
|
|
|
|
|
|
|
// 调用父类的方法
|
|
|
|
super.onBackPressed();
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean clearSettingState() {
|
|
|
|
private boolean clearSettingState() {
|
|
|
|
|
|
|
|
// 如果mNoteBgColorSelector可见,则将其设置为不可见,并返回true
|
|
|
|
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE) {
|
|
|
|
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE) {
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// 如果mFontSizeSelector可见,则将其设置为不可见,并返回true
|
|
|
|
} else if (mFontSizeSelector.getVisibility() == View.VISIBLE) {
|
|
|
|
} else if (mFontSizeSelector.getVisibility() == View.VISIBLE) {
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果以上两种情况都不满足,则返回false
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 当背景颜色改变时调用
|
|
|
|
public void onBackgroundColorChanged() {
|
|
|
|
public void onBackgroundColorChanged() {
|
|
|
|
|
|
|
|
// 根据当前笔记的背景颜色ID,找到对应的背景颜色选择器,并将其可见性设置为可见
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
View.VISIBLE);
|
|
|
|
View.VISIBLE);
|
|
|
|
|
|
|
|
// 设置笔记编辑面板的背景颜色为当前笔记的背景颜色资源ID
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
|
|
|
|
|
|
|
|
// 设置标题面板的背景颜色为当前笔记的标题背景颜色资源ID
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
|
|
|
|
// 如果Activity正在结束,则返回true
|
|
|
|
if (isFinishing()) {
|
|
|
|
if (isFinishing()) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 清除设置状态
|
|
|
|
clearSettingState();
|
|
|
|
clearSettingState();
|
|
|
|
|
|
|
|
// 清空菜单
|
|
|
|
menu.clear();
|
|
|
|
menu.clear();
|
|
|
|
|
|
|
|
// 如果当前笔记是通话记录,则加载通话记录编辑菜单
|
|
|
|
if (mWorkingNote.getFolderId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
if (mWorkingNote.getFolderId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
getMenuInflater().inflate(R.menu.call_note_edit, menu);
|
|
|
|
getMenuInflater().inflate(R.menu.call_note_edit, menu);
|
|
|
|
|
|
|
|
// 否则加载普通编辑菜单
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
getMenuInflater().inflate(R.menu.note_edit, menu);
|
|
|
|
getMenuInflater().inflate(R.menu.note_edit, menu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果当前笔记是清单模式,则将菜单项的标题设置为普通模式
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
menu.findItem(R.id.menu_list_mode).setTitle(R.string.menu_normal_mode);
|
|
|
|
menu.findItem(R.id.menu_list_mode).setTitle(R.string.menu_normal_mode);
|
|
|
|
|
|
|
|
// 否则将菜单项的标题设置为清单模式
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
menu.findItem(R.id.menu_list_mode).setTitle(R.string.menu_list_mode);
|
|
|
|
menu.findItem(R.id.menu_list_mode).setTitle(R.string.menu_list_mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果当前笔记有闹钟提醒,则隐藏提醒菜单项
|
|
|
|
if (mWorkingNote.hasClockAlert()) {
|
|
|
|
if (mWorkingNote.hasClockAlert()) {
|
|
|
|
menu.findItem(R.id.menu_alert).setVisible(false);
|
|
|
|
menu.findItem(R.id.menu_alert).setVisible(false);
|
|
|
|
|
|
|
|
// 否则隐藏删除提醒菜单项
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
menu.findItem(R.id.menu_delete_remind).setVisible(false);
|
|
|
|
menu.findItem(R.id.menu_delete_remind).setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 返回true
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
|
|
|
// 根据菜单项的id执行相应的操作
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.menu_new_note:
|
|
|
|
case R.id.menu_new_note:
|
|
|
|
|
|
|
|
// 创建新笔记
|
|
|
|
createNewNote();
|
|
|
|
createNewNote();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case R.id.menu_delete:
|
|
|
|
case R.id.menu_delete:
|
|
|
|
|
|
|
|
// 弹出删除确认对话框
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(getString(R.string.alert_title_delete));
|
|
|
|
builder.setTitle(getString(R.string.alert_title_delete));
|
|
|
|
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
|
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
@ -519,6 +678,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
builder.setPositiveButton(android.R.string.ok,
|
|
|
|
builder.setPositiveButton(android.R.string.ok,
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
|
|
|
// 删除当前笔记并关闭活动
|
|
|
|
deleteCurrentNote();
|
|
|
|
deleteCurrentNote();
|
|
|
|
finish();
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -527,24 +687,30 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
builder.show();
|
|
|
|
builder.show();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case R.id.menu_font_size:
|
|
|
|
case R.id.menu_font_size:
|
|
|
|
|
|
|
|
// 显示字体大小选择器
|
|
|
|
mFontSizeSelector.setVisibility(View.VISIBLE);
|
|
|
|
mFontSizeSelector.setVisibility(View.VISIBLE);
|
|
|
|
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
|
|
|
|
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case R.id.menu_list_mode:
|
|
|
|
case R.id.menu_list_mode:
|
|
|
|
|
|
|
|
// 切换列表模式
|
|
|
|
mWorkingNote.setCheckListMode(mWorkingNote.getCheckListMode() == 0 ?
|
|
|
|
mWorkingNote.setCheckListMode(mWorkingNote.getCheckListMode() == 0 ?
|
|
|
|
TextNote.MODE_CHECK_LIST : 0);
|
|
|
|
TextNote.MODE_CHECK_LIST : 0);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case R.id.menu_share:
|
|
|
|
case R.id.menu_share:
|
|
|
|
|
|
|
|
// 获取当前笔记内容并分享
|
|
|
|
getWorkingText();
|
|
|
|
getWorkingText();
|
|
|
|
sendTo(this, mWorkingNote.getContent());
|
|
|
|
sendTo(this, mWorkingNote.getContent());
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case R.id.menu_send_to_desktop:
|
|
|
|
case R.id.menu_send_to_desktop:
|
|
|
|
|
|
|
|
// 发送到桌面
|
|
|
|
sendToDesktop();
|
|
|
|
sendToDesktop();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case R.id.menu_alert:
|
|
|
|
case R.id.menu_alert:
|
|
|
|
|
|
|
|
// 设置提醒
|
|
|
|
setReminder();
|
|
|
|
setReminder();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case R.id.menu_delete_remind:
|
|
|
|
case R.id.menu_delete_remind:
|
|
|
|
|
|
|
|
// 删除提醒
|
|
|
|
mWorkingNote.setAlertDate(0, false);
|
|
|
|
mWorkingNote.setAlertDate(0, false);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
@ -554,12 +720,17 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void setReminder() {
|
|
|
|
private void setReminder() {
|
|
|
|
|
|
|
|
// 创建一个DateTimePickerDialog对象,参数为当前上下文和当前时间
|
|
|
|
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
|
|
|
|
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
|
|
|
|
|
|
|
|
// 设置DateTimePickerDialog的监听器
|
|
|
|
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
|
|
|
|
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
|
|
|
|
|
|
|
|
// 当日期时间被设置时,调用此方法
|
|
|
|
public void OnDateTimeSet(AlertDialog dialog, long date) {
|
|
|
|
public void OnDateTimeSet(AlertDialog dialog, long date) {
|
|
|
|
|
|
|
|
// 设置工作笔记的提醒日期
|
|
|
|
mWorkingNote.setAlertDate(date , true);
|
|
|
|
mWorkingNote.setAlertDate(date , true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// 显示DateTimePickerDialog
|
|
|
|
d.show();
|
|
|
|
d.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -567,10 +738,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* Share note to apps that support {@link Intent#ACTION_SEND} action
|
|
|
|
* Share note to apps that support {@link Intent#ACTION_SEND} action
|
|
|
|
* and {@text/plain} type
|
|
|
|
* and {@text/plain} type
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
// 向指定上下文发送信息
|
|
|
|
private void sendTo(Context context, String info) {
|
|
|
|
private void sendTo(Context context, String info) {
|
|
|
|
|
|
|
|
// 创建一个发送意图
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
|
|
|
|
// 将信息添加到意图中
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, info);
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, info);
|
|
|
|
|
|
|
|
// 设置意图的类型为文本
|
|
|
|
intent.setType("text/plain");
|
|
|
|
intent.setType("text/plain");
|
|
|
|
|
|
|
|
// 启动意图
|
|
|
|
context.startActivity(intent);
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -586,29 +762,44 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
startActivity(intent);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 删除当前笔记
|
|
|
|
private void deleteCurrentNote() {
|
|
|
|
private void deleteCurrentNote() {
|
|
|
|
|
|
|
|
// 如果当前笔记存在于数据库中
|
|
|
|
if (mWorkingNote.existInDatabase()) {
|
|
|
|
if (mWorkingNote.existInDatabase()) {
|
|
|
|
|
|
|
|
// 创建一个HashSet来存储要删除的笔记的id
|
|
|
|
HashSet<Long> ids = new HashSet<Long>();
|
|
|
|
HashSet<Long> ids = new HashSet<Long>();
|
|
|
|
|
|
|
|
// 获取当前笔记的id
|
|
|
|
long id = mWorkingNote.getNoteId();
|
|
|
|
long id = mWorkingNote.getNoteId();
|
|
|
|
|
|
|
|
// 如果当前笔记的id不是根文件夹的id
|
|
|
|
if (id != Notes.ID_ROOT_FOLDER) {
|
|
|
|
if (id != Notes.ID_ROOT_FOLDER) {
|
|
|
|
|
|
|
|
// 将当前笔记的id添加到HashSet中
|
|
|
|
ids.add(id);
|
|
|
|
ids.add(id);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 如果当前笔记的id是根文件夹的id,则打印错误日志
|
|
|
|
Log.d(TAG, "Wrong note id, should not happen");
|
|
|
|
Log.d(TAG, "Wrong note id, should not happen");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果当前不是同步模式
|
|
|
|
if (!isSyncMode()) {
|
|
|
|
if (!isSyncMode()) {
|
|
|
|
|
|
|
|
// 批量删除笔记
|
|
|
|
if (!DataUtils.batchDeleteNotes(getContentResolver(), ids)) {
|
|
|
|
if (!DataUtils.batchDeleteNotes(getContentResolver(), ids)) {
|
|
|
|
|
|
|
|
// 如果删除失败,则打印错误日志
|
|
|
|
Log.e(TAG, "Delete Note error");
|
|
|
|
Log.e(TAG, "Delete Note error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 如果是同步模式
|
|
|
|
if (!DataUtils.batchMoveToFolder(getContentResolver(), ids, Notes.ID_TRASH_FOLER)) {
|
|
|
|
if (!DataUtils.batchMoveToFolder(getContentResolver(), ids, Notes.ID_TRASH_FOLER)) {
|
|
|
|
|
|
|
|
// 如果移动到垃圾桶文件夹失败,则打印错误日志
|
|
|
|
Log.e(TAG, "Move notes to trash folder error, should not happens");
|
|
|
|
Log.e(TAG, "Move notes to trash folder error, should not happens");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 标记当前笔记为已删除
|
|
|
|
mWorkingNote.markDeleted(true);
|
|
|
|
mWorkingNote.markDeleted(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否为同步模式
|
|
|
|
private boolean isSyncMode() {
|
|
|
|
private boolean isSyncMode() {
|
|
|
|
|
|
|
|
// 获取同步账户名称
|
|
|
|
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
|
|
|
|
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -642,22 +833,29 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 当小部件发生变化时调用
|
|
|
|
public void onWidgetChanged() {
|
|
|
|
public void onWidgetChanged() {
|
|
|
|
|
|
|
|
// 更新小部件
|
|
|
|
updateWidget();
|
|
|
|
updateWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void onEditTextDelete(int index, String text) {
|
|
|
|
public void onEditTextDelete(int index, String text) {
|
|
|
|
|
|
|
|
// 获取EditTextList的子视图数量
|
|
|
|
int childCount = mEditTextList.getChildCount();
|
|
|
|
int childCount = mEditTextList.getChildCount();
|
|
|
|
|
|
|
|
// 如果子视图数量为1,则直接返回
|
|
|
|
if (childCount == 1) {
|
|
|
|
if (childCount == 1) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从被删除的EditText的下一个开始,依次将每个EditText的索引减1
|
|
|
|
for (int i = index + 1; i < childCount; i++) {
|
|
|
|
for (int i = index + 1; i < childCount; i++) {
|
|
|
|
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
|
|
|
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
|
|
|
.setIndex(i - 1);
|
|
|
|
.setIndex(i - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从EditTextList中移除被删除的EditText
|
|
|
|
mEditTextList.removeViewAt(index);
|
|
|
|
mEditTextList.removeViewAt(index);
|
|
|
|
|
|
|
|
// 获取被删除的EditText的前一个EditText
|
|
|
|
NoteEditText edit = null;
|
|
|
|
NoteEditText edit = null;
|
|
|
|
if(index == 0) {
|
|
|
|
if(index == 0) {
|
|
|
|
edit = (NoteEditText) mEditTextList.getChildAt(0).findViewById(
|
|
|
|
edit = (NoteEditText) mEditTextList.getChildAt(0).findViewById(
|
|
|
@ -666,9 +864,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
edit = (NoteEditText) mEditTextList.getChildAt(index - 1).findViewById(
|
|
|
|
edit = (NoteEditText) mEditTextList.getChildAt(index - 1).findViewById(
|
|
|
|
R.id.et_edit_text);
|
|
|
|
R.id.et_edit_text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取被删除的EditText的长度
|
|
|
|
int length = edit.length();
|
|
|
|
int length = edit.length();
|
|
|
|
|
|
|
|
// 将被删除的EditText的内容追加到前一个EditText中
|
|
|
|
edit.append(text);
|
|
|
|
edit.append(text);
|
|
|
|
|
|
|
|
// 将焦点设置到前一个EditText中
|
|
|
|
edit.requestFocus();
|
|
|
|
edit.requestFocus();
|
|
|
|
|
|
|
|
// 将光标设置到前一个EditText的末尾
|
|
|
|
edit.setSelection(length);
|
|
|
|
edit.setSelection(length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -676,119 +878,190 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Should not happen, check for debug
|
|
|
|
* Should not happen, check for debug
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
// 如果index大于mEditTextList的子元素数量,则输出错误日志
|
|
|
|
if(index > mEditTextList.getChildCount()) {
|
|
|
|
if(index > mEditTextList.getChildCount()) {
|
|
|
|
Log.e(TAG, "Index out of mEditTextList boundrary, should not happen");
|
|
|
|
Log.e(TAG, "Index out of mEditTextList boundrary, should not happen");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取列表项
|
|
|
|
View view = getListItem(text, index);
|
|
|
|
View view = getListItem(text, index);
|
|
|
|
|
|
|
|
// 将列表项添加到mEditTextList中
|
|
|
|
mEditTextList.addView(view, index);
|
|
|
|
mEditTextList.addView(view, index);
|
|
|
|
|
|
|
|
// 获取NoteEditText
|
|
|
|
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
|
|
|
|
// 设置焦点
|
|
|
|
edit.requestFocus();
|
|
|
|
edit.requestFocus();
|
|
|
|
|
|
|
|
// 设置光标位置
|
|
|
|
edit.setSelection(0);
|
|
|
|
edit.setSelection(0);
|
|
|
|
|
|
|
|
// 遍历mEditTextList中的子元素,从index+1开始
|
|
|
|
for (int i = index + 1; i < mEditTextList.getChildCount(); i++) {
|
|
|
|
for (int i = index + 1; i < mEditTextList.getChildCount(); i++) {
|
|
|
|
|
|
|
|
// 设置NoteEditText的索引
|
|
|
|
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
|
|
|
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
|
|
|
.setIndex(i);
|
|
|
|
.setIndex(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 切换到列表模式
|
|
|
|
private void switchToListMode(String text) {
|
|
|
|
private void switchToListMode(String text) {
|
|
|
|
|
|
|
|
// 移除所有视图
|
|
|
|
mEditTextList.removeAllViews();
|
|
|
|
mEditTextList.removeAllViews();
|
|
|
|
|
|
|
|
// 将文本按行分割
|
|
|
|
String[] items = text.split("\n");
|
|
|
|
String[] items = text.split("\n");
|
|
|
|
|
|
|
|
// 初始化索引
|
|
|
|
int index = 0;
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
// 遍历每一行
|
|
|
|
for (String item : items) {
|
|
|
|
for (String item : items) {
|
|
|
|
|
|
|
|
// 如果行不为空
|
|
|
|
if(!TextUtils.isEmpty(item)) {
|
|
|
|
if(!TextUtils.isEmpty(item)) {
|
|
|
|
|
|
|
|
// 添加列表项
|
|
|
|
mEditTextList.addView(getListItem(item, index));
|
|
|
|
mEditTextList.addView(getListItem(item, index));
|
|
|
|
|
|
|
|
// 索引自增
|
|
|
|
index++;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 添加一个空列表项
|
|
|
|
mEditTextList.addView(getListItem("", index));
|
|
|
|
mEditTextList.addView(getListItem("", index));
|
|
|
|
|
|
|
|
// 获取最后一个列表项的EditText并请求焦点
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.et_edit_text).requestFocus();
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.et_edit_text).requestFocus();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 隐藏NoteEditor
|
|
|
|
mNoteEditor.setVisibility(View.GONE);
|
|
|
|
mNoteEditor.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
// 显示EditTextList
|
|
|
|
mEditTextList.setVisibility(View.VISIBLE);
|
|
|
|
mEditTextList.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据用户查询结果高亮显示全文
|
|
|
|
private Spannable getHighlightQueryResult(String fullText, String userQuery) {
|
|
|
|
private Spannable getHighlightQueryResult(String fullText, String userQuery) {
|
|
|
|
|
|
|
|
// 创建一个SpannableString对象,用于存储高亮显示的文本
|
|
|
|
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
|
|
|
|
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
|
|
|
|
|
|
|
|
// 如果用户查询结果不为空
|
|
|
|
if (!TextUtils.isEmpty(userQuery)) {
|
|
|
|
if (!TextUtils.isEmpty(userQuery)) {
|
|
|
|
|
|
|
|
// 创建一个正则表达式对象,用于匹配用户查询结果
|
|
|
|
mPattern = Pattern.compile(userQuery);
|
|
|
|
mPattern = Pattern.compile(userQuery);
|
|
|
|
|
|
|
|
// 创建一个Matcher对象,用于匹配全文
|
|
|
|
Matcher m = mPattern.matcher(fullText);
|
|
|
|
Matcher m = mPattern.matcher(fullText);
|
|
|
|
|
|
|
|
// 定义一个起始位置
|
|
|
|
int start = 0;
|
|
|
|
int start = 0;
|
|
|
|
|
|
|
|
// 循环匹配全文
|
|
|
|
while (m.find(start)) {
|
|
|
|
while (m.find(start)) {
|
|
|
|
|
|
|
|
// 设置高亮显示的背景颜色
|
|
|
|
spannable.setSpan(
|
|
|
|
spannable.setSpan(
|
|
|
|
new BackgroundColorSpan(this.getResources().getColor(
|
|
|
|
new BackgroundColorSpan(this.getResources().getColor(
|
|
|
|
R.color.user_query_highlight)), m.start(), m.end(),
|
|
|
|
R.color.user_query_highlight)), m.start(), m.end(),
|
|
|
|
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
|
|
|
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
|
|
|
|
|
|
|
// 更新起始位置
|
|
|
|
start = m.end();
|
|
|
|
start = m.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 返回高亮显示的文本
|
|
|
|
return spannable;
|
|
|
|
return spannable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据传入的item和index获取一个View
|
|
|
|
private View getListItem(String item, int index) {
|
|
|
|
private View getListItem(String item, int index) {
|
|
|
|
|
|
|
|
// 通过LayoutInflater加载布局文件
|
|
|
|
View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null);
|
|
|
|
View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null);
|
|
|
|
|
|
|
|
// 获取EditText
|
|
|
|
final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
|
|
|
|
// 设置EditText的文本样式
|
|
|
|
edit.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
|
|
|
|
edit.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
|
|
|
|
|
|
|
|
// 获取CheckBox
|
|
|
|
CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item));
|
|
|
|
CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item));
|
|
|
|
|
|
|
|
// 设置CheckBox的监听器
|
|
|
|
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
|
|
|
|
// 如果CheckBox被选中
|
|
|
|
if (isChecked) {
|
|
|
|
if (isChecked) {
|
|
|
|
|
|
|
|
// 设置EditText的画笔标志,添加删除线
|
|
|
|
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
|
|
|
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 设置EditText的画笔标志,取消删除线
|
|
|
|
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
|
|
|
|
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果item以TAG_CHECKED开头
|
|
|
|
if (item.startsWith(TAG_CHECKED)) {
|
|
|
|
if (item.startsWith(TAG_CHECKED)) {
|
|
|
|
|
|
|
|
// 设置CheckBox为选中状态
|
|
|
|
cb.setChecked(true);
|
|
|
|
cb.setChecked(true);
|
|
|
|
|
|
|
|
// 设置EditText的画笔标志,添加删除线
|
|
|
|
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
|
|
|
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
|
|
|
|
|
|
|
// 去掉TAG_CHECKED
|
|
|
|
item = item.substring(TAG_CHECKED.length(), item.length()).trim();
|
|
|
|
item = item.substring(TAG_CHECKED.length(), item.length()).trim();
|
|
|
|
|
|
|
|
// 如果item以TAG_UNCHECKED开头
|
|
|
|
} else if (item.startsWith(TAG_UNCHECKED)) {
|
|
|
|
} else if (item.startsWith(TAG_UNCHECKED)) {
|
|
|
|
|
|
|
|
// 设置CheckBox为未选中状态
|
|
|
|
cb.setChecked(false);
|
|
|
|
cb.setChecked(false);
|
|
|
|
|
|
|
|
// 设置EditText的画笔标志,取消删除线
|
|
|
|
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
|
|
|
|
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
|
|
|
|
|
|
|
|
// 去掉TAG_UNCHECKED
|
|
|
|
item = item.substring(TAG_UNCHECKED.length(), item.length()).trim();
|
|
|
|
item = item.substring(TAG_UNCHECKED.length(), item.length()).trim();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置EditText的监听器
|
|
|
|
edit.setOnTextViewChangeListener(this);
|
|
|
|
edit.setOnTextViewChangeListener(this);
|
|
|
|
|
|
|
|
// 设置EditText的索引
|
|
|
|
edit.setIndex(index);
|
|
|
|
edit.setIndex(index);
|
|
|
|
|
|
|
|
// 设置EditText的文本
|
|
|
|
edit.setText(getHighlightQueryResult(item, mUserQuery));
|
|
|
|
edit.setText(getHighlightQueryResult(item, mUserQuery));
|
|
|
|
return view;
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 当EditText的文本发生变化时调用
|
|
|
|
public void onTextChange(int index, boolean hasText) {
|
|
|
|
public void onTextChange(int index, boolean hasText) {
|
|
|
|
|
|
|
|
// 如果索引超出范围
|
|
|
|
if (index >= mEditTextList.getChildCount()) {
|
|
|
|
if (index >= mEditTextList.getChildCount()) {
|
|
|
|
Log.e(TAG, "Wrong index, should not happen");
|
|
|
|
Log.e(TAG, "Wrong index, should not happen");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果有文本
|
|
|
|
if(hasText) {
|
|
|
|
if(hasText) {
|
|
|
|
|
|
|
|
// 设置CheckBox为可见
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.VISIBLE);
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
// 如果没有文本
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 设置CheckBox为不可见
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.GONE);
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void onCheckListModeChanged(int oldMode, int newMode) {
|
|
|
|
public void onCheckListModeChanged(int oldMode, int newMode) {
|
|
|
|
|
|
|
|
// 如果新模式是检查列表模式
|
|
|
|
if (newMode == TextNote.MODE_CHECK_LIST) {
|
|
|
|
if (newMode == TextNote.MODE_CHECK_LIST) {
|
|
|
|
|
|
|
|
// 切换到列表模式
|
|
|
|
switchToListMode(mNoteEditor.getText().toString());
|
|
|
|
switchToListMode(mNoteEditor.getText().toString());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 如果没有获取到工作文本
|
|
|
|
if (!getWorkingText()) {
|
|
|
|
if (!getWorkingText()) {
|
|
|
|
mWorkingNote.setWorkingText(mWorkingNote.getContent().replace(TAG_UNCHECKED + " ",
|
|
|
|
|
|
|
|
|
|
|
|
// 将工作笔记的内容中的未选中标签替换为空字符串
|
|
|
|
|
|
|
|
mWorkingNote.setWorkingText(mWorkingNote.getContent().replace(TAG_UNCHECKED + " ", ""));
|
|
|
|
""));
|
|
|
|
""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 设置笔记编辑器的内容为高亮查询结果
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
|
|
|
|
// 隐藏文本编辑器列表
|
|
|
|
mEditTextList.setVisibility(View.GONE);
|
|
|
|
mEditTextList.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
// 显示笔记编辑器
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取工作文本
|
|
|
|
private boolean getWorkingText() {
|
|
|
|
private boolean getWorkingText() {
|
|
|
|
boolean hasChecked = false;
|
|
|
|
boolean hasChecked = false;
|
|
|
|
|
|
|
|
// 如果工作笔记的检查列表模式为检查列表模式
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
|
|
|
|
// 创建一个StringBuilder对象
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
// 遍历EditTextList的子视图
|
|
|
|
for (int i = 0; i < mEditTextList.getChildCount(); i++) {
|
|
|
|
for (int i = 0; i < mEditTextList.getChildCount(); i++) {
|
|
|
|
|
|
|
|
// 获取子视图
|
|
|
|
View view = mEditTextList.getChildAt(i);
|
|
|
|
View view = mEditTextList.getChildAt(i);
|
|
|
|
|
|
|
|
// 获取NoteEditText对象
|
|
|
|
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
|
|
|
|
// 如果EditText的内容不为空
|
|
|
|
if (!TextUtils.isEmpty(edit.getText())) {
|
|
|
|
if (!TextUtils.isEmpty(edit.getText())) {
|
|
|
|
if (((CheckBox) view.findViewById(R.id.cb_edit_item)).isChecked()) {
|
|
|
|
if (((CheckBox) view.findViewById(R.id.cb_edit_item)).isChecked()) {
|
|
|
|
sb.append(TAG_CHECKED).append(" ").append(edit.getText()).append("\n");
|
|
|
|
sb.append(TAG_CHECKED).append(" ").append(edit.getText()).append("\n");
|
|
|
@ -806,8 +1079,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean saveNote() {
|
|
|
|
private boolean saveNote() {
|
|
|
|
|
|
|
|
// 获取当前工作文本
|
|
|
|
getWorkingText();
|
|
|
|
getWorkingText();
|
|
|
|
|
|
|
|
// 保存当前笔记
|
|
|
|
boolean saved = mWorkingNote.saveNote();
|
|
|
|
boolean saved = mWorkingNote.saveNote();
|
|
|
|
|
|
|
|
// 如果保存成功
|
|
|
|
if (saved) {
|
|
|
|
if (saved) {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* There are two modes from List view to edit view, open one note,
|
|
|
|
* There are two modes from List view to edit view, open one note,
|
|
|
@ -818,6 +1094,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
setResult(RESULT_OK);
|
|
|
|
setResult(RESULT_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 返回保存结果
|
|
|
|
return saved;
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -856,18 +1133,26 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据传入的content,去除TAG_CHECKED和TAG_UNCHECKED标签,并返回处理后的字符串
|
|
|
|
private String makeShortcutIconTitle(String content) {
|
|
|
|
private String makeShortcutIconTitle(String content) {
|
|
|
|
|
|
|
|
// 去除TAG_CHECKED标签
|
|
|
|
content = content.replace(TAG_CHECKED, "");
|
|
|
|
content = content.replace(TAG_CHECKED, "");
|
|
|
|
|
|
|
|
// 去除TAG_UNCHECKED标签
|
|
|
|
content = content.replace(TAG_UNCHECKED, "");
|
|
|
|
content = content.replace(TAG_UNCHECKED, "");
|
|
|
|
|
|
|
|
// 如果处理后的字符串长度大于SHORTCUT_ICON_TITLE_MAX_LEN,则截取前SHORTCUT_ICON_TITLE_MAX_LEN个字符
|
|
|
|
return content.length() > SHORTCUT_ICON_TITLE_MAX_LEN ? content.substring(0,
|
|
|
|
return content.length() > SHORTCUT_ICON_TITLE_MAX_LEN ? content.substring(0,
|
|
|
|
SHORTCUT_ICON_TITLE_MAX_LEN) : content;
|
|
|
|
SHORTCUT_ICON_TITLE_MAX_LEN) : content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 显示Toast,使用默认时长
|
|
|
|
private void showToast(int resId) {
|
|
|
|
private void showToast(int resId) {
|
|
|
|
|
|
|
|
// 调用showToast方法,传入resId和默认时长
|
|
|
|
showToast(resId, Toast.LENGTH_SHORT);
|
|
|
|
showToast(resId, Toast.LENGTH_SHORT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 显示Toast,使用指定时长
|
|
|
|
private void showToast(int resId, int duration) {
|
|
|
|
private void showToast(int resId, int duration) {
|
|
|
|
|
|
|
|
// 使用Toast.makeText方法创建Toast对象,并显示
|
|
|
|
Toast.makeText(this, resId, duration).show();
|
|
|
|
Toast.makeText(this, resId, duration).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|