From f1cdac85978a661cd7092e12520460aa6e3edd69 Mon Sep 17 00:00:00 2001 From: george Date: Mon, 4 Jun 2012 18:02:00 +0800 Subject: [PATCH] update service --- weibosrc/com/weibo/client/WeiboDataService.java | 82 +++++++++++++++---------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/weibosrc/com/weibo/client/WeiboDataService.java b/weibosrc/com/weibo/client/WeiboDataService.java index 8113c73..76f4d49 100644 --- a/weibosrc/com/weibo/client/WeiboDataService.java +++ b/weibosrc/com/weibo/client/WeiboDataService.java @@ -1,15 +1,16 @@ -package com.weibo.client; -import com.weibo.net.AccessToken; -import com.weibo.net.WeiboException; -import com.weibo.sina.Authorize; -import com.weibo.sina.TimeLineView; +package com.weibo.client; import android.app.Service; import android.content.Intent; import android.content.SharedPreferences; import android.os.Binder; +import android.os.Handler; import android.os.IBinder; +import android.os.Message; + +import com.weibo.net.AccessToken; +import com.weibo.net.WeiboException; public class WeiboDataService extends Service { @@ -17,8 +18,11 @@ public class WeiboDataService extends Service { * Class for clients to access. Because we know this service always runs in * the same process as its clients, we don't need to deal with IPC. */ + private boolean isWeiboInit = false; - + + private static final int INIT = 0; + public class LocalBinder extends Binder { WeiboDataService getService() { return WeiboDataService.this; @@ -33,37 +37,22 @@ public class WeiboDataService extends Service { // TODO Auto-generated method stub return mBinder; } - - public void init(){ - + + public void init() { + } - public void reflash(){ - + + public void reflash() { + } - - public void pull(Paging paging){ - + + public void pull(Paging paging) { + } @Override public void onCreate() { - SharedPreferences user = getSharedPreferences("oauth", 0); - String oauth_token = user.getString("oauth_token", ""); - String oauth_token_secret = user.getString("oauth_token_secret", ""); - if (oauth_token.length() > 0 && oauth_token_secret.length() > 0) { - AccessToken accessToken = new AccessToken(oauth_token, Weibo.CONSUMER_SECRET); - accessToken.setExpiresIn(oauth_token_secret); - Weibo.getInstance().setAccessToken(accessToken); - Weibo.getInstance().setContext(getBaseContext()); - Weibo.setUid(user.getString("uid", "")); - try { - Weibo.getInstance().getOAuthUid(); - } catch (WeiboException e) { - isWeiboInit=false; - e.printStackTrace(); - } - isWeiboInit = true; - } + mHandler.obtainMessage(INIT).sendToTarget(); super.onCreate(); } @@ -74,7 +63,36 @@ public class WeiboDataService extends Service { public void setWeiboInit(boolean isWeiboInit) { this.isWeiboInit = isWeiboInit; } - + + private Handler mHandler = new Handler() { + + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case 0: + SharedPreferences user = getSharedPreferences("oauth", 0); + String oauth_token = user.getString("oauth_token", ""); + String oauth_token_secret = user.getString("oauth_token_secret", ""); + if (oauth_token.length() > 0 && oauth_token_secret.length() > 0) { + AccessToken accessToken = new AccessToken(oauth_token, + Weibo.CONSUMER_SECRET); + accessToken.setExpiresIn(oauth_token_secret); + Weibo.getInstance().setAccessToken(accessToken); + Weibo.getInstance().setContext(getBaseContext()); + Weibo.setUid(user.getString("uid", "")); + try { + Weibo.getInstance().getOAuthUid(); + } catch (WeiboException e) { + isWeiboInit = false; + e.printStackTrace(); + } + isWeiboInit = true; + } + break; + } + } + + }; } -- 2.11.4.GIT