KomodoOpenLab / InputAccessLib

InputAccessLib is a library that enhances the compatibility of Android applications with a variety of alternative input devices such as external keyboards, adapted switches, hands-free kits and remote controls.
10 stars 16 forks source link

setOnMenuItemClickListener() does not get called when a menu item is clicked. #35

Closed rishabhjain08 closed 12 years ago

rishabhjain08 commented 12 years ago

Currently if devs set menu item click listener to a menu item using setOnMenuItemClickListener then the current implementation cannot handle that i.e. even if the menu item gets clicked the listener is not invoked. I tried many things and searched a lot but there seems to be no decent way to handle that. The best I was able to come up with was a method InputAccess.setOnMenuItemClickListener(MenuItem, OnMenuItemClickListener) [not a static function] to which the devs need to pass a menu item and a listener. Should I implement it? With the new additions devs will have to call InputAccess.setOnMenuItemClickListener(MenuItem, OnMenuItemClickListener) if devs have used MenuItem.setOnMenuItemClickListener in their code. It should be suggested to devs that they use onOptionsItemSelected() instead of attaching a listener to a menu item if they are using InputAccessLib.

rishabhjain08 commented 12 years ago

da77cba957a551b95a3f6f83f33a8af64e42e2b6

rishabhjain08 commented 12 years ago

I found a novel way to overcome the issue. I created custom Menu, SubMenu and MenuItem class and passed them to the callback functions such as onCreateOptionsMenu(), onPrepareOptionsMenu() and onOptionsMenuClosed(). The problem was that Menu.getItem returned object of type android.view.MenuItem, so what I did was to maintain an ArrayList of type <android.view.MenuItem, ca.idi.tecla.lib.menu.MenuItem> and create and return the object of type ca.idi.tecla.lib.menu.MenuItem instead of android.view.MenuItem

ijdoc commented 12 years ago

Do you still need my input on this? I was caught up on something else for a couple of days.

rishabhjain08 commented 12 years ago

@jorgesilva I came up with an idea and the problem has been solved.