private void doCheckin() { Logger.i("doCheckin() called"); scheduler = parent.getScheduler(); if (scheduler != null) { lastCheckinTimeText.setText("Checking in..."); scheduler.handleCheckin(true); } }
private void updateLastCheckinTime() { Logger.i("updateLastCheckinTime() called"); scheduler = parent.getScheduler(); if (scheduler != null) { Date lastCheckin = scheduler.getLastCheckinTime(); if (lastCheckin != null) { lastCheckinTimeText.setText("Last checkin " + lastCheckin); } else { lastCheckinTimeText.setText("No checkins yet"); } } }
private void updateConsole() { Logger.i("updateConsole() called"); scheduler = parent.getScheduler(); if (scheduler != null) { AbstractCollection<MeasurementTask> tasks = scheduler.getTaskQueue(); consoleContent.clear(); taskMap.clear(); for (MeasurementTask task : tasks) { String taskStr = task.toString(); consoleContent.add(taskStr); taskMap.put(taskStr, task.getDescription().key); } } updateLastCheckinTime(); }
/** Handles the deletion of the measurement tasks when the user clicks the context menu */ @Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); switch (item.getItemId()) { case R.id.ctxMenuDeleteTask: scheduler = parent.getScheduler(); if (scheduler != null) { String selectedTaskString = consoleContent.getItem(longClickedItemPosition); String taskKey = taskMap.get(selectedTaskString); if (taskKey != null) { scheduler.removeTaskByKey(taskKey); } } updateConsole(); return true; default: } return false; }
@Override public void onClick(View v) { MeasurementTask newTask = null; boolean showLengthWarning = false; try { if (measurementTypeUnderEdit.equals(PingTask.TYPE)) { EditText pingTargetText = (EditText) findViewById(R.id.pingTargetText); Map<String, String> params = new HashMap<String, String>(); params.put("target", pingTargetText.getText().toString()); PingDesc desc = new PingDesc( null, Calendar.getInstance().getTime(), null, Config.DEFAULT_USER_MEASUREMENT_INTERVAL_SEC, Config.DEFAULT_USER_MEASUREMENT_COUNT, MeasurementTask.USER_PRIORITY, params); newTask = new PingTask(desc, MeasurementCreationActivity.this.getApplicationContext()); } else if (measurementTypeUnderEdit.equals(HttpTask.TYPE)) { EditText httpUrlText = (EditText) findViewById(R.id.httpUrlText); Map<String, String> params = new HashMap<String, String>(); params.put("url", httpUrlText.getText().toString()); params.put("method", "get"); HttpDesc desc = new HttpDesc( null, Calendar.getInstance().getTime(), null, Config.DEFAULT_USER_MEASUREMENT_INTERVAL_SEC, Config.DEFAULT_USER_MEASUREMENT_COUNT, MeasurementTask.USER_PRIORITY, params); newTask = new HttpTask(desc, MeasurementCreationActivity.this.getApplicationContext()); } else if (measurementTypeUnderEdit.equals(TracerouteTask.TYPE)) { EditText targetText = (EditText) findViewById(R.id.tracerouteTargetText); Map<String, String> params = new HashMap<String, String>(); params.put("target", targetText.getText().toString()); TracerouteDesc desc = new TracerouteDesc( null, Calendar.getInstance().getTime(), null, Config.DEFAULT_USER_MEASUREMENT_INTERVAL_SEC, Config.DEFAULT_USER_MEASUREMENT_COUNT, MeasurementTask.USER_PRIORITY, params); newTask = new TracerouteTask(desc, MeasurementCreationActivity.this.getApplicationContext()); showLengthWarning = true; } else if (measurementTypeUnderEdit.equals(DnsLookupTask.TYPE)) { EditText dnsTargetText = (EditText) findViewById(R.id.dnsLookupText); Map<String, String> params = new HashMap<String, String>(); params.put("target", dnsTargetText.getText().toString()); DnsLookupDesc desc = new DnsLookupDesc( null, Calendar.getInstance().getTime(), null, Config.DEFAULT_USER_MEASUREMENT_INTERVAL_SEC, Config.DEFAULT_USER_MEASUREMENT_COUNT, MeasurementTask.USER_PRIORITY, params); newTask = new DnsLookupTask(desc, MeasurementCreationActivity.this.getApplicationContext()); } else if (measurementTypeUnderEdit.equals(UDPBurstTask.TYPE)) { EditText udpTargetText = (EditText) findViewById(R.id.UDPBurstLookupText); Map<String, String> params = new HashMap<String, String>(); params.put("target", udpTargetText.getText().toString()); params.put("direction", udpDir); UDPBurstDesc desc = new UDPBurstDesc( null, Calendar.getInstance().getTime(), null, Config.DEFAULT_USER_MEASUREMENT_INTERVAL_SEC, Config.DEFAULT_USER_MEASUREMENT_COUNT, MeasurementTask.USER_PRIORITY, params); newTask = new UDPBurstTask(desc, MeasurementCreationActivity.this.getApplicationContext()); } if (newTask != null) { MeasurementScheduler scheduler = parent.getScheduler(); if (scheduler != null && scheduler.submitTask(newTask)) { /* * Broadcast an intent with MEASUREMENT_ACTION so that the scheduler will immediately * handles the user measurement */ MeasurementCreationActivity.this.sendBroadcast( new UpdateIntent("", UpdateIntent.MEASUREMENT_ACTION)); SpeedometerApp parent = (SpeedometerApp) getParent(); TabHost tabHost = parent.getTabHost(); tabHost.setCurrentTabByTag(ResultsConsoleActivity.TAB_TAG); String toastStr = MeasurementCreationActivity.this.getString(R.string.userMeasurementSuccessToast); if (showLengthWarning) { toastStr += newTask.getDescriptor() + " measurements can be long. Please be patient."; } Toast.makeText(MeasurementCreationActivity.this, toastStr, Toast.LENGTH_LONG).show(); if (scheduler.getCurrentTask() != null) { showBusySchedulerStatus(); } } else { Toast.makeText( MeasurementCreationActivity.this, R.string.userMeasurementFailureToast, Toast.LENGTH_LONG) .show(); } } } catch (Exception e) { Log.e(SpeedometerApp.TAG, "Exception when creating user measurements", e); Toast.makeText( MeasurementCreationActivity.this, R.string.invalidUserMeasurementInputToast, Toast.LENGTH_LONG) .show(); } }