O'Reilly logo

Android™ Tablet Application Development For Dummies® by Donn Felker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with the Android Framework Classes

You're now getting into the good stuff: the real nitty-gritty of Android development — the Android framework classes! Yes, activities, views, and widgets are integral parts of the system, but when it comes down to it, they're plumbing and they're required in any modern operating system (in one capacity or another). The real fun is just about to start.

In the following section, you add a class to your app that determines whether the device's brightness setting is currently in a daytime mode (bright) or in evening mode (dim) and that sets the brightness to the other mode. At that point, you can start toggling the device brightness.

To add these classes, you could type all of this into the MainActivity.java file — but then the application would start to get long and complicated. My grandparents used to remind me that the key to keeping anything clean is good organization, and I believe the same is true for code. To keep things clean, then, you are going to create another Java file in your application that will house the code for implementing the brightness toggling logic.

Retrieving and setting screen brightness

Add a new file with the name of BrightnessHelper.java to your src/ folder. Inside of this class, you are going to add two static methods with the method names setCurrentBrightness and getCurrentBrightness. The basic code for the class should look like this (here I exclude the specifics of the two methods — I get to these later — and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required