Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for a more universal onUserInteraction() event - not just in one Activity

Tags:

android

events

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

like image 675
Roy Hinkley Avatar asked Nov 12 '13 20:11

Roy Hinkley


1 Answers

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>
like image 151
user2203031 Avatar answered Nov 15 '22 21:11

user2203031