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
[webview_flutter] Add a backgroundColor option to the Android webview #4569
Merged
stuartmorgan-g
merged 7 commits into
flutter:master
from
e-adrien:webview_flutter_android
Dec 6, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2709bd9
Add a backgroundColor option to the Android webview
e-adrien c9aceb0
Run formatter
e-adrien 9b65959
Replace loadUrl by loadHtmlString in the example
e-adrien 9bc6101
Hard code Colors.green to prevent test breaking if the color changes …
e-adrien 1f6d28b
Nits
e-adrien b098a81
Nit
e-adrien c654cfd
Disable the test integration test temporarily.
stuartmorgan-g 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
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
61 changes: 61 additions & 0 deletions
61
...pp/src/androidTest/java/io/flutter/plugins/webviewflutterexample/BackgroundColorTest.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,61 @@ | ||
| // 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.webviewflutterexample; | ||
|
|
||
| import static androidx.test.espresso.flutter.EspressoFlutter.onFlutterWidget; | ||
| import static androidx.test.espresso.flutter.action.FlutterActions.click; | ||
| import static androidx.test.espresso.flutter.matcher.FlutterMatchers.withText; | ||
| import static androidx.test.espresso.flutter.matcher.FlutterMatchers.withValueKey; | ||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| import android.graphics.Bitmap; | ||
| import android.graphics.Color; | ||
| import androidx.test.core.app.ActivityScenario; | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
| import androidx.test.rule.ActivityTestRule; | ||
| import androidx.test.runner.screenshot.ScreenCapture; | ||
| import androidx.test.runner.screenshot.Screenshot; | ||
| import org.junit.Before; | ||
| import org.junit.Ignore; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| @RunWith(AndroidJUnit4.class) | ||
| public class BackgroundColorTest { | ||
| @Rule | ||
| public ActivityTestRule<DriverExtensionActivity> myActivityTestRule = | ||
| new ActivityTestRule<>(DriverExtensionActivity.class, true, false); | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| ActivityScenario.launch(DriverExtensionActivity.class); | ||
| } | ||
|
|
||
| @Ignore("Doesn't run in Firebase Test Lab: https://github.com/flutter/flutter/issues/94748") | ||
| @Test | ||
| public void backgroundColor() { | ||
| onFlutterWidget(withValueKey("ShowPopupMenu")).perform(click()); | ||
| onFlutterWidget(withValueKey("ShowTransparentBackgroundExample")).perform(click()); | ||
| onFlutterWidget(withText("Transparent background test")); | ||
|
|
||
| final ScreenCapture screenCapture = Screenshot.capture(); | ||
| final Bitmap screenBitmap = screenCapture.getBitmap(); | ||
|
|
||
| final int centerLeftColor = | ||
| screenBitmap.getPixel(10, (int) Math.floor(screenBitmap.getHeight() / 2.0)); | ||
| final int centerColor = | ||
| screenBitmap.getPixel( | ||
| (int) Math.floor(screenBitmap.getWidth() / 2.0), | ||
| (int) Math.floor(screenBitmap.getHeight() / 2.0)); | ||
|
|
||
| // Flutter Colors.green color : 0xFF4CAF50 | ||
| // https://github.com/flutter/flutter/blob/f4abaa0735eba4dfd8f33f73363911d63931fe03/packages/flutter/lib/src/material/colors.dart#L1208 | ||
| // The background color of the webview is : rgba(0, 0, 0, 0.5) | ||
| // The expected color is : rgba(38, 87, 40, 1) -> 0xFF265728 | ||
| assertEquals(0xFF265728, centerLeftColor); | ||
| assertEquals(Color.RED, centerColor); | ||
| } | ||
| } | ||
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
16 changes: 16 additions & 0 deletions
16
...d/app/src/main/java/io/flutter/plugins/webviewflutterexample/DriverExtensionActivity.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,16 @@ | ||
| // 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.webviewflutterexample; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
| import io.flutter.embedding.android.FlutterActivity; | ||
|
|
||
| public class DriverExtensionActivity extends FlutterActivity { | ||
| @Override | ||
| @NonNull | ||
| public String getDartEntrypointFunctionName() { | ||
| return "appMain"; | ||
| } | ||
| } |
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.