I've since tried to write my own CustomKeyEvent and override the 
writeToParcel(...) function and the Parcelable.CREATOR field, based off of 
what I've found on 
grepcode<http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/android/view/KeyEvent.java#2898>,
 
but this doesn't seem to work. In any case because the framework hands me a 
KeyEvent object in the onKey(...) of my TextView, defining my own object 
even with a properly Parcelable character String would not help me.

My fundamental issue is that I want to pass the "likely" key presses to my 
application, which can then use touch input from another view to determine 
which key has the highest probability of being pressed and so display 
update the TextView . This means that my IME needs to be able to send 
custom events. Or is there another way to do this?

Thanks a lot,
 Matthew

On Friday, September 21, 2012 6:53:34 PM UTC-4, Matthew Williams wrote:
>
> Hi,
>
> Please see my original posting on StackOverflow 
> here<http://stackoverflow.com/questions/12519856/android-custom-keyevent-not-passing-to-textview>
>  - I 
> couldn't get a response, and I think this problem is specific enough to ask 
> here.
>
> What I'm trying to do is capture all the likely keys from the keyboard, 
> using int[] keycodes in the onKey(int kc, int[] keycodes) function of the 
> example IME given in the SDK.
> I 
>    setProximityCorrectionEnabled(true) 
> in my LatinKeyBoardView.java  so that the keycodes[] array is properly 
> initialised coming in to the onKey(...).
>
> I want to send these keys back to my application, which then uses another 
> set of touch input to in fact determine which key was pressed.
>
> The way I do this is by using this 
> <http://developer.android.com/reference/android/view/KeyEvent.html#KeyEvent(long,+java.lang.String,+int,+int)>KeyEvent(...)
>  
> constructor, as shown below.
>
>   onKey(int primaryCode, int[] keyCodes) {
>
>     ...
>
>     String characterString = new String();
>       for (int c : keyCodes) {
>   characterString += (char)c;
>       }
>       
>       KeyEvent ke = new KeyEvent(SystemClock.uptimeMillis(),
>             characterString, 0, KeyEvent.FLAG_SOFT_KEYBOARD);
>       Log.e(TAG, "parceling: " + ke.getCharacters()); 
>
>       // Drop it into a parcel for experimenting.
>       Parcel p = Parcel.obtain();
>       ke.writeToParcel(p, 0);
>
>       // Construct KeyEvent from this parcel.
>       KeyEvent kee = KeyEvent.CREATOR.createFromParcel(p);
>       Log.e(TAG, "unparceled cstring: " + kee.getCharacters()); // Null
>
>    ...
>
>   }
>
> The last Log output is "unparceled cstring: null"
>
> I also get null from within my custom TextView onKey(...), although the 
> KeyEvent that is passed in from the IME is properly constructed with 
> event.getAction() == KeyEvent.ACTION_MULTIPLE, and event.getKeyCode() == 
> KeyEvent.KEYCODE_UNKNOWN.
>
> It seems that KeyEvent.writeToParcel(...)/KeyEvent.CREATOR don't 
> marshal/unmarshal the internal character array of the KeyEvent. Is this the 
> expected behaviour? Or am I missing something.
>
> Thanks a lot,
>  Matthew
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to