Touch event handling in Blackberry

I am trying to implement simple touch event handling on a Blackberry 9550 emulator, but this will not work. In fact, touchEvent is never called, "because text never appears on the console. In addition, I get the annoying" Full menu "that appears when you touch the screen. Here's the code:

package mypackage;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.EventInjector.TouchEvent;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.VirtualKeyboard;
import net.rim.device.api.ui.container.MainScreen;

public class MyScreen extends MainScreen
{   
public MyScreen()
{    
    super(NO_SYSTEM_MENU_ITEMS);
    getScreen().getVirtualKeyboard().setVisibility(VirtualKeyboard.HIDE_FORCE);      
    add(new HandleTouch());

}

class HandleTouch extends Field {

    protected void layout(int width, int height) {
        setExtent(width, height);
    }

    public void paint(Graphics graphics) {
        graphics.drawBitmap(0, 0, this.getWidth(), this.getHeight(), Bitmap.getBitmapResource("bg.png"), 0, 0);
    }

    public boolean isFocusable() { return true;}

    protected boolean touchEvent(TouchEvent message) {
        switch( message.getEvent() ) {
        case TouchEvent.CLICK:
            System.out.println("----------------------------->CLICK");
            return true;
        case TouchEvent.DOWN:
            System.out.println("----------------------------->DOWN");
            return true;    
        case TouchEvent.MOVE:
            System.out.println("----------------------------->MOVE");
            return true;    
        }
        System.out.println("PRINT ME SOMETHING IN ANY CASE");
        return false;
    }

    public HandleTouch() {

    }
}

}

+3
source share
2 answers

1). First of all, using this code

protected void layout(int width, int height) {
    setExtent(width, height);
}

. , BB UI / layout(int width, int height), . (360 ), - VerticalFieldManager (, , ) ( 1073741823 px). , Bitmap, , , " " ( Storm 9530).

, layout() , :

protected void layout(int width, int height) {
    setExtent(Math.min(width, 360), Math.min(height, 480));
}

2).

, touchEvent

, . , ( ). ( TouchEvent.DOWN > TouchEvent.CLICK > TouchEvent.UNCLICK > TouchEvent.UP), ( TouchEvent.DOWN > TouchEvent.UP).

3).

, " ", .

, TouchEvent.UNCLICK. , :

protected boolean touchEvent(TouchEvent message) {
    return true;
}

. , . TouchEvent.UNCLICK , BB UI getContextMenu(int instance) makeContextMenu(ContextMenu contextMenu, int instance) . , ( ContextMenu, getContextMenu(int instance), getContextMenu(int instance) smt, :

public ContextMenu getContextMenu(int instance) {
    // just in case check if a context menu is requested
    // in order not to disable other types of menu
    boolean isContextMenu = (Menu.INSTANCE_CONTEXT == instance);
    return isContextMenu ? null : super.getContextMenu(instance);
}

4). , / touchEvent(TouchEvent message). / , ( ). , , . . , touchEvent(TouchEvent message), - . ( ButtonField), navigationClick(int status, int time) navigationUnclick(int status, int time). BB UI , .

+6

Arhimed, , , googling...

, . BB OS 5.0. Storm Torch. OS 4.5, - .

1) 4, Touch Event Click Click, touchEvent(TouchEvent) false. navigationClick(int, int) false, ContextMenu.

2) getContextMenu(int). 3. , BB6 .

3) getContextMenu() - . , null.

, , ! popup (?), "Full Menu". , MainMenu.... ...

, .

4) , true touchEvent(TouchEvent). , (), BB. , , .

5) OP TouchEvent.UNCLICK. 18 , navigationUnClick(int, int). 1 , UNCLICK navigationUnClick(int, int), .

, navigationClick(int, int), navigationUnClick(int, int), .


, anser.

+3

All Articles