Compare commits

...

2 Commits

@ -155,4 +155,4 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
mPlayer = null; mPlayer = null;
} }
} }
} }

@ -71,19 +71,25 @@ import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/**
* NoteEditActivity
*/
public class NoteEditActivity extends Activity implements OnClickListener, public class NoteEditActivity extends Activity implements OnClickListener,
NoteSettingChangedListener, OnTextViewChangeListener { NoteSettingChangedListener, OnTextViewChangeListener {
private class HeadViewHolder {
public TextView tvModified;
public ImageView ivAlertIcon; /**
* HeadViewHolder
public TextView tvAlertDate; */
private class HeadViewHolder {
public ImageView ibSetBgColor; 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>(); private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
static { static {
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW); 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); sBgSelectorBtnsMap.put(R.id.iv_bg_white, ResourceParser.WHITE);
} }
/**
* sBgSelectorSelectionMap HashMap ID ID
*/
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>(); private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
static { static {
sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select); 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); 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>(); private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
static { static {
sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE); 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); 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>(); 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);
@ -118,37 +133,90 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SUPER, R.id.iv_super_select); sFontSelectorSelectionMap.put(ResourceParser.TEXT_SUPER, R.id.iv_super_select);
} }
/**
* TAG
*/
private static final String TAG = "NoteEditActivity"; private static final String TAG = "NoteEditActivity";
/**
* mNoteHeaderHolder HeadViewHolder
*/
private HeadViewHolder mNoteHeaderHolder; private HeadViewHolder mNoteHeaderHolder;
/**
* mHeadViewPanel
*/
private View mHeadViewPanel; private View mHeadViewPanel;
/**
* mNoteBgColorSelector
*/
private View mNoteBgColorSelector; private View mNoteBgColorSelector;
/**
* mFontSizeSelector
*/
private View mFontSizeSelector; private View mFontSizeSelector;
/**
* mNoteEditor EditText
*/
private EditText mNoteEditor; private EditText mNoteEditor;
/**
* mNoteEditorPanel
*/
private View mNoteEditorPanel; private View mNoteEditorPanel;
/**
* mWorkingNote WorkingNote
*/
private WorkingNote mWorkingNote; private WorkingNote mWorkingNote;
/**
* mSharedPrefs SharedPreferences
*/
private SharedPreferences mSharedPrefs; private SharedPreferences mSharedPrefs;
/**
* mFontSizeId ID
*/
private int mFontSizeId; private int mFontSizeId;
/**
* PREFERENCE_FONT_SIZE
*/
private static final String PREFERENCE_FONT_SIZE = "pref_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; 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_CHECKED = String.valueOf('\u221A');
public static final String TAG_UNCHECKED = String.valueOf('\u25A1'); public static final String TAG_UNCHECKED = String.valueOf('\u25A1');
/**
* mEditTextList NoteEditText LinearLayout
*/
private LinearLayout mEditTextList; private LinearLayout mEditTextList;
/**
* mUserQuery
*/
private String mUserQuery; private String mUserQuery;
/**
* mPattern
*/
private Pattern mPattern; private Pattern mPattern;
/**
* onCreate
*/
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(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 * onRestoreInstanceState
* user load this activity, we should restore the former state
*/ */
@Override @Override
protected void onRestoreInstanceState(Bundle savedInstanceState) { 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) { 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; mWorkingNote = null;
if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) { if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0); long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
mUserQuery = ""; mUserQuery = "";
/**
* Starting from the searched result
*/
if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) { if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {
noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY)); noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY); 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_STATE_HIDDEN
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) { } else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
// New note // 新笔记
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0); long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID, int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID); AppWidgetManager.INVALID_APPWIDGET_ID);
@ -224,108 +290,168 @@ public class NoteEditActivity extends Activity implements OnClickListener,
int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID,
ResourceParser.getDefaultBgId(this)); ResourceParser.getDefaultBgId(this));
// Parse call-record note // 解析通话记录笔记
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); // 从传入的 Intent 中获取电话号码
long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0); String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
if (callDate != 0 && phoneNumber != null) { // 从传入的 Intent 中获取通话日期,若不存在则返回默认值 0
if (TextUtils.isEmpty(phoneNumber)) { long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);
Log.w(TAG, "The call record number is null"); // 如果通话日期不为 0 且电话号码不为 null
} if (callDate!= 0 && phoneNumber!= null) {
long noteId = 0; // 如果电话号码为空字符串
if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(), if (TextUtils.isEmpty(phoneNumber)) {
phoneNumber, callDate)) > 0) { // 打印警告日志,提示通话记录号码为空
mWorkingNote = WorkingNote.load(this, noteId); Log.w(TAG, "The call record number is null");
if (mWorkingNote == null) { }
Log.e(TAG, "load call note failed with note id" + noteId); // 初始化笔记 ID 为 0
finish(); long noteId = 0;
return false; // 通过电话号码和通话日期从内容解析器中获取笔记 ID
} // 如果获取到的笔记 ID 大于 0
} else { if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(),
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, phoneNumber, callDate)) > 0) {
widgetType, bgResId); // 根据笔记 ID 加载工作笔记
mWorkingNote.convertToCallNote(phoneNumber, callDate); mWorkingNote = WorkingNote.load(this, noteId);
} // 如果加载的工作笔记为 null
} else { if (mWorkingNote == null) {
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType, // 打印错误日志,提示加载通话笔记失败
bgResId); Log.e(TAG, "load call note failed with note id" + noteId);
} // 结束当前活动
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");
finish(); finish();
// 返回 false 表示操作失败
return false; return false;
} }
mWorkingNote.setOnSettingStatusChangedListener(this); } else {
return true; // 创建一个空笔记
} mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId,
widgetType, bgResId);
@Override // 将空笔记转换为通话笔记
protected void onResume() { mWorkingNote.convertToCallNote(phoneNumber, callDate);
super.onResume();
initNoteScreen();
} }
} else {
// 创建一个空笔记
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType,
bgResId);
}
private void initNoteScreen() { // 设置窗口的软键盘模式,调整布局大小并使其可见
mNoteEditor.setTextAppearance(this, TextAppearanceResources getWindow().setSoftInputMode(
.getTexAppearanceResource(mFontSizeId)); WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) { | WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
switchToListMode(mWorkingNote.getContent()); } else {
} else { // 打印错误日志,提示 Intent 未指定支持的操作
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery)); Log.e(TAG, "Intent not specified action, should not support");
mNoteEditor.setSelection(mNoteEditor.getText().length()); // 结束当前活动
} finish();
for (Integer id : sBgSelectorSelectionMap.keySet()) { // 返回 false 表示操作失败
findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE); return false;
} }
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId()); // 为工作笔记设置状态改变监听器
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId()); mWorkingNote.setOnSettingStatusChangedListener(this);
// 返回 true 表示操作成功
return true;
}
mNoteHeaderHolder.tvModified.setText(DateUtils.formatDateTime(this, /**
mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_DATE * onResume
| DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME */
| DateUtils.FORMAT_SHOW_YEAR)); // 重写 onResume 方法
@Override
protected void onResume() {
// 调用父类的 onResume 方法
super.onResume();
// 初始化笔记屏幕
initNoteScreen();
}
/** /**
* TODO: Add the menu for setting alert. Currently disable it because the DateTimePicker * initNoteScreen
* is not ready */
*/ // 定义初始化笔记屏幕的方法
showAlertHeader(); 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());
} }
// 遍历背景选择器选中状态映射的键集
private void showAlertHeader() { for (Integer id : sBgSelectorSelectionMap.keySet()) {
if (mWorkingNote.hasClockAlert()) { // 获取对应键的视图并设置为不可见
long time = System.currentTimeMillis(); findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);
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);
};
} }
// 设置头部视图面板的背景资源
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
// 设置笔记编辑器面板的背景资源
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
@Override // 设置笔记头部修改时间的文本
protected void onNewIntent(Intent intent) { mNoteHeaderHolder.tvModified.setText(DateUtils.formatDateTime(this,
super.onNewIntent(intent); mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_DATE
initActivityState(intent); | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME
| DateUtils.FORMAT_SHOW_YEAR));
/**
* TODO: Add the menu for setting alert. Currently disable it because the DateTimePicker
* is not ready
*/
// 显示提醒头部
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 便
*/
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(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()) { if (!mWorkingNote.existInDatabase()) {
saveNote(); saveNote();
} }
@ -333,6 +459,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
Log.d(TAG, "Save working note id: " + mWorkingNote.getNoteId() + " onSaveInstanceState"); Log.d(TAG, "Save working note id: " + mWorkingNote.getNoteId() + " onSaveInstanceState");
} }
/**
* dispatchTouchEvent
*/
@Override @Override
public boolean dispatchTouchEvent(MotionEvent ev) { public boolean dispatchTouchEvent(MotionEvent ev) {
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE if (mNoteBgColorSelector.getVisibility() == View.VISIBLE
@ -349,6 +478,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return super.dispatchTouchEvent(ev); return super.dispatchTouchEvent(ev);
} }
/**
* inRangeOfView
*/
private boolean inRangeOfView(View view, MotionEvent ev) { private boolean inRangeOfView(View view, MotionEvent ev) {
int []location = new int[2]; int []location = new int[2];
view.getLocationOnScreen(location); view.getLocationOnScreen(location);
@ -358,11 +490,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|| ev.getX() > (x + view.getWidth()) || ev.getX() > (x + view.getWidth())
|| ev.getY() < y || ev.getY() < y
|| ev.getY() > (y + view.getHeight())) { || ev.getY() > (y + view.getHeight())) {
return false; return false;
} }
return true; return true;
} }
/**
* initResources
*/
private void initResources() { private void initResources() {
mHeadViewPanel = findViewById(R.id.note_title); mHeadViewPanel = findViewById(R.id.note_title);
mNoteHeaderHolder = new HeadViewHolder(); mNoteHeaderHolder = new HeadViewHolder();
@ -397,6 +532,9 @@ 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() {
super.onPause(); super.onPause();
@ -406,6 +544,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
clearSettingState(); clearSettingState();
} }
/**
* updateWidget
*/
private void updateWidget() { private void updateWidget() {
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) { if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {
@ -418,19 +559,22 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
mWorkingNote.getWidgetId() mWorkingNote.getWidgetId()
}); });
sendBroadcast(intent); sendBroadcast(intent);
setResult(RESULT_OK, intent); setResult(RESULT_OK, intent);
} }
/**
* onClick ID
*/
public void onClick(View v) { public void onClick(View v) {
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);
@ -452,6 +596,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
} }
/**
* onBackPressed
*/
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if(clearSettingState()) { if(clearSettingState()) {
@ -462,6 +609,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
super.onBackPressed(); super.onBackPressed();
} }
/**
* clearSettingState true false
*/
private boolean clearSettingState() { private boolean clearSettingState() {
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE) { if (mNoteBgColorSelector.getVisibility() == View.VISIBLE) {
mNoteBgColorSelector.setVisibility(View.GONE); mNoteBgColorSelector.setVisibility(View.GONE);
@ -473,6 +623,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return false; return false;
} }
/**
* onBackgroundColorChanged
*/
public void onBackgroundColorChanged() { public void onBackgroundColorChanged() {
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility( findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
View.VISIBLE); View.VISIBLE);
@ -480,6 +633,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId()); mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
} }
/**
* onPrepareOptionsMenu true
*/
@Override @Override
public boolean onPrepareOptionsMenu(Menu menu) { public boolean onPrepareOptionsMenu(Menu menu) {
if (isFinishing()) { if (isFinishing()) {
@ -505,6 +661,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return true; return true;
} }
/**
* onOptionsItemSelected ID
*/
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
@ -553,6 +712,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return true; return true;
} }
/**
* setReminder
*/
private void setReminder() { private void setReminder() {
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis()); DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
d.setOnDateTimeSetListener(new OnDateTimeSetListener() { d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
@ -564,8 +726,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
/** /**
* Share note to apps that support {@link Intent#ACTION_SEND} action * sendTo ACTION_SEND text/plain
* 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);
@ -574,11 +735,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
context.startActivity(intent); context.startActivity(intent);
} }
/**
* createNewNote NoteEditActivity
*/
private void createNewNote() { private void createNewNote() {
// Firstly, save current editing notes // 首先保存当前编辑的笔记
saveNote(); saveNote();
// For safety, start a new NoteEditActivity // 为了安全,创建一个新的 NoteEditActivity
finish(); finish();
Intent intent = new Intent(this, NoteEditActivity.class); Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_INSERT_OR_EDIT); intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
@ -586,6 +750,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
startActivity(intent); startActivity(intent);
} }
/**
* deleteCurrentNote
*/
private void deleteCurrentNote() { private void deleteCurrentNote() {
if (mWorkingNote.existInDatabase()) { if (mWorkingNote.existInDatabase()) {
HashSet<Long> ids = new HashSet<Long>(); HashSet<Long> ids = new HashSet<Long>();
@ -608,15 +775,17 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mWorkingNote.markDeleted(true); mWorkingNote.markDeleted(true);
} }
/**
* isSyncMode
*/
private boolean isSyncMode() { private boolean isSyncMode() {
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0; return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
} }
/**
* onClockAlertChanged
*/
public void onClockAlertChanged(long date, boolean set) { 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()) { if (!mWorkingNote.existInDatabase()) {
saveNote(); saveNote();
} }
@ -632,20 +801,21 @@ public class NoteEditActivity extends Activity implements OnClickListener,
alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent); alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent);
} }
} else { } 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"); Log.e(TAG, "Clock alert setting error");
showToast(R.string.error_note_empty_for_clock); showToast(R.string.error_note_empty_for_clock);
} }
} }
/**
* onWidgetChanged
*/
public void onWidgetChanged() { public void onWidgetChanged() {
updateWidget(); updateWidget();
} }
/**
* onEditTextDelete
*/
public void onEditTextDelete(int index, String text) { public void onEditTextDelete(int index, String text) {
int childCount = mEditTextList.getChildCount(); int childCount = mEditTextList.getChildCount();
if (childCount == 1) { if (childCount == 1) {
@ -672,10 +842,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
edit.setSelection(length); edit.setSelection(length);
} }
/**
* onEditTextEnter
*/
public void onEditTextEnter(int index, String text) { public void onEditTextEnter(int index, String text) {
/**
* Should not happen, check for debug
*/
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");
} }
@ -691,13 +861,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
} }
/**
* switchToListMode
*/
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++;
} }
} }
@ -708,6 +881,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mEditTextList.setVisibility(View.VISIBLE); mEditTextList.setVisibility(View.VISIBLE);
} }
/**
* getHighlightQueryResult
*/
private Spannable getHighlightQueryResult(String fullText, String userQuery) { private Spannable getHighlightQueryResult(String fullText, String userQuery) {
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText); SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
if (!TextUtils.isEmpty(userQuery)) { if (!TextUtils.isEmpty(userQuery)) {
@ -725,6 +901,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return spannable; return spannable;
} }
/**
* getListItem
*/
private View getListItem(String item, int index) { private View getListItem(String item, int index) {
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);
final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text); final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
@ -756,6 +935,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return view; return view;
} }
/**
* onTextChange
*/
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");
@ -768,13 +950,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
} }
/**
* onCheckListModeChanged
*/
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 + " ", "").trim());
""));
} }
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery)); mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
mEditTextList.setVisibility(View.GONE); mEditTextList.setVisibility(View.GONE);
@ -782,6 +966,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
} }
/**
* getWorkingText
*/
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) {
@ -805,28 +992,30 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return hasChecked; return hasChecked;
} }
/**
* saveNote RESULT_OK
*
* @return true false
*/
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, * /
* create/edit a node. Opening node requires to the original *
* position in the list when back from edit view, while creating a * {@link #RESULT_OK} /
* new node requires to the top of the list. This code
* {@link #RESULT_OK} is used to identify the create/edit state
*/ */
setResult(RESULT_OK); setResult(RESULT_OK);
} }
return saved; return saved;
} }
/**
* sendToDesktop
*
*/
private void 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()) { if (!mWorkingNote.existInDatabase()) {
saveNote(); saveNote();
} }
@ -847,15 +1036,20 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sendBroadcast(sender); sendBroadcast(sender);
} else { } else {
/** /**
* There is the condition that user has input nothing (the note is * ID
* not worthy saving), we have no note id, remind the user that he
* should input something
*/ */
Log.e(TAG, "Send to desktop error"); Log.e(TAG, "Send to desktop error");
showToast(R.string.error_note_empty_for_send_to_desktop); showToast(R.string.error_note_empty_for_send_to_desktop);
} }
} }
/**
* makeShortcutIconTitle
* 10
*
* @param content
* @return
*/
private String makeShortcutIconTitle(String content) { private String makeShortcutIconTitle(String content) {
content = content.replace(TAG_CHECKED, ""); content = content.replace(TAG_CHECKED, "");
content = content.replace(TAG_UNCHECKED, ""); content = content.replace(TAG_UNCHECKED, "");
@ -863,11 +1057,22 @@ public class NoteEditActivity extends Activity implements OnClickListener,
SHORTCUT_ICON_TITLE_MAX_LEN) : content; SHORTCUT_ICON_TITLE_MAX_LEN) : content;
} }
/**
* showToast Toast
*
* @param resId ID
*/
private void showToast(int resId) { private void showToast(int resId) {
showToast(resId, Toast.LENGTH_SHORT); showToast(resId, Toast.LENGTH_SHORT);
} }
/**
* showToast Toast
*
* @param resId ID
* @param duration Toast
*/
private void showToast(int resId, int duration) { private void showToast(int resId, int duration) {
Toast.makeText(this, resId, duration).show(); Toast.makeText(this, resId, duration).show();
} }
} }

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save