From ee280379e8aa74390d8ae355608df0c79fff3bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E4=B8=BD=E4=B8=BD?= <726944313@qq.com> Date: Thu, 29 May 2025 09:34:25 +0800 Subject: [PATCH] wll --- .../net/micode/notes/ui/NoteEditActivity.java | 60 ++++++++++++++++++- .../app/src/main/res/layout/note_edit.xml | 15 +++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/01src/XiaoMiNotes/MyApplication/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/01src/XiaoMiNotes/MyApplication/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java index 96a9ff8..02c2e1c 100644 --- a/01src/XiaoMiNotes/MyApplication/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/01src/XiaoMiNotes/MyApplication/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -28,6 +28,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Paint; +import android.media.MediaPlayer; import android.os.Bundle; import android.preference.PreferenceManager; import android.text.Spannable; @@ -51,6 +52,11 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; 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.data.Notes; @@ -72,6 +78,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; + public class NoteEditActivity extends Activity implements OnClickListener, NoteSettingChangedListener, OnTextViewChangeListener { private class HeadViewHolder { @@ -148,12 +155,33 @@ public class NoteEditActivity extends Activity implements OnClickListener, private String mUserQuery; private Pattern mPattern; + private Button readButton; + + private TextToSpeech tts;//接口 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 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())) { finish(); return; @@ -161,6 +189,36 @@ public class NoteEditActivity extends Activity implements OnClickListener, 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 * user load this activity, we should restore the former state diff --git a/01src/XiaoMiNotes/MyApplication/app/src/main/res/layout/note_edit.xml b/01src/XiaoMiNotes/MyApplication/app/src/main/res/layout/note_edit.xml index 10b2aa7..90b3056 100644 --- a/01src/XiaoMiNotes/MyApplication/app/src/main/res/layout/note_edit.xml +++ b/01src/XiaoMiNotes/MyApplication/app/src/main/res/layout/note_edit.xml @@ -69,6 +69,17 @@ android:layout_height="fill_parent" android:orientation="vertical"> +