Commit 94f01e51 authored by Yacumima's avatar Yacumima

improve

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