|
|
|
|
@ -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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|