diff --git a/src/Notes-master/res/drawable/category_bg.xml b/src/Notes-master/res/drawable/category_bg.xml
new file mode 100644
index 0000000..f9419de
--- /dev/null
+++ b/src/Notes-master/res/drawable/category_bg.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/drawable/ic_launcher_background.xml b/src/Notes-master/res/drawable/ic_launcher_background.xml
new file mode 100644
index 0000000..07d5da9
--- /dev/null
+++ b/src/Notes-master/res/drawable/ic_launcher_background.xml
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Notes-master/res/drawable/ic_launcher_foreground.xml b/src/Notes-master/res/drawable/ic_launcher_foreground.xml
new file mode 100644
index 0000000..2b068d1
--- /dev/null
+++ b/src/Notes-master/res/drawable/ic_launcher_foreground.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/drawable/mi_logo_background.xml b/src/Notes-master/res/drawable/mi_logo_background.xml
new file mode 100644
index 0000000..80c49d0
--- /dev/null
+++ b/src/Notes-master/res/drawable/mi_logo_background.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/layout/activity_friend_management.xml b/src/Notes-master/res/layout/activity_friend_management.xml
new file mode 100644
index 0000000..1a97657
--- /dev/null
+++ b/src/Notes-master/res/layout/activity_friend_management.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/layout/activity_friend_note_edit.xml b/src/Notes-master/res/layout/activity_friend_note_edit.xml
new file mode 100644
index 0000000..6dcf460
--- /dev/null
+++ b/src/Notes-master/res/layout/activity_friend_note_edit.xml
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/layout/activity_friend_note_list.xml b/src/Notes-master/res/layout/activity_friend_note_list.xml
new file mode 100644
index 0000000..39a42f7
--- /dev/null
+++ b/src/Notes-master/res/layout/activity_friend_note_list.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/layout/activity_login.xml b/src/Notes-master/res/layout/activity_login.xml
new file mode 100644
index 0000000..69a0139
--- /dev/null
+++ b/src/Notes-master/res/layout/activity_login.xml
@@ -0,0 +1,147 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/layout/activity_main.xml b/src/Notes-master/res/layout/activity_main.xml
new file mode 100644
index 0000000..86a5d97
--- /dev/null
+++ b/src/Notes-master/res/layout/activity_main.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/layout/activity_splash.xml b/src/Notes-master/res/layout/activity_splash.xml
new file mode 100644
index 0000000..3e060a4
--- /dev/null
+++ b/src/Notes-master/res/layout/activity_splash.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/layout/chat_activity.xml b/src/Notes-master/res/layout/chat_activity.xml
new file mode 100644
index 0000000..33e4530
--- /dev/null
+++ b/src/Notes-master/res/layout/chat_activity.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Notes-master/res/layout/chat_message_received_item.xml b/src/Notes-master/res/layout/chat_message_received_item.xml
new file mode 100644
index 0000000..9dd9aa8
--- /dev/null
+++ b/src/Notes-master/res/layout/chat_message_received_item.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Notes-master/res/layout/chat_message_received_note_item.xml b/src/Notes-master/res/layout/chat_message_received_note_item.xml
new file mode 100644
index 0000000..df3d62f
--- /dev/null
+++ b/src/Notes-master/res/layout/chat_message_received_note_item.xml
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Notes-master/res/layout/chat_message_sent_item.xml b/src/Notes-master/res/layout/chat_message_sent_item.xml
new file mode 100644
index 0000000..b9038fb
--- /dev/null
+++ b/src/Notes-master/res/layout/chat_message_sent_item.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Notes-master/res/layout/chat_message_sent_note_item.xml b/src/Notes-master/res/layout/chat_message_sent_note_item.xml
new file mode 100644
index 0000000..3bb0c6f
--- /dev/null
+++ b/src/Notes-master/res/layout/chat_message_sent_note_item.xml
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Notes-master/res/layout/dialog_change_password.xml b/src/Notes-master/res/layout/dialog_change_password.xml
new file mode 100644
index 0000000..c8e703b
--- /dev/null
+++ b/src/Notes-master/res/layout/dialog_change_password.xml
@@ -0,0 +1,150 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/layout/dialog_register.xml b/src/Notes-master/res/layout/dialog_register.xml
new file mode 100644
index 0000000..a4d2243
--- /dev/null
+++ b/src/Notes-master/res/layout/dialog_register.xml
@@ -0,0 +1,124 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/layout/item_friend.xml b/src/Notes-master/res/layout/item_friend.xml
new file mode 100644
index 0000000..bfd61f0
--- /dev/null
+++ b/src/Notes-master/res/layout/item_friend.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/layout/password_input_dialog.xml b/src/Notes-master/res/layout/password_input_dialog.xml
new file mode 100644
index 0000000..826ab01
--- /dev/null
+++ b/src/Notes-master/res/layout/password_input_dialog.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/layout/password_setting_dialog.xml b/src/Notes-master/res/layout/password_setting_dialog.xml
new file mode 100644
index 0000000..ebc749f
--- /dev/null
+++ b/src/Notes-master/res/layout/password_setting_dialog.xml
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/mipmap-anydpi/ic_launcher.xml b/src/Notes-master/res/mipmap-anydpi/ic_launcher.xml
new file mode 100644
index 0000000..6f3b755
--- /dev/null
+++ b/src/Notes-master/res/mipmap-anydpi/ic_launcher.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/mipmap-anydpi/ic_launcher_round.xml b/src/Notes-master/res/mipmap-anydpi/ic_launcher_round.xml
new file mode 100644
index 0000000..6f3b755
--- /dev/null
+++ b/src/Notes-master/res/mipmap-anydpi/ic_launcher_round.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/mipmap-hdpi/ic_launcher.webp b/src/Notes-master/res/mipmap-hdpi/ic_launcher.webp
new file mode 100644
index 0000000..c209e78
Binary files /dev/null and b/src/Notes-master/res/mipmap-hdpi/ic_launcher.webp differ
diff --git a/src/Notes-master/res/mipmap-hdpi/ic_launcher_round.webp b/src/Notes-master/res/mipmap-hdpi/ic_launcher_round.webp
new file mode 100644
index 0000000..b2dfe3d
Binary files /dev/null and b/src/Notes-master/res/mipmap-hdpi/ic_launcher_round.webp differ
diff --git a/src/Notes-master/res/mipmap-mdpi/ic_launcher.webp b/src/Notes-master/res/mipmap-mdpi/ic_launcher.webp
new file mode 100644
index 0000000..4f0f1d6
Binary files /dev/null and b/src/Notes-master/res/mipmap-mdpi/ic_launcher.webp differ
diff --git a/src/Notes-master/res/mipmap-mdpi/ic_launcher_round.webp b/src/Notes-master/res/mipmap-mdpi/ic_launcher_round.webp
new file mode 100644
index 0000000..62b611d
Binary files /dev/null and b/src/Notes-master/res/mipmap-mdpi/ic_launcher_round.webp differ
diff --git a/src/Notes-master/res/mipmap-xhdpi/ic_launcher.webp b/src/Notes-master/res/mipmap-xhdpi/ic_launcher.webp
new file mode 100644
index 0000000..948a307
Binary files /dev/null and b/src/Notes-master/res/mipmap-xhdpi/ic_launcher.webp differ
diff --git a/src/Notes-master/res/mipmap-xhdpi/ic_launcher_round.webp b/src/Notes-master/res/mipmap-xhdpi/ic_launcher_round.webp
new file mode 100644
index 0000000..1b9a695
Binary files /dev/null and b/src/Notes-master/res/mipmap-xhdpi/ic_launcher_round.webp differ
diff --git a/src/Notes-master/res/mipmap-xxhdpi/ic_launcher.webp b/src/Notes-master/res/mipmap-xxhdpi/ic_launcher.webp
new file mode 100644
index 0000000..28d4b77
Binary files /dev/null and b/src/Notes-master/res/mipmap-xxhdpi/ic_launcher.webp differ
diff --git a/src/Notes-master/res/mipmap-xxhdpi/ic_launcher_round.webp b/src/Notes-master/res/mipmap-xxhdpi/ic_launcher_round.webp
new file mode 100644
index 0000000..9287f50
Binary files /dev/null and b/src/Notes-master/res/mipmap-xxhdpi/ic_launcher_round.webp differ
diff --git a/src/Notes-master/res/mipmap-xxxhdpi/ic_launcher.webp b/src/Notes-master/res/mipmap-xxxhdpi/ic_launcher.webp
new file mode 100644
index 0000000..aa7d642
Binary files /dev/null and b/src/Notes-master/res/mipmap-xxxhdpi/ic_launcher.webp differ
diff --git a/src/Notes-master/res/mipmap-xxxhdpi/ic_launcher_round.webp b/src/Notes-master/res/mipmap-xxxhdpi/ic_launcher_round.webp
new file mode 100644
index 0000000..9126ae3
Binary files /dev/null and b/src/Notes-master/res/mipmap-xxxhdpi/ic_launcher_round.webp differ
diff --git a/src/Notes-master/res/values-night/themes.xml b/src/Notes-master/res/values-night/themes.xml
new file mode 100644
index 0000000..d2c68d1
--- /dev/null
+++ b/src/Notes-master/res/values-night/themes.xml
@@ -0,0 +1,7 @@
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/values/themes.xml b/src/Notes-master/res/values/themes.xml
new file mode 100644
index 0000000..7c616ff
--- /dev/null
+++ b/src/Notes-master/res/values/themes.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/xml/backup_rules.xml b/src/Notes-master/res/xml/backup_rules.xml
new file mode 100644
index 0000000..4df9255
--- /dev/null
+++ b/src/Notes-master/res/xml/backup_rules.xml
@@ -0,0 +1,13 @@
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/res/xml/data_extraction_rules.xml b/src/Notes-master/res/xml/data_extraction_rules.xml
new file mode 100644
index 0000000..9ee9997
--- /dev/null
+++ b/src/Notes-master/res/xml/data_extraction_rules.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master/src/net/micode/notes/data/Messages.java b/src/Notes-master/src/net/micode/notes/data/Messages.java
new file mode 100644
index 0000000..d6f2629
--- /dev/null
+++ b/src/Notes-master/src/net/micode/notes/data/Messages.java
@@ -0,0 +1,23 @@
+package net.micode.notes.data;
+
+public class Messages {
+
+ public interface MessageColumns {
+ public static final String ID = "id";
+ public static final String SENDER_ID = "sender_id";
+ public static final String RECEIVER_ID = "receiver_id";
+ public static final String CONTENT = "content";
+ public static final String MESSAGE_TYPE = "message_type";
+ public static final String CREATED_DATE = "created_date";
+ public static final String IS_READ = "is_read";
+ }
+
+ public interface MessageType {
+ public static final int TEXT = 0;
+ public static final int IMAGE = 1;
+ public static final int EMOTION = 2;
+ public static final int NOTE = 3;
+ }
+
+ public static final long ID_INVALID = -1;
+}
diff --git a/src/Notes-master/src/net/micode/notes/data/Users.java b/src/Notes-master/src/net/micode/notes/data/Users.java
new file mode 100644
index 0000000..1ba7b7f
--- /dev/null
+++ b/src/Notes-master/src/net/micode/notes/data/Users.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.micode.notes.data;
+
+public class Users {
+ public interface UserColumns {
+ public static final String ID = "_id";
+ public static final String USERNAME = "username";
+ public static final String PASSWORD = "password";
+ public static final String CREATED_DATE = "created_date";
+ public static final String MODIFIED_DATE = "modified_date";
+ }
+
+ public interface UserConstants {
+ // 可以添加一些用户相关的常量
+ }
+}
\ No newline at end of file
diff --git a/src/Notes-master/src/net/micode/notes/tool/CategoryUtil.java b/src/Notes-master/src/net/micode/notes/tool/CategoryUtil.java
new file mode 100644
index 0000000..54c6bad
--- /dev/null
+++ b/src/Notes-master/src/net/micode/notes/tool/CategoryUtil.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.micode.notes.tool;
+
+import android.text.TextUtils;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+/**
+ * 便签自动分类工具类
+ */
+public class CategoryUtil {
+ // 分类关键词映射表
+ private static final Map CATEGORY_KEYWORDS = new HashMap<>();
+
+ static {
+ // 工作相关
+ addKeywords("工作", "工作", "任务", "项目", "会议", "报告", "加班", "上班", "下班", "同事", "领导", "客户", "公司");
+
+ // 学习相关
+ addKeywords("学习", "学习", "考试", "作业", "复习", "预习", "课程", "老师", "学生", "学校", "教材", "笔记", "知识点");
+
+ // 生活相关
+ addKeywords("生活", "生活", "日常", "购物", "吃饭", "旅游", "电影", "音乐", "健身", "运动", "休息", "睡觉", "起床");
+
+ // 想法相关
+ addKeywords("想法", "想法", "创意", "灵感", "思考", "感悟", "心得", "体会", "观点", "意见", "建议");
+
+ // 待办相关
+ addKeywords("待办", "待办", "todo", "需要", "必须", "应该", "计划", "安排", "准备");
+
+ // 其他默认分类
+ addKeywords("其他", "");
+ }
+
+ // 批量添加关键词
+ private static void addKeywords(String category, String... keywords) {
+ for (String keyword : keywords) {
+ CATEGORY_KEYWORDS.put(keyword, category);
+ }
+ }
+
+ /**
+ * 根据便签内容自动分类
+ * @param content 便签内容
+ * @return 分类结果,不超过3个字符
+ */
+ public static String autoCategorize(String content) {
+ if (TextUtils.isEmpty(content)) {
+ return "其他";
+ }
+
+ // 转为小写进行匹配
+ String lowerContent = content.toLowerCase();
+
+ // 遍历关键词,匹配分类
+ for (Map.Entry entry : CATEGORY_KEYWORDS.entrySet()) {
+ String keyword = entry.getKey();
+ String category = entry.getValue();
+
+ // 跳过空关键词(默认分类)
+ if (TextUtils.isEmpty(keyword)) {
+ continue;
+ }
+
+ // 关键词匹配
+ if (lowerContent.contains(keyword.toLowerCase())) {
+ return category;
+ }
+ }
+
+ // 默认分类
+ return "其他";
+ }
+}
\ No newline at end of file
diff --git a/src/Notes-master/src/net/micode/notes/tool/UserManager.java b/src/Notes-master/src/net/micode/notes/tool/UserManager.java
new file mode 100644
index 0000000..1254109
--- /dev/null
+++ b/src/Notes-master/src/net/micode/notes/tool/UserManager.java
@@ -0,0 +1,192 @@
+/*
+ * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.micode.notes.tool;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.util.Log;
+import net.micode.notes.data.NotesDatabaseHelper;
+import net.micode.notes.data.Users;
+
+/**
+ * 用户管理类,用于保存和获取当前登录用户的信息
+ */
+public class UserManager {
+ private static final String TAG = "UserManager";
+ private static final String PREF_NAME = "user_preferences";
+ private static final String KEY_CURRENT_USER_ID = "current_user_id";
+ private static final String KEY_CURRENT_USERNAME = "current_username";
+
+ private static UserManager sInstance;
+ private SharedPreferences mPrefs;
+ private Context mContext;
+
+ private UserManager(Context context) {
+ mContext = context.getApplicationContext();
+ mPrefs = mContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
+ }
+
+ public static synchronized UserManager getInstance(Context context) {
+ if (sInstance == null) {
+ sInstance = new UserManager(context);
+ }
+ return sInstance;
+ }
+
+ /**
+ * 保存当前登录用户的信息
+ * @param userId 用户ID
+ * @param username 用户名
+ */
+ public void saveCurrentUser(long userId, String username) {
+ SharedPreferences.Editor editor = mPrefs.edit();
+ editor.putLong(KEY_CURRENT_USER_ID, userId);
+ editor.putString(KEY_CURRENT_USERNAME, username);
+ editor.apply();
+ }
+
+ /**
+ * 获取当前登录用户的ID
+ * @return 当前用户ID,未登录返回-1
+ */
+ public long getCurrentUserId() {
+ return mPrefs.getLong(KEY_CURRENT_USER_ID, -1);
+ }
+
+ /**
+ * 获取当前登录用户的用户名
+ * @return 当前用户名,未登录返回null
+ */
+ public String getCurrentUsername() {
+ return mPrefs.getString(KEY_CURRENT_USERNAME, null);
+ }
+
+ /**
+ * 清除当前用户信息,用于退出登录
+ */
+ public void clearCurrentUser() {
+ SharedPreferences.Editor editor = mPrefs.edit();
+ editor.remove(KEY_CURRENT_USER_ID);
+ editor.remove(KEY_CURRENT_USERNAME);
+ editor.apply();
+ }
+
+ /**
+ * 检查是否已登录
+ * @return 是否已登录
+ */
+ public boolean isLoggedIn() {
+ return getCurrentUserId() != -1;
+ }
+
+ /**
+ * 验证用户密码
+ * @param userId 用户ID
+ * @param password 输入的密码
+ * @return 密码是否正确
+ */
+ public boolean validatePassword(long userId, String password) {
+ try {
+ // 直接访问数据库验证密码
+ NotesDatabaseHelper helper = NotesDatabaseHelper.getInstance(mContext);
+ SQLiteDatabase db = helper.getReadableDatabase();
+
+ Cursor cursor = null;
+ try {
+ String selection = Users.UserColumns.ID + " = ? AND " + Users.UserColumns.PASSWORD + " = ?";
+ String[] selectionArgs = {String.valueOf(userId), password};
+
+ cursor = db.query(
+ NotesDatabaseHelper.TABLE.USER,
+ new String[]{Users.UserColumns.ID},
+ selection,
+ selectionArgs,
+ null,
+ null,
+ null
+ );
+
+ return cursor != null && cursor.moveToFirst();
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * 设置当前用户
+ * @param userId 用户ID
+ */
+ public void setCurrentUser(long userId) {
+ try {
+ // 查询用户的用户名
+ NotesDatabaseHelper helper = NotesDatabaseHelper.getInstance(mContext);
+ SQLiteDatabase db = helper.getReadableDatabase();
+
+ Cursor cursor = null;
+ String username = "未知用户";
+ try {
+ String selection = Users.UserColumns.ID + " = ?";
+ String[] selectionArgs = {String.valueOf(userId)};
+
+ cursor = db.query(
+ NotesDatabaseHelper.TABLE.USER,
+ new String[]{Users.UserColumns.USERNAME},
+ selection,
+ selectionArgs,
+ null,
+ null,
+ null
+ );
+
+ if (cursor != null && cursor.moveToFirst()) {
+ username = cursor.getString(0);
+ }
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
+ }
+
+ // 保存当前用户信息
+ SharedPreferences.Editor editor = mPrefs.edit();
+ editor.putLong(KEY_CURRENT_USER_ID, userId);
+ editor.putString(KEY_CURRENT_USERNAME, username);
+ editor.apply();
+ } catch (Exception e) {
+ Log.e(TAG, "Error in setCurrentUser: " + e.getMessage());
+ e.printStackTrace();
+ // 即使发生异常,也确保保存用户ID,避免状态不一致
+ try {
+ SharedPreferences.Editor editor = mPrefs.edit();
+ editor.putLong(KEY_CURRENT_USER_ID, userId);
+ editor.putString(KEY_CURRENT_USERNAME, "未知用户");
+ editor.apply();
+ } catch (Exception innerE) {
+ Log.e(TAG, "Error in emergency save: " + innerE.getMessage());
+ innerE.printStackTrace();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Notes-master/src/net/micode/notes/ui/ChatActivity.java b/src/Notes-master/src/net/micode/notes/ui/ChatActivity.java
new file mode 100644
index 0000000..3f35133
--- /dev/null
+++ b/src/Notes-master/src/net/micode/notes/ui/ChatActivity.java
@@ -0,0 +1,432 @@
+package net.micode.notes.ui;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.text.TextUtils;
+import android.graphics.Color;
+
+import net.micode.notes.R;
+import net.micode.notes.data.Messages;
+import net.micode.notes.data.NotesDatabaseHelper;
+import net.micode.notes.tool.UserManager;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+public class ChatActivity extends Activity {
+ private static final String TAG = "ChatActivity";
+
+ private ListView mChatListView;
+ private EditText mMessageEditText;
+ private Button mSendButton;
+ private ChatAdapter mChatAdapter;
+ private List mMessageList;
+
+ private NotesDatabaseHelper mDbHelper;
+ private SQLiteDatabase mDb;
+ private UserManager mUserManager;
+
+ private long mCurrentUserId;
+ private long mFriendId;
+ private String mFriendUsername;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ try {
+ setContentView(R.layout.chat_activity);
+
+ // 设置ActionBar
+ ActionBar actionBar = getActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ }
+
+ // 获取Intent参数
+ mFriendId = getIntent().getLongExtra("friend_id", -1);
+ mFriendUsername = getIntent().getStringExtra("friend_username");
+
+ if (mFriendId == -1 || mFriendUsername == null) {
+ Toast.makeText(this, "无效的好友信息", Toast.LENGTH_SHORT).show();
+ finish();
+ return;
+ }
+
+ // 设置ActionBar标题为好友用户名
+ if (actionBar != null) {
+ actionBar.setTitle(mFriendUsername);
+ }
+
+ // 初始化数据库
+ mDbHelper = NotesDatabaseHelper.getInstance(this);
+ if (mDbHelper != null) {
+ mDb = mDbHelper.getWritableDatabase();
+ }
+
+ // 初始化UserManager
+ mUserManager = UserManager.getInstance(this);
+ if (mUserManager != null) {
+ mCurrentUserId = mUserManager.getCurrentUserId();
+ }
+
+ // 初始化界面控件
+ mChatListView = findViewById(R.id.chat_list);
+ mMessageEditText = findViewById(R.id.message_edit_text);
+ mSendButton = findViewById(R.id.send_button);
+
+ // 初始化消息列表
+ mMessageList = new ArrayList<>();
+ mChatAdapter = new ChatAdapter(this, mMessageList, mCurrentUserId);
+ mChatListView.setAdapter(mChatAdapter);
+
+ // 设置发送按钮点击事件
+ mSendButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ sendMessage();
+ }
+ });
+
+ // 加载聊天记录
+ loadChatHistory();
+ } catch (Exception e) {
+ Log.e(TAG, "Error in onCreate: " + e.getMessage(), e);
+ Toast.makeText(this, "聊天界面初始化失败", Toast.LENGTH_SHORT).show();
+ finish();
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ try {
+ // 重新获取当前用户ID,确保在账号切换后能使用正确的用户ID
+ if (mUserManager != null) {
+ mCurrentUserId = mUserManager.getCurrentUserId();
+ Log.d(TAG, "Updated current user ID to: " + mCurrentUserId);
+ }
+
+ // 更新适配器的当前用户ID
+ if (mChatAdapter != null) {
+ mChatAdapter.mCurrentUserId = mCurrentUserId;
+ }
+
+ // 重新加载聊天记录
+ loadChatHistory();
+ } catch (Exception e) {
+ Log.e(TAG, "Error in onResume: " + e.getMessage(), e);
+ }
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ // 关闭数据库连接
+ if (mDb != null && mDb.isOpen()) {
+ mDb.close();
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(android.view.MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ // 返回上一级活动
+ finish();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+ /**
+ * 加载聊天记录
+ */
+ private void loadChatHistory() {
+ mMessageList.clear();
+
+ // 查询聊天记录
+ String sql = "SELECT * FROM " + NotesDatabaseHelper.TABLE.MESSAGE + " WHERE " +
+ "(" + Messages.MessageColumns.SENDER_ID + " = ? AND " + Messages.MessageColumns.RECEIVER_ID + " = ?) OR " +
+ "(" + Messages.MessageColumns.SENDER_ID + " = ? AND " + Messages.MessageColumns.RECEIVER_ID + " = ?) " +
+ "ORDER BY " + Messages.MessageColumns.CREATED_DATE + " ASC";
+
+ Cursor cursor = mDb.rawQuery(sql, new String[]{
+ String.valueOf(mCurrentUserId), String.valueOf(mFriendId),
+ String.valueOf(mFriendId), String.valueOf(mCurrentUserId)
+ });
+
+ if (cursor != null) {
+ while (cursor.moveToNext()) {
+ long id = cursor.getLong(cursor.getColumnIndexOrThrow(Messages.MessageColumns.ID));
+ long senderId = cursor.getLong(cursor.getColumnIndexOrThrow(Messages.MessageColumns.SENDER_ID));
+ long receiverId = cursor.getLong(cursor.getColumnIndexOrThrow(Messages.MessageColumns.RECEIVER_ID));
+ String content = cursor.getString(cursor.getColumnIndexOrThrow(Messages.MessageColumns.CONTENT));
+ int messageType = cursor.getInt(cursor.getColumnIndexOrThrow(Messages.MessageColumns.MESSAGE_TYPE));
+ long createdDate = cursor.getLong(cursor.getColumnIndexOrThrow(Messages.MessageColumns.CREATED_DATE));
+ int isRead = cursor.getInt(cursor.getColumnIndexOrThrow(Messages.MessageColumns.IS_READ));
+
+ mMessageList.add(new ChatMessage(id, senderId, receiverId, content, messageType, createdDate, isRead));
+ }
+ cursor.close();
+ }
+
+ // 通知适配器数据变化
+ mChatAdapter.notifyDataSetChanged();
+
+ // 滚动到底部
+ if (!mMessageList.isEmpty()) {
+ mChatListView.setSelection(mMessageList.size() - 1);
+ }
+
+ // 将接收到的消息标记为已读
+ markMessagesAsRead();
+ }
+
+ /**
+ * 发送消息
+ */
+ private void sendMessage() {
+ String content = mMessageEditText.getText().toString().trim();
+ if (content.isEmpty()) {
+ Toast.makeText(this, "消息内容不能为空", Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ // 创建消息对象
+ ContentValues values = new ContentValues();
+ values.put(Messages.MessageColumns.SENDER_ID, mCurrentUserId);
+ values.put(Messages.MessageColumns.RECEIVER_ID, mFriendId);
+ values.put(Messages.MessageColumns.CONTENT, content);
+ values.put(Messages.MessageColumns.MESSAGE_TYPE, Messages.MessageType.TEXT);
+ values.put(Messages.MessageColumns.CREATED_DATE, System.currentTimeMillis());
+ values.put(Messages.MessageColumns.IS_READ, 0);
+
+ // 插入消息到数据库
+ long messageId = mDb.insert(NotesDatabaseHelper.TABLE.MESSAGE, null, values);
+ if (messageId != -1) {
+ // 清空输入框
+ mMessageEditText.setText("");
+
+ // 重新加载聊天记录
+ loadChatHistory();
+ } else {
+ Toast.makeText(this, "发送失败", Toast.LENGTH_SHORT).show();
+ Log.e(TAG, "Failed to send message");
+ }
+ }
+
+ /**
+ * 将接收到的消息标记为已读
+ */
+ private void markMessagesAsRead() {
+ ContentValues values = new ContentValues();
+ values.put(Messages.MessageColumns.IS_READ, 1);
+
+ int updatedRows = mDb.update(NotesDatabaseHelper.TABLE.MESSAGE, values,
+ Messages.MessageColumns.SENDER_ID + " = ? AND " + Messages.MessageColumns.RECEIVER_ID + " = ? AND " + Messages.MessageColumns.IS_READ + " = 0",
+ new String[]{String.valueOf(mFriendId), String.valueOf(mCurrentUserId)});
+
+ Log.d(TAG, "Marked " + updatedRows + " messages as read");
+ }
+
+ /**
+ * 显示便签详情
+ */
+ private void showNoteDetail(String noteData) {
+ try {
+ // 解析便签数据
+ String[] noteParts = noteData.split("\\|");
+ if (noteParts.length < 2) {
+ Toast.makeText(this, "无效的便签数据", Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ String noteTitle = noteParts[0];
+ String noteContent = noteParts[1];
+
+ if (TextUtils.isEmpty(noteTitle)) {
+ noteTitle = "无标题便签";
+ }
+
+ // 创建并显示便签详情对话框
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(noteTitle);
+ builder.setMessage(noteContent);
+ builder.setPositiveButton("确定", null);
+ builder.show();
+ } catch (Exception e) {
+ Log.e(TAG, "Error showing note detail: " + e.getMessage(), e);
+ Toast.makeText(this, "显示便签详情失败", Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ /**
+ * 聊天消息实体类
+ */
+ private static class ChatMessage {
+ long id;
+ long senderId;
+ long receiverId;
+ String content;
+ int messageType;
+ long createdDate;
+ int isRead;
+
+ ChatMessage(long id, long senderId, long receiverId, String content, int messageType, long createdDate, int isRead) {
+ this.id = id;
+ this.senderId = senderId;
+ this.receiverId = receiverId;
+ this.content = content;
+ this.messageType = messageType;
+ this.createdDate = createdDate;
+ this.isRead = isRead;
+ }
+ }
+
+ /**
+ * 聊天消息适配器
+ */
+ private static class ChatAdapter extends BaseAdapter {
+ private static final int VIEW_TYPE_SENT_TEXT = 0;
+ private static final int VIEW_TYPE_RECEIVED_TEXT = 1;
+ private static final int VIEW_TYPE_SENT_NOTE = 2;
+ private static final int VIEW_TYPE_RECEIVED_NOTE = 3;
+
+ private Context mContext;
+ private List mMessageList;
+ public long mCurrentUserId;
+ private LayoutInflater mInflater;
+ private SimpleDateFormat mDateFormat;
+
+ ChatAdapter(Context context, List messageList, long currentUserId) {
+ mContext = context;
+ mMessageList = messageList;
+ mCurrentUserId = currentUserId;
+ mInflater = LayoutInflater.from(context);
+ mDateFormat = new SimpleDateFormat("HH:mm");
+ }
+
+ @Override
+ public int getCount() {
+ return mMessageList.size();
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return mMessageList.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public int getViewTypeCount() {
+ return 4; // 四种视图类型:发送文本、接收文本、发送便签、接收便签
+ }
+
+ @Override
+ public int getItemViewType(int position) {
+ ChatMessage message = mMessageList.get(position);
+ boolean isSentByMe = message.senderId == mCurrentUserId;
+ if (message.messageType == Messages.MessageType.NOTE) {
+ return isSentByMe ? VIEW_TYPE_SENT_NOTE : VIEW_TYPE_RECEIVED_NOTE;
+ } else {
+ return isSentByMe ? VIEW_TYPE_SENT_TEXT : VIEW_TYPE_RECEIVED_TEXT;
+ }
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ ChatMessage message = mMessageList.get(position);
+ boolean isSentByMe = message.senderId == mCurrentUserId;
+
+ ViewHolder holder;
+ if (convertView == null) {
+ // 根据视图类型选择不同的布局
+ int viewType = getItemViewType(position);
+ switch (viewType) {
+ case VIEW_TYPE_SENT_NOTE:
+ convertView = mInflater.inflate(R.layout.chat_message_sent_note_item, parent, false);
+ break;
+ case VIEW_TYPE_RECEIVED_NOTE:
+ convertView = mInflater.inflate(R.layout.chat_message_received_note_item, parent, false);
+ break;
+ case VIEW_TYPE_SENT_TEXT:
+ default:
+ convertView = mInflater.inflate(R.layout.chat_message_sent_item, parent, false);
+ break;
+ case VIEW_TYPE_RECEIVED_TEXT:
+ convertView = mInflater.inflate(R.layout.chat_message_received_item, parent, false);
+ break;
+ }
+
+ holder = new ViewHolder();
+ holder.contentTextView = convertView.findViewById(R.id.message_content);
+ holder.timeTextView = convertView.findViewById(R.id.message_time);
+ convertView.setTag(holder);
+ } else {
+ holder = (ViewHolder) convertView.getTag();
+ }
+
+ // 设置消息内容
+ if (message.messageType == Messages.MessageType.NOTE) {
+ // 便签类型消息,只显示便签标题
+ String[] noteData = message.content.split("\\|");
+ if (noteData.length >= 2) {
+ String noteTitle = noteData[0];
+ if (TextUtils.isEmpty(noteTitle)) {
+ noteTitle = "无标题便签";
+ }
+ holder.contentTextView.setText(noteTitle);
+ // 设置不同的颜色,区分于普通文本消息
+ holder.contentTextView.setTextColor(Color.BLUE); // 使用蓝色区分便签消息
+ holder.contentTextView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ // 点击便签,查看详情
+ ((ChatActivity) mContext).showNoteDetail(message.content);
+ }
+ });
+ }
+ } else {
+ // 普通文本消息
+ holder.contentTextView.setText(message.content);
+ holder.contentTextView.setOnClickListener(null);
+ }
+
+ // 设置消息时间
+ Date date = new Date(message.createdDate);
+ holder.timeTextView.setText(mDateFormat.format(date));
+
+ return convertView;
+ }
+
+ private static class ViewHolder {
+ TextView contentTextView;
+ TextView timeTextView;
+ }
+ }
+}
diff --git a/src/Notes-master/src/net/micode/notes/ui/FriendManagementActivity.java b/src/Notes-master/src/net/micode/notes/ui/FriendManagementActivity.java
new file mode 100644
index 0000000..679971d
--- /dev/null
+++ b/src/Notes-master/src/net/micode/notes/ui/FriendManagementActivity.java
@@ -0,0 +1,206 @@
+package net.micode.notes.ui;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.BaseAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import net.micode.notes.R;
+import net.micode.notes.data.NotesDatabaseHelper;
+import net.micode.notes.tool.UserManager;
+import net.micode.notes.data.Users;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class FriendManagementActivity extends Activity {
+ private ListView mFriendListView;
+ private FriendAdapter mFriendAdapter;
+ private List mFriendList;
+ private NotesDatabaseHelper mDbHelper;
+ private SQLiteDatabase mDb;
+ private UserManager mUserManager;
+ private long mCurrentUserId;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_friend_management);
+
+ // 设置ActionBar
+ ActionBar actionBar = getActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setTitle("好友管理");
+ }
+
+ // 初始化数据库
+ mDbHelper = NotesDatabaseHelper.getInstance(this);
+ mDb = mDbHelper.getWritableDatabase();
+
+ // 初始化UserManager
+ mUserManager = UserManager.getInstance(this);
+ mCurrentUserId = mUserManager.getCurrentUserId();
+
+ // 初始化ListView
+ mFriendListView = findViewById(R.id.friend_list);
+ mFriendList = new ArrayList<>();
+ mFriendAdapter = new FriendAdapter(this, mFriendList);
+ mFriendListView.setAdapter(mFriendAdapter);
+
+ // 设置ListView点击事件
+ mFriendListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ Friend friend = mFriendList.get(position);
+ // 启动与好友聊天的活动
+ Intent intent = new Intent(FriendManagementActivity.this, ChatActivity.class);
+ intent.putExtra("friend_id", friend.id);
+ intent.putExtra("friend_username", friend.username);
+ startActivity(intent);
+ }
+ });
+
+ // 加载好友列表
+ loadFriendList();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ // 重新加载好友列表
+ loadFriendList();
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ // 关闭数据库连接
+ if (mDb != null && mDb.isOpen()) {
+ mDb.close();
+ }
+ }
+
+ /**
+ * 加载好友列表,即除当前用户以外的所有用户
+ */
+ private void loadFriendList() {
+ mFriendList.clear();
+
+ // 查询除当前用户以外的所有用户
+ Cursor cursor = mDb.query(
+ NotesDatabaseHelper.TABLE.USER,
+ new String[]{Users.UserColumns.ID, Users.UserColumns.USERNAME},
+ Users.UserColumns.ID + " != ?",
+ new String[]{String.valueOf(mCurrentUserId)},
+ null,
+ null,
+ null
+ );
+
+ if (cursor != null) {
+ while (cursor.moveToNext()) {
+ long id = cursor.getLong(cursor.getColumnIndexOrThrow(Users.UserColumns.ID));
+ String username = cursor.getString(cursor.getColumnIndexOrThrow(Users.UserColumns.USERNAME));
+ mFriendList.add(new Friend(id, username));
+ }
+ cursor.close();
+ }
+
+ // 通知适配器数据变化
+ mFriendAdapter.notifyDataSetChanged();
+
+ // 如果没有好友,显示提示
+ if (mFriendList.isEmpty()) {
+ Toast.makeText(this, "暂无其他用户", Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ /**
+ * 好友实体类
+ */
+ private static class Friend {
+ long id;
+ String username;
+
+ Friend(long id, String username) {
+ this.id = id;
+ this.username = username;
+ }
+ }
+
+ /**
+ * 好友列表适配器
+ */
+ private static class FriendAdapter extends BaseAdapter {
+ private Context mContext;
+ private List mFriendList;
+ private LayoutInflater mInflater;
+
+ FriendAdapter(Context context, List friendList) {
+ mContext = context;
+ mFriendList = friendList;
+ mInflater = LayoutInflater.from(context);
+ }
+
+ @Override
+ public int getCount() {
+ return mFriendList.size();
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return mFriendList.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ ViewHolder holder;
+ if (convertView == null) {
+ convertView = mInflater.inflate(R.layout.item_friend, parent, false);
+ holder = new ViewHolder();
+ holder.usernameTextView = convertView.findViewById(R.id.friend_username);
+ convertView.setTag(holder);
+ } else {
+ holder = (ViewHolder) convertView.getTag();
+ }
+
+ Friend friend = mFriendList.get(position);
+ holder.usernameTextView.setText(friend.username);
+
+ return convertView;
+ }
+
+ private static class ViewHolder {
+ TextView usernameTextView;
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(android.view.MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ // 返回上一级活动
+ finish();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Notes-master/src/net/micode/notes/ui/FriendNoteEditActivity.java b/src/Notes-master/src/net/micode/notes/ui/FriendNoteEditActivity.java
new file mode 100644
index 0000000..d5c6620
--- /dev/null
+++ b/src/Notes-master/src/net/micode/notes/ui/FriendNoteEditActivity.java
@@ -0,0 +1,239 @@
+package net.micode.notes.ui;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.View;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import net.micode.notes.R;
+import net.micode.notes.data.Notes;
+
+
+public class FriendNoteEditActivity extends Activity {
+ private TextView mNoteEditor;
+ private TextView mNoteTitleView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_friend_note_edit);
+
+ // 设置ActionBar
+ ActionBar actionBar = getActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setTitle("查看便签");
+ }
+
+ // 初始化控件
+ mNoteEditor = findViewById(R.id.note_edit_view);
+ mNoteTitleView = findViewById(R.id.note_title_view);
+
+ // 加载便签数据
+ if (savedInstanceState == null && !initActivityState(getIntent())) {
+ finish();
+ return;
+ }
+ initNoteScreen();
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
+ if (savedInstanceState != null && savedInstanceState.containsKey(Intent.EXTRA_UID)) {
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.putExtra(Intent.EXTRA_UID, savedInstanceState.getLong(Intent.EXTRA_UID));
+ intent.putExtra("friend_id", savedInstanceState.getLong("friend_id"));
+ if (!initActivityState(intent)) {
+ finish();
+ return;
+ }
+ // 恢复状态后重新初始化界面
+ initNoteScreen();
+ }
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ if (getIntent() != null) {
+ outState.putLong(Intent.EXTRA_UID, getIntent().getLongExtra(Intent.EXTRA_UID, 0));
+ outState.putLong("friend_id", getIntent().getLongExtra("friend_id", -1));
+ }
+ }
+
+ private String mNoteContent;
+ private String mNoteTitle;
+ private long mModifiedDate;
+
+ private boolean initActivityState(Intent intent) {
+ /**
+ * 只支持查看模式
+ */
+ long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
+ long friendId = intent.getLongExtra("friend_id", -1);
+
+ if (noteId <= 0 || friendId <= 0) {
+ Toast.makeText(this, "便签信息错误", Toast.LENGTH_SHORT).show();
+ finish();
+ return false;
+ }
+
+ try {
+ // 查询便签基本信息,包括标题
+ String[] noteProjection = {
+ net.micode.notes.data.Notes.NoteColumns.MODIFIED_DATE,
+ net.micode.notes.data.Notes.NoteColumns.TITLE
+ };
+
+ android.database.Cursor noteCursor = null;
+ try {
+ // 使用ContentResolver查询便签基本信息
+ noteCursor = getContentResolver().query(
+ android.content.ContentUris.withAppendedId(net.micode.notes.data.Notes.CONTENT_NOTE_URI, noteId),
+ noteProjection,
+ null,
+ null,
+ null
+ );
+
+ if (noteCursor != null) {
+ if (noteCursor.moveToFirst()) {
+ mModifiedDate = noteCursor.getLong(0);
+ mNoteTitle = noteCursor.getString(1);
+ }
+ noteCursor.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ Toast.makeText(this, "查询便签信息失败", Toast.LENGTH_SHORT).show();
+ }
+
+ // 查询便签具体内容,这是必须的,因为完整内容存储在Data表中
+ String[] dataProjection = {net.micode.notes.data.Notes.DataColumns.CONTENT};
+ String dataSelection = net.micode.notes.data.Notes.DataColumns.NOTE_ID + " = ? AND " +
+ net.micode.notes.data.Notes.DataColumns.MIME_TYPE + " = ?";
+ String[] dataSelectionArgs = {String.valueOf(noteId), net.micode.notes.data.Notes.DataConstants.NOTE};
+
+ android.database.Cursor dataCursor = null;
+ try {
+ // 使用ContentResolver查询数据
+ dataCursor = getContentResolver().query(
+ net.micode.notes.data.Notes.CONTENT_DATA_URI,
+ dataProjection,
+ dataSelection,
+ dataSelectionArgs,
+ null
+ );
+
+ if (dataCursor != null) {
+ if (dataCursor.moveToFirst()) {
+ mNoteContent = dataCursor.getString(0);
+ }
+ dataCursor.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ Toast.makeText(this, "查询便签内容失败", Toast.LENGTH_SHORT).show();
+ } finally {
+ if (dataCursor != null) {
+ dataCursor.close();
+ }
+ }
+
+ // 如果查询失败,尝试使用数据库直接查询
+ if (mNoteContent == null || mNoteContent.isEmpty()) {
+ try {
+ // 直接使用数据库查询,绕过ContentProvider的用户过滤
+ net.micode.notes.data.NotesDatabaseHelper helper = net.micode.notes.data.NotesDatabaseHelper.getInstance(FriendNoteEditActivity.this);
+ if (helper != null) {
+ dataCursor = helper.getReadableDatabase().query(
+ net.micode.notes.data.NotesDatabaseHelper.TABLE.DATA,
+ dataProjection,
+ dataSelection,
+ dataSelectionArgs,
+ null,
+ null,
+ null
+ );
+
+ if (dataCursor != null) {
+ if (dataCursor.moveToFirst()) {
+ mNoteContent = dataCursor.getString(0);
+ }
+ dataCursor.close();
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ Toast.makeText(this, "直接查询便签内容失败", Toast.LENGTH_SHORT).show();
+ } finally {
+ if (dataCursor != null) {
+ dataCursor.close();
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ Toast.makeText(this, "初始化便签失败: " + e.getMessage(), Toast.LENGTH_SHORT).show();
+ finish();
+ return false;
+ }
+ return true;
+ }
+
+ private void initNoteScreen() {
+ // 显示修改日期
+ TextView modifiedDateTextView = findViewById(R.id.tv_modified_date);
+ modifiedDateTextView.setText(android.text.format.DateUtils.formatDateTime(
+ this, mModifiedDate,
+ android.text.format.DateUtils.FORMAT_SHOW_DATE |
+ android.text.format.DateUtils.FORMAT_NUMERIC_DATE |
+ android.text.format.DateUtils.FORMAT_SHOW_TIME));
+
+ // 显示便签标题
+ if (mNoteTitle != null && !mNoteTitle.isEmpty()) {
+ mNoteTitleView.setVisibility(View.VISIBLE);
+ mNoteTitleView.setText(mNoteTitle);
+ } else {
+ // 如果没有标题,隐藏标题文本视图
+ mNoteTitleView.setVisibility(View.GONE);
+ }
+
+ // 显示便签内容,添加调试日志
+ if (mNoteContent != null && !mNoteContent.isEmpty()) {
+ mNoteEditor.setText(mNoteContent);
+ // 设置文本颜色为深色,确保可见
+ mNoteEditor.setTextColor(getResources().getColor(android.R.color.primary_text_dark));
+ // 设置背景色为白色,确保可见
+ mNoteEditor.setBackgroundColor(getResources().getColor(android.R.color.white));
+ } else {
+ // 如果内容为空,显示提示文本
+ mNoteEditor.setText("(空便签)");
+ mNoteEditor.setTextColor(getResources().getColor(android.R.color.secondary_text_dark));
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // 不显示菜单,因为是只读模式
+ return false;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(android.view.MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ // 返回上一级活动
+ finish();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Notes-master/src/net/micode/notes/ui/FriendNoteListActivity.java b/src/Notes-master/src/net/micode/notes/ui/FriendNoteListActivity.java
new file mode 100644
index 0000000..6a381eb
--- /dev/null
+++ b/src/Notes-master/src/net/micode/notes/ui/FriendNoteListActivity.java
@@ -0,0 +1,271 @@
+package net.micode.notes.ui;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.content.Intent;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.BaseAdapter;
+import android.widget.ImageView;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import net.micode.notes.R;
+import net.micode.notes.data.Notes;
+import net.micode.notes.data.Notes.NoteColumns;
+import net.micode.notes.model.WorkingNote;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class FriendNoteListActivity extends Activity {
+ private ListView mNoteListView;
+ private NoteAdapter mNoteAdapter;
+ private List mNoteList;
+ private long mFriendId;
+ private String mFriendUsername;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_friend_note_list);
+
+ // 获取好友信息
+ mFriendId = getIntent().getLongExtra("friend_id", -1);
+ mFriendUsername = getIntent().getStringExtra("friend_username");
+
+ if (mFriendId == -1 || mFriendUsername == null) {
+ Toast.makeText(this, "好友信息错误", Toast.LENGTH_SHORT).show();
+ finish();
+ return;
+ }
+
+ // 设置ActionBar
+ ActionBar actionBar = getActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setTitle(mFriendUsername + "的公开便签");
+ }
+
+ // 初始化ListView
+ mNoteListView = findViewById(R.id.friend_note_list);
+ mNoteList = new ArrayList<>();
+ mNoteAdapter = new NoteAdapter(this, mNoteList);
+ mNoteListView.setAdapter(mNoteAdapter);
+
+ // 设置ListView点击事件
+ mNoteListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ Note note = mNoteList.get(position);
+ // 启动查看便签详情的活动
+ Intent intent = new Intent(FriendNoteListActivity.this, FriendNoteEditActivity.class);
+ intent.putExtra(Intent.EXTRA_UID, note.id);
+ intent.putExtra("friend_id", mFriendId);
+ startActivity(intent);
+ }
+ });
+
+ // 加载好友的公开便签
+ loadFriendNotes();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ // 重新加载好友便签
+ loadFriendNotes();
+ }
+
+ /**
+ * 加载好友的公开便签
+ */
+ private void loadFriendNotes() {
+ try {
+ mNoteList.clear();
+
+ // 查询好友的所有公开便签
+ String[] projection = {
+ NoteColumns.ID,
+ NoteColumns.TITLE,
+ NoteColumns.SNIPPET,
+ NoteColumns.MODIFIED_DATE,
+ NoteColumns.TYPE,
+ NoteColumns.PINNED,
+ NoteColumns.LOCKED,
+ NoteColumns.PUBLIC
+ };
+
+ String selection = NoteColumns.USER_ID + " = ? AND " + NoteColumns.PUBLIC + " = 1 AND " + NoteColumns.PARENT_ID + " <> " + Notes.ID_TRASH_FOLER;
+ String[] selectionArgs = {String.valueOf(mFriendId)};
+
+ Cursor cursor = null;
+ try {
+ cursor = getContentResolver().query(
+ Notes.CONTENT_NOTE_URI,
+ projection,
+ selection,
+ selectionArgs,
+ NoteColumns.PINNED + " DESC, " + NoteColumns.MODIFIED_DATE + " DESC"
+ );
+
+ if (cursor != null) {
+ while (cursor.moveToNext()) {
+ long id = cursor.getLong(cursor.getColumnIndexOrThrow(NoteColumns.ID));
+ String title = cursor.getString(cursor.getColumnIndexOrThrow(NoteColumns.TITLE));
+ String content = cursor.getString(cursor.getColumnIndexOrThrow(NoteColumns.SNIPPET));
+ long modifiedDate = cursor.getLong(cursor.getColumnIndexOrThrow(NoteColumns.MODIFIED_DATE));
+ int type = cursor.getInt(cursor.getColumnIndexOrThrow(NoteColumns.TYPE));
+ int pinned = cursor.getInt(cursor.getColumnIndexOrThrow(NoteColumns.PINNED));
+ int locked = cursor.getInt(cursor.getColumnIndexOrThrow(NoteColumns.LOCKED));
+ int isPublic = cursor.getInt(cursor.getColumnIndexOrThrow(NoteColumns.PUBLIC));
+
+ mNoteList.add(new Note(id, title, content, modifiedDate, type, pinned, locked, isPublic));
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ Toast.makeText(this, "查询好友便签失败: " + e.getMessage(), Toast.LENGTH_SHORT).show();
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
+ }
+
+ // 通知适配器数据变化
+ mNoteAdapter.notifyDataSetChanged();
+
+ // 如果没有公开便签,显示提示
+ if (mNoteList.isEmpty()) {
+ Toast.makeText(this, mFriendUsername + "没有公开的便签", Toast.LENGTH_SHORT).show();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ Toast.makeText(this, "加载好友便签失败", Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ /**
+ * 便签实体类
+ */
+ private static class Note {
+ long id;
+ String title;
+ String content;
+ long modifiedDate;
+ int type;
+ int pinned;
+ int locked;
+ int isPublic;
+
+ Note(long id, String title, String content, long modifiedDate, int type, int pinned, int locked, int isPublic) {
+ this.id = id;
+ this.title = title;
+ this.content = content;
+ this.modifiedDate = modifiedDate;
+ this.type = type;
+ this.pinned = pinned;
+ this.locked = locked;
+ this.isPublic = isPublic;
+ }
+ }
+
+ /**
+ * 便签列表适配器
+ */
+ private static class NoteAdapter extends BaseAdapter {
+ private Activity mActivity;
+ private List mNoteList;
+ private LayoutInflater mInflater;
+
+ NoteAdapter(Activity activity, List noteList) {
+ mActivity = activity;
+ mNoteList = noteList;
+ mInflater = LayoutInflater.from(activity);
+ }
+
+ @Override
+ public int getCount() {
+ return mNoteList.size();
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return mNoteList.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ ViewHolder holder;
+ if (convertView == null) {
+ convertView = mInflater.inflate(R.layout.note_item, parent, false);
+ holder = new ViewHolder();
+ holder.titleTextView = convertView.findViewById(R.id.tv_title);
+ holder.modifiedDateTextView = convertView.findViewById(R.id.tv_time);
+ holder.pinnedImageView = convertView.findViewById(R.id.iv_alert_icon);
+ holder.lockedImageView = convertView.findViewById(R.id.iv_lock_icon);
+ holder.publicImageView = convertView.findViewById(R.id.iv_public_icon);
+ convertView.setTag(holder);
+ } else {
+ holder = (ViewHolder) convertView.getTag();
+ }
+
+ Note note = mNoteList.get(position);
+ // 显示标题,如果标题为空则显示内容摘要
+ String displayText;
+ if (note.title != null && !note.title.isEmpty()) {
+ displayText = note.title;
+ } else {
+ displayText = note.content;
+ }
+ holder.titleTextView.setText(displayText);
+ holder.modifiedDateTextView.setText(android.text.format.DateUtils.formatDateTime(
+ mActivity, note.modifiedDate,
+ android.text.format.DateUtils.FORMAT_SHOW_DATE |
+ android.text.format.DateUtils.FORMAT_NUMERIC_DATE |
+ android.text.format.DateUtils.FORMAT_SHOW_TIME));
+
+ // 设置置顶图标
+ holder.pinnedImageView.setVisibility(note.pinned == 1 ? View.VISIBLE : View.GONE);
+
+ // 设置锁定图标
+ holder.lockedImageView.setVisibility(note.locked == 1 ? View.VISIBLE : View.GONE);
+
+ // 设置公开图标
+ holder.publicImageView.setVisibility(note.isPublic == 1 ? View.VISIBLE : View.GONE);
+
+ return convertView;
+ }
+
+ private static class ViewHolder {
+ TextView titleTextView;
+ TextView modifiedDateTextView;
+ ImageView pinnedImageView;
+ ImageView lockedImageView;
+ ImageView publicImageView;
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(android.view.MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ // 返回上一级活动
+ finish();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Notes-master/src/net/micode/notes/ui/LoginActivity.java b/src/Notes-master/src/net/micode/notes/ui/LoginActivity.java
new file mode 100644
index 0000000..d613e4a
--- /dev/null
+++ b/src/Notes-master/src/net/micode/notes/ui/LoginActivity.java
@@ -0,0 +1,321 @@
+/*
+ * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.micode.notes.ui;
+
+import android.content.ContentValues;
+import android.content.Intent;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.Toast;
+
+import androidx.appcompat.app.AlertDialog;
+import androidx.appcompat.app.AppCompatActivity;
+
+import net.micode.notes.R;
+import net.micode.notes.data.NotesDatabaseHelper;
+import net.micode.notes.data.Users;
+import net.micode.notes.tool.UserManager;
+
+public class LoginActivity extends AppCompatActivity {
+
+ private EditText etUsername;
+ private EditText etPassword;
+
+ private NotesDatabaseHelper mDbHelper;
+ private SQLiteDatabase mDb;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_login);
+
+ // 初始化数据库
+ mDbHelper = NotesDatabaseHelper.getInstance(this);
+ mDb = mDbHelper.getWritableDatabase();
+
+ // 初始化控件
+ etUsername = findViewById(R.id.et_username);
+ etPassword = findViewById(R.id.et_password);
+ }
+
+ /**
+ * 登录按钮点击事件
+ */
+ public void onLoginClick(View view) {
+ String username = etUsername.getText().toString().trim();
+ String password = etPassword.getText().toString().trim();
+
+ // 验证输入
+ if (username.isEmpty() || password.isEmpty()) {
+ Toast.makeText(this, "用户名和密码不能为空", Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ // 验证用户名和密码
+ long userId = validateUser(username, password);
+ if (userId != -1) {
+ // 登录成功,保存用户信息
+ UserManager userManager = UserManager.getInstance(this);
+ userManager.saveCurrentUser(userId, username);
+
+ // 跳转到便签列表
+ Intent intent = new Intent(this, NotesListActivity.class);
+ startActivity(intent);
+ finish();
+ } else {
+ // 登录失败,提示错误
+ Toast.makeText(this, "用户名或密码错误", Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ /**
+ * 注册按钮点击事件
+ */
+ public void onRegisterClick(View view) {
+ showRegisterDialog();
+ }
+
+ /**
+ * 修改密码按钮点击事件
+ */
+ public void onChangePasswordClick(View view) {
+ showChangePasswordDialog();
+ }
+
+ /**
+ * 显示注册对话框
+ */
+ private void showRegisterDialog() {
+ View dialogView = getLayoutInflater().inflate(R.layout.dialog_register, null);
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setView(dialogView);
+
+ final AlertDialog dialog = builder.create();
+
+ // 初始化注册对话框控件
+ final EditText etRegisterUsername = dialogView.findViewById(R.id.et_register_username);
+ final EditText etRegisterPassword = dialogView.findViewById(R.id.et_register_password);
+ final EditText etRegisterConfirmPassword = dialogView.findViewById(R.id.et_register_confirm_password);
+ Button btnRegisterCancel = dialogView.findViewById(R.id.btn_register_cancel);
+ Button btnRegisterConfirm = dialogView.findViewById(R.id.btn_register_confirm);
+
+ // 取消按钮点击事件
+ btnRegisterCancel.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ dialog.dismiss();
+ }
+ });
+
+ // 注册按钮点击事件
+ btnRegisterConfirm.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ String username = etRegisterUsername.getText().toString().trim();
+ String password = etRegisterPassword.getText().toString().trim();
+ String confirmPassword = etRegisterConfirmPassword.getText().toString().trim();
+
+ // 验证输入
+ if (username.isEmpty() || password.isEmpty() || confirmPassword.isEmpty()) {
+ Toast.makeText(LoginActivity.this, "请填写完整信息", Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ if (!password.equals(confirmPassword)) {
+ Toast.makeText(LoginActivity.this, "两次输入的密码不一致", Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ // 检查用户名是否已存在
+ if (isUsernameExists(username)) {
+ Toast.makeText(LoginActivity.this, "用户名已存在", Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ // 注册用户
+ if (registerUser(username, password)) {
+ Toast.makeText(LoginActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
+ dialog.dismiss();
+ } else {
+ Toast.makeText(LoginActivity.this, "注册失败,请重试", Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+
+ dialog.show();
+ }
+
+ /**
+ * 显示修改密码对话框
+ */
+ private void showChangePasswordDialog() {
+ View dialogView = getLayoutInflater().inflate(R.layout.dialog_change_password, null);
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setView(dialogView);
+
+ final AlertDialog dialog = builder.create();
+
+ // 初始化修改密码对话框控件
+ final EditText etChangeUsername = dialogView.findViewById(R.id.et_change_username);
+ final EditText etCurrentPassword = dialogView.findViewById(R.id.et_current_password);
+ final EditText etNewPassword = dialogView.findViewById(R.id.et_new_password);
+ final EditText etConfirmNewPassword = dialogView.findViewById(R.id.et_confirm_new_password);
+ Button btnChangeCancel = dialogView.findViewById(R.id.btn_change_cancel);
+ Button btnChangeConfirm = dialogView.findViewById(R.id.btn_change_confirm);
+
+ // 取消按钮点击事件
+ btnChangeCancel.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ dialog.dismiss();
+ }
+ });
+
+ // 确认修改按钮点击事件
+ btnChangeConfirm.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ String username = etChangeUsername.getText().toString().trim();
+ String currentPassword = etCurrentPassword.getText().toString().trim();
+ String newPassword = etNewPassword.getText().toString().trim();
+ String confirmNewPassword = etConfirmNewPassword.getText().toString().trim();
+
+ // 验证输入
+ if (username.isEmpty() || currentPassword.isEmpty() || newPassword.isEmpty() || confirmNewPassword.isEmpty()) {
+ Toast.makeText(LoginActivity.this, "请填写完整信息", Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ if (!newPassword.equals(confirmNewPassword)) {
+ Toast.makeText(LoginActivity.this, "两次输入的新密码不一致", Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ // 验证当前密码
+ if (validateUser(username, currentPassword) == -1) {
+ Toast.makeText(LoginActivity.this, "用户名或当前密码错误", Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ // 修改密码
+ if (changePassword(username, newPassword)) {
+ Toast.makeText(LoginActivity.this, "密码修改成功", Toast.LENGTH_SHORT).show();
+ dialog.dismiss();
+ } else {
+ Toast.makeText(LoginActivity.this, "密码修改失败,请重试", Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+
+ dialog.show();
+ }
+
+ /**
+ * 验证用户名和密码,并返回用户ID
+ */
+ private long validateUser(String username, String password) {
+ String[] projection = {Users.UserColumns.ID};
+ String selection = Users.UserColumns.USERNAME + " = ? AND " + Users.UserColumns.PASSWORD + " = ?";
+ String[] selectionArgs = {username, password};
+
+ Cursor cursor = mDb.query(
+ NotesDatabaseHelper.TABLE.USER,
+ projection,
+ selection,
+ selectionArgs,
+ null,
+ null,
+ null
+ );
+
+ long userId = -1;
+ if (cursor.moveToFirst()) {
+ userId = cursor.getLong(cursor.getColumnIndexOrThrow(Users.UserColumns.ID));
+ }
+ cursor.close();
+ return userId;
+ }
+
+ /**
+ * 检查用户名是否已存在
+ */
+ private boolean isUsernameExists(String username) {
+ String[] projection = {Users.UserColumns.ID};
+ String selection = Users.UserColumns.USERNAME + " = ?";
+ String[] selectionArgs = {username};
+
+ Cursor cursor = mDb.query(
+ NotesDatabaseHelper.TABLE.USER,
+ projection,
+ selection,
+ selectionArgs,
+ null,
+ null,
+ null
+ );
+
+ boolean exists = cursor.getCount() > 0;
+ cursor.close();
+ return exists;
+ }
+
+ /**
+ * 注册用户
+ */
+ private boolean registerUser(String username, String password) {
+ ContentValues values = new ContentValues();
+ values.put(Users.UserColumns.USERNAME, username);
+ values.put(Users.UserColumns.PASSWORD, password);
+
+ long result = mDb.insert(NotesDatabaseHelper.TABLE.USER, null, values);
+ return result != -1;
+ }
+
+ /**
+ * 修改密码
+ */
+ private boolean changePassword(String username, String newPassword) {
+ ContentValues values = new ContentValues();
+ values.put(Users.UserColumns.PASSWORD, newPassword);
+ values.put(Users.UserColumns.MODIFIED_DATE, System.currentTimeMillis());
+
+ String selection = Users.UserColumns.USERNAME + " = ?";
+ String[] selectionArgs = {username};
+
+ int result = mDb.update(
+ NotesDatabaseHelper.TABLE.USER,
+ values,
+ selection,
+ selectionArgs
+ );
+
+ return result > 0;
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ // 关闭数据库连接
+ if (mDb != null && mDb.isOpen()) {
+ mDb.close();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Notes-master/src/net/micode/notes/ui/SplashActivity.java b/src/Notes-master/src/net/micode/notes/ui/SplashActivity.java
new file mode 100644
index 0000000..f3d7a3f
--- /dev/null
+++ b/src/Notes-master/src/net/micode/notes/ui/SplashActivity.java
@@ -0,0 +1,56 @@
+package net.micode.notes.ui;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.view.animation.AlphaAnimation;
+import android.view.animation.Animation;
+import android.widget.LinearLayout;
+
+import net.micode.notes.R;
+
+public class SplashActivity extends Activity {
+
+ private static final int SPLASH_DISPLAY_DURATION = 2000; // 2秒
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_splash);
+
+ // 找到小米logo容器
+ LinearLayout miLogo = findViewById(R.id.mi_logo);
+
+ // 创建淡入淡出动画
+ AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
+ animation.setDuration(1500); // 1.5秒
+ animation.setAnimationListener(new Animation.AnimationListener() {
+ @Override
+ public void onAnimationStart(Animation animation) {
+ // 动画开始时的回调
+ }
+
+ @Override
+ public void onAnimationEnd(Animation animation) {
+ // 动画结束后跳转到主界面
+ new Handler().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ Intent mainIntent = new Intent(SplashActivity.this, NotesListActivity.class);
+ SplashActivity.this.startActivity(mainIntent);
+ SplashActivity.this.finish();
+ }
+ }, 500); // 延迟500毫秒后跳转
+ }
+
+ @Override
+ public void onAnimationRepeat(Animation animation) {
+ // 动画重复时的回调
+ }
+ });
+
+ // 应用动画到小米logo
+ miLogo.startAnimation(animation);
+ }
+}
\ No newline at end of file