Search code examples
androidandroid-sourceonfocusglobalevent

Listen to EditText OnFocusChangeListener Globally


I am interested in building a system application for Android which can globally listen to all EditText on focus change event, somehow I am gonna provide certain service when the user gain focus on any EditText.

I have successfully downloaded AOSP(Android Open Source Project) and I want to start writing my app as system application.

My question is can I do that as a system application "listening to global events" ?

if possible what are they areas I need to dig up to learn more about gaining such a privilege.

Any suggestion or help would be greatly appreciated.


Solution

  • I suggest you start by looking at View.java class which basically has the basic building block for user interface component.

    ../frameworks/base/core/java/android/view/View.java
    

    and lookup the method onFocusChanged if you are only interested in EditText add the following line

     if (this instanceof EditText) {
          Toast.makeText(getContext(), "focus gained!", Toast.LENGTH_SHORT).show(); 
     }
    

    build again and you will see toast notification everytime you gain focus to any EditText around the OS