My app is a simple "Brightness Changer", that also changes System Brightness (what isn't to easy to implement :D).
I actually set up everything and its working fine... except for one little annoying thing... everytime the brightness changes the screen first "flashes" to the highest brightness (like 100% light) and after a half second or so, it changes to the right brightness.
Example: System Brightness should be 120: 1. Change to 255 (max.), adter half second change to 120.
Here is the code of my two classes. The Dummy class is used to "reset" the (necessary for applying brightness change.)
EDIT: btw. i think the problem is the "lp.screenBrightness = 100/100.0f;" in the dummyactivity. But it wont work without it :/
test.java
public class Test extends Activity
{
SeekBar seekbar;
TextView value;
TextView debug;
Button button1;
Button button2;
Button button3;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
value = (TextView) findViewById(R.id.textview2);
debug = (TextView) findViewById(R.id.textview3);
seekbar = (SeekBar) findViewById(R.id.seekbar);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
seekbar.setOnSeekBarChangeListener( new OnSeekBarChangeListener()
{
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser)
{
// TODO Auto-generated method stub
int brightness = progress+1;
double b = brightness/2.55;
double c = Math.round(b*100)/100;
int percent = (int) c;
if (percent==0) {
value.setText("Lightlevel: !MIN!");
}else if (percent==100){
value.setText("Lightlevel: !MAX!");
}else{
value.setText("Lightlevel: "+percent+"%");
}
debug.setText("int brightness: "+brightness+" / double b:"+b+" / double c: "+c+" / int percent: "+percent);
Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_BRIGHTNESS, brightness);
}
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
Intent in = new Intent(Test.this,DummyBrightnessActivity.class);
startActivity(in);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
});
button1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_BRIGHTNESS, 1);
Intent in = new Intent(Test.this,DummyBrightnessActivity.class);
startActivity(in);
}
});
button2.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_BRIGHTNESS, 127);
Intent in = new Intent(Test.this,DummyBrightnessActivity.class);
startActivity(in);
}
});
button3.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_BRIGHTNESS, 255);
Intent in = new Intent(Test.this,DummyBrightnessActivity.class);
startActivity(in);
}
});
}
}
DummyBrightnessActivity.java
public class DummyBrightnessActivity extends Activity{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//setContentView(R.layout.dummy);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 100/100.0f;
getWindow().setAttributes(lp);
Timer timer2 = new Timer();
timer2.schedule(new TimerTask() {
public void run() {
finish();
}
}, 500);
}
}