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- public class Homefragment extends Fragment implements
- OnRefreshLoadingMoreListener {
- private Context context;
- private DragListView lv;
- private Myviewadapter adapter;
- private Oauth2AccessToken mAccessToken;
-
- private StatusList statuses;
-
- private StatusesAPI mStatusesAPI;
- List<mystatus> mystatuslist;
- ContentValues values;
- String TABLE_NAME = "weibo" ;
- SQLiteDatabase database;
-
- Handler handler = new Handler() {
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case 0 :
- statuses = (StatusList) msg.obj;
- break ;
- case 1 :
- statuses = (StatusList) msg.obj;
- break ;
- case 2 :
- StatusList statuse = (StatusList) msg.obj;
- statuses.statusList.addAll(statuses.statusList.size(),
- statuse.statusList);
- break ;
- default :
- break ;
- }
- adapter = new Myviewadapter(context,statuses, null );
- lv.setAdapter(adapter);
- }
-
- };
-
- public Homefragment(Context context) {
- super ();
- this .context = context;
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.fragment_home, container, false );
-
- getinformation(getActivity().getApplicationContext());
- lv = (DragListView) view.findViewById(R.id.dragListView1);
-
- lv.getFooterViewsCount();
- lv.setOnCreateContextMenuListener( this );
- lv.setOnRefreshListener( this );
- if (!GlobalstaiticData.connect) {
- database = Databaseinit.initdatabase(context);
- select();
- adapter = new Myviewadapter(context, null ,mystatuslist);
- lv.setAdapter(adapter);
- Log.i( "123" ,mystatuslist.size()+ "" );
- }
- return view;
- }
-
- private void select() {
- mystatuslist = new ArrayList<mystatus>();
- Cursor cursor = database.query(TABLE_NAME, null , null , null , null ,
- null , null );
- for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
- String screen_name = cursor.getString(cursor
- .getColumnIndex( "screen_name" ));
- String source = cursor.getString(cursor.getColumnIndex( "source" ));
- String text = cursor.getString(cursor.getColumnIndex( "text" ));
- String retext = cursor.getString(cursor.getColumnIndex( "retext" ));
- String idstr = cursor.getString(cursor.getColumnIndex( "idstr" ));
- byte [] head = cursor.getBlob(cursor.getColumnIndex( "head" ));
- Mystatus mystatus = new Mystatus(screen_name, source, text, retext,
- idstr,head);
- mystatuslist.add(mystatus);
- }
- }
-
- private void getinformation(Context context) {
-
- mAccessToken = AccessTokenKeeper.readAccessToken(context);
-
- mStatusesAPI = new StatusesAPI(mAccessToken);
- if (mAccessToken != null && mAccessToken.isSessionValid()) {
- mStatusesAPI.friendsTimeline(0L, 0L, 10 , 1 , false , 0 , false ,
- mListener);
- } else {
- Toast.makeText(context, "Token does not exist" , Toast.LENGTH_LONG).show();
- }
- }
-
-
-
-
- private RequestListener mListener = new RequestListener() {
- @Override
- public void onComplete(String response) {
- Log.i( "json" , response);
- if (!TextUtils.isEmpty(response)) {
- if (response.startsWith( "{\"statuses\"" )) {
-
- StatusList statuses = StatusList.parse(response);
- Message msg = new Message();
- msg.what = 0 ;
- msg.obj = statuses;
- handler.sendMessage(msg);
- if (statuses != null && statuses.total_number > 0 ) {
- Toast.makeText(getActivity().getApplicationContext(),
- "Successfully obtained the microblog information stream, number of entries: " + statuses.statusList.size(),
- Toast.LENGTH_LONG).show();
- }
- } else if (response.startsWith( "{\"created_at\"" )) {
-
- Status status = Status.parse(response);
- Toast.makeText(getActivity().getApplicationContext(),
- "Sent a Weibo successfully, id = " + status.id, Toast.LENGTH_LONG)
- .show();
- } else {
- Toast.makeText(getActivity().getApplicationContext(),
- response, Toast.LENGTH_LONG).show();
- }
- }
- }
-
- @Override
- public void onWeiboException(WeiboException e) {
-
-
-
- }
- };
-
- private void getinformationmore(Context context) {
-
- mAccessToken = AccessTokenKeeper.readAccessToken(context);
-
- mStatusesAPI = new StatusesAPI(mAccessToken);
- if (mAccessToken != null && mAccessToken.isSessionValid()) {
- mStatusesAPI.friendsTimeline(0L, 0L, 5 , 2 , false , 0 , false ,
- moreListener);
- } else {
- Toast.makeText(context, "Token does not exist" , Toast.LENGTH_LONG).show();
- }
- }
-
-
-
-
- private RequestListener moreListener = new RequestListener() {
- @Override
- public void onComplete(String response) {
- Log.i( "json" , response);
- if (!TextUtils.isEmpty(response)) {
- if (response.startsWith( "{\"statuses\"" )) {
-
- StatusList statuses = StatusList.parse(response);
- Message msg = new Message();
- msg.what = 2 ;
- msg.obj = statuses;
- handler.sendMessage(msg);
- lv.onLoadMoreComplete( false );
- if (statuses != null && statuses.total_number > 0 ) {
- Toast.makeText(getActivity().getApplicationContext(),
- "Successfully obtained the microblog information stream, number of entries: " + statuses.statusList.size(),
- Toast.LENGTH_LONG).show();
- }
- } else if (response.startsWith( "{\"created_at\"" )) {
-
- Status status = Status.parse(response);
- Toast.makeText(getActivity().getApplicationContext(),
- "Sent a Weibo successfully, id = " + status.id, Toast.LENGTH_LONG)
- .show();
- } else {
- Toast.makeText(getActivity().getApplicationContext(),
- response, Toast.LENGTH_LONG).show();
- }
- }
- }
-
- @Override
- public void onWeiboException(WeiboException e) {
-
-
-
- }
- };
-
- private void getinformationupdata(Context context) {
- mAccessToken = AccessTokenKeeper.readAccessToken(context);
-
- mStatusesAPI = new StatusesAPI(mAccessToken);
- if (mAccessToken != null && mAccessToken.isSessionValid()) {
- mStatusesAPI.friendsTimeline(0L, 0L, 10 , 1 , false , 0 , false ,
- myListener);
- } else {
- Toast.makeText(context, "Token does not exist" , Toast.LENGTH_LONG).show();
- }
- }
-
-
-
-
-
-
- private RequestListener myListener = new RequestListener() {
-
- @Override
- public void onComplete(String response) {
- if (!TextUtils.isEmpty(response)) {
- if (response.startsWith( "{\"statuses\"" )) {
-
-
- StatusList statuses = StatusList.parse(response);
- Message msg = new Message();
- msg.what = 1 ;
- msg.obj = statuses;
- handler.sendMessage(msg);
- lv.onRefreshComplete();
- if (statuses != null && statuses.total_number > 0 ) {
- Toast.makeText(getActivity().getApplicationContext(),
- "Successfully obtained the microblog information stream, number of entries: " + statuses.statusList.size(),
- Toast.LENGTH_LONG).show();
- }
- } else if (response.startsWith( "{\"created_at\"" )) {
-
-
- Status status = Status.parse(response);
- Toast.makeText(getActivity().getApplicationContext(),
- "Sent a Weibo successfully, id = " + status.id, Toast.LENGTH_LONG)
- .show();
- } else {
- Toast.makeText(getActivity().getApplicationContext(),
- response, Toast.LENGTH_LONG).show();
- }
- }
- }
-
- @Override
- public void onWeiboException(WeiboException e) {
-
-
-
- }
- };
-
- @Override
- public void onCreateContextMenu(ContextMenu menu, View v,
- ContextMenuInfo menuInfo) {
- menu.setHeaderTitle( "More Operations" );
-
- menu.add( 0 , Menu.FIRST, 0 , "Forward" );
- menu.add( 0 , Menu.FIRST + 1 , 0 , "Comments" );
- super .onCreateContextMenu(menu, v, menuInfo);
- }
-
- @Override
- public boolean onContextItemSelected(MenuItem item) {
- AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
- .getMenuInfo();
- switch (item.getItemId()) {
- case 1 :
- Intent intent1 = new Intent(getActivity(), RepostActivity. class );
- intent1.putExtra( "status" , statuses.statusList.get(info.position));
- startActivity(intent1);
- break ;
- case 2 :
- Intent intent = new Intent(getActivity(),
- CommentsomebadyActivity.class ) ;
- intent.putExtra( "id" , statuses.statusList.get(info.position).idstr);
- Log.i( "comment" , "Weibo:"
- + statuses.statusList.get(info.position).idstr);
- startActivity(intent);
- break ;
- default :
- break ;
- }
-
-
-
- return super .onContextItemSelected(item);
- }
-
-
-
-
- @Override
- public void onRefresh() {
- getinformationupdata(context);
- }
-
-
-
-
- @Override
- public void onLoadMore() {
- getinformationmore(context);
- }
-
- }
- </mystatus></mystatus>
Source code download address: http://down..com/data/1977280 |