Android Open Source - doubanbook4android Base P2 R Activity






From Project

Back to project page doubanbook4android.

License

The source code is released under:

Eclipse Public License - v 1.0 THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECI...

If you think the Android project doubanbook4android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.study.doubanbook_for_android.activity;
/*from w ww .  j  a  va2s . co  m*/
import java.util.ArrayList;
import java.util.List;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.study.doubanbook_for_android.R;

/**
 * 
 * ??????????,fetchdata,sendMessage,seleHandleMsg,selfhandleMsg??BUG updatatime
 * 2013-12-13
 * 
 * @author tezuka-pc
 * 
 * @param <T>
 */
public class BaseP2RActivity<T> extends BaseActivity implements
    OnRefreshListener<ListView>, OnItemClickListener {

  PullToRefreshListView p2r_lv;
  protected ArrayList<T> dataList = new ArrayList<T>();
  public static final int REQUEST_CODE_PUBLISH = 0;
  protected BaseAdapter adapter;
  protected int pageIndex = 0;

  public static final int SUCCESS = 0;
  public static final int FAILURE = 1;

  // thread
  private MessageHandler msgHandler;

  class MessageHandler extends Handler {
    public MessageHandler(Looper looper) {
      super(looper);
    }

    @Override
    public void handleMessage(Message msg) {
      // ???????? ??????????????title?
      // result = (GeneralResult) (msg.obj);
      // addData(result.getBooks());
      selfHandleMsg(msg);
    }
  }

  /**
   * ??MESSAGEHANDLER??????????UI??
   * 
   * @param b
   * @param status
   */
  void sendMessage(Object b, int status) {
    Message message = Message.obtain();
    message.arg1 = status;
    message.obj = b;
    msgHandler.sendMessage(message);
  }

  /**
   * ????????????????,??????????
   * 
   * @param msg
   */
  public void selfHandleMsg(Message msg) {
    // TODO Auto-generated method stub

  }

  void initP2RLvAndThread() {
    // init p2r
    p2r_lv = (PullToRefreshListView) this.findViewById(R.id.p2r_lv);
    ListView listview = p2r_lv.getRefreshableView();
    listview.setVerticalFadingEdgeEnabled(false);
    p2r_lv.setMode(Mode.PULL_FROM_END);
    p2r_lv.setShowIndicator(false);
    p2r_lv.setOnItemClickListener(this);
    p2r_lv.setOnRefreshListener(this);
    p2r_lv.setAdapter(getAdapter());

    // init msgHandler
    Looper looper = Looper.myLooper();
    msgHandler = new MessageHandler(looper);
  }

  /**
   * ??????
   * 
   * @param data
   */
  void addData(List<T> data) {
    refreshCompleted();
    if (data != null) {
      dataList.addAll(data);
      // TODO DEBUG?WHY
      // ???????????????????,???????????
      // p2r_lv.setAdapter(adapter);
      adapter.notifyDataSetChanged();
    }
  }

  // ?????????
  protected void reUpdateData() {
    dataList.clear();
    fetchData();
  }

  protected void refreshCompleted() {
    p2r_lv.onRefreshComplete();
  }

  // ------------------------------------------------

  /**
   * ?????????????.
   */
  public void fetchData() {

  }

  @Override
  public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

  }

  @Override
  public void onRefresh(PullToRefreshBase<ListView> refreshView) {

  }

  // ??adatper????????
  protected void notifyUpdate() {
    getAdapter().notifyDataSetChanged();
  }

  private BaseAdapter getAdapter() {
    return adapter;
  }
}




Java Source Code List

.UserListAdapter.java
com.study.doubanbook_for_android.activity.BaseActivity.java
com.study.doubanbook_for_android.activity.BaseP2RActivity.java
com.study.doubanbook_for_android.activity.BookDetailActivity.java
com.study.doubanbook_for_android.activity.BookListsActivity.java
com.study.doubanbook_for_android.activity.BookNoteListActivity.java
com.study.doubanbook_for_android.activity.CollectDetailActivity.java
com.study.doubanbook_for_android.activity.NoteAndUserDetailActivity.java
com.study.doubanbook_for_android.activity.SerchInputActivity.java
com.study.doubanbook_for_android.activity.TextActivity1.java
com.study.doubanbook_for_android.activity.UserDetailActivity.java
com.study.doubanbook_for_android.activity.UserListActivity.java
com.study.doubanbook_for_android.activity.UserNoteActivity.java
com.study.doubanbook_for_android.adapter.BookAdapter.java
com.study.doubanbook_for_android.adapter.CommentAdapter.java
com.study.doubanbook_for_android.adapter.UserNoteAdapter.java
com.study.doubanbook_for_android.api.NetUtils.java
com.study.doubanbook_for_android.api.SSLSocketFactoryEx.java
com.study.doubanbook_for_android.api.WrongMsg.java
com.study.doubanbook_for_android.auth.AccessToken.java
com.study.doubanbook_for_android.auth.DoubanDialogError.java
com.study.doubanbook_for_android.auth.DoubanDialog.java
com.study.doubanbook_for_android.auth.DoubanException.java
com.study.doubanbook_for_android.auth.DoubanOAuthListener.java
com.study.doubanbook_for_android.auth.DoubanParameters.java
com.study.doubanbook_for_android.auth.DoubanRequest.java
com.study.doubanbook_for_android.auth.Douban.java
com.study.doubanbook_for_android.auth.KeepToken.java
com.study.doubanbook_for_android.auth.SimpleDoubanOAuthListener.java
com.study.doubanbook_for_android.auth.Token.java
com.study.doubanbook_for_android.business.DoubanBusiness.java
com.study.doubanbook_for_android.callback.AsynCallback.java
com.study.doubanbook_for_android.imagedownloader.FileCache.java
com.study.doubanbook_for_android.imagedownloader.INetImageDownloader.java
com.study.doubanbook_for_android.imagedownloader.ImageCache.java
com.study.doubanbook_for_android.imagedownloader.ImageDownloaderListener.java
com.study.doubanbook_for_android.imagedownloader.ImageDownloader.java
com.study.doubanbook_for_android.model.Annotations.java
com.study.doubanbook_for_android.model.AuthorUser.java
com.study.doubanbook_for_android.model.BookItem.java
com.study.doubanbook_for_android.model.CollectBookMsg.java
com.study.doubanbook_for_android.model.CollectSuccessResult.java
com.study.doubanbook_for_android.model.CommentItem.java
com.study.doubanbook_for_android.model.Comment.java
com.study.doubanbook_for_android.model.CurrenUserCollection.java
com.study.doubanbook_for_android.model.GeneralNoteResult.java
com.study.doubanbook_for_android.model.GeneralResult.java
com.study.doubanbook_for_android.model.GeneralUserResult.java
com.study.doubanbook_for_android.model.ImageItem.java
com.study.doubanbook_for_android.model.Rating.java
com.study.doubanbook_for_android.model.RequestGrantScope.java
com.study.doubanbook_for_android.model.TagItem.java
com.study.doubanbook_for_android.model.URLMananeger.java
com.study.doubanbook_for_android.utils.EncodeUtils.java
com.study.doubanbook_for_android.utils.JsonParser.java
com.study.doubanbook_for_android.utils.JsonUtil.java
com.study.doubanbook_for_android.utils.UriUtils.java