I need to be able to know when the user is not interacting with the tablet/phone for a period of time. I am currently attempting to gain this intelligence using:
@Override
public void onUserInteraction(){
lastInteraction = System.currentTimeMillis();
}
However, it only fires with direct interaction of the Activity (or fragment in said Activity), not any displayed dialogs. Is there a more universal way to achieve this without adding this to every dialog?
Documentation
I solved this problem by wrapping dialogs into custom layout:
public class InteractionInterceptorLayer extends LinearLayout {
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
//any actions here...
return super.dispatchTouchEvent(ev);
}
//constructors...
}
And in layout definition:
<com.package.InteractionInterceptorLayer xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
// layout goes here
</com.package.InteractionInterceptorLayer>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With