FunctionSelectActivity.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. package com.usai.apex;
  2. import android.app.ActionBar;
  3. import android.app.Activity;
  4. import android.app.NotificationManager;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.content.SharedPreferences;
  8. import android.database.sqlite.SQLiteDatabase;
  9. import android.os.Bundle;
  10. import android.support.v4.app.FragmentActivity;
  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.view.inputmethod.InputMethodManager;
  17. import android.widget.ArrayAdapter;
  18. import android.widget.AutoCompleteTextView;
  19. import android.widget.Button;
  20. import android.widget.RadioGroup;
  21. import android.widget.RadioGroup.OnCheckedChangeListener;
  22. import android.widget.TextView;
  23. import com.usai.apex.mainframe.NewDetailActivity;
  24. import com.usai.util.dbUtil;
  25. public class FunctionSelectActivity extends FragmentActivity implements
  26. OnClickListener, OnCheckedChangeListener
  27. {
  28. static final int PASSWORD_CHANGED = 1;
  29. private static final int REQUEST_LOGINACTIVITY = 1;
  30. private static final int REQUEST_CHANGEPASSWORD_ACTIVITY = 2;
  31. private static final int REQUEST_TOOLS_ACTIVITY = 3;
  32. ArrayAdapter<String> adapter = null;
  33. @Override
  34. public boolean onOptionsItemSelected(MenuItem item)
  35. {
  36. Intent intent = new Intent();
  37. switch (item.getItemId())
  38. {
  39. case R.id.action_settings:
  40. intent.setClass(this, SettingsActivity.class);
  41. // intent.putExtra("user", user);
  42. // intent.putExtra("password", password);
  43. // intent.putExtra("function_name", function_name);
  44. // intent.putExtra("behavior", Network.BEHAVIOR_SEARCH);
  45. startActivity(intent);
  46. break;
  47. default:
  48. break;
  49. }
  50. return super.onOptionsItemSelected(item);
  51. }
  52. @Override
  53. public boolean onCreateOptionsMenu(Menu menu)
  54. {
  55. // Inflate the menu; this adds items to the action bar if it is present.
  56. getMenuInflater().inflate(R.menu.function_select, menu);
  57. return true;
  58. }
  59. @Override
  60. protected void onCreate(Bundle savedInstanceState)
  61. {
  62. // user = ApexTrackingApplication.get_user();
  63. // password= getIntent().getStringExtra("password");
  64. super.onCreate(savedInstanceState);
  65. setContentView(R.layout.new_function_select);
  66. ActionBar bar = getActionBar();
  67. bar.setTitle("");
  68. //
  69. TextView tv_booking = (TextView) findViewById(R.id.tv_booking);
  70. tv_booking.setOnClickListener(this);
  71. TextView tv_info = (TextView) findViewById(R.id.tv_info);
  72. tv_info.setOnClickListener(this);
  73. TextView tv_detail = (TextView) findViewById(R.id.tv_detail);
  74. tv_detail.setOnClickListener(this);
  75. // TextView tv_cargo = (TextView)findViewById(R.id.tv_cargo);
  76. // tv_cargo.setOnClickListener(this);
  77. TextView tv_doc = (TextView) findViewById(R.id.tv_doc);
  78. tv_doc.setOnClickListener(this);
  79. TextView tv_message = (TextView) findViewById(R.id.tv_message);
  80. tv_message.setOnClickListener(this);
  81. TextView tv_exit = (TextView) findViewById(R.id.tv_exit);
  82. tv_exit.setOnClickListener(this);
  83. TextView tv_loc = (TextView) findViewById(R.id.tv_location);
  84. tv_loc.setOnClickListener(this);
  85. TextView tv_tools = (TextView) findViewById(R.id.tv_tools);
  86. tv_tools.setOnClickListener(this);
  87. Button btn_search = (Button) findViewById(R.id.btn_search);
  88. btn_search.setOnClickListener(this);
  89. Button btn_clear = (Button) findViewById(R.id.btn_clear);
  90. btn_clear.setOnClickListener(this);
  91. RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
  92. rg.setOnCheckedChangeListener(this);
  93. // AutoCompleteTextView et = (AutoCompleteTextView)
  94. // findViewById(R.id.atv_criterion);
  95. // if (rg.getCheckedRadioButtonId() == R.id.radio0)
  96. // adapter = new ArrayAdapter<String>(this,
  97. // android.R.layout.simple_dropdown_item_1line,
  98. // dbUtil.get_searchhistory("h_bol"));
  99. // else
  100. // adapter = new ArrayAdapter<String>(this,
  101. // android.R.layout.simple_dropdown_item_1line,
  102. // dbUtil.get_searchhistory("ctnr"));
  103. // et.setAdapter(adapter);
  104. SharedPreferences pref = ApexTrackingApplication.get_instance()
  105. .getSharedPreferences("Apex", 0);
  106. boolean autologin = pref.getBoolean("autologin", false);
  107. if (!autologin)
  108. {
  109. Intent i = new Intent();
  110. i.setClass(this, ApexActivity.class);
  111. startActivityForResult(i, REQUEST_LOGINACTIVITY);
  112. }
  113. }
  114. @Override
  115. protected void onActivityResult(int requestCode, int resultCode, Intent data)
  116. {
  117. switch (requestCode)
  118. {
  119. case REQUEST_LOGINACTIVITY:
  120. if (resultCode == Activity.RESULT_CANCELED)
  121. finish();
  122. break;
  123. case REQUEST_TOOLS_ACTIVITY:
  124. if (resultCode == PASSWORD_CHANGED)
  125. {
  126. String UNIQUE_STRING = "com.usai.apex.push.cancel";
  127. Intent intent = new Intent(UNIQUE_STRING);
  128. sendBroadcast(intent);
  129. Intent i = new Intent();
  130. i.setClass(this, ApexActivity.class);
  131. startActivityForResult(i, REQUEST_LOGINACTIVITY);
  132. }
  133. break;
  134. default:
  135. break;
  136. }
  137. super.onActivityResult(requestCode, resultCode, data);
  138. }
  139. @Override
  140. protected void onDestroy()
  141. {
  142. // dbUtil.CloseDB(m_db);
  143. super.onDestroy();
  144. }
  145. @Override
  146. public void onClick(View v)
  147. {
  148. switch (v.getId())
  149. {
  150. case R.id.btn_clear:
  151. {
  152. AutoCompleteTextView et = (AutoCompleteTextView) findViewById(R.id.atv_criterion);
  153. et.setText("");
  154. break;
  155. }
  156. case R.id.btn_search:
  157. {
  158. AutoCompleteTextView et = (AutoCompleteTextView) findViewById(R.id.atv_criterion);
  159. // et.clearFocus();
  160. InputMethodManager inputMethodManager = (InputMethodManager) getApplicationContext()
  161. .getSystemService(Context.INPUT_METHOD_SERVICE);
  162. inputMethodManager.hideSoftInputFromWindow(et.getWindowToken(),
  163. 0);
  164. inputMethodManager.hideStatusIcon(et.getWindowToken());
  165. String cargo_criterion = et.getText().toString();
  166. // if (TextUtils.isEmpty(cargo_criterion))
  167. // {
  168. // et.setError(getString(R.string.error_field_required));
  169. // et.requestFocus();
  170. // }
  171. // else
  172. // {
  173. Intent intent = new Intent();
  174. intent.setClass(this, NewDetailActivity.class);
  175. intent.putExtra("action0", "Tracking");
  176. intent.putExtra("function_name", "Cargo Tracking");
  177. intent.putExtra("cargo_criterion", cargo_criterion);
  178. intent.putExtra("actions_count", 1);
  179. intent.putExtra("_id", "dumb");
  180. String h_field;
  181. RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
  182. if (rg.getCheckedRadioButtonId() == R.id.radio0)
  183. {
  184. intent.putExtra("criterion_type", 0);
  185. h_field = "h_bol";
  186. }
  187. else
  188. {
  189. intent.putExtra("criterion_type", 1);
  190. h_field = "ctnr";
  191. }
  192. dbUtil.savehistory(h_field, cargo_criterion);
  193. startActivity(intent);
  194. break;
  195. }
  196. case R.id.tv_booking:
  197. {
  198. Intent intent = new Intent();
  199. intent.setClass(this, SearchListActivity.class);
  200. // intent.putExtra("user", ApexTrackingApplication.get_user());
  201. // intent.putExtra("password", password);
  202. intent.putExtra("function_name", "Ocean Booking");
  203. intent.putExtra("title", "Booking Search");
  204. startActivity(intent);
  205. break;
  206. }
  207. case R.id.tv_info:
  208. {
  209. Intent intent = new Intent();
  210. intent.setClass(this, SearchListActivity.class);
  211. // intent.putExtra("user", user);
  212. // intent.putExtra("password", password);
  213. intent.putExtra("function_name", "Ocean B/L info.");
  214. intent.putExtra("title", "B/L info. Search");
  215. startActivity(intent);
  216. break;
  217. }
  218. case R.id.tv_detail:
  219. {
  220. Intent intent = new Intent();
  221. intent.setClass(this, SearchListActivity.class);
  222. // intent.putExtra("user", user);
  223. // intent.putExtra("password", password);
  224. intent.putExtra("function_name", "Container detail");
  225. intent.putExtra("title", "Container Search");
  226. startActivity(intent);
  227. break;
  228. }
  229. case R.id.tv_doc:
  230. {
  231. Intent intent = new Intent();
  232. intent.setClass(this, DocumentsActivity.class);
  233. // // intent.putExtra("user", user);
  234. // // intent.putExtra("password", password);
  235. // intent.putExtra("function_name", "Download Document");
  236. // intent.putExtra("title", "Document Search");
  237. startActivity(intent);
  238. break;
  239. }
  240. case R.id.tv_message:
  241. {
  242. Intent intent = new Intent();
  243. intent.setClass(this, MessageActivity.class);
  244. startActivity(intent);
  245. //
  246. // Intent intent = new Intent();
  247. // intent.setClass(this, ChangePasswordActivity.class);
  248. // // intent.putExtra("function_name", "Container Detail");
  249. // startActivityForResult(intent,
  250. // REQUEST_CHANGEPASSWORD_ACTIVITY);
  251. break;
  252. }
  253. case R.id.tv_exit:
  254. {
  255. String UNIQUE_STRING = "com.usai.apex.push.cancel";
  256. Intent intent = new Intent(UNIQUE_STRING);
  257. // intent.putExtra("key1", "value1");
  258. // intent.putExtra("key2", "value2");
  259. sendBroadcast(intent);
  260. // ApexTrackingApplication.cancelalarm();
  261. // ApexTrackingApplication.put_password("");
  262. // ApexTrackingApplication.put_sessionid("");
  263. // ApexTrackingApplication.put_user("");
  264. Intent i = new Intent();
  265. i.setClass(this, ApexActivity.class);
  266. startActivityForResult(i, 1);
  267. // finish();
  268. // System.exit(0);
  269. break;
  270. }
  271. case R.id.tv_tools:
  272. {
  273. Intent intent = new Intent();
  274. intent.setClass(this, InnerToolsActivity.class);
  275. intent.putExtra("launcher", "inner");
  276. startActivityForResult(intent,REQUEST_TOOLS_ACTIVITY);
  277. break;
  278. }
  279. case R.id.tv_location:
  280. {
  281. Log.d("==============", "start location activity");
  282. Intent intent = new Intent();
  283. intent.setClass(this, InnerMapActivity.class);
  284. // intent.putExtra("user", user);
  285. // intent.putExtra("password", password);
  286. // intent.putExtra("function_name", "Container Detail");
  287. startActivity(intent);
  288. break;
  289. }
  290. default:
  291. break;
  292. }
  293. // TODO Auto-generated method stub
  294. }
  295. // class HistoryAdapter extends SimpleCursorAdapter{
  296. //
  297. // public HistoryAdapter(Context context, int layout, Cursor c,
  298. // String[] from, int[] to)
  299. // {
  300. // super(context, layout, c, from, to,FLAG_AUTO_REQUERY);
  301. // // TODO Auto-generated constructor stub
  302. // }
  303. //
  304. // }
  305. @Override
  306. protected void onResume()
  307. {
  308. SQLiteDatabase db = dbUtil.OpenDB(this, null, false);
  309. int count = dbUtil.get_count(db, "push_message", "read = 0 and user = '"+ApexTrackingApplication.get_user()+"'");
  310. dbUtil.CloseDB(db);
  311. NotificationManager nManager = (NotificationManager) this
  312. .getSystemService(Context.NOTIFICATION_SERVICE);
  313. nManager.cancel(R.layout.activity_apex);
  314. ApexTrackingApplication.ncount=1;
  315. // Intent intent = new Intent();
  316. // intent.setClass(ApexTrackingApplication
  317. // .get_instance(), FunctionSelectActivity.class);
  318. // Intent addShortcut = new Intent(
  319. // "com.android.launcher.action.INSTALL_SHORTCUT");
  320. // Parcelable icon = Intent.ShortcutIconResource.fromContext(this,
  321. // R.drawable.ic_launcher);
  322. // addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
  323. // getString(R.string.app_name));
  324. // addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
  325. // addShortcut.putExtra("duplicate", 0);
  326. // addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
  327. // Log.e("uuuuuuuuuuuuuuuurrrrrrrrrrrrrriiiiiiiii",
  328. // intent.toUri(MODE_WORLD_WRITEABLE));
  329. // sendBroadcast(addShortcut);
  330. if (count > 0)
  331. {
  332. TextView tv_message = (TextView) findViewById(R.id.tv_message);
  333. tv_message.setCompoundDrawablesWithIntrinsicBounds(0,
  334. R.drawable.ic_message_new, 0, 0);
  335. }
  336. else
  337. {
  338. TextView tv_message = (TextView) findViewById(R.id.tv_message);
  339. tv_message.setCompoundDrawablesWithIntrinsicBounds(0,
  340. R.drawable.ic_message, 0, 0);
  341. }
  342. RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
  343. AutoCompleteTextView et = (AutoCompleteTextView) findViewById(R.id.atv_criterion);
  344. if (rg.getCheckedRadioButtonId() == R.id.radio0)
  345. adapter = new ArrayAdapter<String>(this,
  346. android.R.layout.simple_dropdown_item_1line,
  347. dbUtil.get_searchhistory("h_bol"));
  348. else
  349. adapter = new ArrayAdapter<String>(this,
  350. android.R.layout.simple_dropdown_item_1line,
  351. dbUtil.get_searchhistory("ctnr"));
  352. et.setAdapter(adapter);
  353. super.onResume();
  354. }
  355. @Override
  356. public void onCheckedChanged(RadioGroup group, int checkedId)
  357. {
  358. AutoCompleteTextView et = (AutoCompleteTextView) findViewById(R.id.atv_criterion);
  359. if (checkedId == R.id.radio0)
  360. adapter = new ArrayAdapter<String>(this,
  361. android.R.layout.simple_dropdown_item_1line,
  362. dbUtil.get_searchhistory("h_bol"));
  363. else
  364. adapter = new ArrayAdapter<String>(this,
  365. android.R.layout.simple_dropdown_item_1line,
  366. dbUtil.get_searchhistory("ctnr"));
  367. et.setAdapter(adapter);
  368. }
  369. }