|
@@ -50,26 +50,33 @@ import java.io.InputStream;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Iterator;
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
|
|
+import static java.lang.Thread.sleep;
|
|
|
|
|
+
|
|
|
//import static com.usai.redant.CommonEditor.CommonEditorActivity.URL_REMOTE;
|
|
//import static com.usai.redant.CommonEditor.CommonEditorActivity.URL_REMOTE;
|
|
|
|
|
|
|
|
|
|
|
|
|
-public class SearchResultActivity extends AppCompatActivity implements AbsListView.OnScrollListener {
|
|
|
|
|
|
|
+public class SearchResultActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
protected Bundle mParams;
|
|
protected Bundle mParams;
|
|
|
protected JSONObject resultData = new JSONObject();
|
|
protected JSONObject resultData = new JSONObject();
|
|
|
|
|
|
|
|
protected Context mContext;
|
|
protected Context mContext;
|
|
|
- protected ListView resultListView;
|
|
|
|
|
|
|
+ protected PullRefreshListView resultListView;
|
|
|
protected ResultAdapter adapter;
|
|
protected ResultAdapter adapter;
|
|
|
|
|
+ protected SwipeRefreshLayout resultSwipe;
|
|
|
|
|
+ protected View list_footer;
|
|
|
|
|
+ protected View refresh_footer;
|
|
|
|
|
|
|
|
private View clickedView;
|
|
private View clickedView;
|
|
|
private View.OnTouchListener resultRowClickListener;
|
|
private View.OnTouchListener resultRowClickListener;
|
|
|
private GestureDetector detector;
|
|
private GestureDetector detector;
|
|
|
|
|
|
|
|
- protected TextView footer;
|
|
|
|
|
- protected int footer_height = 60;
|
|
|
|
|
|
|
+ protected int footer_height;
|
|
|
|
|
+ protected int header_height;
|
|
|
|
|
|
|
|
ProgressDialog progressDialog;
|
|
ProgressDialog progressDialog;
|
|
|
|
|
+ public boolean isLoading = false;//表示是否正处于加载状态
|
|
|
|
|
+
|
|
|
|
|
|
|
|
public void cellDoubleTapAction(int position) {
|
|
public void cellDoubleTapAction(int position) {
|
|
|
|
|
|
|
@@ -166,13 +173,23 @@ public class SearchResultActivity extends AppCompatActivity implements AbsListVi
|
|
|
// }
|
|
// }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ void setMargin(View view,int l,int t,int r,int b) {
|
|
|
|
|
+ RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(view.getLayoutParams());
|
|
|
|
|
+ lp.setMargins(l, t, r, b);
|
|
|
|
|
+ view.setLayoutParams(lp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.activity_search_result);
|
|
setContentView(R.layout.activity_search_result);
|
|
|
|
|
|
|
|
mContext = this;
|
|
mContext = this;
|
|
|
- resultListView = (ListView)findViewById(R.id.result_table_list);
|
|
|
|
|
|
|
+ footer_height = dp2px(this,30);
|
|
|
|
|
+ header_height = dp2px(this,60);
|
|
|
|
|
+
|
|
|
|
|
+ resultListView = (PullRefreshListView) findViewById(R.id.result_table_list);
|
|
|
|
|
+ resultSwipe = findViewById(R.id.result_swipe);
|
|
|
|
|
|
|
|
progressDialog = new ProgressDialog(mContext);
|
|
progressDialog = new ProgressDialog(mContext);
|
|
|
progressDialog.setCancelable(false);
|
|
progressDialog.setCancelable(false);
|
|
@@ -180,24 +197,51 @@ public class SearchResultActivity extends AppCompatActivity implements AbsListVi
|
|
|
initClickListener();
|
|
initClickListener();
|
|
|
|
|
|
|
|
|
|
|
|
|
- footer = new TextView(mContext);
|
|
|
|
|
- footer.setBackgroundColor(Color.WHITE);
|
|
|
|
|
- footer.setGravity(Gravity.CENTER);
|
|
|
|
|
- footer.setText("Load More");
|
|
|
|
|
- footer.setTextSize(sp2px(mContext,8));
|
|
|
|
|
- footer.setVisibility(View.INVISIBLE);
|
|
|
|
|
|
|
+ adapter = new ResultAdapter(mContext);
|
|
|
|
|
+ resultListView.setAdapter(adapter);
|
|
|
|
|
+ resultListView.setDividerHeight(0);
|
|
|
|
|
|
|
|
- AbsListView.LayoutParams footerLayoutParams = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,footer_height);
|
|
|
|
|
- footer.setLayoutParams(footerLayoutParams);
|
|
|
|
|
|
|
+ // refresh header & footer
|
|
|
|
|
+ list_footer = View.inflate(this, R.layout.refresh_footer, null);
|
|
|
|
|
+ resultListView.setRefreshFooter(list_footer);
|
|
|
|
|
|
|
|
- resultListView.addFooterView(footer);
|
|
|
|
|
|
|
+ refresh_footer = findViewById(R.id.result_refresh_footer);
|
|
|
|
|
+ refresh_footer.bringToFront();
|
|
|
|
|
|
|
|
|
|
+ resultListView.setOnRefreshListener(new PullRefreshListView.OnRefreshListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onHeaderStateChange(int state, int offset) {
|
|
|
|
|
+ Log.d("Pull Down", "onHeaderStateChange: " + offset);
|
|
|
|
|
+// setMargin(refresh_header,0,offset,0,0);
|
|
|
|
|
+// if (state == PullRefreshListView.REFRESHING) {
|
|
|
|
|
+// loadData();
|
|
|
|
|
+// }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onFooterStateChange(int state, int offset) {
|
|
|
|
|
+
|
|
|
|
|
+ setMargin(refresh_footer,0,resultListView.getHeight() - offset,0,0);
|
|
|
|
|
+ if (state == PullRefreshListView.REFRESHING) {
|
|
|
|
|
+ if (!isLoading) {
|
|
|
|
|
+ loadMore();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ resultSwipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onRefresh() {
|
|
|
|
|
+ if (isLoading) {
|
|
|
|
|
+ resultSwipe.setRefreshing(false);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ loadData();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- adapter = new ResultAdapter(mContext);
|
|
|
|
|
- resultListView.setAdapter(adapter);
|
|
|
|
|
- resultListView.setDividerHeight(0);
|
|
|
|
|
|
|
|
|
|
- resultListView.setOnScrollListener(this);
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState != null) {
|
|
if (savedInstanceState != null) {
|
|
|
mParams = savedInstanceState.getBundle("query_params");
|
|
mParams = savedInstanceState.getBundle("query_params");
|
|
@@ -279,30 +323,31 @@ public class SearchResultActivity extends AppCompatActivity implements AbsListVi
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public int last_index;
|
|
|
|
|
- public int total_index;
|
|
|
|
|
- public boolean isLoading = false;//表示是否正处于加载状态
|
|
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
|
|
|
|
- last_index = firstVisibleItem+visibleItemCount;
|
|
|
|
|
- total_index = totalItemCount;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onScrollStateChanged(AbsListView view, int scrollState) {
|
|
|
|
|
- if(last_index == total_index && (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE))
|
|
|
|
|
- {
|
|
|
|
|
- // 表示此时需要显示刷新视图界面进行新数据的加载(要等滑动停止)
|
|
|
|
|
- if(!isLoading)
|
|
|
|
|
- {
|
|
|
|
|
- // 设置刷新界面可见
|
|
|
|
|
- footer.setVisibility(View.VISIBLE);
|
|
|
|
|
- loadMore();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// public int last_index;
|
|
|
|
|
+// public int total_index;
|
|
|
|
|
+//
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
|
|
|
|
+// last_index = firstVisibleItem+visibleItemCount;
|
|
|
|
|
+// total_index = totalItemCount;
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public void onScrollStateChanged(AbsListView view, int scrollState) {
|
|
|
|
|
+// if(last_index == total_index && (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE))
|
|
|
|
|
+// {
|
|
|
|
|
+// // 表示此时需要显示刷新视图界面进行新数据的加载(要等滑动停止)
|
|
|
|
|
+// if(!isLoading)
|
|
|
|
|
+// {
|
|
|
|
|
+// // 设置刷新界面可见
|
|
|
|
|
+// footer.setVisibility(View.VISIBLE);
|
|
|
|
|
+// loadMore();
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
|
|
+ // 设置header 和 footer宽度,否则listView会显示默认宽度
|
|
|
protected void setupUI() {
|
|
protected void setupUI() {
|
|
|
try {
|
|
try {
|
|
|
if (resultData == null) {
|
|
if (resultData == null) {
|
|
@@ -319,14 +364,13 @@ public class SearchResultActivity extends AppCompatActivity implements AbsListVi
|
|
|
int width = header.getInt("width");
|
|
int width = header.getInt("width");
|
|
|
width = convertDp2Px(width);
|
|
width = convertDp2Px(width);
|
|
|
|
|
|
|
|
- AbsListView.LayoutParams footerLayoutParams = (AbsListView.LayoutParams)footer.getLayoutParams();
|
|
|
|
|
|
|
+ AbsListView.LayoutParams footerLayoutParams = (AbsListView.LayoutParams)list_footer.getLayoutParams();
|
|
|
if (footerLayoutParams == null) {
|
|
if (footerLayoutParams == null) {
|
|
|
footerLayoutParams = new AbsListView.LayoutParams(width,footer_height);
|
|
footerLayoutParams = new AbsListView.LayoutParams(width,footer_height);
|
|
|
}
|
|
}
|
|
|
footerLayoutParams.height = footer_height;
|
|
footerLayoutParams.height = footer_height;
|
|
|
footerLayoutParams.width = width;
|
|
footerLayoutParams.width = width;
|
|
|
-
|
|
|
|
|
- footer.setLayoutParams(footerLayoutParams);
|
|
|
|
|
|
|
+ list_footer.setLayoutParams(footerLayoutParams);
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
} catch (JSONException e) {
|
|
@@ -336,7 +380,12 @@ public class SearchResultActivity extends AppCompatActivity implements AbsListVi
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void loadComplete() {
|
|
public void loadComplete() {
|
|
|
- footer.setVisibility(View.GONE);//设置刷新界面不可见
|
|
|
|
|
|
|
+
|
|
|
|
|
+ setupUI();
|
|
|
|
|
+ resultListView.completeRefresh();
|
|
|
|
|
+ if (resultSwipe.isRefreshing()) {
|
|
|
|
|
+ resultSwipe.setRefreshing(false);
|
|
|
|
|
+ }
|
|
|
resultListView.forceLayout();
|
|
resultListView.forceLayout();
|
|
|
|
|
|
|
|
isLoading = false;//设置正在刷新标志位false
|
|
isLoading = false;//设置正在刷新标志位false
|
|
@@ -428,7 +477,7 @@ public class SearchResultActivity extends AppCompatActivity implements AbsListVi
|
|
|
runOnUiThread(new Runnable() {
|
|
runOnUiThread(new Runnable() {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
|
- setupUI();
|
|
|
|
|
|
|
+
|
|
|
loadComplete();
|
|
loadComplete();
|
|
|
int result = resultData.optInt("result",0);
|
|
int result = resultData.optInt("result",0);
|
|
|
if (result == 2) {
|
|
if (result == 2) {
|
|
@@ -514,7 +563,7 @@ public class SearchResultActivity extends AppCompatActivity implements AbsListVi
|
|
|
runOnUiThread(new Runnable() {
|
|
runOnUiThread(new Runnable() {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
|
- setupUI();
|
|
|
|
|
|
|
+
|
|
|
loadComplete();
|
|
loadComplete();
|
|
|
adapter.notifyDataSetChanged();
|
|
adapter.notifyDataSetChanged();
|
|
|
}
|
|
}
|