|
|
|
@ -1,26 +1,19 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2010-2011, 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.preference.PreferenceManager;
|
|
|
|
|
|
|
|
|
|
import net.micode.notes.R;
|
|
|
|
|
import net.micode.notes.ui.NotesPreferenceActivity;
|
|
|
|
|
/*简介:字面意义是资源分析器,实际上就是获取资源并且在程序中使用,比如颜色图片等
|
|
|
|
|
* 实现方法:主要利用R.java这个类,其中包括
|
|
|
|
|
* R.id 组件资源引用
|
|
|
|
|
* R.drawable 图片资源 (被使用)
|
|
|
|
|
* R.layout 布局资源
|
|
|
|
|
* R.menu 菜单资源
|
|
|
|
|
* R.String 文字资源
|
|
|
|
|
* R.style 主题资源 (被使用)
|
|
|
|
|
* 在按顺序设置好相应的id后,就可以编写简单的getXXX函数获取需要的资源
|
|
|
|
|
*
|
|
|
|
|
* 特殊的变量 :
|
|
|
|
|
* @BG_DEFAULT_COLOR 默认背景颜色(黄)
|
|
|
|
|
* BG_DEFAULT_FONT_SIZE 默认文本大小(中)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public class ResourceParser {
|
|
|
|
|
|
|
|
|
@ -64,7 +57,7 @@ public class ResourceParser {
|
|
|
|
|
return BG_EDIT_TITLE_RESOURCES[id];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//直接获取默认的背景颜色。看不太懂,这个PREFERENCE_SET_BG_COLOR_KEY是个final string,也就是说getBoolean肯定执行else,为什么要这么写
|
|
|
|
|
public static int getDefaultBgId(Context context) {
|
|
|
|
|
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
|
|
|
|
|
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
|
|
|
|
@ -162,6 +155,7 @@ public class ResourceParser {
|
|
|
|
|
R.style.TextAppearanceSuper
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//这里有一个容错的函数,防止输入的id大于资源总量,若如此,则自动返回默认的设置结果
|
|
|
|
|
public static int getTexAppearanceResource(int id) {
|
|
|
|
|
/**
|
|
|
|
|
* HACKME: Fix bug of store the resource id in shared preference.
|
|
|
|
@ -179,3 +173,4 @@ public class ResourceParser {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|