[Android] HC++ wire up dart platform channel code and integration test. (#162751)
Use the PlatformViewController2 to register a platform view, allow the dart side platform view logic to opt into this new platform view. Wires up an integration test with android_engine_test.
This commit is contained in:
@@ -21,12 +21,12 @@ found in the LICENSE file. -->
|
||||
while the Flutter UI initializes. After that, this theme continues
|
||||
to determine the Window background behind the Flutter UI. -->
|
||||
<meta-data
|
||||
android:name="io.flutter.embedding.android.NormalTheme"
|
||||
android:resource="@style/NormalTheme"
|
||||
/>
|
||||
android:name="io.flutter.embedding.android.NormalTheme"
|
||||
android:resource="@style/NormalTheme"
|
||||
/>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Don't delete the meta-data below.
|
||||
@@ -34,6 +34,7 @@ found in the LICENSE file. -->
|
||||
<meta-data android:name="flutterEmbedding" android:value="2" />
|
||||
<meta-data android:name="io.flutter.embedding.android.EnableImpeller" android:value="true" />
|
||||
<meta-data android:name="io.flutter.embedding.android.ImpellerBackend" android:value="vulkan" />
|
||||
<meta-data android:name="io.flutter.embedding.android.EnableSurfaceControl" android:value="false" />
|
||||
</application>
|
||||
<!-- Required to query activities that can process text, see:
|
||||
https://developer.android.com/training/package-visibility and
|
||||
|
||||
@@ -13,6 +13,7 @@ import androidx.core.view.WindowInsetsControllerCompat
|
||||
import com.example.android_engine_test.extensions.NativeDriverSupportPlugin
|
||||
import com.example.android_engine_test.fixtures.BlueOrangeGradientPlatformViewFactory
|
||||
import com.example.android_engine_test.fixtures.BlueOrangeGradientSurfaceViewPlatformViewFactory
|
||||
import com.example.android_engine_test.fixtures.BoxPlatformViewFactory
|
||||
import com.example.android_engine_test.fixtures.ChangingColorButtonPlatformViewFactory
|
||||
import com.example.android_engine_test.fixtures.OtherFaceTexturePlugin
|
||||
import com.example.android_engine_test.fixtures.SmileyFaceTexturePlugin
|
||||
@@ -31,6 +32,17 @@ class MainActivity : FlutterActivity() {
|
||||
add(NativeDriverSupportPlugin())
|
||||
}
|
||||
|
||||
// TODO(jonahwilliams): make platform view controllers share platform view registry.
|
||||
flutterEngine
|
||||
.platformViewsController2
|
||||
.registry
|
||||
.apply {
|
||||
registerViewFactory("blue_orange_gradient_platform_view", BlueOrangeGradientPlatformViewFactory())
|
||||
registerViewFactory("blue_orange_gradient_surface_view_platform_view", BlueOrangeGradientSurfaceViewPlatformViewFactory())
|
||||
registerViewFactory("changing_color_button_platform_view", ChangingColorButtonPlatformViewFactory())
|
||||
registerViewFactory("box_platform_view", BoxPlatformViewFactory())
|
||||
}
|
||||
|
||||
flutterEngine
|
||||
.platformViewsController
|
||||
.registry
|
||||
@@ -38,6 +50,7 @@ class MainActivity : FlutterActivity() {
|
||||
registerViewFactory("blue_orange_gradient_platform_view", BlueOrangeGradientPlatformViewFactory())
|
||||
registerViewFactory("blue_orange_gradient_surface_view_platform_view", BlueOrangeGradientSurfaceViewPlatformViewFactory())
|
||||
registerViewFactory("changing_color_button_platform_view", ChangingColorButtonPlatformViewFactory())
|
||||
registerViewFactory("box_platform_view", BoxPlatformViewFactory())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
@file:Suppress("PackageName")
|
||||
|
||||
package com.example.android_engine_test.fixtures
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import io.flutter.plugin.platform.PlatformView
|
||||
import io.flutter.plugin.platform.PlatformViewFactory
|
||||
|
||||
class BoxPlatformViewFactory : PlatformViewFactory(null) {
|
||||
override fun create(
|
||||
context: Context,
|
||||
viewId: Int,
|
||||
args: Any?
|
||||
): PlatformView = BoxPlatformView(context)
|
||||
}
|
||||
|
||||
private class BoxPlatformView(
|
||||
context: Context
|
||||
) : View(context),
|
||||
PlatformView {
|
||||
val paint = Paint()
|
||||
|
||||
init {
|
||||
layoutParams =
|
||||
ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
}
|
||||
|
||||
override fun getView(): View = this
|
||||
|
||||
override fun dispose() {}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), paint)
|
||||
super.onDraw(canvas)
|
||||
}
|
||||
|
||||
override fun onSizeChanged(
|
||||
w: Int,
|
||||
h: Int,
|
||||
oldw: Int,
|
||||
oldh: Int
|
||||
) {
|
||||
paint.color = Color.rgb(0x41, 0x69, 0xE1)
|
||||
super.onSizeChanged(w, h, oldw, oldh)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user