From 27c20427cc30cdd0e1e9b80002525a5a8d42a7c9 Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Tue, 18 Jul 2017 19:16:15 -0700 Subject: [PATCH] Add `PluginRegistry.Registrar#view()` (flutter/engine#3900) Sometimes, plugin instances need access to the `FlutterView`. They can currently cast the `messenger()`, but that's fragile. This adds API support for getting the view from the registry. --- .../android/io/flutter/app/FlutterActivityDelegate.java | 5 +++++ .../android/io/flutter/plugin/common/PluginRegistry.java | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java index 9639738210..0a7bf20fd5 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java @@ -289,6 +289,11 @@ public final class FlutterActivityDelegate return flutterView; } + @Override + public FlutterView view() { + return flutterView; + } + /** * Publishes a value associated with the plugin being registered. * diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/PluginRegistry.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/PluginRegistry.java index 45f4c078b5..96c75bb70c 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/PluginRegistry.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/PluginRegistry.java @@ -6,6 +6,7 @@ package io.flutter.plugin.common; import android.app.Activity; import android.content.Intent; +import io.flutter.view.FlutterView; /** * Registry used by plugins to set up interaction with Android APIs. @@ -73,6 +74,12 @@ public interface PluginRegistry { */ BinaryMessenger messenger(); + /** + * Returns the {@link FlutterView} that's instantiated by this plugin's + * {@link #activity() activity}. + */ + FlutterView view(); + /** * Publishes a value associated with the plugin being registered. *