Android系统。亮度变化 [英] Android. Brightness Change

查看:172
本文介绍了Android系统。亮度变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图解决以下任务:亮度的平滑变化 从100%至0%,但不能获得平滑的效果。 要强调的是,我使用的亮度以下方法 更改。建议之一。

I am trying to resolve following task: smooth change of brightness from 100% to 0%, but can't gain effect of smoothness. Want to emphasize that I am using following approach of brightness change. The recommended one.

WindowManager.LayoutParams lp = window.getAttributes();

lp.screenBrightness = floatPercent;

window.setAttributes(lp);

那么,它显然作品,但并不顺利。 我将描述逻辑:

Well, it obviously works, but not smooth. I will describe logic:

我有一个线程改变亮度:

I have a thread that changes brightness:

            while (isRunning()) { 
                Thread.sleep(sleepTime); 
                spentTime+=sleepTime; 
                view.post(new Runnable() { 
                    public void run() { 
                        changeBrightness(); 
                    } 
                }); 
            } 

予有亮度变化的持续时间,例如10秒。 我计算 floatPercent 的下一个值(参见上面code段)的 这样,睡眠时间应始终小于50ms。 所以看起来它必须是光滑的。 但是,我总是不平稳过渡。它涉及特别范围 0% - 5%的亮度。平滑度在此完全丧失 亮度范围。

I have duration of brightness change, for example 10 seconds. I calculate next value of floatPercent (see code snippet above) the way, sleepTime should always be less than 50ms. So looks like it had to be smooth. But I always get not smooth transition. It relates specially the range of 0% - 5% of brightness. Smoothness is completely lost on this brightness range.

我已经张贴在谷歌Android开发组这个问题,但无论如何,可能有人已经调查了这一地区。

I have already posted this question on Google Android Developer group, but anyway possibly somebody have already investigated in this area.

推荐答案

从你的code段,它会出现您使用视频下载()上UI线程。

From your code snippet, it would appear you are using Thread.sleep() on the UI thread.

请请请请请请请请请请请请请请请请请请请请请请请请请请请请请请请请请请请请请请请请请请请不要使用视频下载()在UI线程。

Please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please please do not use Thread.sleep() in the UI thread.

由于您使用的后(),只需切换到 postDelayed(),它传递的时间去等待前执行Runnable。

Since you are using post(), just switch to postDelayed(), passing it the time to wait before executing the Runnable.

其实,视频下载()可能是你所遇到的问题,原因,因为视频下载()在UI上说:嘿,Android的!请冻结UI一会儿!,让您的亮度变化可能不会发生,直到返回控制到Android(例如,无论从任何回调返回触发您的code)

In fact, Thread.sleep() may be cause of the problem you are experiencing, since Thread.sleep() on the UI says "Hey, Android! Please freeze the UI for a while!", so your brightness change may not take place until you return control to Android (e.g., return from whatever callback triggered your code).

此外,什么Hackborn女士告诉你在谷歌论坛是绝对正确的:这是依赖于硬件。并非所有的硬件​​将提供你所寻求的平滑度。这可能是你的0-5%的问题 - 硬件只到,比方说,5%的亮度,然后进行跳转到具有背光灯熄灭,什么

Furthermore, what Ms. Hackborn told you on the Google Groups is absolutely correct: this is dependent on hardware. Not all hardware will offer the smoothness you seek. That may be your 0-5% problem -- the hardware only goes to, say, 5% brightness, then makes a jump to having the backlight be off, or something.

这篇关于Android系统。亮度变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆