コード例 #1
1
ファイル: WeiboHeadImage.java プロジェクト: yunsite/yuchbox
  public static WeiboHeadImage SearchHeadImage(
      Vector _imageList, String _imageID, byte _style, int _hashCode, boolean _isWeiboOrIM)
      throws Exception {
    synchronized (_imageList) {
      for (int i = 0; i < _imageList.size(); i++) {
        WeiboHeadImage t_image = (WeiboHeadImage) _imageList.elementAt(i);

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

          if ((t_image.m_dataHash != _hashCode && _hashCode != 0)) {

            // change the new hash code and request head image
            //
            t_image.m_dataHash = _hashCode;

            // the head image has been changed
            // must request image
            //
            SendHeadImageQueryMsg(_imageID, _style, _isWeiboOrIM);
          }

          return t_image;
        }
      }

      WeiboHeadImage t_image = new WeiboHeadImage();

      t_image.m_isWeiboOrIM = _isWeiboOrIM;
      t_image.m_userID = _imageID;
      t_image.m_headImage = getDefaultHeadImage();
      t_image.m_dataHash = _hashCode;
      t_image.m_weiboStyle = _style;

      _imageList.addElement(t_image);

      if (recvMain.isSDCardSupport()) {

        if (sm_loadImageThread == null) {

          sm_loadImageThread =
              new Thread() {

                public void run() {

                  while (true) {

                    try {
                      synchronized (sm_loadImageQueue) {
                        while (sm_loadImageQueue.isEmpty()) {
                          try {
                            sm_loadImageQueue.wait();
                          } catch (Exception e) {
                            exceptionOutput("WHI0", e);
                          }
                        }
                      }

                      WeiboHeadImage t_image = (WeiboHeadImage) sm_loadImageQueue.elementAt(0);

                      if (!LoadWeiboImage(t_image)) {
                        SendHeadImageQueryMsg(
                            t_image.m_userID, t_image.m_weiboStyle, t_image.m_isWeiboOrIM);
                      }

                      sm_loadImageQueue.removeElementAt(0);

                    } catch (Exception e) {
                      exceptionOutput("WHI1", e);
                    }
                  }
                }
              };

          sm_loadImageThread.start();
        }

        if (t_image.m_dataHash != 0) {

          // has image hash code (has head image, maybe some weibo or IM has not set image)
          //
          synchronized (sm_loadImageQueue) {
            sm_loadImageQueue.addElement(t_image);

            try {
              sm_loadImageQueue.notify();
            } catch (Exception e) {
              exceptionOutput("WHI2", e);
            }
          }
        }
      }

      return t_image;
    }
  }
コード例 #2
0
ファイル: WeiboHeadImage.java プロジェクト: yunsite/yuchbox
  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;
        }
      }
    }
  }
コード例 #3
0
ファイル: WeiboHeadImage.java プロジェクト: yunsite/yuchbox
  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;
  }