From 1039b34bb62559483937786d00291eafe63672b1 Mon Sep 17 00:00:00 2001 From: xy0dls <2153766822@qq.com> Date: Wed, 23 Apr 2025 23:13:51 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MiNote/.idea/vcs.xml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 MiNote/.idea/vcs.xml diff --git a/MiNote/.idea/vcs.xml b/MiNote/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/MiNote/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From 041f2c127b38f5f2526b2a85b5d6424a1db0ad22 Mon Sep 17 00:00:00 2001 From: xy0dls <2153766822@qq.com> Date: Wed, 23 Apr 2025 23:19:43 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E7=9A=84xml=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MiNote/app/src/main/res/layout/note_edit.xml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MiNote/app/src/main/res/layout/note_edit.xml b/MiNote/app/src/main/res/layout/note_edit.xml index 10b2aa7..2b96193 100644 --- a/MiNote/app/src/main/res/layout/note_edit.xml +++ b/MiNote/app/src/main/res/layout/note_edit.xml @@ -57,10 +57,14 @@ android:textAppearance="@style/TextAppearanceSecondaryItem" /> + android:layout_marginLeft="7dp" + android:layout_marginTop="600dp" + android:layout_marginBottom="7dp" + android:src="@android:drawable/ic_menu_gallery" /> + Date: Wed, 23 Apr 2025 23:22:50 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E9=87=8D=E5=86=99onCreate()=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/micode/notes/ui/NoteEditActivity.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java index 862883b..fe746ae 100644 --- a/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -47,6 +47,7 @@ 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; @@ -74,6 +75,7 @@ import java.util.regex.Pattern; public class NoteEditActivity extends Activity implements OnClickListener, NoteSettingChangedListener, OnTextViewChangeListener { + private static final int PHOTO_REQUEST = 1; private class HeadViewHolder { public TextView tvModified; @@ -159,8 +161,26 @@ public class NoteEditActivity extends Activity implements OnClickListener, return; } initResources(); + + //根据id获取添加图片按钮 + final ImageButton add_img_btn = (ImageButton) findViewById(R.id.add_img_btn); + //为点击图片按钮设置监听器 + add_img_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Log.d(TAG, "onClick: click add image button"); + //ACTION_GET_CONTENT: 允许用户选择特殊种类的数据,并返回(特殊种类的数据:照一张相片或录一段音) + Intent loadImage = new Intent(Intent.ACTION_GET_CONTENT); + //Category属性用于指定当前动作(Action)被执行的环境. + //CATEGORY_OPENABLE; 用来指示一个ACTION_GET_CONTENT的intent + loadImage.addCategory(Intent.CATEGORY_OPENABLE); + loadImage.setType("image/*"); + startActivityForResult(loadImage, PHOTO_REQUEST); + } + }); } + /** * 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 From 490f56b08ff790fce13ea2a23459a08545286b19 Mon Sep 17 00:00:00 2001 From: xy0dls <2153766822@qq.com> Date: Wed, 23 Apr 2025 23:24:43 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0convertToImage()=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/micode/notes/ui/NoteEditActivity.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java index fe746ae..b1d6dd8 100644 --- a/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -27,14 +27,18 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.graphics.Paint; import android.os.Bundle; import android.preference.PreferenceManager; +import android.text.Editable; import android.text.Spannable; import android.text.SpannableString; import android.text.TextUtils; import android.text.format.DateUtils; import android.text.style.BackgroundColorSpan; +import android.text.style.ImageSpan; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; @@ -880,4 +884,45 @@ public class NoteEditActivity extends Activity implements OnClickListener, private void showToast(int resId, int duration) { Toast.makeText(this, resId, duration).show(); } + //路径字符串格式 转换为 图片image格式 + private void convertToImage() { + NoteEditText noteEditText = (NoteEditText) findViewById(R.id.note_edit_view); //获取当前的edit + Editable editable = noteEditText.getText();//1.获取text + String noteText = editable.toString(); //2.将note内容转换为字符串 + int length = editable.length(); //内容的长度 + //3.截取img片段 [local]+uri+[local],提取uri + for(int i = 0; i < length; i++) { + for(int j = i; j < length; j++) { + String img_fragment = noteText.substring(i, j+1); //img_fragment:关于图片路径的片段 + if(img_fragment.length() > 15 && img_fragment.endsWith("[/local]") && img_fragment.startsWith("[local]")){ + int limit = 7; //[local]为7个字符 + //[local][/local]共15个字符,剩下的为真正的path长度 + int len = img_fragment.length()-15; + //从[local]之后的len个字符就是path + String path = img_fragment.substring(limit,limit+len);//获取到了图片路径 + Bitmap bitmap = null; + Log.d(TAG, "图片的路径是:"+path); + try { + bitmap = BitmapFactory.decodeFile(path);//将图片路径解码为图片格式 + } catch (Exception e) { + e.printStackTrace(); + } + if(bitmap!=null){ //若图片存在 + Log.d(TAG, "图片不为null"); + ImageSpan imageSpan = new ImageSpan(NoteEditActivity.this, bitmap); + //4.创建一个SpannableString对象,以便插入用ImageSpan对象封装的图像 + String ss = "[local]" + path + "[/local]"; + SpannableString spannableString = new SpannableString(ss); + //5.将指定的标记对象附加到文本的开始...结束范围 + spannableString.setSpan(imageSpan, 0, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + Log.d(TAG, "Create spannable string success!"); + Editable edit_text = noteEditText.getEditableText(); + edit_text.delete(i,i+len+15); //6.删掉图片路径的文字 + edit_text.insert(i, spannableString); //7.在路径的起始位置插入图片 + } + } + } + } + } + } From 69c85a92cd716fc48f80650f8af3e5ff775696ab Mon Sep 17 00:00:00 2001 From: xy0dls <2153766822@qq.com> Date: Wed, 23 Apr 2025 23:35:44 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0onActivityResult()?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/micode/notes/model/WorkingNote.java | 2 +- .../net/micode/notes/ui/NoteEditActivity.java | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/MiNote/app/src/main/java/net/micode/notes/model/WorkingNote.java b/MiNote/app/src/main/java/net/micode/notes/model/WorkingNote.java index be081e4..a1a2455 100644 --- a/MiNote/app/src/main/java/net/micode/notes/model/WorkingNote.java +++ b/MiNote/app/src/main/java/net/micode/notes/model/WorkingNote.java @@ -38,7 +38,7 @@ public class WorkingNote { // Note Id private long mNoteId; // Note content - private String mContent; + public String mContent; // Note mode private int mMode; diff --git a/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java index b1d6dd8..6966d10 100644 --- a/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -22,7 +22,9 @@ import android.app.AlertDialog; import android.app.PendingIntent; import android.app.SearchManager; import android.appwidget.AppWidgetManager; +import android.content.ContentResolver; import android.content.ContentUris; +import android.content.ContentValues; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -30,6 +32,7 @@ import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Paint; +import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; import android.text.Editable; @@ -70,6 +73,7 @@ import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener; import net.micode.notes.widget.NoteWidgetProvider_2x; import net.micode.notes.widget.NoteWidgetProvider_4x; +import java.io.FileNotFoundException; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -924,5 +928,57 @@ public class NoteEditActivity extends Activity implements OnClickListener, } } } + //重写onActivityResult()来处理返回的数据 + protected void onActivityResult(int requestCode, int resultCode, Intent intent) { + super.onActivityResult(requestCode, resultCode, intent); + ContentResolver resolver = getContentResolver(); + switch (requestCode) { + case PHOTO_REQUEST: + Uri originalUri = intent.getData(); //1.获得图片的真实路径 + Bitmap bitmap = null; + try { + bitmap = BitmapFactory.decodeStream(resolver.openInputStream(originalUri));//2.解码图片 + } catch (FileNotFoundException e) { + Log.d(TAG, "onActivityResult: get file_exception"); + e.printStackTrace(); + } + + if(bitmap != null){ + //3.根据Bitmap对象创建ImageSpan对象 + Log.d(TAG, "onActivityResult: bitmap is not null"); + ImageSpan imageSpan = new ImageSpan(NoteEditActivity.this, bitmap); + String path = getPath(this,originalUri); + //4.使用[local][/local]将path括起来,用于之后方便识别图片路径在note中的位置 + String img_fragment= "[local]" + path + "[/local]"; + //创建一个SpannableString对象,以便插入用ImageSpan对象封装的图像 + SpannableString spannableString = new SpannableString(img_fragment); + spannableString.setSpan(imageSpan, 0, img_fragment.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + //5.将选择的图片追加到EditText中光标所在位置 + NoteEditText e = (NoteEditText) findViewById(R.id.note_edit_view); + int index = e.getSelectionStart(); //获取光标所在位置 + Log.d(TAG, "Index是: " + index); + Editable edit_text = e.getEditableText(); + edit_text.insert(index, spannableString); //将图片插入到光标所在位置 + + mWorkingNote.mContent = e.getText().toString(); + //6.把改动提交到数据库中,两个数据库表都要改的 + ContentResolver contentResolver = getContentResolver(); + ContentValues contentValues = new ContentValues(); + final long id = mWorkingNote.getNoteId(); + contentValues.put("snippet",mWorkingNote.mContent); + contentResolver.update(Uri.parse("content://micode_notes/note"), contentValues,"_id=?",new String[]{""+id}); + ContentValues contentValues1 = new ContentValues(); + contentValues1.put("content",mWorkingNote.mContent); + contentResolver.update(Uri.parse("content://micode_notes/data"), contentValues1,"mime_type=? and note_id=?", new String[]{"vnd.android.cursor.item/text_note",""+id}); + + }else{ + Toast.makeText(NoteEditActivity.this, "获取图片失败", Toast.LENGTH_SHORT).show(); + } + break; + default: + break; + } + } + } From 4880528df8f0f87dc95191cfaae5c66c2a454d7e Mon Sep 17 00:00:00 2001 From: xy0dls <2153766822@qq.com> Date: Wed, 23 Apr 2025 23:37:40 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0getPath()=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/net/micode/notes/ui/NoteEditActivity.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java index 6966d10..5bdc98e 100644 --- a/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -980,5 +980,9 @@ public class NoteEditActivity extends Activity implements OnClickListener, } } + private String getPath(NoteEditActivity noteEditActivity, Uri originalUri) { + return ""; + } + }