Add a FlutterView level integration example on Android for add-to-app (#632)
1
add_to_app/android_view/app/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
55
add_to_app/android_view/app/build.gradle
Normal file
@@ -0,0 +1,55 @@
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
}
|
||||
|
||||
android {
|
||||
ndkVersion "21.3.6528147"
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion "30.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "dev.flutter.example.androidView"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 30
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation 'androidx.core:core-ktx:1.3.2'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'com.google.android.material:material:1.2.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.2'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.3.2'
|
||||
implementation "androidx.recyclerview:recyclerview:1.1.0"
|
||||
implementation project(path: ':flutter')
|
||||
testImplementation 'junit:junit:4.+'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
}
|
||||
21
add_to_app/android_view/app/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
23
add_to_app/android_view/app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="dev.flutter.example.androidView">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.FlutterViewIntegration">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,220 @@
|
||||
// Copyright 2019 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package dev.flutter.example.androidView
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleObserver
|
||||
import androidx.lifecycle.OnLifecycleEvent
|
||||
import io.flutter.embedding.android.FlutterView
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.platform.PlatformPlugin
|
||||
|
||||
/**
|
||||
* This is an application-specific wrapper class that exists to expose the intersection of an
|
||||
* application's active activity and an application's visible view to a [FlutterEngine] for
|
||||
* rendering.
|
||||
*
|
||||
* Omitted features from the [io.flutter.embedding.android.FlutterActivity] include:
|
||||
* * **State restoration**. If you're integrating at the view level, you should handle activity
|
||||
* state restoration yourself.
|
||||
* * **Engine creations**. At this level of granularity, you must make an engine and attach.
|
||||
* and all engine features like initial route etc must be configured on the engine yourself.
|
||||
* * **Splash screens**. You must implement it yourself. Read from
|
||||
* `addOnFirstFrameRenderedListener` as needed.
|
||||
* * **Transparency, surface/texture**. These are just [FlutterView] level APIs. Set them on the
|
||||
* [FlutterView] directly.
|
||||
* * **Intents**. This doesn't do any translation of intents into actions in the [FlutterEngine].
|
||||
* you must do them yourself.
|
||||
* * **Back buttons**. You must decide whether to send it to Flutter via
|
||||
* [FlutterEngine.getNavigationChannel.popRoute()], or consume it natively. Though that
|
||||
* decision may be difficult due to https://github.com/flutter/flutter/issues/67011.
|
||||
* * **Low memory signals**. You're strongly encouraged to pass the low memory signals (such
|
||||
* as from the host `Activity`'s `onTrimMemory` callbacks) to the [FlutterEngine] to let
|
||||
* Flutter and the Dart VM cull its own memory usage.
|
||||
*
|
||||
* Your own [FlutterView] integrating application may need a similar wrapper but you must decide on
|
||||
* what the appropriate intersection between the [FlutterView], the [FlutterEngine] and your
|
||||
* `Activity` should be for your own application.
|
||||
*/
|
||||
class FlutterViewEngine(val engine: FlutterEngine) : LifecycleObserver{
|
||||
private var flutterView: FlutterView? = null
|
||||
private var activity: ComponentActivity? = null
|
||||
private var platformPlugin: PlatformPlugin? = null
|
||||
|
||||
/**
|
||||
* This is the intersection of an available activity and of a visible [FlutterView]. This is
|
||||
* where Flutter would start rendering.
|
||||
*/
|
||||
private fun hookActivityAndView() {
|
||||
// Assert state.
|
||||
activity!!.let { activity ->
|
||||
flutterView!!.let { flutterView ->
|
||||
platformPlugin = PlatformPlugin(activity, engine.platformChannel)
|
||||
|
||||
engine.activityControlSurface.attachToActivity(activity, activity.lifecycle)
|
||||
flutterView.attachToFlutterEngine(engine)
|
||||
activity.lifecycle.addObserver(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lost the intersection of either an available activity or a visible
|
||||
* [FlutterView].
|
||||
*/
|
||||
private fun unhookActivityAndView() {
|
||||
// Stop reacting to activity events.
|
||||
activity!!.lifecycle.removeObserver(this)
|
||||
|
||||
// Plugins are no longer attached to an activity.
|
||||
engine.activityControlSurface.detachFromActivity()
|
||||
|
||||
// Release Flutter's control of UI such as system chrome.
|
||||
platformPlugin!!.destroy()
|
||||
platformPlugin = null
|
||||
|
||||
// Set Flutter's application state to detached.
|
||||
engine.lifecycleChannel.appIsDetached();
|
||||
|
||||
// Detach rendering pipeline.
|
||||
flutterView!!.detachFromFlutterEngine()
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal that a host `Activity` is now ready. If there is no [FlutterView] instance currently
|
||||
* attached to the view hierarchy and visible, Flutter is not yet rendering.
|
||||
*
|
||||
* You can also choose at this point whether to notify the plugins that an `Activity` is
|
||||
* attached or not. You can also choose at this point whether to connect a Flutter
|
||||
* [PlatformPlugin] at this point which allows your Dart program to trigger things like
|
||||
* haptic feedback and read the clipboard. This sample arbitrarily chooses no for both.
|
||||
*/
|
||||
fun attachToActivity(activity: ComponentActivity) {
|
||||
this.activity = activity
|
||||
if (flutterView != null) {
|
||||
hookActivityAndView()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal that a host `Activity` now no longer connected. If there were a [FlutterView] in
|
||||
* the view hierarchy and visible at this moment, that [FlutterView] will stop rendering.
|
||||
*
|
||||
* You can also choose at this point whether to notify the plugins that an `Activity` is
|
||||
* no longer attached or not. You can also choose at this point whether to disconnect Flutter's
|
||||
* [PlatformPlugin] at this point which stops your Dart program being able to trigger things
|
||||
* like haptic feedback and read the clipboard. This sample arbitrarily chooses yes for both.
|
||||
*/
|
||||
fun detachActivity() {
|
||||
if (flutterView != null) {
|
||||
unhookActivityAndView()
|
||||
}
|
||||
activity = null
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal that a [FlutterView] instance is created and attached to a visible Android view
|
||||
* hierarchy.
|
||||
*
|
||||
* If an `Activity` was also previously provided, this puts Flutter into the rendering state
|
||||
* for this [FlutterView]. This also connects this wrapper class to listen to the `Activity`'s
|
||||
* lifecycle to pause rendering when the activity is put into the background while the
|
||||
* view is still attached to the view hierarchy.
|
||||
*/
|
||||
fun attachFlutterView(flutterView: FlutterView) {
|
||||
this.flutterView = flutterView
|
||||
if (activity != null) {
|
||||
hookActivityAndView()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal that the attached [FlutterView] instance destroyed or no longer attached to a visible
|
||||
* Android view hierarchy.
|
||||
*
|
||||
* If an `Activity` was attached, this stops Flutter from rendering. It also makes this wrapper
|
||||
* class stop listening to the `Activity`'s lifecycle since it's no longer rendering.
|
||||
*/
|
||||
fun detachFlutterView() {
|
||||
unhookActivityAndView()
|
||||
flutterView = null
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to let Flutter respond to the `Activity`'s resumed lifecycle event while both an
|
||||
* `Activity` and a [FlutterView] are attached.
|
||||
*/
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
private fun resumeActivity() {
|
||||
if (activity != null) {
|
||||
engine.lifecycleChannel.appIsResumed()
|
||||
}
|
||||
|
||||
platformPlugin?.updateSystemUiOverlays()
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to let Flutter respond to the `Activity`'s paused lifecycle event while both an
|
||||
* `Activity` and a [FlutterView] are attached.
|
||||
*/
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||
private fun pauseActivity() {
|
||||
if (activity != null) {
|
||||
engine.lifecycleChannel.appIsInactive()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to let Flutter respond to the `Activity`'s stopped lifecycle event while both an
|
||||
* `Activity` and a [FlutterView] are attached.
|
||||
*/
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||
private fun stopActivity() {
|
||||
if (activity != null) {
|
||||
engine.lifecycleChannel.appIsPaused()
|
||||
}
|
||||
}
|
||||
|
||||
// These events aren't used but would be needed for Flutter plugins consuming
|
||||
// these events to function.
|
||||
|
||||
/**
|
||||
* Pass through the `Activity`'s `onRequestPermissionsResult` signal to plugins that may be
|
||||
* listening to it while the `Activity` and the [FlutterView] are connected.
|
||||
*/
|
||||
fun onRequestPermissionsResult(
|
||||
requestCode: Int,
|
||||
permissions: Array<out String>,
|
||||
grantResults: IntArray
|
||||
) {
|
||||
if (activity != null && flutterView != null) {
|
||||
engine
|
||||
.activityControlSurface
|
||||
.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass through the `Activity`'s `onActivityResult` signal to plugins that may be
|
||||
* listening to it while the `Activity` and the [FlutterView] are connected.
|
||||
*/
|
||||
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (activity != null && flutterView != null) {
|
||||
engine.activityControlSurface.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass through the `Activity`'s `onUserLeaveHint` signal to plugins that may be
|
||||
* listening to it while the `Activity` and the [FlutterView] are connected.
|
||||
*/
|
||||
fun onUserLeaveHint() {
|
||||
if (activity != null && flutterView != null) {
|
||||
engine.activityControlSurface.onUserLeaveHint();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
// Copyright 2019 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package dev.flutter.example.androidView
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dev.flutter.example.androidView.databinding.AndroidCardBinding
|
||||
import io.flutter.embedding.android.FlutterView
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import java.util.*
|
||||
import kotlin.random.Random
|
||||
|
||||
/**
|
||||
* A demo-specific implementation of a [RecyclerView.Adapter] to setup the demo environment used
|
||||
* to display view-level Flutter cells inside a list.
|
||||
*
|
||||
* The only instructional parts of this class are to show when to call
|
||||
* [FlutterViewEngine.attachFlutterView] and [FlutterViewEngine.detachActivity] on a
|
||||
* [FlutterViewEngine] equivalent class that you may want to create in your own application.
|
||||
*/
|
||||
class ListAdapter(context: Context, private val flutterViewEngine: FlutterViewEngine) : RecyclerView.Adapter<ListAdapter.Cell>() {
|
||||
// Save the previous cells determined to be Flutter cells to avoid a confusing visual effect
|
||||
// that the Flutter cells change position when scrolling back.
|
||||
var previousFlutterCells = TreeSet<Int>();
|
||||
|
||||
private val matchParentLayout = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
|
||||
|
||||
private val random = Random.Default
|
||||
private val flutterView = FlutterView(context)
|
||||
private val flutterChannel = MethodChannel(flutterViewEngine.engine.dartExecutor, "dev.flutter.example/cell")
|
||||
|
||||
private var flutterCell: Cell? = null
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] based on the `android_card` layout XML.
|
||||
*/
|
||||
inner class Cell(val binding: AndroidCardBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): Cell {
|
||||
val binding = AndroidCardBinding.inflate(LayoutInflater.from(viewGroup.context), viewGroup, false)
|
||||
|
||||
// Let the default view holder have an "Android card" inflated from the layout XML. When
|
||||
// needed, hide the Android card and show a Flutter one instead.
|
||||
return Cell(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(cell: Cell, position: Int) {
|
||||
// While scrolling forward, if no Flutter is presently showing, let the next one have a 1/3
|
||||
// chance of being Flutter.
|
||||
//
|
||||
// While scrolling backward, let it be deterministic, and only show cells that were
|
||||
// previously Flutter cells as Flutter cells.
|
||||
if (previousFlutterCells.contains(position)
|
||||
|| ((previousFlutterCells.isEmpty() || position > previousFlutterCells.last())
|
||||
&& flutterCell == null
|
||||
&& random.nextInt(3) == 0)) {
|
||||
// If we're restoring a cell at a previous location, the current cell may not have
|
||||
// recycled yet since that JVM timing is indeterministic. Yank it from the current one.
|
||||
//
|
||||
// This shouldn't produce any visual glitches since in the forward direction,
|
||||
// Flutter cells were only introduced once the previous Flutter cell recycled.
|
||||
if (flutterCell != null) {
|
||||
Log.w("FeedAdapter", "While restoring a previous Flutter cell, a current "
|
||||
+ "yet to be recycled Flutter cell was detached.")
|
||||
flutterCell!!.binding.root.removeView(flutterView)
|
||||
flutterViewEngine.detachFlutterView()
|
||||
flutterCell = null
|
||||
}
|
||||
|
||||
// Add the Flutter card and hide the Android card for the cells chosen to be Flutter
|
||||
// cells.
|
||||
cell.binding.root.addView(flutterView, matchParentLayout)
|
||||
cell.binding.androidCard.visibility = View.GONE
|
||||
|
||||
// Keep track of the cell so we know which one to restore back to the "Android cell"
|
||||
// state when the view gets recycled.
|
||||
flutterCell = cell
|
||||
// Keep track that this position has once been a Flutter cell. Let it be a Flutter cell
|
||||
// again when scrolling back to this position.
|
||||
previousFlutterCells.add(position)
|
||||
|
||||
// This is what makes the Flutter cell start rendering.
|
||||
flutterViewEngine.attachFlutterView(flutterView)
|
||||
// Tell Flutter which index it's at so Flutter could show the cell number too in its
|
||||
// own widget tree.
|
||||
flutterChannel.invokeMethod("setCellNumber", position)
|
||||
} else {
|
||||
// If it's not selected as a Flutter cell, just show the Android card.
|
||||
cell.binding.androidCard.visibility = View.VISIBLE
|
||||
cell.binding.cellNumber.text = position.toString();
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount() = 100
|
||||
|
||||
override fun onViewRecycled(cell: Cell) {
|
||||
if (cell == flutterCell) {
|
||||
cell.binding.root.removeView(flutterView)
|
||||
flutterViewEngine.detachFlutterView()
|
||||
flutterCell = null
|
||||
}
|
||||
super.onViewRecycled(cell)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
// Copyright 2019 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package dev.flutter.example.androidView
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import dev.flutter.example.androidView.databinding.ActivityMainBinding
|
||||
import io.flutter.FlutterInjector
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.embedding.engine.dart.DartExecutor
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
// There are 3 files in this sample. MainActivity and ListAdapter are just
|
||||
// fictional setups. FlutterViewEngine is instructional and demonstrates the
|
||||
// various plumbing needed for a functioning FlutterView integration.
|
||||
/**
|
||||
* Main activity for this demo that shows a page with a `RecyclerView`.
|
||||
*
|
||||
* There are 3 files in this sample. MainActivity and ListAdapter are just fictional setups.
|
||||
* FlutterViewEngine is instructional and demonstrates the various plumbing needed for a functioning
|
||||
* FlutterView integration.
|
||||
*/
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private lateinit var flutterViewEngine: FlutterViewEngine
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
// TODO: create a multi-engine version after
|
||||
// https://github.com/flutter/flutter/issues/72009 is built.
|
||||
val engine = FlutterEngine(applicationContext)
|
||||
engine.dartExecutor.executeDartEntrypoint(
|
||||
DartExecutor.DartEntrypoint(
|
||||
FlutterInjector.instance().flutterLoader().findAppBundlePath(),
|
||||
"showCell"))
|
||||
|
||||
flutterViewEngine = FlutterViewEngine(engine)
|
||||
// The activity and FlutterView have different lifecycles.
|
||||
// Attach the activity right away but only start rendering when the
|
||||
// view is also scrolled into the screen.
|
||||
flutterViewEngine.attachToActivity(this)
|
||||
|
||||
val layoutManager = LinearLayoutManager(this)
|
||||
val recyclerView = binding.recyclerView
|
||||
val adapter = ListAdapter(this, flutterViewEngine)
|
||||
recyclerView.layoutManager = layoutManager
|
||||
recyclerView.adapter = adapter
|
||||
|
||||
// If the activity was restarted, keep track of the previous scroll
|
||||
// position and of the previous cell indices that were randomly selected
|
||||
// as Flutter cells to preserve immersion.
|
||||
layoutManager.onRestoreInstanceState(savedInstanceState?.getParcelable<Parcelable>("layoutManager"))
|
||||
val previousFlutterCellsArray = savedInstanceState?.getIntegerArrayList("adapter")
|
||||
if (previousFlutterCellsArray != null) {
|
||||
adapter.previousFlutterCells = TreeSet(previousFlutterCellsArray)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
|
||||
outState.putParcelable("layoutManager", binding.recyclerView.layoutManager?.onSaveInstanceState())
|
||||
val previousFlutterCells = (binding.recyclerView.adapter as? ListAdapter)?.previousFlutterCells
|
||||
if (previousFlutterCells != null) {
|
||||
outState.putIntegerArrayList(
|
||||
"adapter",
|
||||
ArrayList(previousFlutterCells)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
flutterViewEngine.detachActivity()
|
||||
}
|
||||
|
||||
// These below aren't used here in this demo but would be needed for Flutter plugins that may
|
||||
// consume these events.
|
||||
|
||||
override fun onRequestPermissionsResult(
|
||||
requestCode: Int,
|
||||
permissions: Array<out String>,
|
||||
grantResults: IntArray
|
||||
) {
|
||||
flutterViewEngine.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
flutterViewEngine.onActivityResult(requestCode, resultCode, data)
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
|
||||
override fun onUserLeaveHint() {
|
||||
flutterViewEngine.onUserLeaveHint()
|
||||
super.onUserLeaveHint()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M3,13h8L11,3L3,3v10zM3,21h8v-6L3,15v6zM13,21h8L21,11h-8v10zM13,3v6h8L21,3h-8z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#3DDC84"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="160dp">
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/androidCard"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginHorizontal="36dp"
|
||||
android:layout_marginVertical="24dp"
|
||||
app:cardBackgroundColor="#F1F1F1"
|
||||
app:cardCornerRadius="16dp"
|
||||
app:cardElevation="16dp">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/cellNumber"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:textAppearance="?attr/textAppearanceHeadline3"/>
|
||||
</FrameLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
</FrameLayout>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 7.3 KiB |
|
After Width: | Height: | Size: 7.7 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,16 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.FlutterViewIntegration" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/purple_200</item>
|
||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||
<item name="colorOnPrimary">@color/black</item>
|
||||
<!-- Secondary brand color. -->
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_200</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Status bar color. -->
|
||||
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
</resources>
|
||||
10
add_to_app/android_view/app/src/main/res/values/colors.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="purple_200">#FFBB86FC</color>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,5 @@
|
||||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
</resources>
|
||||
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">Flutter View Integration</string>
|
||||
</resources>
|
||||
16
add_to_app/android_view/app/src/main/res/values/themes.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.FlutterViewIntegration" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/purple_500</item>
|
||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||
<item name="colorOnPrimary">@color/white</item>
|
||||
<!-- Secondary brand color. -->
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_700</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Status bar color. -->
|
||||
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
</resources>
|
||||