Skip to content

Commit 659ccf9

Browse files
committed
Add AutoSizeConfig#isVertical
1 parent f4422bf commit 659ccf9

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

autosize/src/main/java/me/jessyan/autosize/AutoSizeConfig.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public final class AutoSizeConfig {
116116
* 是否让框架支持自定义 {@link Fragment} 的适配参数, 由于这个需求是比较少见的, 所以须要使用者手动开启
117117
*/
118118
private boolean isCustomFragment;
119+
/**
120+
* 屏幕方向, {@link true} 为纵向, {@link false} 为横向
121+
*/
122+
private boolean isVertical;
119123

120124
public static AutoSizeConfig getInstance() {
121125
if (sInstance == null) {
@@ -173,6 +177,7 @@ AutoSizeConfig init(final Application application, boolean isBaseOnWidth, AutoAd
173177
final DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
174178

175179
getMetaData(application);
180+
isVertical = application.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
176181
int[] screenSize = ScreenUtils.getScreenSize(application);
177182
mScreenWidth = screenSize[0];
178183
mScreenHeight = screenSize[1];
@@ -191,6 +196,7 @@ public void onConfigurationChanged(Configuration newConfig) {
191196
Resources.getSystem().getDisplayMetrics().scaledDensity;
192197
LogUtils.d("initScaledDensity = " + mInitScaledDensity + " on ConfigurationChanged");
193198
}
199+
isVertical = application.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
194200
int[] screenSize = ScreenUtils.getScreenSize(application);
195201
mScreenWidth = screenSize[0];
196202
mScreenHeight = screenSize[1];
@@ -419,6 +425,42 @@ public float getInitXdpi() {
419425
return mInitXdpi;
420426
}
421427

428+
/**
429+
* 获取屏幕方向
430+
*
431+
* @return {@link true} 为纵向, {@link false} 为横向
432+
*/
433+
public boolean isVertical() {
434+
return isVertical;
435+
}
436+
437+
/**
438+
* 设置屏幕方向
439+
*
440+
* @param vertical {@link true} 为纵向, {@link false} 为横向
441+
*/
442+
public void setVertical(boolean vertical) {
443+
isVertical = vertical;
444+
}
445+
446+
/**
447+
* 设置屏幕宽度
448+
*
449+
* @param screenWidth 屏幕宽度
450+
*/
451+
public void setScreenWidth(int screenWidth) {
452+
mScreenWidth = screenWidth;
453+
}
454+
455+
/**
456+
* 设置屏幕高度
457+
*
458+
* @param screenHeight 屏幕高度 (包含状态栏和导航栏)
459+
*/
460+
public void setScreenHeight(int screenHeight) {
461+
mScreenHeight = screenHeight;
462+
}
463+
422464
/**
423465
* 获取使用者在 AndroidManifest 中填写的 Meta 信息
424466
* <p>

0 commit comments

Comments
 (0)