forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[webview_flutter] Add a backgroundColor option to the Android webview (…
…flutter#4569) This PR add an option to set the background color of the Android webview. Part of: flutter#3431 Part of: flutter/flutter#29300
- Loading branch information
Showing
17 changed files
with
275 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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.