diff --git a/01src/XiaoMiNotes/MyApplication/app/src/main/java/net/micode/notes/timer/CountDown.java b/01src/XiaoMiNotes/MyApplication/app/src/main/java/net/micode/notes/timer/CountDown.java new file mode 100644 index 0000000..c2be388 --- /dev/null +++ b/01src/XiaoMiNotes/MyApplication/app/src/main/java/net/micode/notes/timer/CountDown.java @@ -0,0 +1,156 @@ +package net.micode.notes.timer; + +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.Button; +import android.widget.Toast; +import android.widget.TextView; +import android.os.CountDownTimer; +import android.media.MediaPlayer; +import android.view.Menu; +import android.view.MenuItem; +import android.view.MenuInflater; +import android.view.MenuItem.OnMenuItemClickListener; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + + +import net.micode.notes.R; + +public class CountDown extends AppCompatActivity implements CountDownListener { + private Button startButton,resetButton,stopButton; + private static final int HOUR = 60*60*1000;//小时 + private static final int MIN = 60*1000;//分钟 + private static final int SEC = 1000;//秒 + private long hour,min,sec; + private boolean IsRunning;//是不是在跑 + private long startTime;//开始时间 + private long currentTime;//还剩多久 + private CountDownTimer timer; + private CountDownListener listener; + + + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + //getWindow().setBackgroundDrawableResource(R.drawable.cloud); + setContentView(R.layout.activity_count_down); + startButton = findViewById(R.id.button_start); + resetButton = findViewById(R.id.button_reset); + stopButton = findViewById(R.id.button_stop);//按钮 + startButton.setOnClickListener(new View.OnClickListener() { + @Override public void onClick(View view) { + start(); + } + }); + + resetButton.setOnClickListener(new View.OnClickListener() { + @Override public void onClick(View view) { + reset(); + } + }); + + stopButton.setOnClickListener(new View.OnClickListener() { + @Override public void onClick(View view) { + stop(); + } + }); + Intent intent = this.getIntent(); + hour=intent.getLongExtra("hour", 0L); + min=intent.getLongExtra("min", 0L); + sec=intent.getLongExtra("sec", 0L); + currentTime=startTime=hour*HOUR+min*MIN+sec*SEC; + updateTime(startTime); + IsRunning=false; + start();//开始跑 + + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + + } + public void setTime(long duration){ + if(IsRunning)return; + currentTime=startTime=duration; + updateTime(duration); + } + + public void start() { + if(IsRunning) {return;}//还在跑 + IsRunning = true; + timer = new CountDownTimer(currentTime, 100){//精度100ms + @Override public void onTick(long millis){ + currentTime = millis; + updateTime(millis); + //invalidate(); + } + + @Override public void onFinish() { + stop(); + if (listener != null) { + listener.onFinishCountDown(); + } + + } + }; + timer.start(); + } + + public void reset() { + stop(); + setTime(startTime); + //invalidate(); + } + + public void stop() { + if(!IsRunning){return;}//已经停了 + IsRunning=false; + timer.cancel(); + setListener(this);//监听器 + } + + public void updateTime(long duration){//展示倒计时数字 + TextView timeView = findViewById(R.id.timeshow); + String res=getTimeShow(duration); + timeView.setText(res); + } + public String getTimeShow(long duration){//获取显示数字 + int hour=(int)duration/HOUR; + duration%=HOUR; + int min=(int)duration/MIN; + duration%=MIN; + int sec=(int)duration/SEC; + String format="%02d"; + String Shour = String.format(format, hour); + String Smin = String.format( format, min); + String Ssec = String.format(format, sec); + return String.format("%s h : %s m : %s s", Shour, Smin, Ssec); + } + public void setListener(CountDownListener listener) { + this.listener = listener; + } + @Override + public void onFinishCountDown() {//倒计时截至 + //Toast.makeText(this, "Time up !!!", Toast.LENGTH_SHORT).show(); + TextView timeView = findViewById(R.id.timeshow); + timeView.setText("Time up !!!"); + MediaPlayer player=MediaPlayer.create(this,R.raw.timedown); + player.start(); + } + + +} + + + diff --git a/01src/XiaoMiNotes/MyApplication/app/src/main/java/net/micode/notes/timer/CountDownListener.java b/01src/XiaoMiNotes/MyApplication/app/src/main/java/net/micode/notes/timer/CountDownListener.java new file mode 100644 index 0000000..db1e8bf --- /dev/null +++ b/01src/XiaoMiNotes/MyApplication/app/src/main/java/net/micode/notes/timer/CountDownListener.java @@ -0,0 +1,5 @@ +package net.micode.notes.timer; + +public interface CountDownListener {//监听器 + public void onFinishCountDown();//是否完成倒计时 +} \ No newline at end of file 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/java/net/micode/notes/ui/NotesListActivity.java b/01src/XiaoMiNotes/MyApplication/app/src/main/java/net/micode/notes/ui/NotesListActivity.java index e843aec..e559d8b 100644 --- a/01src/XiaoMiNotes/MyApplication/app/src/main/java/net/micode/notes/ui/NotesListActivity.java +++ b/01src/XiaoMiNotes/MyApplication/app/src/main/java/net/micode/notes/ui/NotesListActivity.java @@ -331,6 +331,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt public void onClick(DialogInterface dialog, int which) { batchDelete(); + //Notesback(); } }); builder.setNegativeButton(android.R.string.cancel, null); @@ -505,6 +506,32 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt } }.execute(); } + private void Notesback(){ + new AsyncTask>() { + protected HashSet doInBackground(Void... unused) { + HashSet widgets = mNotesListAdapter.getSelectedWidget(); + + if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter + .getSelectedItemIds(), Notes.ID_ROOT_FOLDER)) { + Log.e(TAG, "Move notes to trash folder error, should not happens"); + } + return widgets; + } + @Override + protected void onPostExecute(HashSet widgets) { + if (widgets != null) { + for (AppWidgetAttribute widget : widgets) { + if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID + && widget.widgetType != Notes.TYPE_WIDGET_INVALIDE) { + updateWidget(widget.widgetId, widget.widgetType); + } + } + } + mModeCallBack.finishActionMode(); + } + }.execute(); + //DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter.getSelectedItemIds(),Notes.ID_ROOT_FOLDER); + } private void deleteFolder(long folderId) { if (folderId == Notes.ID_ROOT_FOLDER) { @@ -579,6 +606,74 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); } + + private void showTimeGet() {//获取倒计时时间 + final AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("请输入倒计时时间");//标题 + View view = LayoutInflater.from(this).inflate(R.layout.get_time, null); + final EditText hour = (EditText) view.findViewById(R.id.hour); + final EditText min = (EditText) view.findViewById(R.id.min); + final EditText sec = (EditText) view.findViewById(R.id.sec); + showSoftInput();//打开键盘 + builder.setPositiveButton(android.R.string.ok, null);// 确认(逻辑在下方) + builder.setNegativeButton(android.R.string.cancel, null); + final Dialog dialog = builder.setView(view).show();//显示 + + final Button positive = (Button) dialog.findViewById(android.R.id.button1); + positive.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(v.getContext(), net.micode.notes.timer.CountDown.class); + long h=Long.parseLong(hour.getText().toString()); + intent.putExtra("hour",h); + long m=Long.parseLong(min.getText().toString()); + intent.putExtra("min",m); + long s=Long.parseLong(sec.getText().toString()); + intent.putExtra("sec",s); + Toast.makeText(v.getContext(), "正在跳转", Toast.LENGTH_SHORT).show(); + startActivity(intent);//跳转页面到倒计时 + + dialog.dismiss(); + } + }); + + + //后面全是监听器 + if (TextUtils.isEmpty(hour.getText())) { + positive.setEnabled(false); + } + hour.addTextChangedListener(new TextWatcher() {//监听器 + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + public void onTextChanged(CharSequence s, int start, int before, int count) { + if (!TextUtils.isEmpty(hour.getText())&&!TextUtils.isEmpty(min.getText()) + &&!TextUtils.isEmpty(sec.getText())) + {positive.setEnabled(true);} + else{positive.setEnabled(false);} + } + public void afterTextChanged(Editable s) {} + }); + min.addTextChangedListener(new TextWatcher() {//监听器 + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + public void onTextChanged(CharSequence s, int start, int before, int count) { + if (!TextUtils.isEmpty(hour.getText())&&!TextUtils.isEmpty(min.getText()) + &&!TextUtils.isEmpty(sec.getText())) + {positive.setEnabled(true);} + else{positive.setEnabled(false);} + } + public void afterTextChanged(Editable s) {} + }); + sec.addTextChangedListener(new TextWatcher() {//监听器 + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + public void onTextChanged(CharSequence s, int start, int before, int count) { + if (!TextUtils.isEmpty(hour.getText())&&!TextUtils.isEmpty(min.getText()) + &&!TextUtils.isEmpty(sec.getText())) + {positive.setEnabled(true);} + else{positive.setEnabled(false);} + } + public void afterTextChanged(Editable s) {} + }); + } + private void showCreateOrModifyFolderDialog(final boolean create) { final AlertDialog.Builder builder = new AlertDialog.Builder(this); View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null); @@ -812,6 +907,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt case R.id.menu_search: onSearchRequested(); break; + case R.id.menu_countdown: + showTimeGet(); + break; default: break; } diff --git a/01src/XiaoMiNotes/MyApplication/app/src/main/res/layout/activity_count_down.xml b/01src/XiaoMiNotes/MyApplication/app/src/main/res/layout/activity_count_down.xml new file mode 100644 index 0000000..a0cb92d --- /dev/null +++ b/01src/XiaoMiNotes/MyApplication/app/src/main/res/layout/activity_count_down.xml @@ -0,0 +1,63 @@ + + + + + + +