Commit 45bd79f7 authored by Alan McNatty's avatar Alan McNatty
Browse files

Implemented multi-submit of images .. however this version has a leak in it.

parent bf3ce9b4
......@@ -45,6 +45,7 @@
android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
......@@ -75,7 +76,8 @@
<service android:name=".TransferService" android:label="@string/filetransfers"/>
</application>
<uses-sdk android:minSdkVersion="3" />
<!-- API Level 4 aka 1.6 required for multi-send support -->
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
\ No newline at end of file
......@@ -8,4 +8,4 @@
# project structure.
# Project target.
target=android-3
target=android-4
......@@ -46,7 +46,7 @@
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ArtifactConfirmLayout"
android:id="@+id/ArtifactTitleLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
......@@ -71,8 +71,9 @@
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ArtifactDescriptionLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
......
......@@ -20,7 +20,7 @@
android:layout_height="fill_parent">
<TextView android:id="@+id/TransferPictureName"
android:text="Picture"
android:text="Artefact"
android:gravity="bottom"
android:textSize="8pt"
android:layout_width="fill_parent"
......
......@@ -20,10 +20,13 @@
package nz.net.catalyst.MaharaDroid;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
/*
* The ArtifactSendReceiver class is taken from the PictureSendReceiver class
......@@ -46,14 +49,28 @@ public class ArtifactSendReceiver extends Activity {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String [] uris = new String[]{};
if (intent.getAction().equals(Intent.ACTION_SEND)) {
Bundle extras = intent.getExtras();
if (extras.containsKey("android.intent.extra.STREAM")) {
Uri uri = (Uri)extras.get("android.intent.extra.STREAM");
Intent i = new Intent(this, ArtifactSettings.class);
i.putExtra("uri", uri.toString());
uris = new String[] { uri.toString() };
i.putExtra("uri", uris);
startActivity(i);
}
} else if (intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
ArrayList<Parcelable> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
int c = 0;
uris = new String[list.size()];
for (Parcelable p : list) {
Uri uri = (Uri) p;
uris[c++] = uri.toString();
}
Intent i = new Intent(this, ArtifactSettings.class);
i.putExtra("uri", uris);
startActivity(i);
}
finish();
}
......
......@@ -34,6 +34,7 @@ import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
......@@ -58,7 +59,8 @@ public class ArtifactSettings extends Activity implements OnClickListener {
private SharedPreferences mPrefs;
private Bundle m_extras;
private String m_filepath = null;
private String [] uris = null;
private Boolean isMulti = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -79,30 +81,33 @@ public class ArtifactSettings extends Activity implements OnClickListener {
if ( DEBUG ) Log.d(TAG, "No extras .. nothing to do!");
finish();
}
else {
ContentResolver cr = getContentResolver();
Uri uri = Uri.parse(m_extras.getString("uri"));
if ( DEBUG ) Log.d(TAG, "URI = '" + uri.toString() + "'");
// Get the filename of the media file and use that as the default title.
Cursor cursor = cr.query(uri, new String[]{android.provider.MediaStore.MediaColumns.DATA}, null, null, null);
if (cursor != null) {
if ( DEBUG ) Log.d(TAG, "cursor query succeeded");
cursor.moveToFirst();
m_filepath = cursor.getString(0);
cursor.close();
} else {
if ( DEBUG ) Log.d(TAG, "cursor query failed");
// If nothing found by query then assume the file is good to go as is.
m_filepath = uri.getPath();
}
if (m_filepath != null) {
String title = m_filepath.substring(m_filepath.lastIndexOf("/") + 1);
uris = m_extras.getStringArray("uri");
// If single - show the title (with default) and description
if ( uris.length == 1 ) {
isMulti = false;
String filepath = getFilePath(uris[0]);
if (filepath != null) {
// Default the title to the filename and make it all selected for easy replacement
String title = filepath.substring(filepath.lastIndexOf("/") + 1);
((EditText)findViewById(R.id.txtArtifactTitle)).setText(title);
((EditText)findViewById(R.id.txtArtifactTitle)).selectAll();
if ( DEBUG ) Log.d(TAG, "m_filepath = '" + m_filepath + "'");
if ( DEBUG ) Log.d(TAG, "filepath = '" + filepath + "'");
}
} else if ( uris.length > 1 ) {
isMulti = true;
LinearLayout l;
l = (LinearLayout)this.findViewById(R.id.ArtifactTitleLayout);
l.setVisibility(LinearLayout.GONE);
l = (LinearLayout)this.findViewById(R.id.ArtifactDescriptionLayout);
l.setVisibility(LinearLayout.GONE);
} else {
if ( DEBUG ) Log.d(TAG, "No uri's .. nothing to do!");
finish();
}
}
......@@ -130,20 +135,54 @@ public class ArtifactSettings extends Activity implements OnClickListener {
return;
}
// uploader_intent will contain all of the necessary information about this
// upload in the Extras Bundle.
Intent uploader_intent = new Intent(this, TransferService.class);
uploader_intent.putExtra("filename", m_filepath);
uploader_intent.putExtra("title", ((EditText)findViewById(R.id.txtArtifactTitle)).getText().toString());
uploader_intent.putExtra("tags", ((EditText)findViewById(R.id.txtArtifactTags)).getText().toString());
uploader_intent.putExtra("description", ((EditText)findViewById(R.id.txtArtifactDescription)).getText().toString());
// Start the uploader service and pass in the intent containing
// the upload information.
startService(uploader_intent);
Toast.makeText(this, R.string.uploadstarting, Toast.LENGTH_SHORT).show();
for ( int i = 0; i < uris.length; i++ ) {
String filepath = getFilePath(uris[i]);
// uploader_intent will contain all of the necessary information about this
// upload in the Extras Bundle.
Intent uploader_intent = new Intent(this, TransferService.class);
uploader_intent.putExtra("filename", filepath);
uploader_intent.putExtra("tags", ((EditText)findViewById(R.id.txtArtifactTags)).getText().toString());
if ( isMulti ) {
// Set a default title but no description
String title = filepath.substring(filepath.lastIndexOf("/") + 1);
uploader_intent.putExtra("title", title);
} else {
uploader_intent.putExtra("title", ((EditText)findViewById(R.id.txtArtifactTitle)).getText().toString());
uploader_intent.putExtra("description", ((EditText)findViewById(R.id.txtArtifactDescription)).getText().toString());
}
// Start the uploader service and pass in the intent containing
// the upload information.
startService(uploader_intent);
}
Toast.makeText(this, R.string.uploadstarting, Toast.LENGTH_SHORT).show();
}
private String getFilePath(String u) {
ContentResolver cr = getContentResolver();
Uri uri = Uri.parse(u);
String file_path = null;
if ( DEBUG ) Log.d(TAG, "URI = '" + uri.toString() + "'");
// Get the filename of the media file and use that as the default title.
Cursor cursor = cr.query(uri, new String[]{android.provider.MediaStore.MediaColumns.DATA}, null, null, null);
if (cursor != null) {
if ( DEBUG ) Log.d(TAG, "cursor query succeeded");
cursor.moveToFirst();
file_path = cursor.getString(0);
cursor.close();
} else {
if ( DEBUG ) Log.d(TAG, "cursor query failed");
// If nothing found by query then assume the file is good to go as is.
file_path = uri.getPath();
}
return file_path;
}
private void acceptConditions(Boolean accepted) {
final Button button = (Button)findViewById(R.id.btnUpload);
button.setEnabled(accepted);
......
......@@ -37,8 +37,6 @@ public class GlobalResources {
public static final String INTENT_BIND_TRANSFER_SERVICE = "nz.net.catalyst.MaharaDroid.BIND_TRANSFER_SERVICE";
public static final String INTENT_BIND_DOWNLOADER = "nz.net.catalyst.MaharaDroid.BIND_DOWNLOADER";
public static final String INTENT_UPLOAD_PROGRESS_UPDATE = "nz.net.catalyst.MaharaDroid.UPLOAD_PROGRESS_UPDATE";
public static final String INTENT_DOWNLOAD_PROGRESS_UPDATE = "nz.net.catalyst.MaharaDroid.DOWNLOAD_PROGRESS_UPDATE";
public static final String TRANSFER_TYPE_UPLOAD = "Upload";
......
......@@ -70,7 +70,6 @@ public class TransferService extends Service {
@Override
public void onCreate() {
super.onCreate();
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
}
......@@ -120,7 +119,7 @@ public class TransferService extends Service {
upload_info.getString("description"),
getApplicationContext());
publishProgress(new String[]{"start", upload_info.getString("title")});
publishProgress(new String[]{"finish", upload_info.getString("title")});
m_uploads.remove();
if (result == null || result.has("fail")) {
String err_str = null;
......@@ -221,7 +220,6 @@ public class TransferService extends Service {
@Override
public void onDestroy () {
super.onDestroy();
//mPrefs.unregisterOnSharedPreferenceChangeListener(this);
((NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE)).cancel(GlobalResources.UPLOADER_ID);
if (m_update_receiver != null) {
this.unregisterReceiver(m_update_receiver);
......@@ -236,8 +234,7 @@ public class TransferService extends Service {
}
m_update_receiver = new NotificationProgressUpdateReceiver();
if (m_update_receiver != null) {
IntentFilter filter = new IntentFilter(GlobalResources.INTENT_DOWNLOAD_PROGRESS_UPDATE);
filter.addAction(GlobalResources.INTENT_UPLOAD_PROGRESS_UPDATE);
IntentFilter filter = new IntentFilter(GlobalResources.INTENT_UPLOAD_PROGRESS_UPDATE);
this.registerReceiver(m_update_receiver, filter);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment