Skip to content

Commit 11415f9

Browse files
committed
Add Design to UnitsManager
1 parent 11e737f commit 11415f9

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

autosize/src/main/java/me/jessyan/autosize/unit/UnitsManager.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@
4040
* ================================================
4141
*/
4242
public class UnitsManager {
43+
/**
44+
* 设计图上的总宽度, 建议单位为 px, 当使用者想将旧项目从主单位过渡到副单位, 或从副单位过渡到主单位时使用
45+
* 因为在使用主单位时, 建议在 AndroidManifest 中填写设计图的 dp 尺寸, 比如 360 * 640
46+
* 而副单位有一个特性是可以直接在 AndroidManifest 中填写设计图的 px 尺寸, 比如 1080 * 1920
47+
* 但在 AndroidManifest 中却只能填写一套设计图尺寸, 所以当在旧项目中想让主单位和副单位共存
48+
* 又想使用副单位的特性, 就需要一个地方保存副单位的设计图尺寸
49+
*/
50+
private float mDesignWidth;
51+
/**
52+
* 设计图上的总高度, 建议单位为 px, 当使用者想将旧项目从主单位过渡到副单位, 或从副单位过渡到主单位时使用
53+
* 因为在使用主单位时, 建议在 AndroidManifest 中填写设计图的 dp 尺寸, 比如 360 * 640
54+
* 而副单位有一个特性是可以直接在 AndroidManifest 中填写设计图的 px 尺寸, 比如 1080 * 1920
55+
* 但在 AndroidManifest 中却只能填写一套设计图尺寸, 所以当在旧项目中想让主单位和副单位共存
56+
* 又想使用副单位的特性, 就需要一个地方保存副单位的设计图尺寸
57+
*/
58+
private float mDesignHeight;
4359
/**
4460
* 是否支持 dp 单位, 默认支持
4561
*/
@@ -53,6 +69,65 @@ public class UnitsManager {
5369
*/
5470
private Subunits mSupportSubunits = Subunits.NONE;
5571

72+
/**
73+
* 设置设计图尺寸
74+
*
75+
* @param designWidth 设计图上的总宽度, 建议单位为 px
76+
* @param designHeight 设计图上的总高度, 建议单位为 px
77+
* @return {@link UnitsManager}
78+
* @see #mDesignWidth 详情请查看这个字段的注释
79+
* @see #mDesignHeight 详情请查看这个字段的注释
80+
*/
81+
public UnitsManager setDesignSize(float designWidth, float designHeight) {
82+
setDesignWidth(designWidth);
83+
setDesignHeight(designHeight);
84+
return this;
85+
}
86+
87+
/**
88+
* 返回 {@link #mDesignWidth}
89+
*
90+
* @return {@link #mDesignWidth}
91+
*/
92+
public float getDesignWidth() {
93+
return mDesignWidth;
94+
}
95+
96+
/**
97+
* 设置设计图上的总宽度, 建议单位为 px
98+
*
99+
* @param designWidth 设计图上的总宽度, 建议单位为 px
100+
* @return {@link UnitsManager}
101+
* @see #mDesignWidth 详情请查看这个字段的注释
102+
*/
103+
public UnitsManager setDesignWidth(float designWidth) {
104+
Preconditions.checkArgument(designWidth > 0, "designWidth must be > 0");
105+
mDesignWidth = designWidth;
106+
return this;
107+
}
108+
109+
/**
110+
* 返回 {@link #mDesignHeight}
111+
*
112+
* @return {@link #mDesignHeight}
113+
*/
114+
public float getDesignHeight() {
115+
return mDesignHeight;
116+
}
117+
118+
/**
119+
* 设置设计图上的总高度, 建议单位为 px
120+
*
121+
* @param designHeight 设计图上的总高度, 建议单位为 px
122+
* @return {@link UnitsManager}
123+
* @see #mDesignHeight 详情请查看这个字段的注释
124+
*/
125+
public UnitsManager setDesignHeight(float designHeight) {
126+
Preconditions.checkArgument(designHeight > 0, "designHeight must be > 0");
127+
mDesignHeight = designHeight;
128+
return this;
129+
}
130+
56131
/**
57132
* 是否支持 dp 单位, 默认支持, 详情请看类文件的注释 {@link UnitsManager}
58133
*

0 commit comments

Comments
 (0)