Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e41ea0e
add android show title customization functionality
Alex-Usmanov Oct 17, 2023
fb67692
Pass the parameter
Alex-Usmanov Oct 17, 2023
21cd06f
Dependency overrides
Alex-Usmanov Oct 17, 2023
276c08b
Add tests for native side
Alex-Usmanov Oct 17, 2023
1897451
Cover dart side with tests
Alex-Usmanov Oct 17, 2023
5cd1709
Format
Alex-Usmanov Oct 17, 2023
bc943c5
Reduce code repetition
Alex-Usmanov Oct 17, 2023
d6306ba
Revert todo change
Alex-Usmanov Oct 18, 2023
f59475b
Wrap browser customization values in another configuration object
Alex-Usmanov Oct 20, 2023
157343b
Remove deps overrides
Alex-Usmanov Oct 20, 2023
ae20b08
Revert more deps overrides
Alex-Usmanov Oct 20, 2023
214b0a9
Revert web as well
Alex-Usmanov Oct 20, 2023
cd7dfc9
Revert go_router
Alex-Usmanov Oct 20, 2023
d205c7c
Merge branch 'main' into main
Alex-Usmanov Oct 20, 2023
5eef662
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Oct 27, 2023
c86ff6e
Format files
Alex-Usmanov Oct 27, 2023
92b2197
Fix tests
Alex-Usmanov Oct 27, 2023
425617e
Add browseroptions to launchUrlString & add more tests
Alex-Usmanov Oct 30, 2023
ece2b78
Fix docstrings
Alex-Usmanov Dec 7, 2023
3ddd644
Revert test format change
Alex-Usmanov Dec 7, 2023
cd361d0
Fix tests
Alex-Usmanov Dec 8, 2023
f0017b7
Version bumps and changelogs
Alex-Usmanov Dec 8, 2023
6105671
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Dec 8, 2023
a50be0f
Return path-based dependencies
Alex-Usmanov Dec 8, 2023
ef9c154
Add licences
Alex-Usmanov Dec 11, 2023
f4b08cb
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Dec 11, 2023
80d439b
Fix documentation & changelog
Alex-Usmanov Dec 26, 2023
992d38e
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Dec 26, 2023
193c076
Add backticks to SFSafariViewController in platform interface changelog
Alex-Usmanov Jan 4, 2024
b399c9b
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Jan 4, 2024
1ad83a2
More merging
Alex-Usmanov Jan 4, 2024
298a705
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov Feb 12, 2024
70f5eb0
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov Mar 31, 2024
8f67ab9
Remove dependency overrides
Alex-Usmanov Mar 31, 2024
c203ae0
Revert changelog
Alex-Usmanov Apr 1, 2024
5ae7bc9
Merge branch 'main' into show-title
Alex-Usmanov Apr 7, 2024
e646958
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov May 10, 2024
7d92695
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov May 21, 2024
90360b0
Fix missing classname in type_conversion.dart
Alex-Usmanov Jun 3, 2024
647a8ce
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov Jun 3, 2024
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
Next Next commit
add android show title customization functionality
  • Loading branch information
Alex-Usmanov committed Oct 17, 2023
commit e41ea0ebb74d862e686b44a4a351d456bcc01515
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2013 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.urllauncher;

import androidx.browser.customtabs.CustomTabsIntent;
import io.flutter.plugins.urllauncher.Messages.WebViewOptions;

public interface CustomTabsIntentFactory {
CustomTabsIntent getCustomTabsIntent(WebViewOptions options);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2013 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.urllauncher;

import androidx.browser.customtabs.CustomTabsIntent;

import io.flutter.plugins.urllauncher.Messages.WebViewOptions;

public class CustomTabsIntentFactoryImpl implements CustomTabsIntentFactory {
@Override
public CustomTabsIntent getCustomTabsIntent(WebViewOptions options) {
return new CustomTabsIntent.Builder()
.setShowTitle(options.getShowTitle())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 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.
// Autogenerated from Pigeon (v10.0.0), do not edit directly.
// Autogenerated from Pigeon (v10.1.6), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package io.flutter.plugins.urllauncher;
Expand All @@ -16,6 +16,10 @@
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** Generated class from Pigeon. */
Expand All @@ -31,7 +35,8 @@ public static class FlutterError extends RuntimeException {
/** The error details. Must be a datatype supported by the api codec. */
public final Object details;

public FlutterError(@NonNull String code, @Nullable String message, @Nullable Object details) {
public FlutterError(@NonNull String code, @Nullable String message, @Nullable Object details)
{
super(message);
this.code = code;
this.details = details;
Expand All @@ -50,15 +55,15 @@ protected static ArrayList<Object> wrapError(@NonNull Throwable exception) {
errorList.add(exception.toString());
errorList.add(exception.getClass().getSimpleName());
errorList.add(
"Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception));
"Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception));
}
return errorList;
}

/**
* Configuration options for an in-app WebView.
*
* <p>Generated class from Pigeon that represents data sent in messages.
* Generated class from Pigeon that represents data sent in messages.
*/
public static final class WebViewOptions {
private @NonNull Boolean enableJavaScript;
Expand Down Expand Up @@ -100,6 +105,19 @@ public void setHeaders(@NonNull Map<String, String> setterArg) {
this.headers = setterArg;
}

private @NonNull Boolean showTitle;

public @NonNull Boolean getShowTitle() {
return showTitle;
}

public void setShowTitle(@NonNull Boolean setterArg) {
if (setterArg == null) {
throw new IllegalStateException("Nonnull field \"showTitle\" is null.");
}
this.showTitle = setterArg;
}

/** Constructor is non-public to enforce null safety; use Builder. */
WebViewOptions() {}

Expand All @@ -126,21 +144,30 @@ public static final class Builder {
return this;
}

private @Nullable Boolean showTitle;

public @NonNull Builder setShowTitle(@NonNull Boolean setterArg) {
this.showTitle = setterArg;
return this;
}

public @NonNull WebViewOptions build() {
WebViewOptions pigeonReturn = new WebViewOptions();
pigeonReturn.setEnableJavaScript(enableJavaScript);
pigeonReturn.setEnableDomStorage(enableDomStorage);
pigeonReturn.setHeaders(headers);
pigeonReturn.setShowTitle(showTitle);
return pigeonReturn;
}
}

@NonNull
ArrayList<Object> toList() {
ArrayList<Object> toListResult = new ArrayList<Object>(3);
ArrayList<Object> toListResult = new ArrayList<Object>(4);
toListResult.add(enableJavaScript);
toListResult.add(enableDomStorage);
toListResult.add(headers);
toListResult.add(showTitle);
return toListResult;
}

Expand All @@ -152,6 +179,8 @@ ArrayList<Object> toList() {
pigeonResult.setEnableDomStorage((Boolean) enableDomStorage);
Object headers = list.get(2);
pigeonResult.setHeaders((Map<String, String>) headers);
Object showTitle = list.get(3);
pigeonResult.setShowTitle((Boolean) showTitle);
return pigeonResult;
}
}
Expand Down Expand Up @@ -185,13 +214,16 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) {
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
public interface UrlLauncherApi {
/** Returns true if the URL can definitely be launched. */
@NonNull
@NonNull
Boolean canLaunchUrl(@NonNull String url);
/** Opens the URL externally, returning true if successful. */
@NonNull
@NonNull
Boolean launchUrl(@NonNull String url, @NonNull Map<String, String> headers);
/** Opens the URL in an in-app WebView, returning true if it opens successfully. */
@NonNull
/**
* Opens the URL in an in-app WebView, returning true if it opens
* successfully.
*/
@NonNull
Boolean openUrlInWebView(@NonNull String url, @NonNull WebViewOptions options);
/** Closes the view opened by [openUrlInSafariViewController]. */
void closeWebView();
Expand All @@ -200,12 +232,12 @@ public interface UrlLauncherApi {
static @NonNull MessageCodec<Object> getCodec() {
return UrlLauncherApiCodec.INSTANCE;
}
/** Sets up an instance of `UrlLauncherApi` to handle messages through the `binaryMessenger`. */
/**Sets up an instance of `UrlLauncherApi` to handle messages through the `binaryMessenger`. */
static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable UrlLauncherApi api) {
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger, "dev.flutter.pigeon.UrlLauncherApi.canLaunchUrl", getCodec());
binaryMessenger, "dev.flutter.pigeon.url_launcher_android.UrlLauncherApi.canLaunchUrl", getCodec());
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
Expand All @@ -215,7 +247,8 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable UrlLaunche
try {
Boolean output = api.canLaunchUrl(urlArg);
wrapped.add(0, output);
} catch (Throwable exception) {
}
catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
Expand All @@ -228,7 +261,7 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable UrlLaunche
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger, "dev.flutter.pigeon.UrlLauncherApi.launchUrl", getCodec());
binaryMessenger, "dev.flutter.pigeon.url_launcher_android.UrlLauncherApi.launchUrl", getCodec());
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
Expand All @@ -239,7 +272,8 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable UrlLaunche
try {
Boolean output = api.launchUrl(urlArg, headersArg);
wrapped.add(0, output);
} catch (Throwable exception) {
}
catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
Expand All @@ -252,7 +286,7 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable UrlLaunche
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger, "dev.flutter.pigeon.UrlLauncherApi.openUrlInWebView", getCodec());
binaryMessenger, "dev.flutter.pigeon.url_launcher_android.UrlLauncherApi.openUrlInWebView", getCodec());
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
Expand All @@ -263,7 +297,8 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable UrlLaunche
try {
Boolean output = api.openUrlInWebView(urlArg, optionsArg);
wrapped.add(0, output);
} catch (Throwable exception) {
}
catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
Expand All @@ -276,15 +311,16 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable UrlLaunche
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger, "dev.flutter.pigeon.UrlLauncherApi.closeWebView", getCodec());
binaryMessenger, "dev.flutter.pigeon.url_launcher_android.UrlLauncherApi.closeWebView", getCodec());
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
try {
api.closeWebView();
wrapped.add(0, null);
} catch (Throwable exception) {
}
catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ interface IntentResolver {

private static final String TAG = "UrlLauncher";

private static final CustomTabsIntentFactory customTabsIntentFactory = new CustomTabsIntentFactoryImpl();

private final @NonNull Context applicationContext;

private final @NonNull IntentResolver intentResolver;
Expand Down Expand Up @@ -104,7 +106,7 @@ void setActivity(@Nullable Activity activity) {
// Try to launch using Custom Tabs if they have the necessary functionality.
if (!containsRestrictedHeader(options.getHeaders())) {
Uri uri = Uri.parse(url);
if (openCustomTab(activity, uri, headersBundle)) {
if (openCustomTab(activity, uri, headersBundle, options)) {
return true;
}
}
Expand Down Expand Up @@ -132,9 +134,10 @@ public void closeWebView() {
}

private static boolean openCustomTab(
@NonNull Context context, @NonNull Uri uri, @NonNull Bundle headersBundle) {
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();
@NonNull Context context, @NonNull Uri uri, @NonNull Bundle headersBundle, @NonNull WebViewOptions options) {
CustomTabsIntent customTabsIntent = customTabsIntentFactory.getCustomTabsIntent(options);
customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, headersBundle);

try {
customTabsIntent.launchUrl(context, uri);
} catch (ActivityNotFoundException ex) {
Expand Down Expand Up @@ -176,3 +179,5 @@ private void ensureActivity() {
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ void main() {

// Launch a url then close.
expect(
await launcher.launch(primaryUrl,
useSafariVC: true,
useWebView: true,
enableJavaScript: false,
enableDomStorage: false,
universalLinksOnly: false,
headers: <String, String>{}),
await launcher.launch(
primaryUrl,
useSafariVC: true,
useWebView: true,
enableJavaScript: false,
enableDomStorage: false,
universalLinksOnly: false,
headers: <String, String>{},
showTitle: false,
),
true);
await launcher.closeWebView();
// Delay required to catch android side crashes in onDestroy.
Expand Down
2 changes: 1 addition & 1 deletion packages/url_launcher/url_launcher_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: url_launcher_android
description: Android implementation of the url_launcher plugin.
repository: https://github.com/flutter/packages/tree/main/packages/url_launcher/url_launcher_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
version: 6.1.0
version: 6.2.0
environment:
sdk: ">=2.19.0 <4.0.0"
flutter: ">=3.7.0"
Expand Down