diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 26d3352..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index a818314..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index ef17f64..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/.idea/deploymentTargetSelector.xml b/src/.idea/deploymentTargetSelector.xml
index e03b986..1982524 100644
--- a/src/.idea/deploymentTargetSelector.xml
+++ b/src/.idea/deploymentTargetSelector.xml
@@ -4,9 +4,14 @@
-
-
-
+
+
+
+
+
+
+
+
diff --git a/src/.idea/misc.xml b/src/.idea/misc.xml
index b2c751a..74dd639 100644
--- a/src/.idea/misc.xml
+++ b/src/.idea/misc.xml
@@ -1,3 +1,4 @@
+
diff --git a/src/app/src/main/AndroidManifest.xml b/src/app/src/main/AndroidManifest.xml
index 8d2fd65..b002b6e 100644
--- a/src/app/src/main/AndroidManifest.xml
+++ b/src/app/src/main/AndroidManifest.xml
@@ -24,7 +24,6 @@
tools:targetApi="31">
0) {
Intent intent = new Intent(this, AlarmReceiver.class);
intent.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mWorkingNote.getNoteId()));
- PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
+ PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT // 如果已有 PendingIntent,就更新它的 Intent
+ | PendingIntent.FLAG_IMMUTABLE );
AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE));
showAlertHeader();
if(!set) {
@@ -769,6 +814,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
mEditTextList.setVisibility(View.GONE);
mNoteEditor.setVisibility(View.VISIBLE);
+ convertToImage();
}
}
@@ -860,4 +906,182 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private void showToast(int resId, int duration) {
Toast.makeText(this, resId, duration).show();
}
+ //获取文件的real path
+ public String getPath(final Context context, final Uri uri) {
+
+ final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
+
+ // DocumentProvider
+ if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
+ // ExternalStorageProvider
+// if (isExternalStorageDocument(uri)) {
+// final String docId = DocumentsContract.getDocumentId(uri);
+// final String[] split = docId.split(":");
+// final String type = split[0];
+//
+// if ("primary".equalsIgnoreCase(type)) {
+// return Environment.getExternalStorageDirectory() + "/" + split[1];
+// }
+// }
+// // DownloadsProvider
+// else if (isDownloadsDocument(uri)) {
+// final String id = DocumentsContract.getDocumentId(uri);
+// final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
+// return getDataColumn(context, contentUri, null, null);
+// }
+ // MediaProvider
+// else
+ if (isMediaDocument(uri)) {
+ final String docId = DocumentsContract.getDocumentId(uri);
+ final String[] split = docId.split(":");
+ final String type = split[0];
+
+ Uri contentUri = null;
+ if ("image".equals(type)) {
+ contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
+ }
+
+ final String selection = "_id=?";
+ final String[] selectionArgs = new String[]{split[1]};
+
+ return getDataColumn(context, contentUri, selection, selectionArgs);
+ }
+ }
+ // Media
+ else if ("content".equalsIgnoreCase(uri.getScheme())) {
+ return getDataColumn(context, uri, null, null);
+ }
+ // File
+ else if ("file".equalsIgnoreCase(uri.getScheme())) {
+ return uri.getPath();
+ }
+ return null;
+ }
+ 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.在路径的起始位置插入图片
+ }
+ }
+ }
+ }
+ }
+
+ //获取数据列_获取此 Uri 的数据列的值。这对MediaStore Uris 和其他基于文件的 ContentProvider。
+ public String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
+
+ Cursor cursor = null;
+ final String column = "_data";
+ final String[] projection = {column};
+
+ try {
+ cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
+ if (cursor != null && cursor.moveToFirst()) {
+ final int column_index = cursor.getColumnIndexOrThrow(column);
+ return cursor.getString(column_index);
+ }
+ } finally {
+ if (cursor != null)
+ cursor.close();
+ }
+ return null;
+ }
+
+
+ //是否为外部存储文件
+// public boolean isExternalStorageDocument(Uri uri) {
+// return "com.android.externalstorage.documents".equals(uri.getAuthority());
+// }
+//
+// //是否为下载文件
+// public boolean isDownloadsDocument(Uri uri) {
+// return "com.android.providers.downloads.documents".equals(uri.getAuthority());
+// }
+
+ //是否为媒体文件
+ public boolean isMediaDocument(Uri uri) {
+ return "com.android.providers.media.documents".equals(uri.getAuthority());
+ }
+
+ 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;
+ }
+ }
+ //
}
diff --git a/src/app/src/main/res/layout/note_edit.xml b/src/app/src/main/res/layout/note_edit.xml
index 10b2aa7..6c6fa36 100644
--- a/src/app/src/main/res/layout/note_edit.xml
+++ b/src/app/src/main/res/layout/note_edit.xml
@@ -115,7 +115,14 @@
android:background="@drawable/bg_color_btn_mask" />
-
+
+
%1$s has been set as the sync account
New note background color random
+
Delete
Call notes
Input name
diff --git a/src/gradle/libs.versions.toml b/src/gradle/libs.versions.toml
index 2019aea..72f49c6 100644
--- a/src/gradle/libs.versions.toml
+++ b/src/gradle/libs.versions.toml
@@ -1,12 +1,12 @@
[versions]
-agp = "8.9.1"
+agp = "8.8.0"
junit = "4.13.2"
-junitVersion = "1.2.1"
-espressoCore = "3.6.1"
-appcompat = "1.7.0"
-material = "1.12.0"
-activity = "1.10.1"
-constraintlayout = "2.2.1"
+junitVersion = "1.1.5"
+espressoCore = "3.5.1"
+appcompat = "1.6.1"
+material = "1.10.0"
+activity = "1.8.0"
+constraintlayout = "2.1.4"
[libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" }
diff --git a/src/gradle/wrapper/gradle-wrapper.properties b/src/gradle/wrapper/gradle-wrapper.properties
index 9e6f951..8adfe46 100644
--- a/src/gradle/wrapper/gradle-wrapper.properties
+++ b/src/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Thu Apr 10 14:11:20 CST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists