Android Screen Brightness adjustment

Source: Internet
Author: User
Tags stub

SeekBar SeekBar = (SeekBar) Findviewbyid (R.id.seekbar);

progress bar binding maximum brightness, 255 is maximum brightness
Seekbar.setmax (255);
Get current brightness
int normal = Settings.System.getInt (Getcontentresolver (),
Settings.System.SCREEN_BRIGHTNESS, 255);
progress bar Binding Current brightness
Seekbar.setprogress (normal);

Seekbar.setonseekbarchangelistener (New Onseekbarchangelistener () {

@Override
public void Onstoptrackingtouch (SeekBar SeekBar) {
Get Current progress
int tmpint = seekbar.getprogress ();

When the schedule is less than 80 o'clock, set to 80 to prevent the consequences of too dark unseen.
if (Tmpint < 80) {
Tmpint = 80;
}

Change brightness based on 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.