package com.ectrip.cyt.ui; import java.util.ArrayList; import java.util.Date; import android.content.Intent; import android.media.MediaPlayer; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.posapi.PosApi; import android.text.TextUtils; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.GridView; import android.widget.TextView; import android.widget.Toast; import com.ectrip.cyt.adapter.GridDataAdapter; import com.ectrip.cyt.bean.ImageInfo; import com.ectrip.cyt.center.PosApiHandle; import com.ectrip.cyt.config.DevicTool; import com.ectrip.cyt.config.MyApp; import com.ectrip.cyt.constant.DeviceType; import com.ectrip.cyt.constant.Module; import com.ectrip.cyt.constant.SelectAction; import com.ectrip.cyt.utils.ActivitiesManager; import com.ectrip.cyt.utils.CommetryUtils; import com.ectrip.cyt.utils.CountDownTimer; import com.ectrip.cyt.utils.LogUtil; import com.ectrip.cyt.utils.SharedPreferences2Obj; import com.ectrip.trips.check.R; import com.fri.idcread.idcread; /** * 检票操作 选择页面,包含扫二维码 身份证 串码 * * @author jigo */ public class SelectActionActivity extends BaseActivity implements OnItemClickListener { public final String TAG = "MainActivity"; private GridView gridView1; private GridDataAdapter adapter; private String titleName; private Integer Select; // 选择模式 检票 补票 查票 private Integer type; // 类型 private PosApi mPosSDK = null; private byte mGpioTrig = 0x29;// PC9 MediaPlayer player; /** * 执行扫描,扫描后的结果会通过action为PosApi.ACTION_POS_COMM_STATUS的广播发回 */ Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case 3: try { Bundle bundle = msg.getData(); String id = bundle.getString("id"); if (TextUtils.isEmpty(id)) return; player.start(); // Toast.makeText(SelectActionActivity.this, "身份号码:" + id, Toast.LENGTH_SHORT).show(); Intent intent = new Intent(SelectActionActivity.this, IDOrderListActivity.class); CountDownTimer.firstTime = new Date().getTime();// 不必要的可以删除 intent.putExtra("mode", 0); intent.putExtra("idcardNumber", id); intent.putExtra("titleName", getString(R.string.order_list)); startActivity(intent); } catch (IllegalStateException e) { e.printStackTrace(); } break; } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.app_selection_action); ActivitiesManager.getInstance().pushActivity(this); initView(); init(); // if (DevicTool.isHiboryPos()) { // initScan(); // } } private void initView() { if (Select == null) { Select = SharedPreferences2Obj .getInstance(SelectActionActivity.this) .setName("SelectAction").getObject("Select", Integer.class); titleName = SharedPreferences2Obj .getInstance(SelectActionActivity.this) .setName("SelectAction") .getObject("titleName", String.class); } if (titleName != null) { ((TextView) findViewById(R.id.title)).setText(titleName); } else { ((TextView) findViewById(R.id.title)).setText(R.string.operational); } ((TextView) findViewById(R.id.title)).setVisibility(View.VISIBLE); gridView1 = (GridView) findViewById(R.id.gridView1); LogUtil.i(TAG, "==data==" + initData().size()); gridView1.setNumColumns(2); adapter = new GridDataAdapter(SelectActionActivity.this, initData()); gridView1.setAdapter(adapter); gridView1.setOnItemClickListener(this); findViewById(R.id.topBack).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(); } }); } private void init() { type = SharedPreferences2Obj.getInstance(SelectActionActivity.this) .setName("MachineType").getObject("type", Integer.class); // 扫描提示音 player = MediaPlayer.create(getApplicationContext(), R.raw.beep); } private void initScan() { // 获取PosApi实例 mPosSDK = PosApiHandle.getInstance().getPosApi(); } private ArrayList initData() { ArrayList data = new ArrayList(); data.add(new ImageInfo(getString(R.string.select_action_phone), R.drawable.phone_selector, R.drawable.icon_bg02, Module.PHONE)); data.add(new ImageInfo(getString(R.string.scan_qr_code), R.drawable.scan_selector, R.drawable.icon_bg02, Module.SCAN_QR)); data.add(new ImageInfo(getString(R.string.id_card), R.drawable.id_selector, R.drawable.icon_bg02, Module.IDCARD)); data.add(new ImageInfo(getString(R.string.select_action_order_id), R.drawable.order_selector, R.drawable.icon_bg02, Module.OREDR)); return data; } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { try { CommetryUtils.releaseCommery(this); } catch (Exception e) { e.printStackTrace(); } finish(); } return false; } Runnable run = new Runnable() { @Override public void run() { // TODO Auto-generated method stub // 强制关闭扫描头 mPosSDK.gpioControl(mGpioTrig, 0, 1); isScan = false; } }; boolean isScan = false; public void ScanDomn() { if (!isScan) { mPosSDK.gpioControl(mGpioTrig, 0, 0); isScan = true; handler.removeCallbacks(run); // 3秒后还没有扫描到信息则强制关闭扫描头 handler.postDelayed(run, 3000); } else { mPosSDK.gpioControl(mGpioTrig, 0, 1); mPosSDK.gpioControl(mGpioTrig, 0, 0); isScan = true; handler.removeCallbacks(run); // 3秒后还没有扫描到信息则强制关闭扫描头 handler.postDelayed(run, 3000); } } @Override public void onItemClick(AdapterView parent, View view, int position, long id) { MyApp.getInstance().setCheckType(-1); Intent intent = null; ImageInfo obj = (ImageInfo) view.getTag(R.id.imageView1); switch (obj.getTag()) { case SCAN_QR:// 扫二维码 MyApp.getInstance().setCheckType(0); if (type == DeviceType.GENERAL_POS.getValue() || type == DeviceType.ID_POS.getValue() || type == DeviceType.SMALL_POS.getValue()) { intent = new Intent(SelectActionActivity.this, ScanerOrderActivity.class); if (Select != null) { if (Select == SelectAction.Check.getValue()) { intent.putExtra("titleName", getString(R.string.check_scan_code)); } else if (Select == SelectAction.Reprint.getValue()) { intent.putExtra("titleName", getString(R.string.repriint_scan_code)); } else if (Select == SelectAction.Query.getValue()) { intent.putExtra("titleName", getString(R.string.query_scan_code)); } } else { intent.putExtra("titleName", getString(R.string.scan_qr_code)); } startActivity(intent); } else if (type == DeviceType.BASEWIN_REB_POS.getValue()) { //盛本的红色pos机 Intent intent3 = new Intent(SelectActionActivity.this, PhomeScanerOrderActivity.class); if (Select != null) { if (Select == SelectAction.Check.getValue()) { intent3.putExtra("titleName", getString(R.string.check_scan_code)); } else if (Select == SelectAction.Reprint.getValue()) { intent3.putExtra("titleName", getString(R.string.repriint_scan_code)); } else if (Select == SelectAction.Query.getValue()) { intent3.putExtra("titleName", getString(R.string.query_scan_code)); } } else { intent3.putExtra("titleName", getString(R.string.scan_qr_code)); } startActivity(intent3); } else if (type == DeviceType.HANDSET.getValue()) { // 手持机 二维码功能 // idcread.setpower("/sys/class/gpio/gpio28/value", false); // idcread.setpower("/sys/class/gpio/gpio114/value", // true);// // 给二代证下电 // MToast(SelectActionActivity.this, // "使用其他功能!",MToast.LENGTH_SHORT); Intent intent2 = new Intent(SelectActionActivity.this, NewHandleScanerActivity.class); if (Select != null) { if (Select == SelectAction.Check.getValue()) { intent2.putExtra("titleName", getString(R.string.check_scan_code)); } else if (Select == SelectAction.Reprint.getValue()) { intent2.putExtra("titleName", getString(R.string.repriint_scan_code)); } else if (Select == SelectAction.Query.getValue()) { intent2.putExtra("titleName", getString(R.string.query_scan_code)); } } else { intent2.putExtra("titleName", getString(R.string.scan_qr_code)); } startActivity(intent2); } // else if (type == DeviceType.BLACK_ID_POS.getValue()) { // ScanDomn(); // } else { intent = new Intent(SelectActionActivity.this, PhomeScanerOrderActivity.class); if (Select != null) { if (Select == SelectAction.Check.getValue()) { intent.putExtra("titleName", getString(R.string.check_scan_code)); } else if (Select == SelectAction.Reprint.getValue()) { intent.putExtra("titleName", getString(R.string.repriint_scan_code)); } else if (Select == SelectAction.Query.getValue()) { intent.putExtra("titleName", getString(R.string.query_scan_code)); } } else { intent.putExtra("titleName", getString(R.string.scan_qr_code)); } startActivity(intent); } break; case CODE:// 验证码 intent = new Intent(SelectActionActivity.this, InputCodeActivity.class); if (Select != null) { if (Select == SelectAction.Check.getValue()) { intent.putExtra("titleName", getString(R.string.check_captcha)); } else if (Select == SelectAction.Reprint.getValue()) { intent.putExtra("titleName", getString(R.string.reprint_captcha)); } else if (Select == SelectAction.Query.getValue()) { intent.putExtra("titleName", getString(R.string.query_captcha)); } } else { intent.putExtra("titleName", getString(R.string.captcha)); } startActivity(intent); break; case IDCARD:// 身份证 // 判断是不是039b移动POS机 if (type == DeviceType.ID_POS.getValue() || type == DeviceType.New_IDPOS.getValue()) { intent = new Intent(SelectActionActivity.this, SerialIdCardPortActivity.class); if (Select != null) { if (Select == SelectAction.Check.getValue()) { intent.putExtra("titleName", getString(R.string.check_idcard)); } else if (Select == SelectAction.Reprint.getValue()) { intent.putExtra("titleName", getString(R.string.reprint_idcard)); } else if (Select == SelectAction.Query.getValue()) { intent.putExtra("titleName", getString(R.string.query_idcard)); } } else { intent.putExtra("titleName", getString(R.string.idcard)); } startActivity(intent); } else if (type == DeviceType.BLACK_ID_POS.getValue()) { intent = new Intent(SelectActionActivity.this, BlackIdCardActivity.class); if (Select != null) { if (Select == SelectAction.Check.getValue()) { intent.putExtra("titleName", getString(R.string.check_idcard)); } else if (Select == SelectAction.Reprint.getValue()) { intent.putExtra("titleName", getString(R.string.reprint_idcard)); } else if (Select == SelectAction.Query.getValue()) { intent.putExtra("titleName", getString(R.string.query_idcard)); } } else { intent.putExtra("titleName", getString(R.string.idcard)); } startActivity(intent); } else if (idcread.isIdcard("/dev/ttySAC1")) { // xxx = "打开手持机串口成功!"; intent = new Intent(SelectActionActivity.this, ScanerIdCardActivity.class); if (Select != null) { if (Select == SelectAction.Check.getValue()) { intent.putExtra("titleName", getString(R.string.check_idcard)); } else if (Select == SelectAction.Reprint.getValue()) { intent.putExtra("titleName", getString(R.string.reprint_idcard)); } else if (Select == SelectAction.Query.getValue()) { intent.putExtra("titleName", getString(R.string.query_idcard)); } } else { intent.putExtra("titleName", getString(R.string.idcard)); } startActivity(intent); } else { // xxx = "打开手持机串口失败!"; intent = new Intent(SelectActionActivity.this, InputIdCardActivity.class); if (Select != null) { if (Select == SelectAction.Check.getValue()) { intent.putExtra("titleName", getString(R.string.check_idcard)); } else if (Select == SelectAction.Reprint.getValue()) { intent.putExtra("titleName", getString(R.string.reprint_idcard)); } else if (Select == SelectAction.Query.getValue()) { intent.putExtra("titleName", getString(R.string.query_idcard)); } } else { intent.putExtra("titleName", getString(R.string.idcard)); } startActivity(intent); } break; case PHONE:// 手机号 intent = new Intent(SelectActionActivity.this, InputPhoneActivity.class); if (Select != null) { if (Select == SelectAction.Check.getValue()) { intent.putExtra("titleName", getString(R.string.check_phone)); } else if (Select == SelectAction.Reprint.getValue()) { intent.putExtra("titleName", getString(R.string.reprint_phone)); } else if (Select == SelectAction.Query.getValue()) { intent.putExtra("titleName", getString(R.string.query_phone)); } } else { intent.putExtra("titleName", getString(R.string.phone)); } startActivity(intent); break; case OREDR:// 订单号 intent = new Intent(SelectActionActivity.this, InputOridActivity.class); if (Select != null) { if (Select == SelectAction.Check.getValue()) { intent.putExtra("titleName", getString(R.string.check_order_id)); } else if (Select == SelectAction.Reprint.getValue()) { intent.putExtra("titleName", getString(R.string.reprint_order_id)); } else if (Select == SelectAction.Query.getValue()) { intent.putExtra("titleName", getString(R.string.query_order_id)); } } else { intent.putExtra("titleName", getString(R.string.orderid)); } startActivity(intent); break; // case STATISTIC: // intent = new Intent(SelectActionActivity.this, // StatisticsActivity.class); // intent.putExtra("titleName", getString(R.string.statistic)); // startActivity(intent); // break; } } }