Android screen brightness adjustment

Source: Internet
Author: User

SeekBar seekBar = (SeekBar) findViewById (R. id. seekBar );

// The maximum brightness of the progress bar. The value 255 indicates the maximum brightness.
SeekBar. setMax (255 );
// Obtain the current brightness
Int normal = Settings. System. getInt (getContentResolver (),
Settings. System. SCREEN_BRIGHTNESS, 255 );
// Bind the progress bar to the current brightness
SeekBar. setProgress (normal );

SeekBar. setOnSeekBarChangeListener (new OnSeekBarChangeListener (){

@ Override
Public void onStopTrackingTouch (SeekBar seekBar ){
// Get the current progress
Int tmpInt = seekBar. getProgress ();

// When the progress is less than 80, set it to 80 to prevent the consequences from being too dark.
If (tmpInt <80 ){
TmpInt = 80;
}

// Adjust the brightness based on the current progress
Settings. System. putInt (getContentResolver (),
Settings. System. SCREEN_BRIGHTNESS, tmpInt );
TmpInt = Settings. System. getInt (getContentResolver (),
Settings. System. SCREEN_BRIGHTNESS,-1 );
WindowManager. LayoutParams wl = getWindow (). getAttributes ();

Float tmpFloat = (float) tmpInt/255;
If (tmpFloat> 0 & tmpFloat <= 1 ){
Wl. screenBrightness = tmpFloat;
}
GetWindow (). setAttributes (wl );

}

@ Override
Public void onStartTrackingTouch (SeekBar seekBar ){
// TODO Auto-generated method stub
}

@ Override
Public void onProgressChanged (SeekBar seekBar, int progress,
Boolean fromUser ){
// TODO Auto-generated method stub
}
});

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.