|
|
@ -14,11 +14,15 @@ import android.content.SharedPreferences;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
|
|
|
import android.speech.tts.TextToSpeech;
|
|
|
|
|
|
|
|
import android.speech.tts.TextToSpeech.OnInitListener;
|
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.format.DateUtils;
|
|
|
|
import android.text.format.DateUtils;
|
|
|
|
import android.text.style.BackgroundColorSpan;
|
|
|
|
import android.text.style.BackgroundColorSpan;
|
|
|
|
|
|
|
|
import android.text.Editable;// 引入textwatcher和Editable
|
|
|
|
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.Menu;
|
|
|
@ -30,11 +34,14 @@ 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;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
|
|
|
|
|
|
|
|
import net.micode.notes.R;
|
|
|
|
import net.micode.notes.R;
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
|
import net.micode.notes.data.Notes.TextNote;
|
|
|
|
import net.micode.notes.data.Notes.TextNote;
|
|
|
@ -54,8 +61,6 @@ 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
|
|
|
@ -68,6 +73,9 @@ import jp.wasabeef.richeditor.RichEditor;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
NoteSettingChangedListener, OnTextViewChangeListener {
|
|
|
|
NoteSettingChangedListener, OnTextViewChangeListener {
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 类属性的定义
|
|
|
|
|
|
|
|
*/
|
|
|
|
private class HeadViewHolder {
|
|
|
|
private class HeadViewHolder {
|
|
|
|
public TextView tvModified;
|
|
|
|
public TextView tvModified;
|
|
|
|
|
|
|
|
|
|
|
@ -79,6 +87,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
|
|
public TextView textNum;
|
|
|
|
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 {
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
|
|
|
@ -113,19 +122,28 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SUPER, R.id.iv_super_select);
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SUPER, R.id.iv_super_select);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int PHOTO_REQUEST = 1;//添加图片
|
|
|
|
|
|
|
|
private static final int REQUEST_EXTERNAL_STORAGE=1;//权限申请
|
|
|
|
|
|
|
|
private static String[] PERMISSIONS_STORAGE = {
|
|
|
|
|
|
|
|
"android.permission.READ_EXTERNAL_STORAGE",
|
|
|
|
|
|
|
|
"android.permission.WRITE_EXTERNAL_STORAGE" };//权限名称
|
|
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "NoteEditActivity";
|
|
|
|
private static final String TAG = "NoteEditActivity";
|
|
|
|
|
|
|
|
|
|
|
|
private HeadViewHolder mNoteHeaderHolder;
|
|
|
|
private HeadViewHolder mNoteHeaderHolder;
|
|
|
|
|
|
|
|
|
|
|
|
private View mHeadViewPanel;
|
|
|
|
private View mHeadViewPanel;
|
|
|
|
|
|
|
|
|
|
|
|
private View mNoteBgColorSelector;
|
|
|
|
private View mNoteBgColorSelector;
|
|
|
|
|
|
|
|
|
|
|
|
private View mFontSizeSelector;
|
|
|
|
private View mFontSizeSelector;
|
|
|
|
//private EditText mNoteEditor;
|
|
|
|
|
|
|
|
private RichEditor mNoteEditor;//富文本编辑器
|
|
|
|
private EditText mNoteEditor;
|
|
|
|
private TextView mPreview;
|
|
|
|
|
|
|
|
private String mText;//mText和mNoteLength是给富文本编辑器的
|
|
|
|
|
|
|
|
private int mNoteLength;
|
|
|
|
|
|
|
|
private int mFontSize;
|
|
|
|
|
|
|
|
private View mNoteEditorPanel;
|
|
|
|
private View mNoteEditorPanel;
|
|
|
|
public WorkingNote mWorkingNote;
|
|
|
|
|
|
|
|
|
|
|
|
private WorkingNote mWorkingNote;
|
|
|
|
|
|
|
|
|
|
|
|
private SharedPreferences mSharedPrefs;
|
|
|
|
private SharedPreferences mSharedPrefs;
|
|
|
|
private int mFontSizeId;
|
|
|
|
private int mFontSizeId;
|
|
|
|
|
|
|
|
|
|
|
@ -141,315 +159,50 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
private String mUserQuery;
|
|
|
|
private String mUserQuery;
|
|
|
|
private Pattern mPattern;
|
|
|
|
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 对原始文本进行处理,去除图片字符、换行符和空格字符
|
|
|
|
* @description 对原始文本进行处理,去除图片字符、换行符和空格字符
|
|
|
|
* @date: 1/3/2024 8:48 AM
|
|
|
|
* @date: 1/3/2024 8:48 AM
|
|
|
|
* @author: YangYizhe
|
|
|
|
* @author: YangYizhe
|
|
|
|
* @param oriText
|
|
|
|
* @param oriText
|
|
|
|
* @return 处理后的文本
|
|
|
|
* @return 处理后的文本
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String textChange(String oriText) {
|
|
|
|
private String Textchange(String oriText){
|
|
|
|
StringBuilder stringBuilder = new StringBuilder(oriText);
|
|
|
|
StringBuffer stringBuffer = new StringBuffer(oriText);
|
|
|
|
// 移除所有<>
|
|
|
|
int Flag1 = -1;
|
|
|
|
removeAngleBrackets(stringBuilder);
|
|
|
|
int Flag2 = -1;
|
|
|
|
// 将 替换为普通空格
|
|
|
|
do {//不计入表示图片的字符
|
|
|
|
int index = stringBuilder.indexOf(" ");
|
|
|
|
Flag1 = stringBuffer.indexOf("<img");
|
|
|
|
while (index != -1) {
|
|
|
|
Flag2 = stringBuffer.indexOf(">");
|
|
|
|
stringBuilder.replace(index, index + 6, " ");
|
|
|
|
if (Flag1 != -1 && Flag2 != -1) {
|
|
|
|
index = stringBuilder.indexOf(" ", index + 1);
|
|
|
|
stringBuffer = stringBuffer.replace(Flag1, Flag2+1, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
return stringBuilder.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (Flag1 != -1 && Flag2 != -1);
|
|
|
|
|
|
|
|
|
|
|
|
private String removeBlank(String oriText) {
|
|
|
|
do {//不计入换行字符
|
|
|
|
StringBuilder stringBuilder = new StringBuilder(oriText);
|
|
|
|
Flag1 = stringBuffer.indexOf("\n");
|
|
|
|
// 移除换行符和其他空格
|
|
|
|
|
|
|
|
for (int i = 0; i < stringBuilder.length(); i++) {
|
|
|
|
|
|
|
|
char c = stringBuilder.charAt(i);
|
|
|
|
|
|
|
|
if (c == '\n' || c == ' ') {
|
|
|
|
|
|
|
|
stringBuilder.deleteCharAt(i);
|
|
|
|
|
|
|
|
i--;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return stringBuilder.toString();
|
|
|
|
if (Flag1 != -1){
|
|
|
|
|
|
|
|
stringBuffer = stringBuffer.replace(Flag1, Flag1+1, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
} while (Flag1 != -1);
|
|
|
|
* @method removeAngleBrackets
|
|
|
|
do {//不计入空格字符
|
|
|
|
* @description 用以辅助移除<></>
|
|
|
|
Flag1 = stringBuffer.indexOf(" ");
|
|
|
|
* @date: 1/18/2024 7:22 PM
|
|
|
|
|
|
|
|
* @author: YangYizhe
|
|
|
|
if (Flag1 != -1) {
|
|
|
|
* @param
|
|
|
|
stringBuffer = stringBuffer.replace(Flag1, Flag1+1, "");
|
|
|
|
* @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);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (Flag1 != -1);
|
|
|
|
|
|
|
|
return stringBuffer.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @method count
|
|
|
|
* @method count
|
|
|
|
* @description 监听编辑框文本变化并更新字符数
|
|
|
|
* @description 监听编辑框文本变化并更新字符数
|
|
|
|
* @date: 1/3/2024 9:09 AM
|
|
|
|
* @date: 1/3/2024 9:09 AM
|
|
|
|
* @author: YangYizhe
|
|
|
|
* @author: YangYizhe
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
/**private void count() {
|
|
|
|
private void count() {
|
|
|
|
mNoteEditor.addTextChangedListener(new TextWatcher() {
|
|
|
|
mNoteEditor.addTextChangedListener(new TextWatcher() {
|
|
|
|
int currentLength = 0;
|
|
|
|
int currentLength = 0;
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -459,7 +212,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
currentLength = textChange(mNoteEditor.getText().toString()).length();
|
|
|
|
currentLength = Textchange(mNoteEditor.getText().toString()).length();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -467,7 +220,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
mNoteHeaderHolder.textNum.setText("字数:" + currentLength);
|
|
|
|
mNoteHeaderHolder.textNum.setText("字数:" + currentLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*在 Activity 创建时进行一些初始化工作,包括设置布局、初始化状态和资源等操作
|
|
|
|
*在 Activity 创建时进行一些初始化工作,包括设置布局、初始化状态和资源等操作
|
|
|
@ -476,13 +229,31 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
this.setContentView(R.layout.note_edit);
|
|
|
|
this.setContentView(R.layout.note_edit);
|
|
|
|
|
|
|
|
checkStoragePermissions(this);//动态申请权限
|
|
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
|
|
|
finish();
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
initResources();
|
|
|
|
initResources();
|
|
|
|
initRichEditor();
|
|
|
|
|
|
|
|
//count();
|
|
|
|
final ImageButton add_img_btn = (ImageButton) findViewById(R.id.add_img_btn);//根据id获取添加图片按钮
|
|
|
|
|
|
|
|
//为点击图片按钮设置监听器
|
|
|
|
|
|
|
|
add_img_btn.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
|
|
|
Log.d(TAG, "onClick: click add image button");
|
|
|
|
|
|
|
|
//ACTION_GET_CONTENT: 允许用户选择特殊种类的数据,并返回(特殊种类的数据:照一张相片或录一段音)
|
|
|
|
|
|
|
|
Intent loadImage = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
|
|
|
|
|
//Category属性用于指定当前动作(Action)被执行的环境.
|
|
|
|
|
|
|
|
//CATEGORY_OPENABLE; 用来指示一个ACTION_GET_CONTENT的intent
|
|
|
|
|
|
|
|
loadImage.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
|
|
|
|
|
loadImage.setType("image/*");
|
|
|
|
|
|
|
|
startActivityForResult(loadImage, PHOTO_REQUEST);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
convertToImage();//将路径显示为图片
|
|
|
|
|
|
|
|
count();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -503,7 +274,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean initActivityState(Intent intent) {
|
|
|
|
private boolean initActivityState(Intent intent) {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* If the user specified the {@link Intent#ACTION_VIEW} but not provided with id,
|
|
|
|
* If the user specified the {@link Intent#ACTION_VIEW} but not provided with id,
|
|
|
@ -544,6 +314,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
|
|
|
|
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
|
|
|
|
|
|
|
|
// New note
|
|
|
|
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
|
|
|
|
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
|
|
|
|
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
|
|
|
|
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
|
|
|
|
AppWidgetManager.INVALID_APPWIDGET_ID);
|
|
|
|
AppWidgetManager.INVALID_APPWIDGET_ID);
|
|
|
@ -551,6 +322,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
Notes.TYPE_WIDGET_INVALIDE);
|
|
|
|
Notes.TYPE_WIDGET_INVALIDE);
|
|
|
|
int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID,
|
|
|
|
int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID,
|
|
|
|
ResourceParser.getDefaultBgId(this));
|
|
|
|
ResourceParser.getDefaultBgId(this));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Parse call-record note
|
|
|
|
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
|
|
|
|
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
|
|
|
|
long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);
|
|
|
|
long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);
|
|
|
|
if (callDate != 0 && phoneNumber != null) {
|
|
|
|
if (callDate != 0 && phoneNumber != null) {
|
|
|
@ -602,12 +375,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* @author: YangYizhe
|
|
|
|
* @author: YangYizhe
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void initNoteScreen() {
|
|
|
|
private void initNoteScreen() {
|
|
|
|
mNoteEditor.setEditorFontSize(30);
|
|
|
|
mNoteEditor.setTextAppearance(this, TextAppearanceResources
|
|
|
|
|
|
|
|
.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.setHtml(String.valueOf(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery)));
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
//mNoteEditor.setSelection(mText.length());
|
|
|
|
mNoteEditor.setSelection(mNoteEditor.getText().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);
|
|
|
@ -625,6 +399,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* is not ready
|
|
|
|
* is not ready
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
showAlertHeader();
|
|
|
|
showAlertHeader();
|
|
|
|
|
|
|
|
convertToImage();//将路径转化未图片
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @method showAlertHeader
|
|
|
|
* @method showAlertHeader
|
|
|
@ -642,8 +417,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
if (time > mWorkingNote.getAlertDate()) {
|
|
|
|
if (time > mWorkingNote.getAlertDate()) {
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setText(R.string.note_alert_expired);
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setText(R.string.note_alert_expired);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setText(DateUtils.getRelativeTimeSpanString(
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setText(DateUtils.getRelativeTimeSpanString(
|
|
|
|
mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS));
|
|
|
|
mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -655,12 +429,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
initActivityState(intent);
|
|
|
|
initActivityState(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
@ -675,6 +449,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
outState.putLong(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
|
|
|
outState.putLong(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
|
|
|
Log.d(TAG, "Save working note id: " + mWorkingNote.getNoteId() + " onSaveInstanceState");
|
|
|
|
Log.d(TAG, "Save working note id: " + mWorkingNote.getNoteId() + " onSaveInstanceState");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
|
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE
|
|
|
|
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE
|
|
|
@ -699,8 +474,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
if (ev.getX() < x
|
|
|
|
if (ev.getX() < x
|
|
|
|
|| ev.getX() > (x + view.getWidth())
|
|
|
|
|| ev.getX() > (x + view.getWidth())
|
|
|
|
|| ev.getY() < y
|
|
|
|
|| ev.getY() < y
|
|
|
|
|| ev.getY() > (y + view.getHeight()))
|
|
|
|
|| ev.getY() > (y + view.getHeight())) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
@ -715,18 +489,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
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.textNum = (TextView) findViewById(R.id.text_num);
|
|
|
|
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
|
|
|
|
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
|
|
|
|
mNoteEditor = findViewById(R.id.note_edit_view);
|
|
|
|
mNoteEditor = (EditText) 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);
|
|
|
|
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()) {
|
|
|
@ -750,6 +513,24 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE;
|
|
|
|
mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
|
|
|
|
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//朗读
|
|
|
|
|
|
|
|
mTTS = new TextToSpeech(this,new TextToSpeech.OnInitListener(){
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onInit(int status){
|
|
|
|
|
|
|
|
// 判断是否转化成功
|
|
|
|
|
|
|
|
if (status == TextToSpeech.SUCCESS){
|
|
|
|
|
|
|
|
//默认设定语言为中文
|
|
|
|
|
|
|
|
int result = mTTS.setLanguage(Locale.CHINESE);
|
|
|
|
|
|
|
|
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED){
|
|
|
|
|
|
|
|
Toast.makeText(NoteEditActivity.this, "Language not available.", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
//不支持中文就将语言设置为英文
|
|
|
|
|
|
|
|
mTTS.setLanguage(Locale.US);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -785,7 +566,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
setResult(RESULT_OK, intent);
|
|
|
|
setResult(RESULT_OK, intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
public void onClick(View v) {
|
|
|
|
int id = v.getId();
|
|
|
|
int id = v.getId();
|
|
|
|
if (id == R.id.btn_set_bg_color) {
|
|
|
|
if (id == R.id.btn_set_bg_color) {
|
|
|
@ -806,7 +586,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
getWorkingText();
|
|
|
|
getWorkingText();
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
mNoteEditor.setEditorFontSize(mFontSizeId);
|
|
|
|
mNoteEditor.setTextAppearance(this,
|
|
|
|
|
|
|
|
TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -850,6 +631,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
|
|
|
|
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
|
|
|
|
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
if (isFinishing()) {
|
|
|
|
if (isFinishing()) {
|
|
|
@ -874,6 +656,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @method onOptionsItemSelected
|
|
|
|
* @method onOptionsItemSelected
|
|
|
@ -916,6 +699,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
setReminder();
|
|
|
|
setReminder();
|
|
|
|
} else if (itemId == R.id.menu_delete_remind) {
|
|
|
|
} else if (itemId == R.id.menu_delete_remind) {
|
|
|
|
mWorkingNote.setAlertDate(0, false);
|
|
|
|
mWorkingNote.setAlertDate(0, false);
|
|
|
|
|
|
|
|
} else if (itemId == R.id.menu_voice){
|
|
|
|
|
|
|
|
Log.d("voiceOut","in");
|
|
|
|
|
|
|
|
textToSpeach();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -937,7 +723,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
d.show();
|
|
|
|
d.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Share note to apps that support {@link Intent#ACTION_SEND} action
|
|
|
|
* Share note to apps that support {@link Intent#ACTION_SEND} action
|
|
|
|
* and {@text/plain} type
|
|
|
|
* and {@text/plain} type
|
|
|
@ -1101,15 +886,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
mEditTextList.setVisibility(View.VISIBLE);
|
|
|
|
mEditTextList.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param fullText 完整文本
|
|
|
|
|
|
|
|
* @param userQuery 用户查询关键词
|
|
|
|
|
|
|
|
* @return 带有高亮效果的 Spannable 对象
|
|
|
|
|
|
|
|
* @method getHighlightQueryResult
|
|
|
|
* @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 SpannableString getHighlightQueryResult(String fullText, String userQuery) {
|
|
|
|
private Spannable getHighlightQueryResult(String fullText, String userQuery) {
|
|
|
|
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
|
|
|
|
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
|
|
|
|
if (!TextUtils.isEmpty(userQuery)) {
|
|
|
|
if (!TextUtils.isEmpty(userQuery)) {
|
|
|
|
mPattern = Pattern.compile(userQuery);
|
|
|
|
mPattern = Pattern.compile(userQuery);
|
|
|
@ -1193,17 +978,21 @@ 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(textChange(mText));
|
|
|
|
switchToListMode(mNoteEditor.getText().toString());
|
|
|
|
|
|
|
|
//检查模式切换到列表模式
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (!getWorkingText()) {
|
|
|
|
if (!getWorkingText()) {
|
|
|
|
mWorkingNote.setWorkingText(mWorkingNote.getContent().replace(TAG_UNCHECKED + " ",
|
|
|
|
mWorkingNote.setWorkingText(mWorkingNote.getContent().replace(TAG_UNCHECKED + " ",
|
|
|
|
""));
|
|
|
|
""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mNoteEditor.setHtml(String.valueOf(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery)));
|
|
|
|
//若是获取到文本就改变其检查标记
|
|
|
|
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
mEditTextList.setVisibility(View.GONE);
|
|
|
|
mEditTextList.setVisibility(View.GONE);
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
//修改文本编辑器的内容和可见性
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @method getWorkingText
|
|
|
|
* @method getWorkingText
|
|
|
|
* @description 获取正在编辑的文本内容
|
|
|
|
* @description 获取正在编辑的文本内容
|
|
|
@ -1212,26 +1001,23 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* @return 是否存在已打钩的选项
|
|
|
|
* @return 是否存在已打钩的选项
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private boolean getWorkingText() {
|
|
|
|
private boolean getWorkingText() {
|
|
|
|
boolean hasChecked = false;//初始化check标记
|
|
|
|
boolean hasChecked = false;
|
|
|
|
|
|
|
|
//初始化check标记
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
/**
|
|
|
|
// 若模式为CHECK_LIST
|
|
|
|
* 若模式为CHECK_LIST
|
|
|
|
|
|
|
|
* 先创建可变字符串
|
|
|
|
|
|
|
|
* 遍历所有子编辑框的视图
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
//创建可变字符串
|
|
|
|
for (int i = 0; i < mEditTextList.getChildCount(); i++) {
|
|
|
|
for (int i = 0; i < mEditTextList.getChildCount(); i++) {
|
|
|
|
View view = mEditTextList.getChildAt(i);
|
|
|
|
View view = mEditTextList.getChildAt(i);
|
|
|
|
|
|
|
|
//遍历所有子编辑框的视图
|
|
|
|
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
if (!TextUtils.isEmpty(edit.getText())) {
|
|
|
|
if (!TextUtils.isEmpty(edit.getText())) {
|
|
|
|
/**
|
|
|
|
//若文本不为空
|
|
|
|
* 若文本不为空
|
|
|
|
|
|
|
|
* 该选项框已打钩
|
|
|
|
|
|
|
|
* 扩展字符串为已打钩并把标记置true
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (((CheckBox) view.findViewById(R.id.cb_edit_item)).isChecked()) {
|
|
|
|
if (((CheckBox) view.findViewById(R.id.cb_edit_item)).isChecked()) {
|
|
|
|
|
|
|
|
//该选项框已打钩
|
|
|
|
sb.append(TAG_CHECKED).append(" ").append(edit.getText()).append("\n");
|
|
|
|
sb.append(TAG_CHECKED).append(" ").append(edit.getText()).append("\n");
|
|
|
|
hasChecked = true;
|
|
|
|
hasChecked = true;
|
|
|
|
|
|
|
|
//扩展字符串为已打钩并把标记置true
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
//扩展字符串添加未打钩
|
|
|
|
//扩展字符串添加未打钩
|
|
|
|
sb.append(TAG_UNCHECKED).append(" ").append(edit.getText()).append("\n");
|
|
|
|
sb.append(TAG_UNCHECKED).append(" ").append(edit.getText()).append("\n");
|
|
|
@ -1239,8 +1025,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mWorkingNote.setWorkingText(sb.toString());//利用编辑好的字符串设置运行便签的内容
|
|
|
|
mWorkingNote.setWorkingText(sb.toString());//利用编辑好的字符串设置运行便签的内容
|
|
|
|
|
|
|
|
//利用编辑好的字符串设置运行便签的内容
|
|
|
|
} else {// 若不是该模式直接用编辑器中的内容设置运行中标签的内容
|
|
|
|
} else {// 若不是该模式直接用编辑器中的内容设置运行中标签的内容
|
|
|
|
mWorkingNote.setWorkingText(textChange(mText));
|
|
|
|
mWorkingNote.setWorkingText(mNoteEditor.getText().toString());
|
|
|
|
|
|
|
|
//若是获取到文本就改变其检查标记
|
|
|
|
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
|
|
|
|
mEditTextList.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
//修改文本编辑器的内容和可见性
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hasChecked;
|
|
|
|
return hasChecked;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1254,6 +1046,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
private boolean saveNote() {
|
|
|
|
private boolean saveNote() {
|
|
|
|
getWorkingText();
|
|
|
|
getWorkingText();
|
|
|
|
boolean saved = mWorkingNote.saveNote();
|
|
|
|
boolean saved = mWorkingNote.saveNote();
|
|
|
|
|
|
|
|
//如果便签内容为空,则删除
|
|
|
|
if (TextUtils.isEmpty(mWorkingNote.getContent())) {
|
|
|
|
if (TextUtils.isEmpty(mWorkingNote.getContent())) {
|
|
|
|
deleteCurrentNote();//删除当前便签
|
|
|
|
deleteCurrentNote();//删除当前便签
|
|
|
|
saved = false; // 标记为未保存
|
|
|
|
saved = false; // 标记为未保存
|
|
|
@ -1313,6 +1106,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
showToast(R.string.error_note_empty_for_send_to_desktop);
|
|
|
|
showToast(R.string.error_note_empty_for_send_to_desktop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @method makeShortcutIconTitle
|
|
|
|
* @method makeShortcutIconTitle
|
|
|
|
* @description 生成快捷方式图标标题
|
|
|
|
* @description 生成快捷方式图标标题
|
|
|
@ -1327,12 +1121,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
return content.length() > SHORTCUT_ICON_TITLE_MAX_LEN ? content.substring(0,
|
|
|
|
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) {
|
|
|
|
private void showToast(int resId) {
|
|
|
|
showToast(resId, Toast.LENGTH_SHORT);
|
|
|
|
showToast(resId, Toast.LENGTH_SHORT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void showToast(int resId, int duration) {
|
|
|
|
private void showToast(int resId, int duration) {
|
|
|
|
Toast.makeText(this, resId, duration).show();
|
|
|
|
Toast.makeText(this, resId, duration).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @method convertToImage
|
|
|
|
* @method convertToImage
|
|
|
|
* @description: 路径字符串格式 转换为 图片image格式
|
|
|
|
* @description: 路径字符串格式 转换为 图片image格式
|
|
|
@ -1341,7 +1138,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* @param: void
|
|
|
|
* @param: void
|
|
|
|
* @return: void
|
|
|
|
* @return: void
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
/**private void convertToImage() {
|
|
|
|
private void convertToImage() {
|
|
|
|
NoteEditText noteEditText = (NoteEditText) findViewById(R.id.note_edit_view); //获取当前的edit
|
|
|
|
NoteEditText noteEditText = (NoteEditText) findViewById(R.id.note_edit_view); //获取当前的edit
|
|
|
|
Editable editable = noteEditText.getText();//1.获取text
|
|
|
|
Editable editable = noteEditText.getText();//1.获取text
|
|
|
|
String noteText = editable.toString(); //2.将note内容转换为字符串
|
|
|
|
String noteText = editable.toString(); //2.将note内容转换为字符串
|
|
|
@ -1379,7 +1176,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @method onActivityResult
|
|
|
|
* @method onActivityResult
|
|
|
@ -1389,7 +1186,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* @param:
|
|
|
|
* @param:
|
|
|
|
* @return: void
|
|
|
|
* @return: void
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
/**@Override
|
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, intent);
|
|
|
|
super.onActivityResult(requestCode, resultCode, intent);
|
|
|
|
ContentResolver resolver = getContentResolver();
|
|
|
|
ContentResolver resolver = getContentResolver();
|
|
|
@ -1439,7 +1236,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @method getPath
|
|
|
|
* @method getPath
|
|
|
@ -1449,7 +1246,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* @param:
|
|
|
|
* @param:
|
|
|
|
* @return:
|
|
|
|
* @return:
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
/**public String getPath(final Context context, final Uri uri) {
|
|
|
|
public String getPath(final Context context, final Uri uri) {
|
|
|
|
|
|
|
|
|
|
|
|
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
|
|
|
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
|
|
|
|
|
|
|
|
|
|
@ -1480,7 +1277,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
return uri.getPath();
|
|
|
|
return uri.getPath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @method isMediaDocument
|
|
|
|
* @method isMediaDocument
|
|
|
@ -1490,7 +1287,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* @param: uri
|
|
|
|
* @param: uri
|
|
|
|
* @return:
|
|
|
|
* @return:
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
/**public boolean isMediaDocument(Uri uri) {
|
|
|
|
public boolean isMediaDocument(Uri uri) {
|
|
|
|
return "com.android.providers.media.documents".equals(uri.getAuthority());
|
|
|
|
return "com.android.providers.media.documents".equals(uri.getAuthority());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1502,7 +1299,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* @param:
|
|
|
|
* @param:
|
|
|
|
* @return:
|
|
|
|
* @return:
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
/**public String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
|
|
|
|
public String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
|
|
|
|
|
|
|
|
|
|
|
|
Cursor cursor = null;
|
|
|
|
Cursor cursor = null;
|
|
|
|
final String column = "_data";
|
|
|
|
final String column = "_data";
|
|
|
@ -1529,7 +1326,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* @param: activity
|
|
|
|
* @param: activity
|
|
|
|
* @return: void
|
|
|
|
* @return: void
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
/**public static void checkStoragePermissions(Activity activity){
|
|
|
|
public static void checkStoragePermissions(Activity activity){
|
|
|
|
try{
|
|
|
|
try{
|
|
|
|
//监测是否有写/读的权限
|
|
|
|
//监测是否有写/读的权限
|
|
|
|
int permission= ActivityCompat.checkSelfPermission(activity,
|
|
|
|
int permission= ActivityCompat.checkSelfPermission(activity,
|
|
|
@ -1556,7 +1353,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* @date: 2024/1/16 20:21
|
|
|
|
* @date: 2024/1/16 20:21
|
|
|
|
* @author: WuShuxian
|
|
|
|
* @author: WuShuxian
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
/**private void textToSpeach(){
|
|
|
|
private void textToSpeach(){
|
|
|
|
mTTS.speak(mNoteEditor.getText().toString(),TextToSpeech.QUEUE_FLUSH,null);
|
|
|
|
mTTS.speak(mNoteEditor.getText().toString(),TextToSpeech.QUEUE_FLUSH,null);
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|