upload all

This commit is contained in:
Brad Fitzpatrick 2010-08-01 20:22:11 -07:00
parent 8c65f36662
commit 60efbf15df
2 changed files with 42 additions and 0 deletions

View File

@ -11,6 +11,8 @@ public final class Preferences {
public static final String AUTO_REQUIRE_POWER = "camli.auto.require_power";
public static final String AUTO_REQUIRE_WIFI = "camli.auto.require_wifi";
public static final String AUTO_DIR_PHOTOS = "camli.auto.photos";
private Preferences() {
}
}

View File

@ -120,6 +120,15 @@ public class UploadService extends Service {
return;
}
if (INTENT_UPLOAD_ALL.equals(action)) {
Util.runAsync(new Runnable() {
public void run() {
handleUploadAll();
}
});
return;
}
try {
if (INTENT_POWER_CONNECTED.equals(action)) {
service.resume();
@ -165,6 +174,37 @@ public class UploadService extends Service {
});
}
// Blocks; to be run from AsyncTask only.
private void handleUploadAll() {
List<String> dirs = getBackupDirs();
List<Uri> filesToQueue = new ArrayList<Uri>();
for (String dirName : dirs) {
File dir = new File(dirName);
File[] files = dir.listFiles();
Log.d(TAG, "Contents of " + dirName + ": " + files);
if (files != null) {
for (int i = 0; i < files.length; ++i) {
Log.d(TAG, " " + files[i]);
filesToQueue.add(Uri.fromFile(files[i]));
}
}
}
try {
service.enqueueUploadList(filesToQueue);
} catch (RemoteException e) {
} finally {
stopServiceIfEmpty();
}
}
private List<String> getBackupDirs() {
ArrayList<String> dirs = new ArrayList<String>();
if (mPrefs.getBoolean(Preferences.AUTO_DIR_PHOTOS, true)) {
dirs.add(Environment.getExternalStorageDirectory() + "/DCIM/Camera");
}
return dirs;
}
private void handleSendMultiple(Intent intent) {
ArrayList<Parcelable> items = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
ArrayList<Uri> uris = new ArrayList<Uri>(items.size());