Skip to content

Commit c266348

Browse files
committed
Sina Oauth2.0 modify
1 parent db88317 commit c266348

File tree

6 files changed

+113
-12
lines changed

6 files changed

+113
-12
lines changed

res/drawable-hdpi/avatar_qfish.png

35.2 KB
Loading

res/layout/team_introduction.xml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
44
android:layout_width="match_parent"
5-
android:layout_height="match_parent">
5+
android:layout_height="wrap_content">
66
<LinearLayout
77
android:orientation="vertical"
88
android:layout_width="match_parent"
@@ -117,5 +117,29 @@
117117
android:layout_marginBottom="5dp"/>
118118
</LinearLayout>
119119

120+
<LinearLayout android:layout_height="wrap_content"
121+
android:layout_width="match_parent"
122+
android:layout_gravity="center_horizontal"
123+
android:orientation="vertical"
124+
android:background="@drawable/body_cont_bg" android:gravity="left" android:layout_margin="10dp">
125+
<LinearLayout android:layout_width="wrap_content"
126+
android:layout_height="wrap_content" android:orientation="horizontal"
127+
android:gravity="left" android:layout_margin="10dp">
128+
<ImageView android:layout_width="80dp"
129+
android:layout_height="80dp"
130+
android:src="@drawable/avatar_qfish"/>
131+
<TextView android:layout_height="wrap_content"
132+
android:layout_width="wrap_content"
133+
android:text="QFish" android:layout_gravity="center_vertical" android:textColor="#000000"
134+
android:textStyle="bold" android:layout_marginLeft="10dp"/>
135+
</LinearLayout>
136+
<TextView android:layout_height="wrap_content"
137+
android:layout_width="match_parent"
138+
android:text="@string/qfish_introduction"
139+
android:textSize="12dp" android:textColor="#666666"
140+
android:layout_marginTop="5dp"
141+
android:layout_marginBottom="5dp"/>
142+
</LinearLayout>
143+
120144
</LinearLayout>
121145
</ScrollView>

res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
<string name="xlistview_header_last_time">上次更新时间:</string>
1010
<string name="xlistview_footer_hint_normal">查看更多</string>
1111
<string name="xlistview_footer_hint_ready">松开载入更多</string>
12+
<string name="qfish_introduction">Love coding and hand-drawing, while he is also skilled in HTML and CSS and JS.
13+
What he always saying is "Fight, a way of surviving ~".</string>
14+
1215

1316
</resources>

src/com/BeeFramework/model/BeeQuery.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public <K> AQuery ajax(AjaxCallback<K> callback){
5757
return (BeeQuery)super.ajax(callback);
5858
}
5959

60+
public <K> AQuery ajaxAbsolute(AjaxCallback<K> callback){
61+
62+
return (BeeQuery)super.ajax(callback);
63+
}
64+
6065
public <K> AQuery ajax(String url, Map<String, ?> params, Class<K> type, BeeCallback<K> callback){
6166

6267
callback.type(type).url(url).params(params);

src/com/example/activity/TimelineActivity.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import com.BeeFramework.example.R;
1414
import com.BeeFramework.activity.MainActivity;
1515
import com.BeeFramework.model.BusinessResponse;
16+
import com.sina.weibo.sdk.WeiboSDK;
17+
import com.sina.weibo.sdk.api.IWeiboAPI;
1618
import com.weibo.sdk.android.*;
1719
import com.weibo.sdk.android.sso.SsoHandler;
1820
import org.json.JSONException;
@@ -53,7 +55,7 @@
5355
public class TimelineActivity extends MainActivity implements BusinessResponse, IXListViewListener
5456
{
5557
TimelineModel dataModel;
56-
TimelineAdapter topicSearchAdapter;
58+
TimelineAdapter listAdapter;
5759
XListView feedListView;
5860
Weibo mWeibo;
5961
SharedPreferences shared;
@@ -82,6 +84,8 @@ public void onCreate(Bundle savedInstanceState)
8284
editor = shared.edit();
8385

8486
mWeibo = Weibo.getInstance(AppConst.SINA_KEY,"http://open.weibo.com/apps/"+AppConst.SINA_KEY+"/info/advanced",SCOPE);
87+
IWeiboAPI weiboAPI = WeiboSDK.createWeiboAPI(this,AppConst.SINA_KEY);
88+
8589
mSsoHandler = new SsoHandler(this, mWeibo);
8690
String pkName = this.getPackageName();
8791
mSsoHandler.authorize(new AuthDialogListener(),pkName);
@@ -93,19 +97,27 @@ public void onCreate(Bundle savedInstanceState)
9397
feedListView.setPullLoadEnable(true);
9498
feedListView.setRefreshTime();
9599
feedListView.setXListViewListener(this, 1);
96-
97-
topicSearchAdapter = new TimelineAdapter(this,dataModel.searchResult);
98-
feedListView.setAdapter(topicSearchAdapter);
100+
101+
listAdapter = new TimelineAdapter(this,dataModel.searchResult);
102+
feedListView.setAdapter(listAdapter);
99103

100104
}
101105

102106
@Override
103107
public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status) throws JSONException
104108
{
105-
feedListView.setRefreshTime();
106-
feedListView.stopLoadMore();
107-
feedListView.stopRefresh();
108-
topicSearchAdapter.notifyDataSetChanged();
109+
if (url.startsWith("https://api.weibo.com/oauth2/access_token"))
110+
{
111+
onRefresh(0);
112+
}
113+
else
114+
{
115+
feedListView.setRefreshTime();
116+
feedListView.stopLoadMore();
117+
feedListView.stopRefresh();
118+
listAdapter.notifyDataSetChanged();
119+
}
120+
109121
}
110122

111123
@Override
@@ -142,8 +154,9 @@ public void onComplete(Bundle values) {
142154

143155
String code = values.getString("code");
144156
if(code != null){
145-
editor.putString(ACCESS_TOKEN,code);
146-
editor.commit();
157+
// editor.putString(ACCESS_TOKEN,code);
158+
// editor.commit();
159+
dataModel.getAccessToken(code);
147160
return;
148161
}
149162
String token = values.getString("access_token");

src/com/example/model/TimelineModel.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.example.model;
22

33
import android.content.Context;
4+
import android.content.SharedPreferences;
45
import com.example.protocol.ApiInterface;
56
import com.example.protocol.STATUSES;
67
import com.example.protocol.statusespublic_timelineResponse;
@@ -14,6 +15,8 @@
1415

1516
import java.util.ArrayList;
1617
import java.util.HashMap;
18+
import com.BeeFramework.model.BeeQuery;
19+
1720

1821
/*
1922
* ______ ______ ______
@@ -84,12 +87,65 @@ public void callback(String url, JSONObject jo, AjaxStatus status)
8487

8588
HashMap<String,String> params = new HashMap<String, String>();
8689

87-
url +="?source=3880614442&count=10&access_token="+token;
90+
url +="?source=804874423&count=10&access_token="+token;
8891

8992
cb.url(url).type(JSONObject.class).method(Constants.METHOD_GET);
9093
MyProgressDialog mPro = new MyProgressDialog(mContext, "请稍后...");
9194

9295
aq.progress(mPro.mDialog).ajax(cb);
9396

9497
}
98+
99+
public void getAccessToken(String code) {
100+
String url = "https://api.weibo.com/oauth2/access_token";
101+
102+
103+
BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>(){
104+
105+
@Override
106+
public void callback(String url, JSONObject jo, AjaxStatus status)
107+
{
108+
109+
TimelineModel.this.callback(url, jo, status);
110+
111+
if (jo.has("access_token"))
112+
{
113+
String access_token = jo.optString("access_token");
114+
115+
SharedPreferences shared;
116+
SharedPreferences.Editor editor;
117+
shared = mContext.getSharedPreferences("user_info", 0);
118+
editor = shared.edit();
119+
editor.putString("access_token",access_token);
120+
editor.commit();
121+
122+
try
123+
{
124+
TimelineModel.this.OnMessageResponse(url, jo, status);
125+
}
126+
catch (JSONException e)
127+
{
128+
129+
}
130+
131+
}
132+
}
133+
134+
};
135+
136+
HashMap<String,String> params = new HashMap<String, String>();
137+
params.put("client_id","804874423");
138+
params.put("client_secret","a4151118fc6ba19992fd892155ddd95e");
139+
params.put("grant_type","authorization_code");
140+
params.put("code",code);
141+
params.put("redirect_uri","http://open.weibo.com/apps/804874423/info/advanced");
142+
143+
cb.url(url).type(JSONObject.class).method(Constants.METHOD_POST);
144+
cb.params(params);
145+
MyProgressDialog mPro = new MyProgressDialog(mContext, "请稍后...");
146+
147+
aq.progress(mPro.mDialog);
148+
aq.ajaxAbsolute(cb);
149+
150+
}
95151
}

0 commit comments

Comments
 (0)