Java tutorial
/** * Program : T4Activity.java * Author : chunsoft * Create : 2015-6-31 ?4:24:32 * * Copyright 2015 by newyulong Technologies Ltd. * All rights reserved. * * This software is the confidential and proprietary information * of dlam Technologies Ltd.("Confidential Information"). * You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement * you entered into with dlam Technologies Ltd. * */ /** * Program : T4Activity.java * Author : chunsoft * Create : 2015-6-31 ?4:24:32 * * Copyright 2015 by newyulong Technologies Ltd. * All rights reserved. * * This software is the confidential and proprietary information * of dlam Technologies Ltd.("Confidential Information"). * You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement * you entered into with dlam Technologies Ltd. * */ package com.dlam.activity; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.json.JSONException; import org.json.JSONObject; import com.android.volley.Response; import com.android.volley.Request.Method; import com.dlam.adapter.A_ListDataAdapter; import com.dlam.bean.A_ListBean; import com.dlam.bean.Constant; import com.dlam.bean.infolist; import com.dlam.dragon.R; import com.dlam.net.AbstractVolleyErrorListener; import com.dlam.net.GsonRequest; import com.dlam.pullrefresh.PullToRefreshBase; import com.dlam.pullrefresh.PullToRefreshListView; import com.dlam.pullrefresh.PullToRefreshBase.OnRefreshListener; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.Window; import android.widget.AdapterView; import android.widget.ListView; import android.widget.AdapterView.OnItemClickListener; /** * @author chunsoft * @version 1.0.0 * @2015-6-31 ?4:24:32 */ public class T4Activity extends Activity { // private PullToRefreshListView mPullListView; private ListView mListView; //?? private JSONObject RequestData; private A_ListBean ResponseData; private String URL; private String NET_TAG; private Context mContext; private int curPage = 1; private int toaPage; private String time; private SimpleDateFormat mDateFormat; private String myid; private A_ListDataAdapter mAdapter; private List<infolist> datas; private boolean hasMoreData = true; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); mPullListView = new PullToRefreshListView(this); setContentView(mPullListView); mContext = T4Activity.this; init(); getData(); } private void init() { mDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); mPullListView.setPullLoadEnabled(true); mPullListView.setScrollLoadEnabled(true); time = formatDateTime(System.currentTimeMillis()); } private void getData() { getListgetInfoList(Integer.toString(curPage), "3", "0", time, new VolleyDataCallback() { @Override public void onSuccess(A_ListBean bean) { curPage++; toaPage = Integer.parseInt(bean.getTotalpage()); datas = bean.getInfolist(); mAdapter = new A_ListDataAdapter(mContext, datas, R.layout.listitem); mListView = mPullListView.getRefreshableView(); mListView.setAdapter(mAdapter); mListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { myid = datas.get(position).getId().toString(); Intent intent = new Intent(); intent.putExtra("myid", myid); intent.setClass(mContext, A_ServiceDetailActivity.class); T4Activity.this.startActivity(intent); } }); } }); mPullListView.setOnRefreshListener(new OnRefreshListener<ListView>() { @Override public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) { //mIsStart = true; getUpdateData(); } @Override public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) { //mIsStart = false; getMoreData(); } }); setLastUpdateTime(); } private void setLastUpdateTime() { String text = formatDateTime(System.currentTimeMillis()); mPullListView.setLastUpdatedLabel(text); } private String formatDateTime(long time) { if (0 == time) { return ""; } return mDateFormat.format(new Date(time)); } public void getMoreData() { if (curPage <= toaPage) { hasMoreData = true; getListgetInfoList(String.valueOf(curPage), "3", "0", "0", new VolleyDataCallback() { @Override public void onSuccess(A_ListBean bean) { System.out.println("?" + bean.getCurrentpage()); List<infolist> dataBean = new ArrayList<infolist>(); dataBean = bean.getInfolist(); for (int i = 0; i < dataBean.size(); i++) { datas.add(dataBean.get(i)); System.out.println(i + "title----------" + dataBean.get(i).getTitle()); } mAdapter.notifyDataSetChanged(); mPullListView.onPullDownRefreshComplete(); mPullListView.onPullUpRefreshComplete(); mPullListView.setHasMoreData(hasMoreData); setLastUpdateTime(); curPage++; } } ); } else { hasMoreData = false; mPullListView.setHasMoreData(hasMoreData); } } public void getUpdateData() { String time = formatDateTime(System.currentTimeMillis()); getListgetInfoList(Integer.toString(curPage), "3", "0", time, new VolleyDataCallback() { @Override public void onSuccess(A_ListBean bean) { String curPage = bean.getCurrentpage(); String toaPage = bean.getTotalpage(); boolean hasMoreData = true; if (curPage == toaPage) { hasMoreData = false; } List<infolist> dataBean = bean.getInfolist(); for (int i = 0; i < dataBean.size(); i++) { datas.add(dataBean.get(i)); } mAdapter.notifyDataSetChanged(); mPullListView.onPullDownRefreshComplete(); mPullListView.onPullUpRefreshComplete(); mPullListView.setHasMoreData(hasMoreData); setLastUpdateTime(); } }); } public A_ListBean getListgetInfoList(String currentpage, String type1id, String type2id, String issuetime, final VolleyDataCallback callback) { URL = Constant.IP + Constant.GetInfoList + "/currentpage/" + currentpage + "/type1id/" + type1id + "/type2id/" + type2id + "/issuetime/" + "0"; RequestData = new JSONObject(); try { RequestData.put("currentpage", currentpage); RequestData.put("type1id", type1id); RequestData.put("type2id", type2id); RequestData.put("issuetime", issuetime); } catch (JSONException e) { e.printStackTrace(); } GsonRequest<A_ListBean> request = new GsonRequest<A_ListBean>(Method.GET, URL, RequestData.toString(), new Response.Listener<A_ListBean>() { @Override public void onResponse(A_ListBean response) { ResponseData = response; callback.onSuccess(response); } }, new AbstractVolleyErrorListener(mContext) { @Override public void onError() { Log.e(NET_TAG, "----onError"); } }, A_ListBean.class); MyApplication.getInstance().addToRequestQueue(request); return ResponseData; } //?? public interface VolleyDataCallback { void onSuccess(A_ListBean datas); } }