PDA

View Full Version : Help with Bananas


perrce
03-17-2008, 08:39 PM
I'm trying to write my first HME application and I'm having some trouble. I've written a simple "Hello World" app, and I can't get handleKeyPress() to work when I'm using Bananas.

Basically, if my application extends Application, then I can catch a left key press to cleanly exit the application. But, if instead my application extends BApplication, then it won't catch key presses. (It just bonks at me.) This has happened if I use SDK version 1.4/Bananas 1.3, or if I use the latest SDK 1.4.1e/Bananas 1.3.1e. My JRE version is 1.6.0_03.

Is there something special I have to change for handleKeyPress() to work in an application that uses Bananas?

Thanks for your help. For reference, I'm including below the code that does NOT work. (If, however, I remove the 'B' from "BApplications", then it works just fine.


package org.dazeend.hello;

import com.tivo.hme.bananas.*;
import com.tivo.hme.sdk.*;
import com.tivo.hme.interfaces.*;
import java.awt.Color;

public class Hello extends BApplication {

public void init(IContext context) throws Exception {
// Initialization from superclass.
super.init(context);

View root = getRoot();
Resource text = createText("default-36.font", Color.blue, "Hello World");
root.setResource( text );
}

/**
* Handles key presses from TiVo remote control.
*/
@Override
public boolean handleKeyPress(int key, long rawcode) {
switch(key) {
case KEY_LEFT:
this.setActive(false);
return true;
}
return super.handleKeyPress(key, rawcode);
}

}

apps-tv
03-18-2008, 02:09 AM
Bananas expects something to have the focus, add a setFocus to your init() it should work


public void init(IContext context) throws Exception {
// Initialization from superclass.
super.init(context);

View root = getRoot();
Resource text = createText("default-36.font", Color.blue, "Hello World");
root.setResource( text );
setFocus(root);
}

perrce
03-18-2008, 02:54 PM
That didn't work. Any other ideas?

perrce
03-18-2008, 03:46 PM
Never mind. You may have been right after all. Once I created and pushed a BScreen, it worked as expected. Thanks for the help!

supersync
05-13-2008, 09:22 PM
That looks correct. Is your handleKeyPress getting called at all? Try setting a breakpoint in the BApplication handleKeyPress and your handleKeyPress. Or use debug commands to print status messages to the console to help you figure it out. Typically the handleKeyPress for the left key should pop the current screen off the stack to reveal the last screen shown.. try some of the other tivo sample apps..and also spend a little time getting the simulator to work--that way you can experiment a little easier and not have to worry about screen burn-in.