Пример #1
0
 protected void pauseApp() {
   mEndNow = true;
   try {
     conn.setMessageListener(null);
     conn.close();
   } catch (IOException e) {
     System.out.println("pause app caught");
     e.printStackTrace();
   }
 }
Пример #2
0
 public void startApp() {
   if (mForm == null) {
     mForm = new Form(mAppID);
     mNumberEntry = new TextField("Connect To:", null, 256, TextField.PHONENUMBER);
     try {
       mInitialImage = Image.createImage(DEFAULT_IMAGE);
     } catch (Exception e) {
       System.out.println("start app err");
       e.printStackTrace();
     }
     mColorSquare =
         new ImageItem(null, mInitialImage, ImageItem.LAYOUT_DEFAULT, "waiting for image");
     mForm.append(mNumberEntry);
     mForm.append(mColorSquare);
     mForm.addCommand(mRedCommand);
     mForm.addCommand(mExitCommand);
     mForm.addCommand(mBlueCommand);
     mForm.setCommandListener(this);
   }
   Display.getDisplay(this).setCurrent(mForm);
   try {
     conn = (MessageConnection) Connector.open("mms://:" + mAppID);
     conn.setMessageListener(this);
   } catch (Exception e) {
     System.out.println("" + e);
   }
   if (conn != null) {
     startReceive();
   }
 }
Пример #3
0
 protected void destroyApp(boolean unconditional) {
   mEndNow = true;
   try {
     conn.close();
   } catch (IOException e) {
     System.out.println("destroy app caught");
     e.printStackTrace();
   }
 }
Пример #4
0
 public void run() {
   Message msg = null;
   String msgReceived = null;
   Image receivedImage = null;
   mMsgAvail = 0;
   while (!mEndNow) {
     synchronized (mMonitor) {
       // enter monitor
       if (mMsgAvail <= 0) {
         try {
           mMonitor.wait();
         } catch (Exception e) {
           System.out.println(e);
         }
       }
       mMsgAvail--;
     }
     try {
       msg = conn.receive();
       if (msg instanceof MultipartMessage) {
         MultipartMessage mpm = (MultipartMessage) msg;
         MessagePart[] parts = mpm.getMessageParts();
         System.out.println(parts.length);
         if (parts != null) {
           for (int i = 0; i < parts.length; i++) {
             MessagePart mp = parts[i];
             byte[] ba = mp.getContent();
             receivedImage = Image.createImage(ba, 0, ba.length);
             mColorSquare.setImage(receivedImage);
           }
         }
       }
     } catch (IOException e) {
       System.out.println(e);
     }
   }
 }