/** * Downloads the survey based on the ID and then updates the survey object with the filename and * location */ private boolean downloadSurvey(String serverBase, Survey survey) { boolean success = false; try { HttpUtil.httpDownload( props.getProperty(ConstantUtil.SURVEY_S3_URL) + survey.getId() + ConstantUtil.ARCHIVE_SUFFIX, FileUtil.getFileOutputStream( survey.getId() + ConstantUtil.ARCHIVE_SUFFIX, ConstantUtil.DATA_DIR, props.getProperty(ConstantUtil.USE_INTERNAL_STORAGE), this)); extractAndSave( FileUtil.getFileInputStream( survey.getId() + ConstantUtil.ARCHIVE_SUFFIX, ConstantUtil.DATA_DIR, props.getProperty(ConstantUtil.USE_INTERNAL_STORAGE), this)); survey.setFileName(survey.getId() + ConstantUtil.XML_SUFFIX); survey.setType(DEFAULT_TYPE); survey.setLocation(SD_LOC); success = true; } catch (IOException e) { Log.e(TAG, "Could write survey file " + survey.getFileName(), e); String text = getResources().getString(R.string.cannotupdate); ViewUtil.fireNotification(text, text, this, FAIL_ID, null); PersistentUncaughtExceptionHandler.recordException( new TransferException(survey.getId(), null, e)); } catch (Exception e) { Log.e(TAG, "Could not download survey " + survey.getId(), e); String text = getResources().getString(R.string.cannotupdate); ViewUtil.fireNotification(text, text, this, FAIL_ID, null); PersistentUncaughtExceptionHandler.recordException( new TransferException(survey.getId(), null, e)); } return success; }
/** * displays a notification in the system status bar indicating the completion of the download * operation * * @param type */ private void fireNotification(int count) { String text = getResources().getText(R.string.surveysupdated).toString(); ViewUtil.fireNotification(text, text, this, COMPLETE_ID, null); }