Android Open Source - clinicalguide File Utils






From Project

Back to project page clinicalguide.

License

The source code is released under:

Apache License

If you think the Android project clinicalguide listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.get.oxicam.clinicalguide;
/*  w  w w . j  av a2s.  c  o m*/
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;

import android.content.Context;
import android.media.MediaScannerConnection;
import android.os.Environment;
import android.util.Log;

public class FileUtils {

    private static final String LOG_TAG = "FileUtils";

    /**
     * Returns the base directory for recorded videos, log files, etc.
     */
    public static File getAppDirectory() {
  File f = new File(Environment.getExternalStorageDirectory()
    .getAbsolutePath() + "/ClinicalGuide");
  // create directory if it not exists
  f.mkdirs();
  return f;
    }

    /**
     * Returns a filename containing the current date. The file is placed in the
     * directory returned by getAppDirectory(). The filename is customized by
     * adding the specified prefix and extension. For example calling this
     * method with prefix "vid" and extension ".mp4" will result in a path
     * something like "/mnt/sdcard/ClinicalGuide/vid_20120603-174523.mp4".
     * 
     * @param prefix
     *            Filename prefix.
     * @param extension
     *            Filename extension.
     * @return A file containing the current date.
     */
    public static File getDateFilename(String prefix, String extension) {
  File dir = getAppDirectory();
  GregorianCalendar cal = new GregorianCalendar();
  String f = String.format("%s/%s_%d%02d%02d-%02d%02d%02d%s",
    dir.getAbsolutePath(), prefix, cal.get(Calendar.YEAR),
    cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH),
    cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE),
    cal.get(Calendar.SECOND), extension);
  return new File(f);
    }

    /**
     * Runs the MediaScanner service on the specified file. This is needed to
     * see the file on an attached computer.
     */
    public static void updateFileForMtp(File file, Context context) {
  if (file != null && context != null) {
      String path = file.getAbsolutePath();
      Log.d(LOG_TAG, "running MediaScanner on: " + path);
      String[] paths = { path };
      MediaScannerConnection.scanFile(context, paths, null, null);
  }
    }

    public static boolean writeFile(String data, String fileName) {
  try {
      Log.w("FileWriting", getAppDirectory().getPath());
      File output = new File(getAppDirectory().getPath() + "/" + fileName);
      if (!output.exists()) {
    output.createNewFile();
      }

      BufferedWriter bw = new BufferedWriter(new FileWriter(output));
      bw.append(data);
      bw.close();
  } catch (FileNotFoundException fnfe) {
      return false;
  } catch (IOException ioe) {
      return false;
  }
  return true;
    }
}




Java Source Code List

.PatientDetailsDataSource.java
org.get.oxicam.clinicalguide.ClinicalGuideActivity.java
org.get.oxicam.clinicalguide.FileUtils.java
org.get.oxicam.clinicalguide.LoginActivity.java
org.get.oxicam.clinicalguide.db.DatabaseHelper.java
org.get.oxicam.clinicalguide.db.Database.java
org.get.oxicam.clinicalguide.db.FollowupDataSource.java
org.get.oxicam.clinicalguide.db.FollowupDetails.java
org.get.oxicam.clinicalguide.db.FollowupSQLHelper.java
org.get.oxicam.clinicalguide.db.HistoryDetailsDataSource.java
org.get.oxicam.clinicalguide.db.HistoryDetailsSQLHelper.java
org.get.oxicam.clinicalguide.db.HistoryDetails.java
org.get.oxicam.clinicalguide.db.PatientDetailsSQLHelper.java
org.get.oxicam.clinicalguide.db.PatientDetails.java
org.get.oxicam.clinicalguide.db.RegistrationValidator.java
org.get.oxicam.clinicalguide.db.Validator.java
org.get.oxicam.clinicalguide.encryption.Encryption.java
org.get.oxicam.clinicalguide.ui.AnswersReviewFragment.java
org.get.oxicam.clinicalguide.ui.AssessmentDetailFragment.java
org.get.oxicam.clinicalguide.ui.ClassificationFragment.java
org.get.oxicam.clinicalguide.ui.ClassificationListItem.java
org.get.oxicam.clinicalguide.ui.DatePickerFragment.java
org.get.oxicam.clinicalguide.ui.ExportFragment.java
org.get.oxicam.clinicalguide.ui.ExportscreenListItem.java
org.get.oxicam.clinicalguide.ui.FollowUpFragment.java
org.get.oxicam.clinicalguide.ui.FormScreenFragment.java
org.get.oxicam.clinicalguide.ui.HomescreenFragment.java
org.get.oxicam.clinicalguide.ui.HomescreenListItem.java
org.get.oxicam.clinicalguide.ui.ListItemOnClickListener.java
org.get.oxicam.clinicalguide.ui.MainSymptomFragment.java
org.get.oxicam.clinicalguide.ui.MainSymptomListItem.java
org.get.oxicam.clinicalguide.ui.NumberTickerValueChangeListener.java
org.get.oxicam.clinicalguide.ui.NumberTicker.java
org.get.oxicam.clinicalguide.ui.PatientDetailsFragment.java
org.get.oxicam.clinicalguide.ui.PatientHistoryFragment.java
org.get.oxicam.clinicalguide.ui.PatientsFragment.java
org.get.oxicam.clinicalguide.ui.QuestionListItem.java
org.get.oxicam.clinicalguide.ui.QuestionnaireFragment.java
org.get.oxicam.clinicalguide.ui.StatScreenFragment.java
org.get.oxicam.clinicalguide.ui.SummaryScreenFragment.java
org.get.oxicam.clinicalguide.ui.TextViewCustomFont.java
org.get.oxicam.clinicalguide.ui.TreatmentConfirmationDialog.java
org.get.oxicam.clinicalguide.ui.TreatmentFragment.java
org.get.oxicam.clinicalguide.ui.TreatmentListItem.java
org.get.oxicam.clinicalguide.ui.ViewDetailScreenFragment.java
org.get.oxicam.clinicalguide.xml.CGFormParser.java
org.get.oxicam.clinicalguide.xml.CGParser.java
org.get.oxicam.clinicalguide.xml.CGStatsParser.java
org.get.oxicam.clinicalguide.xml.DateHelper.java
org.get.oxicam.clinicalguide.xml.FormGenerator.java
org.get.oxicam.clinicalguide.xml.ParserHelper.java
org.get.oxicam.clinicalguide.xml.StatsGenerator.java
org.get.oxicam.clinicalguide.xml.XMLHandler.java
org.get.oxicam.clinicalguide.xml.data.AbstractAnswer.java
org.get.oxicam.clinicalguide.xml.data.Annotation.java
org.get.oxicam.clinicalguide.xml.data.AnswerValidator.java
org.get.oxicam.clinicalguide.xml.data.Answer.java
org.get.oxicam.clinicalguide.xml.data.Assessment.java
org.get.oxicam.clinicalguide.xml.data.CombinedAnswer.java
org.get.oxicam.clinicalguide.xml.data.FollowUp.java
org.get.oxicam.clinicalguide.xml.data.FormQuery.java
org.get.oxicam.clinicalguide.xml.data.Info.java
org.get.oxicam.clinicalguide.xml.data.Option.java
org.get.oxicam.clinicalguide.xml.data.PatientAttribute.java
org.get.oxicam.clinicalguide.xml.data.Question.java
org.get.oxicam.clinicalguide.xml.data.Questionnaire.java
org.get.oxicam.clinicalguide.xml.data.SimpleAnswer.java
org.get.oxicam.clinicalguide.xml.data.Symptom.java
org.get.oxicam.clinicalguide.xml.data.TreatmentAction.java
org.get.oxicam.clinicalguide.xml.data.Treatment.java
org.get.oxicam.clinicalguide.xml.data.User.java
org.get.oxicam.clinicalguide.xml.forms.FormCell.java
org.get.oxicam.clinicalguide.xml.forms.FormColumn.java
org.get.oxicam.clinicalguide.xml.forms.FormDuration.java
org.get.oxicam.clinicalguide.xml.forms.Form.java
org.get.oxicam.clinicalguide.xml.query.QueryHelper.java
org.get.oxicam.clinicalguide.xml.query.QueryResultCell.java
org.get.oxicam.clinicalguide.xml.query.QueryResultRow.java
org.get.oxicam.clinicalguide.xml.query.QueryResultTable.java
org.get.oxicam.clinicalguide.xml.stats.AbstractStatsQuestion.java
org.get.oxicam.clinicalguide.xml.stats.StatsAnswerHolder.java
org.get.oxicam.clinicalguide.xml.stats.StatsColumnCompare.java
org.get.oxicam.clinicalguide.xml.stats.StatsComparatorOperator.java
org.get.oxicam.clinicalguide.xml.stats.StatsCompareConstraint.java
org.get.oxicam.clinicalguide.xml.stats.StatsConstraint.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionAverage.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionCount.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionExtrema.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionFactory.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionList.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionPercentage.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionRatio.java
org.get.oxicam.clinicalguide.xml.stats.StatsSubject.java
org.get.oxicam.clinicalguide.xml.stats.StatsTimespan.java
org.get.oxicam.clinicalguide.xml.stats.Stats.java