Well, I will go to Netease's Android intern for examination tomorrow, so I will go through the previously written Android code and review it. Imagine, of course, this will not lead to too many essential changes, but I have to try it, in this case, go to the code.
1 package android. lekko. tools; 2 3 import android. app. activity; 4 import android. content. contentResolver; 5 import android. provider. settings; 6 import android. provider. settings. system; 7 import android. view. windowManager; 8 import android. widget. toast; 9 10 public class LightnessControl {11 // determines whether automatic brightness adjustment 12 public static boolean isAutoBrightness (Activity act) {13 boolean automicBrightness = fal Se; 14 ContentResolver aContentResolver = act. getContentResolver (); 15 try {16 automicBrightness = Settings. system. getInt (aContentResolver, 17 Settings. system. SCREEN_BRIGHTNESS_MODE) = Settings. system. SCREEN_BRIGHTNESS_MODE_AUTOMATIC; 18} catch (Exception e) {19 Toast. makeText (act, "brightness cannot be obtained", Toast. LENGTH_SHORT ). show (); 20} 21 return automicBrightness; 22} 23 // brightness 24 public static void SetLight Ness (Activity act, int value) 25 {26 try {27 System. putInt (act. getContentResolver (), System. SCREEN_BRIGHTNESS, value); 28 WindowManager. layoutParams lp = act. getWindow (). getAttributes (); 29 lp. screenBrightness = (value <= 0? 1: value)/255f; 30 act. getWindow (). setAttributes (lp); 31} catch (Exception e) {32 Toast. makeText (act, "brightness cannot be changed", Toast. LENGTH_SHORT ). show (); 33} 34} 35 // obtain the brightness 36 public static int GetLightness (Activity act) 37 {38 return System. getInt (act. getContentResolver (), System. SCREEN_BRIGHTNESS,-1); 39} 40 // stop automatic brightness adjustment 41 public static void stopAutoBrightness (Activity activity) {42 Settings. system. putInt (activity. getContentResolver (), 43 Settings. system. SCREEN_BRIGHTNESS_MODE, 44 Settings. system. SCREEN_BRIGHTNESS_MODE_MANUAL); 45} 46 // enable automatic brightness adjustment 47 public static void startAutoBrightness (Activity activity) {48 Settings. system. putInt (activity. getContentResolver (), 49 Settings. system. SCREEN_BRIGHTNESS_MODE, 50 Settings. system. SCREEN_BRIGHTNESS_MODE_AUTOMATIC); 51} 52}
This is a standalone class. It is mainly used to adjust the screen brightness. Some comments are provided to explain several concepts that are not standard for your reference:
ContentResolver class, which provides methods for accessing external shared data of other applications, such as System. getInt () and System. setInt () used for obtaining and setting the brightness ().
Activity Class, the main class of the android program, an interface must provide such background support, need to inherit this class.
Settings class, which is related to the android program system. You can find all the Settings here.
LayoutParams class, android Interface related parameters, such as height, width, brightness, etc.
Toast class, a prompt box that can automatically disappear, lightweight controls.
Reprinted please indicate the original address: http://www.cnblogs.com/lekko/archive/2013/03/20/2971825.html