
Spying on Android events without modifying source code - kalmar
http://kamalmarhubi.com/blog/2016/10/03/android-events/index.html
======
pawadu
I wonder if you can achieve the same thing by inserting a debug class that
replaces the original parent. That is, change the code to go from

    
    
        View <-- MyView
    

to

    
    
        View <-- DebugView <-- MyView
    

You might even be able to do this without decompiling the code.

~~~
on_and_off
That's the idea behind the probe lib :
[https://github.com/lucasr/probe/blob/master/library/src/main...](https://github.com/lucasr/probe/blob/master/library/src/main/java/org/lucasr/probe/ProbeViewFactory.java)

So, when you write an android app, most of time you describe your ui's layout
in xml files. This xml is then translated to a binary blob during the
compilation (you don't have to know/care about this intermediary format
though). When you need the corresponding ui, you use a layoutInflater in order
to 'inflate' the xml : read its content and create the corresponding views.

One nifty trick is that since the LayoutInflater instantiate the views, it is
the perfect place to replace a view by another. For example, that's how the
support lib works (well, modulo some hacks, the layoutInflater was not thought
out for this initially). When you ask for an ImageView in your xml, the
support lib provides you with an AppCompatImageView instead, adding some new
capabilities independently of the OS version.

probe goes a little bit further and dynamically add some methods to any class
that it inflates, in order to add some layout debugging capabilities.

