public Object invoke(Object obj, Object[] args) throws Exception {
    // input = (email address, subject, body, full attachment path)

    String email = (String) args[0].toString();
    String subject = (String) args[1].toString();
    String body = (String) args[2].toString();
    String attachment = (String) args[3].toString();
    String fName = attachment;
    byte[] data = null;
    FileConnection fconn = null;
    DataInputStream is = null;
    try {
      fconn = (FileConnection) Connector.open(fName, Connector.READ_WRITE);
      is = fconn.openDataInputStream();
      data = IOUtilities.streamToBytes(is);
      is.close();
      fconn.close();
    } catch (Exception ex) {
      Dialog.inform("Error in file path: " + ex.toString());
      return new Boolean(false);
    }
    // create a multipart
    Multipart mp = new Multipart();

    // create the file
    SupportedAttachmentPart sap =
        new SupportedAttachmentPart(mp, "application/x-example", attachment, data);

    TextBodyPart tbp = new TextBodyPart(mp, body);

    // add the file to the multipart
    mp.addBodyPart(tbp);
    mp.addBodyPart(sap);

    // create a message in the sent items folder
    Folder folders[] = Session.getDefaultInstance().getStore().list(Folder.SENT);

    Message message = new Message(folders[0]);
    Address toAdd = new Address(email, "my email");
    Address toAdds[] = new Address[1];
    toAdds[0] = toAdd;
    message.addRecipients(Message.RecipientType.TO, toAdds);
    message.setSubject(subject);
    message.setContent(mp);
    Session session = Session.getDefaultInstance();
    Transport trans = session.getTransport();
    // add recipients to the message and send
    boolean sent = false;
    try {
      trans.send(message);
      sent = true;
    } catch (Exception e) {
      Dialog.inform("Error while sending: " + e.toString());
    }

    return new Boolean(sent);
  }
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();
    }
  }
Ejemplo n.º 3
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;
  }