SearchActivity.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. package com.usai.apex;
  2. import android.app.ListActivity;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.content.SharedPreferences;
  6. import android.content.pm.PackageManager.NameNotFoundException;
  7. import android.database.Cursor;
  8. import android.database.sqlite.SQLiteDatabase;
  9. import android.os.Bundle;
  10. import android.text.InputType;
  11. import android.util.Log;
  12. import android.view.Menu;
  13. import android.view.MenuItem;
  14. import android.view.View;
  15. import android.view.View.OnClickListener;
  16. import android.widget.Button;
  17. import android.widget.EditText;
  18. import android.widget.SimpleCursorAdapter;
  19. import android.widget.Switch;
  20. import com.usai.util.Network;
  21. import com.usai.util.dbUtil;
  22. import java.util.HashMap;
  23. import java.util.Iterator;
  24. public class SearchActivity extends ListActivity implements OnClickListener
  25. {
  26. private SQLiteDatabase m_db = null;
  27. private Cursor m_cursor = null;
  28. String user = null;
  29. String password = null;
  30. String function_name = null;
  31. RecordsAdapter m_listadapter;
  32. // private ListView m_ListView = null;
  33. HashMap<String, String> hashMap = new HashMap<String, String>();
  34. public class RecordsAdapter extends SimpleCursorAdapter
  35. {
  36. public RecordsAdapter(Context context, int layout, Cursor c,
  37. String[] from, int[] to)
  38. {
  39. super(context, layout, c, from, to);
  40. // TODO Auto-generated constructor stub
  41. }
  42. // @Override
  43. // public View getView(int position, View convertView, ViewGroup parent)
  44. // {
  45. // // if(true)
  46. // // return super.getView(position, convertView, parent);
  47. // if(convertView==null)
  48. // convertView = LayoutInflater.from(getApplication()).inflate(
  49. // R.layout.search_lvitem_edit, null);
  50. // // holder = new ViewHolder();
  51. // // holder.textView = (TextView)convertView.findViewById(R.id.text);
  52. // // convertView.setTag(holder);
  53. // final int pos=position;
  54. // // convertView = LayoutInflater.from(getApplication()).inflate(
  55. // // R.layout.search_lvitem_edit, null);
  56. //
  57. // EditText editText = (EditText) convertView
  58. // .findViewById(R.id.edit_val);
  59. // // editText.setText(str);
  60. //
  61. // // 为editText设置TextChangedListener,每次改变的值设置到hashMap
  62. // // 我们要拿到里面的值根据position拿值
  63. // editText.addTextChangedListener(new TextWatcher()
  64. // {
  65. // @Override
  66. // public void onTextChanged(CharSequence s, int start,
  67. // int before, int count)
  68. // {
  69. //
  70. // }
  71. //
  72. // @Override
  73. // public void beforeTextChanged(CharSequence s, int start,
  74. // int count, int after)
  75. // {
  76. //
  77. // }
  78. //
  79. // @Override
  80. // public void afterTextChanged(Editable s)
  81. // {
  82. // // int a = position;
  83. // // 将editText中改变的值设置的HashMap中
  84. // hashMap.put(pos, s.toString());
  85. // }
  86. // });
  87. //
  88. // // // 如果hashMap不为空,就设置的editText
  89. // // if (hashMap.get(position) != null)
  90. // // {
  91. // // editText.setText(hashMap.get(position));
  92. // // }
  93. // return convertView;
  94. // }
  95. @Override
  96. public void bindView(View view, Context context, Cursor cursor)
  97. {
  98. final String f0 = cursor.getString(0);
  99. final String field_type = cursor.getString(1);
  100. final String name = cursor.getString(2);
  101. Log.d("cursor val", "name=" + f0 + " , type=" + field_type);
  102. final EditText edit = (EditText) view.findViewById(R.id.edit_val);
  103. edit.setText(hashMap.get(name));
  104. Log.v("from hashmap",
  105. "name=" + name + " , val=" + hashMap.get(name));
  106. // edit.seton
  107. // edit.addTextChangedListener(new TextWatcher()
  108. // {
  109. // @Override
  110. // public void onTextChanged(CharSequence s, int start,
  111. // int before, int count)
  112. // {
  113. //
  114. // }
  115. //
  116. // @Override
  117. // public void beforeTextChanged(CharSequence s, int start,
  118. // int count, int after)
  119. // {
  120. //
  121. // }
  122. //
  123. // @Override
  124. // public void afterTextChanged(Editable s)
  125. // {
  126. // // 将editText中改变的值设置的HashMap中
  127. // String val = s.toString();
  128. // val.trim();
  129. // if (val.length() > 0)
  130. // {
  131. // hashMap.put(name, val);
  132. //
  133. // Log.i("to hashmap", "name=" + name + " , val=" + val);
  134. // }
  135. // }
  136. // });
  137. Switch switch_bool = (Switch) view.findViewById(R.id.switch_bool);
  138. if (field_type.equals("boolean"))
  139. {
  140. edit.setVisibility(View.GONE);
  141. switch_bool.setVisibility(View.VISIBLE);
  142. }
  143. else
  144. {
  145. edit.setVisibility(View.VISIBLE);
  146. switch_bool.setVisibility(View.GONE);
  147. if (field_type.equals("time"))
  148. {
  149. edit.setInputType(InputType.TYPE_DATETIME_VARIATION_DATE
  150. | InputType.TYPE_CLASS_DATETIME);
  151. }
  152. else
  153. if (field_type.equals("int"))
  154. {
  155. edit.setInputType(InputType.TYPE_CLASS_NUMBER);
  156. }
  157. else
  158. {
  159. edit.setInputType(InputType.TYPE_CLASS_TEXT);
  160. }
  161. Log.d("ime debug", "name=" + f0 + " , type=" + field_type
  162. + ", ime=" + edit.getInputType());
  163. }
  164. super.bindView(view, context, cursor);
  165. // TextView tvname = (TextView) view.findViewById(R.id.name);
  166. // TextView tvinfo = (TextView) view.findViewById(R.id.info);
  167. // String sname = cursor.getString(1);
  168. // int iburntype = cursor.getInt(2);
  169. // dbgUtil.Log(Log.INFO, "============>", "BURN TYPE =" +
  170. // iburntype);
  171. // if (sname == null || sname.equals(""))
  172. // tvname.setVisibility(TextView.GONE);
  173. // else
  174. // tvname.setVisibility(View.VISIBLE);
  175. // if (m_Activityinfo.NumberType != dbUtil.NUMBER_TYPE_WHITE
  176. // && iburntype >= 0)
  177. // {
  178. //
  179. // tvinfo.setText(m_arrBurntype[iburntype]);
  180. // tvinfo.setVisibility(View.VISIBLE);
  181. // }
  182. // else
  183. // {
  184. // tvinfo.setVisibility(View.GONE);
  185. // }
  186. }
  187. }
  188. @Override
  189. protected void onDestroy()
  190. {
  191. dbUtil.CloseDB(m_db);
  192. super.onDestroy();
  193. }
  194. @Override
  195. protected void onCreate(Bundle savedInstanceState)
  196. {
  197. super.onCreate(savedInstanceState);
  198. user = ApexTrackingApplication.get_user();
  199. password = ApexTrackingApplication.get_pass();
  200. function_name = getIntent().getStringExtra("function_name");
  201. setContentView(R.layout.activity_search);
  202. m_db = dbUtil.OpenDB(this, null, true);
  203. // m_TextView = (TextView) findViewById(R.id.summarytext);
  204. // m_TextView.setText(getString(m_Activityinfo.TextViewValue));
  205. // m_ListView = (ListView) findViewById(android.R.id.list);
  206. m_cursor = m_db.query("fields_info", new String[] { "aname",
  207. "field_type", "name", "_id" }, "function_name='"
  208. + function_name + "' and user='" + user + "' and behavior="
  209. + Network.BEHAVIOR_SEARCH + " and show = 1", null, null, null,
  210. "priority , aname", null);
  211. startManagingCursor(m_cursor);
  212. m_listadapter = new RecordsAdapter(this,
  213. // Use a template that displays a text view
  214. R.layout.search_lvitem_edit,
  215. // Give the cursor to the list adatper
  216. m_cursor,
  217. // Map the NAME column in the people database to...
  218. new String[] { "aname", "field_type", "name" },
  219. // The "text1" view defined in the XML template
  220. new int[] { R.id.aname, R.id.tv_type });
  221. setListAdapter(m_listadapter);
  222. Button btnok = (Button) findViewById(R.id.btnok);
  223. btnok.setOnClickListener(this);
  224. Button btncancel = (Button) findViewById(R.id.btncancel);
  225. btncancel.setOnClickListener(this);
  226. SharedPreferences RunOnce = getSharedPreferences("Apex", 0);
  227. String vername;
  228. try
  229. {
  230. vername = getPackageManager().getPackageInfo("com.usai.apex", 0).versionName;
  231. boolean bFirstRun = RunOnce.getBoolean("FirstRun" + vername
  232. + "_search", true);
  233. if (bFirstRun&&false)
  234. {
  235. SharedPreferences.Editor editor = RunOnce.edit();
  236. editor.putBoolean("FirstRun" + vername + "_search", false);
  237. // Don't forget to commit your edits!!!
  238. editor.commit();
  239. Intent intent = new Intent();
  240. intent.setClass(this, HelpActivity.class);
  241. intent.putExtra("caller", "search");
  242. startActivity(intent);
  243. }
  244. }
  245. catch (NameNotFoundException e)
  246. {
  247. // TODO Auto-generated catch block
  248. e.printStackTrace();
  249. }
  250. // initlist();
  251. // m_ListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
  252. // m_listadapter = new FieldsAdapter(this, data, resource, from, to);
  253. // m_listadapter = new RecordsAdapter(this,
  254. // // Use a template that displays a text view
  255. // m_iListItemID,
  256. // // Give the cursor to the list adatper
  257. // m_cursor,
  258. // // Map the NAME column in the people database to...
  259. // m_sDispFields,
  260. // // The "text1" view defined in the XML template
  261. // m_iViewIDs);
  262. }
  263. // private void RefreshList()
  264. // {
  265. // // if (dbUtil.isRecordExist(m_db,
  266. // // "user_numberlist","type = "+m_Activityinfo.NumberType))
  267. // // {
  268. // // m_TextView.setVisibility(ListView.INVISIBLE);
  269. // // m_ListView.setVisibility(ListView.VISIBLE);
  270. // //
  271. // // }
  272. // // else
  273. // // {
  274. // // m_TextView.setVisibility(ListView.VISIBLE);
  275. // // m_ListView.setVisibility(ListView.INVISIBLE);
  276. // // }
  277. // hashMap.clear();
  278. // m_cursor.requery();
  279. // }
  280. // private void initlist()
  281. // {
  282. // m_ListView = (ListView) findViewById(android.R.id.list);
  283. // ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String,
  284. // Object>>();
  285. // HashMap<String, Object> map = null;
  286. //
  287. // String[] strings = { "alias", "type", "name" };// Map的key集合数组
  288. // int[] ids = { R.id.aliasName, R.id.tv_type };// 对应布局文件的id
  289. // SimpleAdapter simpleAdapter = new SimpleAdapter(this, list,
  290. // R.layout.search_lvitem_edit, strings, ids);
  291. //
  292. // // listView1.setAdapter(simpleAdapter);//绑定适配器
  293. // setListAdapter(simpleAdapter);
  294. // }
  295. @Override
  296. public boolean onCreateOptionsMenu(Menu menu)
  297. {
  298. // Inflate the menu; this adds items to the action bar if it is present.
  299. getMenuInflater().inflate(R.menu.search, menu);
  300. return true;
  301. }
  302. @Override
  303. public boolean onOptionsItemSelected(MenuItem item)
  304. {
  305. Intent intent = new Intent();
  306. switch (item.getItemId())
  307. {
  308. case R.id.action_custom_fields:
  309. intent.setClass(this, CustomizeFieldsActivity.class);
  310. intent.putExtra("user", user);
  311. // intent.putExtra("password", password);
  312. intent.putExtra("function_name", function_name);
  313. intent.putExtra("behavior", Network.BEHAVIOR_SEARCH);
  314. startActivity(intent);
  315. break;
  316. case R.id.action_help:
  317. // Intent intent = new Intent();
  318. intent.setClass(this, HelpActivity.class);
  319. intent.putExtra("caller", "search");
  320. // // intent.putExtra("password", password);
  321. // intent.putExtra("function_name", function_name);
  322. // intent.putExtra("behavior", Network.BEHAVIOR_SEARCH);
  323. startActivity(intent);
  324. break;
  325. default:
  326. break;
  327. }
  328. return super.onOptionsItemSelected(item);
  329. }
  330. @Override
  331. public void onClick(View v)
  332. {
  333. switch (v.getId())
  334. {
  335. case R.id.btnok:
  336. {
  337. Intent intent = new Intent();
  338. intent.setClass(this, ResultActivity.class);
  339. intent.putExtra("user", user);
  340. intent.putExtra("password", password);
  341. intent.putExtra("function_name", function_name);
  342. Bundle parms = new Bundle();
  343. parms.putString("module_name", function_name);
  344. parms.putString("columns", dbUtil.get_fields(user, function_name));
  345. Iterator<String> iter = hashMap.keySet().iterator();
  346. while (iter.hasNext())
  347. {
  348. String field = (String) iter.next();
  349. String val = (String) hashMap.get(field);
  350. parms.putString(field, val);
  351. // Cursor c = (Cursor) m_listadapter.getItem(key);
  352. Log.d("@@@@@@@@@", field + " : " + val);
  353. }
  354. intent.putExtra("searchParms", parms);
  355. startActivity(intent);
  356. break;
  357. }
  358. case R.id.btncancel:
  359. finish();
  360. break;
  361. default:
  362. break;
  363. }
  364. }
  365. // class FieldsAdapter extends SimpleAdapter
  366. // {
  367. //
  368. // public FieldsAdapter(Context context,
  369. // List<? extends Map<String, ?>> data, int resource,
  370. // String[] from, int[] to)
  371. // {
  372. // super(context, data, resource, from, to);
  373. // // TODO Auto-generated constructor stub
  374. // }
  375. //
  376. // }
  377. }