]>
Commit | Line | Data |
---|---|---|
184c5221 JW |
1 | /* Dumload.java |
2 | * Main front-end glue for Dumload. | |
3 | * | |
4 | * This program is free software: you can redistribute it and/or modify it | |
5 | * under the terms of the GNU General Public License, version 3, as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License | |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | */ | |
16 | ||
0763e16d JW |
17 | package com.joshuawise.dumload; |
18 | ||
0763e16d | 19 | import android.app.Activity; |
0763e16d | 20 | import android.content.Intent; |
42aa7dfd | 21 | import android.content.SharedPreferences; |
0763e16d JW |
22 | import android.net.Uri; |
23 | import android.os.Bundle; | |
42aa7dfd | 24 | import android.preference.PreferenceManager; |
25 | import android.util.Log; | |
26 | import android.view.View; | |
27 | import android.widget.Button; | |
0763e16d JW |
28 | import android.widget.TextView; |
29 | import android.widget.Toast; | |
0763e16d JW |
30 | |
31 | public class Dumload extends Activity { | |
42aa7dfd | 32 | |
33 | private SharedPreferences prefs; | |
34 | ||
0763e16d JW |
35 | /** Called when the activity is first created. */ |
36 | @Override | |
37 | public void onCreate(Bundle savedInstanceState) { | |
38 | super.onCreate(savedInstanceState); | |
39 | setContentView(R.layout.main); | |
40 | TextView tv = (TextView)findViewById(R.id.suckit); | |
41 | tv.setText("Suck it."); | |
42 | } | |
43 | ||
44 | private void say(String s) { | |
45 | Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show(); | |
46 | } | |
47 | ||
48 | public void onStart() { | |
49 | super.onStart(); | |
bb6544e9 | 50 | final Dumload thisact = this; |
0763e16d | 51 | |
42aa7dfd | 52 | prefs = PreferenceManager.getDefaultSharedPreferences(this); |
53 | ||
0763e16d | 54 | Intent i = getIntent(); /* i *am* not an intent! */ |
bb6544e9 JW |
55 | |
56 | if (!i.getAction().equals(Intent.ACTION_SEND)) | |
0763e16d | 57 | { |
42aa7dfd | 58 | // say("Unknown intent for dumload"); |
59 | // this.finish(); | |
60 | Intent pi = new Intent(this, Preferences.class); | |
61 | startActivity(pi); | |
bb6544e9 | 62 | return; |
0763e16d | 63 | } |
bb6544e9 JW |
64 | |
65 | Bundle extras = i.getExtras(); | |
66 | final Uri uri = (Uri)extras.getParcelable(Intent.EXTRA_STREAM); | |
67 | ||
68 | Log.e("Dumload", "Got a send -- starting service."); | |
69 | ||
70 | Button go = (Button)findViewById(R.id.go); | |
71 | go.setOnClickListener(new View.OnClickListener() { | |
72 | public void onClick(View v) { | |
73 | String s = ((TextView) findViewById(R.id.entry)).getText().toString(); | |
74 | android.content.ComponentName cn = getApplicationContext() | |
75 | .startService(new Intent() | |
76 | .setClass(getApplicationContext(), Uploader.class) | |
77 | .setData(uri) | |
78 | .putExtra("com.joshuawise.dumload.dest", s)); | |
79 | if (cn == null) | |
80 | say("Failed to start uploader."); | |
81 | else | |
82 | Log.e("Dumload", "Started service " + cn.toString() + "."); | |
83 | finish(); | |
84 | } | |
85 | }); | |
86 | ||
87 | String uribase = uri.toString(); | |
88 | ||
89 | ||
90 | ((TextView) findViewById(R.id.suckit)).setText("Where to?"); | |
42aa7dfd | 91 | ((TextView) findViewById(R.id.entry)).setText(prefs.getString("defaultUploadPath", "/var/www/") + uribase.substring(uribase.lastIndexOf("/") + 1) + ".jpg"); |
bb6544e9 | 92 | |
0763e16d JW |
93 | } |
94 | } |