コード例 #1
0
  @Test
  public void destroyOutboxDirectMessage() {
    try {
      Paging<User> paging = new Paging<User>();
      List<User> listUser = weibo.getFollowers(paging);
      assertTrue(ListUtil.isNotEmpty(listUser));

      User user = listUser.get(0);
      assertNotNull(user);

      String text = "测试删除私信接口:destroyOutboxDirectMessage,莫慌," + System.currentTimeMillis();
      DirectMessage message = weibo.sendDirectMessage(user.getDisplayName(), text);
      assertNotNull(message);
      assertTrue(StringUtil.isNotEmpty(message.getId()));

      TestUtil.sleep();

      DirectMessage deletedMessage = weibo.destroyOutboxDirectMessage(message.getId());
      assertNotNull(deletedMessage);
      assertTrue(StringUtil.isNotEmpty(deletedMessage.getId()));
    } catch (LibException e) {
      e.printStackTrace();
      assertTrue(false);
    }
  }
コード例 #2
0
ファイル: HotStatusesTask.java プロジェクト: Terry-L/YiBo
  @Override
  protected List<com.cattong.entity.Status> doInBackground(Void... params) {
    if (microBlog == null) {
      return null;
    }

    List<com.cattong.entity.Status> listStatus = null;
    paging = adapter.getPaging();
    com.cattong.entity.Status max = adapter.getMin();
    paging.setGlobalMax(max);

    if (paging.moveToNext()) {
      try {
        if (type == StatusCatalog.Hot_Retweet.getCatalogNo()) {
          listStatus = microBlog.getDailyHotRetweets(paging);
        } else {
          listStatus = microBlog.getDailyHotComments(paging);
        }
      } catch (LibException e) {
        if (Logger.isDebug()) Log.e(TAG, "Task", e);
        message = ResourceBook.getResultCodeValue(e.getErrorCode(), context);
        paging.moveToPrevious();
      }
    }
    ResponseCountUtil.getResponseCounts(listStatus, microBlog);

    return listStatus;
  }
コード例 #3
0
  @Override
  protected User doInBackground(Void... params) {
    if (image == null) {
      return null;
    }

    Weibo microBlog = GlobalVars.getMicroBlog(accountId);
    if (microBlog == null) {
      return null;
    }

    User user = null;
    try {

      if (image != null) {
        String fileExtension = FileUtil.getFileExtensionFromName(image.getName());
        int size = ImageQuality.Low.getSize();
        ImageQuality quality = sheJiaoMao.getImageUploadQuality();
        if (quality == ImageQuality.High || GlobalVars.NET_TYPE == NetType.WIFI) {
          size = ImageQuality.High.getSize();
        } else if (quality == ImageQuality.Middle || quality == ImageQuality.Low) {
          size = quality.getSize();
          if (Logger.isDebug()) Log.d(TAG, "prefix size: " + size);
          // 对低速网络进行压缩
          if (GlobalVars.NET_TYPE == NetType.MOBILE_GPRS
              || GlobalVars.NET_TYPE == NetType.MOBILE_EDGE) {
            size = ImageQuality.Low.getSize();
          }
        }
        String destName =
            ImageCache.getTempFolder()
                + File.separator
                + System.currentTimeMillis()
                + "."
                + fileExtension;
        File dest = new File(destName);
        boolean isSuccess = ImageUtil.scaleImageFile(image, dest, size);
        if (isSuccess) {
          image = dest;
        }
        user = microBlog.updateProfileImage(image);
      }
    } catch (LibException e) {
      if (Logger.isDebug()) Log.e(TAG, "Task", e);
      resultMsg = ResourceBook.getResultCodeValue(e.getErrorCode(), context);
    }

    return user;
  }
コード例 #4
0
  @Override
  protected Boolean doInBackground(Void... params) {
    boolean isSuccess = false;
    if (microBlog == null || type == null) {
      return isSuccess;
    }

    try {
      isSuccess = microBlog.resetUnreadCount(type);
    } catch (LibException e) {
      if (Logger.isDebug()) e.printStackTrace();
    }

    return isSuccess;
  }
コード例 #5
0
  @Override
  protected Bitmap doInBackground(Void... params) {
    if (imageView == null || url == null) {
      return bitmap;
    }

    if (Logger.isDebug()) Log.i(LOG_TAG, "Get Header image from remote!");
    try {
      Bitmap newBitmap = ImageUtil.getBitmapByUrl(url);

      /** 加入cache中* */
      if (newBitmap != null) {
        // 生成mini图
        Bitmap scaleBitmap =
            ImageUtil.scaleBitmapTo(newBitmap, SheJiaoMaoApplication.getSmallAvatarSize());
        Bitmap roundBitmap = ImageUtil.getRoundedCornerBitmap(scaleBitmap);
        if (scaleBitmap != newBitmap) {
          scaleBitmap.recycle();
        }

        CachedImage resultWrap = new CachedImage(roundBitmap);
        if (isMini) {
          bitmap = roundBitmap;
        }
        imageInfo.setCacheType(CachedImageKey.IMAGE_HEAD_MINI);
        imageCache.put(imageInfo, resultWrap);

        // 生成normal图
        scaleBitmap =
            ImageUtil.scaleBitmapTo(newBitmap, SheJiaoMaoApplication.getNormalAvatarSize());
        roundBitmap = ImageUtil.getRoundedCornerBitmap(scaleBitmap);
        scaleBitmap.recycle();

        resultWrap = new CachedImage(roundBitmap);
        imageInfo.setCacheType(CachedImageKey.IMAGE_HEAD_NORMAL);
        imageCache.put(imageInfo, resultWrap);

        newBitmap.recycle();
        if (!isMini) {
          bitmap = roundBitmap;
        }
      }
    } catch (LibException e) {
      if (Logger.isDebug()) Log.e(LOG_TAG, e.getMessage(), e);
    }

    return bitmap;
  }
コード例 #6
0
ファイル: UpdateCommentTask.java プロジェクト: kdeplus/YiBo
  @Override
  protected Comment doInBackground(Void... params) {
    if (StringUtil.isEmpty(text)) {
      resultMsg = context.getString(R.string.msg_comment_empty);
      return null;
    }
    if (StringUtil.isEmpty(statusId)) {
      return null;
    }

    try {
      if (commentId == null) {
        newComment = microBlog.createComment(text, statusId);
      } else {
        newComment = microBlog.createComment(text, statusId, commentId);
      }
    } catch (LibException e) {
      if (Constants.DEBUG) Log.e(TAG, "Task", e);
      resultMsg = ResourceBook.getResultCodeValue(e.getErrorCode(), context);
    }

    return newComment;
  }
コード例 #7
0
ファイル: XAuthTask.java プロジェクト: JeffLiang/YiBo
  @Override
  protected Boolean doInBackground(Void... arg) {
    boolean isSuccess = false;
    if (auth == null) {
      return isSuccess;
    }

    oauthConfig = auth.getoAuthConfig();
    if (oauthConfig == null) {
      return isSuccess;
    }

    String username = auth.getAccessToken();
    String password = auth.getAccessSecret();
    ServiceProvider sp = auth.getServiceProvider();
    try {
      if (NetUtil.isNETWAP()
          && (URLUtil.isHttpsUrl(oauthConfig.getRequestTokenUrl())
              || URLUtil.isHttpsUrl(oauthConfig.getAccessTokenUrl()))) {
        throw new SheJiaoMaoException(SheJiaoMaoException.NET_HTTPS_UNDER_CMWAP);
      }

      Authorization resultAuth = null;
      switch (sp) {
        case NetEase:
          if (username.indexOf("@") < 0) {
            username += "@163.com"; // 如果用户没输入完整的邮件地址,则自动追加 @163.com
          }
          // 直落
        case Sina:
        case Sohu:
        case Fanfou:
        case Twitter:
          auth.setAccessToken(username);
          auth.setAccessSecret(password);
          if (oauthConfig.getAuthVersion() == Authorization.AUTH_VERSION_OAUTH_2) {
            OAuth2AuthorizeHelper authHelper = new OAuth2AuthorizeHelper();
            resultAuth = authHelper.retrieveAccessToken(auth);
          } else {
            OAuthAuthorizeHelper authHelper = new OAuthAuthorizeHelper();
            resultAuth = authHelper.retrieveAccessToken(auth);
          }

          break;
        default:
          break;
      }

      if (resultAuth == null) {
        throw new SheJiaoMaoException(SheJiaoMaoException.AUTH_TOKEN_IS_NULL);
      }

      Logger.debug(resultAuth.toString());

      BaseUser user = null;
      if (sp.isSns()) {
        Sns sns = SnsFactory.getInstance(resultAuth);
        String userId = sns.getUserId();
        user = sns.showUser(userId);
      } else {
        Weibo mBlog = WeiboFactory.getInstance(resultAuth);
        user = mBlog.verifyCredentials();
      }

      final LocalAccountDao accountDao = new LocalAccountDao(context);
      if (accountDao.isExists(sp, user.getUserId())) {
        throw new SheJiaoMaoException(SheJiaoMaoException.ACCOUNT_IS_EXIST);
      }

      if (accountDao.findAllValid() == null) {
        isMakeDefault = true;
      }

      account = new LocalAccount();
      account.setAuthorization(auth);
      account.setUser(user);
      account.setState(Account.STATE_ACTIVE);
      account.setAppKey(oauthConfig.getConsumerKey());
      account.setAppSecret(oauthConfig.getConsumerSecret());
      account.setCreatedAt(new Date());
      accountDao.add(account);

      if (isMakeDefault) {
        accountDao.makeDefault(account);
      }

      GlobalVars.addAccount(account);

      isSuccess = true;
    } catch (LibException e) {
      resultMsg = ResourceBook.getResultCodeValue(e.getErrorCode(), context);
      Logger.error(resultMsg, e);
      context.resetAuthToken();
    } catch (SheJiaoMaoException e) {
      resultMsg = ResourceBook.getResultCodeValue(e.getStatusCode(), context);
      Logger.error(resultMsg, e);
      context.resetAuthToken();
    }

    return isSuccess;
  }