ResultActivity.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. package com.usai.apex;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.Set;
  5. import org.json.JSONException;
  6. import org.json.JSONObject;
  7. import com.usai.util.Network;
  8. import com.usai.util.dbUtil;
  9. import android.net.Uri;
  10. import android.os.AsyncTask;
  11. import android.os.Build;
  12. import android.os.Bundle;
  13. import android.animation.Animator;
  14. import android.animation.AnimatorListenerAdapter;
  15. import android.app.Activity;
  16. import android.app.AlertDialog;
  17. import android.app.Dialog;
  18. import android.app.DownloadManager;
  19. import android.app.AlertDialog.Builder;
  20. import android.app.DownloadManager.Request;
  21. import android.content.DialogInterface;
  22. import android.content.Intent;
  23. import android.content.SharedPreferences;
  24. import android.content.pm.PackageManager.NameNotFoundException;
  25. import android.database.Cursor;
  26. import android.database.sqlite.SQLiteDatabase;
  27. import android.text.Html;
  28. import android.text.style.URLSpan;
  29. import android.util.Log;
  30. import android.util.SparseArray;
  31. import android.view.ContextMenu;
  32. import android.view.Gravity;
  33. import android.view.Menu;
  34. import android.view.MenuItem;
  35. import android.view.View;
  36. import android.view.ContextMenu.ContextMenuInfo;
  37. import android.view.View.OnClickListener;
  38. import android.view.View.OnCreateContextMenuListener;
  39. import android.widget.Button;
  40. import android.widget.EditText;
  41. import android.widget.LinearLayout;
  42. import android.widget.TableLayout;
  43. import android.widget.TableRow;
  44. import android.widget.TextView;
  45. import android.widget.Toast;
  46. public class ResultActivity extends Activity
  47. {
  48. private static final int REQUEST_LOGINACTIVITY = 1;
  49. String user = null;
  50. String password = null;
  51. String function_name = null;
  52. private SearchTask m_task = null;
  53. final int OFFSET = 5;
  54. int sel = -1;
  55. Bundle searchParms = null;
  56. SearchResult searchresult = new SearchResult();
  57. SparseArray<String> showfieldmap = new SparseArray<String>();
  58. // HashMap<Integer, String> showfieldmap = new HashMap<Integer, String>();
  59. private TextView mStatusMessageView;
  60. // private View mSearchFormView;
  61. private View footview;
  62. private View mStatusView;
  63. int actioncount = 0;
  64. // private class resultAdapter extends SimpleAdapter
  65. // {
  66. //
  67. //
  68. // }
  69. @Override
  70. protected void onCreate(Bundle savedInstanceState)
  71. {
  72. user = ApexTrackingApplication.get_user();
  73. password = ApexTrackingApplication.get_pass();
  74. function_name = getIntent().getStringExtra("function_name");
  75. if (function_name.equals("Ocean Booking"))
  76. setTitle("Booking Result");
  77. else if (function_name.equals("Ocean B/L info."))
  78. setTitle("B/L info. Result");
  79. else if (function_name.equals("Container detail"))
  80. setTitle("Container Result");
  81. else if (function_name.equals("Download Document"))
  82. setTitle("Document Result");
  83. searchParms = getIntent().getBundleExtra("searchParms");
  84. super.onCreate(savedInstanceState);
  85. setContentView(R.layout.activity_result);
  86. SQLiteDatabase db = dbUtil.OpenDB(ResultActivity.this, null, false);
  87. Cursor cursor = db
  88. .query("actions_info", new String[] { "count(*)" },
  89. "function_name='" + function_name + "' and user='"
  90. + user + "'", null, null, null, "priority",
  91. null);
  92. if (cursor.moveToNext())
  93. {
  94. actioncount = cursor.getInt(0);
  95. }
  96. dbUtil.CloseCursor(cursor);
  97. dbUtil.CloseDB(db);
  98. footview = findViewById(R.id.foot);
  99. // mSearchFormView = findViewById(R.id.search_form);
  100. Button btnnext = (Button) findViewById(R.id.btn_next);
  101. btnnext.setOnClickListener(new View.OnClickListener()
  102. {
  103. @Override
  104. public void onClick(View v)
  105. {
  106. // TextView tv_head = (TextView) findViewById(R.id.tv_head);
  107. // searchresult.set_direction(1);
  108. if (searchresult.get_totalcount() == -1)
  109. requestdata(true);
  110. else
  111. {
  112. // if (searchresult.get_direction() == -1)
  113. searchresult.set_offset(searchresult.get_offset() + OFFSET);
  114. requestdata(false);
  115. }
  116. }
  117. });
  118. Button btnpre = (Button) findViewById(R.id.btn_pre);
  119. btnpre.setOnClickListener(new View.OnClickListener()
  120. {
  121. @Override
  122. public void onClick(View v)
  123. {
  124. // TextView tv_head = (TextView) findViewById(R.id.tv_head);
  125. // searchresult.set_direction(-1);
  126. if (searchresult.get_totalcount() == -1)
  127. requestdata(true);
  128. else
  129. {
  130. searchresult.set_offset(searchresult.get_offset() - OFFSET);
  131. requestdata(false);
  132. }
  133. }
  134. });
  135. mStatusView = findViewById(R.id.status);
  136. mStatusMessageView = (TextView) findViewById(R.id.status_message);
  137. LinearLayout ll = (LinearLayout) findViewById(R.id.ll_refresh);
  138. Button btn_refresh = (Button) ll.findViewById(R.id.btn_refresh);
  139. btn_refresh.setOnClickListener(new View.OnClickListener()
  140. {
  141. @Override
  142. public void onClick(View v)
  143. {
  144. LinearLayout ll = (LinearLayout) findViewById(R.id.ll_refresh);
  145. ll.setVisibility(View.INVISIBLE);
  146. if (searchresult.get_totalcount() == -1)
  147. requestdata(true);
  148. else
  149. requestdata(false);
  150. }
  151. });
  152. SharedPreferences RunOnce = getSharedPreferences("Apex", 0);
  153. String vername;
  154. try
  155. {
  156. vername = getPackageManager().getPackageInfo("com.usai.apex", 0).versionName;
  157. boolean bFirstRun = RunOnce.getBoolean("FirstRun" + vername
  158. + "_result", true);
  159. if (bFirstRun)
  160. {
  161. SharedPreferences.Editor editor = RunOnce.edit();
  162. editor.putBoolean("FirstRun" + vername + "_result", false);
  163. // Don't forget to commit your edits!!!
  164. editor.commit();
  165. Intent intent = new Intent();
  166. intent.setClass(this, HelpActivity.class);
  167. intent.putExtra("caller", "result");
  168. startActivity(intent);
  169. }
  170. }
  171. catch (NameNotFoundException e)
  172. {
  173. // TODO Auto-generated catch block
  174. e.printStackTrace();
  175. }
  176. initTableHeader();
  177. if (savedInstanceState != null)
  178. {
  179. searchresult = (SearchResult) savedInstanceState
  180. .getSerializable("searchresult");
  181. if (searchresult.get_totalcount() == -1)
  182. requestdata(true);
  183. else
  184. initTable();
  185. }
  186. else
  187. requestdata(true);
  188. }
  189. @Override
  190. protected void onDestroy()
  191. {
  192. if (m_task != null)
  193. m_task.cancel(false);
  194. super.onDestroy();
  195. }
  196. private void initTable()
  197. {
  198. // int loadcount = searchresult.get_count();
  199. int totalcount = searchresult.get_totalcount();
  200. TextView tv_head = (TextView) findViewById(R.id.head);
  201. if (totalcount == 0)
  202. {
  203. tv_head.setText(R.string.str_0);
  204. return;
  205. }
  206. else if (searchresult.get_totalcount() > 2000)
  207. {
  208. tv_head.setText(R.string.str_2000);
  209. }
  210. else
  211. tv_head.setText(/*
  212. * loadcount + "/" + //
  213. */searchresult.get_totalcount()
  214. + getText(R.string.str_records).toString());
  215. TableLayout tl = (TableLayout) findViewById(R.id.result_table);
  216. tl.removeViews(1, tl.getChildCount() - 1);
  217. // int newcount = loadcount - showcount + 1;// +1 header row
  218. for (int i = 0; i < searchresult.get_recordscount(); i++)
  219. {
  220. TableRow recordRow = new TableRow(ResultActivity.this);
  221. recordRow.setOnLongClickListener(new View.OnLongClickListener()
  222. {
  223. @Override
  224. public boolean onLongClick(View v)
  225. {
  226. // TODO Auto-generated method stub
  227. // v.setBackgroundColor(Color.GRAY);
  228. // v.showContextMenu();
  229. // return true;
  230. TableRow tr = (TableRow) v;
  231. TextView tvno = (TextView) tr.getChildAt(0);
  232. sel = (Integer.parseInt(tvno.getText().toString())-1) % 5 ;
  233. registerForContextMenu(v);
  234. openContextMenu(v);
  235. unregisterForContextMenu(v);
  236. return true;
  237. }
  238. });
  239. // registerForContextMenu(recordRow);
  240. // recordRow.setClickable(true);
  241. // registerForContextMenu(recordRow);
  242. // recordRow.setOnCreateContextMenuListener(m_tableMenu);
  243. // recordRow.SETSE
  244. HashMap<String, String> record = searchresult.get_record(i);
  245. TextView field = new TextView(ResultActivity.this);
  246. field.setBackgroundResource(R.drawable.tableitem);
  247. field.setText(searchresult.get_offset() + i + 1 + "");
  248. Log.d("offset=" + searchresult.get_offset(), "");
  249. field.setGravity(Gravity.CENTER);
  250. field.setPadding(10, 5, 10, 5);
  251. field.setTextSize(20);
  252. recordRow.addView(field);
  253. for (int j = 0; j < showfieldmap.size(); j++)
  254. {
  255. TextView field1 = new TextView(ResultActivity.this);
  256. // Log.d("onPostExecute", showfieldmap.get(j));
  257. String str = record.get(showfieldmap.get(j));
  258. field1.setBackgroundResource(R.drawable.tableitem);
  259. if (str.toLowerCase().trim().equals("null"))
  260. str = "";
  261. // field1.setBackgroundColor(0xFFFFFFFF);
  262. field1.setText(Html.fromHtml(str));
  263. if (actioncount == 0)
  264. field1.setOnClickListener(new OnClickListener()
  265. {
  266. @Override
  267. public void onClick(View v)
  268. {
  269. // if (true)
  270. // return;
  271. URLSpan span[] = ((TextView) v).getUrls();
  272. if (span.length < 1)
  273. return;
  274. span[0].getURL();
  275. Log.d("Text", span[0].getURL());
  276. TextView tv = (TextView)v;
  277. final DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
  278. Uri uri = Uri.parse(span[0].getURL());
  279. final Request request = new Request(uri);
  280. // 设置允许使用的网络类型,这里是移动网络和wifi都可以
  281. request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE
  282. | DownloadManager.Request.NETWORK_WIFI);
  283. request.setDestinationInExternalPublicDir("Apex Mobile",tv.getText().toString());
  284. // 禁止发出通知,既后台下载,如果要使用这一句必须声明一个权限:android.permission.DOWNLOAD_WITHOUT_NOTIFICATION
  285. // request.setShowRunningNotification(false);
  286. // 不显示下载界面
  287. request.setVisibleInDownloadsUi(false);
  288. request.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
  289. /*
  290. * 设置下载后文件存放的位置,如果sdcard不可用,那么设置这个将报错,
  291. * 因此最好不设置如果sdcard可用,下载后的文件 在/mnt/sdcard/Android/
  292. * data/packageName/files目录下面
  293. * ,如果sdcard不可用,设置了下面这个将报错,不设置,下载后的文件在/cache这个 目录下面
  294. */
  295. // request.setDestinationInExternalFilesDir(this,
  296. // null, "tar.apk");
  297. AlertDialog.Builder builder = new Builder(
  298. ResultActivity.this);
  299. builder.setMessage(getString(R.string.str_downloadmessage));
  300. builder.setTitle(getString(R.string.str_confirmdownload));
  301. builder.setPositiveButton(
  302. getString(R.string.str_download),
  303. new Dialog.OnClickListener()
  304. {
  305. @Override
  306. public void onClick(
  307. DialogInterface dialog,
  308. int which)
  309. {
  310. downloadManager.enqueue(request);
  311. dialog.dismiss();
  312. }
  313. });
  314. builder.setNegativeButton(
  315. getString(R.string.str_cancel),
  316. new Dialog.OnClickListener()
  317. {
  318. @Override
  319. public void onClick(
  320. DialogInterface dialog,
  321. int which)
  322. {
  323. dialog.dismiss();
  324. }
  325. });
  326. builder.create().show();
  327. }
  328. });
  329. // field1.setText(str);
  330. field1.setGravity(Gravity.LEFT);
  331. field1.setPadding(10, 5, 10, 5);
  332. field1.setTextSize(20);
  333. // field.setTextAppearance(ResultActivity.this,
  334. // android.R.attr.textAppearanceMedium);
  335. recordRow.addView(field1);
  336. }
  337. tl.addView(recordRow);
  338. }
  339. Button btnnext = (Button) findViewById(R.id.btn_next);
  340. Button btnpre = (Button) findViewById(R.id.btn_pre);
  341. if (searchresult.get_offset() == 0)
  342. btnpre.setEnabled(false);
  343. else
  344. {
  345. btnpre.setEnabled(true);
  346. }
  347. if ((searchresult.get_totalcount() - searchresult.get_offset() <= OFFSET)
  348. || (searchresult.get_totalcount() == 0))
  349. btnnext.setEnabled(false);
  350. else
  351. btnnext.setEnabled(true);
  352. }
  353. private OnCreateContextMenuListener m_tableMenu = new OnCreateContextMenuListener()
  354. {
  355. @Override
  356. public void onCreateContextMenu(
  357. ContextMenu contextmenu,
  358. View view,
  359. ContextMenuInfo contextmenuinfo)
  360. {
  361. contextmenu
  362. .add(Menu.NONE,
  363. 0,
  364. 0,
  365. getString(R.string.str_detail));
  366. }
  367. };
  368. @Override
  369. public boolean onContextItemSelected(MenuItem item)
  370. {
  371. // menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
  372. // Log.d("table row select", sel+ "");
  373. Intent intent = new Intent();
  374. intent.setClass(this, DetailActivity.class);
  375. SQLiteDatabase db = dbUtil.OpenDB(this, null, false);
  376. Cursor cursor = db.query("actions_info",
  377. new String[] { "name", "_id" }, "function_name='"
  378. + function_name + "' and user='" + user + "'", null,
  379. null, null, "priority", null);
  380. int i = 0;
  381. while (cursor.moveToNext())
  382. {
  383. String name = cursor.getString(0);
  384. Log.d("actionname", name);
  385. intent.putExtra("action" + i, name);
  386. i++;
  387. }
  388. intent.putExtra("function_name", function_name);
  389. intent.putExtra("actions_count", i);
  390. intent.putExtra("_id", searchresult.get_record(sel).get("_id")
  391. .toString());
  392. dbUtil.CloseCursor(cursor);
  393. dbUtil.CloseDB(db);
  394. startActivity(intent);
  395. return super.onContextItemSelected(item);
  396. }
  397. // @Override
  398. // public void onCreateContextMenu(ContextMenu menu, View v,
  399. // ContextMenuInfo menuInfo)
  400. // {
  401. // // // TODO Auto-generated method stub
  402. // menu.add(Menu.NONE, 0, 0, "Detail");
  403. // // // contextmenu.add(Menu.NONE, 1, 1, "�༭");
  404. // super.onCreateContextMenu(menu, v, menuInfo);
  405. // }
  406. void initTableHeader()
  407. {
  408. TableLayout tl = (TableLayout) findViewById(R.id.result_table);
  409. tl.setFocusable(true);
  410. tl.setOnCreateContextMenuListener(m_tableMenu);
  411. SQLiteDatabase db = dbUtil.OpenDB(this, null, false);
  412. Cursor cursor = db.query("fields_info", new String[] { "aname", "name",
  413. "_id" }, "function_name='" + function_name + "' and user='"
  414. + user + "' and behavior=" + Network.BEHAVIOR_RESULT
  415. + " and show = 1", null, null, null, "priority , aname", null);
  416. TableRow headerRow = (TableRow) findViewById(R.id.tr_header);
  417. int pos = 0;
  418. showfieldmap.clear();
  419. headerRow.removeAllViews();
  420. ArrayList<HashMap<String, String>> gridheader = new ArrayList<HashMap<String, String>>();
  421. HashMap<String, String> map = new HashMap<String, String>();
  422. map.put("key", "no.");
  423. gridheader.add(map);
  424. Button btn = new Button(this);
  425. btn.setBackgroundResource(R.drawable.tablehead);
  426. btn.setPadding(0, 0, 0, 0);
  427. btn.setText("No.");
  428. headerRow.addView(btn);
  429. while (cursor.moveToNext())
  430. {
  431. String aname = cursor.getString(0);
  432. Button btn1 = new Button(this);
  433. btn1.setBackgroundResource(R.drawable.tablehead);
  434. btn1.setText(aname);
  435. headerRow.addView(btn1);
  436. showfieldmap.put(pos, cursor.getString(1));
  437. map.put("key", "header");
  438. gridheader.add(map);
  439. pos++;
  440. }
  441. dbUtil.CloseCursor(cursor);
  442. dbUtil.CloseDB(db);
  443. // SimpleAdapter adapter = new SimpleAdapter(this,
  444. // gridheader,// �����Դ
  445. // R.layout.result_item,//XMLʵ��
  446. // new String[] { "key" }, // ��̬������ImageItem��Ӧ������
  447. // new int[] { R.id.tv_value });
  448. //
  449. // GridView gridview = (GridView) findViewById(R.id.grid_result);
  450. // gridview.setNumColumns(2);
  451. // gridview.setAdapter(adapter);
  452. }
  453. @Override
  454. public boolean onCreateOptionsMenu(Menu menu)
  455. {
  456. // Inflate the menu; this adds items to the action bar if it is present.
  457. getMenuInflater().inflate(R.menu.result, menu);
  458. return true;
  459. }
  460. @Override
  461. public boolean onOptionsItemSelected(MenuItem item)
  462. {
  463. Intent intent = new Intent();
  464. switch (item.getItemId())
  465. {
  466. case R.id.action_custom_fields:
  467. intent.setClass(this, CustomizeFieldsActivity.class);
  468. intent.putExtra("user", user);
  469. // intent.putExtra("password", password);
  470. intent.putExtra("function_name", function_name);
  471. intent.putExtra("behavior", Network.BEHAVIOR_RESULT);
  472. startActivity(intent);
  473. break;
  474. case R.id.action_help:
  475. // Intent intent = new Intent();
  476. intent.setClass(this, HelpActivity.class);
  477. intent.putExtra("caller", "result");
  478. // // intent.putExtra("password", password);
  479. // intent.putExtra("function_name", function_name);
  480. // intent.putExtra("behavior", Network.BEHAVIOR_SEARCH);
  481. startActivity(intent);
  482. break;
  483. case R.id.action_save_search:
  484. // LayoutInflater factory = LayoutInflater.from(this);
  485. // final View textEntryView =
  486. // factory.inflate(R.layout.alert_dialog_text_entry, null);
  487. final View edit = new EditText(this);
  488. new AlertDialog.Builder(this)
  489. .setIconAttribute(android.R.attr.alertDialogIcon)
  490. .setTitle(R.string.str_createname)
  491. .setView(edit)
  492. .setPositiveButton(android.R.string.ok,
  493. new DialogInterface.OnClickListener()
  494. {
  495. public void onClick(DialogInterface dialog,
  496. int whichButton)
  497. {
  498. String name = ((EditText) edit)
  499. .getText().toString();
  500. String param = getIntent().toUri(0);
  501. JSONObject obj = new JSONObject();
  502. Set<String> keys = searchParms.keySet();
  503. for (String key : keys)
  504. {
  505. try
  506. {
  507. obj.put(key, searchParms.get(key).toString());
  508. }
  509. catch (JSONException e)
  510. {
  511. // TODO Auto-generated catch block
  512. e.printStackTrace();
  513. }
  514. }
  515. obj.toString();
  516. SQLiteDatabase db = dbUtil.OpenDB(
  517. ApexTrackingApplication.get_instance(), null, true);
  518. db.execSQL("insert into history(params,name,criterion,module_name,user,create_time) values('"
  519. + param
  520. + "','"
  521. + name
  522. + "','"
  523. + obj.toString()
  524. + "','"
  525. + function_name
  526. + "','"
  527. + ApexTrackingApplication.get_user()
  528. + "',"
  529. + System.currentTimeMillis() + ")");
  530. dbUtil.CloseDB(db);
  531. /* User clicked OK so do some stuff */
  532. }
  533. })
  534. .setNegativeButton(android.R.string.cancel,
  535. new DialogInterface.OnClickListener()
  536. {
  537. public void onClick(DialogInterface dialog,
  538. int whichButton)
  539. {
  540. /* User clicked cancel so do some stuff */
  541. }
  542. }).create().show();
  543. break;
  544. default:
  545. break;
  546. }
  547. return super.onOptionsItemSelected(item);
  548. }
  549. public void requestdata(boolean requestcount)
  550. {
  551. if (m_task != null)
  552. {
  553. return;
  554. }
  555. mStatusMessageView.setText(R.string.str_Loading);
  556. showProgress(true);
  557. m_task = new SearchTask();
  558. m_task.execute(requestcount);
  559. }
  560. private void showProgress(final boolean show)
  561. {
  562. // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
  563. // for very easy animations. If available, use these APIs to fade-in
  564. // the progress spinner.
  565. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
  566. {
  567. int shortAnimTime = getResources().getInteger(
  568. android.R.integer.config_shortAnimTime);
  569. mStatusView.setVisibility(View.VISIBLE);
  570. mStatusView.animate().setDuration(shortAnimTime)
  571. .alpha(show ? 1 : 0)
  572. .setListener(new AnimatorListenerAdapter()
  573. {
  574. @Override
  575. public void onAnimationEnd(Animator animation)
  576. {
  577. mStatusView.setVisibility(show ? View.VISIBLE
  578. : View.INVISIBLE);
  579. }
  580. });
  581. footview.setVisibility(View.VISIBLE);
  582. footview.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
  583. .setListener(new AnimatorListenerAdapter()
  584. {
  585. @Override
  586. public void onAnimationEnd(Animator animation)
  587. {
  588. footview.setVisibility(show ? View.INVISIBLE
  589. : View.VISIBLE);
  590. }
  591. });
  592. // mSearchFormView.setVisibility(View.VISIBLE);
  593. // mSearchFormView.animate().setDuration(shortAnimTime)
  594. // .alpha(show ? 0 : 1)
  595. // .setListener(new AnimatorListenerAdapter()
  596. // {
  597. // @Override
  598. // public void onAnimationEnd(Animator animation)
  599. // {
  600. // mSearchFormView.setVisibility(show ? View.INVISIBLE
  601. // : View.VISIBLE);
  602. // }
  603. // });
  604. }
  605. else
  606. {
  607. // The ViewPropertyAnimator APIs are not available, so simply show
  608. // and hide the relevant UI components.
  609. mStatusView.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
  610. footview.setVisibility(show ? View.INVISIBLE : View.VISIBLE);
  611. // mSearchFormView.setVisibility(show ? View.INVISIBLE :
  612. // View.VISIBLE);
  613. }
  614. }
  615. public class SearchTask extends AsyncTask<Boolean, Void, Boolean>
  616. {
  617. // int err_code = ERR_CODE_NONE;
  618. int errorcode;
  619. @Override
  620. protected Boolean doInBackground(Boolean... params)
  621. {
  622. if (!Network.NetworkIsAvailable())
  623. {
  624. errorcode = Network.RESULT_NET_NOTAVAILABLE;
  625. return false;
  626. }
  627. if (params[0])
  628. {
  629. int ret = Network.get_recordcount(searchParms);
  630. if (ret >= 0)
  631. {
  632. searchresult.put_totalcount(ret);
  633. if (ret == 0)
  634. return true;
  635. }
  636. else
  637. {
  638. errorcode = ret;
  639. return false;
  640. }
  641. }
  642. // if (searchresult.get_direction() == -1)
  643. // searchresult.set_offset(searchresult.get_offset() - 20);
  644. searchParms.putString("offset", searchresult.get_offset() + "");
  645. String jstr = Network.get_records(user, password, searchParms);
  646. if (jstr == null || jstr.length() <= 0)
  647. {
  648. // Log.d(TAG, "json is wrong");
  649. errorcode = Network.RESULT_NET_ERROR;
  650. return false;
  651. }
  652. JSONObject jsobj;
  653. //
  654. // array = new JSONArray(json);
  655. try
  656. {
  657. jsobj = new JSONObject(jstr);
  658. // if (searchresult.get_fieldscount() == 0)
  659. // {
  660. // JSONObject objfields = jsobj.getJSONObject("fields");
  661. // if (objfields != null)
  662. // searchresult.init_fields(objfields.toString());
  663. // }
  664. JSONObject objrecords = jsobj.getJSONObject("records");
  665. if (objrecords != null)
  666. searchresult.add_records(objrecords.toString());
  667. errorcode = Network.RESULT_TRUE;
  668. return true;
  669. }
  670. catch (JSONException e)
  671. {
  672. // TODO Auto-generated catch block
  673. e.printStackTrace();
  674. }
  675. errorcode = Network.RESULT_NET_ERROR;
  676. return false;
  677. }
  678. @Override
  679. protected void onPostExecute(final Boolean success)
  680. {
  681. Log.d("onPostExecute", "entry");
  682. m_task = null;
  683. showProgress(false);
  684. if (ApexTrackingApplication.get_authorization() == false)
  685. {
  686. LinearLayout ll = (LinearLayout) findViewById(R.id.ll_refresh);
  687. ll.setVisibility(View.VISIBLE);
  688. Toast toast = Toast.makeText(
  689. ApexTrackingApplication.get_instance(),
  690. getText(R.string.msg_net_passwordchangedremote),
  691. Toast.LENGTH_LONG);
  692. toast.setGravity(Gravity.CENTER, 0, 0);
  693. toast.show();
  694. Intent i = new Intent();
  695. i.setClass(ResultActivity.this, ApexActivity.class);
  696. startActivityForResult(i, REQUEST_LOGINACTIVITY);
  697. return;
  698. }
  699. switch (errorcode)
  700. {
  701. case Network.RESULT_NET_NOTAVAILABLE:
  702. {
  703. Toast toast = Toast.makeText(getApplicationContext(),
  704. getText(R.string.msg_connection_none),
  705. Toast.LENGTH_LONG);
  706. toast.setGravity(Gravity.CENTER, 0, 0);
  707. toast.show();
  708. break;
  709. }
  710. case Network.RESULT_NET_ERROR:
  711. {
  712. Toast toast = Toast.makeText(
  713. ApexTrackingApplication.get_instance(),
  714. getText(R.string.msg_net_resulterror) + ":"
  715. + errorcode, Toast.LENGTH_LONG);
  716. toast.setGravity(Gravity.CENTER, 0, 0);
  717. toast.show();
  718. break;
  719. }
  720. case Network.RESULT_ERROR:
  721. // case Network.RESULT_RESPONSE_NULL:
  722. {
  723. Toast toast = Toast.makeText(getApplicationContext(),
  724. getText(R.string.msg_net_resulterror),
  725. Toast.LENGTH_LONG);
  726. toast.setGravity(Gravity.CENTER, 0, 0);
  727. toast.show();
  728. break;
  729. }
  730. default:
  731. break;
  732. }
  733. if (success)
  734. {
  735. initTable();
  736. }
  737. else
  738. {
  739. LinearLayout ll = (LinearLayout) findViewById(R.id.ll_refresh);
  740. ll.setVisibility(View.VISIBLE);
  741. }
  742. }
  743. @Override
  744. protected void onCancelled()
  745. {
  746. m_task = null;
  747. showProgress(false);
  748. }
  749. }
  750. @Override
  751. protected void onSaveInstanceState(Bundle outState)
  752. {
  753. outState.putSerializable("searchresult", searchresult);
  754. super.onSaveInstanceState(outState);
  755. }
  756. }