Android Open Source - android-whereami D B Location Exporter






From Project

Back to project page android-whereami.

License

The source code is released under:

GNU General Public License

If you think the Android project android-whereami 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 de.uvwxy.whereami.db_location;
/* w w  w  .jav a  2 s  . c om*/
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.util.ArrayList;

import android.util.Log;

public class DBLocationExporter {
  private String filePath;
  private ArrayList<de.uvwxy.whereami.db_location.Location> dbArray;

  public DBLocationExporter(String filePath, ArrayList<de.uvwxy.whereami.db_location.Location> dbArray) {
    super();
    this.filePath = filePath;
    this.dbArray = dbArray;
  }

  public int export(String charset) {
    if (filePath == null)
      return -1;
    if (dbArray == null)
      return -2;

    File f = new File(filePath);

    if (f.exists())
      return -3;

    FileOutputStream fout;
    try {
      fout = new FileOutputStream(f);
    } catch (FileNotFoundException e) {
      Log.d("DBEXPORTER", "Failed creating FileOutPutStream");
      return -4;
    }

    int numLinesWritten = 0;

    try {
      OutputStreamWriter out = new OutputStreamWriter(fout, Charset.forName(charset));
      for (int i = 0; i < dbArray.size(); i++) {
        try {
          out.write(mkLine(dbArray.get(i)));
          if (i != dbArray.size() - 1) {
            out.write("\n");
          }
          numLinesWritten++;
        } catch (IOException e) {
          Log.d("DBEXPORTER", "Failed during writing to file...");
          out.close();
          fout.close();
          return -5;
        }
      }

      out.close();
      fout.close();
    } catch (IOException e) {
      Log.d("DBEXPORTER", "Failed closing FileOutputStreamf..");
      return -6;
    }

    return numLinesWritten;
  }

  private String mkLine(de.uvwxy.whereami.db_location.Location entry) {
    String chard = ",";
    String ret = "\"" + entry.getName() + "\"" + chard //
        + entry.getLatitude() + chard //
        + entry.getLongitude() + chard //
        + entry.getAltitude() + chard //
        + entry.getBearing() + chard //
        + entry.getSpeed() + chard //
        + entry.getTime() + chard //
        + entry.getProvider();
    return ret;
  }
}




Java Source Code List

de.uvwxy.whereami.ActionShare.java
de.uvwxy.whereami.ActivityMain.java
de.uvwxy.whereami.Converter.java
de.uvwxy.whereami.ListItemLocationAdapter.java
de.uvwxy.whereami.LocationManager.java
de.uvwxy.whereami.db_location.DBLocationConnection.java
de.uvwxy.whereami.db_location.DBLocationExporter.java
de.uvwxy.whereami.db_location.DBLocation.java
de.uvwxy.whereami.db_location.Location.java
de.uvwxy.whereami.fragments.FragmentCurrentLocation.java
de.uvwxy.whereami.fragments.FragmentSavedLocations.java
de.uvwxy.whereami.fragments.FragmentSettings.java