|
|
|
|
@ -74,17 +74,17 @@ import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
NoteSettingChangedListener, OnTextViewChangeListener {
|
|
|
|
|
private class HeadViewHolder {
|
|
|
|
|
public TextView tvModified;
|
|
|
|
|
private class HeadViewHolder {//头视图持有者类???
|
|
|
|
|
public TextView tvModified;//文本修改
|
|
|
|
|
|
|
|
|
|
public ImageView ivAlertIcon;
|
|
|
|
|
public ImageView ivAlertIcon;//图像提醒按钮?
|
|
|
|
|
|
|
|
|
|
public TextView tvAlertDate;
|
|
|
|
|
public TextView tvAlertDate;//文本提醒日期?
|
|
|
|
|
|
|
|
|
|
public ImageView ibSetBgColor;
|
|
|
|
|
public ImageView ibSetBgColor;//设置背景颜色图像视图
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();//背景颜色选择按钮映射
|
|
|
|
|
static {
|
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
|
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_red, ResourceParser.RED);
|
|
|
|
|
@ -92,7 +92,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_green, ResourceParser.GREEN);
|
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_white, ResourceParser.WHITE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//上下是反的为啥?构建双向印射关系,方便根据颜色值获取对应的选择按钮ID(比如当前背景是红的,红的按钮就是按下去的),或者根据选择按钮ID获取对应的颜色值
|
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
|
static {
|
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select);
|
|
|
|
|
@ -102,14 +102,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.WHITE, R.id.iv_bg_white_select);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
|
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();//字体大小选择按钮映射
|
|
|
|
|
static {
|
|
|
|
|
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_normal, ResourceParser.TEXT_MEDIUM);
|
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_super, ResourceParser.TEXT_SUPER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//同颜色的映射关系
|
|
|
|
|
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
|
static {
|
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select);
|
|
|
|
|
@ -150,7 +150,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
private Pattern mPattern;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {//创建活动时调用
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
this.setContentView(R.layout.note_edit);
|
|
|
|
|
|
|
|
|
|
@ -158,19 +158,19 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
finish();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
initResources();
|
|
|
|
|
initResources();//初始化资源
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Current activity may be killed when the memory is low. Once it is killed, for another time
|
|
|
|
|
* user load this activity, we should restore the former state
|
|
|
|
|
* user load this activity, we should restore the former state/
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
|
|
|
|
super.onRestoreInstanceState(savedInstanceState);
|
|
|
|
|
protected void onRestoreInstanceState(Bundle savedInstanceState) {//存储uid便于恢复活动状态时调用
|
|
|
|
|
super.onRestoreInstanceState(savedInstanceState); //使用 Intent Extra 在组件之间传递uid
|
|
|
|
|
if (savedInstanceState != null && savedInstanceState.containsKey(Intent.EXTRA_UID)) {
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, savedInstanceState.getLong(Intent.EXTRA_UID));
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW); //创建一个意图,用于显示笔记详情,大小是(action_view显示数据功能)
|
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, savedInstanceState.getLong(Intent.EXTRA_UID));//将uid添加到意图中,用于之后再调出来
|
|
|
|
|
if (!initActivityState(intent)) {
|
|
|
|
|
finish();
|
|
|
|
|
return;
|
|
|
|
|
@ -185,56 +185,56 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
* then jump to the NotesListActivity
|
|
|
|
|
*/
|
|
|
|
|
mWorkingNote = null;
|
|
|
|
|
if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
|
|
|
|
|
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
|
|
|
|
|
mUserQuery = "";
|
|
|
|
|
if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {//如果意图是查看操作
|
|
|
|
|
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);//获取uid
|
|
|
|
|
mUserQuery = "";//初始化用户查询,用于后续搜索
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Starting from the searched result
|
|
|
|
|
*/
|
|
|
|
|
if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {
|
|
|
|
|
noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
|
|
|
|
|
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);
|
|
|
|
|
if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {//如果意图包含搜索数据键
|
|
|
|
|
noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));//解析出笔记id
|
|
|
|
|
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);//解析出用户查询
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) {
|
|
|
|
|
if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) {//如果笔记数据库中不存在该笔记
|
|
|
|
|
Intent jump = new Intent(this, NotesListActivity.class);
|
|
|
|
|
startActivity(jump);
|
|
|
|
|
showToast(R.string.error_note_not_exist);
|
|
|
|
|
startActivity(jump);//执行跳转
|
|
|
|
|
showToast(R.string.error_note_not_exist);//显示笔记不存在的提示
|
|
|
|
|
finish();
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);
|
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);//加载笔记
|
|
|
|
|
if (mWorkingNote == null) {
|
|
|
|
|
Log.e(TAG, "load note failed with note id" + noteId);
|
|
|
|
|
finish();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
|
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
|
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
|
|
|
|
|
getWindow().setSoftInputMode( //控制软键盘的操作?
|
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN //隐藏
|
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);//调整布局
|
|
|
|
|
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {//如果意图是插入或编辑操作
|
|
|
|
|
// New note
|
|
|
|
|
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
|
|
|
|
|
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);//获取文件夹id
|
|
|
|
|
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
|
|
|
|
|
AppWidgetManager.INVALID_APPWIDGET_ID);
|
|
|
|
|
AppWidgetManager.INVALID_APPWIDGET_ID);//获取小部件id
|
|
|
|
|
int widgetType = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_TYPE,
|
|
|
|
|
Notes.TYPE_WIDGET_INVALIDE);
|
|
|
|
|
Notes.TYPE_WIDGET_INVALIDE);//获取小部件类型
|
|
|
|
|
int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID,
|
|
|
|
|
ResourceParser.getDefaultBgId(this));
|
|
|
|
|
ResourceParser.getDefaultBgId(this));//获取背景资源id
|
|
|
|
|
|
|
|
|
|
// Parse call-record note
|
|
|
|
|
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
|
|
|
|
|
long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);
|
|
|
|
|
if (callDate != 0 && phoneNumber != null) {
|
|
|
|
|
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);//获取电话号码
|
|
|
|
|
long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);//获取调用日期
|
|
|
|
|
if (callDate != 0 && phoneNumber != null) {//如果调用日期和电话号码都不为空
|
|
|
|
|
if (TextUtils.isEmpty(phoneNumber)) {
|
|
|
|
|
Log.w(TAG, "The call record number is null");
|
|
|
|
|
}
|
|
|
|
|
long noteId = 0;
|
|
|
|
|
long noteId = 0;//初始化笔记id
|
|
|
|
|
if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(),
|
|
|
|
|
phoneNumber, callDate)) > 0) {
|
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);
|
|
|
|
|
phoneNumber, callDate)) > 0) {//如果记录中根据电话号码和调用日期查询到笔记id
|
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);//加载笔记
|
|
|
|
|
if (mWorkingNote == null) {
|
|
|
|
|
Log.e(TAG, "load call note failed with note id" + noteId);
|
|
|
|
|
finish();
|
|
|
|
|
@ -242,15 +242,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId,
|
|
|
|
|
widgetType, bgResId);
|
|
|
|
|
mWorkingNote.convertToCallNote(phoneNumber, callDate);
|
|
|
|
|
widgetType, bgResId);//新建笔记
|
|
|
|
|
mWorkingNote.convertToCallNote(phoneNumber, callDate);//将笔记转换为call笔记
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType,
|
|
|
|
|
bgResId);
|
|
|
|
|
bgResId);//新建笔记
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
|
getWindow().setSoftInputMode(//设置软键盘操作
|
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
|
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
@ -258,32 +258,32 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
finish();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
mWorkingNote.setOnSettingStatusChangedListener(this);
|
|
|
|
|
mWorkingNote.setOnSettingStatusChangedListener(this);//设置笔记设置状态改变监听器
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
protected void onResume() {//已经oncreate后切出,再次调用时,初始化笔记界面
|
|
|
|
|
super.onResume();
|
|
|
|
|
initNoteScreen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initNoteScreen() {
|
|
|
|
|
mNoteEditor.setTextAppearance(this, TextAppearanceResources
|
|
|
|
|
.getTexAppearanceResource(mFontSizeId));
|
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
|
.getTexAppearanceResource(mFontSizeId));//设置文本字体外观资源
|
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {//根据笔记模式( 清单模式 或 普通模式 )初始化编辑器内容
|
|
|
|
|
switchToListMode(mWorkingNote.getContent());//切换到列表清单模式
|
|
|
|
|
} else {
|
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
|
mNoteEditor.setSelection(mNoteEditor.getText().length());
|
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));//设置文本内容为高亮查询结果
|
|
|
|
|
mNoteEditor.setSelection(mNoteEditor.getText().length());//将光标定位到文本末尾,方便用户继续编辑
|
|
|
|
|
}
|
|
|
|
|
for (Integer id : sBgSelectorSelectionMap.keySet()) {
|
|
|
|
|
for (Integer id : sBgSelectorSelectionMap.keySet()) {//隐藏所有背景色选择器的 选中状态指示器
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
|
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
|
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());//设置笔记标题界面的 背景资源
|
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());设置笔记编辑区界面的 背景资源
|
|
|
|
|
|
|
|
|
|
mNoteHeaderHolder.tvModified.setText(DateUtils.formatDateTime(this,
|
|
|
|
|
mNoteHeaderHolder.tvModified.setText(DateUtils.formatDateTime(this, //显示笔记的 最后修改日期 ,并格式化显示
|
|
|
|
|
mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_DATE
|
|
|
|
|
| DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME
|
|
|
|
|
| DateUtils.FORMAT_SHOW_YEAR));
|
|
|
|
|
@ -295,14 +295,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
showAlertHeader();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showAlertHeader() {
|
|
|
|
|
private void showAlertHeader() {//显示笔记的 闹钟提醒 信息
|
|
|
|
|
if (mWorkingNote.hasClockAlert()) {
|
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
|
if (time > mWorkingNote.getAlertDate()) {
|
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setText(R.string.note_alert_expired);
|
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setText(R.string.note_alert_expired);//显示已过期信息
|
|
|
|
|
} else {
|
|
|
|
|
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.ivAlertIcon.setVisibility(View.VISIBLE);
|
|
|
|
|
@ -313,13 +313,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
|
protected void onNewIntent(Intent intent) {//处理新的intent
|
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
|
initActivityState(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {//保存活动状态
|
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
|
/**
|
|
|
|
|
* For new note without note id, we should firstly save it to
|
|
|
|
|
@ -334,23 +334,23 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {//处理触摸事件
|
|
|
|
|
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE
|
|
|
|
|
&& !inRangeOfView(mNoteBgColorSelector, ev)) {
|
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);
|
|
|
|
|
&& !inRangeOfView(mNoteBgColorSelector, ev)) {//如果背景色选择器可见,且触摸事件不在范围内?
|
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);//隐藏背景色选择器
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mFontSizeSelector.getVisibility() == View.VISIBLE
|
|
|
|
|
&& !inRangeOfView(mFontSizeSelector, ev)) {
|
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
|
&& !inRangeOfView(mFontSizeSelector, ev)) {//如果字体大小选择器可见,且触摸事件不在范围内?
|
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);//隐藏字体大小选择器
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return super.dispatchTouchEvent(ev);
|
|
|
|
|
return super.dispatchTouchEvent(ev);//将事件传递给父类处理
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean inRangeOfView(View view, MotionEvent ev) {
|
|
|
|
|
int []location = new int[2];
|
|
|
|
|
private boolean inRangeOfView(View view, MotionEvent ev) {//判断触摸事件是否在视图范围内
|
|
|
|
|
int []location = new int[2];//获取视图在屏幕上的坐标,长度为2的整数数组
|
|
|
|
|
view.getLocationOnScreen(location);
|
|
|
|
|
int x = location[0];
|
|
|
|
|
int y = location[1];
|
|
|
|
|
@ -363,7 +363,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initResources() {
|
|
|
|
|
private void initResources() {//初始化资源
|
|
|
|
|
mHeadViewPanel = findViewById(R.id.note_title);
|
|
|
|
|
mNoteHeaderHolder = new HeadViewHolder();
|
|
|
|
|
mNoteHeaderHolder.tvModified = (TextView) findViewById(R.id.tv_modified_date);
|
|
|
|
|
@ -398,16 +398,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onPause() {
|
|
|
|
|
super.onPause();
|
|
|
|
|
protected void onPause() {//在活动暂停时调用(切出去了)
|
|
|
|
|
super.onPause();//调用父类的onPause方法
|
|
|
|
|
if(saveNote()) {
|
|
|
|
|
Log.d(TAG, "Note data was saved with length:" + mWorkingNote.getContent().length());
|
|
|
|
|
}
|
|
|
|
|
clearSettingState();
|
|
|
|
|
clearSettingState();//清除设置状态
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateWidget() {
|
|
|
|
|
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
|
|
|
|
private void updateWidget() {//更新应用小部件
|
|
|
|
|
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);//接受意图
|
|
|
|
|
if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {
|
|
|
|
|
intent.setClass(this, NoteWidgetProvider_2x.class);
|
|
|
|
|
} else if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_4X) {
|
|
|
|
|
@ -417,30 +417,31 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
|
|
|
|
|
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {//添加应用小部件id
|
|
|
|
|
mWorkingNote.getWidgetId()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
sendBroadcast(intent);
|
|
|
|
|
setResult(RESULT_OK, intent);
|
|
|
|
|
sendBroadcast(intent);//发送广播更新应用小部件
|
|
|
|
|
setResult(RESULT_OK, intent);//设置结果为成功,返回意图
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
public void onClick(View v) {//点击事件处理,语法细节没看
|
|
|
|
|
int id = v.getId();
|
|
|
|
|
if (id == R.id.btn_set_bg_color) {
|
|
|
|
|
if (id == R.id.btn_set_bg_color) {//如果点击的是设置背景颜色按钮
|
|
|
|
|
mNoteBgColorSelector.setVisibility(View.VISIBLE);
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
|
- View.VISIBLE);
|
|
|
|
|
} else if (sBgSelectorBtnsMap.containsKey(id)) {
|
|
|
|
|
} else if (sBgSelectorBtnsMap.containsKey(id)) {//如果点击的是背景颜色选择按钮
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
|
View.GONE);
|
|
|
|
|
mWorkingNote.setBgColorId(sBgSelectorBtnsMap.get(id));
|
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);
|
|
|
|
|
} else if (sFontSizeBtnsMap.containsKey(id)) {
|
|
|
|
|
} else if (sFontSizeBtnsMap.containsKey(id)) {//如果点击的是字体大小选择按钮
|
|
|
|
|
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.GONE);
|
|
|
|
|
mFontSizeId = sFontSizeBtnsMap.get(id);
|
|
|
|
|
mSharedPrefs.edit().putInt(PREFERENCE_FONT_SIZE, mFontSizeId).commit();
|
|
|
|
|
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
|
|
|
|
|
//区分两种模式,列表模式和普通模式
|
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
|
getWorkingText();
|
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
|
@ -453,17 +454,17 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBackPressed() {
|
|
|
|
|
public void onBackPressed() {//返回键处理
|
|
|
|
|
if(clearSettingState()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveNote();
|
|
|
|
|
saveNote();//保存笔记
|
|
|
|
|
super.onBackPressed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean clearSettingState() {
|
|
|
|
|
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE) {
|
|
|
|
|
private boolean clearSettingState() {//清除设置状态
|
|
|
|
|
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE) {//
|
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);
|
|
|
|
|
return true;
|
|
|
|
|
} else if (mFontSizeSelector.getVisibility() == View.VISIBLE) {
|
|
|
|
|
@ -473,29 +474,29 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onBackgroundColorChanged() {
|
|
|
|
|
public void onBackgroundColorChanged() {//
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
|
View.VISIBLE);
|
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
|
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
|
|
|
|
|
View.VISIBLE);//显示选中的背景颜色
|
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());//设置笔记编辑面板的背景颜色
|
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());//设置标题栏的背景颜色
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {//准备选项菜单
|
|
|
|
|
if (isFinishing()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
clearSettingState();
|
|
|
|
|
menu.clear();
|
|
|
|
|
if (mWorkingNote.getFolderId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
|
getMenuInflater().inflate(R.menu.call_note_edit, menu);
|
|
|
|
|
if (mWorkingNote.getFolderId() == Notes.ID_CALL_RECORD_FOLDER) {//判断类型
|
|
|
|
|
getMenuInflater().inflate(R.menu.call_note_edit, menu);//如果是通话记录文件夹, 通话记录转化为菜单
|
|
|
|
|
} else {
|
|
|
|
|
getMenuInflater().inflate(R.menu.note_edit, menu);
|
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
|
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()) {
|
|
|
|
|
menu.findItem(R.id.menu_alert).setVisible(false);
|
|
|
|
|
@ -506,13 +507,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {//处理选项菜单点击事件
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
case R.id.menu_new_note:
|
|
|
|
|
case R.id.menu_new_note://新建笔记
|
|
|
|
|
createNewNote();
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_delete:
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
|
case R.id.menu_delete://删除笔记
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);//创建删除确认对话框
|
|
|
|
|
builder.setTitle(getString(R.string.alert_title_delete));
|
|
|
|
|
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
|
|
builder.setMessage(getString(R.string.alert_message_delete_note));
|
|
|
|
|
@ -526,25 +527,25 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
builder.setNegativeButton(android.R.string.cancel, null);
|
|
|
|
|
builder.show();
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_font_size:
|
|
|
|
|
case R.id.menu_font_size://字体大小选择
|
|
|
|
|
mFontSizeSelector.setVisibility(View.VISIBLE);
|
|
|
|
|
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_list_mode:
|
|
|
|
|
case R.id.menu_list_mode://列表模式切换
|
|
|
|
|
mWorkingNote.setCheckListMode(mWorkingNote.getCheckListMode() == 0 ?
|
|
|
|
|
TextNote.MODE_CHECK_LIST : 0);
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_share:
|
|
|
|
|
case R.id.menu_share://分享笔记
|
|
|
|
|
getWorkingText();
|
|
|
|
|
sendTo(this, mWorkingNote.getContent());
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_send_to_desktop:
|
|
|
|
|
case R.id.menu_send_to_desktop://发送到桌面
|
|
|
|
|
sendToDesktop();
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_alert:
|
|
|
|
|
case R.id.menu_alert://设置提醒
|
|
|
|
|
setReminder();
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_delete_remind:
|
|
|
|
|
case R.id.menu_delete_remind://删除提醒
|
|
|
|
|
mWorkingNote.setAlertDate(0, false);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
@ -552,7 +553,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//下面是上文相关函数的具体实现
|
|
|
|
|
private void setReminder() {
|
|
|
|
|
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
|
|
|
|
|
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
|
|
|
|
|
@ -569,7 +570,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
*/
|
|
|
|
|
private void sendTo(Context context, String info) {
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, info);
|
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, info);//再intetn中添加标签为EXTRA_TEXT, 值为info
|
|
|
|
|
intent.setType("text/plain");
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
@ -590,17 +591,17 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
if (mWorkingNote.existInDatabase()) {
|
|
|
|
|
HashSet<Long> ids = new HashSet<Long>();
|
|
|
|
|
long id = mWorkingNote.getNoteId();
|
|
|
|
|
if (id != Notes.ID_ROOT_FOLDER) {
|
|
|
|
|
ids.add(id);
|
|
|
|
|
if (id != Notes.ID_ROOT_FOLDER) {//如果不是根文件夹
|
|
|
|
|
ids.add(id);//将笔记id添加到集合中
|
|
|
|
|
} else {
|
|
|
|
|
Log.d(TAG, "Wrong note id, should not happen");
|
|
|
|
|
}
|
|
|
|
|
if (!isSyncMode()) {
|
|
|
|
|
if (!DataUtils.batchDeleteNotes(getContentResolver(), ids)) {
|
|
|
|
|
if (!isSyncMode()) {//如果不是同步模式
|
|
|
|
|
if (!DataUtils.batchDeleteNotes(getContentResolver(), ids)) {//批量删除笔记
|
|
|
|
|
Log.e(TAG, "Delete Note error");
|
|
|
|
|
}
|
|
|
|
|
} 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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -612,7 +613,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
@ -646,33 +647,34 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
updateWidget();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onEditTextDelete(int index, String text) {
|
|
|
|
|
int childCount = mEditTextList.getChildCount();
|
|
|
|
|
public void onEditTextDelete(int index, String text) {//处理清单模式下删除列表项 的操作
|
|
|
|
|
int childCount = mEditTextList.getChildCount();//获取编辑框的子视图数量
|
|
|
|
|
if (childCount == 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = index + 1; i < childCount; i++) {
|
|
|
|
|
for (int i = index + 1; i < childCount; i++) {//遍历删除项(index处)之后的所有列表项 ,将它们的索引减1,不会影响到后续的列表项的索引,从而避免了索引错乱的问题
|
|
|
|
|
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
|
|
|
|
.setIndex(i - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mEditTextList.removeViewAt(index);
|
|
|
|
|
mEditTextList.removeViewAt(index);//删除index处的子图
|
|
|
|
|
//亮点:小米笔记清单模式下的特殊设计 ,属于防误删的安全机制 ,主要为了保护用户内容,这是啥意思?
|
|
|
|
|
NoteEditText edit = null;
|
|
|
|
|
if(index == 0) {
|
|
|
|
|
edit = (NoteEditText) mEditTextList.getChildAt(0).findViewById(
|
|
|
|
|
R.id.et_edit_text);
|
|
|
|
|
} else {
|
|
|
|
|
edit = (NoteEditText) mEditTextList.getChildAt(index - 1).findViewById(
|
|
|
|
|
R.id.et_edit_text);
|
|
|
|
|
R.id.et_edit_text);//
|
|
|
|
|
}
|
|
|
|
|
int length = edit.length();
|
|
|
|
|
edit.append(text);
|
|
|
|
|
edit.requestFocus();
|
|
|
|
|
edit.setSelection(length);
|
|
|
|
|
int length = edit.length();//获取删除项(index处)之前的列表项的文本长度
|
|
|
|
|
edit.append(text);//将被删除项的文本追加到目标项末尾
|
|
|
|
|
edit.requestFocus();//将焦点自动切换到目标项
|
|
|
|
|
edit.setSelection(length);//将光标定位到合并前的文本末尾
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onEditTextEnter(int index, String text) {
|
|
|
|
|
public void onEditTextEnter(int index, String text) {//处理清单模式下添加列表项的操作
|
|
|
|
|
/**
|
|
|
|
|
* Should not happen, check for debug
|
|
|
|
|
*/
|
|
|
|
|
@ -681,40 +683,40 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
View view = getListItem(text, index);
|
|
|
|
|
mEditTextList.addView(view, index);
|
|
|
|
|
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
|
mEditTextList.addView(view, index);//将新的列表项视图添加到编辑框中,位置为index
|
|
|
|
|
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);//获取新添加的列表项的编辑框
|
|
|
|
|
edit.requestFocus();
|
|
|
|
|
edit.setSelection(0);
|
|
|
|
|
for (int i = index + 1; i < mEditTextList.getChildCount(); i++) {
|
|
|
|
|
edit.setSelection(0);//将光标定位到新添加的列表项的文本开头
|
|
|
|
|
for (int i = index + 1; i < mEditTextList.getChildCount(); i++) {//索引加一
|
|
|
|
|
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
|
|
|
|
.setIndex(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void switchToListMode(String text) {
|
|
|
|
|
private void switchToListMode(String text) {//将编辑框切换到清单模式
|
|
|
|
|
mEditTextList.removeAllViews();
|
|
|
|
|
String[] items = text.split("\n");
|
|
|
|
|
int index = 0;
|
|
|
|
|
for (String item : items) {
|
|
|
|
|
if(!TextUtils.isEmpty(item)) {
|
|
|
|
|
mEditTextList.addView(getListItem(item, index));
|
|
|
|
|
mEditTextList.addView(getListItem(item, index));//将新的列表项视图添加到编辑框中,位置为index
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mEditTextList.addView(getListItem("", index));
|
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.et_edit_text).requestFocus();
|
|
|
|
|
mEditTextList.addView(getListItem("", index));//添加一个空列表项
|
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.et_edit_text).requestFocus();//将焦点自动切换到新添加的空列表项的编辑框
|
|
|
|
|
|
|
|
|
|
mNoteEditor.setVisibility(View.GONE);
|
|
|
|
|
mNoteEditor.setVisibility(View.GONE);//隐藏编辑框
|
|
|
|
|
mEditTextList.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Spannable getHighlightQueryResult(String fullText, String userQuery) {
|
|
|
|
|
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
|
|
|
|
|
if (!TextUtils.isEmpty(userQuery)) {
|
|
|
|
|
mPattern = Pattern.compile(userQuery);
|
|
|
|
|
Matcher m = mPattern.matcher(fullText);
|
|
|
|
|
private Spannable getHighlightQueryResult(String fullText, String userQuery) {//高亮显示用户查询的文本,这里用了spannable,是比较好的视图管理器
|
|
|
|
|
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);//存储高亮显示的文本
|
|
|
|
|
if (!TextUtils.isEmpty(userQuery)) {
|
|
|
|
|
mPattern = Pattern.compile(userQuery, Pattern.CASE_INSENSITIVE);//编译正则表达式
|
|
|
|
|
Matcher m = mPattern.matcher(fullText);//创建一个 Matcher 对象,用于对输入字符串进行匹配操作
|
|
|
|
|
int start = 0;
|
|
|
|
|
while (m.find(start)) {
|
|
|
|
|
while (m.find(start)) { //构建span字符串
|
|
|
|
|
spannable.setSpan(
|
|
|
|
|
new BackgroundColorSpan(this.getResources().getColor(
|
|
|
|
|
R.color.user_query_highlight)), m.start(), m.end(),
|
|
|
|
|
@ -725,28 +727,28 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return spannable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
|
final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);//获取列表项的编辑框
|
|
|
|
|
edit.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
|
|
|
|
|
CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item));
|
|
|
|
|
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
|
if (isChecked) {
|
|
|
|
|
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
|
|
|
|
CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item)); //复选框用于让用户从有限数量的选项中选择一个或多个选项。
|
|
|
|
|
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {//复选框变化监听
|
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {//
|
|
|
|
|
if (isChecked) {//PaintFlags是Android中用于控制文本绘制样式的位掩码 ,通过位运算组合多个绘制标志
|
|
|
|
|
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);//添加删除线效果
|
|
|
|
|
} else {
|
|
|
|
|
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
|
|
|
|
|
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);//清除删除线效果
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (item.startsWith(TAG_CHECKED)) {
|
|
|
|
|
if (item.startsWith(TAG_CHECKED)) {//如果列表项以(TAG_CHECKED)开头,则将复选框设置为选中状态
|
|
|
|
|
cb.setChecked(true);
|
|
|
|
|
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
|
|
|
|
item = item.substring(TAG_CHECKED.length(), item.length()).trim();
|
|
|
|
|
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);//
|
|
|
|
|
item = item.substring(TAG_CHECKED.length(), item.length()).trim();//
|
|
|
|
|
} else if (item.startsWith(TAG_UNCHECKED)) {
|
|
|
|
|
cb.setChecked(false);
|
|
|
|
|
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
|
|
|
|
|
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);//
|
|
|
|
|
item = item.substring(TAG_UNCHECKED.length(), item.length()).trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -756,25 +758,25 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onTextChange(int index, boolean hasText) {
|
|
|
|
|
if (index >= mEditTextList.getChildCount()) {
|
|
|
|
|
public void onTextChange(int index, boolean hasText) {// 列表项文本变化事件
|
|
|
|
|
if (index >= mEditTextList.getChildCount()) {//检查索引是否超出范围
|
|
|
|
|
Log.e(TAG, "Wrong index, should not happen");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(hasText) {
|
|
|
|
|
if(hasText) {//如果列表项有文本
|
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onCheckListModeChanged(int oldMode, int newMode) {
|
|
|
|
|
if (newMode == TextNote.MODE_CHECK_LIST) {
|
|
|
|
|
public void onCheckListModeChanged(int oldMode, int newMode) {// 检查列表模式变化事件
|
|
|
|
|
if (newMode == TextNote.MODE_CHECK_LIST) {//如果切换到检查列表模式
|
|
|
|
|
switchToListMode(mNoteEditor.getText().toString());
|
|
|
|
|
} else {
|
|
|
|
|
if (!getWorkingText()) {
|
|
|
|
|
mWorkingNote.setWorkingText(mWorkingNote.getContent().replace(TAG_UNCHECKED + " ",
|
|
|
|
|
""));
|
|
|
|
|
""));//如果没有选中项,则将所有未选中项的文本删除
|
|
|
|
|
}
|
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
|
mEditTextList.setVisibility(View.GONE);
|
|
|
|
|
@ -782,19 +784,19 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean getWorkingText() {
|
|
|
|
|
private boolean getWorkingText() {//获取选中项的文本
|
|
|
|
|
boolean hasChecked = false;
|
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {//如果是检查列表模式
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < mEditTextList.getChildCount(); i++) {
|
|
|
|
|
for (int i = 0; i < mEditTextList.getChildCount(); i++) {//遍历所有列表项
|
|
|
|
|
View view = mEditTextList.getChildAt(i);
|
|
|
|
|
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
|
if (!TextUtils.isEmpty(edit.getText())) {
|
|
|
|
|
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");//如果列表项选中,则将其文本添加到 StringBuilder 中
|
|
|
|
|
hasChecked = true;
|
|
|
|
|
} else {
|
|
|
|
|
sb.append(TAG_UNCHECKED).append(" ").append(edit.getText()).append("\n");
|
|
|
|
|
sb.append(TAG_UNCHECKED).append(" ").append(edit.getText()).append("\n");//如果列表项未选中,则将其文本添加到 StringBuilder 中
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -805,7 +807,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return hasChecked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean saveNote() {
|
|
|
|
|
private boolean saveNote() {//保存笔记
|
|
|
|
|
getWorkingText();
|
|
|
|
|
boolean saved = mWorkingNote.saveNote();
|
|
|
|
|
if (saved) {
|
|
|
|
|
@ -821,29 +823,29 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return saved;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mWorkingNote.getNoteId() > 0) {
|
|
|
|
|
if (mWorkingNote.getNoteId() > 0) {//如果笔记存在于数据库中
|
|
|
|
|
Intent sender = new Intent();
|
|
|
|
|
Intent shortcutIntent = new Intent(this, NoteEditActivity.class);
|
|
|
|
|
shortcutIntent.setAction(Intent.ACTION_VIEW);
|
|
|
|
|
shortcutIntent.setAction(Intent.ACTION_VIEW);//设置意图操作行为为查看
|
|
|
|
|
shortcutIntent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
|
|
|
|
sender.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
|
|
|
|
sender.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);//将意图添加到发送者意图中
|
|
|
|
|
sender.putExtra(Intent.EXTRA_SHORTCUT_NAME,
|
|
|
|
|
makeShortcutIconTitle(mWorkingNote.getContent()));
|
|
|
|
|
makeShortcutIconTitle(mWorkingNote.getContent()));//将快捷图标标题添加到发送者意图中
|
|
|
|
|
sender.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
|
|
|
|
|
Intent.ShortcutIconResource.fromContext(this, R.drawable.icon_app));
|
|
|
|
|
sender.putExtra("duplicate", true);
|
|
|
|
|
sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
|
|
|
|
|
showToast(R.string.info_note_enter_desktop);
|
|
|
|
|
sender.putExtra("duplicate", true);//将重复项添加到发送者意图中
|
|
|
|
|
sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT");//设置意图操作行为为安装快捷图标
|
|
|
|
|
showToast(R.string.info_note_enter_desktop);//显示提示消息(成功)
|
|
|
|
|
sendBroadcast(sender);
|
|
|
|
|
} else {
|
|
|
|
|
/**
|
|
|
|
|
@ -856,18 +858,18 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String makeShortcutIconTitle(String content) {
|
|
|
|
|
private String makeShortcutIconTitle(String content) {//创建快捷图标标题
|
|
|
|
|
content = content.replace(TAG_CHECKED, "");
|
|
|
|
|
content = content.replace(TAG_UNCHECKED, "");
|
|
|
|
|
return content.length() > SHORTCUT_ICON_TITLE_MAX_LEN ? content.substring(0,
|
|
|
|
|
SHORTCUT_ICON_TITLE_MAX_LEN) : content;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showToast(int resId) {
|
|
|
|
|
showToast(resId, Toast.LENGTH_SHORT);
|
|
|
|
|
private void showToast(int resId) {//显示短时间的提示消息
|
|
|
|
|
showToast(resId, Toast.LENGTH_SHORT);//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showToast(int resId, int duration) {
|
|
|
|
|
private void showToast(int resId, int duration) {//显示自定义时间长度的 Toast 消息
|
|
|
|
|
Toast.makeText(this, resId, duration).show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|