FunctionSelectActivity.java 13 KB

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