|
|
|
@ -22,158 +22,229 @@ import android.preference.PreferenceManager;
|
|
|
|
|
import net.micode.notes.R;
|
|
|
|
|
import net.micode.notes.ui.NotesPreferenceActivity;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 资源解析工具类 ResourceParser
|
|
|
|
|
*
|
|
|
|
|
* 提供笔记应用中背景色、字体大小等资源的常量定义及获取方法。
|
|
|
|
|
* 支持随机背景色、列表项背景、组件背景以及文本样式资源的获取。
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
// ====== 笔记背景颜色常量 ======
|
|
|
|
|
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; // 红色
|
|
|
|
|
|
|
|
|
|
// 默认背景颜色:黄色
|
|
|
|
|
public static final int BG_DEFAULT_COLOR = YELLOW;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
// ====== 文本大小常量 ======
|
|
|
|
|
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; // 超大号字体
|
|
|
|
|
|
|
|
|
|
// 默认字体大小:中号
|
|
|
|
|
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NoteBgResources 嵌套类
|
|
|
|
|
*
|
|
|
|
|
* 提供编辑界面中笔记背景和标题背景的 drawable 资源获取方法。
|
|
|
|
|
*/
|
|
|
|
|
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 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 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 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
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据颜色 ID 获取笔记编辑背景资源
|
|
|
|
|
*/
|
|
|
|
|
public static int getNoteBgResource(int id) {
|
|
|
|
|
return BG_EDIT_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据颜色 ID 获取笔记编辑标题背景资源
|
|
|
|
|
*/
|
|
|
|
|
public static int getNoteTitleBgResource(int id) {
|
|
|
|
|
return BG_EDIT_TITLE_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取默认背景色 ID
|
|
|
|
|
*
|
|
|
|
|
* 如果用户开启随机背景色偏好,从随机范围中获取;
|
|
|
|
|
* 否则返回默认颜色常量。
|
|
|
|
|
*/
|
|
|
|
|
public static int getDefaultBgId(Context context) {
|
|
|
|
|
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
|
|
|
|
|
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
|
|
|
|
|
boolean randomBg = PreferenceManager
|
|
|
|
|
.getDefaultSharedPreferences(context)
|
|
|
|
|
.getBoolean(NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false);
|
|
|
|
|
if (randomBg) {
|
|
|
|
|
// 随机选取一种背景色
|
|
|
|
|
return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length);
|
|
|
|
|
} else {
|
|
|
|
|
return BG_DEFAULT_COLOR;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NoteItemBgResources 嵌套类
|
|
|
|
|
*
|
|
|
|
|
* 提供笔记列表项不同状态(首、中、末、单独)的背景资源获取方法。
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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 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 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 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 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
|
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取第一项背景资源
|
|
|
|
|
*/
|
|
|
|
|
public static int getNoteBgFirstRes(int id) {
|
|
|
|
|
return BG_FIRST_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取普通项背景资源
|
|
|
|
|
*/
|
|
|
|
|
public static int getNoteBgNormalRes(int id) {
|
|
|
|
|
return BG_NORMAL_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取末尾项背景资源
|
|
|
|
|
*/
|
|
|
|
|
public static int getNoteBgLastRes(int id) {
|
|
|
|
|
return BG_LAST_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取单独一项背景资源
|
|
|
|
|
*/
|
|
|
|
|
public static int getNoteBgSingleRes(int id) {
|
|
|
|
|
return BG_SINGLE_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int getNoteBgNormalRes(int id) {
|
|
|
|
|
return BG_NORMAL_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取文件夹列表项背景资源
|
|
|
|
|
*/
|
|
|
|
|
public static int getFolderBgRes() {
|
|
|
|
|
return R.drawable.list_folder;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* WidgetBgResources 嵌套类
|
|
|
|
|
*
|
|
|
|
|
* 提供 2x 和 4x 大小桌面组件背景资源获取方法。
|
|
|
|
|
*/
|
|
|
|
|
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,
|
|
|
|
|
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 大小组件背景资源
|
|
|
|
|
*/
|
|
|
|
|
public static int getWidget2xBgResource(int id) {
|
|
|
|
|
return BG_2X_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取 4x 大小组件背景资源
|
|
|
|
|
*/
|
|
|
|
|
public static int getWidget4xBgResource(int id) {
|
|
|
|
|
return BG_4X_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TextAppearanceResources 嵌套类
|
|
|
|
|
*
|
|
|
|
|
* 提供文本样式(字体大小)资源获取方法,并包含边界检查逻辑。
|
|
|
|
|
*/
|
|
|
|
|
public static class TextAppearanceResources {
|
|
|
|
|
private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
|
|
|
|
|
R.style.TextAppearanceNormal,
|
|
|
|
|
R.style.TextAppearanceMedium,
|
|
|
|
|
R.style.TextAppearanceLarge,
|
|
|
|
|
R.style.TextAppearanceSuper
|
|
|
|
|
// 文本样式资源数组
|
|
|
|
|
private final static int[] TEXTAPPEARANCE_RESOURCES = new int[] {
|
|
|
|
|
R.style.TextAppearanceNormal,
|
|
|
|
|
R.style.TextAppearanceMedium,
|
|
|
|
|
R.style.TextAppearanceLarge,
|
|
|
|
|
R.style.TextAppearanceSuper
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据文本大小 ID 获取对应的样式资源,超过范围时返回默认字体大小样式
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
// 避免 sharedPreference 中存储的 ID 越界
|
|
|
|
|
if (id < 0 || id >= TEXTAPPEARANCE_RESOURCES.length) {
|
|
|
|
|
return TEXTAPPEARANCE_RESOURCES[BG_DEFAULT_FONT_SIZE];
|
|
|
|
|
}
|
|
|
|
|
return TEXTAPPEARANCE_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取可用文本样式资源数量
|
|
|
|
|
*/
|
|
|
|
|
public static int getResourcesSize() {
|
|
|
|
|
return TEXTAPPEARANCE_RESOURCES.length;
|
|
|
|
|
}
|
|
|
|
|