pull/8/head
ranhao 1 month ago
parent 971c304015
commit c71ce7fa26

@ -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));
}
}
}
}
Loading…
Cancel
Save