Ray Zhang 12 anni fa
parent
commit
44f2b9a631

+ 28 - 12
Apex/res/layout/activity_result.xml

@@ -12,6 +12,7 @@
         android:layout_gravity="center"
         android:gravity="center_horizontal"
         android:orientation="vertical"
+        android:background="#80808080"
         android:visibility="gone" >
 
         <ProgressBar
@@ -29,24 +30,31 @@
             android:textAppearance="?android:attr/textAppearanceMedium" />
     </LinearLayout>
 
-    <HorizontalScrollView
+    <ScrollView
         android:id="@+id/search_form"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:layout_above="@+id/btn_more"
         android:layout_below="@+id/tv_head" >
 
-        <TableLayout
-            android:id="@+id/result_table"
-            android:layout_width="wrap_content"
-            android:layout_height="fill_parent" >
+        <HorizontalScrollView
+            android:id="@+id/horizontalScrollView1"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent" >
 
-            <TableRow
-                android:id="@+id/tr_header"
+            <TableLayout
+                android:id="@+id/result_table"
                 android:layout_width="wrap_content"
-                android:layout_height="wrap_content" >
-            </TableRow>
-        </TableLayout>
-    </HorizontalScrollView>
+                android:layout_height="fill_parent" >
+
+                <TableRow
+                    android:id="@+id/tr_header"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content" >
+                </TableRow>
+            </TableLayout>
+        </HorizontalScrollView>
+    </ScrollView>
 
     <TextView
         android:id="@+id/tv_head"
@@ -54,7 +62,15 @@
         android:layout_height="wrap_content"
         android:layout_alignParentTop="true"
         android:layout_centerHorizontal="true"
-        android:text="Show count here"
+        android:text=""
         android:textAppearance="?android:attr/textAppearanceLarge" />
 
+    <Button
+        android:id="@+id/btn_more"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentLeft="true"
+        android:text="Load More" />
+
 </RelativeLayout>

+ 14 - 0
Apex/res/layout/result_item.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent" >
+
+    <TextView
+        android:id="@+id/tv_value"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentTop="true"
+        android:text="TextView" />
+
+</RelativeLayout>

+ 171 - 51
Apex/src/com/usai/apex/ResultActivity.java

@@ -2,6 +2,9 @@ package com.usai.apex;
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -25,7 +28,11 @@ import android.view.Gravity;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
 import android.widget.Button;
+import android.widget.GridView;
+import android.widget.SimpleAdapter;
 import android.widget.TableLayout;
 import android.widget.TableRow;
 import android.widget.TextView;
@@ -41,11 +48,17 @@ public class ResultActivity extends Activity
 	Bundle searchParms = null;
 	SearchResult searchresult = new SearchResult();
 
-	HashMap<String, Integer> showfieldmap = new HashMap<String, Integer>();
+	HashMap<Integer, String> showfieldmap = new HashMap<Integer, String>();
 	private TextView mStatusMessageView;
-	private View mSearchFormView;
+	// private View mSearchFormView;
+	private Button mbtnMore;
 	private View mStatusView;
 
+	// private class resultAdapter extends SimpleAdapter
+	// {
+	//
+	//
+	// }
 	@Override
 	protected void onCreate(Bundle savedInstanceState)
 	{
@@ -55,7 +68,25 @@ public class ResultActivity extends Activity
 		searchParms = getIntent().getBundleExtra("searchParms");
 		super.onCreate(savedInstanceState);
 		setContentView(R.layout.activity_result);
-		mSearchFormView = findViewById(R.id.search_form);
+		// mSearchFormView = findViewById(R.id.search_form);
+		mbtnMore = (Button) findViewById(R.id.btn_more);
+		mbtnMore.setOnClickListener(new View.OnClickListener()
+		{
+
+			@Override
+			public void onClick(View v)
+			{
+//				TextView tv_head = (TextView) findViewById(R.id.tv_head);
+
+				if (searchresult.get_totalcount()==-1)
+					requestdata(true);
+				else
+				{
+					requestdata(false);
+				}
+
+			}
+		});
 		mStatusView = findViewById(R.id.status);
 		mStatusMessageView = (TextView) findViewById(R.id.status_message);
 		initTable();
@@ -66,26 +97,43 @@ public class ResultActivity extends Activity
 	void initTable()
 	{
 		SQLiteDatabase db = dbUtil.OpenDB(this, null, false);
-		Cursor cursor = db.query("fields_info",
-				new String[] { "aname", "_id" }, "function_name='"
-						+ function_name + "' and user='" + user
-						+ "' and behavior=" + Network.BEHAVIOR_RESULT
-						+ " and show = 1", null, null, null,
-				"priority , aname", null);
+		Cursor cursor = db.query("fields_info", new String[] { "aname", "name",
+				"_id" }, "function_name='" + function_name + "' and user='"
+				+ user + "' and behavior=" + Network.BEHAVIOR_RESULT
+				+ " and show = 1", null, null, null, "priority , aname", null);
 		TableRow headerRow = (TableRow) findViewById(R.id.tr_header);
 		int pos = 0;
 		showfieldmap.clear();
 		headerRow.removeAllViews();
+		ArrayList<HashMap<String, String>> gridheader = new ArrayList<HashMap<String, String>>();
+		HashMap<String, String> map = new HashMap<String, String>();
+		map.put("key", "no.");
+		gridheader.add(map);
 		while (cursor.moveToNext())
 		{
 			String aname = cursor.getString(0);
 			Button btn = new Button(this);
 			btn.setText(aname);
 			headerRow.addView(btn);
-			showfieldmap.put(aname, pos);
+			showfieldmap.put(pos, cursor.getString(1));
+
+			map.put("key", "header");
+			gridheader.add(map);
+			pos++;
 		}
 		dbUtil.CloseCursor(cursor);
 		dbUtil.CloseDB(db);
+
+		// SimpleAdapter adapter = new SimpleAdapter(this,
+		// gridheader,// 数据来源
+		// R.layout.result_item,//XML实现
+		// new String[] { "key" }, // 动态数组与ImageItem对应的子项
+		// new int[] { R.id.tv_value });
+		//
+		// GridView gridview = (GridView) findViewById(R.id.grid_result);
+		// gridview.setNumColumns(2);
+		// gridview.setAdapter(adapter);
+
 	}
 
 	@Override
@@ -123,7 +171,7 @@ public class ResultActivity extends Activity
 		{
 			return;
 		}
-		mStatusMessageView.setText(R.string.login_progress_signing_in);
+		mStatusMessageView.setText("Loading");
 		showProgress(true);
 		m_task = new SearchTask();
 		m_task.execute(requestcount);
@@ -153,25 +201,38 @@ public class ResultActivity extends Activity
 						}
 					});
 
-			mSearchFormView.setVisibility(View.VISIBLE);
-			mSearchFormView.animate().setDuration(shortAnimTime)
-					.alpha(show ? 0 : 1)
+			mbtnMore.setVisibility(View.VISIBLE);
+			mbtnMore.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
 					.setListener(new AnimatorListenerAdapter()
 					{
 						@Override
 						public void onAnimationEnd(Animator animation)
 						{
-							mSearchFormView.setVisibility(show ? View.INVISIBLE
+							mbtnMore.setVisibility(show ? View.INVISIBLE
 									: View.VISIBLE);
 						}
 					});
+			// mSearchFormView.setVisibility(View.VISIBLE);
+			// mSearchFormView.animate().setDuration(shortAnimTime)
+			// .alpha(show ? 0 : 1)
+			// .setListener(new AnimatorListenerAdapter()
+			// {
+			// @Override
+			// public void onAnimationEnd(Animator animation)
+			// {
+			// mSearchFormView.setVisibility(show ? View.INVISIBLE
+			// : View.VISIBLE);
+			// }
+			// });
 		}
 		else
 		{
 			// The ViewPropertyAnimator APIs are not available, so simply show
 			// and hide the relevant UI components.
 			mStatusView.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
-			mSearchFormView.setVisibility(show ? View.INVISIBLE : View.VISIBLE);
+			mbtnMore.setVisibility(show ? View.INVISIBLE : View.VISIBLE);
+			// mSearchFormView.setVisibility(show ? View.INVISIBLE :
+			// View.VISIBLE);
 		}
 	}
 
@@ -197,7 +258,7 @@ public class ResultActivity extends Activity
 				if (ret >= 0)
 				{
 					searchresult.put_totalcount(ret);
-					if(ret==0)
+					if (ret == 0)
 						return true;
 				}
 				else
@@ -207,6 +268,7 @@ public class ResultActivity extends Activity
 				}
 			}
 
+			searchParms.putString("offset", searchresult.get_count()+"");
 			String jstr = Network.get_records(user, password, searchParms);
 			if (jstr == null || jstr.length() <= 0)
 			{
@@ -224,15 +286,14 @@ public class ResultActivity extends Activity
 				if (searchresult.get_fieldscount() == 0)
 				{
 					JSONObject objfields = jsobj.getJSONObject("fields");
-					if(objfields!=null)
+					if (objfields != null)
 						searchresult.init_fields(objfields.toString());
 				}
 				JSONObject objrecords = jsobj.getJSONObject("records");
-				if(objrecords!=null)
+				if (objrecords != null)
 					searchresult.add_records(objrecords.toString());
 				errorcode = Network.RESULT_TRUE;
-				
-				
+
 				return true;
 
 			}
@@ -290,26 +351,54 @@ public class ResultActivity extends Activity
 			if (success)
 			{
 
+				int loadcount = searchresult.get_count();
+				int totalcount = searchresult.get_totalcount();
 				TextView tv_head = (TextView) findViewById(R.id.tv_head);
-				tv_head.setText(searchresult.get_totalcount()+"");
-//				// fill fake data
-//				for(int i=0;i<10;i++)
-//				{
-//					TableRow recordRow = new TableRow(ResultActivity.this);
-//					for(int j=0;j<showfieldmap.size();j++)
-//					{
-//						TextView field = new TextView(ResultActivity.this);
-//						field.setText("fake data");
-//						field.setGravity(Gravity.CENTER);
-//						field.setTextAppearance(ResultActivity.this,android.R.attr.textAppearanceMedium);
-//						recordRow.addView(field);
-//					}
-//					TableLayout tl=(TableLayout)findViewById(R.id.result_table);
-//					tl.addView(recordRow);
-//						
-//				}
-				
-				
+				if (totalcount == 0)
+					tv_head.setText("0 record found");
+				else
+					tv_head.setText(loadcount + "/"
+							+ searchresult.get_totalcount() + " records");
+				TableLayout tl = (TableLayout) findViewById(R.id.result_table);
+
+				int showcount = tl.getChildCount();
+				int newcount = loadcount - showcount + 1;// +1 header row
+				for (int i = 0; i < newcount; i++)
+				{
+					TableRow recordRow = new TableRow(ResultActivity.this);
+					HashMap<String, String> record = searchresult
+							.get_record(loadcount - newcount);
+					for (int j = 0; j < showfieldmap.size(); j++)
+					{
+						TextView field = new TextView(ResultActivity.this);
+						field.setText(record.get(showfieldmap.get(j)));
+						field.setGravity(Gravity.CENTER);
+						field.setPadding(10, 5, 10, 5);
+						field.setTextSize(20);
+						// field.setTextAppearance(ResultActivity.this,
+						// android.R.attr.textAppearanceMedium);
+						recordRow.addView(field);
+					}
+					tl.addView(recordRow);
+				}
+
+				// // fill fake data
+				// for(int i=0;i<10;i++)
+				// {
+				// TableRow recordRow = new TableRow(ResultActivity.this);
+				// for(int j=0;j<showfieldmap.size();j++)
+				// {
+				// TextView field = new TextView(ResultActivity.this);
+				// field.setText("fake data");
+				// field.setGravity(Gravity.CENTER);
+				// field.setTextAppearance(ResultActivity.this,android.R.attr.textAppearanceMedium);
+				// recordRow.addView(field);
+				// }
+				// TableLayout tl=(TableLayout)findViewById(R.id.result_table);
+				// tl.addView(recordRow);
+				//
+				// }
+
 				// SharedPreferences.Editor editor = RunOnce.edit();
 				// editor.putBoolean("FirstRun"+globalUtil.getVerName(this),
 				// false);
@@ -325,6 +414,7 @@ public class ResultActivity extends Activity
 			}
 			else
 			{
+//				TextView tv_head = (TextView) findViewById(R.id.tv_head);
 				// m_etPassword
 				// .setError(getString(R.string.error_incorrect_password));
 				// m_etPassword.requestFocus();
@@ -334,16 +424,16 @@ public class ResultActivity extends Activity
 		@Override
 		protected void onCancelled()
 		{
-			 m_task = null;
-			 showProgress(false);
+			m_task = null;
+			showProgress(false);
 		}
 	}
 
 	private class SearchResult
 	{
-		int total_count = 0;
+		int total_count = -1;
 		// int count = 0;
-		ArrayList<record> records = new ArrayList<record>();
+		ArrayList<HashMap<String, String>> records = new ArrayList<HashMap<String, String>>();
 		ArrayList<field> fields = new ArrayList<field>();
 
 		public void init_fields(String jsonfields)
@@ -353,10 +443,40 @@ public class ResultActivity extends Activity
 
 		}
 
-		public void add_records(String records)
+		public HashMap<String, String> get_record(int i)
 		{
+			return records.get(i);
+		}
+
+		public void add_records(String jsonstr)
+		{
+			try
+			{
+				JSONObject objrecords = new JSONObject(jsonstr);
+				for (int i = 0; i < objrecords.length(); i++)
+				{
+					JSONObject rec = objrecords.getJSONObject("record" + i);
+					Iterator it = rec.keys();
+					HashMap<String, String> record = new HashMap<String, String>();
+					while (it.hasNext()) // loop for each function
+					{
+						String field_name = (String) it.next();
+						String val = rec.getString(field_name);
+						record.put(field_name, val);
+					}
+					records.add(record);
+
+				}
+				// Log.e("records count:",objrecords.length()+"");
+
+			}
+			catch (JSONException e)
+			{
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
 			String TAG = "init_fields@ResultActivity.SearchResult";
-			Log.d(TAG, records);
+			Log.d(TAG, jsonstr);
 		}
 
 		public int get_totalcount()
@@ -379,11 +499,11 @@ public class ResultActivity extends Activity
 			return fields.size();
 		}
 
-		private class record
-		{
-			ArrayList<Object> values;
-
-		}
+		// private class record
+		// {
+		// HashMap<String,Object> values = ;
+		//
+		// }
 
 		private class field
 		{