|
|
|
@ -22,24 +22,43 @@ import android.preference.PreferenceManager;
|
|
|
|
|
import net.micode.notes.R;
|
|
|
|
|
import net.micode.notes.ui.NotesPreferenceActivity;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author hzx
|
|
|
|
|
* 版本:1.0
|
|
|
|
|
* 创建日期:2023/10/29
|
|
|
|
|
* 描述:ResourceParser 资源解析器
|
|
|
|
|
* 封装了一些颜色和字体大小常量,能够通过颜色或字体大小ID获取资源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;
|
|
|
|
|
|
|
|
|
|
// 默认的颜色 黄色 0
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
// 默认的字体大小 中等 1
|
|
|
|
|
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 便签背景资源类
|
|
|
|
|
*/
|
|
|
|
|
public static class NoteBgResources {
|
|
|
|
|
// 编辑界面背景资源数组
|
|
|
|
|
private final static int [] BG_EDIT_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.edit_yellow,
|
|
|
|
|
R.drawable.edit_blue,
|
|
|
|
@ -48,6 +67,7 @@ public class ResourceParser {
|
|
|
|
|
R.drawable.edit_red
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 编辑标题背景资源数组
|
|
|
|
|
private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.edit_title_yellow,
|
|
|
|
|
R.drawable.edit_title_blue,
|
|
|
|
@ -56,25 +76,39 @@ public class ResourceParser {
|
|
|
|
|
R.drawable.edit_title_red
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 根据背景颜色ID获取便签背景资源ID
|
|
|
|
|
public static int getNoteBgResource(int id) {
|
|
|
|
|
return BG_EDIT_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据背景颜色ID获取便签标题背景资源ID
|
|
|
|
|
public static int getNoteTitleBgResource(int id) {
|
|
|
|
|
return BG_EDIT_TITLE_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取默认的背景颜色ID
|
|
|
|
|
* @param context 上下文
|
|
|
|
|
* @return 背景颜色ID
|
|
|
|
|
*/
|
|
|
|
|
public static int getDefaultBgId(Context context) {
|
|
|
|
|
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
|
|
|
|
|
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
|
|
|
|
|
// 设置了随机背景颜色
|
|
|
|
|
// 返回一个随机背景颜色ID
|
|
|
|
|
return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length);
|
|
|
|
|
} else {
|
|
|
|
|
// 返回默认的背景颜色ID
|
|
|
|
|
return BG_DEFAULT_COLOR;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 便签列表项背景颜色资源静态类
|
|
|
|
|
*/
|
|
|
|
|
public static class NoteItemBgResources {
|
|
|
|
|
// 开头背景资源
|
|
|
|
|
private final static int [] BG_FIRST_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.list_yellow_up,
|
|
|
|
|
R.drawable.list_blue_up,
|
|
|
|
@ -83,6 +117,7 @@ public class ResourceParser {
|
|
|
|
|
R.drawable.list_red_up
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 正常背景资源
|
|
|
|
|
private final static int [] BG_NORMAL_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.list_yellow_middle,
|
|
|
|
|
R.drawable.list_blue_middle,
|
|
|
|
@ -91,6 +126,7 @@ public class ResourceParser {
|
|
|
|
|
R.drawable.list_red_middle
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 结尾背景资源
|
|
|
|
|
private final static int [] BG_LAST_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.list_yellow_down,
|
|
|
|
|
R.drawable.list_blue_down,
|
|
|
|
@ -99,6 +135,7 @@ public class ResourceParser {
|
|
|
|
|
R.drawable.list_red_down,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 单独的背景资源
|
|
|
|
|
private final static int [] BG_SINGLE_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.list_yellow_single,
|
|
|
|
|
R.drawable.list_blue_single,
|
|
|
|
@ -107,28 +144,37 @@ public class ResourceParser {
|
|
|
|
|
R.drawable.list_red_single
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 根据背景颜色ID获取开头背景资源ID
|
|
|
|
|
public static int getNoteBgFirstRes(int id) {
|
|
|
|
|
return BG_FIRST_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据背景颜色ID获取结尾背景资源ID
|
|
|
|
|
public static int getNoteBgLastRes(int id) {
|
|
|
|
|
return BG_LAST_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据背景颜色ID获取单独的背景资源ID
|
|
|
|
|
public static int getNoteBgSingleRes(int id) {
|
|
|
|
|
return BG_SINGLE_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据背景颜色ID获取普通背景资源ID
|
|
|
|
|
public static int getNoteBgNormalRes(int id) {
|
|
|
|
|
return BG_NORMAL_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取文件夹背景资源ID
|
|
|
|
|
public static int getFolderBgRes() {
|
|
|
|
|
return R.drawable.list_folder;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 小部件背景资源静态类
|
|
|
|
|
*/
|
|
|
|
|
public static class WidgetBgResources {
|
|
|
|
|
// 2x的小部件背景资源
|
|
|
|
|
private final static int [] BG_2X_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.widget_2x_yellow,
|
|
|
|
|
R.drawable.widget_2x_blue,
|
|
|
|
@ -137,10 +183,12 @@ public class ResourceParser {
|
|
|
|
|
R.drawable.widget_2x_red,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 根据背景颜色ID获取小部件背景资源ID
|
|
|
|
|
public static int getWidget2xBgResource(int id) {
|
|
|
|
|
return BG_2X_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 4x的小部件背景资源
|
|
|
|
|
private final static int [] BG_4X_RESOURCES = new int [] {
|
|
|
|
|
R.drawable.widget_4x_yellow,
|
|
|
|
|
R.drawable.widget_4x_blue,
|
|
|
|
@ -149,12 +197,17 @@ public class ResourceParser {
|
|
|
|
|
R.drawable.widget_4x_red
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 根据背景颜色ID获取小部件背景资源ID
|
|
|
|
|
public static int getWidget4xBgResource(int id) {
|
|
|
|
|
return BG_4X_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 字体资源静态类
|
|
|
|
|
*/
|
|
|
|
|
public static class TextAppearanceResources {
|
|
|
|
|
// 字体资源
|
|
|
|
|
private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
|
|
|
|
|
R.style.TextAppearanceNormal,
|
|
|
|
|
R.style.TextAppearanceMedium,
|
|
|
|
@ -162,18 +215,21 @@ public class ResourceParser {
|
|
|
|
|
R.style.TextAppearanceSuper
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 根据字体大小ID获取字体资源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;
|
|
|
|
|
}
|
|
|
|
|
return TEXTAPPEARANCE_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取字体资源数组的长度
|
|
|
|
|
public static int getResourcesSize() {
|
|
|
|
|
return TEXTAPPEARANCE_RESOURCES.length;
|
|
|
|
|
}
|
|
|
|
|