]>
Commit | Line | Data |
---|---|---|
0763e16d JW |
1 | package com.joshuawise.dumload; |
2 | ||
0763e16d | 3 | import android.app.Activity; |
0763e16d | 4 | import android.content.Intent; |
42aa7dfd | 5 | import android.content.SharedPreferences; |
0763e16d JW |
6 | import android.net.Uri; |
7 | import android.os.Bundle; | |
42aa7dfd | 8 | import android.preference.PreferenceManager; |
9 | import android.util.Log; | |
10 | import android.view.View; | |
11 | import android.widget.Button; | |
0763e16d JW |
12 | import android.widget.TextView; |
13 | import android.widget.Toast; | |
0763e16d JW |
14 | |
15 | public class Dumload extends Activity { | |
42aa7dfd | 16 | |
17 | private SharedPreferences prefs; | |
18 | ||
0763e16d JW |
19 | /** Called when the activity is first created. */ |
20 | @Override | |
21 | public void onCreate(Bundle savedInstanceState) { | |
22 | super.onCreate(savedInstanceState); | |
23 | setContentView(R.layout.main); | |
24 | TextView tv = (TextView)findViewById(R.id.suckit); | |
25 | tv.setText("Suck it."); | |
26 | } | |
27 | ||
28 | private void say(String s) { | |
29 | Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show(); | |
30 | } | |
31 | ||
32 | public void onStart() { | |
33 | super.onStart(); | |
bb6544e9 | 34 | final Dumload thisact = this; |
0763e16d | 35 | |
42aa7dfd | 36 | prefs = PreferenceManager.getDefaultSharedPreferences(this); |
37 | ||
0763e16d | 38 | Intent i = getIntent(); /* i *am* not an intent! */ |
bb6544e9 JW |
39 | |
40 | if (!i.getAction().equals(Intent.ACTION_SEND)) | |
0763e16d | 41 | { |
42aa7dfd | 42 | // say("Unknown intent for dumload"); |
43 | // this.finish(); | |
44 | Intent pi = new Intent(this, Preferences.class); | |
45 | startActivity(pi); | |
bb6544e9 | 46 | return; |
0763e16d | 47 | } |
bb6544e9 JW |
48 | |
49 | Bundle extras = i.getExtras(); | |
50 | final Uri uri = (Uri)extras.getParcelable(Intent.EXTRA_STREAM); | |
51 | ||
52 | Log.e("Dumload", "Got a send -- starting service."); | |
53 | ||
54 | Button go = (Button)findViewById(R.id.go); | |
55 | go.setOnClickListener(new View.OnClickListener() { | |
56 | public void onClick(View v) { | |
57 | String s = ((TextView) findViewById(R.id.entry)).getText().toString(); | |
58 | android.content.ComponentName cn = getApplicationContext() | |
59 | .startService(new Intent() | |
60 | .setClass(getApplicationContext(), Uploader.class) | |
61 | .setData(uri) | |
62 | .putExtra("com.joshuawise.dumload.dest", s)); | |
63 | if (cn == null) | |
64 | say("Failed to start uploader."); | |
65 | else | |
66 | Log.e("Dumload", "Started service " + cn.toString() + "."); | |
67 | finish(); | |
68 | } | |
69 | }); | |
70 | ||
71 | String uribase = uri.toString(); | |
72 | ||
73 | ||
74 | ((TextView) findViewById(R.id.suckit)).setText("Where to?"); | |
42aa7dfd | 75 | ((TextView) findViewById(R.id.entry)).setText(prefs.getString("defaultUploadPath", "/var/www/") + uribase.substring(uribase.lastIndexOf("/") + 1) + ".jpg"); |
bb6544e9 | 76 | |
0763e16d JW |
77 | } |
78 | } |