Skip to content

Commit

Permalink
initial release of working version (with less than 100 lines of code)
Browse files Browse the repository at this point in the history
  • Loading branch information
matgoebl committed Sep 20, 2015
1 parent 90dcdbc commit b2ad9d6
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin"/>
</classpath>
33 changes: 33 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Send2URL</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
21 changes: 21 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.matgoebl.send2url" android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/icon">
<activity android:name="PrefsActivity" android:label="@string/prefsactivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="SendActivity" android:label="@string/sendingactivity">
<intent-filter android:label="@string/app_name">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Send2URL
This app adds an entry to the android share menu. When you share any content (e.g. a picture from the gallery) with "Send2URL" it will be uploaded to the configured server URL using a HTTP POST request.
Send2URL
========

This app adds an entry to the android share menu.
When you share any content (e.g. a picture from the gallery) with "Send2URL"
it will be uploaded to the configured server URL using a HTTP POST request.
84 changes: 84 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Send2URL" default="help">

<!-- The local.properties file is created and updated by the 'android'
tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />

<!-- The build.properties file can be created by you and is never touched
by the 'android' tool. This is the place to change some of the
default property values used by the Ant rules.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="build.properties" />

<!-- The default.properties file is created and updated by the 'android'
tool, as well as ADT.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<property file="default.properties" />

<!-- Custom Android task to deal with the project target, and import the
proper rules.
This requires ant 1.6.0 or above. -->
<path id="android.antlibs">
<pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
<pathelement path="${sdk.dir}/tools/lib/sdklib.jar" />
<pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" />
</path>

<taskdef name="setup"
classname="com.android.ant.SetupTask"
classpathref="android.antlibs" />

<!-- extension targets. Uncomment the ones where you want to do custom work
in between standard targets -->
<!--
<target name="-pre-build">
</target>
<target name="-pre-compile">
</target>
[This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir}]
<target name="-post-compile">
</target>
-->


<!-- Execute the Android Setup task that will setup some properties
specific to the target, and import the build rules files.
The rules file is imported from
<SDK>/platforms/<target_platform>/ant/ant_rules_r#.xml
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<setup> task.
- customize it to your needs.
- Customize the whole script.
- copy/paste the content of the rules files (minus the top node)
into this file, *after* the <setup> task
- disable the import of the rules by changing the setup task
below to <setup import="false" />.
- customize to your needs.
-->
<setup />

</project>
11 changes: 11 additions & 0 deletions default.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=android-8
Binary file added icon.xcf
Binary file not shown.
Binary file added res/drawable-mdpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions res/layout/prefs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference android:selectable="false" android:enabled="false"
android:key="about" android:title="@string/About" android:summary="@string/AboutInfo" />
<EditTextPreference android:key="serverurl"
android:dialogTitle="@string/ServerURL" android:title="@string/ServerURL"
android:dialogMessage="@string/EnterServerURL" android:defaultValue="@string/ServerURLDefault" />
</PreferenceScreen>
16 changes: 16 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Send2URL</string>
<string name="prefsactivity">Send2URL Settings</string>
<string name="sendingactivity">Sending to URL...</string>
<string name="EnterServerURL">Enter the server URL</string>
<string name="ServerURL">Set server URL</string>
<string name="ServerURLDefault">https://user:[email protected]:1234/path/</string>
<string name="SendSuccess">Successfully sent to URL</string>
<string name="SendFailed">Error sending to URL</string>
<string name="About">About</string>
<string name="AboutInfo">
This app adds an entry to the android share menu.
When you share any content (e.g. a picture from the gallery) with "Send2URL" it will be uploaded to the configured server URL using a HTTP POST request.
</string>
</resources>
15 changes: 15 additions & 0 deletions src/com/github/matgoebl/send2url/PrefsActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.matgoebl.send2url;

import com.github.matgoebl.send2url.R;
import android.os.Bundle;
import android.preference.PreferenceActivity;

public class PrefsActivity extends PreferenceActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.prefs);
}
}
79 changes: 79 additions & 0 deletions src/com/github/matgoebl/send2url/SendActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.github.matgoebl.send2url;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Base64;
import android.widget.Toast;

public class SendActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String serverUrl = prefs.getString("serverurl", "");

Intent intent = getIntent();
if (intent != null && intent.getAction().equals(Intent.ACTION_SEND)) {
Bundle extras = intent.getExtras();
if(extras != null && extras.containsKey(Intent.EXTRA_STREAM)) {
Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
ContentResolver contentResolver = getContentResolver();
try {
InputStream stream = contentResolver.openInputStream(uri);
httpPost( serverUrl,stream);
Toast.makeText(getBaseContext(), getString(R.string.SendSuccess),
Toast.LENGTH_LONG).show();
setResult(Activity.RESULT_OK);
} catch (Exception e) {
Toast.makeText(getBaseContext(), getString(R.string.SendFailed) + ":\n" + e.toString(),
Toast.LENGTH_LONG).show();
setResult(Activity.RESULT_CANCELED);
}
}
}
finish();
}

public static void httpPost(String serverUrl, InputStream dataStream) throws ClientProtocolException, IOException, Exception {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(serverUrl);

URL url = new URL(serverUrl);
String userInfo = url.getUserInfo();
if( userInfo != null ) {
httppost.addHeader("Authorization", "Basic " + Base64.encodeToString(userInfo.getBytes(), Base64.NO_WRAP));
}

InputStreamEntity requestEntity = new InputStreamEntity(dataStream,-1);
requestEntity.setContentType("binary/octet-stream");
requestEntity.setChunked(true);
httppost.setEntity(requestEntity);

HttpResponse response = httpclient.execute(httppost);
response.getEntity().getContent().close();
httpclient.getConnectionManager().shutdown();

int status = response.getStatusLine().getStatusCode();
if ( status < 200 || status > 299 ) {
throw new Exception(response.getStatusLine().toString());
}
}
}

0 comments on commit b2ad9d6

Please sign in to comment.