From 5434ed27c40cbd965fdb3d8747730a1f0da74a36 Mon Sep 17 00:00:00 2001 From: zkp <3138559151@qq.com> Date: Wed, 17 Jan 2024 15:56:25 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E6=A0=8F=E4=B8=AD=E6=96=87=E6=9C=AC=E6=92=A4=E5=9B=9E=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/micode/notes/ui/NoteEditActivity.java | 75 +++++++++++++++++++ src/main/res/menu/note_edit.xml | 4 + src/main/res/values/strings.xml | 3 + 3 files changed, 82 insertions(+) diff --git a/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/src/main/java/net/micode/notes/ui/NoteEditActivity.java index 6615af7..9d32456 100644 --- a/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -35,6 +35,8 @@ import android.text.SpannableString; import android.text.TextUtils; import android.text.format.DateUtils; import android.text.style.BackgroundColorSpan; +import android.text.Editable; +import android.text.TextWatcher; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; @@ -70,6 +72,7 @@ import java.util.HashSet; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.Vector; public class NoteEditActivity extends Activity //NOTE: extends--单继承,但可多重继承 @zhoukexing 2023/12/17 23:29 @@ -124,6 +127,8 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 private static final String TAG = "NoteEditActivity"; + private static int MAX_REVOKE_TIMES = 10; + private HeadViewHolder mNoteHeaderHolder; private View mHeadViewPanel; @@ -153,6 +158,10 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 private String mUserQuery; private Pattern mPattern; + // 存储改变的数据 + private Vector mHistory = new Vector(MAX_REVOKE_TIMES); + private boolean mIsRvoke; + /*--- 以上是此类中的数据区,以下是方法区 ---*/ /** @@ -428,6 +437,23 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color); mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this); mNoteEditor = (EditText) findViewById(R.id.note_edit_view); + mNoteEditor.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) + { + } + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + @Override + public void afterTextChanged(Editable s) {//储存文本更改的编辑 + if(!mIsRvoke) { + saveHistory(); + }else { + mIsRvoke = false; + } + } + }); mNoteEditorPanel = findViewById(R.id.sv_note_edit); mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector); for (int id : sBgSelectorBtnsMap.keySet()) { @@ -451,6 +477,7 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE; } mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list); + } @Override @@ -612,6 +639,8 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 setReminder(); } else if (itemId == R.id.menu_delete_remind) { mWorkingNote.setAlertDate(0, false); + } else if (itemId == R.id.menu_revoke) { + doRevoke(); } return true; } @@ -1002,4 +1031,50 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 private void showToast(int resId, int duration) { Toast.makeText(this, resId, duration).show(); } + + /** + * @method saveHistory + * @description 将每次编辑的内容保存在栈中 + * @date: 2024-01-08 8:56 + * @author: 郑鲲鹏 + * @return void + */ + private void saveHistory() { + SpannableString text = new SpannableString(mNoteEditor.getText()); + if (mHistory.size() >= MAX_REVOKE_TIMES) { + mHistory.removeElementAt(0); + mHistory.add(text); + } + else { + mHistory.add(text); + } + } + + /** + * @method doRevoke + * @description 该方法实现撤回的操作 + * @date: 2024-01-08 15:56 + * @author: 郑鲲鹏 + * @return void + */ + private void doRevoke(){ + AlertDialog.Builder dialog = new AlertDialog.Builder(this); + dialog.setTitle(R.string.tips_of_revoke); + dialog.setCancelable(true); + dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + } + }); + mIsRvoke = true; + if(mHistory.size() <= 1){ + dialog.setMessage(R.string.have_not_input_anything); + dialog.show(); + } + else { + mNoteEditor.setText((CharSequence)mHistory.elementAt(mHistory.size() - 2)); + mHistory.removeElementAt(mHistory.size() - 1); + } + } + } //NOTE: 这一整个文件就是这一个类 @zhoukexing 2023/12/17 23:41 diff --git a/src/main/res/menu/note_edit.xml b/src/main/res/menu/note_edit.xml index 494fba6..716e54e 100644 --- a/src/main/res/menu/note_edit.xml +++ b/src/main/res/menu/note_edit.xml @@ -49,4 +49,8 @@ + + \ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 9de6ba8..6041f27 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -66,6 +66,9 @@ Share Send to home Remind me + Revoke text + Tip + You haven not input anything Delete reminder Select folder Parent folder From 015d3e32a95e8c842803ade8f007428a6db12349 Mon Sep 17 00:00:00 2001 From: zkp <3138559151@qq.com> Date: Wed, 17 Jan 2024 23:46:52 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E7=9A=84=E6=88=AA=E5=9B=BE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/AndroidManifest.xml | 3 ++ .../net/micode/notes/ui/NoteEditActivity.java | 47 ++++++++++++++++++- src/main/res/menu/note_edit.xml | 4 ++ src/main/res/values/strings.xml | 3 ++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 6219318..77adafc 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -30,6 +30,9 @@ + + + + + \ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 6041f27..9180d68 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -69,6 +69,7 @@ Revoke text Tip You haven not input anything + Screenshot Delete reminder Select folder Parent folder @@ -84,6 +85,8 @@ The note is not exist Sorry, can not set clock on empty note Sorry, can not send and empty note to home + "Successfully saved the screenshot + Failed to save screenshot Export successful Export fail Export text file (%1$s) to SD (%2$s) directory From 7bfe8578245acdbd966edac8f031ba2ec1f6aee5 Mon Sep 17 00:00:00 2001 From: zkp <3138559151@qq.com> Date: Thu, 18 Jan 2024 08:52:14 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E6=92=A4=E5=9B=9E=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/net/micode/notes/ui/NoteEditActivity.java | 2 +- src/main/res/values/strings.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/src/main/java/net/micode/notes/ui/NoteEditActivity.java index 5667bdb..041645d 100644 --- a/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -1096,7 +1096,7 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 }); mIsRvoke = true; if(mHistory.size() <= 1){ - dialog.setMessage(R.string.have_not_input_anything); + dialog.setMessage(R.string.cannot_revoke_anything); dialog.show(); } else { diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 3c1490d..4306ebb 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -70,7 +70,7 @@ Remind me Revoke text Tip - You haven not input anything + You cannot revoke anything Screenshot Delete reminder Select folder