1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with Bananas

Discussion in 'Developers Corner' started by perrce, Mar 17, 2008.

  1. perrce

    perrce New Member

    79
    0
    Feb 7, 2007
    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.

    Code:
    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);
    	}
    	
    }
    
     
  2. apps-tv

    apps-tv apps.tv for hme apps

    66
    0
    Sep 8, 2005
    San Jose, CA
    Bananas expects something to have the focus, add a setFocus to your init() it should work

    Code:
        
    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);
        }
    
     
  3. perrce

    perrce New Member

    79
    0
    Feb 7, 2007
    That didn't work. Any other ideas?
     
  4. perrce

    perrce New Member

    79
    0
    Feb 7, 2007
    Never mind. You may have been right after all. Once I created and pushed a BScreen, it worked as expected. Thanks for the help!
     
  5. supersync

    supersync New Member

    1
    0
    May 13, 2008
    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.
     

Share This Page