I've been able to find OnClickListeners on views:
@After("execution(* android.widget.AdapterView.OnItemClickListener.onItemClick(..))")
And events on Activities:
@After("execution(* android.app.Activity.onResume(..))")
But for some reason I can't seem to grab onto anything in AlertDialog, Dialog or even Dialog.Builder. I'd like to add an advice any time a dialog is shown.
Didn't work:
@After("execution(* android...AlertDialog.show(..))")
Didn't work:
@After("execution(* android.app.ProgressDialog.show(..))")
Didn't work:
@After("execution(* *..DialogInterface+.*(..) || * *..Dialog+.*(..))")
I would've thought if I could write aspects for Views and Activities, I could do the same thing for AlertDialogs. I'm still thinking it's my limited knowledge of AspectJ that's preventing me from having luck here?
The problem is that Aspects can only be applied to code that you wrote. So indeed, it can be applied to your own Activities and OnItemClickListener implementations, but if you don't create a subclass of Dialog yourself, it will use the class available on the user's device, which won't have your advices applied.