Ejemplo n.º 1
0
  private void loadMoreData(final long maxId) {
    StatusesAPI statusAPI = new StatusesAPI(mAccessToken);
    statusAPI.friendsTimeline(
        0,
        maxId,
        20,
        1,
        false,
        FEATURE.ALL,
        false,
        new RequestListener() {

          @Override
          public void onComplete(String result) {

            Gson gson = new Gson();
            WeiboObject response = gson.fromJson(result, WeiboObject.class);

            for (Statuses status : response.statuses) {
              mAdapter.addStatuses(status);
              mMaxId = status.id - 1;
            }

            if (maxId == 0 && response.statuses.size() > 0) {
              mSinceId = response.statuses.get(0).id;
            }

            runOnUiThread(
                new Runnable() {

                  @Override
                  public void run() {

                    setLastSyncTime(Util.getNowLocaleTime());
                    mAdapter.notifyDataSetChanged();
                    // Call onLoadMoreComplete when the LoadMore
                    // task, has finished
                    mListView.onLoadMoreComplete();
                  }
                });
          }

          @Override
          public void onError(final WeiboException e) {
            Util.showToast(TimelineActivity.this, "Error:" + e.getMessage());
          }

          @Override
          public void onIOException(IOException e) {
            // TODO Auto-generated method stub

          }
        });
  }
Ejemplo n.º 2
0
  private void composeNewPost() {
    StatusesAPI api = new StatusesAPI(mAccessToken);
    mContent = mEdit.getText().toString();
    if (TextUtils.isEmpty(mContent)) return;

    if (!TextUtils.isEmpty(mPicPath)) {
      Util.showToast(this, R.string.sending);
      api.upload(this.mContent, this.mPicPath, mLatitude, mLongitude, this);
    } else {
      // Just update a text weibo!
      api.update(mContent, mLatitude, mLongitude, this);
    }
  }
Ejemplo n.º 3
0
  public void loadReposts() {
    StatusesAPI statusesAPI = new StatusesAPI(BaseActivity.token);
    statusesAPI.repostTimeline(
        status.getId(),
        0,
        0,
        20,
        1,
        WeiboAPI.AUTHOR_FILTER.ALL,
        new RequestListener() {
          @Override
          public void onComplete(String response) {
            JSONTokener tokener = new JSONTokener(response);
            try {
              JSONArray jsonArray = ((JSONObject) tokener.nextValue()).getJSONArray("reposts");
              List<Status> statuses = new ArrayList<Status>();
              for (int i = 0; i < jsonArray.length(); ++i) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                statuses.add(JSONParser.parseStatus(jsonObject));
              }

              Message message = new Message();
              message.obj = statuses;
              message.what = UPDATE_REPO;
              handler.sendMessage(message);

            } catch (JSONException e) {
              e.printStackTrace();
            }
          }

          @Override
          public void onIOException(IOException e) {}

          @Override
          public void onError(WeiboException e) {}
        });
  }
Ejemplo n.º 4
0
  private void shareXinLang() {
    pDialog = ProgressDialog.show(context, "发布中", "请稍等...", true);
    StatusesAPI api = new StatusesAPI(accessToken);
    if (textString.length() >= 140) {
      Toasts.toast(context, "字数不能大于140字符");
      return;
    }
    api.upload(
        textString,
        imagePath,
        "190.0",
        "190.0",
        new RequestListener() {
          @Override
          public void onIOException(IOException arg0) {
            message = new Message();
            message.what = IOEXCEPTION;
            handler.sendMessage(message);
            Log.i("hck", arg0.toString());
          }

          @Override
          public void onError(WeiboException arg0) {
            message = new Message();
            message.what = ERROR;
            handler.sendMessage(message);
            Log.i("hck", arg0.toString());
          }

          @Override
          public void onComplete(String arg0) {
            message = new Message();
            message.what = SUCCESS;
            handler.sendMessage(message);
          }
        });
  }
Ejemplo n.º 5
0
  public static String WeiboStatusUpload(
      Context context,
      final String content,
      final String pic,
      final RequestListener requestListener) {

    weiboUpLoadResult = "success";
    if (accessToken == null) {
      WeiboParameters parameters = new WeiboParameters();
      parameters.add("forcelogin", "true");
      com.weibo.sdk.android.util.Utility.isWifi(context);
      weibo.startDialog(
          context,
          parameters,
          new WeiboAuthListener() {
            // weibo.authorize(context, new WeiboAuthListener() {
            @Override
            public void onComplete(Bundle bundle) {
              access_token = bundle.getString("access_token");
              expires_in = bundle.getString("expires_in");
              accessToken = new Oauth2AccessToken(access_token, expires_in);
              try {
                SendToken();
              } catch (IOException e) {
                e.printStackTrace();
              }

              StatusesAPI statusesAPI = new StatusesAPI(accessToken);
              if (requestListener != null) {
                statusesAPI.upload(content, pic, null, null, requestListener);
              } else {
                statusesAPI.upload(
                    content,
                    pic,
                    null,
                    null,
                    new RequestListener() {
                      @Override
                      public void onComplete(String s) {
                        weiboUpLoadResult = s;
                        weiboUpLoadResult = "success";
                        // Toast.makeText(Record_Journal.this, "微博发布成功", Toast.LENGTH_SHORT).show();
                      }

                      @Override
                      public void onIOException(IOException e) {
                        weiboUpLoadResult = e.getMessage();
                        weiboUpLoadResult = "fail";
                        e.printStackTrace();
                        // Toast.makeText(Record_Journal.this, "微博发布失败:"+e.getMessage(),
                        // Toast.LENGTH_SHORT).show();
                      }

                      @Override
                      public void onError(WeiboException e) {
                        weiboUpLoadResult = e.getMessage();
                        weiboUpLoadResult = "fail";
                        e.printStackTrace();
                        // Toast.makeText(Record_Journal.this, "微博发布失败:"+e.getMessage(),
                        // Toast.LENGTH_SHORT).show();
                      }
                    });
              }
            }

            @Override
            public void onWeiboException(WeiboException e) {
              weiboUpLoadResult = e.getMessage();
              weiboUpLoadResult = "fail";
              e.printStackTrace();
              clearToken();
            }

            @Override
            public void onError(WeiboDialogError weiboDialogError) {
              weiboUpLoadResult = weiboDialogError.getMessage();
              weiboUpLoadResult = "fail";
              weiboDialogError.printStackTrace();
              clearToken();
            }

            @Override
            public void onCancel() {
              clearToken();
            }
          });
    } else {
      StatusesAPI statusesAPI = new StatusesAPI(accessToken);
      if (requestListener != null) {
        statusesAPI.upload(content, pic, null, null, requestListener);
      } else {
        statusesAPI.upload(
            content,
            pic,
            null,
            null,
            new RequestListener() {
              @Override
              public void onComplete(String s) {
                weiboUpLoadResult = s;
                weiboUpLoadResult = "success";
                // Toast.makeText(Record_Journal.this, "微博发布成功", Toast.LENGTH_SHORT).show();
              }

              @Override
              public void onIOException(IOException e) {
                weiboUpLoadResult = e.getMessage();
                weiboUpLoadResult = "fail";
                e.printStackTrace();
                // Toast.makeText(Record_Journal.this, "微博发布失败:"+e.getMessage(),
                // Toast.LENGTH_SHORT).show();
              }

              @Override
              public void onError(WeiboException e) {
                weiboUpLoadResult = e.getMessage();
                weiboUpLoadResult = "fail";
                e.printStackTrace();
                // Toast.makeText(Record_Journal.this, "微博发布失败:"+e.getMessage(),
                // Toast.LENGTH_SHORT).show();
              }
            });
      }
    }

    return weiboUpLoadResult;
  }
Ejemplo n.º 6
0
  @Override
  public void onClick(View v) {
    if (v.equals(btnFav)) {
      Util.showToast(BlogFunActivity.this, "api访问请求已执行,请等待结果");
      FavoritesAPI fav = new FavoritesAPI(MainActivity.accessToken);
      fav.create(
          blogId,
          new RequestListener() {
            @Override
            public void onIOException(IOException e) {
              e.printStackTrace();
            }

            @Override
            public void onError(WeiboException e) {
              Util.showToast(BlogFunActivity.this, "收藏失败:" + e.getMessage());
            }

            @Override
            public void onComplete(String response) {
              //                    Util.showToast(BlogFunActivity.this,response);
              if (mTv != null) {
                Util.setTextViewContent(BlogFunActivity.this, mTv, "收藏结果:" + response);
              }
            }
          });
    } else if (v.equals(btnForward)) {
      Util.showToast(BlogFunActivity.this, "api访问请求已执行,请等待结果");
      StatusesAPI status = new StatusesAPI(MainActivity.accessToken);
      status.repost(
          blogId,
          "无" + System.currentTimeMillis(),
          WeiboAPI.COMMENTS_TYPE.NONE,
          new RequestListener() {

            @Override
            public void onIOException(IOException e) {
              e.printStackTrace();
            }

            @Override
            public void onError(WeiboException e) {
              Util.showToast(BlogFunActivity.this, "转发失败:" + e.getMessage());
            }

            @Override
            public void onComplete(String response) {
              //                            Util.showToast(BlogFunActivity.this,response);
              if (mTv != null) {
                Util.setTextViewContent(BlogFunActivity.this, mTv, "转发结果:" + response);
              }
            }
          });
    } else if (v.equals(btnComment)) {
      Util.showToast(BlogFunActivity.this, "api访问请求已执行,请等待结果");
      CommentsAPI comment = new CommentsAPI(MainActivity.accessToken);
      comment.create(
          "顶!" + System.currentTimeMillis(),
          blogId,
          false,
          new RequestListener() {
            @Override
            public void onIOException(IOException e) {
              e.printStackTrace();
            }

            @Override
            public void onError(WeiboException e) {
              Util.showToast(BlogFunActivity.this, "评论失败:" + e.getMessage());
            }

            @Override
            public void onComplete(String response) {
              //                    Util.showToast(BlogFunActivity.this,response);
              if (mTv != null) {
                Util.setTextViewContent(BlogFunActivity.this, mTv, "评论结果:" + response);
              }
            }
          });
    }
  }
Ejemplo n.º 7
0
  private void getFriendsTimeline(final long sinceId, final long maxId) {

    hideErrorIndicator();
    showLoadingIndicator();

    StatusesAPI statusAPI = new StatusesAPI(mAccessToken);
    statusAPI.friendsTimeline(
        sinceId,
        maxId,
        20,
        1,
        false,
        FEATURE.ALL,
        false,
        new RequestListener() {

          @Override
          public void onComplete(String result) {

            // Util.writeUpdateInfo(result);
            Gson gson = new Gson();
            WeiboObject response = gson.fromJson(result, WeiboObject.class);

            for (Statuses status : response.statuses) {
              mAdapter.addStatuses(status);

              if (sinceId == 0) {
                mMaxId = status.id - 1;
              }
            }

            if (maxId == 0 && response.statuses.size() > 0) {
              mSinceId = response.statuses.get(0).id;
            }

            runOnUiThread(
                new Runnable() {

                  @Override
                  public void run() {
                    hideLoadingIndicator();
                    aq.id(R.id.placeholder_error).gone();

                    showContents();
                    mAdapter.notifyDataSetChanged();
                    setLastSyncTime(Util.getNowLocaleTime());
                  }
                });
          }

          @Override
          public void onError(final WeiboException e) {
            runOnUiThread(
                new Runnable() {

                  @Override
                  public void run() {
                    showErrorIndicator();
                    aq.id(R.id.error_msg).text(e.getMessage());
                    aq.id(R.id.retry_button)
                        .clicked(
                            new OnClickListener() {

                              @Override
                              public void onClick(View v) {
                                getFriendsTimeline(sinceId, maxId);
                              }
                            });
                  }
                });
          }

          @Override
          public void onIOException(IOException e) {}
        });
  }
Ejemplo n.º 8
0
  private void refreshStatus(long sinceId) {
    mActionBar.setProgressBarVisibility(View.VISIBLE);

    StatusesAPI statusAPI = new StatusesAPI(mAccessToken);
    statusAPI.friendsTimeline(
        sinceId,
        0,
        20,
        1,
        false,
        FEATURE.ALL,
        false,
        new RequestListener() {

          @Override
          public void onComplete(String result) {
            Gson gson = new Gson();
            WeiboObject response = gson.fromJson(result, WeiboObject.class);

            final int refreshCount = response.statuses.size();
            Log.d("newsMsgLists length == " + refreshCount);
            if (refreshCount > 0) {
              mSinceId = response.statuses.get(0).id;
              mAdapter.addNewestStatuses(response.statuses);
            }

            runOnUiThread(
                new Runnable() {

                  @Override
                  public void run() {
                    mActionBar.setProgressBarVisibility(View.GONE);
                    mAdapter.notifyDataSetChanged();
                    // Call onRefreshComplete when the list has been
                    // refreshed.
                    mListView.onRefreshComplete();
                    mListView.setLastUpdated(getLastSyncTime(Preferences.PREF_LAST_SYNC_TIME));

                    setLastSyncTime(Util.getNowLocaleTime());

                    if (refreshCount > 0) {
                      displayToast(
                          String.format(
                              getResources().getString(R.string.new_blog_toast), refreshCount));
                    } else {
                      displayToast(R.string.no_new_blog_toast);
                    }
                  }
                });
          }

          @Override
          public void onError(final WeiboException e) {
            Util.showToast(TimelineActivity.this, "Error:" + e.getMessage());
          }

          @Override
          public void onIOException(IOException e) {
            // TODO Auto-generated method stub

          }
        });
  }