Android 12 上调用系统的护眼模式和丽色系统
护眼模式,可以直接使用反射的方式调用
public static final String ColorDisplayManager="android.hardware.display.ColorDisplayManager";
/**
* 设置护眼模式
* @param activated 开关
*/
public static boolean setColorDisplayManager(boolean activated){
boolean ac=false;
GDLog.e("set activated="+activated);
try {
@SuppressLint("PrivateApi") Class<?> colorDisplayManager = Class.forName(ColorDisplayManager);
Object o=colorDisplayManager.newInstance();
/*GDLog.e("setColorDisplayManager2");
Method[] methods= colorDisplayManager.getMethods();
for (Method m:methods) {
GDLog.e("m:"+m.getName()+"---");
Class<?>[] classes= m.getParameterTypes();
for (Class c:classes) {
GDLog.e("c:"+c.getName());
}
}*/
//忽略访问权限修饰符,获取方法
Method setNightDisplayActivated = o.getClass().getDeclaredMethod("setNightDisplayActivated",boolean.class);
setNightDisplayActivated.setAccessible(true);
ac= (boolean) setNightDisplayActivated.invoke(o,activated);
} catch (Exception e) {
e.printStackTrace();
}
return ac;
}
public static boolean isNightDisplayActivated(){
boolean activated=false;
try {
@SuppressLint("PrivateApi") Class<?> colorDisplayManager = Class.forName(ColorDisplayManager);
Object o=colorDisplayManager.newInstance();
//忽略访问权限修饰符,获取方法
Method setNightDisplayActivated = o.getClass().getDeclaredMethod("isNightDisplayActivated",null);
setNightDisplayActivated.setAccessible(true);
activated= (boolean) setNightDisplayActivated.invoke(o);
} catch (Exception e) {
e.printStackTrace();
}
return activated;
}
丽色系统,这块代码不在framework 里面,所以不能直接反射获取,调用需要导入softwinner.display.output.jar 包
jar包下载路径
提取码:rg56
private DefaultDisplayOutputManager displayOutputManager=new DefaultDisplayOutputManager();
//丽色系统
displayOutputManager.setDisplayEnhanceMode(0,displayOutputManager.getDisplayEnhanceMode(0)==1?0:1);
//演示模式,只对半屏有效
displayOutputManager.setDisplayEnhanceMode(0,displayOutputManager.getDisplayEnhanceMode(0)==2?0:2);
//取值范围 <integer name="config_HSL_max_range">10</integer>
// setDisplaySaturation 饱和度
// setDisplayBright 亮度
// setDisplayContrast 对比度
private static final int COLOR_TEMPERATURE_SCALE_MAX = 100; // 100 percentage
// setColorTemperature 色温
// getColorTemperature
//黑白模式
displayOutputManager.setBlackWhiteMode(0,displayOutputManager.getBlackWhiteMode(0)?false:true);
//阅读模式
displayOutputManager.setReadingMode(0,displayOutputManager.getReadingMode(0)?false:true);
网友评论