|
|
|
@ -17,165 +17,469 @@
|
|
|
|
|
package net.micode.notes.tool;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.res.Resources;
|
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
import android.util.SparseIntArray;
|
|
|
|
|
|
|
|
|
|
import net.micode.notes.R;
|
|
|
|
|
import net.micode.notes.ui.NotesPreferenceActivity;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 资源解析工具类 - 提供笔记应用中各种UI资源的统一管理
|
|
|
|
|
* 功能包括:
|
|
|
|
|
* 1. 笔记背景资源管理
|
|
|
|
|
* 2. 笔记布局资源管理
|
|
|
|
|
* 3. 小部件资源管理
|
|
|
|
|
* 4. 文本外观资源管理
|
|
|
|
|
*
|
|
|
|
|
* 设计原则:
|
|
|
|
|
* - 资源ID与语义常量分离
|
|
|
|
|
* - 添加深色模式支持
|
|
|
|
|
* - 增强资源选择的灵活性
|
|
|
|
|
*/
|
|
|
|
|
public class ResourceParser {
|
|
|
|
|
|
|
|
|
|
public static final int YELLOW = 0;
|
|
|
|
|
public static final int BLUE = 1;
|
|
|
|
|
public static final int WHITE = 2;
|
|
|
|
|
public static final int GREEN = 3;
|
|
|
|
|
public static final int RED = 4;
|
|
|
|
|
// 防止实例化
|
|
|
|
|
private ResourceParser() {
|
|
|
|
|
throw new AssertionError("This class cannot be instantiated");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ================== 颜色常量枚举 ================== */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 预定义颜色类型枚举
|
|
|
|
|
*/
|
|
|
|
|
public enum NoteColor {
|
|
|
|
|
YELLOW(0),
|
|
|
|
|
BLUE(1),
|
|
|
|
|
WHITE(2),
|
|
|
|
|
GREEN(3),
|
|
|
|
|
RED(4),
|
|
|
|
|
// 扩展更多颜色选项
|
|
|
|
|
PURPLE(5),
|
|
|
|
|
ORANGE(6);
|
|
|
|
|
|
|
|
|
|
public static final int BG_DEFAULT_COLOR = YELLOW;
|
|
|
|
|
public final int id;
|
|
|
|
|
|
|
|
|
|
public static final int TEXT_SMALL = 0;
|
|
|
|
|
public static final int TEXT_MEDIUM = 1;
|
|
|
|
|
public static final int TEXT_LARGE = 2;
|
|
|
|
|
public static final int TEXT_SUPER = 3;
|
|
|
|
|
NoteColor(int id) {
|
|
|
|
|
this.id = id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final int DEFAULT_ID = YELLOW.id;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取默认颜色ID
|
|
|
|
|
*/
|
|
|
|
|
public static int getDefault() {
|
|
|
|
|
return DEFAULT_ID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
|
|
|
|
|
/**
|
|
|
|
|
* 从整数值获取颜色枚举
|
|
|
|
|
*/
|
|
|
|
|
public static NoteColor fromId(int id) {
|
|
|
|
|
for (NoteColor color : values()) {
|
|
|
|
|
if (color.id == id) {
|
|
|
|
|
return color;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return YELLOW;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ================== 字体大小常量枚举 ================== */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 预定义字体大小类型枚举
|
|
|
|
|
*/
|
|
|
|
|
public enum FontSize {
|
|
|
|
|
SMALL(0),
|
|
|
|
|
MEDIUM(1),
|
|
|
|
|
LARGE(2),
|
|
|
|
|
SUPER(3);
|
|
|
|
|
|
|
|
|
|
public final int id;
|
|
|
|
|
|
|
|
|
|
FontSize(int id) {
|
|
|
|
|
this.id = id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final int DEFAULT_ID = MEDIUM.id;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取默认字体大小ID
|
|
|
|
|
*/
|
|
|
|
|
public static int getDefault() {
|
|
|
|
|
return DEFAULT_ID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ================== 主题模式常量 ================== */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 应用主题模式
|
|
|
|
|
*/
|
|
|
|
|
public enum ThemeMode {
|
|
|
|
|
LIGHT(0),
|
|
|
|
|
DARK(1),
|
|
|
|
|
AUTO(2);
|
|
|
|
|
|
|
|
|
|
public final int id;
|
|
|
|
|
|
|
|
|
|
ThemeMode(int id) {
|
|
|
|
|
this.id = id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ThemeMode fromId(int id) {
|
|
|
|
|
switch (id) {
|
|
|
|
|
case 1: return DARK;
|
|
|
|
|
case 2: return AUTO;
|
|
|
|
|
default: return LIGHT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ================== 笔记背景资源管理 ================== */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 笔记背景资源集合
|
|
|
|
|
*/
|
|
|
|
|
public static class NoteBgResources {
|
|
|
|
|
private final static int [] BG_EDIT_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.edit_yellow,
|
|
|
|
|
R.drawable.edit_blue,
|
|
|
|
|
R.drawable.edit_white,
|
|
|
|
|
R.drawable.edit_green,
|
|
|
|
|
R.drawable.edit_red
|
|
|
|
|
};
|
|
|
|
|
// 编辑界面背景资源
|
|
|
|
|
private static final SparseIntArray BG_EDIT_RESOURCES = new SparseIntArray();
|
|
|
|
|
|
|
|
|
|
private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.edit_title_yellow,
|
|
|
|
|
R.drawable.edit_title_blue,
|
|
|
|
|
R.drawable.edit_title_white,
|
|
|
|
|
R.drawable.edit_title_green,
|
|
|
|
|
R.drawable.edit_title_red
|
|
|
|
|
};
|
|
|
|
|
// 编辑界面标题背景资源
|
|
|
|
|
private static final SparseIntArray BG_EDIT_TITLE_RESOURCES = new SparseIntArray();
|
|
|
|
|
|
|
|
|
|
public static int getNoteBgResource(int id) {
|
|
|
|
|
return BG_EDIT_RESOURCES[id];
|
|
|
|
|
// 静态初始化资源映射
|
|
|
|
|
static {
|
|
|
|
|
// 浅色主题资源
|
|
|
|
|
BG_EDIT_RESOURCES.put(NoteColor.YELLOW.id, R.drawable.edit_yellow);
|
|
|
|
|
BG_EDIT_RESOURCES.put(NoteColor.BLUE.id, R.drawable.edit_blue);
|
|
|
|
|
BG_EDIT_RESOURCES.put(NoteColor.WHITE.id, R.drawable.edit_white);
|
|
|
|
|
BG_EDIT_RESOURCES.put(NoteColor.GREEN.id, R.drawable.edit_green);
|
|
|
|
|
BG_EDIT_RESOURCES.put(NoteColor.RED.id, R.drawable.edit_red);
|
|
|
|
|
BG_EDIT_RESOURCES.put(NoteColor.PURPLE.id, R.drawable.edit_purple);
|
|
|
|
|
BG_EDIT_RESOURCES.put(NoteColor.ORANGE.id, R.drawable.edit_orange);
|
|
|
|
|
|
|
|
|
|
BG_EDIT_TITLE_RESOURCES.put(NoteColor.YELLOW.id, R.drawable.edit_title_yellow);
|
|
|
|
|
BG_EDIT_TITLE_RESOURCES.put(NoteColor.BLUE.id, R.drawable.edit_title_blue);
|
|
|
|
|
BG_EDIT_TITLE_RESOURCES.put(NoteColor.WHITE.id, R.drawable.edit_title_white);
|
|
|
|
|
BG_EDIT_TITLE_RESOURCES.put(NoteColor.GREEN.id, R.drawable.edit_title_green);
|
|
|
|
|
BG_EDIT_TITLE_RESOURCES.put(NoteColor.RED.id, R.drawable.edit_title_red);
|
|
|
|
|
BG_EDIT_TITLE_RESOURCES.put(NoteColor.PURPLE.id, R.drawable.edit_title_purple);
|
|
|
|
|
BG_EDIT_TITLE_RESOURCES.put(NoteColor.ORANGE.id, R.drawable.edit_title_orange);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int getNoteTitleBgResource(int id) {
|
|
|
|
|
return BG_EDIT_TITLE_RESOURCES[id];
|
|
|
|
|
/**
|
|
|
|
|
* 获取笔记编辑背景资源ID
|
|
|
|
|
*
|
|
|
|
|
* @param colorId 颜色ID
|
|
|
|
|
* @return 对应的背景资源ID
|
|
|
|
|
*/
|
|
|
|
|
public static int getNoteBgResource(int colorId) {
|
|
|
|
|
return BG_EDIT_RESOURCES.get(colorId, R.drawable.edit_yellow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取笔记标题背景资源ID
|
|
|
|
|
*
|
|
|
|
|
* @param colorId 颜色ID
|
|
|
|
|
* @return 对应的标题背景资源ID
|
|
|
|
|
*/
|
|
|
|
|
public static int getNoteTitleBgResource(int colorId) {
|
|
|
|
|
return BG_EDIT_TITLE_RESOURCES.get(colorId, R.drawable.edit_title_yellow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取支持的颜色ID数组
|
|
|
|
|
* @return 所有可用的颜色ID数组
|
|
|
|
|
*/
|
|
|
|
|
public static int[] getAvailableColorIds() {
|
|
|
|
|
int[] ids = new int[BG_EDIT_RESOURCES.size()];
|
|
|
|
|
for (int i = 0; i < BG_EDIT_RESOURCES.size(); i++) {
|
|
|
|
|
ids[i] = BG_EDIT_RESOURCES.keyAt(i);
|
|
|
|
|
}
|
|
|
|
|
return ids;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取默认背景颜色ID
|
|
|
|
|
*
|
|
|
|
|
* @param context 上下文对象
|
|
|
|
|
* @return 背景颜色ID
|
|
|
|
|
*/
|
|
|
|
|
public static int getDefaultBgId(Context context) {
|
|
|
|
|
// 检查是否启用随机背景颜色
|
|
|
|
|
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
|
|
|
|
|
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
|
|
|
|
|
return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length);
|
|
|
|
|
} else {
|
|
|
|
|
return BG_DEFAULT_COLOR;
|
|
|
|
|
// 获取所有可用颜色ID
|
|
|
|
|
int[] colorIds = NoteBgResources.getAvailableColorIds();
|
|
|
|
|
if (colorIds.length > 0) {
|
|
|
|
|
return colorIds[(int) (Math.random() * colorIds.length)];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 返回默认颜色
|
|
|
|
|
return NoteColor.getDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class NoteItemBgResources {
|
|
|
|
|
private final static int [] BG_FIRST_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.list_yellow_up,
|
|
|
|
|
R.drawable.list_blue_up,
|
|
|
|
|
R.drawable.list_white_up,
|
|
|
|
|
R.drawable.list_green_up,
|
|
|
|
|
R.drawable.list_red_up
|
|
|
|
|
};
|
|
|
|
|
/* ================== 笔记布局资源管理 ================== */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 笔记布局资源集合
|
|
|
|
|
*/
|
|
|
|
|
public static class NoteLayoutResources {
|
|
|
|
|
// 列表顶部背景资源
|
|
|
|
|
private static final SparseIntArray BG_FIRST_RESOURCES = new SparseIntArray();
|
|
|
|
|
|
|
|
|
|
// 列表中部背景资源
|
|
|
|
|
private static final SparseIntArray BG_NORMAL_RESOURCES = new SparseIntArray();
|
|
|
|
|
|
|
|
|
|
// 列表底部背景资源
|
|
|
|
|
private static final SparseIntArray BG_LAST_RESOURCES = new SparseIntArray();
|
|
|
|
|
|
|
|
|
|
private final static int [] BG_NORMAL_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.list_yellow_middle,
|
|
|
|
|
R.drawable.list_blue_middle,
|
|
|
|
|
R.drawable.list_white_middle,
|
|
|
|
|
R.drawable.list_green_middle,
|
|
|
|
|
R.drawable.list_red_middle
|
|
|
|
|
};
|
|
|
|
|
// 单条笔记背景资源
|
|
|
|
|
private static final SparseIntArray BG_SINGLE_RESOURCES = new SparseIntArray();
|
|
|
|
|
|
|
|
|
|
private final static int [] BG_LAST_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.list_yellow_down,
|
|
|
|
|
R.drawable.list_blue_down,
|
|
|
|
|
R.drawable.list_white_down,
|
|
|
|
|
R.drawable.list_green_down,
|
|
|
|
|
R.drawable.list_red_down,
|
|
|
|
|
};
|
|
|
|
|
// 文件夹背景资源
|
|
|
|
|
private static final SparseIntArray BG_FOLDER_RESOURCES = new SparseIntArray();
|
|
|
|
|
|
|
|
|
|
private final static int [] BG_SINGLE_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.list_yellow_single,
|
|
|
|
|
R.drawable.list_blue_single,
|
|
|
|
|
R.drawable.list_white_single,
|
|
|
|
|
R.drawable.list_green_single,
|
|
|
|
|
R.drawable.list_red_single
|
|
|
|
|
};
|
|
|
|
|
// 静态初始化资源映射
|
|
|
|
|
static {
|
|
|
|
|
// 浅色主题资源
|
|
|
|
|
BG_FIRST_RESOURCES.put(NoteColor.YELLOW.id, R.drawable.list_yellow_up);
|
|
|
|
|
BG_FIRST_RESOURCES.put(NoteColor.BLUE.id, R.drawable.list_blue_up);
|
|
|
|
|
BG_FIRST_RESOURCES.put(NoteColor.WHITE.id, R.drawable.list_white_up);
|
|
|
|
|
BG_FIRST_RESOURCES.put(NoteColor.GREEN.id, R.drawable.list_green_up);
|
|
|
|
|
BG_FIRST_RESOURCES.put(NoteColor.RED.id, R.drawable.list_red_up);
|
|
|
|
|
BG_FIRST_RESOURCES.put(NoteColor.PURPLE.id, R.drawable.list_purple_up);
|
|
|
|
|
BG_FIRST_RESOURCES.put(NoteColor.ORANGE.id, R.drawable.list_orange_up);
|
|
|
|
|
|
|
|
|
|
public static int getNoteBgFirstRes(int id) {
|
|
|
|
|
return BG_FIRST_RESOURCES[id];
|
|
|
|
|
BG_NORMAL_RESOURCES.put(NoteColor.YELLOW.id, R.drawable.list_yellow_middle);
|
|
|
|
|
BG_NORMAL_RESOURCES.put(NoteColor.BLUE.id, R.drawable.list_blue_middle);
|
|
|
|
|
BG_NORMAL_RESOURCES.put(NoteColor.WHITE.id, R.drawable.list_white_middle);
|
|
|
|
|
BG_NORMAL_RESOURCES.put(NoteColor.GREEN.id, R.drawable.list_green_middle);
|
|
|
|
|
BG_NORMAL_RESOURCES.put(NoteColor.RED.id, R.drawable.list_red_middle);
|
|
|
|
|
BG_NORMAL_RESOURCES.put(NoteColor.PURPLE.id, R.drawable.list_purple_middle);
|
|
|
|
|
BG_NORMAL_RESOURCES.put(NoteColor.ORANGE.id, R.drawable.list_orange_middle);
|
|
|
|
|
|
|
|
|
|
BG_LAST_RESOURCES.put(NoteColor.YELLOW.id, R.drawable.list_yellow_down);
|
|
|
|
|
BG_LAST_RESOURCES.put(NoteColor.BLUE.id, R.drawable.list_blue_down);
|
|
|
|
|
BG_LAST_RESOURCES.put(NoteColor.WHITE.id, R.drawable.list_white_down);
|
|
|
|
|
BG_LAST_RESOURCES.put(NoteColor.GREEN.id, R.drawable.list_green_down);
|
|
|
|
|
BG_LAST_RESOURCES.put(NoteColor.RED.id, R.drawable.list_red_down);
|
|
|
|
|
BG_LAST_RESOURCES.put(NoteColor.PURPLE.id, R.drawable.list_purple_down);
|
|
|
|
|
BG_LAST_RESOURCES.put(NoteColor.ORANGE.id, R.drawable.list_orange_down);
|
|
|
|
|
|
|
|
|
|
BG_SINGLE_RESOURCES.put(NoteColor.YELLOW.id, R.drawable.list_yellow_single);
|
|
|
|
|
BG_SINGLE_RESOURCES.put(NoteColor.BLUE.id, R.drawable.list_blue_single);
|
|
|
|
|
BG_SINGLE_RESOURCES.put(NoteColor.WHITE.id, R.drawable.list_white_single);
|
|
|
|
|
BG_SINGLE_RESOURCES.put(NoteColor.GREEN.id, R.drawable.list_green_single);
|
|
|
|
|
BG_SINGLE_RESOURCES.put(NoteColor.RED.id, R.drawable.list_red_single);
|
|
|
|
|
BG_SINGLE_RESOURCES.put(NoteColor.PURPLE.id, R.drawable.list_purple_single);
|
|
|
|
|
BG_SINGLE_RESOURCES.put(NoteColor.ORANGE.id, R.drawable.list_orange_single);
|
|
|
|
|
|
|
|
|
|
BG_FOLDER_RESOURCES.put(ThemeMode.LIGHT.id, R.drawable.list_folder_light);
|
|
|
|
|
BG_FOLDER_RESOURCES.put(ThemeMode.DARK.id, R.drawable.list_folder_dark);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取列表首项背景资源
|
|
|
|
|
*
|
|
|
|
|
* @param colorId 颜色ID
|
|
|
|
|
* @return 背景资源ID
|
|
|
|
|
*/
|
|
|
|
|
public static int getNoteBgFirstRes(int colorId) {
|
|
|
|
|
return BG_FIRST_RESOURCES.get(colorId, R.drawable.list_yellow_up);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int getNoteBgLastRes(int id) {
|
|
|
|
|
return BG_LAST_RESOURCES[id];
|
|
|
|
|
/**
|
|
|
|
|
* 获取列表末项背景资源
|
|
|
|
|
*
|
|
|
|
|
* @param colorId 颜色ID
|
|
|
|
|
* @return 背景资源ID
|
|
|
|
|
*/
|
|
|
|
|
public static int getNoteBgLastRes(int colorId) {
|
|
|
|
|
return BG_LAST_RESOURCES.get(colorId, R.drawable.list_yellow_down);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int getNoteBgSingleRes(int id) {
|
|
|
|
|
return BG_SINGLE_RESOURCES[id];
|
|
|
|
|
/**
|
|
|
|
|
* 获取单条笔记背景资源
|
|
|
|
|
*
|
|
|
|
|
* @param colorId 颜色ID
|
|
|
|
|
* @return 背景资源ID
|
|
|
|
|
*/
|
|
|
|
|
public static int getNoteBgSingleRes(int colorId) {
|
|
|
|
|
return BG_SINGLE_RESOURCES.get(colorId, R.drawable.list_yellow_single);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int getNoteBgNormalRes(int id) {
|
|
|
|
|
return BG_NORMAL_RESOURCES[id];
|
|
|
|
|
/**
|
|
|
|
|
* 获取列表中间项背景资源
|
|
|
|
|
*
|
|
|
|
|
* @param colorId 颜色ID
|
|
|
|
|
* @return 背景资源ID
|
|
|
|
|
*/
|
|
|
|
|
public static int getNoteBgNormalRes(int colorId) {
|
|
|
|
|
return BG_NORMAL_RESOURCES.get(colorId, R.drawable.list_yellow_middle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int getFolderBgRes() {
|
|
|
|
|
return R.drawable.list_folder;
|
|
|
|
|
/**
|
|
|
|
|
* 获取文件夹背景资源(支持主题模式)
|
|
|
|
|
*
|
|
|
|
|
* @param themeMode 主题模式
|
|
|
|
|
* @return 文件夹背景资源ID
|
|
|
|
|
*/
|
|
|
|
|
public static int getFolderBgRes(ThemeMode themeMode) {
|
|
|
|
|
return BG_FOLDER_RESOURCES.get(themeMode.id, R.drawable.list_folder_light);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ================== 小部件资源管理 ================== */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 小部件背景资源集合
|
|
|
|
|
*/
|
|
|
|
|
public static class WidgetBgResources {
|
|
|
|
|
private final static int [] BG_2X_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.widget_2x_yellow,
|
|
|
|
|
R.drawable.widget_2x_blue,
|
|
|
|
|
R.drawable.widget_2x_white,
|
|
|
|
|
R.drawable.widget_2x_green,
|
|
|
|
|
R.drawable.widget_2x_red,
|
|
|
|
|
};
|
|
|
|
|
// 2x小部件背景资源
|
|
|
|
|
private static final SparseIntArray BG_2X_RESOURCES = new SparseIntArray();
|
|
|
|
|
|
|
|
|
|
// 4x小部件背景资源
|
|
|
|
|
private static final SparseIntArray BG_4X_RESOURCES = new SparseIntArray();
|
|
|
|
|
|
|
|
|
|
// 静态初始化资源映射
|
|
|
|
|
static {
|
|
|
|
|
// 浅色主题资源
|
|
|
|
|
BG_2X_RESOURCES.put(NoteColor.YELLOW.id, R.drawable.widget_2x_yellow);
|
|
|
|
|
BG_2X_RESOURCES.put(NoteColor.BLUE.id, R.drawable.widget_2x_blue);
|
|
|
|
|
BG_2X_RESOURCES.put(NoteColor.WHITE.id, R.drawable.widget_2x_white);
|
|
|
|
|
BG_2X_RESOURCES.put(NoteColor.GREEN.id, R.drawable.widget_2x_green);
|
|
|
|
|
BG_2X_RESOURCES.put(NoteColor.RED.id, R.drawable.widget_2x_red);
|
|
|
|
|
BG_2X_RESOURCES.put(NoteColor.PURPLE.id, R.drawable.widget_2x_purple);
|
|
|
|
|
BG_2X_RESOURCES.put(NoteColor.ORANGE.id, R.drawable.widget_2x_orange);
|
|
|
|
|
|
|
|
|
|
public static int getWidget2xBgResource(int id) {
|
|
|
|
|
return BG_2X_RESOURCES[id];
|
|
|
|
|
BG_4X_RESOURCES.put(NoteColor.YELLOW.id, R.drawable.widget_4x_yellow);
|
|
|
|
|
BG_4X_RESOURCES.put(NoteColor.BLUE.id, R.drawable.widget_4x_blue);
|
|
|
|
|
BG_4X_RESOURCES.put(NoteColor.WHITE.id, R.drawable.widget_4x_white);
|
|
|
|
|
BG_4X_RESOURCES.put(NoteColor.GREEN.id, R.drawable.widget_4x_green);
|
|
|
|
|
BG_4X_RESOURCES.put(NoteColor.RED.id, R.drawable.widget_4x_red);
|
|
|
|
|
BG_4X_RESOURCES.put(NoteColor.PURPLE.id, R.drawable.widget_4x_purple);
|
|
|
|
|
BG_4X_RESOURCES.put(NoteColor.ORANGE.id, R.drawable.widget_4x_orange);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private final static int [] BG_4X_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.widget_4x_yellow,
|
|
|
|
|
R.drawable.widget_4x_blue,
|
|
|
|
|
R.drawable.widget_4x_white,
|
|
|
|
|
R.drawable.widget_4x_green,
|
|
|
|
|
R.drawable.widget_4x_red
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* 获取2x小部件背景资源
|
|
|
|
|
*
|
|
|
|
|
* @param colorId 颜色ID
|
|
|
|
|
* @return 背景资源ID
|
|
|
|
|
*/
|
|
|
|
|
public static int getWidget2xBgResource(int colorId) {
|
|
|
|
|
return BG_2X_RESOURCES.get(colorId, R.drawable.widget_2x_yellow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int getWidget4xBgResource(int id) {
|
|
|
|
|
return BG_4X_RESOURCES[id];
|
|
|
|
|
/**
|
|
|
|
|
* 获取4x小部件背景资源
|
|
|
|
|
*
|
|
|
|
|
* @param colorId 颜色ID
|
|
|
|
|
* @return 背景资源ID
|
|
|
|
|
*/
|
|
|
|
|
public static int getWidget4xBgResource(int colorId) {
|
|
|
|
|
return BG_4X_RESOURCES.get(colorId, R.drawable.widget_4x_yellow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ================== 文本外观资源管理 ================== */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文本外观资源集合
|
|
|
|
|
*/
|
|
|
|
|
public static class TextAppearanceResources {
|
|
|
|
|
private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
|
|
|
|
|
R.style.TextAppearanceNormal,
|
|
|
|
|
R.style.TextAppearanceMedium,
|
|
|
|
|
R.style.TextAppearanceLarge,
|
|
|
|
|
R.style.TextAppearanceSuper
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static int getTexAppearanceResource(int id) {
|
|
|
|
|
/**
|
|
|
|
|
* HACKME: Fix bug of store the resource id in shared preference.
|
|
|
|
|
* The id may larger than the length of resources, in this case,
|
|
|
|
|
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
|
|
|
|
|
*/
|
|
|
|
|
if (id >= TEXTAPPEARANCE_RESOURCES.length) {
|
|
|
|
|
return BG_DEFAULT_FONT_SIZE;
|
|
|
|
|
// 文本外观资源映射
|
|
|
|
|
private static final SparseIntArray TEXTAPPEARANCE_RESOURCES = new SparseIntArray();
|
|
|
|
|
|
|
|
|
|
// 静态初始化资源映射
|
|
|
|
|
static {
|
|
|
|
|
TEXTAPPEARANCE_RESOURCES.put(FontSize.SMALL.id, R.style.TextAppearanceSmall);
|
|
|
|
|
TEXTAPPEARANCE_RESOURCES.put(FontSize.MEDIUM.id, R.style.TextAppearanceMedium);
|
|
|
|
|
TEXTAPPEARANCE_RESOURCES.put(FontSize.LARGE.id, R.style.TextAppearanceLarge);
|
|
|
|
|
TEXTAPPEARANCE_RESOURCES.put(FontSize.SUPER.id, R.style.TextAppearanceSuper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取文本外观资源
|
|
|
|
|
*
|
|
|
|
|
* @param fontSizeId 字体大小ID
|
|
|
|
|
* @return 文本外观资源ID
|
|
|
|
|
*/
|
|
|
|
|
public static int getTextAppearanceResource(int fontSizeId) {
|
|
|
|
|
// 边界检查防止越界
|
|
|
|
|
int resourceId = TEXTAPPEARANCE_RESOURCES.get(fontSizeId, -1);
|
|
|
|
|
return resourceId != -1 ? resourceId : FontSize.getDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取可用文本大小数量
|
|
|
|
|
*
|
|
|
|
|
* @return 可用字体大小数量
|
|
|
|
|
*/
|
|
|
|
|
public static int getAvailableSizeCount() {
|
|
|
|
|
return TEXTAPPEARANCE_RESOURCES.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取实际字体大小值(单位为sp)
|
|
|
|
|
*
|
|
|
|
|
* @param context 上下文
|
|
|
|
|
* @param fontSizeId 字体大小ID
|
|
|
|
|
* @return 字体大小值(sp)
|
|
|
|
|
*/
|
|
|
|
|
public static float getFontSizeSp(Context context, int fontSizeId) {
|
|
|
|
|
Resources res = context.getResources();
|
|
|
|
|
|
|
|
|
|
// 映射字体大小ID到实际尺寸值
|
|
|
|
|
switch (fontSizeId) {
|
|
|
|
|
case 0: return res.getDimension(R.dimen.text_size_small) / res.getDisplayMetrics().scaledDensity;
|
|
|
|
|
case 1: return res.getDimension(R.dimen.text_size_medium) / res.getDisplayMetrics().scaledDensity;
|
|
|
|
|
case 2: return res.getDimension(R.dimen.text_size_large) / res.getDisplayMetrics().scaledDensity;
|
|
|
|
|
case 3: return res.getDimension(R.dimen.text_size_super) / res.getDisplayMetrics().scaledDensity;
|
|
|
|
|
default: return 16; // 默认16sp
|
|
|
|
|
}
|
|
|
|
|
return TEXTAPPEARANCE_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ================== 新功能:主题资源解析 ================== */
|
|
|
|
|
|
|
|
|
|
public static int getResourcesSize() {
|
|
|
|
|
return TEXTAPPEARANCE_RESOURCES.length;
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前应用主题模式
|
|
|
|
|
*
|
|
|
|
|
* @param context 上下文
|
|
|
|
|
* @return 当前主题模式
|
|
|
|
|
*/
|
|
|
|
|
public static ThemeMode getCurrentThemeMode(Context context) {
|
|
|
|
|
// 从偏好设置获取主题ID
|
|
|
|
|
int themeId = PreferenceManager.getDefaultSharedPreferences(context)
|
|
|
|
|
.getInt(NotesPreferenceActivity.PREFERENCE_THEME_MODE, 0);
|
|
|
|
|
|
|
|
|
|
return ThemeMode.fromId(themeId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据主题模式获取对应颜色ID
|
|
|
|
|
*
|
|
|
|
|
* @param colorId 基础颜色ID
|
|
|
|
|
* @param themeMode 主题模式
|
|
|
|
|
* @return 适应主题的颜色ID
|
|
|
|
|
*/
|
|
|
|
|
public static int getThemeAdjustedColor(int colorId, ThemeMode themeMode) {
|
|
|
|
|
// 深色模式下调整颜色饱和度
|
|
|
|
|
if (themeMode == ThemeMode.DARK) {
|
|
|
|
|
switch (NoteColor.fromId(colorId)) {
|
|
|
|
|
case YELLOW: return NoteColor.ORANGE.id;
|
|
|
|
|
case WHITE: return NoteColor.BLUE.id;
|
|
|
|
|
case GREEN: return NoteColor.PURPLE.id;
|
|
|
|
|
default: return colorId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return colorId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|