Android源码下载:新浪微博

移动开发 Android
自己做的一个小项目,基本实现了新浪微博所提供接口的主要功能,授权登陆,发送,转发,评论,搜索等等。无网络也可以读取数据库数据离线浏览,整个项目中可能有一些BUG,希望童鞋们找到能联系我!共同学习!

使用服务:新浪微博

功能分类:社交

支持平台:Android

运行环境:Eclipse

开发语言:Java

开发工具:Eclipse

源码大小:6.90MB

源码下载地址:http://down.51cto.com/data/1977280

源码简介

自己做的一个小项目,基本实现了新浪微博所提供接口的主要功能,授权登陆,发送,转发,评论,搜索等等。无网络也可以读取数据库数据离线浏览,整个项目中可能有一些BUG,希望童鞋们找到能联系我!共同学习!

源码运行截图

转发,评论

微博正文

授权登陆

搜索用户

发送微博

评论查看

 

源码片段

  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.     /** 微博信息列表 */ 
  8.     private StatusList statuses; 
  9.     /** 用于获取微博信息流等操作的API */ 
  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, nullnullnullnull
  68.                 nullnull); 
  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.         // 获取当前已保存过的 Token 
  85.         mAccessToken = AccessTokenKeeper.readAccessToken(context); 
  86.         // 对statusAPI实例化 
  87.         mStatusesAPI = new StatusesAPI(mAccessToken); 
  88.         if (mAccessToken != null && mAccessToken.isSessionValid()) { 
  89.             mStatusesAPI.friendsTimeline(0L, 0L, 101false0false
  90.                     mListener); 
  91.         } else { 
  92.             Toast.makeText(context, "Token不存在", Toast.LENGTH_LONG).show(); 
  93.         } 
  94.     } 
  95.   
  96.     /** 
  97.      * 微博 OpenAPI 回调接口。 
  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.                     // 调用 StatusList#parse 解析字符串成微博列表对象 
  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.                                 "获取微博信息流成功, 条数: " + statuses.statusList.size(), 
  114.                                 Toast.LENGTH_LONG).show(); 
  115.                     } 
  116.                 } else if (response.startsWith("{\"created_at\"")) { 
  117.                     // 调用 Status#parse 解析字符串成微博对象 
  118.                     Status status = Status.parse(response); 
  119.                     Toast.makeText(getActivity().getApplicationContext(), 
  120.                             "发送一送微博成功, 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.         // 获取当前已保存过的 Token 
  139.         mAccessToken = AccessTokenKeeper.readAccessToken(context); 
  140.         // 对statusAPI实例化 
  141.         mStatusesAPI = new StatusesAPI(mAccessToken); 
  142.         if (mAccessToken != null && mAccessToken.isSessionValid()) { 
  143.             mStatusesAPI.friendsTimeline(0L, 0L, 52false0false
  144.                     moreListener); 
  145.         } else { 
  146.             Toast.makeText(context, "Token不存在", Toast.LENGTH_LONG).show(); 
  147.         } 
  148.     } 
  149.   
  150.     /** 
  151.      * 微博 OpenAPI 回调接口。 
  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.                     // 调用 StatusList#parse 解析字符串成微博列表对象 
  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.                                 "获取微博信息流成功, 条数: " + statuses.statusList.size(), 
  169.                                 Toast.LENGTH_LONG).show(); 
  170.                     } 
  171.                 } else if (response.startsWith("{\"created_at\"")) { 
  172.                     // 调用 Status#parse 解析字符串成微博对象 
  173.                     Status status = Status.parse(response); 
  174.                     Toast.makeText(getActivity().getApplicationContext(), 
  175.                             "发送一送微博成功, 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) { // 获取当前已保存过的 Token 
  193.         mAccessToken = AccessTokenKeeper.readAccessToken(context); // 
  194.         // 对statusAPI实例化 
  195.         mStatusesAPI = new StatusesAPI(mAccessToken); 
  196.         if (mAccessToken != null && mAccessToken.isSessionValid()) { 
  197.             mStatusesAPI.friendsTimeline(0L, 0L, 101false0false
  198.                     myListener); 
  199.         } else { 
  200.             Toast.makeText(context, "Token不存在", Toast.LENGTH_LONG).show(); 
  201.         } 
  202.     } 
  203.   
  204.     /** 
  205.      * 
  206.      * 微博 OpenAPI 回调接口。 
  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\"")) { // 调用 
  215.                                                             // StatusList#parse 
  216.                     // 解析字符串成微博列表对象 
  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.                                 "获取微博信息流成功, 条数: " + statuses.statusList.size(), 
  226.                                 Toast.LENGTH_LONG).show(); 
  227.                     } 
  228.                 } else if (response.startsWith("{\"created_at\"")) { // 调用 
  229.                                                                         // Status#parse 
  230.                                                                         // 解析字符串成微博对象 
  231.                     Status status = Status.parse(response); 
  232.                     Toast.makeText(getActivity().getApplicationContext(), 
  233.                             "发送一送微博成功, 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("更多操作"); 
  254.         // 添加菜单项 
  255.         menu.add(0, Menu.FIRST, 0"转发"); 
  256.         menu.add(0, Menu.FIRST + 10"评论"); 
  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.         // "第几项:"+item.getItemId()+"  第几个: "+info.position, 
  283.         // Toast.LENGTH_LONG).show(); 
  284.         return super.onContextItemSelected(item); 
  285.     } 
  286.   
  287.     /*** 
  288.      * 下拉刷新 
  289.      */ 
  290.     @Override 
  291.     public void onRefresh() { 
  292.         getinformationupdata(context); 
  293.     } 
  294.   
  295.     /*** 
  296.      * 点击加载更多 
  297.      */ 
  298.     @Override 
  299.     public void onLoadMore() { 
  300.         getinformationmore(context); 
  301.     } 
  302.   
  303. </mystatus></mystatus> 

源码下载地址:http://down.51cto.com/data/1977280

责任编辑:闫佳明 来源: 网络整理
相关推荐

2013-07-10 14:15:38

php新浪微博

2013-07-01 18:34:47

个推案例新浪微博

2011-12-08 16:10:18

2013-07-16 15:21:53

微微博新浪微博AndroidAndroid开发学习

2011-07-22 10:38:55

HTC新浪Facebook

2011-12-08 16:31:43

新浪微博开放平台

2011-12-08 16:51:55

新浪微博开放平台

2015-09-24 18:08:50

微博架构架构演进架构

2013-03-20 10:09:22

微博风云大数据社会化数据分析

2011-08-30 14:48:02

2011-07-01 13:29:15

2011-06-29 09:57:45

2012-07-12 15:00:26

漏洞账号错乱新浪微博

2011-12-20 09:54:43

微博

2017-04-27 11:15:05

新浪微博LNMP架构侯青龙

2020-09-07 14:00:23

腾讯微博微信互联网

2014-01-07 10:46:39

2013-05-27 09:52:35

Android开发移动开发移动应用

2015-01-14 13:59:50

腾讯微博客户端源码下载

2017-04-15 21:36:05

微服务新浪微博WOT
点赞
收藏

51CTO技术栈公众号