From 19721c364fc0a41d0b3b14dffb6a7f53784f8c47 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=92=8B=E5=A4=A9=E7=BF=94?=
Date: Mon, 26 Jan 2026 23:30:03 +0800
Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=90=9C=E7=B4=A2?=
=?UTF-8?q?=E4=BE=BF=E7=AD=BE=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/Notesmaster/.gitignore | 5 +++++
.../app/src/main/AndroidManifest.xml | 9 ++++++++
.../micode/notes/data/NotesRepository.java | 6 +++--
.../micode/notes/ui/NotesListActivity.java | 4 ++--
.../src/main/res/color/primary_text_dark.xml | 22 -------------------
.../main/res/color/secondary_text_dark.xml | 20 -----------------
.../app/src/main/res/layout/note_list.xml | 3 ++-
.../app/src/main/res/values/colors.xml | 7 ++++--
.../app/src/main/res/values/strings.xml | 5 +++++
9 files changed, 32 insertions(+), 49 deletions(-)
delete mode 100644 src/Notesmaster/app/src/main/res/color/primary_text_dark.xml
delete mode 100644 src/Notesmaster/app/src/main/res/color/secondary_text_dark.xml
diff --git a/src/Notesmaster/.gitignore b/src/Notesmaster/.gitignore
index aa724b7..7f909be 100644
--- a/src/Notesmaster/.gitignore
+++ b/src/Notesmaster/.gitignore
@@ -13,3 +13,8 @@
.externalNativeBuild
.cxx
local.properties
+build.gradle.kts
+gradle.properties
+gradlew
+gradlew.bat
+settings.gradle.kts
\ No newline at end of file
diff --git a/src/Notesmaster/app/src/main/AndroidManifest.xml b/src/Notesmaster/app/src/main/AndroidManifest.xml
index 34b32a4..68fb7ab 100644
--- a/src/Notesmaster/app/src/main/AndroidManifest.xml
+++ b/src/Notesmaster/app/src/main/AndroidManifest.xml
@@ -91,6 +91,15 @@
android:resource="@xml/searchable" />
+
+
+
?) AND (" +
+ NoteColumns.TITLE + " LIKE ? OR " +
NoteColumns.SNIPPET + " LIKE ? OR " +
NoteColumns.ID + " IN (SELECT " + DataColumns.NOTE_ID +
" FROM data WHERE " + DataColumns.CONTENT + " LIKE ?))";
String[] selectionArgs = new String[]{
- String.valueOf(Notes.TYPE_NOTE),
+ String.valueOf(Notes.TYPE_SYSTEM),
+ "%" + keyword + "%",
"%" + keyword + "%",
"%" + keyword + "%"
};
diff --git a/src/Notesmaster/app/src/main/java/net/micode/notes/ui/NotesListActivity.java b/src/Notesmaster/app/src/main/java/net/micode/notes/ui/NotesListActivity.java
index 982f0ad..da74a11 100644
--- a/src/Notesmaster/app/src/main/java/net/micode/notes/ui/NotesListActivity.java
+++ b/src/Notesmaster/app/src/main/java/net/micode/notes/ui/NotesListActivity.java
@@ -746,8 +746,8 @@ public class NotesListActivity extends AppCompatActivity
switch (itemId) {
case R.id.menu_search:
- // TODO: 打开搜索对话框
- Toast.makeText(this, "搜索功能开发中", Toast.LENGTH_SHORT).show();
+ Intent searchIntent = new Intent(this, NoteSearchActivity.class);
+ startActivity(searchIntent);
return true;
case R.id.menu_new_folder:
// 创建新文件夹
diff --git a/src/Notesmaster/app/src/main/res/color/primary_text_dark.xml b/src/Notesmaster/app/src/main/res/color/primary_text_dark.xml
deleted file mode 100644
index 7c85459..0000000
--- a/src/Notesmaster/app/src/main/res/color/primary_text_dark.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notesmaster/app/src/main/res/color/secondary_text_dark.xml b/src/Notesmaster/app/src/main/res/color/secondary_text_dark.xml
deleted file mode 100644
index c1c2384..0000000
--- a/src/Notesmaster/app/src/main/res/color/secondary_text_dark.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Notesmaster/app/src/main/res/layout/note_list.xml b/src/Notesmaster/app/src/main/res/layout/note_list.xml
index 21c7ba8..3d88391 100644
--- a/src/Notesmaster/app/src/main/res/layout/note_list.xml
+++ b/src/Notesmaster/app/src/main/res/layout/note_list.xml
@@ -22,7 +22,7 @@
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:background="@drawable/list_background">
+ android:background="@color/background_color">
diff --git a/src/Notesmaster/app/src/main/res/values/colors.xml b/src/Notesmaster/app/src/main/res/values/colors.xml
index 82d81bf..3c01874 100644
--- a/src/Notesmaster/app/src/main/res/values/colors.xml
+++ b/src/Notesmaster/app/src/main/res/values/colors.xml
@@ -17,7 +17,10 @@
#335b5b5b
- #1976D2
+ #263238
#FFFFFF
- #FAFAFA
+ #E8E8E8
+ #000000
+ #808080
+ #FFC107
diff --git a/src/Notesmaster/app/src/main/res/values/strings.xml b/src/Notesmaster/app/src/main/res/values/strings.xml
index c6f38f4..5b212aa 100644
--- a/src/Notesmaster/app/src/main/res/values/strings.xml
+++ b/src/Notesmaster/app/src/main/res/values/strings.xml
@@ -161,4 +161,9 @@
Are you sure you want to delete selected notes?
Unpin
Unlock
+
+
+ No results found
+ Search History
+ Clear
From 269d287c71015260512659c91d20f10c93f7813d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=92=8B=E5=A4=A9=E7=BF=94?=
Date: Mon, 26 Jan 2026 23:44:54 +0800
Subject: [PATCH 2/4] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../notes/tool/SearchHistoryManager.java | 67 +++++++
.../micode/notes/ui/NoteSearchActivity.java | 188 ++++++++++++++++++
.../micode/notes/ui/NoteSearchAdapter.java | 180 +++++++++++++++++
.../main/res/layout/activity_note_search.xml | 68 +++++++
.../main/res/layout/search_history_item.xml | 35 ++++
5 files changed, 538 insertions(+)
create mode 100644 src/Notesmaster/app/src/main/java/net/micode/notes/tool/SearchHistoryManager.java
create mode 100644 src/Notesmaster/app/src/main/java/net/micode/notes/ui/NoteSearchActivity.java
create mode 100644 src/Notesmaster/app/src/main/java/net/micode/notes/ui/NoteSearchAdapter.java
create mode 100644 src/Notesmaster/app/src/main/res/layout/activity_note_search.xml
create mode 100644 src/Notesmaster/app/src/main/res/layout/search_history_item.xml
diff --git a/src/Notesmaster/app/src/main/java/net/micode/notes/tool/SearchHistoryManager.java b/src/Notesmaster/app/src/main/java/net/micode/notes/tool/SearchHistoryManager.java
new file mode 100644
index 0000000..1f3f9b0
--- /dev/null
+++ b/src/Notesmaster/app/src/main/java/net/micode/notes/tool/SearchHistoryManager.java
@@ -0,0 +1,67 @@
+package net.micode.notes.tool;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.text.TextUtils;
+import org.json.JSONArray;
+import org.json.JSONException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class SearchHistoryManager {
+ private static final String PREF_NAME = "search_history";
+ private static final String KEY_HISTORY = "history_list";
+ private static final int MAX_HISTORY_SIZE = 10;
+
+ private final SharedPreferences mPrefs;
+
+ public SearchHistoryManager(Context context) {
+ mPrefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
+ }
+
+ public List getHistory() {
+ String json = mPrefs.getString(KEY_HISTORY, "");
+ List list = new ArrayList<>();
+ if (TextUtils.isEmpty(json)) {
+ return list;
+ }
+ try {
+ JSONArray array = new JSONArray(json);
+ for (int i = 0; i < array.length(); i++) {
+ list.add(array.getString(i));
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return list;
+ }
+
+ public void addHistory(String keyword) {
+ if (TextUtils.isEmpty(keyword)) return;
+ List history = getHistory();
+ // Remove existing to move to top
+ history.remove(keyword);
+ history.add(0, keyword);
+ // Limit size
+ if (history.size() > MAX_HISTORY_SIZE) {
+ history = history.subList(0, MAX_HISTORY_SIZE);
+ }
+ saveHistory(history);
+ }
+
+ public void removeHistory(String keyword) {
+ List history = getHistory();
+ if (history.remove(keyword)) {
+ saveHistory(history);
+ }
+ }
+
+ public void clearHistory() {
+ mPrefs.edit().remove(KEY_HISTORY).apply();
+ }
+
+ private void saveHistory(List history) {
+ JSONArray array = new JSONArray(history);
+ mPrefs.edit().putString(KEY_HISTORY, array.toString()).apply();
+ }
+}
diff --git a/src/Notesmaster/app/src/main/java/net/micode/notes/ui/NoteSearchActivity.java b/src/Notesmaster/app/src/main/java/net/micode/notes/ui/NoteSearchActivity.java
new file mode 100644
index 0000000..523120b
--- /dev/null
+++ b/src/Notesmaster/app/src/main/java/net/micode/notes/ui/NoteSearchActivity.java
@@ -0,0 +1,188 @@
+package net.micode.notes.ui;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.view.View;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.widget.SearchView;
+import androidx.appcompat.widget.Toolbar;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import net.micode.notes.R;
+import net.micode.notes.data.Notes;
+import net.micode.notes.data.NotesRepository;
+import net.micode.notes.tool.SearchHistoryManager;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class NoteSearchActivity extends AppCompatActivity implements SearchView.OnQueryTextListener, NoteSearchAdapter.OnItemClickListener {
+
+ private SearchView mSearchView;
+ private RecyclerView mRecyclerView;
+ private TextView mTvNoResult;
+ private NoteSearchAdapter mAdapter;
+ private NotesRepository mRepository;
+ private SearchHistoryManager mHistoryManager;
+
+ private TextView mBtnShowHistory;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_note_search);
+
+ mRepository = new NotesRepository(getContentResolver());
+ mHistoryManager = new SearchHistoryManager(this);
+
+ initViews();
+ // Initial state: search is empty, show history button if there is history, or just show list
+ // Requirement: "history option below search bar"
+ showHistoryOption();
+ }
+
+ private void initViews() {
+ Toolbar toolbar = findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+ if (getSupportActionBar() != null) {
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+ toolbar.setNavigationOnClickListener(v -> finish());
+
+ mSearchView = findViewById(R.id.search_view);
+ mSearchView.setOnQueryTextListener(this);
+ mSearchView.setFocusable(true);
+ mSearchView.setIconified(false);
+ mSearchView.requestFocusFromTouch();
+
+ mBtnShowHistory = findViewById(R.id.btn_show_history);
+ mBtnShowHistory.setOnClickListener(v -> showHistoryList());
+
+ mRecyclerView = findViewById(R.id.recycler_view);
+ mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
+ mAdapter = new NoteSearchAdapter(this, this);
+ mRecyclerView.setAdapter(mAdapter);
+
+ mTvNoResult = findViewById(R.id.tv_no_result);
+ }
+
+ private void showHistoryOption() {
+ // Show the "History" button, hide the list
+ mBtnShowHistory.setVisibility(View.VISIBLE);
+ mRecyclerView.setVisibility(View.GONE);
+ mTvNoResult.setVisibility(View.GONE);
+ }
+
+ private void showHistoryList() {
+ List history = mHistoryManager.getHistory();
+ if (history.isEmpty()) {
+ // If no history, maybe show a toast or empty state?
+ // But for now, let's just show the empty list which is fine
+ }
+ List
- *
- * 该类继承自PreferenceActivity,使用SharedPreferences来持久化设置数据。
- * 通过GTaskReceiver接收同步服务的广播,实时更新同步状态。
- *
- */
-public class NotesPreferenceActivity extends PreferenceActivity {
- /**
- * SharedPreferences文件名
- */
public static final String PREFERENCE_NAME = "notes_preferences";
-
- /**
- * 同步账户名称的SharedPreferences键
- */
public static final String PREFERENCE_SYNC_ACCOUNT_NAME = "pref_key_account_name";
-
- /**
- * 最后同步时间的SharedPreferences键
- */
- public static final String PREFERENCE_LAST_SYNC_TIME = "pref_last_sync_time";
-
- /**
- * 背景颜色随机显示设置的SharedPreferences键
- */
public static final String PREFERENCE_SET_BG_COLOR_KEY = "pref_key_bg_random_appear";
- public static final String PREFERENCE_SECURITY_KEY = "pref_key_security";
- public static final int REQUEST_CODE_CHECK_PASSWORD = 104;
-
- /**
- * 同步账户分类的Preference键
- */
- private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key";
-
- /**
- * 账户授权过滤器键,用于添加账户Intent
- */
- private static final String AUTHORITIES_FILTER_KEY = "authorities";
-
- /**
- * 同步账户分类的PreferenceCategory
- */
- private PreferenceCategory mAccountCategory;
-
- /**
- * 同步服务广播接收器
- */
- private GTaskReceiver mReceiver;
-
- /**
- * 设置头部视图绑定
- */
- private SettingsHeaderBinding mHeaderBinding;
-
- /**
- * 原始账户数组,用于检测新增账户
- */
- private Account[] mOriAccounts;
-
- /**
- * 是否添加了新账户的标志
- */
- private boolean mHasAddedAccount;
-
- /**
- * 创建Activity
- *
- * 初始化设置界面,包括:
- *
- * - 启用ActionBar的返回导航
- * - 加载preferences.xml配置文件
- * - 初始化账户分类和广播接收器
- * - 添加设置界面头部视图
- *
- *
- * @param icicle 保存的实例状态
- */
- @Override
- protected void onCreate(Bundle icicle) {
- super.onCreate(icicle);
-
- /* using the app icon for navigation */
- getActionBar().setDisplayHomeAsUpEnabled(true);
-
- addPreferencesFromResource(R.xml.preferences);
- mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);
- // Google Tasks同步功能已禁用
- // mReceiver = new GTaskReceiver();
- // IntentFilter filter = new IntentFilter();
- // filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME);
- //registerReceiver(mReceiver, filter);
- // if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
- // // Android 13 (API 33) 及以上版本需要指定导出标志
- // registerReceiver(mReceiver, filter, Context.RECEIVER_NOT_EXPORTED);
- // } else {
- // // Android 12 及以下版本使用旧方法
- // registerReceiver(mReceiver, filter);
- // }
- mOriAccounts = null;
- mHeaderBinding = SettingsHeaderBinding.inflate(getLayoutInflater());
- getListView().addHeaderView(mHeaderBinding.getRoot(), null, true);
-
- loadSecurityPreference();
- }
-
- /**
- * Activity恢复时调用
- *
- * 检查是否有新添加的Google账户,如果有则自动设置为同步账户。
- * 然后刷新UI显示。
- *
- */
@Override
- protected void onResume() {
- super.onResume();
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_settings);
- // need to set sync account automatically if user has added a new
- // account
- if (mHasAddedAccount) {
- Account[] accounts = getGoogleAccounts();
- if (mOriAccounts != null && accounts.length > mOriAccounts.length) {
- for (Account accountNew : accounts) {
- boolean found = false;
- for (Account accountOld : mOriAccounts) {
- if (TextUtils.equals(accountOld.name, accountNew.name)) {
- found = true;
- break;
- }
- }
- if (!found) {
- setSyncAccount(accountNew.name);
- break;
- }
- }
- }
+ if (getSupportActionBar() != null) {
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ getSupportActionBar().setTitle(R.string.preferences_title);
}
- refreshUI();
- }
-
- /**
- * Activity销毁时调用
- *
- * 注销同步服务广播接收器,防止内存泄漏。
- *
- */
- @Override
- protected void onDestroy() {
- // Google Tasks同步功能已禁用
- // if (mReceiver != null) {
- // unregisterReceiver(mReceiver);
- // }
- mHeaderBinding = null;
- super.onDestroy();
- }
-
- private void loadSecurityPreference() {
- Preference securityPref = findPreference(PREFERENCE_SECURITY_KEY);
- if (securityPref != null) {
- securityPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- if (!SecurityManager.getInstance(NotesPreferenceActivity.this).isPasswordSet()) {
- showSetPasswordDialog();
- } else {
- Intent intent = new Intent(NotesPreferenceActivity.this, PasswordActivity.class);
- intent.setAction(PasswordActivity.ACTION_CHECK_PASSWORD);
- startActivityForResult(intent, REQUEST_CODE_CHECK_PASSWORD);
- }
- return true;
- }
- });
- }
- }
-
- private void showSetPasswordDialog() {
- new AlertDialog.Builder(this)
- .setTitle("设置密码")
- .setItems(new String[]{"数字锁", "手势锁"}, (dialog, which) -> {
- int type = (which == 0) ? SecurityManager.TYPE_PIN : SecurityManager.TYPE_PATTERN;
- Intent intent = new Intent(this, PasswordActivity.class);
- intent.setAction(PasswordActivity.ACTION_SETUP_PASSWORD);
- intent.putExtra(PasswordActivity.EXTRA_PASSWORD_TYPE, type);
- startActivity(intent);
- })
- .show();
- }
-
- private void showManagePasswordDialog() {
- new AlertDialog.Builder(this)
- .setTitle("管理密码")
- .setItems(new String[]{"更改密码", "取消密码"}, (dialog, which) -> {
- if (which == 0) { // Change
- showSetPasswordDialog();
- } else { // Remove
- SecurityManager.getInstance(this).removePassword();
- Toast.makeText(this, "密码已取消", Toast.LENGTH_SHORT).show();
- }
- })
- .show();
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == REQUEST_CODE_CHECK_PASSWORD && resultCode == RESULT_OK) {
- showManagePasswordDialog();
+ if (savedInstanceState == null) {
+ getSupportFragmentManager()
+ .beginTransaction()
+ .replace(R.id.settings_container, new SettingsFragment())
+ .commit();
}
- }
-
- /**
- * 加载账户设置选项
- *
- * 创建并添加账户Preference到账户分类中。
- * 点击该Preference时:
- *
- * - 如果未设置账户,显示账户选择对话框
- * - 如果已设置账户,显示确认更改账户对话框
- * - 如果正在同步,显示提示消息
- *
- *
- */
- private void loadAccountPreference() {
- mAccountCategory.removeAll();
- Preference accountPref = new Preference(this);
- final String defaultAccount = getSyncAccountName(this);
- accountPref.setTitle(getString(R.string.preferences_account_title));
- accountPref.setSummary(getString(R.string.preferences_account_summary));
- accountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
- public boolean onPreferenceClick(Preference preference) {
- // Google Tasks同步功能已禁用
- // if (!GTaskSyncService.isSyncing()) {
- // if (TextUtils.isEmpty(defaultAccount)) {
- // // first time to set account
- // showSelectAccountAlertDialog();
- // } else {
- // // if account has already been set, we need to promp
- // // user about risk
- // showChangeAccountConfirmAlertDialog();
- // }
- // } else {
- // Toast.makeText(NotesPreferenceActivity.this,
- // R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT)
- // .show();
- // }
- Toast.makeText(NotesPreferenceActivity.this,
- "Google Tasks同步功能已禁用", Toast.LENGTH_SHORT)
- .show();
- return true;
- }
- });
-
- mAccountCategory.addPreference(accountPref);
+ loadSyncButton();
}
- /**
- * 加载同步按钮和同步状态显示
- *
- * 根据当前同步状态设置按钮文本和点击事件:
- *
- * - 正在同步:显示"取消同步"按钮,点击取消同步
- * - 未同步:显示"立即同步"按钮,点击开始同步
- *
- * 同时显示最后同步时间或当前同步进度。
- *
- */
private void loadSyncButton() {
- Button syncButton = mHeaderBinding.preferenceSyncButton;
- TextView lastSyncTimeView = mHeaderBinding.prefenereceSyncStatusTextview;
+ Button syncButton = findViewById(R.id.preference_sync_button);
+ TextView lastSyncTimeView = findViewById(R.id.prefenerece_sync_status_textview);
// Google Tasks同步功能已禁用
- // set button state
- // if (GTaskSyncService.isSyncing()) {
- // syncButton.setText(getString(R.string.preferences_button_sync_cancel));
- // syncButton.setOnClickListener(new View.OnClickListener() {
- // public void onClick(View v) {
- // GTaskSyncService.cancelSync(NotesPreferenceActivity.this);
- // }
- // });
- // } else {
- // syncButton.setText(getString(R.string.preferences_button_sync_immediately));
- // syncButton.setOnClickListener(new View.OnClickListener() {
- // public void onClick(View v) {
- // GTaskSyncService.startSync(NotesPreferenceActivity.this);
- // }
- // });
- // }
- // syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this)));
-
- // 禁用同步按钮
syncButton.setEnabled(false);
syncButton.setText("同步功能已禁用");
- // set last sync time
- // if (GTaskSyncService.isSyncing()) {
- // lastSyncTimeView.setText(GTaskSyncService.getProgressString());
- // lastSyncTimeView.setVisibility(View.VISIBLE);
- // } else {
- // long lastSyncTime = getLastSyncTime(this);
- // if (lastSyncTime != 0) {
- // lastSyncTimeView.setText(getString(R.string.preferences_last_sync_time,
- // DateFormat.format(getString(R.string.preferences_last_sync_time_format),
- // lastSyncTime)));
- // lastSyncTimeView.setVisibility(View.VISIBLE);
- // } else {
- // lastSyncTimeView.setVisibility(View.GONE);
- // }
- // }
-
lastSyncTimeView.setText("Google Tasks同步功能已禁用");
lastSyncTimeView.setVisibility(View.VISIBLE);
}
- /**
- * 刷新UI显示
- *
- * 重新加载账户设置选项和同步按钮状态。
- *
- */
- private void refreshUI() {
- loadAccountPreference();
- loadSyncButton();
- }
-
- /**
- * 显示选择账户对话框
- *
- * 显示一个对话框,列出所有可用的Google账户供用户选择。
- * 同时提供"添加账户"选项,点击后跳转到系统账户添加界面。
- *
- */
- private void showSelectAccountAlertDialog() {
- AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
-
- View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
- TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
- titleTextView.setText(getString(R.string.preferences_dialog_select_account_title));
- TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
- subtitleTextView.setText(getString(R.string.preferences_dialog_select_account_tips));
-
- dialogBuilder.setCustomTitle(titleView);
- dialogBuilder.setPositiveButton(null, null);
-
- Account[] accounts = getGoogleAccounts();
- String defAccount = getSyncAccountName(this);
-
- mOriAccounts = accounts;
- mHasAddedAccount = false;
-
- if (accounts.length > 0) {
- CharSequence[] items = new CharSequence[accounts.length];
- final CharSequence[] itemMapping = items;
- int checkedItem = -1;
- int index = 0;
- for (Account account : accounts) {
- if (TextUtils.equals(account.name, defAccount)) {
- checkedItem = index;
- }
- items[index++] = account.name;
- }
- dialogBuilder.setSingleChoiceItems(items, checkedItem,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- setSyncAccount(itemMapping[which].toString());
- dialog.dismiss();
- refreshUI();
- }
- });
- }
-
- View addAccountView = LayoutInflater.from(this).inflate(R.layout.add_account_text, null);
- dialogBuilder.setView(addAccountView);
-
- final AlertDialog dialog = dialogBuilder.show();
- addAccountView.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- mHasAddedAccount = true;
- Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
- intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] {
- "gmail-ls"
- });
- startActivityForResult(intent, -1);
- dialog.dismiss();
- }
- });
- }
-
- /**
- * 显示更改账户确认对话框
- *
- * 显示一个对话框,提供三个选项:
- *
- * - 更改账户:显示账户选择对话框
- * - 移除账户:删除当前同步账户并清理相关数据
- * - 取消:关闭对话框
- *
- *
- */
- private void showChangeAccountConfirmAlertDialog() {
- AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
-
- View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
- TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
- titleTextView.setText(getString(R.string.preferences_dialog_change_account_title,
- getSyncAccountName(this)));
- TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
- subtitleTextView.setText(getString(R.string.preferences_dialog_change_account_warn_msg));
- dialogBuilder.setCustomTitle(titleView);
-
- CharSequence[] menuItemArray = new CharSequence[] {
- getString(R.string.preferences_menu_change_account),
- getString(R.string.preferences_menu_remove_account),
- getString(R.string.preferences_menu_cancel)
- };
- dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- if (which == 0) {
- showSelectAccountAlertDialog();
- } else if (which == 1) {
- removeSyncAccount();
- refreshUI();
- }
- }
- });
- dialogBuilder.show();
- }
-
- /**
- * 获取所有Google账户
- *
- * 从系统AccountManager中获取所有类型为"com.google"的账户。
- *
- * @return Google账户数组
- */
- private Account[] getGoogleAccounts() {
- AccountManager accountManager = AccountManager.get(this);
- return accountManager.getAccountsByType("com.google");
- }
-
- /**
- * 设置同步账户
- *
- * 保存指定的账户名称到SharedPreferences,并清理相关数据:
- *
- * - 清除最后同步时间
- * - 清除所有笔记的GTASK_ID和SYNC_ID
- *
- *
- * @param account 要设置的账户名称
- */
- private void setSyncAccount(String account) {
- if (!getSyncAccountName(this).equals(account)) {
- SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = settings.edit();
- if (account != null) {
- editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, account);
- } else {
- editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
- }
- editor.commit();
-
- // clean up last sync time
- setLastSyncTime(this, 0);
-
- // clean up local gtask related info
- new Thread(new Runnable() {
- public void run() {
- ContentValues values = new ContentValues();
- values.put(NoteColumns.GTASK_ID, "");
- values.put(NoteColumns.SYNC_ID, 0);
- getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
- }
- }).start();
-
- Toast.makeText(NotesPreferenceActivity.this,
- getString(R.string.preferences_toast_success_set_accout, account),
- Toast.LENGTH_SHORT).show();
- }
- }
-
- /**
- * 移除同步账户
- *
- * 从SharedPreferences中删除同步账户和最后同步时间,
- * 并清理所有笔记的GTASK_ID和SYNC_ID。
- *
- */
- private void removeSyncAccount() {
- SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = settings.edit();
- if (settings.contains(PREFERENCE_SYNC_ACCOUNT_NAME)) {
- editor.remove(PREFERENCE_SYNC_ACCOUNT_NAME);
- }
- if (settings.contains(PREFERENCE_LAST_SYNC_TIME)) {
- editor.remove(PREFERENCE_LAST_SYNC_TIME);
- }
- editor.commit();
-
- // clean up local gtask related info
- new Thread(new Runnable() {
- public void run() {
- ContentValues values = new ContentValues();
- values.put(NoteColumns.GTASK_ID, "");
- values.put(NoteColumns.SYNC_ID, 0);
- getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
- }
- }).start();
- }
-
- /**
- * 获取同步账户名称
- *
- * 从SharedPreferences中读取已设置的同步账户名称。
- *
- * @param context 上下文对象
- * @return 同步账户名称,如果未设置则返回空字符串
- */
- public static String getSyncAccountName(Context context) {
- SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
- Context.MODE_PRIVATE);
+ public static String getSyncAccountName(android.content.Context context) {
+ android.content.SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, android.content.Context.MODE_PRIVATE);
return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
}
- /**
- * 设置最后同步时间
- *
- * 将指定的同步时间保存到SharedPreferences。
- *
- * @param context 上下文对象
- * @param time 同步时间戳
- */
- public static void setLastSyncTime(Context context, long time) {
- SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
- Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = settings.edit();
- editor.putLong(PREFERENCE_LAST_SYNC_TIME, time);
- editor.commit();
- }
-
- /**
- * 获取最后同步时间
- *
- * 从SharedPreferences中读取最后同步时间。
- *
- * @param context 上下文对象
- * @return 最后同步时间戳,如果未同步过则返回0
- */
- public static long getLastSyncTime(Context context) {
- SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
- Context.MODE_PRIVATE);
- return settings.getLong(PREFERENCE_LAST_SYNC_TIME, 0);
- }
-
- /**
- * 同步服务广播接收器
- *
- * 接收GTaskSyncService发送的广播,实时更新UI显示同步状态和进度。
- *
- */
- private class GTaskReceiver extends BroadcastReceiver {
-
- /**
- * 接收广播
- *
- * 当收到同步服务广播时,刷新UI并更新同步状态显示。
- *
- * @param context 上下文对象
- * @param intent 广播Intent
- */
- @Override
- public void onReceive(Context context, Intent intent) {
- refreshUI();
- // Google Tasks同步功能已禁用
- // if (intent.getBooleanExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_IS_SYNCING, false)) {
- // TextView syncStatus = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
- // syncStatus.setText(intent
- // .getStringExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_PROGRESS_MSG));
- // }
-
- }
- }
-
- /**
- * 处理菜单项选择
- *
- * 处理ActionBar上的菜单项点击事件。
- * 当点击返回按钮时,返回到笔记列表界面。
- *
- * @param item 被点击的菜单项
- * @return true表示已处理,false表示未处理
- */
+ @Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
diff --git a/src/Notesmaster/app/src/main/res/layout/note_edit.xml b/src/Notesmaster/app/src/main/res/layout/note_edit.xml
index b0b9e28..aba7781 100644
--- a/src/Notesmaster/app/src/main/res/layout/note_edit.xml
+++ b/src/Notesmaster/app/src/main/res/layout/note_edit.xml
@@ -170,112 +170,16 @@
android:layout_marginTop="30dp"
android:layout_marginRight="8dp"
android:layout_gravity="top|right"
- android:visibility="gone">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ android:visibility="gone"
+ android:orientation="horizontal">
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Notesmaster/app/src/main/res/menu/note_edit.xml b/src/Notesmaster/app/src/main/res/menu/note_edit.xml
index 35cacd1..bff7ff4 100644
--- a/src/Notesmaster/app/src/main/res/menu/note_edit.xml
+++ b/src/Notesmaster/app/src/main/res/menu/note_edit.xml
@@ -16,12 +16,35 @@
-->