Permalink
Browse files

Implements Sharing component

Work started by
cfromknecht@d890e10

Change-Id: I117c697e0de5a924ea937630eecc00a133adaf44
  • Loading branch information...
victorssilva authored and jisqyv committed Dec 15, 2013
1 parent 8438f65 commit 224023ed8440069157d66f2d65d4f1a52fefaf64
@@ -434,4 +434,10 @@
*/
@Source("com/google/appinventor/images/procedures.png")
ImageResource procedures();
/**
* Designer palette item: Sharing Component
*/
@Source("com/google/appinventor/images/sharing.png")
ImageResource sharingComponent();
}
@@ -109,6 +109,7 @@ private static void initBundledImages() {
bundledImages.put("images/twitter.png", images.twitterComponent());
bundledImages.put("images/voting.png", images.voting());
bundledImages.put("images/web.png", images.web());
bundledImages.put("images/sharing.png", images.sharingComponent());
imagesInitialized = true;
}
@@ -243,6 +243,7 @@ private YaVersion() {
// - CAMERA_COMPONENT_VERSION was incremented to 2.
// For YOUNG_ANDROID_VERSION 86:
// - VIDEOPLAYER_COMPONENT_VERSION was incremented to 5.
// - The Sharing Component was added
public static final int YOUNG_ANDROID_VERSION = 86;
@@ -569,6 +570,8 @@ private YaVersion() {
public static final int PLAYER_COMPONENT_VERSION = 5;
public static final int SHARING_COMPONENT_VERSION = 1;
// For SOUND_COMPONENT_VERSION 2:
// - The Sound.SoundError event was added.
// For SOUND_COMPONENT_VERSION 3:
@@ -0,0 +1,95 @@
package com.google.appinventor.components.runtime;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.webkit.MimeTypeMap;
import android.widget.Toast;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.YaVersion;
import java.io.File;
/**
* Component for sharing files and/or messages through Android's built-in sharing
* functionality.
*
* @author victsou@gmail.com (Victor Silva) - Picked up on @cfromknecht's work
* and fixed file support.
*/
@DesignerComponent(version = YaVersion.SHARING_COMPONENT_VERSION,
description ="Sharing is a non-visible component that enables sharing files and/or " +
"messages between your app and other apps installed on a device. The component " +
"will display a list of the installed apps that can handle the information provided, " +
" and will allow the user to choose one to share the content with, for instance a " +
"mail app, a social network app, a texting app, and so on.",
category = ComponentCategory.SOCIAL,
nonVisible = true, iconName = "images/sharing.png")
public class Sharing extends AndroidNonvisibleComponent {
public Sharing(ComponentContainer container) {
super(container.$form());
}
/**
* Shares a message using Android' built-in sharing.
*/
@SimpleFunction(description = "Shares a message through any capable " +
"application installed on the phone by displaying a list of the available apps and " +
"allowing the user to choose one from the list. The selected app will open with the " +
"message inserted on it.")
public void ShareMessage(String message) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, message);
shareIntent.setType("text/plain");
Context cont = this.form.$context();
cont.startActivity(Intent.createChooser(shareIntent, "Send using..."));
}
/**
* Shares a file using Android' built-in sharing.
*/
@SimpleFunction(description = "Shares a file through any capable application "
+ "installed on the phone by displaying a list of the available apps and allowing the " +
"user to choose one from the list. The selected app will open with the file inserted on it.")
public void ShareFile(String file) {
ShareFileWithMessage(file, "");
}
/**
* Shares a file along with a message using Android' built-in sharing.
*/
@SimpleFunction(description = "Shares both a file and a message through any capable application "
+ "installed on the phone by displaying a list of available apps and allowing the user to " +
" choose one from the list. The selected app will open with the file and message inserted on it.")
public void ShareFileWithMessage(String file, String message) {
Activity act = (Activity) this.form.$context();
Uri uri = Uri.parse(file);
File f = new File(uri.getPath());
if (f.exists()) {
String ext = file.substring(file.lastIndexOf(".")+1).toLowerCase();
MimeTypeMap mime = MimeTypeMap.getSingleton();
String type = mime.getMimeTypeFromExtension(ext);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType(type);
if (message.length() > 0) {
shareIntent.putExtra(Intent.EXTRA_TEXT, message);
}
act.startActivity(shareIntent);
}
else {
Toast.makeText(act, file + " not found", Toast.LENGTH_SHORT).show();
}
}
}
@@ -458,6 +458,11 @@ <h2>Table of Contents</h2>
PhoneNumberPicker
</a>
</li>
<li>
<a href="#Sharing">
Sharing
</a>
</li>
<li>
<a href="#Texting">
Texting
@@ -747,6 +752,25 @@ <h3>Methods</h3>
<dd>Opens the picker, as though the user clicked on it.</dd>
</dl>
<h2 id="Sharing">Sharing</h2>
<p>Sharing is a non-visible component that enables sharing files and/or messages between your app and other apps installed on a device. The component will display a list of the installed apps that can handle the information provided, and will allow the user to choose one to share the content with, for instance a mail app, a social network app, a texting app, and so on.</p>
<h3>Properties</h3>
none
<h3>Events</h3>
none
<h3>Methods</h3>
<dl>
<dt><code>ShareFile(text file)</code></dt>
<dd>Shares a file through any capable application installed on the phone by displaying a list of the available apps and allowing the user to choose one from the list. The selected app will open with the file inserted on it.</dd>
<dt><code>ShareFileWithMessage(text file, text message)</code></dt>
<dd>Shares both a file and a message through any capable application installed on the phone by displaying a list of available apps and allowing the user to choose one from the list. The selected app will open with the file and message inserted on it.</dd>
<dt><code>ShareMessage(text message)</code></dt>
<dd>Shares a message through any capable application installed on the phone by displaying a list of the available apps and allowing the user to choose one from the list. The selected app will open with the message inserted on it.</dd>
</dl>
<h2 id="Texting">
Texting

0 comments on commit 224023e

Please sign in to comment.