protected boolean navigationClick(final int status, int time) {
    System.out.println("***** navigationClick *****");
    System.out.println("status=" + Integer.toHexString(status));
    if ((status & (KeypadListener.STATUS_FOUR_WAY | KeypadListener.STATUS_TRACKWHEEL)) == 0) {
      if (status != 0) Logger.log("navClick ignored status " + Integer.toHexString(status));
      return true;
    }

    boolean used = false;

    try {
      if (c_on_navigation_click == 0)
        c_on_navigation_click = CibylCallTable.getAddressByName("rim_on_navigation_click");
    } catch (Throwable t) {
      Logger.log("Exception in navigationClick: " + t);
      t.printStackTrace();

      System.exit(0);
    }

    if (c_on_navigation_click != 0) {
      UIWorker.addUIEvent(c_on_navigation_click, status, time, 0, 0, true);
    }

    return true;
  }
  private void checkOrientationChanged(int w, int h) {
    // calculate current orientation based on width and height
    int isLandscape = w > h ? 1 : 0;
    if (isLandscape == isLandscapeScreen) {
      return;
    }
    if (!isUIWorkerInit) {
      // verify that UIWorker is initialized
      isUIWorkerInit = UIWorker.isInit();
      if (!isUIWorkerInit) return;
    }
    isLandscapeScreen = isLandscape;
    try {
      if (c_on_orientation_change == 0)
        c_on_orientation_change = CibylCallTable.getAddressByName("rim_on_orientation_change");
    } catch (Throwable t) {
      Logger.log("Exception in checkOrientationChanged: " + t);
      t.printStackTrace();

      System.exit(0);
    }

    if (c_on_orientation_change != 0) {
      UIWorker.addUIEvent(c_on_orientation_change, isLandscape, 0, 0, 0, true);
    }
  }
  protected boolean touchEvent(TouchEvent te) {
    System.out.println("touchEvent type " + Integer.toString(te.getEvent()));
    if (te.getEvent() == TouchEvent.CANCEL) return true;
    int x = te.getX(1);
    int y = te.getY(1);
    if (x < 0 || x > this.getWidth() || y < 0 || y > this.getHeight()) {
      Logger.log(
          "touchedEvent type "
              + Integer.toString(te.getEvent())
              + " x="
              + Integer.toString(x)
              + " y="
              + Integer.toString(x)
              + " outside "
              + Integer.toString(getWidth())
              + "x"
              + Integer.toString(getHeight()));
      return super.touchEvent(te);
    }
    switch (te.getEvent()) {
      case TouchEvent.DOWN:
        touchDownEvent(x, y);
        break;
      case TouchEvent.UP:
        touchUpEvent(x, y);
        break;
      case TouchEvent.MOVE:
        touchMovedEvent(x, y);
        break;
      default:
        return super.touchEvent(te);
    }

    return true;
  }
Beispiel #4
0
  /** Requests an HTTP resource and returns its response as a string */
  public static String request(String httpUrl, Transaction tx) throws IOException {
    checkTransaction(tx);

    DataBuffer buffer = new DataBuffer(256, false);
    InputStream is = null;
    Connection conn = null;
    try {
      // append connection suffix
      httpUrl += getConnectionSuffix();
      Logger.log("Opening URL: " + httpUrl);
      conn = Connector.open(httpUrl);
      tx.setNetworkOperation(conn, is);
      if (conn instanceof HttpConnection) {
        HttpConnection httpConn = (HttpConnection) conn;
        int responseCode = httpConn.getResponseCode();
        is = httpConn.openInputStream();
        tx.setNetworkOperation(conn, is);
        int length = is.read(buffer.getArray());
        buffer.setLength(length);

        String response =
            new String(buffer.getArray(), buffer.getArrayStart(), buffer.getArrayLength());
        if (responseCode == 200) {
          Logger.log("HTTP response: " + response);
          return response;
        } else {
          Logger.warn("HTTP error response: " + response);
          throw new IOException("Http error: " + responseCode + ", " + response);
        }
      } else {
        throw new IOException("Can not make HTTP connection for URL '" + httpUrl + "'");
      }
    } finally {
      PushUtils.close(conn, is, null);
      tx.clearNetworkOperation();
    }
  }
  private void touchMovedEvent(int x, int y) {
    try {
      if (c_on_canvas_button_moved == 0)
        c_on_canvas_button_moved = CibylCallTable.getAddressByName("rim_on_canvas_button_moved");
    } catch (Throwable t) {
      Logger.log("Exception in touchMovedEvent: " + t);
      t.printStackTrace();

      System.exit(0);
    }

    if (c_on_canvas_button_pressed != 0) {
      UIWorker.addUIEvent(c_on_canvas_button_moved, x, y, 0, 0, true);
    }
  }
  protected boolean navigationMovement(final int dx, final int dy, final int status, int time) {
    //		System.out.println("***** navigationMovement *****");
    //		System.out.println("dx=" + dx + " dy=" + dy + " status=" + Integer.toHexString(status));

    boolean used = false;
    // m_graphics.copyArea(0, 0, getVisibleWidth(), getVisibleHeight(), dx * 30, dy * 30);
    // refresh();

    try {
      if (c_on_navigation_movement == 0)
        c_on_navigation_movement = CibylCallTable.getAddressByName("rim_on_navigation_movement");
    } catch (Throwable t) {
      Logger.log("Exception in navigationMovement: " + t);
      t.printStackTrace();

      System.exit(0);
    }

    if (c_on_navigation_movement != 0) {
      UIWorker.addUIEvent(c_on_navigation_movement, dx, dy, status, time, true, true);
    }
    //		System.out.println("used=" + used);
    return true;
  }
  protected boolean keyDown(final int keycode, int time) {
    System.out.println("***** keyDown *****");
    System.out.println("keycode=" + keycode);
    char altedKey = '0';
    boolean useAltedKey = false;
    final int key;
    boolean isAltedKeyboard = false;
    try {
      isAltedKeyboard = hwKeyboardLayoutsLst.containsKey(Keypad.getHardwareLayout());
      // System.out.println("hw layout " + Integer.toString(Keypad.getHardwareLayout()) +
      // (isAltedKeyboard ? " alted" : " non-alted") );
    } catch (Exception e) {
      System.out.println("contains Exception " + e);
    }
    if (isAltedKeyboard) { // Alted keyboard
      altedKey = Keypad.map(Keypad.key(keycode), KeypadListener.STATUS_ALT);
      if ((altedKey == '#') || (altedKey == '*')) { // enable zoom in zoom out.
        useAltedKey = true;
      }
    }

    if (keyDownStackAddress == 0) {
      Logger.log("keyDownStackAddress = 0, before stack init ");
      return true;
    }

    key = Keypad.key(keycode);

    System.out.println("key is = " + key);

    final int status = Keypad.status(keycode);
    // System.out.println("key=" + keycode + " status=" + status);

    if (key == Keypad.KEY_MENU) {
      System.out.println("***** MENU BUTTON PRESSED *****");
      menu_open = true;
      try {
        if (c_on_menu_key_down == 0) {
          c_on_menu_key_down = CibylCallTable.getAddressByName("rim_on_menu_button");
        }
        if (c_on_menu_key_down != 0) {
          // FIXME - should send keycode to C and C should trans to UTF8
          updateUTF8Key(keycode);
          CibylCallTable.call(c_on_menu_key_down, keyDownStackAddress, key, status, time, 0);
        }
      } catch (Exception t) {
        Logger.log("Exception in UI action: " + t);
        t.printStackTrace();
      }
      return false; // return false so RIM will open the menu as necessary.
    } else if (key == Keypad.KEY_VOLUME_DOWN) {
      SoundMgr.updateSoundLevel(-10);
    } else if (key == Keypad.KEY_VOLUME_UP) {
      SoundMgr.updateSoundLevel(10);
    } else if ((key == Keypad.KEY_SEND)
        || (key == Keypad.KEY_APPLICATION)
        || (key == Keypad.KEY_SPEAKERPHONE)
        || (key == Keypad.KEY_CONVENIENCE_1)
        || (key == Keypad.KEY_CONVENIENCE_2)) {
      return false;

    } else if (key == Keypad.KEY_END) {
      return false;
    } else {
      try {
        if (c_on_key_down == 0) c_on_key_down = CibylCallTable.getAddressByName("rim_on_key_down");
      } catch (Throwable t) {
        Logger.log("Exception in keyDown: " + t);
        t.printStackTrace();

        System.exit(0);
      }

      if (c_on_key_down != 0) {
        // FIXME - should send keycode to C and C should trans to UTF8
        if (!useAltedKey) updateUTF8Key(keycode);
        else updateUTF8Key(altedKey);

        UIWorker.addUIEvent(c_on_key_down, key, status, time, 0, true);
      }
    }
    return true;
  }