|
|
@ -30,7 +30,6 @@ import android.view.WindowManager;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CompoundButton;
|
|
|
|
import android.widget.CompoundButton;
|
|
|
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
|
|
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.TextView;
|
|
|
@ -55,6 +54,8 @@ import java.util.Map;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import jp.wasabeef.richeditor.RichEditor;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @Package: net.micode.notes.ui
|
|
|
|
* @Package: net.micode.notes.ui
|
|
|
|
* @ClassName: NoteEditActivity
|
|
|
|
* @ClassName: NoteEditActivity
|
|
|
@ -75,6 +76,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
public TextView tvAlertDate;
|
|
|
|
public TextView tvAlertDate;
|
|
|
|
|
|
|
|
|
|
|
|
public ImageView ibSetBgColor;
|
|
|
|
public ImageView ibSetBgColor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TextView textNum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
static {
|
|
|
|
static {
|
|
|
@ -115,7 +118,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
private View mHeadViewPanel;
|
|
|
|
private View mHeadViewPanel;
|
|
|
|
private View mNoteBgColorSelector;
|
|
|
|
private View mNoteBgColorSelector;
|
|
|
|
private View mFontSizeSelector;
|
|
|
|
private View mFontSizeSelector;
|
|
|
|
private EditText mNoteEditor;
|
|
|
|
//private EditText mNoteEditor;
|
|
|
|
|
|
|
|
private RichEditor mNoteEditor;//富文本编辑器
|
|
|
|
|
|
|
|
private TextView mPreview;
|
|
|
|
|
|
|
|
private String mText;//mText和mNoteLength是给富文本编辑器的
|
|
|
|
|
|
|
|
private int mNoteLength;
|
|
|
|
|
|
|
|
private int mFontSize;
|
|
|
|
private View mNoteEditorPanel;
|
|
|
|
private View mNoteEditorPanel;
|
|
|
|
public WorkingNote mWorkingNote;
|
|
|
|
public WorkingNote mWorkingNote;
|
|
|
|
private SharedPreferences mSharedPrefs;
|
|
|
|
private SharedPreferences mSharedPrefs;
|
|
|
@ -132,6 +140,324 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
|
|
private String mUserQuery;
|
|
|
|
private String mUserQuery;
|
|
|
|
private Pattern mPattern;
|
|
|
|
private Pattern mPattern;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 新增方法:
|
|
|
|
|
|
|
|
* 初始化富文本编辑框
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void initRichEditor(){
|
|
|
|
|
|
|
|
mNoteEditor.setEditorHeight(200);//设置编辑器界面高度
|
|
|
|
|
|
|
|
mNoteEditor.setEditorFontSize(22);//字体大小
|
|
|
|
|
|
|
|
mNoteEditor.setEditorFontColor(1);//字体颜色
|
|
|
|
|
|
|
|
mNoteEditor.setPadding(0, 0, 0, 0);//内边距
|
|
|
|
|
|
|
|
mNoteEditor.setPlaceholder("点击输入内容");//设置默认显示语句
|
|
|
|
|
|
|
|
mNoteEditor.setInputEnabled(true);//设置编辑器是否可用
|
|
|
|
|
|
|
|
mNoteEditor.setBackgroundResource(R.drawable.edit_yellow);//编辑背景
|
|
|
|
|
|
|
|
mNoteEditor.setOnTextChangeListener(new RichEditor.OnTextChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onTextChange(String text) {
|
|
|
|
|
|
|
|
mText = text;
|
|
|
|
|
|
|
|
mNoteLength = textChange(mText).length();
|
|
|
|
|
|
|
|
mNoteHeaderHolder.tvModified.setText(DateUtils.formatDateTime(NoteEditActivity.this,
|
|
|
|
|
|
|
|
mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_DATE
|
|
|
|
|
|
|
|
| DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME
|
|
|
|
|
|
|
|
| DateUtils.FORMAT_SHOW_YEAR)+"\n字符数:"+mNoteLength);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_undo).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.undo();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_redo).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.redo();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_bold).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setBold();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_italic).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setItalic();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
findViewById(R.id.action_subscript).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setSubscript();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_superscript).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setSuperscript();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_strikethrough).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setStrikeThrough();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_underline).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setUnderline();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_heading1).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setHeading(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_heading2).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setHeading(2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_heading3).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setHeading(3);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_heading4).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setHeading(4);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_heading5).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setHeading(5);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_heading6).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setHeading(6);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**findViewById(R.id.action_txt_color).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
private boolean isChanged;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setTextColor(isChanged ? Color.BLACK : Color.RED);
|
|
|
|
|
|
|
|
isChanged = !isChanged;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**findViewById(R.id.action_bg_color).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {//设置点击响应方法
|
|
|
|
|
|
|
|
mNoteEditor.focusEditor();
|
|
|
|
|
|
|
|
new AlertDialog.Builder(NoteEditActivity.this).setTitle("选择字体背景颜色")//设置一个AlertDialog供用户选择具体的颜色
|
|
|
|
|
|
|
|
.setSingleChoiceItems(R.array.text_bg_color, 0,
|
|
|
|
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
|
|
|
switch (which) {
|
|
|
|
|
|
|
|
//红
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
mNoteEditor.setTextBackgroundColor(Color.RED);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
//黄
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
mNoteEditor.setTextBackgroundColor(Color.YELLOW);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
//蓝
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
mNoteEditor.setTextBackgroundColor(Color.BLUE);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
//绿
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
mNoteEditor.setTextBackgroundColor(Color.GREEN);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
//黑
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
|
|
mNoteEditor.setTextBackgroundColor(Color.BLACK);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
|
|
mNoteEditor.setTextBackgroundColor(Color.WHITE);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}).show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});*/
|
|
|
|
|
|
|
|
findViewById(R.id.action_indent).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setIndent();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_outdent).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setOutdent();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_align_left).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setAlignLeft();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_align_center).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setAlignCenter();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_align_right).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setAlignRight();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_blockquote).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setBlockquote();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_insert_bullets).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setBullets();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.action_insert_numbers).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.setNumbers();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**findViewById(R.id.action_insert_link).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.insertLink("https://github.com/wasabeef", "wasabeef");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});*/
|
|
|
|
|
|
|
|
/**findViewById(R.id.action_insert_image).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.insertImage("https://raw.githubusercontent.com/wasabeef/art/master/chip.jpg",
|
|
|
|
|
|
|
|
"dachshund", 320);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});*/
|
|
|
|
|
|
|
|
findViewById(R.id.action_insert_checkbox).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
mNoteEditor.insertTodo();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method textChange
|
|
|
|
|
|
|
|
* @description 对原始文本进行处理,去除图片字符、换行符和空格字符
|
|
|
|
|
|
|
|
* @date: 1/3/2024 8:48 AM
|
|
|
|
|
|
|
|
* @author: YangYizhe
|
|
|
|
|
|
|
|
* @param oriText
|
|
|
|
|
|
|
|
* @return 处理后的文本
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private String textChange(String oriText) {
|
|
|
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder(oriText);
|
|
|
|
|
|
|
|
// 移除所有<>
|
|
|
|
|
|
|
|
removeAngleBrackets(stringBuilder);
|
|
|
|
|
|
|
|
// 移除换行符和空格
|
|
|
|
|
|
|
|
for (int i = 0; i < stringBuilder.length(); i++) {
|
|
|
|
|
|
|
|
char c = stringBuilder.charAt(i);
|
|
|
|
|
|
|
|
if (c == '\n' || c == ' ') {
|
|
|
|
|
|
|
|
stringBuilder.deleteCharAt(i);
|
|
|
|
|
|
|
|
i--;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return stringBuilder.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method removeAngleBrackets
|
|
|
|
|
|
|
|
* @description 用以辅助移除<></>
|
|
|
|
|
|
|
|
* @date: 1/18/2024 7:22 PM
|
|
|
|
|
|
|
|
* @author: YangYizhe
|
|
|
|
|
|
|
|
* @param
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeAngleBrackets(StringBuilder stringBuilder) {
|
|
|
|
|
|
|
|
int startIndex = stringBuilder.indexOf("<");
|
|
|
|
|
|
|
|
int endIndex = stringBuilder.indexOf(">");
|
|
|
|
|
|
|
|
if (startIndex != -1 && endIndex != -1 && startIndex < endIndex) {
|
|
|
|
|
|
|
|
stringBuilder.delete(startIndex, endIndex + 1);
|
|
|
|
|
|
|
|
removeAngleBrackets(stringBuilder);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method count
|
|
|
|
|
|
|
|
* @description 监听编辑框文本变化并更新字符数
|
|
|
|
|
|
|
|
* @date: 1/3/2024 9:09 AM
|
|
|
|
|
|
|
|
* @author: YangYizhe
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**private void count() {
|
|
|
|
|
|
|
|
mNoteEditor.addTextChangedListener(new TextWatcher() {
|
|
|
|
|
|
|
|
int currentLength = 0;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
|
|
|
|
mNoteHeaderHolder.textNum.setText("字数:" + currentLength);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
|
|
|
|
currentLength = textChange(mNoteEditor.getText().toString()).length();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
|
|
|
|
mNoteHeaderHolder.textNum.setText("字数:" + currentLength);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*在 Activity 创建时进行一些初始化工作,包括设置布局、初始化状态和资源等操作
|
|
|
|
*在 Activity 创建时进行一些初始化工作,包括设置布局、初始化状态和资源等操作
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -144,6 +470,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
initResources();
|
|
|
|
initResources();
|
|
|
|
|
|
|
|
initRichEditor();
|
|
|
|
|
|
|
|
//count();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -263,13 +591,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* @author: YangYizhe
|
|
|
|
* @author: YangYizhe
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void initNoteScreen() {
|
|
|
|
private void initNoteScreen() {
|
|
|
|
mNoteEditor.setTextAppearance(this, TextAppearanceResources
|
|
|
|
mNoteEditor.setEditorFontSize(30);
|
|
|
|
.getTexAppearanceResource(mFontSizeId));
|
|
|
|
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
mNoteEditor.setHtml(String.valueOf(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery)));
|
|
|
|
mNoteEditor.setSelection(mNoteEditor.getText().length());
|
|
|
|
//mNoteEditor.setSelection(mText.length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (Integer id : sBgSelectorSelectionMap.keySet()) {
|
|
|
|
for (Integer id : sBgSelectorSelectionMap.keySet()) {
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);
|
|
|
@ -375,8 +702,20 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon);
|
|
|
|
mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon);
|
|
|
|
mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);
|
|
|
|
mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);
|
|
|
|
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
|
|
|
|
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
|
|
|
|
|
|
|
|
mNoteHeaderHolder.textNum = (TextView) findViewById(R.id.text_num);
|
|
|
|
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
|
|
|
|
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
|
|
|
|
mNoteEditor = (EditText) findViewById(R.id.note_edit_view);
|
|
|
|
mNoteEditor = findViewById(R.id.note_edit_view);
|
|
|
|
|
|
|
|
mNoteEditor.setOnTextChangeListener(new RichEditor.OnTextChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onTextChange(String text) {
|
|
|
|
|
|
|
|
mText = text;
|
|
|
|
|
|
|
|
mNoteLength = textChange(mText).length();
|
|
|
|
|
|
|
|
mNoteHeaderHolder.tvModified.setText(DateUtils.formatDateTime(NoteEditActivity.this,
|
|
|
|
|
|
|
|
mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_DATE
|
|
|
|
|
|
|
|
| DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME
|
|
|
|
|
|
|
|
| DateUtils.FORMAT_SHOW_YEAR)+"\n字符数:"+mNoteLength);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
mNoteEditorPanel = findViewById(R.id.sv_note_edit);
|
|
|
|
mNoteEditorPanel = findViewById(R.id.sv_note_edit);
|
|
|
|
mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector);
|
|
|
|
mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector);
|
|
|
|
for (int id : sBgSelectorBtnsMap.keySet()) {
|
|
|
|
for (int id : sBgSelectorBtnsMap.keySet()) {
|
|
|
@ -456,8 +795,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
getWorkingText();
|
|
|
|
getWorkingText();
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
mNoteEditor.setTextAppearance(this,
|
|
|
|
mNoteEditor.setEditorFontSize(mFontSizeId);
|
|
|
|
TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -538,8 +876,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
int itemId = item.getItemId();
|
|
|
|
int itemId = item.getItemId();
|
|
|
|
if (itemId == R.id.menu_new_note) {
|
|
|
|
if (itemId == R.id.menu_new_note) {
|
|
|
|
createNewNote();
|
|
|
|
createNewNote();
|
|
|
|
}
|
|
|
|
} else if (itemId == R.id.menu_delete) {
|
|
|
|
else if (itemId == R.id.menu_delete) {
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(getString(R.string.alert_title_delete));
|
|
|
|
builder.setTitle(getString(R.string.alert_title_delete));
|
|
|
|
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
|
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
|
@ -753,15 +1090,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
mEditTextList.setVisibility(View.VISIBLE);
|
|
|
|
mEditTextList.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @method getHighlightQueryResult
|
|
|
|
* @param fullText 完整文本
|
|
|
|
|
|
|
|
* @param userQuery 用户查询关键词
|
|
|
|
|
|
|
|
* @return 带有高亮效果的 Spannable 对象
|
|
|
|
|
|
|
|
* @method getHighlightQueryResult
|
|
|
|
* @description 获取高亮查询结果
|
|
|
|
* @description 获取高亮查询结果
|
|
|
|
* @date: 12/24/2023 6:18 PM
|
|
|
|
* @date: 12/24/2023 6:18 PM
|
|
|
|
* @author: YangYizhe
|
|
|
|
* @author: YangYizhe
|
|
|
|
* @param fullText 完整文本
|
|
|
|
|
|
|
|
* @param userQuery 用户查询关键词
|
|
|
|
|
|
|
|
* @return 带有高亮效果的 Spannable 对象
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private Spannable getHighlightQueryResult(String fullText, String userQuery) {
|
|
|
|
private SpannableString 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)) {
|
|
|
|
mPattern = Pattern.compile(userQuery);
|
|
|
|
mPattern = Pattern.compile(userQuery);
|
|
|
@ -845,13 +1182,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
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(mText.toString());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (!getWorkingText()) {
|
|
|
|
if (!getWorkingText()) {
|
|
|
|
mWorkingNote.setWorkingText(mWorkingNote.getContent().replace(TAG_UNCHECKED + " ",
|
|
|
|
mWorkingNote.setWorkingText(mWorkingNote.getContent().replace(TAG_UNCHECKED + " ",
|
|
|
|
""));
|
|
|
|
""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
mNoteEditor.setHtml(String.valueOf(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery)));
|
|
|
|
mEditTextList.setVisibility(View.GONE);
|
|
|
|
mEditTextList.setVisibility(View.GONE);
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -892,7 +1229,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mWorkingNote.setWorkingText(sb.toString());//利用编辑好的字符串设置运行便签的内容
|
|
|
|
mWorkingNote.setWorkingText(sb.toString());//利用编辑好的字符串设置运行便签的内容
|
|
|
|
} else {// 若不是该模式直接用编辑器中的内容设置运行中标签的内容
|
|
|
|
} else {// 若不是该模式直接用编辑器中的内容设置运行中标签的内容
|
|
|
|
mWorkingNote.setWorkingText(mNoteEditor.getText().toString());
|
|
|
|
mWorkingNote.setWorkingText(mText.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hasChecked;
|
|
|
|
return hasChecked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|