Question

I am implementing a small library for my projects that should get all touch events in an Activity (no matter how its RootView is populated [buttons, textboxes, ...]) and logs their locations (x,y). The idea is to then get a heatmap (clickmap / tap map) of areas where the patient clicked. To measure how the user is interacting with the application.

I was able to connect a TouchListener to the DecorView using:

public class Sniffer extends Activity {

    View v = getWindow().getDecorView();//.getRootView();

    v.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            float x = event.getAxisValue(MotionEvent.AXIS_X);
            float y = event.getAxisValue(MotionEvent.AXIS_Y);

            Log.i("t...OUCH: ", x + " " + y);

            return false;
        }
    }
    );
}

but this does not work in case the view is populated with other elements [It works great only if the layout is completely empty]. Whenever I click on a child element the logger stops working.

I also tried to implement directly inside the onTouchEvent of the Activity but it does not work...

Any thought?

PS: Considered that what I am doing should be a common problem for UI development and/or user interaction analysis, pre-made applications/libraries pointers are more than welcome.

PPS: Bonus points to the one providing the best way to filter somehow the taps so as to limit the rate of acquisition (without requiring too much to the device --> not slowing down the application just because we are grabbing and storing all those points).

Was it helpful?

Solution

Actually to do this I implemented it this way:

public class Sniffer extends Activity {

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        float x = event.getAxisValue(MotionEvent.AXIS_X);
        float y = event.getAxisValue(MotionEvent.AXIS_Y);

        Log.i("t...OUCH: ", x + " " + y);

        return super.dispatchTouchEvent(event);

    }
}

But I am waiting also to see other (better?) solutions / extensions?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top