|
|
@ -28,6 +28,7 @@ import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
|
|
|
|
import android.media.MediaPlayer;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.Spannable;
|
|
|
@ -51,6 +52,11 @@ 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 android.widget.Button;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.speech.tts.TextToSpeech;
|
|
|
|
|
|
|
|
import android.speech.tts.UtteranceProgressListener;
|
|
|
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
|
|
|
|
import net.micode.notes.R;
|
|
|
|
import net.micode.notes.R;
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
@ -72,6 +78,7 @@ import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
NoteSettingChangedListener, OnTextViewChangeListener {
|
|
|
|
NoteSettingChangedListener, OnTextViewChangeListener {
|
|
|
|
private class HeadViewHolder {
|
|
|
|
private class HeadViewHolder {
|
|
|
@ -148,12 +155,33 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
|
|
private String mUserQuery;
|
|
|
|
private String mUserQuery;
|
|
|
|
private Pattern mPattern;
|
|
|
|
private Pattern mPattern;
|
|
|
|
|
|
|
|
private Button readButton;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private TextToSpeech tts;//接口
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
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);
|
|
|
|
|
|
|
|
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {//tts初始化
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onInit(int status) {
|
|
|
|
|
|
|
|
if(status == TextToSpeech.SUCCESS) {//设置中文
|
|
|
|
|
|
|
|
int result = tts.setLanguage(Locale.CHINA);
|
|
|
|
|
|
|
|
if (result != TextToSpeech.LANG_COUNTRY_AVAILABLE && result != TextToSpeech.LANG_AVAILABLE) {
|
|
|
|
|
|
|
|
Toast.makeText(NoteEditActivity.this, "正在跳转", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
tts.setSpeechRate(1.0f);//速度
|
|
|
|
|
|
|
|
tts.setPitch(1.0f);//音调
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
readButton=findViewById(R.id.readnote);//按钮
|
|
|
|
|
|
|
|
readButton.setOnClickListener(new View.OnClickListener() {//点击阅读
|
|
|
|
|
|
|
|
@Override public void onClick(View view) {
|
|
|
|
|
|
|
|
ReadNow();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
|
|
|
finish();
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -161,6 +189,36 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
initResources();
|
|
|
|
initResources();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void ReadNow(){
|
|
|
|
|
|
|
|
String noteContent = getCurrentNoteContent();
|
|
|
|
|
|
|
|
if (noteContent.isEmpty()){
|
|
|
|
|
|
|
|
MediaPlayer player=MediaPlayer.create(this,R.raw.pleaseinput);
|
|
|
|
|
|
|
|
player.start();
|
|
|
|
|
|
|
|
Toast.makeText(NoteEditActivity.this, "请输入内容", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Toast.makeText(NoteEditActivity.this, "开始阅读", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
// 开始朗读(使用本地语音)
|
|
|
|
|
|
|
|
tts.speak(noteContent, TextToSpeech.QUEUE_ADD, null, "test");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getCurrentNoteContent() {//获取文本
|
|
|
|
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
|
|
|
|
StringBuilder content = new StringBuilder();
|
|
|
|
|
|
|
|
for (int i = 0; i < mEditTextList.getChildCount(); i++) {
|
|
|
|
|
|
|
|
View itemView = mEditTextList.getChildAt(i);
|
|
|
|
|
|
|
|
CheckBox checkBox = itemView.findViewById(R.id.cb_edit_item);
|
|
|
|
|
|
|
|
NoteEditText editText = itemView.findViewById(R.id.et_edit_text);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String prefix = checkBox.isChecked() ? "已完成: " : "未完成: ";
|
|
|
|
|
|
|
|
content.append(prefix).append(editText.getText()).append("\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return content.toString();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return mNoteEditor.getText().toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}//
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Current activity may be killed when the memory is low. Once it is killed, for another time
|
|
|
|
* Current activity may be killed when the memory is low. Once it is killed, for another time
|
|
|
|
* user load this activity, we should restore the former state
|
|
|
|
* user load this activity, we should restore the former state
|
|
|
|