0

How do you undim the display programmatically? I may compile upto 100 times a day. And most of the time the screen has dimmed and I must touch the screen to see clearly what change I just made. I do not need to change system brightness just locally. I've tried both of these variations to no avail, I still have to touch the screen to bring it to full brightness. Now maybe if I attached a 5 lb weight to my arm there would be some benefit rather than the minor irritation of doing the same thing over and over. Code Commented out was tried also:

    WindowManager.LayoutParams layout = getWindow().getAttributes();
    layout.dimAmount=1F;
    //screenBrightness = 1F;
    getWindow().setAttributes(layout);
    setContentView(R.layout.main); 
Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

0

I see two approaches:

1.The easiest way is to prevent the screen from dimming by using the keepScreenOn attribute. You can set it as a View attribute in your XML, but it is possible programmatically as well (setKeepScreenOn).

For example, programmatically, you can add this to your Activity's onCreate() method:

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);    

2.If you want to deal with dimming/brightness, you can try to set layout.screenBrightness as well. If this approach does not work, it might be because the WindowManager does not know about it (i.e. no refresh happens). There is an accepted stackoverflow answer about it here, I never tested it though.

Community
  • 1
  • 1
Thomas Calc
  • 2,994
  • 3
  • 30
  • 56
  • Ok. It took one press and it stays on. Saves me 99 presses. I just need this while creating the app and until I finalize and make the app ready to publish. Is there something I can give a conditional that this is published and dont do this anymore other than having to remember to remove this? bonus points thanks. – user1448524 Jun 12 '12 at 02:38
  • Solved the problem of forgetting to remove this. I used test for version name and if it isnt all numeric then I am still working on it. PackageManager manager = this.getPackageManager(); PackageInfo info = null; try { info = manager.getPackageInfo(this.getPackageName(), 0); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } Toast.makeText( this, "PackageName = " + info.packageName + "\nVersionCode = " + info.versionCode + "\nVersionName = " + info.versionName + "\nPermissions = "+info.permissions, Toast.LENGTH_LONG).show(); – user1448524 Jun 12 '12 at 03:10
  • I'm sorry but I don't understand your comment. It does not seem to be related to the screen dim problem. – Thomas Calc Jun 12 '12 at 03:17
  • I only need this while I am building the app. When I go to publish to market I needed a way to NOT have the undo dim. I solved by just checking the version name if it is all numeric dont set to always on. I changed name to "Developing 1.0" which I am sure to remember to change to all numeric at market publish time. – user1448524 Jun 12 '12 at 03:44
  • OK. I suggest that you maintain a TODO list, or even "TODO" comments in your source code in your development tool/IDE (such as Eclipse). Before you prepare the release version, you can make sure that no such TODO comments exist. Eclipse can display a Tasks list, where it lists all of your todo tasks. – Thomas Calc Jun 12 '12 at 03:50
  • I do keep a todo list. But I also create code to help solve temporary problems. New to JAVA,ANDROID old time C programmer. I can set a global variable called DEBUG thats set by my method. When I change the version name to all numeric that should make sure any code that was created never gets executed. Obviously that code is not huge chunks of memory. Thanks for your help. – user1448524 Jun 12 '12 at 04:00
0

Building on Thomas Calc's previous answer, if you only want the display to stay on when you're developing your application, you may want to try

if (BuildConfig.DEBUG) {
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

This will only make the display stay on while you're developing the application, and not when you export the application for final use.

solarnz
  • 1,041
  • 1
  • 8
  • 23
  • Perfect! Its along the lines I was thinking there had to be some system variable that could be checked. Still learning! Thanks. Dont have a way to split the solutions nor have nuff rep yet either to move up solution. – user1448524 Jun 12 '12 at 04:12
  • OOOPPS! A problem its a known issue Sometimes BuildConfig doesnt work. I'll stick with my not so elegant method. http://code.google.com/p/android/issues/detail?id=27940 – user1448524 Jun 12 '12 at 04:30