├── .gitignore
├── ic_launcher-web.png
├── libs
├── android-support-v4.jar
└── android-async-http-1.4.4.jar
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── values-sw600dp
│ └── dimens.xml
├── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── menu
│ └── main.xml
├── values-sw720dp-land
│ └── dimens.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
└── layout
│ ├── activity_main.xml
│ └── row.xml
├── src
└── org
│ └── donpark
│ └── seedsquirt
│ ├── Constants.java
│ ├── DirObserver.java
│ ├── WatchService.java
│ ├── Post.java
│ ├── PostHandler.java
│ ├── MainActivity.java
│ └── Database.java
├── .settings
└── org.eclipse.jdt.core.prefs
├── .classpath
├── project.properties
├── proguard-project.txt
├── .project
└── AndroidManifest.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 | /gen/
3 |
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donpdonp/seedsquirt/master/ic_launcher-web.png
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donpdonp/seedsquirt/master/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/libs/android-async-http-1.4.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donpdonp/seedsquirt/master/libs/android-async-http-1.4.4.jar
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donpdonp/seedsquirt/master/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donpdonp/seedsquirt/master/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donpdonp/seedsquirt/master/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/donpdonp/seedsquirt/master/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/org/donpark/seedsquirt/Constants.java:
--------------------------------------------------------------------------------
1 | package org.donpark.seedsquirt;
2 |
3 | public interface Constants {
4 | static final String APP_TAG = "SeedSquirt";
5 | }
6 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Seed Squirt
5 | Settings
6 | Hello world!
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
10 |
11 |
15 |
16 |
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 |
--------------------------------------------------------------------------------
/res/layout/row.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
19 |
20 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/src/org/donpark/seedsquirt/DirObserver.java:
--------------------------------------------------------------------------------
1 | package org.donpark.seedsquirt;
2 |
3 | import android.os.FileObserver;
4 | import android.util.Log;
5 |
6 | import com.loopj.android.http.JsonHttpResponseHandler;
7 |
8 | public class DirObserver extends FileObserver implements Constants {
9 |
10 | private Database _db;
11 | private String _path;
12 |
13 | public DirObserver(String path, Database db) {
14 | super(path, CREATE);
15 | _path = path;
16 | _db = db;
17 | }
18 |
19 | @Override
20 | public void onEvent(int event, String path) {
21 | if(path != null) {
22 | Log.d(APP_TAG,"Change "+event+" "+path);
23 | _db.insertUpload(path);
24 | PostHandler handler = new PostHandler(path, _db);
25 | String fullpath = _path+"/"+path;
26 | Post.filePost(fullpath, handler);
27 | }
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | SeedSquirt
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/org/donpark/seedsquirt/WatchService.java:
--------------------------------------------------------------------------------
1 | package org.donpark.seedsquirt;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.Environment;
6 | import android.os.IBinder;
7 | import android.util.Log;
8 |
9 | public class WatchService extends Service implements Constants {
10 |
11 | public static DirObserver photos;
12 | public static Database db;
13 |
14 | @Override
15 | public void onStart(Intent start, int key){
16 | Log.d(APP_TAG, "WatchService onStart()");
17 |
18 | db = new Database(getApplicationContext());
19 | db.open();
20 |
21 | String photoPath = Environment.getExternalStorageDirectory()+"/"+Environment.DIRECTORY_DCIM+"/camera";
22 | photos = new DirObserver(photoPath, db);
23 | Log.d(APP_TAG,"Begin watching "+photoPath);
24 | photos.startWatching();
25 | }
26 |
27 | @Override
28 | public IBinder onBind(Intent arg0) {
29 | return null;
30 | }
31 |
32 | @Override
33 | public void onDestroy(){
34 | db.close();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
18 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/org/donpark/seedsquirt/Post.java:
--------------------------------------------------------------------------------
1 | package org.donpark.seedsquirt;
2 |
3 | import java.io.File;
4 | import java.io.FileNotFoundException;
5 |
6 | import android.os.Handler;
7 | import android.util.Log;
8 |
9 | import com.loopj.android.http.AsyncHttpClient;
10 | import com.loopj.android.http.AsyncHttpResponseHandler;
11 | import com.loopj.android.http.RequestHandle;
12 | import com.loopj.android.http.RequestParams;
13 |
14 |
15 | public class Post implements Constants {
16 | private static AsyncHttpClient client = new AsyncHttpClient();
17 | public static String URL = "http://cdn.donpark.org/i/upload";
18 |
19 | public static RequestHandle filePost(String filename, AsyncHttpResponseHandler handler){
20 | File myFile = new File(filename);
21 | RequestParams params = new RequestParams();
22 | try {
23 | params.put("myfile", myFile);
24 | Log.d(APP_TAG,"Posting "+filename+" to "+URL);
25 | RequestHandle req = client.post(URL, params, handler);
26 | return req;
27 | } catch(FileNotFoundException e) {
28 | return null;
29 | }
30 | }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/src/org/donpark/seedsquirt/PostHandler.java:
--------------------------------------------------------------------------------
1 | package org.donpark.seedsquirt;
2 |
3 | import org.apache.http.Header;
4 | import org.json.JSONObject;
5 |
6 | import android.util.Log;
7 |
8 | import com.loopj.android.http.JsonHttpResponseHandler;
9 | import com.loopj.android.http.TextHttpResponseHandler;
10 |
11 | public class PostHandler extends TextHttpResponseHandler implements Constants {
12 | private String path;
13 | private Database db;
14 |
15 | public PostHandler(String path, Database db){
16 | this.path = path;
17 | this.db = db;
18 | }
19 | @Override
20 | public void onSuccess(int statusCode, Header[] headers, String response) {
21 | Log.d(APP_TAG, "Upload Success "+response);
22 | db.setStatus(Database.SUCCESS_STATUS, path);
23 | }
24 | @Override
25 | public void onStart() {
26 | Log.d(APP_TAG, "Upload Start! ");
27 | }
28 | @Override
29 | public void onProgress(int bytesWritten, int bytesTotal) {
30 | Log.d(APP_TAG, "Upload Progress! written="+bytesWritten+" total="+bytesTotal);
31 | }
32 | @Override
33 | public void onFailure(int statusCode, Header[] headers, String response, Throwable throwable){
34 | Log.d(APP_TAG, "Upload Error "+statusCode+" "+response+" "+throwable);
35 | db.setStatus(Database.ERROR_STATUS, path);
36 | }
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/src/org/donpark/seedsquirt/MainActivity.java:
--------------------------------------------------------------------------------
1 | package org.donpark.seedsquirt;
2 |
3 | import android.os.Bundle;
4 | import android.app.Activity;
5 | import android.content.Intent;
6 | import android.util.Log;
7 | import android.view.Menu;
8 | import android.widget.ListView;
9 | import android.widget.SimpleCursorAdapter;
10 | import android.widget.TextView;
11 |
12 | public class MainActivity extends Activity implements Constants {
13 |
14 | private Database db;
15 | private ListView mainList;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 | }
22 |
23 | @Override
24 | protected void onStart(){
25 | super.onStart();
26 | Log.d(APP_TAG, "MainActivity onStart(). Starting service");
27 | Intent watch = new Intent(this, WatchService.class);
28 | startService(watch);
29 | }
30 |
31 | @Override
32 | protected void onResume(){
33 | super.onResume();
34 | Log.d(APP_TAG, "MainActivity onResume()");
35 | db = new Database(this);
36 | db.open();
37 |
38 | TextView tv = (TextView)findViewById(R.id.greeting);
39 | tv.setText("Upload target "+Post.URL);
40 |
41 | SimpleCursorAdapter adapter=new SimpleCursorAdapter(this,
42 | R.layout.row, db.uploads(),
43 | new String[] {Database.FILENAME_COLUMN, Database.STATUS_COLUMN},
44 | new int[] {R.id.filename, R.id.status});
45 | mainList = (ListView) findViewById(R.id.uploads);
46 | mainList.setAdapter(adapter);
47 |
48 | }
49 |
50 | @Override
51 | public boolean onCreateOptionsMenu(Menu menu) {
52 | // Inflate the menu; this adds items to the action bar if it is present.
53 | getMenuInflater().inflate(R.menu.main, menu);
54 | return true;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/org/donpark/seedsquirt/Database.java:
--------------------------------------------------------------------------------
1 | package org.donpark.seedsquirt;
2 |
3 | import android.content.ContentValues;
4 | import android.content.Context;
5 | import android.database.Cursor;
6 | import android.database.sqlite.SQLiteDatabase;
7 | import android.database.sqlite.SQLiteDatabase.CursorFactory;
8 | import android.database.sqlite.SQLiteOpenHelper;
9 | import android.util.Log;
10 |
11 | public class Database implements Constants {
12 | public static final String DB_NAME="files";
13 | public static int DB_VERSION=1;
14 |
15 | public static final String UPLOADS_TABLE="uploads";
16 | public static final String FILENAME_COLUMN="filename";
17 | public static final String URL_COLUMN="url";
18 | public static final String STATUS_COLUMN="status";
19 | public static final String UPLOADED_AT_COLUMN="uploaded_at";
20 |
21 | public static String INPROGRESS_STATUS = "inprogress";
22 | public static String SUCCESS_STATUS = "success";
23 | public static String ERROR_STATUS = "failed";
24 |
25 | private final Context _context;
26 | private final DbHelper _helper;
27 | private SQLiteDatabase _db;
28 |
29 | public Database(Context context){
30 | _context = context;
31 | _helper = new DbHelper(_context, DB_NAME, null, DB_VERSION);
32 | }
33 |
34 | public void open(){
35 | _db = _helper.getWritableDatabase();
36 | }
37 |
38 | public void close(){
39 | _db.close();
40 | }
41 |
42 | public void insertUpload(String fileName){
43 | Log.d(APP_TAG, "inserting "+fileName);
44 | ContentValues cv = new ContentValues();
45 | cv.put(FILENAME_COLUMN, fileName);
46 | cv.put(STATUS_COLUMN, INPROGRESS_STATUS);
47 |
48 | _db.insert(UPLOADS_TABLE, null, cv);
49 | }
50 |
51 | public Cursor uploads(){
52 | return _db.rawQuery("SELECT * FROM "+UPLOADS_TABLE, null);
53 | }
54 |
55 | public Cursor uploads(String status){
56 | return _db.rawQuery("SELECT *"+
57 | " FROM "+UPLOADS_TABLE+
58 | " WHERE "+STATUS_COLUMN+" = ?",
59 | new String[] {status});
60 | }
61 |
62 | private static class DbHelper extends SQLiteOpenHelper {
63 |
64 | public DbHelper(Context context, String dbName, CursorFactory factory, int version) {
65 | super(context, dbName, factory, version);
66 | }
67 |
68 | @Override
69 | public void onCreate(SQLiteDatabase db) {
70 | db.execSQL("CREATE TABLE "+UPLOADS_TABLE+" (_id INTEGER PRIMARY KEY AUTOINCREMENT, "+
71 | FILENAME_COLUMN+" TEXT, "+
72 | URL_COLUMN+" TEXT, "+
73 | STATUS_COLUMN+" TEXT, "+
74 | UPLOADED_AT_COLUMN+" DATETIME);");
75 | }
76 |
77 | @Override
78 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
79 |
80 | }
81 |
82 | }
83 |
84 | public void setStatus(String status, String filename) {
85 | Log.d(APP_TAG, "setStatus "+status+" for "+filename);
86 | ContentValues cv = new ContentValues();
87 | cv.put(STATUS_COLUMN, status);
88 | _db.update(UPLOADS_TABLE, cv, FILENAME_COLUMN+" = ?", new String[] {filename});
89 | }
90 | }
91 |
--------------------------------------------------------------------------------