|
|
@@ -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
|
|
|
{
|