|
|
|
@ -19,8 +19,6 @@ import android.text.SpannableString;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.text.format.DateUtils;
|
|
|
|
|
import android.text.style.BackgroundColorSpan;
|
|
|
|
|
import android.text.Editable;// 引入textwatcher和Editable
|
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.Menu;
|
|
|
|
@ -32,7 +30,6 @@ import android.view.WindowManager;
|
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
|
import android.widget.CompoundButton;
|
|
|
|
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
@ -57,6 +54,8 @@ import java.util.Map;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
import jp.wasabeef.richeditor.RichEditor;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Package: net.micode.notes.ui
|
|
|
|
|
* @ClassName: NoteEditActivity
|
|
|
|
@ -119,7 +118,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
private View mHeadViewPanel;
|
|
|
|
|
private View mNoteBgColorSelector;
|
|
|
|
|
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;
|
|
|
|
|
public WorkingNote mWorkingNote;
|
|
|
|
|
private SharedPreferences mSharedPrefs;
|
|
|
|
@ -137,42 +141,307 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
private String mUserQuery;
|
|
|
|
|
private Pattern mPattern;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method Textchange
|
|
|
|
|
* 新增方法:
|
|
|
|
|
* 初始化富文本编辑框
|
|
|
|
|
*/
|
|
|
|
|
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 = removeBlank(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){
|
|
|
|
|
StringBuffer stringBuffer = new StringBuffer(oriText);
|
|
|
|
|
int Flag1 = -1;
|
|
|
|
|
int Flag2 = -1;
|
|
|
|
|
do {//不计入表示图片的字符
|
|
|
|
|
Flag1 = stringBuffer.indexOf("<img");
|
|
|
|
|
Flag2 = stringBuffer.indexOf(">");
|
|
|
|
|
if (Flag1 != -1 && Flag2 != -1) {
|
|
|
|
|
stringBuffer = stringBuffer.replace(Flag1, Flag2+1, "");
|
|
|
|
|
private String textChange(String oriText) {
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder(oriText);
|
|
|
|
|
// 移除所有<>
|
|
|
|
|
removeAngleBrackets(stringBuilder);
|
|
|
|
|
// 将 替换为普通空格
|
|
|
|
|
int index = stringBuilder.indexOf(" ");
|
|
|
|
|
while (index != -1) {
|
|
|
|
|
stringBuilder.replace(index, index + 6, " ");
|
|
|
|
|
index = stringBuilder.indexOf(" ", index + 1);
|
|
|
|
|
}
|
|
|
|
|
return stringBuilder.toString();
|
|
|
|
|
}
|
|
|
|
|
} while (Flag1 != -1 && Flag2 != -1);
|
|
|
|
|
|
|
|
|
|
do {//不计入换行字符
|
|
|
|
|
Flag1 = stringBuffer.indexOf("\n");
|
|
|
|
|
|
|
|
|
|
if (Flag1 != -1){
|
|
|
|
|
stringBuffer = stringBuffer.replace(Flag1, Flag1+1, "");
|
|
|
|
|
private String removeBlank(String oriText) {
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder(oriText);
|
|
|
|
|
// 移除换行符和其他空格
|
|
|
|
|
for (int i = 0; i < stringBuilder.length(); i++) {
|
|
|
|
|
char c = stringBuilder.charAt(i);
|
|
|
|
|
if (c == '\n' || c == ' ') {
|
|
|
|
|
stringBuilder.deleteCharAt(i);
|
|
|
|
|
i--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (Flag1 != -1);
|
|
|
|
|
do {//不计入空格字符
|
|
|
|
|
Flag1 = stringBuffer.indexOf(" ");
|
|
|
|
|
|
|
|
|
|
if (Flag1 != -1) {
|
|
|
|
|
stringBuffer = stringBuffer.replace(Flag1, Flag1+1, "");
|
|
|
|
|
return stringBuilder.toString();
|
|
|
|
|
}
|
|
|
|
|
} while (Flag1 != -1);
|
|
|
|
|
return stringBuffer.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
|
|
|
|
@ -180,7 +449,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
* @date: 1/3/2024 9:09 AM
|
|
|
|
|
* @author: YangYizhe
|
|
|
|
|
*/
|
|
|
|
|
private void count() {
|
|
|
|
|
/**private void count() {
|
|
|
|
|
mNoteEditor.addTextChangedListener(new TextWatcher() {
|
|
|
|
|
int currentLength = 0;
|
|
|
|
|
@Override
|
|
|
|
@ -190,7 +459,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
|
currentLength = Textchange(mNoteEditor.getText().toString()).length();
|
|
|
|
|
currentLength = textChange(mNoteEditor.getText().toString()).length();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -198,7 +467,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
mNoteHeaderHolder.textNum.setText("字数:" + currentLength);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*在 Activity 创建时进行一些初始化工作,包括设置布局、初始化状态和资源等操作
|
|
|
|
@ -212,7 +481,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
initResources();
|
|
|
|
|
count();
|
|
|
|
|
initRichEditor();
|
|
|
|
|
//count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -332,13 +602,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
* @author: YangYizhe
|
|
|
|
|
*/
|
|
|
|
|
private void initNoteScreen() {
|
|
|
|
|
mNoteEditor.setTextAppearance(this, TextAppearanceResources
|
|
|
|
|
.getTexAppearanceResource(mFontSizeId));
|
|
|
|
|
mNoteEditor.setEditorFontSize(30);
|
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
|
} else {
|
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
|
mNoteEditor.setSelection(mNoteEditor.getText().length());
|
|
|
|
|
mNoteEditor.setHtml(String.valueOf(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery)));
|
|
|
|
|
//mNoteEditor.setSelection(mText.length());
|
|
|
|
|
}
|
|
|
|
|
for (Integer id : sBgSelectorSelectionMap.keySet()) {
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);
|
|
|
|
@ -446,7 +715,18 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
|
|
|
|
|
mNoteHeaderHolder.textNum = (TextView) findViewById(R.id.text_num);
|
|
|
|
|
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 = removeBlank(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);
|
|
|
|
|
mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector);
|
|
|
|
|
for (int id : sBgSelectorBtnsMap.keySet()) {
|
|
|
|
@ -526,8 +806,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
getWorkingText();
|
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
|
} else {
|
|
|
|
|
mNoteEditor.setTextAppearance(this,
|
|
|
|
|
TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
|
|
|
|
|
mNoteEditor.setEditorFontSize(mFontSizeId);
|
|
|
|
|
}
|
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
@ -822,15 +1101,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
mEditTextList.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @param fullText 完整文本
|
|
|
|
|
* @param userQuery 用户查询关键词
|
|
|
|
|
* @return 带有高亮效果的 Spannable 对象
|
|
|
|
|
* @method getHighlightQueryResult
|
|
|
|
|
* @description 获取高亮查询结果
|
|
|
|
|
* @date: 12/24/2023 6:18 PM
|
|
|
|
|
* @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);
|
|
|
|
|
if (!TextUtils.isEmpty(userQuery)) {
|
|
|
|
|
mPattern = Pattern.compile(userQuery);
|
|
|
|
@ -914,13 +1193,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
*/
|
|
|
|
|
public void onCheckListModeChanged(int oldMode, int newMode) {
|
|
|
|
|
if (newMode == TextNote.MODE_CHECK_LIST) {
|
|
|
|
|
switchToListMode(mNoteEditor.getText().toString());
|
|
|
|
|
switchToListMode(textChange(mText));
|
|
|
|
|
} else {
|
|
|
|
|
if (!getWorkingText()) {
|
|
|
|
|
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);
|
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
@ -961,7 +1240,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
mWorkingNote.setWorkingText(sb.toString());//利用编辑好的字符串设置运行便签的内容
|
|
|
|
|
} else {// 若不是该模式直接用编辑器中的内容设置运行中标签的内容
|
|
|
|
|
mWorkingNote.setWorkingText(mNoteEditor.getText().toString());
|
|
|
|
|
mWorkingNote.setWorkingText(textChange(mText));
|
|
|
|
|
}
|
|
|
|
|
return hasChecked;
|
|
|
|
|
}
|
|
|
|
@ -975,6 +1254,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
private boolean saveNote() {
|
|
|
|
|
getWorkingText();
|
|
|
|
|
boolean saved = mWorkingNote.saveNote();
|
|
|
|
|
if (TextUtils.isEmpty(mWorkingNote.getContent())) {
|
|
|
|
|
deleteCurrentNote();//删除当前便签
|
|
|
|
|
saved = false; // 标记为未保存
|
|
|
|
|
}
|
|
|
|
|
//运行 getWorkingText()之后保存
|
|
|
|
|
if (saved) {
|
|
|
|
|
/**
|
|
|
|
@ -1050,4 +1333,230 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
private void showToast(int resId, int duration) {
|
|
|
|
|
Toast.makeText(this, resId, duration).show();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @method convertToImage
|
|
|
|
|
* @description: 路径字符串格式 转换为 图片image格式
|
|
|
|
|
* @date: 2024/1/3 19:19
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param: void
|
|
|
|
|
* @return: void
|
|
|
|
|
*/
|
|
|
|
|
/**private void convertToImage() {
|
|
|
|
|
NoteEditText noteEditText = (NoteEditText) findViewById(R.id.note_edit_view); //获取当前的edit
|
|
|
|
|
Editable editable = noteEditText.getText();//1.获取text
|
|
|
|
|
String noteText = editable.toString(); //2.将note内容转换为字符串
|
|
|
|
|
int length = editable.length(); //内容的长度
|
|
|
|
|
//3.截取img片段 [local]+uri+[/local],提取uri。算法效率有待改善可以考虑KMP
|
|
|
|
|
for(int i = 0; i < length; i++) {
|
|
|
|
|
for(int j = i; j < length; j++) {
|
|
|
|
|
String img_fragment = noteText.substring(i, j+1); //img_fragment:关于图片路径的片段
|
|
|
|
|
if(img_fragment.length() > 15 && img_fragment.endsWith("[/local]") &&
|
|
|
|
|
img_fragment.startsWith("[local]")){
|
|
|
|
|
int limit = 7; //[local]为7个字符
|
|
|
|
|
int len = img_fragment.length()-15;//[local][/local]共15个字符,剩下的为真正的path长度
|
|
|
|
|
String path = img_fragment.substring(limit,limit+len);//获取到了图片路径从[local]之后的len个字符就是path
|
|
|
|
|
Bitmap bitmap = null;
|
|
|
|
|
Log.d(TAG, "图片的路径是:"+path);
|
|
|
|
|
try {
|
|
|
|
|
bitmap = BitmapFactory.decodeFile(path);//将图片路径解码为图片格式
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
//若图片存在
|
|
|
|
|
if(bitmap!=null){
|
|
|
|
|
Log.d(TAG, "图片不为null");
|
|
|
|
|
ImageSpan imageSpan = new ImageSpan(NoteEditActivity.this, bitmap);
|
|
|
|
|
String ss = "[local]" + path + "[/local]";
|
|
|
|
|
SpannableString spannableString = new SpannableString(ss);//4.创建一个SpannableString对象,以便插入用ImageSpan对象封装的图像
|
|
|
|
|
|
|
|
|
|
spannableString.setSpan(imageSpan, 0, ss.length(),
|
|
|
|
|
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//5.将指定的标记对象附加到文本的开始...结束范围
|
|
|
|
|
Log.d(TAG, "Create spannable string success!");
|
|
|
|
|
Editable edit_text = noteEditText.getEditableText();
|
|
|
|
|
edit_text.delete(i,i+len+15); //6.删掉图片路径的文字
|
|
|
|
|
edit_text.insert(i, spannableString); //7.在路径的起始位置插入图片
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method onActivityResult
|
|
|
|
|
* @description: 插入图片时:重写onActivityResult()来处理返回的数据,点击插入图片返回后执行
|
|
|
|
|
* @date: 2024/1/3 19:20
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param:
|
|
|
|
|
* @return: void
|
|
|
|
|
*/
|
|
|
|
|
/**@Override
|
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, intent);
|
|
|
|
|
ContentResolver resolver = getContentResolver();
|
|
|
|
|
switch (requestCode) {
|
|
|
|
|
case PHOTO_REQUEST:
|
|
|
|
|
Uri originalUri = intent.getData(); //1.获得图片的真实路径
|
|
|
|
|
Bitmap bitmap = null;
|
|
|
|
|
try {
|
|
|
|
|
bitmap = BitmapFactory.decodeStream(resolver.openInputStream(originalUri));//2.解码图片
|
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
Log.d(TAG, "onActivityResult: get file_exception");
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
//3.根据Bitmap对象创建ImageSpan对象
|
|
|
|
|
if(bitmap != null){
|
|
|
|
|
Log.d(TAG, "onActivityResult: bitmap is not null");
|
|
|
|
|
ImageSpan imageSpan = new ImageSpan(NoteEditActivity.this, bitmap);
|
|
|
|
|
String path = getPath(this,originalUri);
|
|
|
|
|
String img_fragment= "[local]" + path + "[/local]";//4.使用[local][/local]将path括起来,用于之后方便识别图片路径在note中的位置
|
|
|
|
|
SpannableString spannableString = new SpannableString(img_fragment);//创建一个SpannableString对象,以便插入用ImageSpan对象封装的图像
|
|
|
|
|
spannableString.setSpan(imageSpan, 0,
|
|
|
|
|
img_fragment.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
|
NoteEditText e = (NoteEditText) findViewById(R.id.note_edit_view);//5.将选择的图片追加到EditText中光标所在位置
|
|
|
|
|
int index = e.getSelectionStart(); //获取光标所在位置
|
|
|
|
|
Log.d(TAG, "Index是: " + index);
|
|
|
|
|
Editable edit_text = e.getEditableText();
|
|
|
|
|
edit_text.insert(index, spannableString); //将图片插入到光标所在位置
|
|
|
|
|
|
|
|
|
|
mWorkingNote.setWorkingText(e.getText().toString());
|
|
|
|
|
//6.把改动提交到数据库中,两个数据库表都要改的
|
|
|
|
|
ContentResolver contentResolver = getContentResolver();
|
|
|
|
|
ContentValues contentValues = new ContentValues();
|
|
|
|
|
final long id = mWorkingNote.getNoteId();
|
|
|
|
|
contentValues.put("snippet",mWorkingNote.getContent());
|
|
|
|
|
contentResolver.update(Uri.parse("content://micode_notes/note"),
|
|
|
|
|
contentValues,"_id=?",new String[]{""+id});
|
|
|
|
|
ContentValues contentValues1 = new ContentValues();
|
|
|
|
|
contentValues1.put("content",mWorkingNote.getContent());
|
|
|
|
|
contentResolver.update(Uri.parse("content://micode_notes/data"),
|
|
|
|
|
contentValues1,"mime_type=? and note_id=?",
|
|
|
|
|
new String[]{"vnd.android.cursor.item/text_note",""+id});
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
Toast.makeText(NoteEditActivity.this, "获取图片失败", Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method getPath
|
|
|
|
|
* @description: 获取文件的real path
|
|
|
|
|
* @date: 2024/1/3 19:22
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param:
|
|
|
|
|
* @return:
|
|
|
|
|
*/
|
|
|
|
|
/**public String getPath(final Context context, final Uri uri) {
|
|
|
|
|
|
|
|
|
|
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
|
|
|
|
|
|
|
|
|
// DocumentProvider
|
|
|
|
|
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
|
|
|
|
|
if (isMediaDocument(uri)) {
|
|
|
|
|
final String docId = DocumentsContract.getDocumentId(uri);
|
|
|
|
|
final String[] split = docId.split(":");
|
|
|
|
|
final String type = split[0];
|
|
|
|
|
|
|
|
|
|
Uri contentUri = null;
|
|
|
|
|
if ("image".equals(type)) {
|
|
|
|
|
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final String selection = "_id=?";
|
|
|
|
|
final String[] selectionArgs = new String[]{split[1]};
|
|
|
|
|
|
|
|
|
|
return getDataColumn(context, contentUri, selection, selectionArgs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Media
|
|
|
|
|
else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
|
|
|
|
return getDataColumn(context, uri, null, null);
|
|
|
|
|
}
|
|
|
|
|
// File
|
|
|
|
|
else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
|
|
|
|
return uri.getPath();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method isMediaDocument
|
|
|
|
|
* @description: 判断是否为媒体文件
|
|
|
|
|
* @date: 2024/1/3 19:23
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param: uri
|
|
|
|
|
* @return:
|
|
|
|
|
*/
|
|
|
|
|
/**public boolean isMediaDocument(Uri uri) {
|
|
|
|
|
return "com.android.providers.media.documents".equals(uri.getAuthority());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method getDataColumn
|
|
|
|
|
* @description: 获取数据列_获取此 Uri 的数据列的值。这对MediaStore Uris 和其他基于文件的 ContentProvider。
|
|
|
|
|
* @date: 2024/1/3 19:23
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param:
|
|
|
|
|
* @return:
|
|
|
|
|
*/
|
|
|
|
|
/**public String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
|
|
|
|
|
|
|
|
|
|
Cursor cursor = null;
|
|
|
|
|
final String column = "_data";
|
|
|
|
|
final String[] projection = {column};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
|
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
|
final int column_index = cursor.getColumnIndexOrThrow(column);
|
|
|
|
|
return cursor.getString(column_index);
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
if (cursor != null)
|
|
|
|
|
cursor.close();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method checkStoragePermissions
|
|
|
|
|
* @description: 用于动态申请权限
|
|
|
|
|
* @date: 2024/1/6 8:58
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param: activity
|
|
|
|
|
* @return: void
|
|
|
|
|
*/
|
|
|
|
|
/**public static void checkStoragePermissions(Activity activity){
|
|
|
|
|
try{
|
|
|
|
|
//监测是否有写/读的权限
|
|
|
|
|
int permission= ActivityCompat.checkSelfPermission(activity,
|
|
|
|
|
"android.permission.WRITE_EXTERNAL_STORAGE");
|
|
|
|
|
int permission1= ActivityCompat.checkSelfPermission(activity,
|
|
|
|
|
"android.permission.READ_EXTERNAL_STORAGE");
|
|
|
|
|
if(permission != PackageManager.PERMISSION_GRANTED){
|
|
|
|
|
//没有写的权限,去申请写的权限,或弹出对话框
|
|
|
|
|
ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE,REQUEST_EXTERNAL_STORAGE);
|
|
|
|
|
}
|
|
|
|
|
if(permission1 != PackageManager.PERMISSION_GRANTED){
|
|
|
|
|
//没有读的权限,去申请读的权限,或弹出对话框
|
|
|
|
|
ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE,REQUEST_EXTERNAL_STORAGE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method textToSpeach
|
|
|
|
|
* @description: 朗读功能
|
|
|
|
|
* @date: 2024/1/16 20:21
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
*/
|
|
|
|
|
/**private void textToSpeach(){
|
|
|
|
|
mTTS.speak(mNoteEditor.getText().toString(),TextToSpeech.QUEUE_FLUSH,null);
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|