Skip to content

Commit

Permalink
postaholic
Browse files Browse the repository at this point in the history
  • Loading branch information
PityOnU committed Sep 16, 2012
1 parent 03edc11 commit d18a3c1
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/com/pennapps/vnd/ffling/BackgroundService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pennapps.vnd.ffling;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -11,6 +12,7 @@
import com.dropbox.client2.DropboxAPI.Entry;
import com.dropbox.client2.android.AndroidAuthSession;
import com.dropbox.client2.exception.DropboxException;
import com.dropbox.client2.exception.DropboxUnlinkedException;

import android.app.Notification;
import android.app.NotificationManager;
Expand All @@ -35,6 +37,7 @@ public class BackgroundService extends Service {
private LocationListener locationListener = new MyLocationListener();
public DropboxAPI<AndroidAuthSession> mDBApi;
private Entry secretList;
private float DROPPOINT_DISTANCE = 10;

// Unique Identification Number for the Notification.
// We use it on Notification start, and to cancel it.
Expand Down Expand Up @@ -105,7 +108,7 @@ public IBinder onBind(Intent intent) {
return mBinder;
}

public void getShitDone() { //hi
public void getShitDone() {
try {
secretList = mDBApi.metadata("/", 0, null, true, null);
Log.i("DbExampleLog", secretList.contents.toString());
Expand All @@ -118,17 +121,17 @@ public void getShitDone() { //hi
Location tempPos = new Location("placeholder");
tempPos.setLatitude(TempLat);
tempPos.setLongitude(TempLong);
// if (locFromGps.distanceTo(tempPos) < DROPPOINT_DISTANCE)
// {
if (true) {
if (myLocation.getLastKnownLocation(LocationManager.GPS_PROVIDER).distanceTo(tempPos) < DROPPOINT_DISTANCE)
{
//if (true) {
// Get file.
FileOutputStream outputStream = null;
try {
File file = new File("/mnt/sdcard/" + secretList.contents.get(i).fileName() + ".txt");
outputStream = new FileOutputStream(file);
DropboxFileInfo info = mDBApi.getFile("/" + secretList.contents.get(i).fileName(), null, outputStream, null);
Log.i("DbExampleLog", "The file's rev is: " + info.getMetadata().rev);
// /path/to/new/file.txt now has stuff in it.
mDBApi.delete("/" + secretList.contents.get(i).fileName());
} catch (DropboxException e) {
Log.e("DbExampleLog",
"Something went wrong while downloading.");
Expand All @@ -150,6 +153,30 @@ public void getShitDone() { //hi
"Something went wrong while getting metadata.");
}
}

public void postaholic(String filePathToPost) {
FileInputStream inputStream = null;
try {
File file = new File(filePathToPost);
inputStream = new FileInputStream(file);
Entry newEntry = mDBApi.putFile("/testing.txt", inputStream,
file.length(), null, null);
Log.i("DbExampleLog", "The uploaded file's rev is: " + newEntry.rev);
} catch (DropboxUnlinkedException e) {
Log.e("DbExampleLog", "User has unlinked.");
} catch (DropboxException e) {
Log.e("DbExampleLog", "Something went wrong while uploading.");
} catch (FileNotFoundException e) {
Log.e("DbExampleLog", "File not found.");
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
}
}
}
}

/**
* Show a notification whenever we decide to.
Expand Down

0 comments on commit d18a3c1

Please sign in to comment.