コード例 #1
0
ファイル: VClient.java プロジェクト: Vendar/cactus
 public boolean addAccount(VAccount account) {
   if (account == null) {
     return false;
   }
   try {
     this.sinaWeibo.setOAuthAccessToken(account.getAccessToken(), account.getTokenSecret());
     weibo4android.User me = this.sinaWeibo.verifyCredentials();
     if (me != null) {
       account.setUserName(me.getScreenName());
       CactusDb.getInstance().saveAccount(account);
     } else {
       return false;
     }
   } catch (WeiboException e) {
     e.printStackTrace();
     return false;
   }
   this.accountAdapter.add(account);
   if (this.activatedAccount != null) {
     this.sinaWeibo.setOAuthAccessToken(
         this.activatedAccount.getAccessToken(), this.activatedAccount.getTokenSecret());
   } else {
     this.activatedAccount = account;
   }
   return true;
 }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.home);

    listView = (ListView) findViewById(R.id.lv_weibos);
    writeBtn = (Button) findViewById(R.id.btn_writer);
    userName = (TextView) findViewById(R.id.txt_wb_title);
    reflesh = (Button) findViewById(R.id.btn_refresh);

    webInstance = this;
    mContext = getApplicationContext();
    accessInfo = InfoHelper.getAccessInfo(mContext);

    accessToken = accessInfo.getAccessToken();
    accessSecret = accessInfo.getAccessSecret();
    userId = accessInfo.getUserID();

    dialog = new ProgressDialog(webInstance);
    dialog.setIndeterminate(false);
    dialog.setCancelable(true);

    System.setProperty("weibo4j.oauth.consumerKey", ConstantsUtils.CONSUMER_KEY);
    System.setProperty("weibo4j.oauth.consumerSecret", ConstantsUtils.CONSUMER_SECRET);

    // 得到一个weibo对象
    weibo = weibo4android.androidexamples.OAuthConstant.getInstance().getWeibo();
    // 设置微博的accessToken和accessSecret
    weibo.setToken(accessToken, accessSecret);

    try {
      user = weibo.showUser(userId);
      userName.setText(user.getName());
    } catch (WeiboException e1) {
      e1.printStackTrace();
    }

    try {
      // 得到weibo数据,使用WeiboAdapater进行显示
      stas = weibo.getFriendsTimeline();
      WeiboAdapter adapter = new WeiboAdapter(mContext, stas);
      listView.setAdapter(adapter);
    } catch (WeiboException e) {
      e.printStackTrace();
    }

    reflesh.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {

            Intent intent = new Intent();
            intent.setClass(FriendsTimeLineActivity.this, FriendsTimeLineActivity.class);
            startActivity(intent);
          }
        });

    writeBtn.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            Intent intent = new Intent();

            Bundle bundle = getIntent().getExtras();
            if (bundle != null) {
              bundle.putString("thisLarge", bundle.getString("thisLarge"));
              bundle.putString("accessToken", accessToken);
              bundle.putString("accessSecret", accessSecret);
              bundle.putString("userId", userId);
              intent.putExtras(bundle);
            }
            intent.setClass(FriendsTimeLineActivity.this, JSUMainActivity.class);
            startActivity(intent);
          }
        });
  }