|
|
/*
|
|
|
* 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;//这行代码声明了类所在的包名,即net.micode.notes.tool。
|
|
|
|
|
|
import android.content.Context;
|
|
|
import android.preference.PreferenceManager;//这两行代码导入了Android框架中的Context和PreferenceManager类。
|
|
|
|
|
|
import net.micode.notes.R;//这行代码导入了net.micode.notes包下的R类。R类是一个自动生成的类,包含了项目中所有资源的引用,如布局、字符串、图片等。
|
|
|
import net.micode.notes.ui.NotesPreferenceActivity;//这行代码导入了net.micode.notes.ui包下的NotesPreferenceActivity类。
|
|
|
|
|
|
public class ResourceParser {//这行代码定义了一个公开的类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到4进行标识。
|
|
|
|
|
|
public static final int BG_DEFAULT_COLOR = YELLOW;//这行代码定义了一个公开的静态常量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 BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;//这行代码定义了一个公开的静态常量BG_DEFAULT_FONT_SIZE,并将其值设置为TEXT_MEDIUM,即默认字体大小为中等
|
|
|
|
|
|
public static class NoteBgResources {//这行代码定义了一个公开的静态内部类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
|
|
|
};//在NoteBgResources内部类中,定义了一个私有的静态整型数组BG_EDIT_RESOURCES,并初始化为包含五个图片资源ID的数组。这些资源ID对应于五种不同颜色的编辑背景图片。
|
|
|
|
|
|
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
|
|
|
};//在NoteBgResources内部类中,定义了另一个私有的静态整型数组BG_EDIT_TITLE_RESOURCES,并初始化为包含五个图片资源ID的数组。这些资源ID对应于五种不同颜色的编辑标题背景图片。
|
|
|
|
|
|
public static int getNoteBgResource(int id) {
|
|
|
return BG_EDIT_RESOURCES[id];
|
|
|
}//在NoteBgResources内部类中,定义了一个公开的静态方法getNoteBgResource,它接受一个整数id作为参数,并返回对应id的编辑背景图片资源ID。
|
|
|
|
|
|
public static int getNoteTitleBgResource(int id) {
|
|
|
return BG_EDIT_TITLE_RESOURCES[id];
|
|
|
}//在NoteBgResources内部类中,定义了另一个公开的静态方法getNoteTitleBgResource,它同样接受一个整数id作为参数,并返回对应id的编辑标题背景图片资源ID。
|
|
|
}
|
|
|
|
|
|
public static int getDefaultBgId(Context context) {//定义了一个公开的静态方法getDefaultBgId,它接受一个Context对象作为参数,并返回一个整型值。这个方法用于获取默认的背景ID。
|
|
|
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(//开始了一个条件判断,使用PreferenceManager获取默认的SharedPreferences实例,然后从中读取一个布尔值。
|
|
|
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {//完成条件判断的部分,检查是否设置了背景颜色的偏好(通过PREFERENCE_SET_BG_COLOR_KEY键),如果没有设置,则默认为false。
|
|
|
return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length);//如果条件为真(即用户设置了自定义背景颜色),则返回一个随机整数,这个整数是NoteBgResources.BG_EDIT_RESOURCES数组长度的某个值
|
|
|
} else {//如果条件为假(即用户没有设置自定义背景颜色),则执行else部分的代码。
|
|
|
return BG_DEFAULT_COLOR;//返回一个名为BG_DEFAULT_COLOR的整型值,这个值是默认的背景颜色ID。
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static class NoteItemBgResources {//定义了一个公开的静态内部类NoteItemBgResources,用于封装笔记项背景资源的获取方法。
|
|
|
private final static int [] BG_FIRST_RESOURCES = new int [] {//定义了一个私有的静态最终整型数组BG_FIRST_RESOURCES,包含了一系列背景资源ID,用于表示笔记项在列表中的第一个位置时的背景。
|
|
|
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 [] {//定义了一个用于表示笔记项在列表中的正常位置时的背景资源ID数组。
|
|
|
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 [] {//定义了一个用于表示笔记项在列表中的最后一个位置时的背景资源ID数组。
|
|
|
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 [] {//定义了一个用于表示单独的笔记项(不在列表中)时的背景资源ID数组。
|
|
|
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) {//定义了一个公开的静态方法,根据提供的ID返回BG_FIRST_RESOURCES数组中对应的背景资源ID。
|
|
|
|
|
|
return BG_FIRST_RESOURCES[id];
|
|
|
}
|
|
|
|
|
|
public static int getNoteBgLastRes(int id) {//定义了一个方法,用于返回BG_LAST_RESOURCES数组中对应的背景资源ID。
|
|
|
return BG_LAST_RESOURCES[id];
|
|
|
}
|
|
|
|
|
|
public static int getNoteBgSingleRes(int id) {//定义了一个方法,用于返回BG_SINGLE_RESOURCES数组中对应的背景资源ID。
|
|
|
return BG_SINGLE_RESOURCES[id];
|
|
|
}
|
|
|
|
|
|
public static int getNoteBgNormalRes(int id) {//定义了一个方法,用于返回BG_SINGLE_RESOURCES数组中对应的背景资源ID。
|
|
|
return BG_NORMAL_RESOURCES[id];
|
|
|
}
|
|
|
|
|
|
public static int getFolderBgRes() {//这行定义了一个方法,返回用于表示文件夹的背景资源ID。
|
|
|
|
|
|
return R.drawable.list_folder;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static class WidgetBgResources {//定义了一个公开的静态内部类 WidgetBgResources。
|
|
|
private final static int [] BG_2X_RESOURCES = new int [] {//定义了一个私有的静态最终整型数组 BG_2X_RESOURCES,包含了一系列小部件在2x尺寸下的背景资源ID。这些资源ID通常指向drawable资源,如图片等。
|
|
|
|
|
|
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,
|
|
|
};
|
|
|
|
|
|
public static int getWidget2xBgResource(int id) {//定义了一个公开的静态方法 getWidget2xBgResource,它接受一个整型参数 id,用于指定想要获取的背景资源的索引。
|
|
|
return BG_2X_RESOURCES[id];//返回 BG_2X_RESOURCES 数组中指定索引 id 的背景资源ID。
|
|
|
}
|
|
|
|
|
|
private final static int [] BG_4X_RESOURCES = new int [] {//定义了一个私有的静态最终整型数组 BG_4X_RESOURCES,包含了一系列小部件在4x尺寸下的背景资源ID。
|
|
|
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
|
|
|
};
|
|
|
|
|
|
public static int getWidget4xBgResource(int id) {//定义了一个公开的静态方法 getWidget4xBgResource,它同样接受一个整型参数 id,用于指定想要获取的背景资源的索引。
|
|
|
|
|
|
return BG_4X_RESOURCES[id];//返回 BG_4X_RESOURCES 数组中指定索引 id 的背景资源ID。
|
|
|
}
|
|
|
}//WidgetBgResources 类结束。
|
|
|
|
|
|
public static class TextAppearanceResources {//定义了一个公开的静态内部类 TextAppearanceResources。
|
|
|
private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
|
|
|
//定义了一个私有的静态最终整型数组 TEXTAPPEARANCE_RESOURCES,包含了一系列文本外观资源ID。这些资源ID通常指向style资源,定义了文本的字体大小、颜色等属性。
|
|
|
R.style.TextAppearanceNormal,
|
|
|
R.style.TextAppearanceMedium,
|
|
|
R.style.TextAppearanceLarge,
|
|
|
R.style.TextAppearanceSuper
|
|
|
};
|
|
|
|
|
|
public static int getTexAppearanceResource(int id) {//定义了一个公开的静态方法 getTexAppearanceResource 接受一个整型参数 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) {//检查提供的索引 id 是否超出了 TEXTAPPEARANCE_RESOURCES 数组的长度。
|
|
|
return BG_DEFAULT_FONT_SIZE;//如果条件为真(即索引超出了数组长度),则返回一个名为 BG_DEFAULT_FONT_SIZE 的整型值。
|
|
|
}
|
|
|
return TEXTAPPEARANCE_RESOURCES[id];//如果条件为假(即索引在数组长度范围内),则返回 TEXTAPPEARANCE_RESOURCES 数组中指定索引 id 的文本外观资源ID
|
|
|
}
|
|
|
|
|
|
public static int getResourcesSize() {//定义了一个公开的静态方法 getResourcesSize,它不接受任何参数,并返回 TEXTAPPEARANCE_RESOURCES 数组的长度。
|
|
|
return TEXTAPPEARANCE_RESOURCES.length;//返回 TEXTAPPEARANCE_RESOURCES 数组的长度。
|
|
|
}
|
|
|
}
|
|
|
}
|