ContainerSearchActivity.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package com.usai.apex;
  2. import android.content.Context;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.support.v7.app.ActionBar;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.view.Gravity;
  8. import android.view.KeyEvent;
  9. import android.view.LayoutInflater;
  10. import android.view.MenuItem;
  11. import android.view.View;
  12. import android.view.inputmethod.EditorInfo;
  13. import android.view.inputmethod.InputMethodManager;
  14. import android.widget.AutoCompleteTextView;
  15. import android.widget.Button;
  16. import android.widget.TextView;
  17. import com.usai.apex.mainframe.NewDetailActivity;
  18. import com.usai.util.dbUtil;
  19. public class ContainerSearchActivity extends AppCompatActivity {
  20. private SegmentView mSegmentView;
  21. private AutoCompleteTextView searchField;
  22. private Button cancelBtn;
  23. @Override
  24. protected void onCreate(Bundle savedInstanceState) {
  25. super.onCreate(savedInstanceState);
  26. setContentView(R.layout.activity_container_search);
  27. cancelBtn = findViewById(R.id.button2);
  28. searchField = findViewById(R.id.atv_criterion2);
  29. cancelBtn.setOnClickListener(new View.OnClickListener() {
  30. @Override
  31. public void onClick(View view) {
  32. searchContainer();
  33. searchField.clearFocus();
  34. InputMethodManager inputMethodManager = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
  35. inputMethodManager.hideSoftInputFromWindow(searchField.getWindowToken(),0);
  36. inputMethodManager.hideStatusIcon(searchField.getWindowToken());
  37. }
  38. });
  39. searchField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
  40. @Override
  41. public boolean onEditorAction(TextView textView, int i, KeyEvent event) {
  42. // 当actionId == XX_SEND 或者 XX_DONE时都触发
  43. // 或者event.getKeyCode == ENTER 且 event.getAction == ACTION_DOWN时也触发
  44. // 注意,这是一定要判断event != null。因为在某些输入法上会返回null。
  45. if (i == EditorInfo.IME_ACTION_SEND || i == EditorInfo.IME_ACTION_DONE || (event != null && KeyEvent.KEYCODE_ENTER == event.getKeyCode() && KeyEvent.ACTION_DOWN == event.getAction())) {
  46. searchContainer();
  47. }
  48. return false;
  49. }
  50. });
  51. setCustomActionBar();
  52. }
  53. private void setCustomActionBar() {
  54. ActionBar.LayoutParams lp =new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
  55. View mActionBarVie = LayoutInflater.from(this).inflate(R.layout.actionbar_segmentview, null);
  56. mSegmentView = mActionBarVie.findViewById(R.id.segmentview);
  57. //
  58. // mSegmentView.setOnSegmentViewClickListener(new SegmentView.onSegmentViewClickListener() {
  59. // @Override
  60. // public void onSegmentViewClick(View view, int postion) {
  61. // switch (postion) {
  62. // case 0:
  63. // Toast.makeText(ContainerSearchActivity.this, "点击了消息" + postion,
  64. // Toast.LENGTH_SHORT).show();
  65. // break;
  66. // case 1:
  67. // Toast.makeText(ContainerSearchActivity.this, "点击了电话" + postion,
  68. // Toast.LENGTH_SHORT).show();
  69. // break;
  70. // default:
  71. // break;
  72. // }
  73. // }
  74. // });
  75. // TextView titleview = mActionBarView.findViewById(R.id.title);
  76. // titleview.setText(getIntent().getStringExtra("title"));
  77. //
  78. // mActionBarView.setBackgroundColor(Color.YELLOW);
  79. // titleview.setBackgroundColor(Color.BLUE);
  80. ActionBar actionBar = getSupportActionBar();
  81. actionBar.setCustomView(mActionBarVie, lp);
  82. actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  83. actionBar.setDisplayShowCustomEnabled(true);
  84. actionBar.setDisplayHomeAsUpEnabled(true);
  85. // actionBar.setIcon(getNumberDrawable());
  86. // actionBar.setDisplayShowHomeEnabled(true);
  87. actionBar.setDisplayShowTitleEnabled(false);
  88. }
  89. @Override
  90. public boolean onOptionsItemSelected(MenuItem item)
  91. {
  92. Intent intent = new Intent();
  93. switch (item.getItemId())
  94. {
  95. case android.R.id.home:
  96. finish();
  97. break;
  98. default:
  99. break;
  100. }
  101. return super.onOptionsItemSelected(item);
  102. }
  103. private void searchContainer() {
  104. InputMethodManager inputMethodManager = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
  105. inputMethodManager.hideSoftInputFromWindow(searchField.getWindowToken(),0);
  106. inputMethodManager.hideStatusIcon(searchField.getWindowToken());
  107. String cargo_criterion = searchField.getText().toString();
  108. Intent intent = new Intent();
  109. intent.setClass(this, NewDetailActivity.class);
  110. intent.putExtra("action0", "Tracking");
  111. intent.putExtra("function_name", "Cargo Tracking");
  112. intent.putExtra("cargo_criterion", cargo_criterion);
  113. intent.putExtra("actions_count", 1);
  114. intent.putExtra("_id", "dumb");
  115. String h_field;
  116. int selectedId = mSegmentView.getSelect();
  117. if (selectedId == 0)
  118. {
  119. intent.putExtra("criterion_type", 0);
  120. h_field = "h_bol";
  121. }
  122. else
  123. {
  124. intent.putExtra("criterion_type", 1);
  125. h_field = "ctnr";
  126. }
  127. dbUtil.savehistory(h_field, cargo_criterion);
  128. startActivity(intent);
  129. }
  130. }