- Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathWindowUtils.java
More file actions
Latest commit
82 lines (76 loc) · 2.51 KB
/
Copy pathWindowUtils.java
File metadata and controls
82 lines (76 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
packagecom.realmo.utils;
importandroid.animation.ValueAnimator;
importandroid.app.Activity;
importandroid.content.Context;
importandroid.content.res.Configuration;
importandroid.view.Surface;
importandroid.view.Window;
importandroid.view.WindowManager;
publicfinalclassWindowUtils {
/**
* Don't let anyone instantiate this class.
*/
privateWindowUtils() {
thrownewError("Do not need instantiate!");
}
/**
* 获取当前窗口的旋转角度
*
* @param activity activity
* @return int
*/
publicstaticintgetDisplayRotation(Activityactivity) {
switch (activity.getWindowManager().getDefaultDisplay().getRotation()) {
caseSurface.ROTATION_0:
return0;
caseSurface.ROTATION_90:
return90;
caseSurface.ROTATION_180:
return180;
caseSurface.ROTATION_270:
return270;
default:
return0;
}
}
/**
* 当前是否是横屏
*
* @param context context
* @return boolean
*/
publicstaticfinalbooleanisLandscape(Contextcontext) {
returncontext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
}
/**
* 当前是否是竖屏
*
* @param context context
* @return boolean
*/
publicstaticfinalbooleanisPortrait(Contextcontext) {
returncontext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
}
/**
* 调整窗口的透明度 1.0f,0.5f 变暗
* @param from from>=0&&from<=1.0f
* @param to to>=0&&to<=1.0f
* @param context 当前的activity
*/
publicstaticvoiddimBackground(finalfloatfrom, finalfloatto, Activitycontext) {
finalWindowwindow = context.getWindow();
ValueAnimatorvalueAnimator = ValueAnimator.ofFloat(from, to);
valueAnimator.setDuration(500);
valueAnimator.addUpdateListener(
newValueAnimator.AnimatorUpdateListener() {
@Override
publicvoidonAnimationUpdate(ValueAnimatoranimation) {
WindowManager.LayoutParamsparams
= window.getAttributes();
params.alpha = (Float) animation.getAnimatedValue();
window.setAttributes(params);
}
});
valueAnimator.start();
}
}