Android source code download: Sina Weibo

Android source code download: Sina Weibo

Service used: Sina Weibo

Functional category: Social

Supported platforms: Android

Operating environment: Eclipse

Development language: Java

Development tool: Eclipse

Source code size: 6.90MB

Source code download address: http://down..com/data/1977280

Source code introduction

A small project I made myself, which basically realizes the main functions of the interface provided by Sina Weibo, including authorized login, sending, forwarding, commenting, searching, etc. Database data can be read and browsed offline without network. There may be some bugs in the whole project, I hope you can contact me if you find them! Let's learn together!

Source code running screenshot

Retweet, comment

Weibo text

Authorized login

Search for users

Send Weibo

Comments View

Source code snippet

  1. public   class Homefragment extends Fragment implements  
  2. OnRefreshLoadingMoreListener {
  3. private Context context;
  4. private DragListView lv;
  5. private Myviewadapter adapter;
  6. private Oauth2AccessToken mAccessToken;
  7. /** Weibo information list */  
  8. private StatusList statuses;
  9. /** API for obtaining Weibo information stream and other operations */  
  10. private StatusesAPI mStatusesAPI;
  11. List<mystatus> mystatuslist;
  12. ContentValues ​​values;
  13. String TABLE_NAME = "weibo" ;
  14. SQLiteDatabase database;
  15.       
  16. Handler handler = new Handler() {
  17. public   void handleMessage(Message msg) {
  18. switch (msg.what) {
  19. case   0 :
  20. statuses = (StatusList) msg.obj;
  21. break ;
  22. case   1 :
  23. statuses = (StatusList) msg.obj;
  24. break ;
  25. case   2 :
  26. StatusList statuse = (StatusList) msg.obj;
  27. statuses.statusList.addAll(statuses.statusList.size(),
  28. statuse.statusList);
  29. break ;
  30. default :
  31. break ;
  32. }
  33. adapter = new Myviewadapter(context,statuses, null );
  34. lv.setAdapter(adapter);
  35. }
  36.   
  37. };
  38.   
  39. public Homefragment(Context context) {
  40. super ();
  41. this .context = context;
  42. }
  43.   
  44. @Override  
  45. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  46. Bundle savedInstanceState) {
  47. View view = inflater.inflate(R.layout.fragment_home, container, false );
  48.   
  49. getinformation(getActivity().getApplicationContext());
  50. lv = (DragListView) view.findViewById(R.id.dragListView1);
  51. // lv = (MyView) view.findViewById(R.id.myview1);  
  52. lv.getFooterViewsCount();
  53. lv.setOnCreateContextMenuListener( this );
  54. lv.setOnRefreshListener( this );
  55. if (!GlobalstaiticData.connect) {
  56. database = Databaseinit.initdatabase(context);
  57. select();
  58. adapter = new Myviewadapter(context, null ,mystatuslist);
  59. lv.setAdapter(adapter);
  60. Log.i( "123" ,mystatuslist.size()+ "" );
  61. }
  62. return view;
  63. }
  64.       
  65. private   void select() {
  66. mystatuslist = new ArrayList<mystatus>();
  67. Cursor cursor = database.query(TABLE_NAME, null , null , null , null ,
  68. null , null );
  69. for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
  70. String screen_name = cursor.getString(cursor
  71. .getColumnIndex( "screen_name" ));
  72. String source = cursor.getString(cursor.getColumnIndex( "source" ));
  73. String text = cursor.getString(cursor.getColumnIndex( "text" ));
  74. String retext = cursor.getString(cursor.getColumnIndex( "retext" ));
  75. String idstr = cursor.getString(cursor.getColumnIndex( "idstr" ));
  76. byte [] head = cursor.getBlob(cursor.getColumnIndex( "head" ));
  77. Mystatus mystatus = new Mystatus(screen_name, source, text, retext,
  78. idstr,head);
  79. mystatuslist.add(mystatus);
  80. }
  81. }
  82.       
  83. private   void getinformation(Context context) {
  84. // Get the currently saved Token  
  85. mAccessToken = AccessTokenKeeper.readAccessToken(context);
  86. //Instantiate statusAPI  
  87. mStatusesAPI = new StatusesAPI(mAccessToken);
  88. if (mAccessToken != null && mAccessToken.isSessionValid()) {
  89. mStatusesAPI.friendsTimeline(0L, 0L, 10 , 1 , false , 0 , false ,
  90. mListener);
  91. } else {
  92. Toast.makeText(context, "Token does not exist" , Toast.LENGTH_LONG).show();
  93. }
  94. }
  95.   
  96. /**
  97. * Weibo OpenAPI callback interface.
  98. */  
  99. private RequestListener mListener = new RequestListener() {
  100. @Override  
  101. public   void onComplete(String response) {
  102. Log.i( "json" , response);
  103. if (!TextUtils.isEmpty(response)) {
  104. if (response.startsWith( "{\"statuses\"" )) {
  105. // Call StatusList#parse to parse the string into a microblog list object  
  106. StatusList statuses = StatusList.parse(response);
  107. Message msg = new Message();
  108. msg.what = 0 ;
  109. msg.obj = statuses;
  110. handler.sendMessage(msg);
  111. if (statuses != null && statuses.total_number > 0 ) {
  112. Toast.makeText(getActivity().getApplicationContext(),
  113. "Successfully obtained the microblog information stream, number of entries: " + statuses.statusList.size(),
  114. Toast.LENGTH_LONG).show();
  115. }
  116. } else   if (response.startsWith( "{\"created_at\"" )) {
  117. // Call Status#parse to parse the string into a Weibo object  
  118. Status status = Status.parse(response);
  119. Toast.makeText(getActivity().getApplicationContext(),
  120. "Sent a Weibo successfully, id = " + status.id, Toast.LENGTH_LONG)
  121. .show();
  122. } else {
  123. Toast.makeText(getActivity().getApplicationContext(),
  124. response, Toast.LENGTH_LONG).show();
  125. }
  126. }
  127. }
  128.   
  129. @Override  
  130. public   void onWeiboException(WeiboException e) {
  131. // ErrorInfo info = ErrorInfo.parse(e.getMessage());  
  132. // Toast.makeText(getActivity().getApplicationContext(),  
  133. // info.toString(), Toast.LENGTH_LONG).show();  
  134. }
  135. };
  136.   
  137. private   void getinformationmore(Context context) {
  138. // Get the currently saved Token  
  139. mAccessToken = AccessTokenKeeper.readAccessToken(context);
  140. //Instantiate statusAPI  
  141. mStatusesAPI = new StatusesAPI(mAccessToken);
  142. if (mAccessToken != null && mAccessToken.isSessionValid()) {
  143. mStatusesAPI.friendsTimeline(0L, 0L, 5 , 2 , false , 0 , false ,
  144. moreListener);
  145. } else {
  146. Toast.makeText(context, "Token does not exist" , Toast.LENGTH_LONG).show();
  147. }
  148. }
  149.   
  150. /**
  151. * Weibo OpenAPI callback interface.
  152. */  
  153. private RequestListener moreListener = new RequestListener() {
  154. @Override  
  155. public   void onComplete(String response) {
  156. Log.i( "json" , response);
  157. if (!TextUtils.isEmpty(response)) {
  158. if (response.startsWith( "{\"statuses\"" )) {
  159. // Call StatusList#parse to parse the string into a microblog list object  
  160. StatusList statuses = StatusList.parse(response);
  161. Message msg = new Message();
  162. msg.what = 2 ;
  163. msg.obj = statuses;
  164. handler.sendMessage(msg);
  165. lv.onLoadMoreComplete( false );
  166. if (statuses != null && statuses.total_number > 0 ) {
  167. Toast.makeText(getActivity().getApplicationContext(),
  168. "Successfully obtained the microblog information stream, number of entries: " + statuses.statusList.size(),
  169. Toast.LENGTH_LONG).show();
  170. }
  171. } else   if (response.startsWith( "{\"created_at\"" )) {
  172. // Call Status#parse to parse the string into a Weibo object  
  173. Status status = Status.parse(response);
  174. Toast.makeText(getActivity().getApplicationContext(),
  175. "Sent a Weibo successfully, id = " + status.id, Toast.LENGTH_LONG)
  176. .show();
  177. } else {
  178. Toast.makeText(getActivity().getApplicationContext(),
  179. response, Toast.LENGTH_LONG).show();
  180. }
  181. }
  182. }
  183.   
  184. @Override  
  185. public   void onWeiboException(WeiboException e) {
  186. // ErrorInfo info = ErrorInfo.parse(e.getMessage());  
  187. // Toast.makeText(getActivity().getApplicationContext(),  
  188. // info.toString(), Toast.LENGTH_LONG).show();  
  189. }
  190. };
  191.   
  192. private   void getinformationupdata(Context context) { // Get the currently saved Token  
  193. mAccessToken = AccessTokenKeeper.readAccessToken(context); //  
  194. //Instantiate statusAPI  
  195. mStatusesAPI = new StatusesAPI(mAccessToken);
  196. if (mAccessToken != null && mAccessToken.isSessionValid()) {
  197. mStatusesAPI.friendsTimeline(0L, 0L, 10 , 1 , false , 0 , false ,
  198. myListener);
  199. } else {
  200. Toast.makeText(context, "Token does not exist" , Toast.LENGTH_LONG).show();
  201. }
  202. }
  203.   
  204. /**
  205. *
  206. * Weibo OpenAPI callback interface.
  207. */  
  208.   
  209. private RequestListener myListener = new RequestListener() {
  210.   
  211. @Override  
  212. public   void onComplete(String response) {
  213. if (!TextUtils.isEmpty(response)) {
  214. if (response.startsWith( "{\"statuses\"" )) { // call  
  215. // StatusList#parse  
  216. // Parse the string into a Weibo list object  
  217. StatusList statuses = StatusList.parse(response);
  218. Message msg = new Message();
  219. msg.what = 1 ;
  220. msg.obj = statuses;
  221. handler.sendMessage(msg);
  222. lv.onRefreshComplete();
  223. if (statuses != null && statuses.total_number > 0 ) {
  224. Toast.makeText(getActivity().getApplicationContext(),
  225. "Successfully obtained the microblog information stream, number of entries: " + statuses.statusList.size(),
  226. Toast.LENGTH_LONG).show();
  227. }
  228. } else   if (response.startsWith( "{\"created_at\"" )) { // Call  
  229. // Status#parse  
  230. // Parse the string into a Weibo object  
  231. Status status = Status.parse(response);
  232. Toast.makeText(getActivity().getApplicationContext(),
  233. "Sent a Weibo successfully, id = " + status.id, Toast.LENGTH_LONG)
  234. .show();
  235. } else {
  236. Toast.makeText(getActivity().getApplicationContext(),
  237. response, Toast.LENGTH_LONG).show();
  238. }
  239. }
  240. }
  241.   
  242. @Override  
  243. public   void onWeiboException(WeiboException e) {
  244. // ErrorInfo info = ErrorInfo.parse(e.getMessage());  
  245. // Toast.makeText(getActivity().getApplicationContext(),  
  246. // info.toString(), Toast.LENGTH_LONG).show();  
  247. }
  248. };
  249.   
  250. @Override  
  251. public   void onCreateContextMenu(ContextMenu menu, View v,
  252. ContextMenuInfo menuInfo) {
  253. menu.setHeaderTitle( "More Operations" );
  254. // Add menu items  
  255. menu.add( 0 , Menu.FIRST, 0 , "Forward" );
  256. menu.add( 0 , Menu.FIRST + 1 , 0 , "Comments" );
  257. super .onCreateContextMenu(menu, v, menuInfo);
  258. }
  259.   
  260. @Override  
  261. public   boolean onContextItemSelected(MenuItem item) {
  262. AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
  263. .getMenuInfo();
  264. switch (item.getItemId()) {
  265. case   1 :
  266. Intent intent1 = new Intent(getActivity(), RepostActivity. class );
  267. intent1.putExtra( "status" , statuses.statusList.get(info.position));
  268. startActivity(intent1);
  269. break ;
  270. case   2 :
  271. Intent intent = new Intent(getActivity(),
  272. CommentsomebadyActivity.class ) ;
  273. intent.putExtra( "id" , statuses.statusList.get(info.position).idstr);
  274. Log.i( "comment" , "Weibo:"  
  275. + statuses.statusList.get(info.position).idstr);
  276. startActivity(intent);
  277. break ;
  278. default :
  279. break ;
  280. }
  281. // Toast.makeText(getActivity().getApplicationContext(),  
  282. // "Number of items: "+item.getItemId()+" Number of items: "+info.position,  
  283. // Toast.LENGTH_LONG).show();  
  284. return   super .onContextItemSelected(item);
  285. }
  286.   
  287. /***
  288. * Pull down to refresh
  289. */  
  290. @Override  
  291. public   void onRefresh() {
  292. getinformationupdata(context);
  293. }
  294.   
  295. /***
  296. * Click to load more
  297. */  
  298. @Override  
  299. public   void onLoadMore() {
  300. getinformationmore(context);
  301. }
  302.   
  303. }
  304. </mystatus></mystatus>

Source code download address: http://down..com/data/1977280

<<:  How many of the five factors that hold back game development does your team meet?

>>:  Android source code: Get a list of cities across the country similar to contact sorting

Recommend

"Zhehaiyan C50", a netizen caught a coded fish and its origin was found!

Recently, a Taizhou netizen @小羊驼 asked for help o...

Google finally compromises, native app store takes back Chinese market

[[147857]] On September 5, according to The Infor...

How much does it cost to customize a beauty mini app in Shenzhen?

Shenzhen beauty mini program customization price ...

Android event distribution mechanism source code and example analysis

1. Understanding of the event distribution proces...

Android Wear summary: Making smartwatches cool

David Singleton, Director of Engineering at Google...

Please save these tips for achieving mobile app user growth!

When traffic and users in various industries are ...

Will people who rely on coffee to "extend their lives" be healthier?

Coffee is a daily drink in modern people's li...

How to promote a website? Detailed explanation of website promotion!

Promotion goals Compared with the complete Intern...

How to operate your enterprise group App?

It’s another July. I still remember that I was bu...