// Executes UNIX command. private String exec(String command) { try { if (D) Log.d(TAG, "Exec command: " + command); Process process = Runtime.getRuntime().exec(command); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); BufferedReader errreader = new BufferedReader(new InputStreamReader(process.getErrorStream())); int read; char[] buffer = new char[4096]; StringBuffer output = new StringBuffer(); while ((read = reader.read(buffer)) > 0) { output.append(buffer, 0, read); } while ((read = errreader.read(buffer)) > 0) { output.append(buffer, 0, read); } errreader.close(); process.waitFor(); if (D) Log.d(TAG, output.toString()); return output.toString(); } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } }
private void goToShowMsg(ShowMessageFromWX.Req showReq) { WXMediaMessage wxMsg = showReq.message; WXAppExtendObject obj = (WXAppExtendObject) wxMsg.mediaObject; StringBuffer msg = new StringBuffer(); // 组织一个待显示的消息内容 msg.append("description: "); msg.append(wxMsg.description); msg.append("\n"); msg.append("extInfo: "); msg.append(obj.extInfo); msg.append("\n"); msg.append("filePath: "); msg.append(obj.filePath); Intent intent = new Intent(this, ShowFromWXActivity.class); intent.putExtra(net.sourceforge.simcpux.Constants.ShowMsgActivity.STitle, wxMsg.title); intent.putExtra(net.sourceforge.simcpux.Constants.ShowMsgActivity.SMessage, msg.toString()); intent.putExtra(net.sourceforge.simcpux.Constants.ShowMsgActivity.BAThumbData, wxMsg.thumbData); startActivity(intent); // finish(); }
@Override public void onClick(View view) { switch (view.getId()) { case R.id.backBtn: DeviceRestActivity.this.finish(); break; case R.id.button1: try { String startTime = startTimeTV.getText().toString(); String endTime = endTimeTV.getText().toString(); StringBuffer bufferOne = new StringBuffer(); StringBuffer bufferTwo = new StringBuffer(); if (checkTVOne1.isChecked()) { bufferOne.append("1"); } else { bufferOne.append("0"); } if (checkTVOne2.isChecked()) { bufferOne.append("2"); } else { bufferOne.append("0"); } if (checkTVOne3.isChecked()) { bufferOne.append("3"); } else { bufferOne.append("0"); } if (checkTVOne4.isChecked()) { bufferOne.append("4"); } else { bufferOne.append("0"); } if (checkTVOne5.isChecked()) { bufferOne.append("5"); } else { bufferOne.append("0"); } if (checkTVOne6.isChecked()) { bufferOne.append("6"); } else { bufferOne.append("0"); } if (checkTVOne7.isChecked()) { bufferOne.append("7"); } else { bufferOne.append("0"); } if (checkTV1.isChecked()) { bufferTwo.append("1"); } else { bufferTwo.append("0"); } if (checkTV2.isChecked()) { bufferTwo.append("2"); } else { bufferTwo.append("0"); } if (checkTV3.isChecked()) { bufferTwo.append("3"); } else { bufferTwo.append("0"); } if (checkTV4.isChecked()) { bufferTwo.append("4"); } else { bufferTwo.append("0"); } if (checkTV5.isChecked()) { bufferTwo.append("5"); } else { bufferTwo.append("0"); } if (checkTV6.isChecked()) { bufferTwo.append("6"); } else { bufferTwo.append("0"); } if (checkTV7.isChecked()) { bufferTwo.append("7"); } else { bufferTwo.append("0"); } String content = String.format( "%s-%s,%s,%s-%s,%s", startTimeTV.getText().toString(), endTimeTV.getText().toString(), bufferOne, startTimeTV1.getText().toString(), endTimeTV1.getText().toString(), bufferTwo); // String content = // startTime+"-"+endTime+","+startTime+"-"+endTime+","+bufferTwo.toString(); content = content.replace(":", ""); if (Session.getInstance().getDevice() != null) { sendCommand(content); } // addFence(object); } catch (Exception e) { e.printStackTrace(); } break; case R.id.checkTV1: if (checkTV1.isChecked()) { checkTV1.setChecked(false); } else { checkTV1.setChecked(true); } break; case R.id.checkTV2: if (checkTV2.isChecked()) { checkTV2.setChecked(false); } else { checkTV2.setChecked(true); } break; case R.id.checkTV3: if (checkTV3.isChecked()) { checkTV3.setChecked(false); } else { checkTV3.setChecked(true); } break; case R.id.checkTV4: if (checkTV4.isChecked()) { checkTV4.setChecked(false); } else { checkTV4.setChecked(true); } break; case R.id.checkTV5: if (checkTV5.isChecked()) { checkTV5.setChecked(false); } else { checkTV5.setChecked(true); } break; case R.id.checkTV6: if (checkTV6.isChecked()) { checkTV6.setChecked(false); } else { checkTV6.setChecked(true); } break; case R.id.checkTV7: if (checkTV7.isChecked()) { checkTV7.setChecked(false); } else { checkTV7.setChecked(true); } break; case R.id.checkTV_all: if (checkTVAll.isChecked()) { checkTV1.setChecked(false); checkTV2.setChecked(false); checkTV3.setChecked(false); checkTV4.setChecked(false); checkTV5.setChecked(false); checkTV6.setChecked(false); checkTV7.setChecked(false); checkTVAll.setChecked(false); } else { checkTV1.setChecked(true); checkTV2.setChecked(true); checkTV3.setChecked(true); checkTV4.setChecked(true); checkTV5.setChecked(true); checkTV6.setChecked(true); checkTV7.setChecked(true); checkTVAll.setChecked(true); } break; case R.id.checkTV_one_1: if (checkTVOne1.isChecked()) { checkTVOne1.setChecked(false); } else { checkTVOne1.setChecked(true); } break; case R.id.checkTV_one_2: if (checkTVOne2.isChecked()) { checkTVOne2.setChecked(false); } else { checkTVOne2.setChecked(true); } break; case R.id.checkTV_one_3: if (checkTVOne3.isChecked()) { checkTVOne3.setChecked(false); } else { checkTVOne3.setChecked(true); } break; case R.id.checkTV_one_4: if (checkTVOne4.isChecked()) { checkTVOne4.setChecked(false); } else { checkTVOne4.setChecked(true); } break; case R.id.checkTV_one_5: if (checkTVOne5.isChecked()) { checkTVOne5.setChecked(false); } else { checkTVOne5.setChecked(true); } break; case R.id.checkTV_one_6: if (checkTVOne6.isChecked()) { checkTVOne6.setChecked(false); } else { checkTVOne6.setChecked(true); } break; case R.id.checkTV_one_7: if (checkTVOne7.isChecked()) { checkTVOne7.setChecked(false); } else { checkTVOne7.setChecked(true); } break; case R.id.checkTV_one_all: if (checkTVOneAll.isChecked()) { checkTVOne1.setChecked(false); checkTVOne2.setChecked(false); checkTVOne3.setChecked(false); checkTVOne4.setChecked(false); checkTVOne5.setChecked(false); checkTVOne6.setChecked(false); checkTVOne7.setChecked(false); checkTVOneAll.setChecked(false); } else { checkTVOne1.setChecked(true); checkTVOne2.setChecked(true); checkTVOne3.setChecked(true); checkTVOne4.setChecked(true); checkTVOne5.setChecked(true); checkTVOne6.setChecked(true); checkTVOne7.setChecked(true); checkTVOneAll.setChecked(true); } break; case R.id.startTimeTV: showTimeDialog(startTimeTV.getText().toString(), (TextView) view); break; case R.id.endTimeTV: showTimeDialog(endTimeTV.getText().toString(), (TextView) view); break; case R.id.startTimeTV2: showTimeDialog(startTimeTV1.getText().toString(), (TextView) view); break; case R.id.endTimeTV2: showTimeDialog(endTimeTV1.getText().toString(), (TextView) view); break; } }