示例#1
0
  public static void AddWeiboHeadImage(
      Vector _imageList, int _style, String _id, byte[] _dataArray) {

    synchronized (_imageList) {
      for (int i = 0; i < _imageList.size(); i++) {
        WeiboHeadImage t_image = (WeiboHeadImage) _imageList.elementAt(i);

        if (t_image.m_userID.equals(_id) && _style == t_image.m_weiboStyle) {

          try {
            t_image.m_headImage =
                EncodedImage.createEncodedImage(_dataArray, 0, _dataArray.length).getBitmap();
            t_image.m_dataHash = _dataArray.length;

            debugOutput(
                "recv " + _style + " head image " + _id + " dataHash " + t_image.m_dataHash);

          } catch (Exception ex) {
            exceptionOutput("AWHI+" + _id, ex);
          }

          break;
        }
      }
    }
  }
示例#2
0
  public static EncodedImage getImage(String url, Manager parent) throws IOException {
    url += ";deviceside=true";
    HttpConnection connection = null;
    InputStream inputStream = null;
    try {
      ConnectionFactory cf = new ConnectionFactory();
      cf.setConnectionTimeout(2500);
      ConnectionDescriptor cd = cf.getConnection(url);
      HttpConnection httpConn;
      httpConn = (HttpConnection) cd.getConnection();
      inputStream = httpConn.openInputStream();
      StringBuffer rawResponse = new StringBuffer();
      byte[] responseData = new byte[10000];
      int length = 0;
      while (-1 != (length = inputStream.read(responseData))) {
        rawResponse.append(new String(responseData, 0, length));
      }
      String result = rawResponse.toString();
      byte[] dataArray = result.getBytes();
      // Image.createImage(InputStream);
      httpConn.close();
      return EncodedImage.createEncodedImage(dataArray, 0, dataArray.length);

    } catch (IOException e1) {
      //
    }

    return null;
  }
示例#3
0
  private static Bitmap getDefaultHeadImage() throws Exception {

    if (sm_defaultHeadImage == null) {

      if (sm_mainApp == null && UiApplication.getUiApplication() instanceof recvMain) {
        sm_mainApp = (recvMain) UiApplication.getUiApplication();
      }

      byte[] bytes =
          IOUtilities.streamToBytes(
              sm_mainApp
                  .getClass()
                  .getResourceAsStream(
                      fsm_largeHeadImage ? "/defaultHeadImage_l.png" : "/defaultHeadImage.png"));
      sm_defaultHeadImage = EncodedImage.createEncodedImage(bytes, 0, bytes.length).getBitmap();
      sm_defaultHeadImageHashCode = bytes.length;
    }

    return sm_defaultHeadImage;
  }
示例#4
0
 public void run() {
   FileSelectorPopupScreen fs =
       new FileSelectorPopupScreen(
           System.getProperty("fileconn.dir.memorycard.photos").substring(8),
           new String[] {"png", "jpg", "gif", "jpeg"});
   fs.pickFile();
   if (Util.cekDir("file:///" + fs.getFile(), false)) {
     int apa =
         Dialog.ask(
             "Resize if bigger than Screen",
             new String[] {"100%", "80%", "50%", "30%", "10%"},
             0);
     String data = Util.bacaFile("file:///" + fs.getFile());
     EncodedImage img =
         EncodedImage.createEncodedImage(data.getBytes(), 0, data.getBytes().length);
     int sw = 0, sh = 0;
     if (apa == 0) {
       sw = Display.getWidth();
       sh = Display.getHeight();
     } else if (apa == 1) {
       sw = (int) (0.8 * Display.getWidth());
       sh = (int) (0.8 * Display.getHeight());
     } else if (apa == 2) {
       sw = (int) (0.5 * Display.getWidth());
       sh = (int) (0.5 * Display.getHeight());
     } else if (apa == 3) {
       sw = (int) (0.3 * Display.getWidth());
       sh = (int) (0.3 * Display.getHeight());
     } else if (apa == 4) {
       sw = (int) (0.1 * Display.getWidth());
       sh = (int) (0.1 * Display.getHeight());
     } else {
       return;
     }
     gbrfield.setGbr(ImageUtil.bestFit2(img, sw, sh).getBitmap());
     img = null;
   }
 }
示例#5
0
  private static boolean LoadWeiboImage(WeiboHeadImage _image) {

    String t_imageFilename = null;

    try {

      if (!sm_mainApp.isSDCardAvailable(false)) {
        return true;
      }

      if (fsm_largeHeadImage) {
        if (_image.m_isWeiboOrIM) {
          t_imageFilename =
              sm_mainApp.GetWeiboHeadImageDir(_image.m_weiboStyle) + _image.m_userID + "_l.png";
        } else {
          t_imageFilename =
              sm_mainApp.GetIMHeadImageDir(_image.m_weiboStyle) + _image.m_userID + "_l.png";
        }

      } else {
        if (_image.m_isWeiboOrIM) {
          t_imageFilename =
              sm_mainApp.GetWeiboHeadImageDir(_image.m_weiboStyle) + _image.m_userID + ".png";
        } else {
          t_imageFilename =
              sm_mainApp.GetIMHeadImageDir(_image.m_weiboStyle) + _image.m_userID + ".png";
        }
      }

      FileConnection t_fc = (FileConnection) Connector.open(t_imageFilename, Connector.READ_WRITE);
      try {
        if (t_fc.exists()) {
          InputStream t_fileIn = t_fc.openInputStream();
          try {

            byte[] t_data = new byte[(int) t_fc.fileSize()];
            sendReceive.ForceReadByte(t_fileIn, t_data, t_data.length);

            _image.m_headImage =
                EncodedImage.createEncodedImage(t_data, 0, t_data.length).getBitmap();
            _image.m_dataHash = t_data.length;

          } finally {
            t_fileIn.close();
            t_fileIn = null;
          }

          return true;
        }

      } finally {
        t_fc.close();
        t_fc = null;
      }
    } catch (Exception e) {
      debugOutput("LWI:" + t_imageFilename);
      exceptionOutput("LWI1", e);
    }

    return false;
  }
  public void run() {
    if (URL != null && URL.length() > 0) {
      ConnectionFactory f = new ConnectionFactory();
      ConnectionDescriptor descr = f.getConnection(URL);
      String targetURL;
      targetURL = descr.getUrl();
      HttpConnection httpConnection = null;
      DataOutputStream httpDataOutput = null;
      InputStream httpInput = null;
      int rc;

      try {
        httpConnection = (HttpConnection) Connector.open(targetURL);
        rc = httpConnection.getResponseCode();
        if (rc != HttpConnection.HTTP_OK) {
          throw new IOException("HTTP response code: " + rc);
        }
        httpInput = httpConnection.openInputStream();
        InputStream inp = httpInput;
        byte[] b = IOUtilities.streamToBytes(inp);
        final EncodedImage hai = EncodedImage.createEncodedImage(b, 0, b.length);
        final Bitmap bmp = hai.getBitmap();
        System.out.println(bmp.toString());

        if (target != null) {
          UiApplication.getUiApplication()
              .invokeLater(
                  new Runnable() {

                    public void run() {
                      // TODO Auto-generated method stub
                      if (isDetailEvent == true) {
                        target.setBitmap(
                            DisplayHelper.CreateScaledCopyKeepAspectRatio(
                                bmp,
                                (int) (Display.getWidth() * 0.7),
                                (int) (Display.getHeight() * 0.3)));
                      } else {
                        target.setBitmap(
                            DisplayHelper.CreateScaledCopyKeepAspectRatio(
                                bmp, target.getBitmapWidth(), target.getBitmapHeight()));
                      }
                    }
                  });
        }

        if (localPath != null) {
          Utils.saveBitmap(localPath, bmp);
        }

        if (imageCache != null) {
          if (Utils.saveBitmap(
              ImageCacheModel.getImageCacheDirectory() + imageCache.getFileName(), bmp)) {
            //		    		   CacheUtils.getInstance().addImageCache(imageCache);
            System.out.println("image write success");
          }
        }

        if (callback != null) callback.onImageDownloaded(true, bmp);

      } catch (Exception ex) {
        System.out.println("URL Bitmap Error........" + ex.getMessage());
      } finally {
        try {
          if (httpInput != null) httpInput.close();
          if (httpDataOutput != null) httpDataOutput.close();
          if (httpConnection != null) httpConnection.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }