Commit 35b9977f authored by yangwu.jia's avatar yangwu.jia

Merge branch 'feature/flutter_1.9_upgrade' into feature/flutter_1.9_androidx_upgrade

# Conflicts:
#	android/src/main/java/com/idlefish/flutterboost/BoostPluginRegistry.java
parents 28e3e2e7 21ebee21
package com.idlefish.flutterboost; package com.idlefish.flutterboost;
import android.app.Activity;
import android.content.Context; import io.flutter.Log;
import androidx.annotation.Nullable;
import com.idlefish.flutterboost.interfaces.IContainerRecord;
import io.flutter.app.FlutterPluginRegistry;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry; import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger; import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.PluginRegistry; import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.platform.PlatformViewRegistry;
import io.flutter.view.FlutterView;
import io.flutter.view.TextureRegistry;
import java.lang.ref.WeakReference; import java.util.*;
public class BoostPluginRegistry extends ShimPluginRegistry {
protected WeakReference<Activity> mCurrentActivityRef;
private FlutterEngine mEngine; public class BoostPluginRegistry implements PluginRegistry {
private Context mContext; private static final String TAG = "ShimPluginRegistry";
public BoostPluginRegistry(FlutterEngine engine, Context context) { private final FlutterEngine flutterEngine;
super(engine); private final Map<String, Object> pluginMap = new HashMap();
mEngine = engine; private final BoostRegistrarAggregate shimRegistrarAggregate;
mContext=context;
}
public BoostRegistrarAggregate getRegistrarAggregate() {
return shimRegistrarAggregate;
}
public BoostPluginRegistry(FlutterEngine flutterEngine) {
this.flutterEngine = flutterEngine;
this.shimRegistrarAggregate = new BoostRegistrarAggregate();
this.flutterEngine.getPlugins().add(this.shimRegistrarAggregate);
}
public PluginRegistry.Registrar registrarFor(String pluginKey) { public Registrar registrarFor(String pluginKey) {
return new BoostRegistrar(mEngine, super.registrarFor(pluginKey)); Log.v("ShimPluginRegistry", "Creating plugin Registrar for '" + pluginKey + "'");
if (this.pluginMap.containsKey(pluginKey)) {
throw new IllegalStateException("Plugin key " + pluginKey + " is already in use");
} else {
this.pluginMap.put(pluginKey, (Object) null);
BoostRegistrar registrar = new BoostRegistrar(pluginKey, this.pluginMap);
this.shimRegistrarAggregate.addPlugin(registrar);
return registrar;
} }
}
public void currentActivity(@Nullable Activity activity) { public boolean hasPlugin(String pluginKey) {
mCurrentActivityRef = new WeakReference<>(activity); return this.pluginMap.containsKey(pluginKey);
} }
public class BoostRegistrar implements PluginRegistry.Registrar { public Object valuePublishedByPlugin(String pluginKey) {
return this.pluginMap.get(pluginKey);
}
private final PluginRegistry.Registrar mRegistrar; public static class BoostRegistrarAggregate implements FlutterPlugin, ActivityAware {
private final FlutterEngine mEngine; private final Set<BoostRegistrar> shimRegistrars;
private FlutterPluginBinding flutterPluginBinding;
private ActivityPluginBinding activityPluginBinding;
BoostRegistrar(FlutterEngine engine, PluginRegistry.Registrar registrar) { public ActivityPluginBinding getActivityPluginBinding() {
mRegistrar = registrar; return activityPluginBinding;
mEngine = engine;
} }
@Override private BoostRegistrarAggregate() {
public Activity activity() { this.shimRegistrars = new HashSet();
Activity activity; }
IContainerRecord record;
record = NewFlutterBoost.instance().containerManager().getCurrentTopRecord(); public void addPlugin(BoostRegistrar shimRegistrar) {
if (record == null) { this.shimRegistrars.add(shimRegistrar);
record = NewFlutterBoost.instance().containerManager().getLastGenerateRecord(); if (this.flutterPluginBinding != null) {
shimRegistrar.onAttachedToEngine(this.flutterPluginBinding);
} }
if (record == null) { if (this.activityPluginBinding != null) {
activity = NewFlutterBoost.instance().currentActivity(); shimRegistrar.onAttachedToActivity(this.activityPluginBinding);
} else {
activity = record.getContainer().getContextActivity();
} }
if (activity == null && mCurrentActivityRef != null) { }
activity = mCurrentActivityRef.get();
} public void onAttachedToEngine(FlutterPluginBinding binding) {
this.flutterPluginBinding = binding;
Iterator var2 = this.shimRegistrars.iterator();
if (activity == null) { while (var2.hasNext()) {
throw new RuntimeException("current has no valid Activity yet"); BoostRegistrar shimRegistrar = (BoostRegistrar) var2.next();
shimRegistrar.onAttachedToEngine(binding);
} }
return activity;
} }
@Override public void onDetachedFromEngine(FlutterPluginBinding binding) {
public Context context() { Iterator var2 = this.shimRegistrars.iterator();
return BoostPluginRegistry.this.mContext;
}
@Override while (var2.hasNext()) {
public Context activeContext() { BoostRegistrar shimRegistrar = (BoostRegistrar) var2.next();
return BoostPluginRegistry.this.mContext; shimRegistrar.onDetachedFromEngine(binding);
} }
@Override this.flutterPluginBinding = null;
public BinaryMessenger messenger() {
return mEngine.getDartExecutor();
} }
@Override public void onAttachedToActivity(ActivityPluginBinding binding) {
public TextureRegistry textures() { this.activityPluginBinding = binding;
return mEngine.getRenderer(); Iterator var2 = this.shimRegistrars.iterator();
}
@Override while (var2.hasNext()) {
public PlatformViewRegistry platformViewRegistry() { BoostRegistrar shimRegistrar = (BoostRegistrar) var2.next();
return mEngine.getPlatformViewsController().getRegistry(); shimRegistrar.onAttachedToActivity(binding);
} }
@Override
public FlutterView view() {
throw new RuntimeException("should not use!!!");
} }
@Override public void onDetachedFromActivityForConfigChanges() {
public String lookupKeyForAsset(String s) { Iterator var1 = this.shimRegistrars.iterator();
return mRegistrar.lookupKeyForAsset(s);
}
@Override while (var1.hasNext()) {
public String lookupKeyForAsset(String s, String s1) { BoostRegistrar shimRegistrar = (BoostRegistrar) var1.next();
return mRegistrar.lookupKeyForAsset(s, s1); shimRegistrar.onDetachedFromActivity();
} }
@Override this.activityPluginBinding = null;
public PluginRegistry.Registrar publish(Object o) {
return mRegistrar.publish(o);
} }
@Override public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding) {
public PluginRegistry.Registrar addRequestPermissionsResultListener(PluginRegistry.RequestPermissionsResultListener requestPermissionsResultListener) { Iterator var2 = this.shimRegistrars.iterator();
return mRegistrar.addRequestPermissionsResultListener(requestPermissionsResultListener);
}
@Override while (var2.hasNext()) {
public PluginRegistry.Registrar addActivityResultListener(PluginRegistry.ActivityResultListener activityResultListener) { BoostRegistrar shimRegistrar = (BoostRegistrar) var2.next();
return mRegistrar.addActivityResultListener(activityResultListener); shimRegistrar.onReattachedToActivityForConfigChanges(binding);
} }
@Override
public PluginRegistry.Registrar addNewIntentListener(PluginRegistry.NewIntentListener newIntentListener) {
return mRegistrar.addNewIntentListener(newIntentListener);
} }
@Override public void onDetachedFromActivity() {
public PluginRegistry.Registrar addUserLeaveHintListener(PluginRegistry.UserLeaveHintListener userLeaveHintListener) { Iterator var1 = this.shimRegistrars.iterator();
return mRegistrar.addUserLeaveHintListener(userLeaveHintListener);
} while (var1.hasNext()) {
BoostRegistrar shimRegistrar = (BoostRegistrar) var1.next();
shimRegistrar.onDetachedFromActivity();
}
@Override
public PluginRegistry.Registrar addViewDestroyListener(PluginRegistry.ViewDestroyListener viewDestroyListener) {
return mRegistrar.addViewDestroyListener(viewDestroyListener);
} }
} }
} }
package com.idlefish.flutterboost;
import android.app.Activity;
import android.content.Context;
import android.support.annotation.NonNull;
import io.flutter.Log;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.PluginRegistry.ActivityResultListener;
import io.flutter.plugin.common.PluginRegistry.NewIntentListener;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.plugin.common.PluginRegistry.RequestPermissionsResultListener;
import io.flutter.plugin.common.PluginRegistry.UserLeaveHintListener;
import io.flutter.plugin.common.PluginRegistry.ViewDestroyListener;
import io.flutter.plugin.platform.PlatformViewRegistry;
import io.flutter.view.FlutterMain;
import io.flutter.view.FlutterNativeView;
import io.flutter.view.FlutterView;
import io.flutter.view.TextureRegistry;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
class BoostRegistrar implements Registrar, FlutterPlugin, ActivityAware {
private static final String TAG = "ShimRegistrar";
private final Map<String, Object> globalRegistrarMap;
private final String pluginId;
private final Set<ViewDestroyListener> viewDestroyListeners = new HashSet();
private final Set<RequestPermissionsResultListener> requestPermissionsResultListeners = new HashSet();
private final Set<ActivityResultListener> activityResultListeners = new HashSet();
private final Set<NewIntentListener> newIntentListeners = new HashSet();
private final Set<UserLeaveHintListener> userLeaveHintListeners = new HashSet();
private FlutterPluginBinding pluginBinding;
private ActivityPluginBinding activityPluginBinding;
public BoostRegistrar(@NonNull String pluginId, @NonNull Map<String, Object> globalRegistrarMap) {
this.pluginId = pluginId;
this.globalRegistrarMap = globalRegistrarMap;
}
public Activity activity() {
if(this.activityPluginBinding != null){
return this.activityPluginBinding.getActivity();
}
if(NewFlutterBoost.instance().currentActivity()!=null){
return NewFlutterBoost.instance().currentActivity();
}
return null;
}
public Context context() {
return this.pluginBinding != null ? this.pluginBinding.getApplicationContext() : null;
}
public Context activeContext() {
return (Context)(this.activityPluginBinding == null ? this.context() : this.activity());
}
public BinaryMessenger messenger() {
return this.pluginBinding != null ? this.pluginBinding.getFlutterEngine().getDartExecutor() : null;
}
public TextureRegistry textures() {
return this.pluginBinding != null ? this.pluginBinding.getFlutterEngine().getRenderer() : null;
}
public PlatformViewRegistry platformViewRegistry() {
return this.pluginBinding != null ? this.pluginBinding.getFlutterEngine().getPlatformViewsController().getRegistry() : null;
}
public FlutterView view() {
throw new UnsupportedOperationException("The new embedding does not support the old FlutterView.");
}
public String lookupKeyForAsset(String asset) {
return FlutterMain.getLookupKeyForAsset(asset);
}
public String lookupKeyForAsset(String asset, String packageName) {
return FlutterMain.getLookupKeyForAsset(asset, packageName);
}
public Registrar publish(Object value) {
this.globalRegistrarMap.put(this.pluginId, value);
return this;
}
public Registrar addRequestPermissionsResultListener(RequestPermissionsResultListener listener) {
this.requestPermissionsResultListeners.add(listener);
if (this.activityPluginBinding != null) {
this.activityPluginBinding.addRequestPermissionsResultListener(listener);
}
return this;
}
public Registrar addActivityResultListener(ActivityResultListener listener) {
this.activityResultListeners.add(listener);
if (this.activityPluginBinding != null) {
this.activityPluginBinding.addActivityResultListener(listener);
}
return this;
}
public Registrar addNewIntentListener(NewIntentListener listener) {
this.newIntentListeners.add(listener);
if (this.activityPluginBinding != null) {
this.activityPluginBinding.addOnNewIntentListener(listener);
}
return this;
}
public Registrar addUserLeaveHintListener(UserLeaveHintListener listener) {
this.userLeaveHintListeners.add(listener);
if (this.activityPluginBinding != null) {
this.activityPluginBinding.addOnUserLeaveHintListener(listener);
}
return this;
}
@NonNull
public Registrar addViewDestroyListener(@NonNull ViewDestroyListener listener) {
this.viewDestroyListeners.add(listener);
return this;
}
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
Log.v("ShimRegistrar", "Attached to FlutterEngine.");
this.pluginBinding = binding;
}
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
Log.v("ShimRegistrar", "Detached from FlutterEngine.");
Iterator var2 = this.viewDestroyListeners.iterator();
while(var2.hasNext()) {
ViewDestroyListener listener = (ViewDestroyListener)var2.next();
listener.onViewDestroy((FlutterNativeView)null);
}
this.pluginBinding = null;
}
public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) {
Log.v("ShimRegistrar", "Attached to an Activity.");
this.activityPluginBinding = binding;
this.addExistingListenersToActivityPluginBinding();
}
public void onDetachedFromActivityForConfigChanges() {
Log.v("ShimRegistrar", "Detached from an Activity for config changes.");
this.activityPluginBinding = null;
}
public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) {
Log.v("ShimRegistrar", "Reconnected to an Activity after config changes.");
this.activityPluginBinding = binding;
this.addExistingListenersToActivityPluginBinding();
}
public void onDetachedFromActivity() {
Log.v("ShimRegistrar", "Detached from an Activity.");
this.activityPluginBinding = null;
}
private void addExistingListenersToActivityPluginBinding() {
Iterator var1 = this.requestPermissionsResultListeners.iterator();
while(var1.hasNext()) {
RequestPermissionsResultListener listener = (RequestPermissionsResultListener)var1.next();
this.activityPluginBinding.addRequestPermissionsResultListener(listener);
}
var1 = this.activityResultListeners.iterator();
while(var1.hasNext()) {
ActivityResultListener listener = (ActivityResultListener)var1.next();
this.activityPluginBinding.addActivityResultListener(listener);
}
var1 = this.newIntentListeners.iterator();
while(var1.hasNext()) {
NewIntentListener listener = (NewIntentListener)var1.next();
this.activityPluginBinding.addOnNewIntentListener(listener);
}
var1 = this.userLeaveHintListeners.iterator();
while(var1.hasNext()) {
UserLeaveHintListener listener = (UserLeaveHintListener)var1.next();
this.activityPluginBinding.addOnUserLeaveHintListener(listener);
}
}
}
...@@ -175,6 +175,7 @@ public class ContainerRecord implements IContainerRecord { ...@@ -175,6 +175,7 @@ public class ContainerRecord implements IContainerRecord {
@Override @Override
public void onContainerResult(int requestCode, int resultCode, Map<String, Object> result) { public void onContainerResult(int requestCode, int resultCode, Map<String, Object> result) {
mManager.setContainerResult(this, requestCode,resultCode, result);
} }
...@@ -192,41 +193,6 @@ public class ContainerRecord implements IContainerRecord { ...@@ -192,41 +193,6 @@ public class ContainerRecord implements IContainerRecord {
public void onLowMemory() { public void onLowMemory() {
} }
//
// @Override
// public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
// mContainer.getBoostFlutterView().onRequestPermissionsResult(requestCode, permissions, grantResults);
// }
//
// @Override
// public void onNewIntent(Intent intent) {
// mContainer.getBoostFlutterView().onNewIntent(intent);
// }
//
// @Override
// public void onActivityResult(int requestCode, int resultCode, Intent data) {
// mContainer.getBoostFlutterView().onActivityResult(requestCode, resultCode, data);
// }
//
// @Override
// public void onContainerResult(int requestCode, int resultCode, Map<String, Object> result) {
// mManager.setContainerResult(this, requestCode,resultCode, result);
// }
//
// @Override
// public void onUserLeaveHint() {
// mContainer.getBoostFlutterView().onUserLeaveHint();
// }
//
// @Override
// public void onTrimMemory(int level) {
// mContainer.getBoostFlutterView().onTrimMemory(level);
// }
//
// @Override
// public void onLowMemory() {
// mContainer.getBoostFlutterView().onLowMemory();
// }
private class MethodChannelProxy { private class MethodChannelProxy {
......
...@@ -12,10 +12,12 @@ import io.flutter.embedding.android.FlutterView; ...@@ -12,10 +12,12 @@ import io.flutter.embedding.android.FlutterView;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs; import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.dart.DartExecutor; import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry; import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;
import io.flutter.plugin.common.PluginRegistry; import io.flutter.plugin.common.PluginRegistry;
import io.flutter.view.FlutterMain; import io.flutter.view.FlutterMain;
import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -29,7 +31,6 @@ public class NewFlutterBoost { ...@@ -29,7 +31,6 @@ public class NewFlutterBoost {
private PluginRegistry mRegistry; private PluginRegistry mRegistry;
static NewFlutterBoost sInstance = null; static NewFlutterBoost sInstance = null;
public static NewFlutterBoost instance() { public static NewFlutterBoost instance() {
if (sInstance == null) { if (sInstance == null) {
sInstance = new NewFlutterBoost(); sInstance = new NewFlutterBoost();
...@@ -154,18 +155,10 @@ public class NewFlutterBoost { ...@@ -154,18 +155,10 @@ public class NewFlutterBoost {
FlutterMain.findAppBundlePath(), FlutterMain.findAppBundlePath(),
"main" "main"
); );
flutterEngine.getDartExecutor().executeDartEntrypoint(entrypoint);
mRegistry = new BoostPluginRegistry(createEngine(),mPlatform.getApplication());
((BoostPluginRegistry) mRegistry).currentActivity(mCurrentActiveActivity);
mPlatform.registerPlugins(mRegistry);
if(mPlatform.lifecycleListener!=null){
mPlatform.lifecycleListener.onPluginsRegistered();
}
flutterEngine.getDartExecutor().executeDartEntrypoint(entrypoint);
mRegistry = new BoostPluginRegistry(createEngine());
registerPlugins();
} }
...@@ -192,7 +185,7 @@ public class NewFlutterBoost { ...@@ -192,7 +185,7 @@ public class NewFlutterBoost {
private boolean isDebug = false; private boolean isDebug = false;
private FlutterView.RenderMode renderMode = FlutterView.RenderMode.surface; private FlutterView.RenderMode renderMode = FlutterView.RenderMode.texture;
private Application mApp; private Application mApp;
...@@ -322,6 +315,22 @@ public class NewFlutterBoost { ...@@ -322,6 +315,22 @@ public class NewFlutterBoost {
} }
private void registerPlugins() {
try {
Class clz = Class.forName("io.flutter.plugins.GeneratedPluginRegistrant");
Method method = clz.getDeclaredMethod("registerWith", PluginRegistry.class);
method.invoke(null, mRegistry);
} catch (Throwable t) {
throw new RuntimeException(t);
}
if(mPlatform.lifecycleListener!=null){
mPlatform.lifecycleListener.onPluginsRegistered();
}
}
public FlutterEngine engineProvider() { public FlutterEngine engineProvider() {
return mEngine; return mEngine;
} }
......
...@@ -34,15 +34,7 @@ public abstract class Platform { ...@@ -34,15 +34,7 @@ public abstract class Platform {
} }
public void registerPlugins(PluginRegistry registry) {
try {
Class clz = Class.forName("io.flutter.plugins.GeneratedPluginRegistrant");
Method method = clz.getDeclaredMethod("registerWith", PluginRegistry.class);
method.invoke(null, registry);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
} }
package com.idlefish.flutterboost;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import io.flutter.embedding.engine.systemchannels.KeyEventChannel;
import io.flutter.plugin.editing.TextInputPlugin;
public class XAndroidKeyProcessor {
@NonNull
private final KeyEventChannel keyEventChannel;
@NonNull
private final XTextInputPlugin textInputPlugin;
private int combiningCharacter;
public XAndroidKeyProcessor(@NonNull KeyEventChannel keyEventChannel, @NonNull XTextInputPlugin textInputPlugin) {
this.keyEventChannel = keyEventChannel;
this.textInputPlugin = textInputPlugin;
}
public void onKeyUp(@NonNull KeyEvent keyEvent) {
Character complexCharacter = applyCombiningCharacterToBaseCharacter(keyEvent.getUnicodeChar());
keyEventChannel.keyUp(
new KeyEventChannel.FlutterKeyEvent(keyEvent, complexCharacter)
);
}
public void onKeyDown(@NonNull KeyEvent keyEvent) {
if (textInputPlugin.getLastInputConnection() != null
&& textInputPlugin.getInputMethodManager().isAcceptingText()) {
textInputPlugin.getLastInputConnection().sendKeyEvent(keyEvent);
}
Character complexCharacter = applyCombiningCharacterToBaseCharacter(keyEvent.getUnicodeChar());
keyEventChannel.keyDown(
new KeyEventChannel.FlutterKeyEvent(keyEvent, complexCharacter)
);
}
/**
* Applies the given Unicode character in {@code newCharacterCodePoint} to a previously
* entered Unicode combining character and returns the combination of these characters
* if a combination exists.
* <p>
* This method mutates {@link #combiningCharacter} over time to combine characters.
* <p>
* One of the following things happens in this method:
* <ul>
* <li>If no previous {@link #combiningCharacter} exists and the {@code newCharacterCodePoint}
* is not a combining character, then {@code newCharacterCodePoint} is returned.</li>
* <li>If no previous {@link #combiningCharacter} exists and the {@code newCharacterCodePoint}
* is a combining character, then {@code newCharacterCodePoint} is saved as the
* {@link #combiningCharacter} and null is returned.</li>
* <li>If a previous {@link #combiningCharacter} exists and the {@code newCharacterCodePoint}
* is also a combining character, then the {@code newCharacterCodePoint} is combined with
* the existing {@link #combiningCharacter} and null is returned.</li>
* <li>If a previous {@link #combiningCharacter} exists and the {@code newCharacterCodePoint}
* is not a combining character, then the {@link #combiningCharacter} is applied to the
* regular {@code newCharacterCodePoint} and the resulting complex character is returned. The
* {@link #combiningCharacter} is cleared.</li>
* </ul>
* <p>
* The following reference explains the concept of a "combining character":
* https://en.wikipedia.org/wiki/Combining_character
*/
@Nullable
private Character applyCombiningCharacterToBaseCharacter(int newCharacterCodePoint) {
if (newCharacterCodePoint == 0) {
return null;
}
Character complexCharacter = (char) newCharacterCodePoint;
boolean isNewCodePointACombiningCharacter = (newCharacterCodePoint & KeyCharacterMap.COMBINING_ACCENT) != 0;
if (isNewCodePointACombiningCharacter) {
// If a combining character was entered before, combine this one with that one.
int plainCodePoint = newCharacterCodePoint & KeyCharacterMap.COMBINING_ACCENT_MASK;
if (combiningCharacter != 0) {
combiningCharacter = KeyCharacterMap.getDeadChar(combiningCharacter, plainCodePoint);
} else {
combiningCharacter = plainCodePoint;
}
} else {
// The new character is a regular character. Apply combiningCharacter to it, if it exists.
if (combiningCharacter != 0) {
int combinedChar = KeyCharacterMap.getDeadChar(combiningCharacter, newCharacterCodePoint);
if (combinedChar > 0) {
complexCharacter = (char) combinedChar;
}
combiningCharacter = 0;
}
}
return complexCharacter;
}
}
\ No newline at end of file
...@@ -90,14 +90,16 @@ public class XFlutterView extends FrameLayout { ...@@ -90,14 +90,16 @@ public class XFlutterView extends FrameLayout {
// These components essentially add some additional behavioral logic on top of // These components essentially add some additional behavioral logic on top of
// existing, stateless system channels, e.g., KeyEventChannel, TextInputChannel, etc. // existing, stateless system channels, e.g., KeyEventChannel, TextInputChannel, etc.
@Nullable @Nullable
private TextInputPlugin textInputPlugin; private XTextInputPlugin textInputPlugin;
@Nullable @Nullable
private AndroidKeyProcessor androidKeyProcessor; private XAndroidKeyProcessor androidKeyProcessor;
@Nullable @Nullable
private AndroidTouchProcessor androidTouchProcessor; private AndroidTouchProcessor androidTouchProcessor;
@Nullable @Nullable
private AccessibilityBridge accessibilityBridge; private AccessibilityBridge accessibilityBridge;
private boolean hasAddFirstFrameRenderedListener=false;
// Directly implemented View behavior that communicates with Flutter. // Directly implemented View behavior that communicates with Flutter.
private final FlutterRenderer.ViewportMetrics viewportMetrics = new FlutterRenderer.ViewportMetrics(); private final FlutterRenderer.ViewportMetrics viewportMetrics = new FlutterRenderer.ViewportMetrics();
...@@ -566,6 +568,7 @@ public class XFlutterView extends FrameLayout { ...@@ -566,6 +568,7 @@ public class XFlutterView extends FrameLayout {
* See {@link #detachFromFlutterEngine()} for information on how to detach from a * See {@link #detachFromFlutterEngine()} for information on how to detach from a
* {@link FlutterEngine}. * {@link FlutterEngine}.
*/ */
public void attachToFlutterEngine( public void attachToFlutterEngine(
@NonNull FlutterEngine flutterEngine @NonNull FlutterEngine flutterEngine
) { ) {
...@@ -582,27 +585,35 @@ public class XFlutterView extends FrameLayout { ...@@ -582,27 +585,35 @@ public class XFlutterView extends FrameLayout {
+ " to new engine."); + " to new engine.");
detachFromFlutterEngine(); detachFromFlutterEngine();
} }
this.requestFocus();
this.flutterEngine = flutterEngine; this.flutterEngine = flutterEngine;
// Instruct our FlutterRenderer that we are now its designated RenderSurface. // Instruct our FlutterRenderer that we are now its designated RenderSurface.
FlutterRenderer flutterRenderer = this.flutterEngine.getRenderer(); FlutterRenderer flutterRenderer = this.flutterEngine.getRenderer();
didRenderFirstFrame = flutterRenderer.hasRenderedFirstFrame(); didRenderFirstFrame = flutterRenderer.hasRenderedFirstFrame();
if(!hasAddFirstFrameRenderedListener){
flutterRenderer.addOnFirstFrameRenderedListener(onFirstFrameRenderedListener);
hasAddFirstFrameRenderedListener=true;
}
flutterRenderer.attachToRenderSurface(renderSurface); flutterRenderer.attachToRenderSurface(renderSurface);
flutterRenderer.addOnFirstFrameRenderedListener(onFirstFrameRenderedListener);
// Initialize various components that know how to process Android View I/O // Initialize various components that know how to process Android View I/O
// in a way that Flutter understands. // in a way that Flutter understands.
if(this.textInputPlugin!=null){
this.textInputPlugin.destroy();
resolveMemoryLeaks();
if(textInputPlugin==null){
textInputPlugin = new XTextInputPlugin(
this,
flutterEngine.getTextInputChannel(),
this.flutterEngine.getPlatformViewsController()
);
} }
this.textInputPlugin = new TextInputPlugin(this, this.flutterEngine.getDartExecutor(), this.flutterEngine.getPlatformViewsController()); textInputPlugin.setTextInputMethodHandler();
textInputPlugin.getInputMethodManager().restartInput(this);
this.androidKeyProcessor = new AndroidKeyProcessor( this.androidKeyProcessor = new XAndroidKeyProcessor(
this.flutterEngine.getKeyEventChannel(), this.flutterEngine.getKeyEventChannel(),
textInputPlugin textInputPlugin
); );
...@@ -643,9 +654,9 @@ public class XFlutterView extends FrameLayout { ...@@ -643,9 +654,9 @@ public class XFlutterView extends FrameLayout {
// If the first frame has already been rendered, notify all first frame listeners. // If the first frame has already been rendered, notify all first frame listeners.
// Do this after all other initialization so that listeners don't inadvertently interact // Do this after all other initialization so that listeners don't inadvertently interact
// with a FlutterView that is only partially attached to a FlutterEngine. // with a FlutterView that is only partially attached to a FlutterEngine.
if (didRenderFirstFrame) { // if (didRenderFirstFrame) {
onFirstFrameRenderedListener.onFirstFrameRendered(); // onFirstFrameRenderedListener.onFirstFrameRendered();
} // }
} }
/** /**
...@@ -681,9 +692,8 @@ public class XFlutterView extends FrameLayout { ...@@ -681,9 +692,8 @@ public class XFlutterView extends FrameLayout {
// now that the engine is detached. The new InputConnection will be null, which // now that the engine is detached. The new InputConnection will be null, which
// signifies that this View does not process input (until a new engine is attached). // signifies that this View does not process input (until a new engine is attached).
// TODO(mattcarroll): once this is proven to work, move this line ot TextInputPlugin // TODO(mattcarroll): once this is proven to work, move this line ot TextInputPlugin
textInputPlugin.getInputMethodManager().restartInput(this);
textInputPlugin.destroy(); // resolveMemoryLeaks();
resolveMemoryLeaks();
// Instruct our FlutterRenderer that we are no longer interested in being its RenderSurface. // Instruct our FlutterRenderer that we are no longer interested in being its RenderSurface.
FlutterRenderer flutterRenderer = flutterEngine.getRenderer(); FlutterRenderer flutterRenderer = flutterEngine.getRenderer();
// didRenderFirstFrame = false; // didRenderFirstFrame = false;
...@@ -691,7 +701,9 @@ public class XFlutterView extends FrameLayout { ...@@ -691,7 +701,9 @@ public class XFlutterView extends FrameLayout {
flutterRenderer.detachFromRenderSurface(); flutterRenderer.detachFromRenderSurface();
flutterEngine = null; flutterEngine = null;
} }
public void release(){
textInputPlugin.release();
}
public void resolveMemoryLeaks(){ public void resolveMemoryLeaks(){
try { try {
......
...@@ -15,9 +15,11 @@ import android.view.ViewGroup; ...@@ -15,9 +15,11 @@ import android.view.ViewGroup;
import java.io.Serializable; import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.idlefish.flutterboost.BoostPluginRegistry;
import com.idlefish.flutterboost.NewFlutterBoost; import com.idlefish.flutterboost.NewFlutterBoost;
import com.idlefish.flutterboost.Utils; import com.idlefish.flutterboost.Utils;
import com.idlefish.flutterboost.XFlutterView; import com.idlefish.flutterboost.XFlutterView;
...@@ -28,6 +30,7 @@ import io.flutter.app.FlutterActivity; ...@@ -28,6 +30,7 @@ import io.flutter.app.FlutterActivity;
import io.flutter.embedding.android.*; import io.flutter.embedding.android.*;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs; import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.platform.PlatformPlugin; import io.flutter.plugin.platform.PlatformPlugin;
import io.flutter.view.FlutterMain; import io.flutter.view.FlutterMain;
...@@ -74,13 +77,15 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine ...@@ -74,13 +77,15 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
return flutterEngine; return flutterEngine;
} }
XFlutterView getFlutterView(){
return flutterView;
}
void onAttach(@NonNull Context context) { void onAttach(@NonNull Context context) {
ensureAlive(); ensureAlive();
if (NewFlutterBoost.instance().platform().whenEngineStart() == NewFlutterBoost.ConfigBuilder.FLUTTER_ACTIVITY_CREATED) { if (NewFlutterBoost.instance().platform().whenEngineStart() == NewFlutterBoost.ConfigBuilder.FLUTTER_ACTIVITY_CREATED) {
NewFlutterBoost.instance().doInitialFlutter(); NewFlutterBoost.instance().doInitialFlutter();
} }
// When "retain instance" is true, the FlutterEngine will survive configuration // When "retain instance" is true, the FlutterEngine will survive configuration
// changes. Therefore, we create a new one only if one does not already exist. // changes. Therefore, we create a new one only if one does not already exist.
if (flutterEngine == null) { if (flutterEngine == null) {
...@@ -95,23 +100,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine ...@@ -95,23 +100,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
// use-cases. // use-cases.
platformPlugin = host.providePlatformPlugin(host.getActivity(), flutterEngine); platformPlugin = host.providePlatformPlugin(host.getActivity(), flutterEngine);
if (host.shouldAttachEngineToActivity()) {
// Notify any plugins that are currently attached to our FlutterEngine that they
// are now attached to an Activity.
//
// Passing this Fragment's Lifecycle should be sufficient because as long as this Fragment
// is attached to its Activity, the lifecycles should be in sync. Once this Fragment is
// detached from its Activity, that Activity will be detached from the FlutterEngine, too,
// which means there shouldn't be any possibility for the Fragment Lifecycle to get out of
// sync with the Activity. We use the Fragment's Lifecycle because it is possible that the
// attached Activity is not a LifecycleOwner.
Log.d(TAG, "Attaching FlutterEngine to the Activity that owns this Fragment.");
flutterEngine.getActivityControlSurface().attachToActivity(
host.getActivity(),
host.getLifecycle()
);
}
host.configureFlutterEngine(flutterEngine); host.configureFlutterEngine(flutterEngine);
} }
...@@ -142,6 +130,11 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine ...@@ -142,6 +130,11 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
@NonNull @NonNull
View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Log.v(TAG, "Creating FlutterView."); Log.v(TAG, "Creating FlutterView.");
flutterEngine.getActivityControlSurface().attachToActivity(
host.getActivity(),
host.getLifecycle()
);
mSyncer = NewFlutterBoost.instance().containerManager().generateSyncer(this); mSyncer = NewFlutterBoost.instance().containerManager().generateSyncer(this);
...@@ -184,22 +177,24 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine ...@@ -184,22 +177,24 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
Log.v(TAG, "onResume()"); Log.v(TAG, "onResume()");
ensureAlive(); ensureAlive();
flutterEngine.getLifecycleChannel().appIsResumed(); flutterEngine.getLifecycleChannel().appIsResumed();
BoostPluginRegistry registry= (BoostPluginRegistry)NewFlutterBoost.instance().getPluginRegistry();
ActivityPluginBinding binding=registry.getRegistrarAggregate().getActivityPluginBinding();
if(binding!=null&&(binding.getActivity()!=this.host.getActivity())){
flutterEngine.getActivityControlSurface().attachToActivity(
host.getActivity(),
host.getLifecycle()
);
}
} }
void onPostResume() { void onPostResume() {
Log.v(TAG, "onPostResume()"); Log.v(TAG, "onPostResume()");
ensureAlive(); ensureAlive();
if (flutterEngine != null) { Utils.setStatusBarLightMode(host.getActivity(),true);
if (platformPlugin != null) {
// TODO(mattcarroll): find a better way to handle the update of UI overlays than calling through
// to platformPlugin. We're implicitly entangling the Window, Activity, Fragment,
// and engine all with this one call.
platformPlugin.updateSystemUiOverlays();
}
} else {
Log.w(TAG, "onPostResume() invoked before NewFlutterFragment was attached to an Activity.");
}
} }
...@@ -215,7 +210,8 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine ...@@ -215,7 +210,8 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
void onStop() { void onStop() {
Log.v(TAG, "onStop()"); Log.v(TAG, "onStop()");
ensureAlive(); ensureAlive();
// flutterView.detachFromFlutterEngine();
} }
void onDestroyView() { void onDestroyView() {
...@@ -223,6 +219,14 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine ...@@ -223,6 +219,14 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
mSyncer.onDestroy(); mSyncer.onDestroy();
ensureAlive(); ensureAlive();
BoostPluginRegistry registry= (BoostPluginRegistry)NewFlutterBoost.instance().getPluginRegistry();
ActivityPluginBinding binding=registry.getRegistrarAggregate().getActivityPluginBinding();
if(binding!=null&&(binding.getActivity()==this.host.getActivity())){
registry.getRegistrarAggregate().onDetachedFromActivityForConfigChanges();
flutterEngine.getActivityControlSurface().detachFromActivityForConfigChanges();
}
flutterView.release();
} }
...@@ -230,15 +234,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine ...@@ -230,15 +234,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
Log.v(TAG, "onDetach()"); Log.v(TAG, "onDetach()");
ensureAlive(); ensureAlive();
if (host.shouldAttachEngineToActivity()) {
// Notify plugins that they are no longer attached to an Activity.
Log.d(TAG, "Detaching FlutterEngine from the Activity that owns this Fragment.");
if (host.getActivity().isChangingConfigurations()) {
flutterEngine.getActivityControlSurface().detachFromActivityForConfigChanges();
} else {
flutterEngine.getActivityControlSurface().detachFromActivity();
}
}
// Null out the platformPlugin to avoid a possible retain cycle between the plugin, this Fragment, // Null out the platformPlugin to avoid a possible retain cycle between the plugin, this Fragment,
// and this Fragment's Activity. // and this Fragment's Activity.
...@@ -372,10 +368,26 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine ...@@ -372,10 +368,26 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
@Override @Override
public void finishContainer(Map<String, Object> result) { public void finishContainer(Map<String, Object> result) {
this.host.finishContainer(result);
if(result != null) {
setBoostResult(this.host.getActivity(),new HashMap<>(result));
this.host.getActivity().finish();
}else{
this.host.getActivity().finish();
}
} }
public void setBoostResult(Activity activity, HashMap result) {
Intent intent = new Intent();
if (result != null) {
intent.putExtra(IFlutterViewContainer.RESULT_KEY, result);
}
activity.setResult(Activity.RESULT_OK, intent);
}
@Override @Override
public String getContainerUrl() { public String getContainerUrl() {
return this.host.getContainerUrl(); return this.host.getContainerUrl();
...@@ -473,7 +485,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine ...@@ -473,7 +485,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
void finishContainer(Map<String, Object> result) ;
String getContainerUrl() ; String getContainerUrl() ;
......
...@@ -59,9 +59,8 @@ public class FlutterSplashView extends FrameLayout { ...@@ -59,9 +59,8 @@ public class FlutterSplashView extends FrameLayout {
private final OnFirstFrameRenderedListener onFirstFrameRenderedListener = new OnFirstFrameRenderedListener() { private final OnFirstFrameRenderedListener onFirstFrameRenderedListener = new OnFirstFrameRenderedListener() {
@Override @Override
public void onFirstFrameRendered() { public void onFirstFrameRendered() {
if (splashScreen != null&&!hasRendered) { if (splashScreen != null) {
transitionToFlutter(); transitionToFlutter();
hasRendered=true;
} }
} }
}; };
...@@ -292,6 +291,9 @@ public class FlutterSplashView extends FrameLayout { ...@@ -292,6 +291,9 @@ public class FlutterSplashView extends FrameLayout {
} }
} }
public void onAttach() { public void onAttach() {
Debuger.log("BoostFlutterView onAttach"); Debuger.log("BoostFlutterView onAttach");
......
...@@ -21,6 +21,7 @@ import android.view.*; ...@@ -21,6 +21,7 @@ import android.view.*;
import android.widget.*; import android.widget.*;
import com.idlefish.flutterboost.NewFlutterBoost; import com.idlefish.flutterboost.NewFlutterBoost;
import com.idlefish.flutterboost.Utils; import com.idlefish.flutterboost.Utils;
import com.idlefish.flutterboost.XFlutterView;
import io.flutter.Log; import io.flutter.Log;
import io.flutter.embedding.android.DrawableSplashScreen; import io.flutter.embedding.android.DrawableSplashScreen;
import io.flutter.embedding.android.FlutterView; import io.flutter.embedding.android.FlutterView;
...@@ -241,8 +242,12 @@ public class NewBoostFlutterActivity extends Activity ...@@ -241,8 +242,12 @@ public class NewBoostFlutterActivity extends Activity
window.setStatusBarColor(Color.TRANSPARENT); window.setStatusBarColor(Color.TRANSPARENT);
window.getDecorView().setSystemUiVisibility(PlatformPlugin.DEFAULT_SYSTEM_UI); window.getDecorView().setSystemUiVisibility(PlatformPlugin.DEFAULT_SYSTEM_UI);
} }
Utils.setStatusBarLightMode(this,true);
}
protected XFlutterView getFlutterView(){
return delegate.getFlutterView();
} }
@Override @Override
...@@ -469,12 +474,6 @@ public class NewBoostFlutterActivity extends Activity ...@@ -469,12 +474,6 @@ public class NewBoostFlutterActivity extends Activity
@Override
public void finishContainer(Map<String, Object> result) {
Activity activity= this.getActivity();
activity.finish();
}
@Override @Override
public String getContainerUrl() { public String getContainerUrl() {
......
...@@ -15,6 +15,7 @@ import android.view.View; ...@@ -15,6 +15,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.idlefish.flutterboost.NewFlutterBoost; import com.idlefish.flutterboost.NewFlutterBoost;
import com.idlefish.flutterboost.XFlutterView;
import io.flutter.embedding.android.*; import io.flutter.embedding.android.*;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs; import io.flutter.embedding.engine.FlutterShellArgs;
...@@ -233,6 +234,10 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr ...@@ -233,6 +234,10 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
private FlutterActivityAndFragmentDelegate delegate; private FlutterActivityAndFragmentDelegate delegate;
protected XFlutterView getFlutterView(){
return delegate.getFlutterView();
}
public NewFlutterFragment() { public NewFlutterFragment() {
// Ensure that we at least have an empty Bundle of arguments so that we don't // Ensure that we at least have an empty Bundle of arguments so that we don't
// need to continually check for null arguments before grabbing one. // need to continually check for null arguments before grabbing one.
...@@ -489,12 +494,7 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr ...@@ -489,12 +494,7 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
} }
@Override
public void finishContainer(Map<String, Object> result) {
Activity activity = this.getActivity();
activity.finish();
}
@Override @Override
public String getContainerUrl() { public String getContainerUrl() {
......
...@@ -9,6 +9,7 @@ import com.idlefish.flutterboost.*; ...@@ -9,6 +9,7 @@ import com.idlefish.flutterboost.*;
import java.util.Map; import java.util.Map;
import com.idlefish.flutterboost.interfaces.INativeRouter; import com.idlefish.flutterboost.interfaces.INativeRouter;
import io.flutter.embedding.android.FlutterView;
import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel;
public class MyApplication extends Application { public class MyApplication extends Application {
...@@ -49,6 +50,7 @@ public class MyApplication extends Application { ...@@ -49,6 +50,7 @@ public class MyApplication extends Application {
.ConfigBuilder(this,router) .ConfigBuilder(this,router)
.isDebug(true) .isDebug(true)
.whenEngineStart(NewFlutterBoost.ConfigBuilder.ANY_ACTIVITY_CREATED) .whenEngineStart(NewFlutterBoost.ConfigBuilder.ANY_ACTIVITY_CREATED)
.renderMode(FlutterView.RenderMode.texture)
.lifecycleListener(lifecycleListener) .lifecycleListener(lifecycleListener)
.build(); .build();
......
...@@ -108,6 +108,10 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> { ...@@ -108,6 +108,10 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
final String message=widget.message; final String message=widget.message;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
brightness:Brightness.light,
backgroundColor: Colors.white,
textTheme:new TextTheme(title: TextStyle(color: Colors.black)) ,
title: Text('flutter_boost_example'), title: Text('flutter_boost_example'),
), ),
body: SingleChildScrollView( body: SingleChildScrollView(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment