@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { try { switch (resultCode) { case ActivityInlandAirlineticketSelectPassengers.SELECTED_FINISH: Bundle b = null; if (data != null) { b = data.getExtras(); } else break; String passengerListString = "", allPassengerListString = ""; if (b != null && b.containsKey(SELECTEDPASSENGERSLIST)) { passengerListString = b.getString(SELECTEDPASSENGERSLIST); } if (b != null && b.containsKey(ALLPASSENGERSLIST)) { allPassengerListString = b.getString(ALLPASSENGERSLIST); } else break; try { passengerList.clear(); passengerList = (ArrayList<Passenger>) JSONHelper.parseCollection(passengerListString, List.class, Passenger.class); allPassengerList = (ArrayList<Passenger>) JSONHelper.parseCollection(allPassengerListString, List.class, Passenger.class); passengerList = ActivityInlandAirlineticketBooking.removeDuplictePassengers(passengerList); caculateMoney(); if (passengerList.size() > 0) { add_passager_tv.setText("修改乘客"); passenger_head_divid_line.setVisibility(View.VISIBLE); } else if (passengerList.size() == 0) { add_passager_tv.setText("新增乘客"); passenger_head_divid_line.setVisibility(View.GONE); } ListAdapter adapter = new PassengerListAdapter(context, passengerList); passenger_listview.setAdapter(adapter); ActivityInlandAirlineticketBooking.setListViewHeightBasedOnChildren(passenger_listview); } catch (Exception e) { e.printStackTrace(); break; } break; default: break; } if (requestCode == CONTANCT_REQUEST_CODE) { // 联系人 if (data == null) return; Bundle b = data.getExtras(); if (b != null && b.containsKey("pickedPhoneNum")) { String myNum = b.getString("pickedPhoneNum"); if (myNum.startsWith("17951")) { myNum = myNum.substring(5); } else if (myNum.startsWith("+86")) { myNum = myNum.substring(3); } contact_person_phone_et.setText(myNum); } } else if (requestCode == BAOXIAN_REQUEST_CODE) { if (data == null) return; Bundle b = data.getExtras(); if (b != null && b.containsKey(ActivityTrainBaoxian.BAOXIAN_BUNDSTRING)) { String baoxian = b.getString(ActivityTrainBaoxian.BAOXIAN_BUNDSTRING); baoxian_price_and_count_tv.setText(baoxian); if (baoxian.equals(ActivityTrainBaoxian.No_Baoxian)) { baoxian_unitPrice = 0; } else if (baoxian.equals(ActivityTrainBaoxian.Baoxian_Five)) { baoxian_unitPrice = 5; } else if (baoxian.equals(ActivityTrainBaoxian.Baoxian_Ten)) { baoxian_unitPrice = 10; } } caculateMoney(); } } catch (Exception e) { e.printStackTrace(); } }
@Override public void handleMessage(Message msg) { switch (msg.what) { case VALIDCODE_MSG_CODE: djsx_tv.setVisibility(View.VISIBLE); yanzhengma_iv.setImageBitmap(validCodeBitmap); break; case COMMIT_ORDER_MSG_CODE: if (commitReturnJson.length() == 0) { getValidCodePic(); // 提交失败后需刷新验证码 yanzhengma_input_et.setText(""); progressdialog.dismiss(); // new AlertDialog.Builder(context).setTitle("发生异常,订单提交失败!") // .setPositiveButton("确认", null).show(); final CustomerAlertDialog cad = new CustomerAlertDialog(context, true); cad.setTitle("发生异常,订单提交失败"); cad.setPositiveButton( "知道了", new OnClickListener() { @Override public void onClick(View arg0) { cad.dismiss(); } }); break; } JSONTokener jsonParser; jsonParser = new JSONTokener(commitReturnJson); try { JSONObject jsonObject = (JSONObject) jsonParser.nextValue(); String state = jsonObject.getString("c"); if (state.equals("0000")) { String orderID = jsonObject.getJSONObject("d").getString("msg"); Intent intent = new Intent(context, ActivityTrainOrderDetail.class); intent.putExtra(ActivityTrainOrderDetail.ORDERRECEIPT, orderID); startActivityForResult(intent, NEW_ORDER_DETAIL_CODE); } else { // new AlertDialog.Builder(context) // .setTitle( // jsonObject.getJSONObject("d") // .getString("msg")) // .setPositiveButton("确定", null).show(); final CustomerAlertDialog cad = new CustomerAlertDialog(context, true); cad.setTitle(jsonObject.getJSONObject("d").getString("msg")); cad.setPositiveButton( "知道了", new OnClickListener() { @Override public void onClick(View arg0) { cad.dismiss(); } }); getValidCodePic(); // 提交失败后需刷新验证码 yanzhengma_input_et.setText(""); } // else { // Toast.makeText(context, "发生异常,提交订单失败!", 0).show(); // getValidCodePic();//提交失败后需刷新验证码 // yanzhengma_input_et.setText(""); // } progressdialog.dismiss(); } catch (Exception e) { e.printStackTrace(); getValidCodePic(); // 提交失败后需刷新验证码 yanzhengma_input_et.setText(""); progressdialog.dismiss(); } break; } }
@SuppressLint("ResourceAsColor") @Override public void onClick(View v) { try { switch (v.getId()) { case R.id.back_imgbtn: finish(); break; case R.id.home_imgbtn: startActivity(new Intent(context, MainActivity.class)); break; case R.id.lianxiren_icon_imgbtn: startActivityForResult( new Intent(context, com.jike.shanglv.SeclectCity.ContactListActivity.class), CONTANCT_REQUEST_CODE); break; case R.id.modify_seat_tv: finish(); break; case R.id.djsx_tv: case R.id.yanzhengma_iv: getValidCodePic(); break; case R.id.add_passager_rl: Intent intent = new Intent(context, ActivityInlandAirlineticketSelectPassengers.class); intent.putExtra(ActivityInlandAirlineticketSelectPassengers.SYSTYPE, "2"); intent.putExtra(ActivityInlandAirlineticketSelectPassengers.TITLE_NAME, "选择旅客"); intent.putExtra(ALLPASSENGERSLIST, JSONHelper.toJSON(allPassengerList)); intent.putExtra(SELECTEDPASSENGERSLIST, JSONHelper.toJSON(passengerList)); startActivityForResult(intent, ADD_PASSENGERS_FORRESULET_CODE); break; case R.id.baoxian_price_and_count_tv: case R.id.baoxian_check_imgbtn: case R.id.baoxian_rl: Intent intent_bx = new Intent(context, ActivityTrainBaoxian.class); intent_bx.putExtra( ActivityTrainBaoxian.BAOXIAN_BUNDSTRING, baoxian_price_and_count_tv.getText().toString().trim()); startActivityForResult(intent_bx, BAOXIAN_REQUEST_CODE); break; case R.id.order_now_btn: if (selectedSeatIndex == -1) { order_now_btn.setEnabled(false); break; } if (passengerList.size() == 0) { // new AlertDialog.Builder(context).setTitle("乘客不能为空") // .setMessage("请添加乘客信息!") // .setPositiveButton("确定", null).show(); final CustomerAlertDialog cad = new CustomerAlertDialog(context, true); cad.setTitle("请添加乘客信息"); cad.setPositiveButton( "确定", new OnClickListener() { @Override public void onClick(View arg0) { cad.dismiss(); } }); break; } else if (remainTicketCount < passengerList.size()) { final CustomerAlertDialog cad = new CustomerAlertDialog(context, true); cad.setTitle( "当前仅剩余" + remainTicketCount + "张票,无法满足" + passengerList.size() + "个人的预订需求"); cad.setPositiveButton( "确定", new OnClickListener() { @Override public void onClick(View arg0) { cad.dismiss(); } }); break; } if (yanzhengma_input_et.getText().toString().length() != 4) { // new AlertDialog.Builder(context).setTitle("请输入验证码") // .setPositiveButton("确定", null).show(); final CustomerAlertDialog cad = new CustomerAlertDialog(context, true); cad.setTitle("请输入验证码"); cad.setPositiveButton( "确定", new OnClickListener() { @Override public void onClick(View arg0) { cad.dismiss(); } }); break; } if (!CommonFunc.isMobileNO(contact_person_phone_et.getText().toString().trim())) { // new // AlertDialog.Builder(context).setTitle("手机号码格式不正确") // .setMessage("请输入合法的手机号码!") // .setPositiveButton("确定", null).show(); final CustomerAlertDialog cad = new CustomerAlertDialog(context, true); cad.setTitle("手机号码格式不正确"); cad.setPositiveButton( "确定", new OnClickListener() { @Override public void onClick(View arg0) { cad.dismiss(); } }); break; } else { sp.edit() .putString( SPkeys.trainContactPhone.getString(), contact_person_phone_et.getText().toString()) .commit(); } commitOrder(); break; default: break; } } catch (Exception e) { e.printStackTrace(); } }
private void initView() { context = this; sp = getSharedPreferences(SPkeys.SPNAME.getString(), 0); imageLoader = new ImageLoader(context.getApplicationContext()); passengerList = new ArrayList<Passenger>(); allPassengerList = new ArrayList<Passenger>(); xibie_listview = (ListView) findViewById(R.id.xibie_listview); add_passager_rl = (RelativeLayout) findViewById(R.id.add_passager_rl); baoxian_rl = (RelativeLayout) findViewById(R.id.baoxian_rl); lianxiren_icon_imgbtn = (ImageButton) findViewById(R.id.lianxiren_icon_imgbtn); back_imgbtn = (ImageButton) findViewById(R.id.back_imgbtn); home_imgbtn = (ImageButton) findViewById(R.id.home_imgbtn); train_num_tv = (TextView) findViewById(R.id.train_num_tv); train_type_tv = (TextView) findViewById(R.id.train_type_tv); runtime_tv = (TextView) findViewById(R.id.runtime_tv); start_station_tv = (TextView) findViewById(R.id.start_station_tv); start_time_tv = (TextView) findViewById(R.id.start_time_tv); start_date_tv = (TextView) findViewById(R.id.start_date_tv); end_station_tv = (TextView) findViewById(R.id.end_station_tv); end_time_tv = (TextView) findViewById(R.id.end_time_tv); end_date_tv = (TextView) findViewById(R.id.end_date_tv); seat_grad_tv = (TextView) findViewById(R.id.seat_grad_tv); ticket_price_tv = (TextView) findViewById(R.id.ticket_price_tv); remain_count_tv = (TextView) findViewById(R.id.remain_count_tv); modify_seat_tv = (TextView) findViewById(R.id.modify_seat_tv); add_passager_tv = (TextView) findViewById(R.id.add_passager_tv); djsx_tv = (TextView) findViewById(R.id.djsx_tv); baoxian_price_and_count_tv = (TextView) findViewById(R.id.baoxian_price_and_count_tv); order_totalmoney_tv = (TextView) findViewById(R.id.order_totalmoney_tv); contact_person_phone_et = (ClearEditText) findViewById(R.id.contact_person_phone_et); yanzhengma_input_et = (ClearEditText) findViewById(R.id.yanzhengma_input_et); passenger_head_divid_line = findViewById(R.id.passenger_head_divid_line); passenger_listview = (ListView) findViewById(R.id.passenger_listview); start_station_icon_iv = (ImageView) findViewById(R.id.start_station_icon_iv); end_station_icon_iv = (ImageView) findViewById(R.id.end_station_icon_iv); yanzhengma_iv = (ImageView) findViewById(R.id.yanzhengma_iv); order_now_btn = (Button) findViewById(R.id.order_now_btn); back_imgbtn.setOnClickListener(btnClickListner); home_imgbtn.setOnClickListener(btnClickListner); modify_seat_tv.setOnClickListener(btnClickListner); yanzhengma_iv.setOnClickListener(btnClickListner); ((TextView) findViewById(R.id.djsx_tv)).setOnClickListener(btnClickListner); add_passager_rl.setOnClickListener(btnClickListner); order_now_btn.setOnClickListener(btnClickListner); baoxian_price_and_count_tv.setOnClickListener(btnClickListner); baoxian_rl.setOnClickListener(btnClickListner); lianxiren_icon_imgbtn.setOnClickListener(btnClickListner); getIntentTrainInfo(); train_num_tv.setText(ti.getTrainID()); train_type_tv.setText(ti.getTrainType()); runtime_tv.setText("历时:" + ti.getRunTime()); start_station_tv.setText(ti.getStationS()); end_station_tv.setText(ti.getStationE()); seat_grad_tv.setText(ti.getSeat_Type()); ticket_price_tv.setText("¥" + ticket_price); remain_count_tv.setText("余票" + ti.getRemain_Count() + "张"); start_time_tv.setText(ti.getGoTime()); end_time_tv.setText(ti.getETime()); adapter_xibie = new MyListAdapter(context, ti.getSeatList()); adapter_xibie.setCurrentID(selectedSeatIndex); remainTicketCount = Integer.valueOf(ti.getRemain_Count()); // adapter_xibie.notifyDataSetChanged(); xibie_listview.setAdapter(adapter_xibie); ActivityInlandAirlineticketBooking.setListViewHeightBasedOnChildren(xibie_listview); xibie_listview.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { try { if (position != selectedSeatIndex) { adapter_xibie.setCurrentID(position); adapter_xibie.notifyDataSetChanged(); } selectedSeatIndex = position; // adapter_xibie.notifyDataSetChanged(); ticket_price = Float.valueOf(ti.getSeatList().get(position).getPrice()); remainTicketCount = Integer.valueOf(ti.getSeatList().get(position).getShengyu()); caculateMoney(); } catch (Exception e) { e.printStackTrace(); } } }); if (selectedSeatIndex == -1) { order_now_btn.setEnabled(false); order_now_btn.setBackground( getResources().getDrawable(R.drawable.booking_immediately_button_d)); } String SFType = ti.getSFType(); if (SFType.length() == 3) { String SType = SFType.substring(0, 1); String FType = SFType.substring(2, 3); if (SType.equals("始")) { start_station_icon_iv.setBackground(getResources().getDrawable(R.drawable.trains_start)); } else if (SType.equals("过")) { start_station_icon_iv.setBackground(getResources().getDrawable(R.drawable.train_over)); } if (FType.equals("终")) { end_station_icon_iv.setBackground(getResources().getDrawable(R.drawable.train_final)); } else if (FType.equals("过")) { end_station_icon_iv.setBackground(getResources().getDrawable(R.drawable.train_over)); } } getValidCodePic(); // 获取验证码信息 // 对于常用联系人,直接返回上次订票时的联系人手机号,若不存在则返回本机手机号码 if (sp.getString(SPkeys.trainContactPhone.getString(), "").equals("")) contact_person_phone_et.setText(CommonFunc.getPhoneNumber(context)); else contact_person_phone_et.setText(sp.getString(SPkeys.trainContactPhone.getString(), "")); caculateMoney(); }