@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_udp_monitor_activity); handleTitleDisplay( getString(R.string.btn_title_back), getString(R.string.str_setting_item_netcheck), getString(R.string.btn_clear_all_text)); mSocketLayer = new UDPSocketUtil(); tryAgain = (Button) findViewById(R.id.try_again); tryAgain.setOnClickListener(this); clearBuuton = (Button) findViewById(R.id.clear); clearBuuton.setOnClickListener(this); udpSend = (TextView) findViewById(R.id.totlesend); updReceive = (TextView) findViewById(R.id.totlereceive); losebacket = (TextView) findViewById(R.id.lostrate); maxDelay = (TextView) findViewById(R.id.maxdelay); minDelay = (TextView) findViewById(R.id.mindelay); avarageDelay = (TextView) findViewById(R.id.avaragedelay); startTimer(); mSocketLayer.start(); tryAgain.setEnabled(false); clearBuuton.setEnabled(true); }
@Override protected void handleTitleAction(int direction) { if (direction == TITLE_RIGHT_ACTION) { mSocketLayer.stop(); updateUI(true); stopTimer(); tryAgain.setEnabled(true); clearBuuton.setEnabled(false); } else { super.handleTitleAction(direction); } }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.try_again: startTimer(); mSocketLayer.start(); tryAgain.setEnabled(false); clearBuuton.setEnabled(true); updateUI(true); break; case R.id.clear: mSocketLayer.stop(); updateUI(false); stopTimer(); tryAgain.setEnabled(true); clearBuuton.setEnabled(false); break; default: break; } }
@Override protected void onDestroy() { super.onDestroy(); mSocketLayer.stop(); stopTimer(); }
private void updateUI(boolean isRest) { if (isRest) { udpSend.setText("总发包数(包):0"); updReceive.setText("总收报数(包):0"); losebacket.setText("丢报率(%):0"); maxDelay.setText("最大延时(ms):0"); minDelay.setText("最小延时(ms):0"); avarageDelay.setText("平均延时(ms):0"); return; } Log4Util.i(VoiceHelper.DEMO_TAG, "mSocketLayer.getSumDelay() = " + mSocketLayer.getSumDelay()); udpSend.setText("总发包数(包):" + mSocketLayer.getSendPacketCount()); updReceive.setText("总收报数(包):" + mSocketLayer.getRecePacketCount()); losebacket.setText( "丢报率(%):" + (mSocketLayer.getSendPacketCount() == 0 ? "0" : (((float) (mSocketLayer.getSendPacketCount() - mSocketLayer.getRecePacketCount()) * 100) / (mSocketLayer.getSendPacketCount())))); maxDelay.setText("最大延时(ms):" + mSocketLayer.getMaxDelay()); minDelay.setText("最小延时(ms):" + mSocketLayer.getMinDelay()); avarageDelay.setText( "平均延时(ms):" + (mSocketLayer.getSendPacketCount() == 0 ? "0" : (((long) (mSocketLayer.getSumDelay() / mSocketLayer.getSendPacketCount()))))); }