由于Android源码(AOSP)亮度算法只针对触摸设备进行计算,使用键盘的设备均会有不同的BUG,所以我打算如果用户下拉了状态栏,他只能滑动亮度条调节亮度,要想用按键调节亮度则需要把状态栏隐藏,避免出现亮度条动画异常问题。
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
expanded 表示当前用户是否打开状态栏
@Override
public void panelExpansionChanged(float frac, boolean expanded) {
super.panelExpansionChanged(frac, expanded);
//wangrui Get status bar open state
Intent intent = new Intent("com.xxx.statusBarFlag");
intent.putExtra("statusBarFlag",expanded);
mContext.sendBroadcast(intent);
updateScrimFraction();
if ((frac == 0 || frac == 1) && mBar.getNavigationBarView() != null) {
mBar.getNavigationBarView().onStatusBarPanelStateChanged();
}
}
frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
//wangrui status bar status
private boolean statusBarFlag = false;
//wangrui Register the broadcast to get the status bar open state
context.registerReceiver(mstatusBarReceiver, new IntentFilter("com.xxx.statusBarFlag"));
若用户打开了状态栏,禁止按键调节亮度
@Override
public long interceptKeyBeforeDispatching(IBinder focusedToken, KeyEvent event,
int policyFlags) {
else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
//wangrui When the status bar is open, buttons are not allowed to adjust the brightness
++ if (statusBarFlag){
++ return 0;
++ }
}
//wangrui Broadcast receiver Get status bar status
BroadcastReceiver mstatusBarReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
statusBarFlag = intent.getBooleanExtra("statusBarFlag",false);
}
};