protected void createScreenOffPacoEvents(Context context) { ExperimentProviderUtil experimentProviderUtil = new ExperimentProviderUtil(context); List<Experiment> experimentsNeedingEvent = initializeExperimentsWatchingAppUsage(experimentProviderUtil); for (Experiment experiment : experimentsNeedingEvent) { Event event = createScreenOffPacoEvent(experiment); experimentProviderUtil.insertEvent(event); } }
private void refreshList() { List<Long> joinedExperimentServerIds = experimentProviderUtil.getJoinedExperimentServerIds(); if (joinedExperimentServerIds != null && joinedExperimentServerIds.size() > 0) { progressBar.setVisibility(View.VISIBLE); final Long[] arrayOfIds = joinedExperimentServerIds.toArray(new Long[joinedExperimentServerIds.size()]); new PacoBackgroundService( this, ExperimentUrlBuilder.buildUrlForFullExperiment(userPrefs, arrayOfIds)) .execute(); } }
private static List<Experiment> initializeExperimentsWatchingAppUsage( ExperimentProviderUtil experimentProviderUtil) { List<Experiment> joined = experimentProviderUtil.getJoinedExperiments(); List<Experiment> experimentsNeedingEvent = Lists.newArrayList(); DateTime now = DateTime.now(); for (Experiment experiment2 : joined) { if (!ActionScheduleGenerator.isOver(now, experiment2.getExperimentDAO()) && ExperimentHelper.isLogActions(experiment2.getExperimentDAO())) { experimentsNeedingEvent.add(experiment2); } } return experimentsNeedingEvent; }
private void saveDownloadedExperiments( ExperimentProviderUtil experimentProviderUtil, String contentAsString) { try { experimentProviderUtil.updateExistingExperiments(contentAsString); } catch (JsonParseException e) { // Nothing to be done here. } catch (JsonMappingException e) { // Nothing to be done here. } catch (UnsupportedCharsetException e) { // Nothing to be done here. } catch (IOException e) { // Nothing to be done here. } }
/** * Creates a pacot for stopping an experiment * * @param experiment */ private void createStopEvent(Experiment experiment) { Event event = new Event(); event.setExperimentId(experiment.getId()); event.setServerExperimentId(experiment.getExperimentDAO().getId()); event.setExperimentName(experiment.getExperimentDAO().getTitle()); event.setExperimentVersion(experiment.getExperimentDAO().getVersion()); event.setResponseTime(new DateTime()); Output responseForInput = new Output(); responseForInput.setAnswer("false"); responseForInput.setName("joined"); event.addResponse(responseForInput); experimentProviderUtil.insertEvent(event); startService(new Intent(this, SyncService.class)); }
// Visible for testing public void deleteExperiment(Experiment experiment2) { NotificationCreator nc = NotificationCreator.create(this); nc.timeoutNotificationsForExperiment(experiment2.getExperimentDAO().getId()); createStopEvent(experiment2); experimentProviderUtil.deleteExperiment(experiment2.getId()); if (ExperimentHelper.shouldWatchProcesses(experiment2.getExperimentDAO())) { BroadcastTriggerReceiver.initPollingAndLoggingPreference(this); } new AndroidEsmSignalStore(this) .deleteAllSignalsForSurvey(experiment2.getExperimentDAO().getId()); reloadAdapter(); startService(new Intent(this, BeeperService.class)); startService(new Intent(this, ExperimentExpirationManagerService.class)); }
public void reloadAdapter() { experiments = experimentProviderUtil.getJoinedExperiments(); sortExperimentsByTitle(experiments); adapter = new AvailableExperimentsListAdapter(this, R.id.find_experiments_list, experiments); list.setAdapter(adapter); }