From c71ce7fa262574818a74f0732faed48459f4e53a Mon Sep 17 00:00:00 2001 From: ranhao <2352406715@qq.com> Date: Mon, 19 Jan 2026 19:47:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E4=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/notes/tool/ElderModeUtils.java | 109 +++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/notes/tool/ElderModeUtils.java diff --git a/src/notes/tool/ElderModeUtils.java b/src/notes/tool/ElderModeUtils.java new file mode 100644 index 0000000..11f4132 --- /dev/null +++ b/src/notes/tool/ElderModeUtils.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2026, 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.preference.PreferenceManager; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import net.micode.notes.R; +import net.micode.notes.ui.NotesPreferenceActivity; + +/** + * 老年人模式工具类,用于管理老年人模式的设置和应用 + */ +public class ElderModeUtils { + /** + * 老年人模式的字体缩放比例 + */ + private static final float ELDER_MODE_FONT_SCALE = 1.1f; + + /** + * 检查是否启用了老年人模式 + * + * @param context 上下文 + * @return 是否启用了老年人模式 + */ + public static boolean isElderModeEnabled(Context context) { + // 使用默认的SharedPreferences,因为CheckBoxPreference会自动保存到这里 + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + return preferences.getBoolean(NotesPreferenceActivity.PREFERENCE_ELDER_MODE_KEY, false); + } + + /** + * 应用老年人模式到指定的View + * + * @param context 上下文 + * @param view 要应用老年人模式的View + */ + public static void applyElderMode(Context context, View view) { + if (!isElderModeEnabled(context)) { + return; + } + + // 只对用户输入的内容应用字体增大,系统信息保持不变 + if (view instanceof TextView) { + TextView textView = (TextView) view; + int id = textView.getId(); + + // 只增大用户输入内容的字体 + if (id == R.id.tv_title || // 笔记列表中的标题(用户输入内容) + id == R.id.note_edit_view) { // 编辑界面中的内容(用户输入) + textView.setTextSize(textView.getTextSize() * ELDER_MODE_FONT_SCALE); + } + } else if (view instanceof ViewGroup) { + // 递归处理ViewGroup中的所有子View + ViewGroup viewGroup = (ViewGroup) view; + for (int i = 0; i < viewGroup.getChildCount(); i++) { + applyElderMode(context, viewGroup.getChildAt(i)); + } + } + } + + /** + * 清除老年人模式的应用 + * + * @param context 上下文 + * @param view 要清除老年人模式的View + */ + public static void clearElderMode(Context context, View view) { + if (!isElderModeEnabled(context)) { + return; + } + + // 只对用户输入的内容应用字体恢复,系统信息保持不变 + if (view instanceof TextView) { + TextView textView = (TextView) view; + int id = textView.getId(); + + // 只恢复用户输入内容的字体 + if (id == R.id.tv_title || // 笔记列表中的标题(用户输入内容) + id == R.id.note_edit_view) { // 编辑界面中的内容(用户输入) + textView.setTextSize(textView.getTextSize() / ELDER_MODE_FONT_SCALE); + } + } else if (view instanceof ViewGroup) { + // 递归处理ViewGroup中的所有子View + ViewGroup viewGroup = (ViewGroup) view; + for (int i = 0; i < viewGroup.getChildCount(); i++) { + clearElderMode(context, viewGroup.getChildAt(i)); + } + } + } +} \ No newline at end of file