BrightnessDialog.java
2.05 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
package com.wd.player.gesturedialog;
import android.app.Activity;
import android.view.Window;
import android.view.WindowManager;
import com.aliyun.svideo.wd.player.R;
/**
* 手势滑动的时的亮度提示框
*/
public class BrightnessDialog extends BaseGestureDialog {
private static final String TAG = BrightnessDialog.class.getSimpleName();
// 当前亮度。0~100
private int mCurrentBrightness = 0;
public BrightnessDialog(Activity activity, int percent) {
super(activity);
mCurrentBrightness = percent;
//设置亮度图片
mImageView.setImageResource(R.mipmap.alivc_brightness);
updateBrightness(percent);
}
/**
* 更新对话框上的亮度百分比
* @param percent 亮度百分比
*/
public void updateBrightness(int percent) {
mTextView.setText(percent + "%");
}
/**
* 获取当前亮度百分比
* @param activity 活动
* @return 当前亮度百分比
*/
public static int getActivityBrightness(Activity activity) {
if (activity != null) {
Window window = activity.getWindow();
WindowManager.LayoutParams layoutParams = window.getAttributes();
float screenBrightness = layoutParams.screenBrightness;
if (screenBrightness > 1) {
screenBrightness = 1;
} else if (screenBrightness < 0.1f) {
//解决三星某些手机亮度值等于0自动锁屏的bug
screenBrightness = 0.1f;
}
return (int) (screenBrightness * 100);
}
return 0;
}
/**
* 计算最终的亮度百分比
* @param changePercent 变化的百分比
* @return 最终的亮度百分比
*/
public int getTargetBrightnessPercent(int changePercent) {
int newBrightness = mCurrentBrightness - changePercent;
if (newBrightness > 100) {
newBrightness = 100;
} else if (newBrightness < 0) {
newBrightness = 0;
}
return newBrightness;
}
}