changing screen brightness

Put your problem here if it does not fit any of the other categories.

Re: changing screen brightness

Postby mcmurph » Mon Jun 01, 2009 6:38 am

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. android.provider.Settings.System.putInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS, brightness);
  3.  
  4.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


This works fine but there is a delay before the brightness actually changes, like a minute or so. Why? And can this be speeded up? Using the system settings it changes instantly. Also programs like PowerManager can change the brightness at once. I know there used to be the possibility to use android.os.IHardware but this API is not available anymore. So how do they do it??? BTW: if I lock the phone (red button) and unlock it's applied at once.
mcmurph
Freshman
Freshman
 
Posts: 3
Joined: Tue Apr 28, 2009 8:42 am

Top

Re: changing screen brightness

Postby mcmurph » Mon Jun 01, 2009 9:31 am

mcmurph wrote:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. android.provider.Settings.System.putInt(getContentResolver(),
  2.         android.provider.Settings.System.SCREEN_BRIGHTNESS, brightness);
  3.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


This works fine but there is a delay before the brightness actually changes, like a minute or so. Why? And can this be speeded up? Using the system settings it changes instantly. Also programs like PowerManager can change the brightness at once. I know there used to be the possibility to use android.os.IHardware but this API is not available anymore. So how do they do it??? BTW: if I lock the phone (red button) and unlock it's applied at once.


I found a workaround:
1. change the system setting:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. android.provider.Settings.System.putInt(getContentResolver(),
  3.  
  4.         android.provider.Settings.System.SCREEN_BRIGHTNESS, brightness);
  5.  
  6.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

2. set the brightness for the current activity
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. lp = getWindow().getAttributes();
  3.  
  4. lp.screenBrightness = (float) (brightness / 255.0);
  5.  
  6. getWindow().setAttributes(lp);
  7.  
  8.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

3. wait for some time before finishing (this is only needed if you work without a visible activity or if you want to exit directly after applying the changes. because if you exit immediately the brightness will not be applied immediately but delayed)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Timer timer = new Timer();
  3.  
  4. timer.schedule(new TimerTask()
  5.  
  6.         {
  7.  
  8.                 @Override
  9.  
  10.                 public void run()
  11.  
  12.                 {
  13.  
  14.                         this.cancel();
  15.  
  16.                         finish();
  17.  
  18.                 }
  19.  
  20.         }, 1000, 5000);
  21.  
  22.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


But that's insane, isn't it ???
I mean step 2, ok, what the heck, but step 3 ???

Do you know of a better way? Please share!
mcmurph
Freshman
Freshman
 
Posts: 3
Joined: Tue Apr 28, 2009 8:42 am

Top
Previous

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 14 guests