I use Activity.onUserInteraction() in my application which triggers on any interaction (e.g. tapping the screen somewhere) even if it will not lead to action. Perfect for screen timeouts, etc.
public class MainActivity extends Activity {
...
public void onUserInteraction()
{
idleTimer = 15;
}
...
}
However, when I show a dialog (via AlertDialog.Builder) the above method won't be called anymore. I understand that it isn't my activity anymore, but how can I implement something similar when the dialog is active? I would like to track any activity, not just the ones result in action to manage (lower) brightness manually after a given length of user inactivity.
In case you need details about how the dialog is shown:
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
View view = getLayoutInflater().inflate(R.layout.number_picker, null);
final NumberPicker np = (NumberPicker)view.findViewById(R.id.numberPicker);
if (np == null)
return;
alertDialogBuilder
.setMessage(title)
.setView(view)
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MainActivity.onNumberPickerClose(code, np.getValue());
dialog.cancel();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
MainActivity.SetupNumberPicker(np, from, to, defaultValue);
alertDialog.show();