private int availableMessages() {
    String content;
    try {
      StreamConnection s = null;
      s = (StreamConnection) Connector.open(getAvailableUrl());
      HttpConnection httpConn = (HttpConnection) s;

      int status = httpConn.getResponseCode();

      if (status == HttpConnection.HTTP_OK) {
        // Is this html?

        InputStream input = s.openInputStream();

        byte[] data = new byte[256];
        int len = 0;
        int size = 0;
        StringBuffer raw = new StringBuffer();

        while (-1 != (len = input.read(data))) {
          // Exit condition for the thread. An IOException is
          // thrown because of the call to  httpConn.close(),
          // causing the thread to terminate.
          if (_stop) {
            httpConn.close();
            s.close();
            input.close();
          }
          raw.append(new String(data, 0, len));
          size += len;
        }

        //         raw.insert(0, "bytes received]\n");
        //       raw.insert(0, size);
        //     raw.insert(0, '[');
        content = raw.toString();
        input.close();
      } else {
        content = "response code = " + status;
      }
      s.close();
    } catch (IOCancelledException e) {
      System.out.println(e.toString());
      return inserted;
    } catch (Exception e) {
      System.out.println(e.toString());
      return inserted;
    }
    String intString = content;
    int i = 0;
    for (; i < content.length(); i++) {
      char aChar = content.charAt(i);
      if (aChar < '0' || aChar > '9') break;
    }
    if (i > 0) return Integer.parseInt(content.substring(0, i));
    return inserted;
  }
Ejemplo n.º 2
0
  public static void updateUTF8Key(char c) {
    if (c_key_down_value_addr == 0) return;

    String s = String.valueOf(c);
    try {
      byte[] b = s.getBytes("UTF-8");
      CRunTime.memcpy(c_key_down_value_addr, b, 0, b.length);
      CRunTime.memoryWriteByte(c_key_down_value_addr + b.length, 0);
    } catch (Exception e) {
      CRunTime.memoryWriteByte(c_key_down_value_addr, 0);
      e.printStackTrace();
    }
  }
  /**
   * Constructor.
   *
   * @param text The text to be displayed on the button
   * @param style Combination of field style bits to specify display attributes
   */
  public BOC(String dboc, String iboc, String tboc) {
    super(Field.NON_FOCUSABLE);
    try {
      _width = Display.getWidth();
      switch (_width) {
        case 480:
          f2 = 20;

          dbmp = Bitmap.getBitmapResource("bocdom480.jpg");
          ibmp = Bitmap.getBitmapResource("bocinter480.jpg");
          tbmp = Bitmap.getBitmapResource("boctotal480.jpg");
          _height = 60;
          break;
        case 360:
          f2 = 19;
          dbmp = Bitmap.getBitmapResource("bocdom360.png");
          ibmp = Bitmap.getBitmapResource("bocinter360.png");
          tbmp = Bitmap.getBitmapResource("boctotal360.png");
          _height = 60;
          break;
        default:
          f2 = 17;
          dbmp = Bitmap.getBitmapResource("bocdom320.png");
          ibmp = Bitmap.getBitmapResource("bocinter320.png");
          tbmp = Bitmap.getBitmapResource("boctotal320.png");

          _height = 60;
          break;
      }
      _dboc = dboc;
      _iboc = iboc;
      _tboc = tboc;
      FontFamily ff1 = FontFamily.forName("BBAlpha Serif");
      font = ff1.getFont(Font.PLAIN, f2);

    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    }
  }
Ejemplo n.º 4
0
  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;
  }