| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- package com.usai.apex;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v7.app.ActionBar;
- import android.support.v7.app.AppCompatActivity;
- import android.view.Gravity;
- import android.view.KeyEvent;
- import android.view.LayoutInflater;
- import android.view.MenuItem;
- import android.view.View;
- import android.view.inputmethod.EditorInfo;
- import android.view.inputmethod.InputMethodManager;
- import android.widget.AutoCompleteTextView;
- import android.widget.Button;
- import android.widget.TextView;
- import com.usai.apex.mainframe.NewDetailActivity;
- import com.usai.util.dbUtil;
- public class ContainerSearchActivity extends AppCompatActivity {
- private SegmentView mSegmentView;
- private AutoCompleteTextView searchField;
- private Button cancelBtn;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_container_search);
- cancelBtn = findViewById(R.id.button2);
- searchField = findViewById(R.id.atv_criterion2);
- cancelBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- searchContainer();
- searchField.clearFocus();
- InputMethodManager inputMethodManager = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- inputMethodManager.hideSoftInputFromWindow(searchField.getWindowToken(),0);
- inputMethodManager.hideStatusIcon(searchField.getWindowToken());
- }
- });
- searchField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView textView, int i, KeyEvent event) {
- // 当actionId == XX_SEND 或者 XX_DONE时都触发
- // 或者event.getKeyCode == ENTER 且 event.getAction == ACTION_DOWN时也触发
- // 注意,这是一定要判断event != null。因为在某些输入法上会返回null。
- if (i == EditorInfo.IME_ACTION_SEND || i == EditorInfo.IME_ACTION_DONE || (event != null && KeyEvent.KEYCODE_ENTER == event.getKeyCode() && KeyEvent.ACTION_DOWN == event.getAction())) {
- searchContainer();
- }
- return false;
- }
- });
- setCustomActionBar();
- }
- private void setCustomActionBar() {
- ActionBar.LayoutParams lp =new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
- View mActionBarVie = LayoutInflater.from(this).inflate(R.layout.actionbar_segmentview, null);
- mSegmentView = mActionBarVie.findViewById(R.id.segmentview);
- //
- // mSegmentView.setOnSegmentViewClickListener(new SegmentView.onSegmentViewClickListener() {
- // @Override
- // public void onSegmentViewClick(View view, int postion) {
- // switch (postion) {
- // case 0:
- // Toast.makeText(ContainerSearchActivity.this, "点击了消息" + postion,
- // Toast.LENGTH_SHORT).show();
- // break;
- // case 1:
- // Toast.makeText(ContainerSearchActivity.this, "点击了电话" + postion,
- // Toast.LENGTH_SHORT).show();
- // break;
- // default:
- // break;
- // }
- // }
- // });
- // TextView titleview = mActionBarView.findViewById(R.id.title);
- // titleview.setText(getIntent().getStringExtra("title"));
- //
- // mActionBarView.setBackgroundColor(Color.YELLOW);
- // titleview.setBackgroundColor(Color.BLUE);
- ActionBar actionBar = getSupportActionBar();
- actionBar.setCustomView(mActionBarVie, lp);
- actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
- actionBar.setDisplayShowCustomEnabled(true);
- actionBar.setDisplayHomeAsUpEnabled(true);
- // actionBar.setIcon(getNumberDrawable());
- // actionBar.setDisplayShowHomeEnabled(true);
- actionBar.setDisplayShowTitleEnabled(false);
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item)
- {
- Intent intent = new Intent();
- switch (item.getItemId())
- {
- case android.R.id.home:
- finish();
- break;
- default:
- break;
- }
- return super.onOptionsItemSelected(item);
- }
- private void searchContainer() {
- InputMethodManager inputMethodManager = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- inputMethodManager.hideSoftInputFromWindow(searchField.getWindowToken(),0);
- inputMethodManager.hideStatusIcon(searchField.getWindowToken());
- String cargo_criterion = searchField.getText().toString();
- Intent intent = new Intent();
- intent.setClass(this, NewDetailActivity.class);
- intent.putExtra("action0", "Tracking");
- intent.putExtra("function_name", "Cargo Tracking");
- intent.putExtra("cargo_criterion", cargo_criterion);
- intent.putExtra("actions_count", 1);
- intent.putExtra("_id", "dumb");
- String h_field;
- int selectedId = mSegmentView.getSelect();
- if (selectedId == 0)
- {
- intent.putExtra("criterion_type", 0);
- h_field = "h_bol";
- }
- else
- {
- intent.putExtra("criterion_type", 1);
- h_field = "ctnr";
- }
- dbUtil.savehistory(h_field, cargo_criterion);
- startActivity(intent);
- }
- }
|