Commit 94f01e51 authored by Yacumima's avatar Yacumima

improve

parent 436c5960
...@@ -26,10 +26,11 @@ package com.taobao.idlefish.flutterboost; ...@@ -26,10 +26,11 @@ package com.taobao.idlefish.flutterboost;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewCompat;
import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -71,6 +72,8 @@ public class BoostFlutterView extends FrameLayout { ...@@ -71,6 +72,8 @@ public class BoostFlutterView extends FrameLayout {
new io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener() { new io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener() {
@Override @Override
public void onFirstFrameRendered() { public void onFirstFrameRendered() {
Debuger.log("BoostFlutterView onFirstFrameRendered");
if(mRenderingProgressCover != null && mRenderingProgressCover.getParent() != null) { if(mRenderingProgressCover != null && mRenderingProgressCover.getParent() != null) {
((ViewGroup)mRenderingProgressCover.getParent()).removeView(mRenderingProgressCover); ((ViewGroup)mRenderingProgressCover.getParent()).removeView(mRenderingProgressCover);
} }
...@@ -240,13 +243,18 @@ public class BoostFlutterView extends FrameLayout { ...@@ -240,13 +243,18 @@ public class BoostFlutterView extends FrameLayout {
((ViewGroup)mSnapshot.getParent()).removeView(mSnapshot); ((ViewGroup)mSnapshot.getParent()).removeView(mSnapshot);
} }
Debuger.log("BoostFlutterView snapshot"); final Bitmap bitmap = mFlutterEngine.getRenderer().getBitmap();
if(bitmap != null) {
Debuger.log("BoostFlutterView snapshot "+bitmap.getByteCount());
mSnapshot.setImageBitmap(mFlutterEngine.getRenderer().getBitmap()); //Utils.saveBitmap(bitmap,"/sdcard/idlefish/fb/ss-"+ SystemClock.uptimeMillis());
mSnapshot.setImageBitmap(bitmap);
BoostFlutterView.this.addView(mSnapshot); BoostFlutterView.this.addView(mSnapshot);
} }
}
mFlutterView.removeOnFirstFrameRenderedListener(mOnFirstFrameRenderedListener);
final IStateListener stateListener = FlutterBoostPlugin.sInstance.mStateListener; final IStateListener stateListener = FlutterBoostPlugin.sInstance.mStateListener;
if(stateListener != null) { if(stateListener != null) {
stateListener.beforeEngineDetach(mFlutterEngine,this); stateListener.beforeEngineDetach(mFlutterEngine,this);
...@@ -259,6 +267,8 @@ public class BoostFlutterView extends FrameLayout { ...@@ -259,6 +267,8 @@ public class BoostFlutterView extends FrameLayout {
public void onDestroy() { public void onDestroy() {
Debuger.log("BoostFlutterView onDestroy"); Debuger.log("BoostFlutterView onDestroy");
mFlutterView.removeOnFirstFrameRenderedListener(mOnFirstFrameRenderedListener);
mPlatformPlugin = null; mPlatformPlugin = null;
mFlutterEngine = null; mFlutterEngine = null;
} }
......
...@@ -65,7 +65,7 @@ public class ContainerRecord implements IContainerRecord { ...@@ -65,7 +65,7 @@ public class ContainerRecord implements IContainerRecord {
Utils.assertCallOnMainThread(); Utils.assertCallOnMainThread();
BoostEngineProvider.assertEngineRunning(); BoostEngineProvider.assertEngineRunning();
if(mState != STATE_UNKNOW) { if (mState != STATE_UNKNOW) {
Debuger.exception("state error"); Debuger.exception("state error");
} }
...@@ -78,7 +78,7 @@ public class ContainerRecord implements IContainerRecord { ...@@ -78,7 +78,7 @@ public class ContainerRecord implements IContainerRecord {
public void onAppear() { public void onAppear() {
Utils.assertCallOnMainThread(); Utils.assertCallOnMainThread();
if(mState != STATE_CREATED && mState != STATE_DISAPPEAR) { if (mState != STATE_CREATED && mState != STATE_DISAPPEAR) {
Debuger.exception("state error"); Debuger.exception("state error");
} }
...@@ -95,7 +95,7 @@ public class ContainerRecord implements IContainerRecord { ...@@ -95,7 +95,7 @@ public class ContainerRecord implements IContainerRecord {
public void onDisappear() { public void onDisappear() {
Utils.assertCallOnMainThread(); Utils.assertCallOnMainThread();
if(mState != STATE_APPEAR) { if (mState != STATE_APPEAR) {
Debuger.exception("state error"); Debuger.exception("state error");
} }
...@@ -112,7 +112,7 @@ public class ContainerRecord implements IContainerRecord { ...@@ -112,7 +112,7 @@ public class ContainerRecord implements IContainerRecord {
public void onDestroy() { public void onDestroy() {
Utils.assertCallOnMainThread(); Utils.assertCallOnMainThread();
if(mState != STATE_DISAPPEAR) { if (mState != STATE_DISAPPEAR) {
Debuger.exception("state error"); Debuger.exception("state error");
} }
...@@ -120,9 +120,11 @@ public class ContainerRecord implements IContainerRecord { ...@@ -120,9 +120,11 @@ public class ContainerRecord implements IContainerRecord {
mProxy.destroy(); mProxy.destroy();
mContainer.getBoostFlutterView().onDestroy();
mManager.removeRecord(this); mManager.removeRecord(this);
if(!mManager.hasContainerAppear()) { if (!mManager.hasContainerAppear()) {
mContainer.getBoostFlutterView().onPause(); mContainer.getBoostFlutterView().onPause();
mContainer.getBoostFlutterView().onStop(); mContainer.getBoostFlutterView().onStop();
} }
...@@ -132,7 +134,7 @@ public class ContainerRecord implements IContainerRecord { ...@@ -132,7 +134,7 @@ public class ContainerRecord implements IContainerRecord {
public void onBackPressed() { public void onBackPressed() {
Utils.assertCallOnMainThread(); Utils.assertCallOnMainThread();
if(mState == STATE_UNKNOW || mState == STATE_DESTROYED) { if (mState == STATE_UNKNOW || mState == STATE_DESTROYED) {
Debuger.exception("state error"); Debuger.exception("state error");
} }
...@@ -141,14 +143,14 @@ public class ContainerRecord implements IContainerRecord { ...@@ -141,14 +143,14 @@ public class ContainerRecord implements IContainerRecord {
map.put("name", mContainer.getContainerUrl()); map.put("name", mContainer.getContainerUrl());
map.put("uniqueId", mUniqueId); map.put("uniqueId", mUniqueId);
FlutterBoostPlugin.singleton().channel().sendEvent("lifecycle",map); FlutterBoostPlugin.singleton().channel().sendEvent("lifecycle", map);
mContainer.getBoostFlutterView().onBackPressed(); mContainer.getBoostFlutterView().onBackPressed();
} }
@Override @Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
mContainer.getBoostFlutterView().onRequestPermissionsResult(requestCode,permissions,grantResults); mContainer.getBoostFlutterView().onRequestPermissionsResult(requestCode, permissions, grantResults);
} }
@Override @Override
...@@ -158,12 +160,12 @@ public class ContainerRecord implements IContainerRecord { ...@@ -158,12 +160,12 @@ public class ContainerRecord implements IContainerRecord {
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
mContainer.getBoostFlutterView().onActivityResult(requestCode,resultCode,data); mContainer.getBoostFlutterView().onActivityResult(requestCode, resultCode, data);
} }
@Override @Override
public void onContainerResult(int requestCode, Map<String,Object> result) { public void onContainerResult(int requestCode, Map<String, Object> result) {
mManager.setContainerResult(this,requestCode,result); mManager.setContainerResult(this, requestCode, result);
} }
@Override @Override
...@@ -187,7 +189,7 @@ public class ContainerRecord implements IContainerRecord { ...@@ -187,7 +189,7 @@ public class ContainerRecord implements IContainerRecord {
private void create() { private void create() {
if (mState == STATE_UNKNOW) { if (mState == STATE_UNKNOW) {
invokeChannelUnsafe( invokeChannelUnsafe("didInitPageContainer",
mContainer.getContainerUrl(), mContainer.getContainerUrl(),
mContainer.getContainerUrlParams(), mContainer.getContainerUrlParams(),
mUniqueId mUniqueId
...@@ -198,7 +200,7 @@ public class ContainerRecord implements IContainerRecord { ...@@ -198,7 +200,7 @@ public class ContainerRecord implements IContainerRecord {
} }
private void appear() { private void appear() {
invokeChannelUnsafe( invokeChannelUnsafe("didShowPageContainer",
mContainer.getContainerUrl(), mContainer.getContainerUrl(),
mContainer.getContainerUrlParams(), mContainer.getContainerUrlParams(),
mUniqueId mUniqueId
...@@ -210,7 +212,7 @@ public class ContainerRecord implements IContainerRecord { ...@@ -210,7 +212,7 @@ public class ContainerRecord implements IContainerRecord {
private void disappear() { private void disappear() {
if (mState < STATE_DISAPPEAR) { if (mState < STATE_DISAPPEAR) {
invokeChannel( invokeChannel("didDisappearPageContainer",
mContainer.getContainerUrl(), mContainer.getContainerUrl(),
mContainer.getContainerUrlParams(), mContainer.getContainerUrlParams(),
mUniqueId mUniqueId
...@@ -223,7 +225,7 @@ public class ContainerRecord implements IContainerRecord { ...@@ -223,7 +225,7 @@ public class ContainerRecord implements IContainerRecord {
private void destroy() { private void destroy() {
if (mState < STATE_DESTROYED) { if (mState < STATE_DESTROYED) {
invokeChannel( invokeChannel("willDeallocPageContainer",
mContainer.getContainerUrl(), mContainer.getContainerUrl(),
mContainer.getContainerUrlParams(), mContainer.getContainerUrlParams(),
mUniqueId mUniqueId
...@@ -234,20 +236,20 @@ public class ContainerRecord implements IContainerRecord { ...@@ -234,20 +236,20 @@ public class ContainerRecord implements IContainerRecord {
} }
} }
public void invokeChannel(String pageName, Map params, String uniqueId) { public void invokeChannel(String method, String url, Map params, String uniqueId) {
HashMap<String, Object> args = new HashMap<>(); HashMap<String, Object> args = new HashMap<>();
args.put("pageName", pageName); args.put("pageName", url);
args.put("params", params); args.put("params", params);
args.put("uniqueId", uniqueId); args.put("uniqueId", uniqueId);
FlutterBoostPlugin.singleton().channel().invokeMethod("didInitPageContainer", args); FlutterBoostPlugin.singleton().channel().invokeMethod(method, args);
} }
public void invokeChannelUnsafe(String pageName, Map params, String uniqueId) { public void invokeChannelUnsafe(String method, String url, Map params, String uniqueId) {
HashMap<String, Object> args = new HashMap<>(); HashMap<String, Object> args = new HashMap<>();
args.put("pageName", pageName); args.put("pageName", url);
args.put("params", params); args.put("params", params);
args.put("uniqueId", uniqueId); args.put("uniqueId", uniqueId);
FlutterBoostPlugin.singleton().channel().invokeMethodUnsafe("didInitPageContainer", args); FlutterBoostPlugin.singleton().channel().invokeMethodUnsafe(method, args);
} }
} }
} }
...@@ -26,6 +26,12 @@ package com.taobao.idlefish.flutterboost; ...@@ -26,6 +26,12 @@ package com.taobao.idlefish.flutterboost;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.os.Looper; import android.os.Looper;
import android.util.Log;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Utils { public class Utils {
...@@ -35,6 +41,29 @@ public class Utils { ...@@ -35,6 +41,29 @@ public class Utils {
} }
} }
public static void saveBitmap(Bitmap bm, String filePath) {
File f = new File(filePath);
try {
if (!f.exists()) {
if(!f.getParentFile().exists() && !f.getParentFile().mkdirs()) {
throw new Exception("mkdir except");
}
if(!f.createNewFile()){
throw new Exception("createNewFile except");
}
}
FileOutputStream out = new FileOutputStream(f);
bm.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
} catch (Throwable t){
throw new RuntimeException(t);
}
}
public static boolean checkImageValid(final Bitmap bitmap) { public static boolean checkImageValid(final Bitmap bitmap) {
if (null == bitmap) { if (null == bitmap) {
return false; return false;
......
...@@ -105,7 +105,7 @@ public abstract class BoostFlutterActivity extends Activity implements IFlutterV ...@@ -105,7 +105,7 @@ public abstract class BoostFlutterActivity extends Activity implements IFlutterV
BoostFlutterView.Builder builder = new BoostFlutterView.Builder(this); BoostFlutterView.Builder builder = new BoostFlutterView.Builder(this);
return builder.flutterEngine(engine) return builder.flutterEngine(engine)
.renderMode(FlutterView.RenderMode.texture) .renderMode(FlutterView.RenderMode.surface)
.transparencyMode(isBackgroundTransparent() ? .transparencyMode(isBackgroundTransparent() ?
FlutterView.TransparencyMode.transparent : FlutterView.TransparencyMode.transparent :
FlutterView.TransparencyMode.opaque) FlutterView.TransparencyMode.opaque)
......
...@@ -25,7 +25,7 @@ apply plugin: 'com.android.application' ...@@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android { android {
compileSdkVersion 27 compileSdkVersion 26
lintOptions { lintOptions {
disable 'InvalidPackage' disable 'InvalidPackage'
...@@ -35,7 +35,7 @@ android { ...@@ -35,7 +35,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.taobao.idlefish.flutterboostexample" applicationId "com.taobao.idlefish.flutterboostexample"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 27 targetSdkVersion 26
versionCode flutterVersionCode.toInteger() versionCode flutterVersionCode.toInteger()
versionName flutterVersionName versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
...@@ -58,6 +58,6 @@ dependencies { ...@@ -58,6 +58,6 @@ dependencies {
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:support-v4:27.1.1' implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:appcompat-v7:26.1.0'
} }
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
--> -->
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that <!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method. calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide In most cases you can leave this as-is, but you if you want to provide
......
...@@ -104,6 +104,8 @@ class ContainerCoordinator { ...@@ -104,6 +104,8 @@ class ContainerCoordinator {
Map map = event; Map map = event;
final String type = map['type']; final String type = map['type'];
Logger.log("onEvent $type");
switch (type) { switch (type) {
//Handler back key pressed event. //Handler back key pressed event.
case 'backPressedCallback': case 'backPressedCallback':
...@@ -141,6 +143,8 @@ class ContainerCoordinator { ...@@ -141,6 +143,8 @@ class ContainerCoordinator {
} }
Future<dynamic> _onMethodCall(MethodCall call) { Future<dynamic> _onMethodCall(MethodCall call) {
Logger.log("onMetohdCall ${call.method}");
switch (call.method) { switch (call.method) {
case "didInitPageContainer": case "didInitPageContainer":
{ {
......
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