at first write the following permission in your manifest.xml file
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
then, when the 10 seconds pass, run the following code to reduce the Brightness of the device to it's lower level:
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 0); //Set the system brightness
android.view.WindowManager.LayoutParams w_lp = getWindow().getAttributes(); //Get the current window attributes
w_lp.screenBrightness = progress / (float)255; //Set the brightness of this window
getWindow().setAttributes(w_lp); //Apply attribute changes to this window
and in case you need know how to make sure that it waited for 10 seconds without any user activity, implement the above code the following way:
public class YOUR_ACTIVITY extends Activity {
public static int x = 0; // must be static
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
run_thread();
}
private void run_thread(){
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
while(x < 10){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
x++;
}
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 0); //Set the system brightness to it's lowest value
android.view.WindowManager.LayoutParams w_lp = getWindow().getAttributes(); //Get the current window attributes
w_lp.screenBrightness = progress / (float)255; //Set the brightness of this window
getWindow().setAttributes(w_lp); //Apply attribute changes to this window
}
});
thread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
x = 0;
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 255); //Set the system brightness back to it's full value
android.view.WindowManager.LayoutParams w_lp = getWindow().getAttributes(); //Get the current window attributes
w_lp.screenBrightness = progress / (float)255; //Set the brightness of this window
getWindow().setAttributes(w_lp); //Apply attribute changes to this window
return true;
}