Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/share/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.6.3

* Support the v2 Android embedder.
* Update to AndroidX.
* Migrate to using the new e2e test binding.
* Add a e2e test.

## 0.6.2+4

* Define clang module for iOS.
Expand Down
26 changes: 26 additions & 0 deletions packages/share/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,29 @@ android {
disable 'InvalidPackage'
}
}

// TODO(cyanglaz): Remove this hack once androidx.lifecycle is included on stable. https://github.com/flutter/flutter/issues/42348
afterEvaluate {
def containsEmbeddingDependencies = false
for (def configuration : configurations.all) {
for (def dependency : configuration.dependencies) {
if (dependency.group == 'io.flutter' &&
dependency.name.startsWith('flutter_embedding') &&
dependency.isTransitive())
{
containsEmbeddingDependencies = true
break
}
}
}
if (!containsEmbeddingDependencies) {
android {
dependencies {
def lifecycle_version = "1.1.1"
api "android.arch.lifecycle:runtime:$lifecycle_version"
api "android.arch.lifecycle:common:$lifecycle_version"
api "android.arch.lifecycle:common-java8:$lifecycle_version"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2019 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.share;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import java.util.Map;

/** Handles the method calls for the plugin. */
class MethodCallHandler implements MethodChannel.MethodCallHandler {

private Share share;

MethodCallHandler(Share share) {
this.share = share;
}

@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
if (call.method.equals("share")) {
if (!(call.arguments instanceof Map)) {
throw new IllegalArgumentException("Map argument expected");
}
// Android does not support showing the share sheet at a particular point on screen.
share.share((String) call.argument("text"), (String) call.argument("subject"));
result.success(null);
} else {
result.notImplemented();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2019 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.share;

import android.app.Activity;
import android.content.Intent;

/** Handles share intent. */
class Share {

private Activity activity;

/**
* Constructs a Share object. The {@code activity} is used to start the share intent. It might be
* null when constructing the {@link Share} object and set to non-null when an activity is
* available using {@link #setActivity(Activity)}.
*/
Share(Activity activity) {
this.activity = activity;
}

/**
* Sets the activity when an activity is available. When the activity becomes unavailable, use
* this method to set it to null.
*/
void setActivity(Activity activity) {
this.activity = activity;
}

void share(String text, String subject) {
if (text == null || text.isEmpty()) {
throw new IllegalArgumentException("Non-empty text expected");
}

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
shareIntent.setType("text/plain");
Intent chooserIntent = Intent.createChooser(shareIntent, null /* dialog title optional */);
if (activity != null) {
activity.startActivity(chooserIntent);
} else {
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(chooserIntent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,68 @@

package io.flutter.plugins.share;

import android.content.Intent;
import io.flutter.plugin.common.MethodCall;
import android.app.Activity;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import java.util.Map;

/** Plugin method host for presenting a share sheet via Intent */
public class SharePlugin implements MethodChannel.MethodCallHandler {
public class SharePlugin implements FlutterPlugin, ActivityAware {

private static final String CHANNEL = "plugins.flutter.io/share";
private MethodCallHandler handler;
private Share share;
private MethodChannel methodChannel;

public static void registerWith(Registrar registrar) {
MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL);
SharePlugin instance = new SharePlugin(registrar);
channel.setMethodCallHandler(instance);
SharePlugin plugin = new SharePlugin();
plugin.setUpChannel(registrar.activity(), registrar.messenger());
}

private final Registrar mRegistrar;
@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
setUpChannel(null, binding.getFlutterEngine().getDartExecutor());
}

@Override
public void onDetachedFromEngine(FlutterPluginBinding binding) {
methodChannel.setMethodCallHandler(null);
methodChannel = null;
share = null;
}

@Override
public void onAttachedToActivity(ActivityPluginBinding binding) {
share.setActivity(binding.getActivity());
}

private SharePlugin(Registrar registrar) {
this.mRegistrar = registrar;
@Override
public void onDetachedFromActivity() {
tearDownChannel();
}

@Override
public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding) {
onAttachedToActivity(binding);
}

@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
if (call.method.equals("share")) {
if (!(call.arguments instanceof Map)) {
throw new IllegalArgumentException("Map argument expected");
}
// Android does not support showing the share sheet at a particular point on screen.
share((String) call.argument("text"), (String) call.argument("subject"));
result.success(null);
} else {
result.notImplemented();
}
}

private void share(String text, String subject) {
if (text == null || text.isEmpty()) {
throw new IllegalArgumentException("Non-empty text expected");
}

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
shareIntent.setType("text/plain");
Intent chooserIntent = Intent.createChooser(shareIntent, null /* dialog title optional */);
if (mRegistrar.activity() != null) {
mRegistrar.activity().startActivity(chooserIntent);
} else {
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mRegistrar.context().startActivity(chooserIntent);
}
public void onDetachedFromActivityForConfigChanges() {
onDetachedFromActivity();
}

private void setUpChannel(Activity activity, BinaryMessenger messenger) {
methodChannel = new MethodChannel(messenger, CHANNEL);
share = new Share(activity);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like activity is always null at this point. You can probably remove the local activity variable and exclusively use the setter method, instead.

handler = new MethodCallHandler(share);
methodChannel.setMethodCallHandler(handler);
}

private void tearDownChannel() {
share.setActivity(null);
methodChannel.setMethodCallHandler(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
<uses-permission android:name="android.permission.INTERNET"/>

<application android:name="io.flutter.app.FlutterApplication" android:label="share_example" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity"
<activity android:name=".EmbeddingV1Activity"
android:launchMode="singleTop"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a comment about singleTop in the sensor PR.

android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
</activity>
<activity android:name=".MainActivity"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.shareexample;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class EmbeddingV1Activity extends FlutterActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.flutter.plugins.shareexample;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.e2e.FlutterRunner;
import org.junit.Rule;
import org.junit.runner.RunWith;

@RunWith(FlutterRunner.class)
public class EmbeddingV1ActivityTest {
@Rule
public ActivityTestRule<EmbeddingV1Activity> rule =
new ActivityTestRule<>(EmbeddingV1Activity.class);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Copyright 2019 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.shareexample;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.share.SharePlugin;

public class MainActivity extends FlutterActivity {

// TODO(cyanglaz): Remove this once v2 of GeneratedPluginRegistrant rolls to stable.
// https://github.com/flutter/flutter/issues/42694
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
public void configureFlutterEngine(FlutterEngine flutterEngine) {
super.configureFlutterEngine(flutterEngine);
flutterEngine.getPlugins().add(new SharePlugin());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.shareexample;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.e2e.FlutterRunner;
import org.junit.Rule;
import org.junit.runner.RunWith;

@RunWith(FlutterRunner.class)
public class MainActivityTest {
@Rule public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class);
}
3 changes: 3 additions & 0 deletions packages/share/example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
10 changes: 10 additions & 0 deletions packages/share/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,15 @@ dependencies:
share:
path: ../

dev_dependencies:
flutter_driver:
sdk: flutter
e2e: ^0.2.0

flutter:
uses-material-design: true

environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
flutter: ">=1.9.1+hotfix.2 <2.0.0"

15 changes: 15 additions & 0 deletions packages/share/example/test_driver/test/share_e2e_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:io';
import 'package:flutter_driver/flutter_driver.dart';

Future<void> main() async {
final FlutterDriver driver = await FlutterDriver.connect();
final String result =
await driver.requestData(null, timeout: const Duration(minutes: 1));
driver.close();
exit(result == 'pass' ? 0 : 1);
}
5 changes: 3 additions & 2 deletions packages/share/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for sharing content via the platform share UI, using
the ACTION_SEND intent on Android and UIActivityViewController on iOS.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/share
version: 0.6.2+4
version: 0.6.3

flutter:
plugin:
Expand All @@ -21,7 +21,8 @@ dev_dependencies:
mockito: ^3.0.0
flutter_test:
sdk: flutter
e2e: ^0.2.0

environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
flutter: ">=1.6.0 <2.0.0"
flutter: ">=1.6.7 <2.0.0"
Loading