|
|
|
@ -15,12 +15,10 @@
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
|
|
|
|
|
|
import android.speech.tts.TextToSpeech.OnInitListener;
|
|
|
|
|
|
|
|
|
|
import android.app.AlarmManager;
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
|
import android.app.Dialog;
|
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
|
import android.app.SearchManager;
|
|
|
|
|
import android.appwidget.AppWidgetManager;
|
|
|
|
@ -32,8 +30,6 @@ import android.content.SharedPreferences;
|
|
|
|
|
import android.graphics.Paint;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
import android.speech.tts.TextToSpeech;
|
|
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
|
import android.text.Editable;
|
|
|
|
|
import android.text.Spannable;
|
|
|
|
@ -50,12 +46,11 @@ import android.view.MotionEvent;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
|
import android.view.WindowManager;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
|
import android.widget.CompoundButton;
|
|
|
|
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
@ -76,7 +71,6 @@ import net.micode.notes.widget.NoteWidgetProvider_4x;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
@ -96,9 +90,6 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
public ImageView ibSetBgColor;
|
|
|
|
|
}
|
|
|
|
|
//使用Map实现数据存储
|
|
|
|
|
final String[] mPermissionList = new String[]{
|
|
|
|
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
|
|
|
Manifest.permission.READ_EXTERNAL_STORAGE};
|
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
|
static {
|
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
|
|
|
|
@ -140,7 +131,7 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
private static final String TAG = "NoteEditActivity";
|
|
|
|
|
|
|
|
|
|
private HeadViewHolder mNoteHeaderHolder;
|
|
|
|
|
private TextToSpeech mTTS;
|
|
|
|
|
|
|
|
|
|
private View mHeadViewPanel;
|
|
|
|
|
//私有化一个界面操作mHeadViewPanel,对表头的操作
|
|
|
|
|
private View mNoteBgColorSelector;
|
|
|
|
@ -174,7 +165,6 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
//字符数量计数显示
|
|
|
|
|
private TextView textView;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
@ -186,7 +176,6 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
}
|
|
|
|
|
initResources();
|
|
|
|
|
count();
|
|
|
|
|
read();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -227,7 +216,7 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
}
|
|
|
|
|
//如果ID在数据库中未找到
|
|
|
|
|
if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) {
|
|
|
|
|
Intent jump = new Intent(this, net.micode.notes.ui.NotesListActivity.class);
|
|
|
|
|
Intent jump = new Intent(this, NotesListActivity.class);
|
|
|
|
|
startActivity(jump);
|
|
|
|
|
//程序将跳转到上面声明的intent——jump
|
|
|
|
|
showToast(R.string.error_note_not_exist);
|
|
|
|
@ -307,7 +296,8 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initNoteScreen() {
|
|
|
|
|
//对界面的初始化操作
|
|
|
|
|
|
|
|
|
|
//对便签的初始化操作
|
|
|
|
|
mNoteEditor.setTextAppearance(this, TextAppearanceResources
|
|
|
|
|
.getTexAppearanceResource(mFontSizeId));
|
|
|
|
|
//设置外观
|
|
|
|
@ -412,20 +402,6 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initResources() {
|
|
|
|
|
|
|
|
|
|
mTTS = new TextToSpeech(this, new OnInitListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onInit(int status) {
|
|
|
|
|
|
|
|
|
|
if (status == TextToSpeech.SUCCESS) {
|
|
|
|
|
int result = mTTS.setLanguage(Locale.US);
|
|
|
|
|
|
|
|
|
|
if (result != TextToSpeech.LANG_COUNTRY_AVAILABLE && result != TextToSpeech.LANG_AVAILABLE) {
|
|
|
|
|
//Toast.makeText(CodeView.this,"TTS暂时不支持这种语言朗读",50000).show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
mHeadViewPanel = findViewById(R.id.note_title);
|
|
|
|
|
mNoteHeaderHolder = new HeadViewHolder();
|
|
|
|
|
mNoteHeaderHolder.tvModified = (TextView) findViewById(R.id.tv_modified_date);
|
|
|
|
@ -492,7 +468,7 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
if (id == R.id.btn_set_bg_color) {
|
|
|
|
|
mNoteBgColorSelector.setVisibility(View.VISIBLE);
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
|
View.VISIBLE);
|
|
|
|
|
- View.VISIBLE);
|
|
|
|
|
} else if (sBgSelectorBtnsMap.containsKey(id)) {
|
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
|
View.GONE);
|
|
|
|
@ -511,8 +487,6 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
|
|
|
|
|
}
|
|
|
|
|
mFontSizeSelector.setVisibility(View.GONE);
|
|
|
|
|
}else if (id==R.id.read_note){
|
|
|
|
|
mTTS.speak(mNoteEditor.getText().toString(),TextToSpeech.QUEUE_FLUSH,null);
|
|
|
|
|
}
|
|
|
|
|
}//************************存在问题
|
|
|
|
|
|
|
|
|
@ -571,7 +545,6 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
/*
|
|
|
|
|
* 函数功能:动态改变菜单选项内容
|
|
|
|
@ -580,14 +553,56 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
//根据菜单的id来编剧相关项目
|
|
|
|
|
case R.id.action_insert_image:
|
|
|
|
|
//绑定按钮的点击响应,获取危险权限,这里的100是申请码,可以自己定义,整数即可
|
|
|
|
|
ActivityCompat.requestPermissions(NoteEditActivity.this, mPermissionList, 100);
|
|
|
|
|
//用于获取焦点,否则插入图片时没有响应
|
|
|
|
|
mNoteEditor.getFocusable();
|
|
|
|
|
mNoteEditor.insertImage(realPathFromUri, realPathFromUri + "\" style=\"max-width:100%");
|
|
|
|
|
case R.id.locker:
|
|
|
|
|
//为便签上锁
|
|
|
|
|
final AlertDialog.Builder create_password = new AlertDialog.Builder(this);
|
|
|
|
|
//创建关于上锁操作的对话框
|
|
|
|
|
final View view = LayoutInflater.from(this).inflate(R.layout.buttom,null);
|
|
|
|
|
//???
|
|
|
|
|
final EditText etName = (EditText)view.findViewById(R.id.password);
|
|
|
|
|
final EditText etTag = (EditText)view.findViewById(R.id.tag);
|
|
|
|
|
//???
|
|
|
|
|
etName.setText("");
|
|
|
|
|
etName.setHint(" Please input your password");
|
|
|
|
|
etTag.setText("");
|
|
|
|
|
etTag.setHint(" Please input your tag");
|
|
|
|
|
create_password.setTitle(getString(R.string.alert_set_password));
|
|
|
|
|
//设置标题为Set your password
|
|
|
|
|
create_password.setNegativeButton("OK", new DialogInterface.OnClickListener() {//设置监听,获取输入的字符串
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
String password = etName.getText().toString();
|
|
|
|
|
String tag = etTag.getText().toString();
|
|
|
|
|
//获取输入的字符串
|
|
|
|
|
mWorkingNote.setPassword(password,tag);
|
|
|
|
|
//设置密码
|
|
|
|
|
Toast.makeText(NoteEditActivity.this,"Password created successfully",Toast.LENGTH_SHORT).show();
|
|
|
|
|
//设置密码成功的消息弹窗
|
|
|
|
|
InputMethodManager inputMethodManager = (InputMethodManager)
|
|
|
|
|
getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
inputMethodManager.hideSoftInputFromWindow(etName.getWindowToken(),0);
|
|
|
|
|
//关闭软键盘
|
|
|
|
|
dialog.dismiss();
|
|
|
|
|
//关闭dialog
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
create_password.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
//关闭软键盘
|
|
|
|
|
Toast.makeText(NoteEditActivity.this,"Canceling...",Toast.LENGTH_SHORT).show();
|
|
|
|
|
InputMethodManager inputMethodManager = (InputMethodManager)
|
|
|
|
|
getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
inputMethodManager.hideSoftInputFromWindow(etName.getWindowToken(),0);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
final Dialog dialog = create_password.setView(view).show();//error
|
|
|
|
|
dialog.show();
|
|
|
|
|
break;
|
|
|
|
|
case R.id.unlocker:
|
|
|
|
|
mWorkingNote.setPassword("","");
|
|
|
|
|
Toast.makeText(NoteEditActivity.this,"Password unlocked successfully",Toast.LENGTH_SHORT).show();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R.id.menu_new_note:
|
|
|
|
|
//创建一个新的便签
|
|
|
|
|
createNewNote();
|
|
|
|
@ -659,7 +674,7 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
* 函数实现:如下注释
|
|
|
|
|
*/
|
|
|
|
|
private void setReminder() {
|
|
|
|
|
net.micode.notes.ui.DateTimePickerDialog d = new net.micode.notes.ui.DateTimePickerDialog(this, System.currentTimeMillis());
|
|
|
|
|
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
|
|
|
|
|
// 建立修改时间日期的对话框
|
|
|
|
|
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
|
|
|
|
|
public void OnDateTimeSet(AlertDialog dialog, long date) {
|
|
|
|
@ -751,7 +766,7 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
* 函数实现:直接看NotesPreferenceActivity中同步名称是否为空
|
|
|
|
|
*/
|
|
|
|
|
private boolean isSyncMode() {
|
|
|
|
|
return net.micode.notes.ui.NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
|
|
|
|
|
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -768,7 +783,7 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
saveNote();
|
|
|
|
|
}
|
|
|
|
|
if (mWorkingNote.getNoteId() > 0) {
|
|
|
|
|
Intent intent = new Intent(this, net.micode.notes.ui.AlarmReceiver.class);
|
|
|
|
|
Intent intent = new Intent(this, AlarmReceiver.class);
|
|
|
|
|
intent.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mWorkingNote.getNoteId()));
|
|
|
|
|
//若有有运行的便签就是建立一个链接器将标签id都存在uri中
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
|
|
|
|
@ -811,19 +826,19 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
}
|
|
|
|
|
//没有编辑框的话直接返回
|
|
|
|
|
for (int i = index + 1; i < childCount; i++) {
|
|
|
|
|
((net.micode.notes.ui.NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
|
|
|
|
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
|
|
|
|
.setIndex(i - 1);
|
|
|
|
|
//通过id把编辑框存在便签编辑框中
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mEditTextList.removeViewAt(index);
|
|
|
|
|
//删除特定位置的视图
|
|
|
|
|
net.micode.notes.ui.NoteEditText edit = null;
|
|
|
|
|
NoteEditText edit = null;
|
|
|
|
|
if(index == 0) {
|
|
|
|
|
edit = (net.micode.notes.ui.NoteEditText) mEditTextList.getChildAt(0).findViewById(
|
|
|
|
|
edit = (NoteEditText) mEditTextList.getChildAt(0).findViewById(
|
|
|
|
|
R.id.et_edit_text);
|
|
|
|
|
} else {
|
|
|
|
|
edit = (net.micode.notes.ui.NoteEditText) mEditTextList.getChildAt(index - 1).findViewById(
|
|
|
|
|
edit = (NoteEditText) mEditTextList.getChildAt(index - 1).findViewById(
|
|
|
|
|
R.id.et_edit_text);
|
|
|
|
|
}
|
|
|
|
|
//通过id把编辑框存在空的NoteEditText中
|
|
|
|
@ -849,11 +864,11 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
View view = getListItem(text, index);
|
|
|
|
|
mEditTextList.addView(view, index);
|
|
|
|
|
//建立一个新的视图并添加到编辑文本框内
|
|
|
|
|
net.micode.notes.ui.NoteEditText edit = (net.micode.notes.ui.NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
|
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
|
edit.requestFocus();//请求优先操作
|
|
|
|
|
edit.setSelection(0);//定位到起始位置
|
|
|
|
|
for (int i = index + 1; i < mEditTextList.getChildCount(); i++) {
|
|
|
|
|
((net.micode.notes.ui.NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
|
|
|
|
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
|
|
|
|
.setIndex(i);
|
|
|
|
|
//遍历子文本框并设置对应对下标
|
|
|
|
|
}
|
|
|
|
@ -918,7 +933,7 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
private View getListItem(String item, int index) {
|
|
|
|
|
View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null);
|
|
|
|
|
//创建一个视图
|
|
|
|
|
final net.micode.notes.ui.NoteEditText edit = (net.micode.notes.ui.NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
|
final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
|
edit.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
|
|
|
|
|
//创建一个文本编辑框并设置可见性
|
|
|
|
|
CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item));
|
|
|
|
@ -1005,7 +1020,7 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
for (int i = 0; i < mEditTextList.getChildCount(); i++) {
|
|
|
|
|
View view = mEditTextList.getChildAt(i);
|
|
|
|
|
//遍历所有子编辑框的视图
|
|
|
|
|
net.micode.notes.ui.NoteEditText edit = (net.micode.notes.ui.NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
|
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
|
|
|
|
if (!TextUtils.isEmpty(edit.getText())) {
|
|
|
|
|
//若文本不为空
|
|
|
|
|
if (((CheckBox) view.findViewById(R.id.cb_edit_item)).isChecked()) {
|
|
|
|
@ -1179,32 +1194,6 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
|
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
|
textView.setText("字符数: " + currentLength);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void read() {
|
|
|
|
|
ImageButton read = findViewById(R.id.read_note);
|
|
|
|
|
read.setOnClickListener(new OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
mTTS.speak(mNoteEditor.getText().toString(),TextToSpeech.QUEUE_FLUSH,null);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// final String[] mPermissionList = new String[]{
|
|
|
|
|
// Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
|
|
|
// Manifest.permission.READ_EXTERNAL_STORAGE};
|
|
|
|
|
// findViewById(R.id.action_insert_image).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
// @Override
|
|
|
|
|
// public void onClick(View v) {
|
|
|
|
|
////绑定按钮的点击响应,获取危险权限,这里的100是申请码,可以自己定义,整数即可
|
|
|
|
|
// ActivityCompat.requestPermissions(NoteEditActivity.this, mPermissionList, 100);
|
|
|
|
|
////用于获取焦点,否则插入图片时没有响应
|
|
|
|
|
// mNoteEditor.focusEditor();
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
}
|