This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Share] Support v2 android embedder. #2156
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
c1b7aa8
git st
0395b36
gradle properties update
3b396f3
new embedding
3f57f80
Update gradle.properties
d372d3d
refactor
fa50246
Merge branch 'migrate_share' of github.com:cyanglaz/plugins into migr…
f8066d2
update javadocs
0296390
add license header
f268c32
merge 2 packages
6488ff6
refactor
4530b8d
refactor
ae774b6
rename activities
250eb14
non public
7e0d74f
fix gradle
3033ef6
review fixes
c76a838
review fixes
db46000
Merge branch 'master' into migrate_share
83dfcb5
revert the change that moved the activity out of the constructor
9ae8145
add driver tests
3ba4341
e2e tests
b51bb35
Merge branch 'master' into migrate_share
7acd1d9
Update pubspec.yaml
1722803
Update MainActivity.java
2ffc180
remove androidx constraint
ba7e66b
Update pubspec.yaml
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/share/android/src/main/java/io/flutter/plugins/share/MethodCallHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
packages/share/android/src/main/java/io/flutter/plugins/share/Share.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made a comment about |
||
| 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"/> | ||
|
|
||
18 changes: 18 additions & 0 deletions
18
...xample/android/app/src/main/java/io/flutter/plugins/shareexample/EmbeddingV1Activity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...le/android/app/src/main/java/io/flutter/plugins/shareexample/EmbeddingV1ActivityTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
17 changes: 9 additions & 8 deletions
17
...share/example/android/app/src/main/java/io/flutter/plugins/shareexample/MainActivity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
...e/example/android/app/src/main/java/io/flutter/plugins/shareexample/MainActivityTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/share/example/test_driver/test/share_e2e_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: | ||
|
|
@@ -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" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like
activityis always null at this point. You can probably remove the localactivityvariable and exclusively use the setter method, instead.