|
|
|
@ -27,9 +27,11 @@ import android.content.Context;
|
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.graphics.Paint;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
|
import android.text.Spannable;
|
|
|
|
|
import android.text.SpannableString;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
@ -65,6 +67,7 @@ import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener;
|
|
|
|
|
import net.micode.notes.widget.NoteWidgetProvider_2x;
|
|
|
|
|
import net.micode.notes.widget.NoteWidgetProvider_4x;
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Map;
|
|
|
|
@ -72,8 +75,10 @@ import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
public class NoteEditActivity extends AppCompatActivity implements OnClickListener,
|
|
|
|
|
NoteSettingChangedListener, OnTextViewChangeListener {
|
|
|
|
|
private static final int REQUEST_CODE = 8848;
|
|
|
|
|
|
|
|
|
|
private class HeadViewHolder {
|
|
|
|
|
public TextView tvModified;
|
|
|
|
|
|
|
|
|
@ -132,7 +137,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
private View mNoteEditorPanel;
|
|
|
|
|
|
|
|
|
|
private WorkingNote mWorkingNote;
|
|
|
|
|
public WorkingNote mWorkingNote;
|
|
|
|
|
|
|
|
|
|
private SharedPreferences mSharedPrefs;
|
|
|
|
|
private int mFontSizeId;
|
|
|
|
@ -273,40 +278,40 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
.getTexAppearanceResource(mFontSizeId));//获取用户当前字体的大小
|
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {//转化为清单模式
|
|
|
|
|
switchToListMode(mWorkingNote.getContent());//获取对应的内容
|
|
|
|
|
} else {
|
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
|
mNoteEditor.setSelection(mNoteEditor.getText().length());
|
|
|
|
|
} else {//如果不是清单模式
|
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));//对用户输入的关键字文本进行高亮显示
|
|
|
|
|
mNoteEditor.setSelection(mNoteEditor.getText().length());//获取选取的长度
|
|
|
|
|
}
|
|
|
|
|
for (Integer id : sBgSelectorSelectionMap.keySet()) {
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);//找到当前键的值,也就是id,并隐藏背景选择器选中的背景图
|
|
|
|
|
}
|
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
|
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
|
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());//在头部显示标题
|
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());//在背景显示对应的背景颜色
|
|
|
|
|
|
|
|
|
|
mNoteHeaderHolder.tvModified.setText(DateUtils.formatDateTime(this,
|
|
|
|
|
mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_DATE
|
|
|
|
|
| DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME
|
|
|
|
|
| DateUtils.FORMAT_SHOW_YEAR));
|
|
|
|
|
| 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);
|
|
|
|
|
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(
|
|
|
|
|
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.VISIBLE);//显示提醒日期
|
|
|
|
|
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.VISIBLE);//显示提醒图标
|
|
|
|
|
} else {//没有时间提醒就隐藏对应的提醒标志
|
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
|
|
|
|
|
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
|
|
|
|
|
};
|
|
|
|
@ -326,75 +331,75 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
* 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();
|
|
|
|
|
}
|
|
|
|
|
outState.putLong(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
|
|
|
|
Log.d(TAG, "Save working note id: " + mWorkingNote.getNoteId() + " onSaveInstanceState");
|
|
|
|
|
outState.putLong(Intent.EXTRA_UID, mWorkingNote.getNoteId());//初始化
|
|
|
|
|
Log.d(TAG, "Save working note id: " + mWorkingNote.getNoteId() + " onSaveInstanceState");//显示对应id信息和保存成功
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
if (mFontSizeSelector.getVisibility() == View.VISIBLE//判断字体大小选择器是否显示,并且是否在改变字体大小的控制范围内
|
|
|
|
|
&& !inRangeOfView(mFontSizeSelector, ev)) {
|
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);//将其隐藏起来
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return super.dispatchTouchEvent(ev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean inRangeOfView(View view, MotionEvent ev) {
|
|
|
|
|
int []location = new int[2];
|
|
|
|
|
view.getLocationOnScreen(location);
|
|
|
|
|
int x = location[0];
|
|
|
|
|
int y = location[1];
|
|
|
|
|
int []location = new int[2];//获取位置
|
|
|
|
|
view.getLocationOnScreen(location);//获取鼠标所在屏幕的左上角对应位置
|
|
|
|
|
int x = location[0];//横坐标
|
|
|
|
|
int y = location[1];//纵坐标
|
|
|
|
|
if (ev.getX() < x
|
|
|
|
|
|| ev.getX() > (x + view.getWidth())
|
|
|
|
|
|| ev.getY() < y
|
|
|
|
|
|| ev.getY() > (y + view.getHeight())) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}//ev.getX获取了触摸事件的横坐标,getY则是获取纵坐标,该判断语句就是判断触摸事件的横纵坐标在该视图的外部
|
|
|
|
|
return true;//在管辖范畴内
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initResources() {
|
|
|
|
|
mHeadViewPanel = findViewById(R.id.note_title);
|
|
|
|
|
mNoteHeaderHolder = new HeadViewHolder();
|
|
|
|
|
mNoteHeaderHolder.tvModified = (TextView) findViewById(R.id.tv_modified_date);
|
|
|
|
|
mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon);
|
|
|
|
|
mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);
|
|
|
|
|
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
|
|
|
|
|
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
|
|
|
|
|
mNoteEditor = (EditText) findViewById(R.id.note_edit_view);
|
|
|
|
|
mNoteEditorPanel = findViewById(R.id.sv_note_edit);
|
|
|
|
|
mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector);
|
|
|
|
|
for (int id : sBgSelectorBtnsMap.keySet()) {
|
|
|
|
|
mHeadViewPanel = findViewById(R.id.note_title);//获取对应id的视图
|
|
|
|
|
mNoteHeaderHolder = new HeadViewHolder();//实例化头部信息
|
|
|
|
|
mNoteHeaderHolder.tvModified = (TextView) findViewById(R.id.tv_modified_date);//把修改日期视图封装在mNoteHeaderHolder中
|
|
|
|
|
mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon);//把提醒图标视图封装在对象中
|
|
|
|
|
mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);//把提醒日期视图封装在对象中
|
|
|
|
|
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);//把改变背景颜色的视图封装在对象中
|
|
|
|
|
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);//设置对应的监听器
|
|
|
|
|
mNoteEditor = (EditText) findViewById(R.id.note_edit_view);//找到对应的编辑器视图
|
|
|
|
|
mNoteEditorPanel = findViewById(R.id.sv_note_edit);//把保存便签的视图放在该对象中
|
|
|
|
|
mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector);//将背景颜色选择器捆绑给mNoteBgColorSelector中
|
|
|
|
|
for (int id : sBgSelectorBtnsMap.keySet()) {//为每一种背景颜色对应的视图设置监听器
|
|
|
|
|
ImageView iv = (ImageView) findViewById(id);
|
|
|
|
|
iv.setOnClickListener(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mFontSizeSelector = findViewById(R.id.font_size_selector);
|
|
|
|
|
for (int id : sFontSizeBtnsMap.keySet()) {
|
|
|
|
|
mFontSizeSelector = findViewById(R.id.font_size_selector);//捆绑字体大小选择器
|
|
|
|
|
for (int id : sFontSizeBtnsMap.keySet()) {//为每一种字体大小设置监听器
|
|
|
|
|
View view = findViewById(id);
|
|
|
|
|
view.setOnClickListener(this);
|
|
|
|
|
};
|
|
|
|
|
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
|
mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);
|
|
|
|
|
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);//获取默认的共享偏好
|
|
|
|
|
mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);//设置字体大小
|
|
|
|
|
/**
|
|
|
|
|
* HACKME: Fix bug of store the resource id in shared preference.
|
|
|
|
|
* The id may larger than the length of resources, in this case,
|
|
|
|
|
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
|
|
|
|
|
*/
|
|
|
|
|
if(mFontSizeId >= TextAppearanceResources.getResourcesSize()) {
|
|
|
|
|
if(mFontSizeId >= TextAppearanceResources.getResourcesSize()) {//如果设置的字体大小的id超过了限制,那么就重新调回默认的字体大小
|
|
|
|
|
mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE;
|
|
|
|
|
}
|
|
|
|
|
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
|
|
|
|
|
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);//线性放置
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -402,72 +407,72 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
super.onPause();
|
|
|
|
|
if(saveNote()) {
|
|
|
|
|
Log.d(TAG, "Note data was saved with length:" + mWorkingNote.getContent().length());
|
|
|
|
|
}
|
|
|
|
|
}//提示已保存对应文本
|
|
|
|
|
clearSettingState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateWidget() {
|
|
|
|
|
private void updateWidget() {//更新widget
|
|
|
|
|
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
|
|
|
|
if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {
|
|
|
|
|
if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {//更新到2x大小
|
|
|
|
|
intent.setClass(this, NoteWidgetProvider_2x.class);
|
|
|
|
|
} else if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_4X) {
|
|
|
|
|
} else if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_4X) {//更新到4x大小
|
|
|
|
|
intent.setClass(this, NoteWidgetProvider_4x.class);
|
|
|
|
|
} else {
|
|
|
|
|
Log.e(TAG, "Unspported widget type");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
|
|
|
|
|
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {//把对应id附加上去
|
|
|
|
|
mWorkingNote.getWidgetId()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
sendBroadcast(intent);
|
|
|
|
|
sendBroadcast(intent);//让widget进行刷新操作,从而实现数据同步
|
|
|
|
|
setResult(RESULT_OK, intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
int id = v.getId();
|
|
|
|
|
if (id == R.id.btn_set_bg_color) {
|
|
|
|
|
mNoteBgColorSelector.setVisibility(View.VISIBLE);
|
|
|
|
|
int id = v.getId();//获取id号
|
|
|
|
|
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)) {//如果是背景选择按钮包含此id
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
|
View.GONE);
|
|
|
|
|
mWorkingNote.setBgColorId(sBgSelectorBtnsMap.get(id));
|
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);
|
|
|
|
|
} 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());
|
|
|
|
|
View.GONE);//将选择视图关闭
|
|
|
|
|
mWorkingNote.setBgColorId(sBgSelectorBtnsMap.get(id));//设置对应的背景颜色
|
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);//
|
|
|
|
|
} 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());//转化为列表模式
|
|
|
|
|
} else {
|
|
|
|
|
mNoteEditor.setTextAppearance(this,
|
|
|
|
|
TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
|
|
|
|
|
TextAppearanceResources.getTexAppearanceResource(mFontSizeId));//显示字体大小
|
|
|
|
|
}
|
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);//关闭字体大小显示
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBackPressed() {
|
|
|
|
|
if(clearSettingState()) {
|
|
|
|
|
if(clearSettingState()) {//关闭对应的窗口
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveNote();
|
|
|
|
|
saveNote();//保存笔记
|
|
|
|
|
super.onBackPressed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean clearSettingState() {
|
|
|
|
|
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE) {
|
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);
|
|
|
|
|
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE) {//判断背景颜色选择器是否可见
|
|
|
|
|
mNoteBgColorSelector.setVisibility(View.GONE);//关闭
|
|
|
|
|
return true;
|
|
|
|
|
} else if (mFontSizeSelector.getVisibility() == View.VISIBLE) {
|
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
|
} else if (mFontSizeSelector.getVisibility() == View.VISIBLE) {//判断字体大小是否可见
|
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);//关闭
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
@ -475,89 +480,103 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
public void onBackgroundColorChanged() {
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
|
View.VISIBLE);
|
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
|
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
|
|
|
|
|
View.VISIBLE);//找到对应颜色的id并进行视图显示
|
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());//编辑面板进行显示
|
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());//试图面板显示
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
|
if (isFinishing()) {
|
|
|
|
|
if (isFinishing()) {//页面完成
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
clearSettingState();
|
|
|
|
|
menu.clear();
|
|
|
|
|
clearSettingState();//关闭设置的状态
|
|
|
|
|
menu.clear();//清空菜单
|
|
|
|
|
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 {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
if (mWorkingNote.hasClockAlert()) {
|
|
|
|
|
menu.findItem(R.id.menu_alert).setVisible(false);
|
|
|
|
|
if (mWorkingNote.hasClockAlert()) {//显示是否有闹钟提示
|
|
|
|
|
menu.findItem(R.id.menu_alert).setVisible(false);//关闭提示
|
|
|
|
|
} else {
|
|
|
|
|
menu.findItem(R.id.menu_delete_remind).setVisible(false);
|
|
|
|
|
menu.findItem(R.id.menu_delete_remind).setVisible(false);//菜单删除提醒关闭
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
switch (item.getItemId()) {//根据选项的id号进行对应的选择
|
|
|
|
|
case R.id.menu_new_note:
|
|
|
|
|
createNewNote();
|
|
|
|
|
createNewNote();//创建新的标签
|
|
|
|
|
break;
|
|
|
|
|
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));
|
|
|
|
|
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));//提示要不要删除
|
|
|
|
|
builder.setPositiveButton(android.R.string.ok,
|
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
new DialogInterface.OnClickListener() {//确定按钮
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
deleteCurrentNote();
|
|
|
|
|
deleteCurrentNote();//删除当前的便签
|
|
|
|
|
finish();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
builder.setNegativeButton(android.R.string.cancel, null);
|
|
|
|
|
builder.show();
|
|
|
|
|
builder.setNegativeButton(android.R.string.cancel, null);//不确定
|
|
|
|
|
builder.show();//继续展示对应界面
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_font_size:
|
|
|
|
|
mFontSizeSelector.setVisibility(View.VISIBLE);
|
|
|
|
|
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
|
|
|
|
|
case R.id.menu_font_size://字体大小菜单
|
|
|
|
|
mFontSizeSelector.setVisibility(View.VISIBLE);//显示字体选择器
|
|
|
|
|
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);//将字体大小选择器显示出来
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_list_mode:
|
|
|
|
|
mWorkingNote.setCheckListMode(mWorkingNote.getCheckListMode() == 0 ?
|
|
|
|
|
TextNote.MODE_CHECK_LIST : 0);
|
|
|
|
|
TextNote.MODE_CHECK_LIST : 0);//设置列表模式
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_share:
|
|
|
|
|
getWorkingText();
|
|
|
|
|
case R.id.menu_share://进行菜单分享
|
|
|
|
|
getWorkingText();//获取便签的内容
|
|
|
|
|
sendTo(this, mWorkingNote.getContent());
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_send_to_desktop:
|
|
|
|
|
sendToDesktop();
|
|
|
|
|
sendToDesktop();//发送到桌面上
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_alert:
|
|
|
|
|
setReminder();
|
|
|
|
|
setReminder();//设置提醒器
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_delete_remind:
|
|
|
|
|
mWorkingNote.setAlertDate(0, false);
|
|
|
|
|
mWorkingNote.setAlertDate(0, false);//设置日期提醒器
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_Graffiti:
|
|
|
|
|
Intent intent = new Intent(this, MyPaintToolsActivity.class);
|
|
|
|
|
if (mWorkingNote.getImage() != null) {
|
|
|
|
|
intent.putExtra("Bitmap", mWorkingNote.getImage());
|
|
|
|
|
}
|
|
|
|
|
startActivityForResult(intent, REQUEST_CODE);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) {
|
|
|
|
|
mWorkingNote.setImage(data.getByteArrayExtra("result"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setReminder() {
|
|
|
|
|
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
|
|
|
|
|
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
|
|
|
|
|
private void setReminder() {//设置提醒器
|
|
|
|
|
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());//设置新的对话框
|
|
|
|
|
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {//设置监听器
|
|
|
|
|
public void OnDateTimeSet(AlertDialog dialog, long date) {
|
|
|
|
|
mWorkingNote.setAlertDate(date , true);
|
|
|
|
|
mWorkingNote.setAlertDate(date , true);//设置信息
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
d.show();
|
|
|
|
@ -568,10 +587,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
* and {@text/plain} type
|
|
|
|
|
*/
|
|
|
|
|
private void sendTo(Context context, String info) {
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, info);
|
|
|
|
|
intent.setType("text/plain");
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);//代表发送一个文本信息
|
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, info);//向intend中加入文本信息
|
|
|
|
|
intent.setType("text/plain");//文本类型
|
|
|
|
|
context.startActivity(intent);//启动这个intent,也就是发送信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createNewNote() {
|
|
|
|
@ -580,36 +599,36 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
// For safety, start a new NoteEditActivity
|
|
|
|
|
finish();
|
|
|
|
|
Intent intent = new Intent(this, NoteEditActivity.class);
|
|
|
|
|
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
|
|
|
|
|
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mWorkingNote.getFolderId());
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
Intent intent = new Intent(this, NoteEditActivity.class);//新建一个intent
|
|
|
|
|
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);//设置为编辑或者插入
|
|
|
|
|
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mWorkingNote.getFolderId());//给id
|
|
|
|
|
startActivity(intent);//进行相应的编辑活动
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void deleteCurrentNote() {
|
|
|
|
|
if (mWorkingNote.existInDatabase()) {
|
|
|
|
|
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);//加入
|
|
|
|
|
} else {
|
|
|
|
|
Log.d(TAG, "Wrong note id, should not happen");
|
|
|
|
|
Log.d(TAG, "Wrong note id, should not happen");//不存在这样的便签id
|
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mWorkingNote.markDeleted(true);
|
|
|
|
|
mWorkingNote.markDeleted(true);//标记为已经删除
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isSyncMode() {
|
|
|
|
|
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
|
|
|
|
|
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;//获取账号名称,如果不是空则代表是同步模式下
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onClockAlertChanged(long date, boolean set) {
|
|
|
|
@ -617,19 +636,19 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
* User could set clock to an unsaved note, so before setting the
|
|
|
|
|
* alert clock, we should save the note first
|
|
|
|
|
*/
|
|
|
|
|
if (!mWorkingNote.existInDatabase()) {
|
|
|
|
|
saveNote();
|
|
|
|
|
}
|
|
|
|
|
if (mWorkingNote.getNoteId() > 0) {
|
|
|
|
|
Intent intent = new Intent(this, AlarmReceiver.class);
|
|
|
|
|
intent.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mWorkingNote.getNoteId()));
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
|
|
|
|
|
AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE));
|
|
|
|
|
showAlertHeader();
|
|
|
|
|
if(!set) {
|
|
|
|
|
if (!mWorkingNote.existInDatabase()) {//如果不在数据库中
|
|
|
|
|
saveNote();//保存
|
|
|
|
|
}
|
|
|
|
|
if (mWorkingNote.getNoteId() > 0) {//如果id为有效id
|
|
|
|
|
Intent intent = new Intent(this, AlarmReceiver.class);//新建intent
|
|
|
|
|
intent.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mWorkingNote.getNoteId()));//设置对应的日期,和对应的信息
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);//设置触发intent
|
|
|
|
|
AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE));//设置闹钟提醒
|
|
|
|
|
showAlertHeader();//显示提醒的标题
|
|
|
|
|
if(!set) {//如果要关闭提醒
|
|
|
|
|
alarmManager.cancel(pendingIntent);
|
|
|
|
|
} else {
|
|
|
|
|
alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent);
|
|
|
|
|
alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent);//设置提醒
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/**
|
|
|
|
@ -647,162 +666,162 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onEditTextDelete(int index, String text) {
|
|
|
|
|
int childCount = mEditTextList.getChildCount();
|
|
|
|
|
if (childCount == 1) {
|
|
|
|
|
int childCount = mEditTextList.getChildCount();//获取当前便签列表的孩子个数
|
|
|
|
|
if (childCount == 1) {//如果只有一个孩子
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = index + 1; i < childCount; i++) {
|
|
|
|
|
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
|
|
|
|
.setIndex(i - 1);
|
|
|
|
|
.setIndex(i - 1);//将index后的文本往前移动
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mEditTextList.removeViewAt(index);
|
|
|
|
|
mEditTextList.removeViewAt(index);//把对应下标的列表内容删除
|
|
|
|
|
NoteEditText edit = null;
|
|
|
|
|
if(index == 0) {
|
|
|
|
|
if(index == 0) {//如果下标是0,那么就获取第一个标签
|
|
|
|
|
edit = (NoteEditText) mEditTextList.getChildAt(0).findViewById(
|
|
|
|
|
R.id.et_edit_text);
|
|
|
|
|
} else {
|
|
|
|
|
} else {//否则就是下标减一,因为删除了一个元素
|
|
|
|
|
edit = (NoteEditText) mEditTextList.getChildAt(index - 1).findViewById(
|
|
|
|
|
R.id.et_edit_text);
|
|
|
|
|
}
|
|
|
|
|
int length = edit.length();
|
|
|
|
|
edit.append(text);
|
|
|
|
|
edit.requestFocus();
|
|
|
|
|
edit.setSelection(length);
|
|
|
|
|
edit.append(text);//把对应的文本内容加入
|
|
|
|
|
edit.requestFocus();//获取焦点
|
|
|
|
|
edit.setSelection(length);//设置光标到对应的长度
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
View view = getListItem(text, index);
|
|
|
|
|
mEditTextList.addView(view, 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++) {
|
|
|
|
|
View view = getListItem(text, index);//获取对应下标的列表物品的视图
|
|
|
|
|
mEditTextList.addView(view, 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++) {//保证NoteEditText的索引值和列表元素的实际位置一致
|
|
|
|
|
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
|
|
|
|
.setIndex(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void switchToListMode(String text) {
|
|
|
|
|
mEditTextList.removeAllViews();
|
|
|
|
|
String[] items = text.split("\n");
|
|
|
|
|
mEditTextList.removeAllViews();//关掉所有的视图
|
|
|
|
|
String[] items = text.split("\n");//将对应的文本据回车分开
|
|
|
|
|
int index = 0;
|
|
|
|
|
for (String item : items) {
|
|
|
|
|
if(!TextUtils.isEmpty(item)) {
|
|
|
|
|
mEditTextList.addView(getListItem(item, index));
|
|
|
|
|
index++;
|
|
|
|
|
for (String item : items) {//遍历里面的元素
|
|
|
|
|
if(!TextUtils.isEmpty(item)) {//如果对应文本不是空
|
|
|
|
|
mEditTextList.addView(getListItem(item, 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);
|
|
|
|
|
mEditTextList.setVisibility(View.VISIBLE);
|
|
|
|
|
mNoteEditor.setVisibility(View.GONE);//将便签编辑器取消
|
|
|
|
|
mEditTextList.setVisibility(View.VISIBLE);//将便文本列表显示出来
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Spannable getHighlightQueryResult(String fullText, String userQuery) {
|
|
|
|
|
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);
|
|
|
|
|
int start = 0;
|
|
|
|
|
while (m.find(start)) {
|
|
|
|
|
if (!TextUtils.isEmpty(userQuery)) {//判断用户查询的内容是否为空
|
|
|
|
|
mPattern = Pattern.compile(userQuery);//将对应得文本转化为匹配模式
|
|
|
|
|
Matcher m = mPattern.matcher(fullText);//把对应得文本匹配出来
|
|
|
|
|
int start = 0;//定义开始
|
|
|
|
|
while (m.find(start)) {//到达下一个位置
|
|
|
|
|
spannable.setSpan(
|
|
|
|
|
new BackgroundColorSpan(this.getResources().getColor(
|
|
|
|
|
R.color.user_query_highlight)), m.start(), m.end(),
|
|
|
|
|
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
|
|
|
|
start = m.end();
|
|
|
|
|
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);//设置对应得高亮模式
|
|
|
|
|
start = m.end();//更新扫描得开始位置
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return spannable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
edit.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
|
|
|
|
|
CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item));
|
|
|
|
|
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
|
View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null);//获取布局解析器对象
|
|
|
|
|
final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);//找到对应id得控件对象
|
|
|
|
|
edit.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId));//设置文本形式
|
|
|
|
|
CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item));//根据id找到对应的多选框
|
|
|
|
|
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {//监听复选框的变化
|
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
|
if (isChecked) {
|
|
|
|
|
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
|
|
|
|
} else {
|
|
|
|
|
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
|
|
|
|
|
if (isChecked) {//勾选了对应的复选框
|
|
|
|
|
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);//加上对应的删除线
|
|
|
|
|
} else {//取消了勾选
|
|
|
|
|
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);//删除对应的删除线
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (item.startsWith(TAG_CHECKED)) {
|
|
|
|
|
cb.setChecked(true);
|
|
|
|
|
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
|
|
|
|
item = item.substring(TAG_CHECKED.length(), item.length()).trim();
|
|
|
|
|
if (item.startsWith(TAG_CHECKED)) {//如果该列表项已经被勾选了
|
|
|
|
|
cb.setChecked(true);//设置为选中状态
|
|
|
|
|
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);
|
|
|
|
|
item = item.substring(TAG_UNCHECKED.length(), item.length()).trim();
|
|
|
|
|
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);//未勾选状态
|
|
|
|
|
item = item.substring(TAG_UNCHECKED.length(), item.length()).trim();//去除TAG_UNCHECKED前缀
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
edit.setOnTextViewChangeListener(this);
|
|
|
|
|
edit.setOnTextViewChangeListener(this);//给当前事件捆绑监听器
|
|
|
|
|
edit.setIndex(index);
|
|
|
|
|
edit.setText(getHighlightQueryResult(item, mUserQuery));
|
|
|
|
|
edit.setText(getHighlightQueryResult(item, mUserQuery));//对用户的查询显示高亮
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onTextChange(int index, boolean hasText) {
|
|
|
|
|
if (index >= mEditTextList.getChildCount()) {
|
|
|
|
|
if (index >= mEditTextList.getChildCount()) {//看坐标是否大于子控件数目如果大于,是无效操作
|
|
|
|
|
Log.e(TAG, "Wrong index, should not happen");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(hasText) {
|
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.VISIBLE);
|
|
|
|
|
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) {
|
|
|
|
|
switchToListMode(mNoteEditor.getText().toString());
|
|
|
|
|
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);
|
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);
|
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));//
|
|
|
|
|
mEditTextList.setVisibility(View.GONE);//
|
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);//
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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++) {
|
|
|
|
|
View view = mEditTextList.getChildAt(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");
|
|
|
|
|
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中
|
|
|
|
|
hasChecked = true;
|
|
|
|
|
} else {
|
|
|
|
|
sb.append(TAG_UNCHECKED).append(" ").append(edit.getText()).append("\n");
|
|
|
|
|
sb.append(TAG_UNCHECKED).append(" ").append(edit.getText()).append("\n");//没有勾选
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mWorkingNote.setWorkingText(sb.toString());
|
|
|
|
|
mWorkingNote.setWorkingText(sb.toString());//将其转化为String类
|
|
|
|
|
} else {
|
|
|
|
|
mWorkingNote.setWorkingText(mNoteEditor.getText().toString());
|
|
|
|
|
mWorkingNote.setWorkingText(mNoteEditor.getText().toString());//设置文本内容
|
|
|
|
|
}
|
|
|
|
|
return hasChecked;
|
|
|
|
|
return hasChecked;//存在勾选的选项
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean saveNote() {
|
|
|
|
@ -833,19 +852,19 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
if (mWorkingNote.getNoteId() > 0) {
|
|
|
|
|
Intent sender = new Intent();
|
|
|
|
|
Intent shortcutIntent = new Intent(this, NoteEditActivity.class);
|
|
|
|
|
Intent shortcutIntent = new Intent(this, NoteEditActivity.class);//表示点击桌面快捷方式需要启动的activity
|
|
|
|
|
shortcutIntent.setAction(Intent.ACTION_VIEW);
|
|
|
|
|
shortcutIntent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
|
|
|
|
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));
|
|
|
|
|
Intent.ShortcutIconResource.fromContext(this, R.drawable.icon_app));//快捷方式的图标
|
|
|
|
|
sender.putExtra("duplicate", true);
|
|
|
|
|
sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
|
|
|
|
|
sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT");//拟定发送的广播类型
|
|
|
|
|
showToast(R.string.info_note_enter_desktop);
|
|
|
|
|
sendBroadcast(sender);
|
|
|
|
|
} else {
|
|
|
|
|
sendBroadcast(sender);//创建对应的快捷方式
|
|
|
|
|
} else {//对应的便签不存在
|
|
|
|
|
/**
|
|
|
|
|
* There is the condition that user has input nothing (the note is
|
|
|
|
|
* not worthy saving), we have no note id, remind the user that he
|
|
|
|
@ -857,17 +876,17 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String makeShortcutIconTitle(String content) {
|
|
|
|
|
content = content.replace(TAG_CHECKED, "");
|
|
|
|
|
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;
|
|
|
|
|
SHORTCUT_ICON_TITLE_MAX_LEN) : content;//将便签前几个字作为标题
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showToast(int resId) {
|
|
|
|
|
showToast(resId, Toast.LENGTH_SHORT);
|
|
|
|
|
}
|
|
|
|
|
}//显示提示信息
|
|
|
|
|
|
|
|
|
|
private void showToast(int resId, int duration) {
|
|
|
|
|
Toast.makeText(this, resId, duration).show();
|
|
|
|
|
Toast.makeText(this, resId, duration).show();//在指定时间内显示对应的信息
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|