Ray Zhang 12 лет назад
Родитель
Сommit
de4d5b9e89

+ 9 - 3
Apex/AndroidManifest.xml

@@ -2,7 +2,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.usai.apex"
     android:versionCode="1"
-    android:versionName="1.0" >
+    android:versionName="1.0214" >
 
     <!-- Copied from Google Maps Library/AndroidManifest.xml. -->
     <uses-sdk
@@ -49,7 +49,7 @@
                 <action android:name="android.intent.action.MAIN" />
 
                 <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
+            </intent-filter>

             -->
         </activity>
         <activity
@@ -72,7 +72,7 @@
         <activity
             android:name="com.usai.apex.DirectTrackingFragment"
             android:label="@string/title_activity_direct_tracking" >
-        </activity>





+        </activity>






         -->
         <activity
             android:name="com.usai.apex.FunctionSelectActivity"
@@ -112,6 +112,12 @@
             android:name="com.usai.apex.CargoTrackingActivity"
             android:label="@string/title_activity_cargo_tracking" >
         </activity>
+        <activity
+            android:name="com.usai.apex.SearchListActivity"
+            android:label="@string/title_activity_search_list" 
+            android:screenOrientation="portrait"
+            android:windowSoftInputMode="adjustUnspecified|stateHidden">
+        </activity>
     </application>
 
 </manifest>

+ 47 - 0
Apex/res/layout/activity_search_list.xml

@@ -0,0 +1,47 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".SearchListActivity" >
+
+    <ScrollView
+        android:id="@+id/scrollView1"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_above="@+id/foot" >
+
+        <LinearLayout
+            android:id="@+id/ll_list"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+
+            android:orientation="vertical" >
+        </LinearLayout>
+    </ScrollView>
+
+    <LinearLayout
+        android:id="@+id/foot"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentLeft="true"
+        android:orientation="horizontal" >
+
+        <Button
+            android:id="@+id/btncancel"
+            style="?android:attr/buttonStyleSmall"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:text="@android:string/cancel" />
+
+        <Button
+            android:id="@+id/btnok"
+            style="?android:attr/buttonStyleSmall"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:text="@string/search" />
+    </LinearLayout>
+
+</RelativeLayout>

+ 29 - 0
Apex/res/layout/search_item_edit.xml

@@ -0,0 +1,29 @@
+<?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="wrap_content" >
+
+    <TextView
+        android:id="@+id/aname"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentTop="true"
+        android:text="Medium Text"
+        android:textAppearance="?android:attr/textAppearanceMedium" />
+
+    <EditText
+        android:id="@+id/edit_val"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_below="@+id/aname"
+        android:ems="15"
+        android:hint="@string/prompt_search_criterion"
+        android:inputType="textAutoComplete"
+        android:maxLines="1"
+        android:singleLine="true"
+        android:text="" >
+    </EditText>
+
+</RelativeLayout>

+ 24 - 0
Apex/res/layout/search_item_switch.xml

@@ -0,0 +1,24 @@
+<?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="wrap_content" >
+
+    <TextView
+        android:id="@+id/aname"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentTop="true"
+        android:text="Medium Text"
+        android:textAppearance="?android:attr/textAppearanceMedium" />
+<Switch
+        android:id="@+id/switch_bool"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentRight="true"
+        android:layout_below="@+id/aname"
+        android:text=""
+        android:textOff="false"
+        android:textOn="true"
+        android:visibility="visible" />
+</RelativeLayout>

+ 3 - 3
Apex/res/layout/search_lvitem_edit.xml

@@ -4,7 +4,7 @@
     android:layout_height="wrap_content" >
 
     <TextView
-        android:id="@+id/aliasName"
+        android:id="@+id/aname"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentLeft="true"
@@ -17,7 +17,7 @@
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_alignParentLeft="true"
-        android:layout_below="@+id/aliasName"
+        android:layout_below="@+id/aname"
         android:ems="15"
         android:hint="@string/prompt_search_criterion"
         android:inputType="textAutoComplete"
@@ -31,7 +31,7 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentLeft="true"
-        android:layout_below="@+id/aliasName"
+        android:layout_below="@+id/aname"
         android:text=""
         android:textOff="no"
         android:textOn="yes"

+ 14 - 0
Apex/res/menu/search_list.xml

@@ -0,0 +1,14 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+
+    <item
+        android:id="@+id/action_custom_fields"
+        android:orderInCategory="100"
+        android:showAsAction="never"
+        android:title="@string/action_custom_fields"/>
+    <item
+        android:id="@+id/action_help"
+        android:orderInCategory="200"
+        android:showAsAction="ifRoom" 
+        android:icon="@android:drawable/ic_menu_help"
+        android:title="@string/action_help"/>
+</menu>

+ 1 - 0
Apex/res/values/strings.xml

@@ -45,5 +45,6 @@
       via an &lt;a&gt; tag.  Use a \"tel:\" URL
       to <a href="tel:4155551212">dial a phone number</a>.
</string>
     <string name="title_activity_cargo_tracking">CargoTrackingActivity</string>
+    <string name="title_activity_search_list">SearchListActivity</string>
 
 </resources>

+ 3 - 3
Apex/src/com/usai/apex/FunctionSelectActivity.java

@@ -60,7 +60,7 @@ public class FunctionSelectActivity extends FragmentActivity implements OnClickL
 		case R.id.ibtn_booking:
 		{
 			Intent intent = new Intent();
-			intent.setClass(this, SearchActivity.class);
+			intent.setClass(this, SearchListActivity.class);
 			intent.putExtra("user", user);
 			intent.putExtra("password", password);
 			intent.putExtra("function_name", "Ocean Booking");
@@ -70,7 +70,7 @@ public class FunctionSelectActivity extends FragmentActivity implements OnClickL
 		case R.id.ibtn_info:
 		{
 			Intent intent = new Intent();
-			intent.setClass(this, SearchActivity.class);
+			intent.setClass(this, SearchListActivity.class);
 			intent.putExtra("user", user);
 			intent.putExtra("password", password);
 			intent.putExtra("function_name", "Ocean B/L info.");
@@ -80,7 +80,7 @@ public class FunctionSelectActivity extends FragmentActivity implements OnClickL
 		case R.id.ibtn_detail:
 		{
 			Intent intent = new Intent();
-			intent.setClass(this, SearchActivity.class);
+			intent.setClass(this, SearchListActivity.class);
 			intent.putExtra("user", user);
 			intent.putExtra("password", password);
 			intent.putExtra("function_name", "Container detail");

+ 66 - 57
Apex/src/com/usai/apex/SearchActivity.java

@@ -34,7 +34,7 @@ public class SearchActivity extends ListActivity implements OnClickListener
 	String password = null;
 	String function_name = null;
 	RecordsAdapter m_listadapter;
-//	private ListView m_ListView = null;
+	// private ListView m_ListView = null;
 	HashMap<String, String> hashMap = new HashMap<String, String>();
 
 	public class RecordsAdapter extends SimpleCursorAdapter
@@ -107,37 +107,44 @@ public class SearchActivity extends ListActivity implements OnClickListener
 			final String f0 = cursor.getString(0);
 			final String field_type = cursor.getString(1);
 			final String name = cursor.getString(2);
-			
-			Log.e("cursor val", "name="+f0+" , type="+field_type);
-			final EditText edit = (EditText) view.findViewById(R.id.edit_val);
-			edit.addTextChangedListener(new TextWatcher()
-			{
-				@Override
-				public void onTextChanged(CharSequence s, int start,
-						int before, int count)
-				{
-
-				}
 
-				@Override
-				public void beforeTextChanged(CharSequence s, int start,
-						int count, int after)
-				{
-
-				}
+			Log.e("cursor val", "name=" + f0 + " , type=" + field_type);
+			final EditText edit = (EditText) view.findViewById(R.id.edit_val);
+			edit.setText(hashMap.get(name));
+			Log.v("from hashmap",
+					"name=" + name + " , val=" + hashMap.get(name));
 
-				@Override
-				public void afterTextChanged(Editable s)
-				{
-					// 将editText中改变的值设置的HashMap中
-					String val = s.toString();
-					val.trim();
-					if (val.length() > 0)
-						hashMap.put(name, val);
-					
-//					Log.d("ime debug", "name="+f0+" , type="+field_type+", ime="+edit.getInputType());
-				}
-			});
+//			edit.seton
+//			edit.addTextChangedListener(new TextWatcher()
+//			{
+//				@Override
+//				public void onTextChanged(CharSequence s, int start,
+//						int before, int count)
+//				{
+//
+//				}
+//
+//				@Override
+//				public void beforeTextChanged(CharSequence s, int start,
+//						int count, int after)
+//				{
+//
+//				}
+//
+//				@Override
+//				public void afterTextChanged(Editable s)
+//				{
+//					// 将editText中改变的值设置的HashMap中
+//					String val = s.toString();
+//					val.trim();
+//					if (val.length() > 0)
+//					{
+//						hashMap.put(name, val);
+//
+//						Log.i("to hashmap", "name=" + name + " , val=" + val);
+//					}
+//				}
+//			});
 			Switch switch_bool = (Switch) view.findViewById(R.id.switch_bool);
 			if (field_type.equals("boolean"))
 			{
@@ -152,16 +159,20 @@ public class SearchActivity extends ListActivity implements OnClickListener
 				{
 					edit.setInputType(InputType.TYPE_DATETIME_VARIATION_DATE
 							| InputType.TYPE_CLASS_DATETIME);
-					
-				}
-				else if (field_type.equals("int")) {
-					
-					edit.setInputType(InputType.TYPE_CLASS_NUMBER);
-				}
-				else {
-					edit.setInputType(InputType.TYPE_CLASS_TEXT);
+
 				}
-				Log.d("ime debug", "name="+f0+" , type="+field_type+", ime="+edit.getInputType());
+				else
+					if (field_type.equals("int"))
+					{
+
+						edit.setInputType(InputType.TYPE_CLASS_NUMBER);
+					}
+					else
+					{
+						edit.setInputType(InputType.TYPE_CLASS_TEXT);
+					}
+				Log.d("ime debug", "name=" + f0 + " , type=" + field_type
+						+ ", ime=" + edit.getInputType());
 			}
 			super.bindView(view, context, cursor);
 
@@ -209,7 +220,7 @@ public class SearchActivity extends ListActivity implements OnClickListener
 		m_db = dbUtil.OpenDB(this, null, true);
 		// m_TextView = (TextView) findViewById(R.id.summarytext);
 		// m_TextView.setText(getString(m_Activityinfo.TextViewValue));
-//		m_ListView = (ListView) findViewById(android.R.id.list);
+		// m_ListView = (ListView) findViewById(android.R.id.list);
 		m_cursor = m_db.query("fields_info", new String[] { "aname",
 				"field_type", "name", "_id" }, "function_name='"
 				+ function_name + "' and user='" + user + "' and behavior="
@@ -224,35 +235,33 @@ public class SearchActivity extends ListActivity implements OnClickListener
 				// Map the NAME column in the people database to...
 				new String[] { "aname", "field_type", "name" },
 				// The "text1" view defined in the XML template
-				new int[] { R.id.aliasName, R.id.tv_type });
+				new int[] { R.id.aname, R.id.tv_type });
 		setListAdapter(m_listadapter);
 		Button btnok = (Button) findViewById(R.id.btnok);
 		btnok.setOnClickListener(this);
 		Button btncancel = (Button) findViewById(R.id.btncancel);
 		btncancel.setOnClickListener(this);
-		
-		
+
 		SharedPreferences RunOnce = getSharedPreferences("Apex", 0);
-		
+
 		String vername;
 		try
 		{
-			vername = getPackageManager().getPackageInfo(
-					"com.usai.apex", 0).versionName;
-			boolean bFirstRun = RunOnce.getBoolean(
-					"FirstRun"+vername+"_search", true);
-			if(bFirstRun)
+			vername = getPackageManager().getPackageInfo("com.usai.apex", 0).versionName;
+			boolean bFirstRun = RunOnce.getBoolean("FirstRun" + vername
+					+ "_search", true);
+			if (bFirstRun)
 			{
 				SharedPreferences.Editor editor = RunOnce.edit();
-				editor.putBoolean("FirstRun"+vername+"_search", false);
+				editor.putBoolean("FirstRun" + vername + "_search", false);
 				// Don't forget to commit your edits!!!
 				editor.commit();
 				Intent intent = new Intent();
 				intent.setClass(this, HelpActivity.class);
 				intent.putExtra("caller", "search");
 				startActivity(intent);
-				
-			}		
+
+			}
 		}
 		catch (NameNotFoundException e)
 		{
@@ -334,12 +343,12 @@ public class SearchActivity extends ListActivity implements OnClickListener
 			startActivity(intent);
 			break;
 		case R.id.action_help:
-//			Intent intent = new Intent();
+			// Intent intent = new Intent();
 			intent.setClass(this, HelpActivity.class);
 			intent.putExtra("caller", "search");
-//			// intent.putExtra("password", password);
-//			intent.putExtra("function_name", function_name);
-//			intent.putExtra("behavior", Network.BEHAVIOR_SEARCH);
+			// // intent.putExtra("password", password);
+			// intent.putExtra("function_name", function_name);
+			// intent.putExtra("behavior", Network.BEHAVIOR_SEARCH);
 			startActivity(intent);
 			break;
 		default:
@@ -361,7 +370,7 @@ public class SearchActivity extends ListActivity implements OnClickListener
 			intent.putExtra("password", password);
 			intent.putExtra("function_name", function_name);
 			Bundle parms = new Bundle();
-			parms.putString("module_name",function_name);
+			parms.putString("module_name", function_name);
 			parms.putString("columns", dbUtil.get_fields(user, function_name));
 			Iterator<String> iter = hashMap.keySet().iterator();
 			while (iter.hasNext())

+ 243 - 0
Apex/src/com/usai/apex/SearchListActivity.java

@@ -0,0 +1,243 @@
+package com.usai.apex;
+
+import java.util.HashMap;
+import java.util.Iterator;
+
+import com.usai.util.Network;
+import com.usai.util.dbUtil;
+
+import android.os.Bundle;
+import android.app.Activity;
+import android.content.Intent;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.text.Editable;
+import android.text.InputType;
+import android.text.TextWatcher;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.CompoundButton;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.Switch;
+import android.widget.TextView;
+
+public class SearchListActivity extends Activity implements OnClickListener
+{
+
+	LinearLayout ll_list;
+	String user = null;
+	String password = null;
+	String function_name = null;
+	HashMap<String, Field> hashMap = new HashMap<String, Field>();
+	private class Field
+	{
+		String name;
+		String value;
+		public Field(String n,String v)
+		{
+			name=n;
+			value=v;
+		}
+	}
+	@Override
+	protected void onCreate(Bundle savedInstanceState)
+	{
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_search_list);
+		user = getIntent().getStringExtra("user");
+		password = getIntent().getStringExtra("password");
+		function_name = getIntent().getStringExtra("function_name");
+
+		ll_list = (LinearLayout) findViewById(R.id.ll_list);
+		Button btnok = (Button) findViewById(R.id.btnok);
+		btnok.setOnClickListener(this);
+		Button btncancel = (Button) findViewById(R.id.btncancel);
+		btncancel.setOnClickListener(this);
+
+		
+	}
+	@Override
+	protected void onResume()
+	{
+		init();
+		super.onResume();
+	}
+
+	void init()
+	{
+		hashMap.clear();
+		ll_list.removeAllViews();
+		SQLiteDatabase db = dbUtil.OpenDB(this, null, true);
+		Cursor cursor = db.query("fields_info", new String[] { "aname",
+				"field_type", "name", "_id" }, "function_name='"
+				+ function_name + "' and user='" + user + "' and behavior="
+				+ Network.BEHAVIOR_SEARCH + " and show = 1", null, null, null,
+				"priority , aname", null);
+		while (cursor.moveToNext())
+		{
+			final String aname = cursor.getString(0);
+			String field_type = cursor.getString(1);
+			final String name = cursor.getString(2);
+
+//			hashMap.put(aname, field);
+
+			if (field_type.equals("boolean"))
+			{
+				RelativeLayout switchitem = (RelativeLayout) this
+						.getLayoutInflater().inflate(
+								R.layout.search_item_switch, null);
+				TextView tvname = (TextView) switchitem
+						.findViewById(R.id.aname);
+				tvname.setText(aname);
+				Switch switch_bool = (Switch) switchitem
+						.findViewById(R.id.switch_bool);
+				switch_bool.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
+
+					@Override
+					public void onCheckedChanged(CompoundButton buttonView,
+							boolean isChecked)
+					{
+						String val;
+						if(isChecked)
+							val="true";
+						else
+							val="false";
+						Field field = new Field(name,val);
+						field.name = aname;
+						hashMap.put(aname,field);
+						
+					}
+					
+				});
+				ll_list.addView(switchitem);
+			}
+			else
+			{
+				RelativeLayout edititem = (RelativeLayout) this
+						.getLayoutInflater().inflate(R.layout.search_item_edit,
+								null);
+				TextView tvname = (TextView) edititem.findViewById(R.id.aname);
+				tvname.setText(aname);
+				EditText edit = (EditText) edititem.findViewById(R.id.edit_val);
+				edit.addTextChangedListener(new TextWatcher()
+				{
+					@Override
+					public void onTextChanged(CharSequence s, int start,
+							int before, int count)
+					{
+	
+					}
+	
+					@Override
+					public void beforeTextChanged(CharSequence s, int start,
+							int count, int after)
+					{
+	
+					}
+	
+					@Override
+					public void afterTextChanged(Editable s)
+					{
+						// ½«editTextÖиıäµÄÖµÉèÖõÄHashMapÖÐ
+						String val = s.toString();
+						val.trim();
+						if (val.length() > 0)
+						{
+							Field field = new Field(name,val);
+							field.name = aname;
+							hashMap.put(aname,field);
+						}
+					}
+
+		
+				});
+				if (field_type.equals("time"))
+					edit.setInputType(InputType.TYPE_DATETIME_VARIATION_DATE
+							| InputType.TYPE_CLASS_DATETIME);
+				else if (field_type.equals("int"))
+					edit.setInputType(InputType.TYPE_CLASS_NUMBER);
+
+				ll_list.addView(edititem);
+			}
+		}
+	}
+
+	@Override
+	public boolean onCreateOptionsMenu(Menu menu)
+	{
+		// Inflate the menu; this adds items to the action bar if it is present.
+		getMenuInflater().inflate(R.menu.search_list, menu);
+		return true;
+	}
+
+	@Override
+	public void onClick(View v)
+	{
+		switch (v.getId())
+		{
+		case R.id.btnok:
+		{
+			Intent intent = new Intent();
+			intent.setClass(this, ResultActivity.class);
+			intent.putExtra("user", user);
+			intent.putExtra("password", password);
+			intent.putExtra("function_name", function_name);
+			Bundle parms = new Bundle();
+			parms.putString("module_name", function_name);
+			parms.putString("columns", dbUtil.get_fields(user, function_name));
+			Iterator<String> iter = hashMap.keySet().iterator();
+			while (iter.hasNext())
+			{
+				String aname = (String) iter.next();
+				Field field = (Field) hashMap.get(aname);
+				parms.putString(field.name, field.value);
+			}
+			intent.putExtra("searchParms", parms);
+
+			startActivity(intent);
+
+			break;
+		}
+		case R.id.btncancel:
+			finish();
+			break;
+		default:
+			break;
+		}
+
+	}
+
+	@Override
+	public boolean onOptionsItemSelected(MenuItem item)
+	{
+		Intent intent = new Intent();
+		switch (item.getItemId())
+		{
+		case R.id.action_custom_fields:
+			intent.setClass(this, CustomizeFieldsActivity.class);
+			intent.putExtra("user", user);
+			// intent.putExtra("password", password);
+			intent.putExtra("function_name", function_name);
+			intent.putExtra("behavior", Network.BEHAVIOR_SEARCH);
+			startActivity(intent);
+			break;
+		case R.id.action_help:
+			// Intent intent = new Intent();
+			intent.setClass(this, HelpActivity.class);
+			intent.putExtra("caller", "search");
+			// // intent.putExtra("password", password);
+			// intent.putExtra("function_name", function_name);
+			// intent.putExtra("behavior", Network.BEHAVIOR_SEARCH);
+			startActivity(intent);
+			break;
+		default:
+			break;
+		}
+		return super.onOptionsItemSelected(item);
+	}
+}