Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 871aca4

Browse files
authored
Merge pull request #21 from xster/share
Add a first party share plugin
2 parents 7d65cc7 + 254455a commit 871aca4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1572
-0
lines changed

packages/share/.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
.atom/
3+
.idea
4+
.packages
5+
.pub/
6+
build/
7+
ios/.generated/
8+
packages
9+
pubspec.lock

packages/share/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## [0.1.0] - 2017-05-05
2+
3+
* Initial Open Source release.

packages/share/LICENSE

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017, the Flutter project authors. All rights reserved.
2+
//
3+
// Redistribution and use in source and binary forms, with or without
4+
// modification, are permitted provided that the following conditions are
5+
// met:
6+
//
7+
// * Redistributions of source code must retain the above copyright
8+
// notice, this list of conditions and the following disclaimer.
9+
// * Redistributions in binary form must reproduce the above
10+
// copyright notice, this list of conditions and the following disclaimer
11+
// in the documentation and/or other materials provided with the
12+
// distribution.
13+
// * Neither the name of Google Inc. nor the names of its
14+
// contributors may be used to endorse or promote products derived from
15+
// this software without specific prior written permission.
16+
//
17+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/share/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# share
2+
3+
A Flutter plugin to share content from your Flutter app via the platform's
4+
share dialog.
5+
6+
Wraps the ACTION_SEND Intent on Android and UIActivityViewController
7+
on iOS.
8+
9+
## Usage
10+
11+
To use, first add `share` as a [dependency in your pubspec.yaml](https://flutter.io/platform-plugins/).
12+
```yaml
13+
dependencies:
14+
flutter:
15+
sdk: flutter
16+
share: ^0.1.0
17+
```
18+
19+
Import the library via
20+
```dart
21+
import 'package:share/share.dart';
22+
```
23+
24+
Then invoke the static `share` method anywhere in your Dart code
25+
```dart
26+
share('check out my website https://example.com');
27+
```

packages/share/android/.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
10+
/gradle
11+
/gradlew
12+
/gradlew.bat

packages/share/android/build.gradle

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
group 'io.flutter.plugins.share'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
jcenter()
7+
}
8+
9+
dependencies {
10+
classpath 'com.android.tools.build:gradle:2.3.0'
11+
}
12+
}
13+
14+
allprojects {
15+
repositories {
16+
jcenter()
17+
}
18+
}
19+
20+
apply plugin: 'com.android.library'
21+
22+
android {
23+
compileSdkVersion 25
24+
buildToolsVersion '25.0.0'
25+
26+
defaultConfig {
27+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
28+
}
29+
lintOptions {
30+
disable 'InvalidPackage'
31+
}
32+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.jvmargs=-Xmx1536M
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'share'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.flutter.plugins.share"
3+
android:versionCode="1"
4+
android:versionName="0.0.1">
5+
6+
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
7+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.share;
6+
7+
import android.content.Context;
8+
import android.content.Intent;
9+
10+
import io.flutter.app.FlutterActivity;
11+
import io.flutter.plugin.common.MethodChannel;
12+
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
13+
import io.flutter.plugin.common.MethodChannel.Result;
14+
import io.flutter.plugin.common.MethodCall;
15+
16+
/** Plugin method host for presenting a share sheet via Intent */
17+
public class SharePlugin implements MethodChannel.MethodCallHandler {
18+
19+
private static final String PLATFORM_CHANNEL = "plugins.flutter.io/share";
20+
21+
public static SharePlugin register(FlutterActivity flutterActivity) {
22+
return new SharePlugin(flutterActivity);
23+
}
24+
25+
private Context context;
26+
27+
private SharePlugin(FlutterActivity flutterActivity) {
28+
context = flutterActivity;
29+
new MethodChannel(flutterActivity.getFlutterView(), PLATFORM_CHANNEL)
30+
.setMethodCallHandler(this);
31+
}
32+
33+
@Override
34+
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
35+
if (call.method.equals("share")) {
36+
if (!(call.arguments instanceof String)) {
37+
result.error("ARGUMENT_ERROR", "String argument expected", null);
38+
return;
39+
}
40+
final String text = (String) call.arguments;
41+
share(text);
42+
result.success(null);
43+
} else {
44+
result.error("UNKNOWN_METHOD", "Unknown share method called", null);
45+
}
46+
}
47+
48+
private void share(String text) {
49+
Intent shareIntent = new Intent();
50+
shareIntent.setAction(Intent.ACTION_SEND);
51+
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
52+
shareIntent.setType("text/plain");
53+
context.startActivity(Intent.createChooser(shareIntent, null /* dialog title optional */));
54+
}
55+
56+
}

packages/share/example/.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
.atom/
3+
.idea
4+
.packages
5+
.pub/
6+
build/
7+
ios/.generated/
8+
packages
9+
pubspec.lock
10+
.flutter-plugins

packages/share/example/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# share_example
2+
3+
Demonstrates how to use the share plugin.
4+
5+
## Getting Started
6+
7+
For help getting started with Flutter, view our online
8+
[documentation](http://flutter.io/).

packages/share/example/android.iml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$/android">
6+
<sourceFolder url="file://$MODULE_DIR$/android/app/src/main/java" isTestSource="false" />
7+
</content>
8+
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="library" name="Flutter for Android" level="project" />
11+
</component>
12+
</module>
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
PluginRegistry.java
10+
11+
/gradle
12+
/gradlew
13+
/gradlew.bat
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
def localProperties = new Properties()
2+
def localPropertiesFile = rootProject.file('local.properties')
3+
if (localPropertiesFile.exists()) {
4+
localPropertiesFile.withInputStream { stream ->
5+
localProperties.load(stream)
6+
}
7+
}
8+
9+
def flutterRoot = localProperties.getProperty('flutter.sdk')
10+
if (flutterRoot == null) {
11+
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12+
}
13+
14+
apply plugin: 'com.android.application'
15+
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
16+
17+
android {
18+
compileSdkVersion 25
19+
buildToolsVersion '25.0.2'
20+
21+
lintOptions {
22+
disable 'InvalidPackage'
23+
}
24+
25+
defaultConfig {
26+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
27+
}
28+
29+
buildTypes {
30+
release {
31+
// TODO: Add your own signing config for the release build.
32+
// Signing with the debug keys for now, so `flutter run --release` works.
33+
signingConfig signingConfigs.debug
34+
}
35+
}
36+
}
37+
38+
flutter {
39+
source '../..'
40+
}
41+
42+
dependencies {
43+
androidTestCompile 'com.android.support:support-annotations:25.0.0'
44+
androidTestCompile 'com.android.support.test:runner:0.5'
45+
androidTestCompile 'com.android.support.test:rules:0.5'
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.flutter.plugins.share_example"
3+
android:versionCode="1"
4+
android:versionName="0.0.1">
5+
6+
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
7+
8+
<!-- The INTERNET permission is required for development. Specifically,
9+
flutter needs it to communicate with the running application
10+
to allow setting breakpoints, to provide hot reload, etc.
11+
-->
12+
<uses-permission android:name="android.permission.INTERNET"/>
13+
14+
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
15+
calls FlutterMain.startInitialization(this); in its onCreate method.
16+
In most cases you can leave this as-is, but you if you want to provide
17+
additional functionality it is fine to subclass or reimplement
18+
FlutterApplication and put your custom class here. -->
19+
<application android:name="io.flutter.app.FlutterApplication" android:label="share_example" android:icon="@mipmap/ic_launcher">
20+
<activity android:name=".MainActivity"
21+
android:launchMode="singleTop"
22+
android:theme="@android:style/Theme.Black.NoTitleBar"
23+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
24+
android:hardwareAccelerated="true"
25+
android:windowSoftInputMode="adjustResize">
26+
<intent-filter>
27+
<action android:name="android.intent.action.MAIN"/>
28+
<category android:name="android.intent.category.LAUNCHER"/>
29+
</intent-filter>
30+
</activity>
31+
</application>
32+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.share_example;
6+
7+
import android.os.Bundle;
8+
import io.flutter.app.FlutterActivity;
9+
import io.flutter.plugins.PluginRegistry;
10+
11+
public class MainActivity extends FlutterActivity {
12+
PluginRegistry pluginRegistry;
13+
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
pluginRegistry = new PluginRegistry();
18+
pluginRegistry.registerAll(this);
19+
}
20+
}
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
6+
dependencies {
7+
classpath 'com.android.tools.build:gradle:2.2.3'
8+
}
9+
}
10+
11+
allprojects {
12+
repositories {
13+
jcenter()
14+
}
15+
}
16+
17+
rootProject.buildDir = '../build'
18+
subprojects {
19+
project.buildDir = "${rootProject.buildDir}/${project.name}"
20+
project.evaluationDependsOn(':app')
21+
}
22+
23+
task clean(type: Delete) {
24+
delete rootProject.buildDir
25+
}
26+
27+
task wrapper(type: Wrapper) {
28+
gradleVersion = '2.14.1'
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.jvmargs=-Xmx1536M
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
include ':app'
2+
3+
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
4+
5+
def plugins = new Properties()
6+
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
7+
if (pluginsFile.exists()) {
8+
pluginsFile.withInputStream { stream -> plugins.load(stream) }
9+
}
10+
11+
plugins.each { name, path ->
12+
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
13+
include ":$name"
14+
project(":$name").projectDir = pluginDirectory
15+
}

0 commit comments

Comments
 (0)