Commit ceb75b14 authored by Yacumima's avatar Yacumima

dev

parent 5d05f740
......@@ -29,6 +29,8 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.os.SystemClock;
import android.support.v4.view.ViewCompat;
import android.view.Gravity;
import android.view.View;
......@@ -41,6 +43,7 @@ import android.widget.TextView;
import com.idlefish.flutterboost.interfaces.IStateListener;
import java.io.File;
import java.util.LinkedList;
import java.util.List;
......@@ -63,9 +66,11 @@ public class BoostFlutterView extends FrameLayout {
private final List<OnFirstFrameRenderedListener> mFirstFrameRenderedListeners = new LinkedList<>();
private boolean mEngineAttached = false;
private boolean mNeedSnapshotWhenDetach = false;
private ImageView mSnapshot;
private SnapshotView mSnapshot;
private final io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener mOnFirstFrameRenderedListener =
new io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener() {
......@@ -77,8 +82,8 @@ public class BoostFlutterView extends FrameLayout {
((ViewGroup)mRenderingProgressCover.getParent()).removeView(mRenderingProgressCover);
}
if(mNeedSnapshotWhenDetach && mSnapshot.getParent() != null) {
((ViewGroup)mSnapshot.getParent()).removeView(mSnapshot);
if(mNeedSnapshotWhenDetach) {
mSnapshot.dismissSnapshot(BoostFlutterView.this);
}
final Object[] listeners = mFirstFrameRenderedListeners.toArray();
......@@ -111,6 +116,8 @@ public class BoostFlutterView extends FrameLayout {
addView(mFlutterView, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
mSnapshot = new SnapshotView(getContext());
if(mRenderingProgressCoverCreator != null) {
mRenderingProgressCover = mRenderingProgressCoverCreator
.createRenderingProgressCover(getContext());
......@@ -123,12 +130,6 @@ public class BoostFlutterView extends FrameLayout {
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
mSnapshot = new ImageView(getContext());
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.gravity = Gravity.CENTER;
mSnapshot.setLayoutParams(params);
mFlutterView.addOnFirstFrameRenderedListener(mOnFirstFrameRenderedListener);
mFlutterEngine.startRun((Activity)getContext());
......@@ -228,30 +229,29 @@ public class BoostFlutterView extends FrameLayout {
stateListener.beforeEngineAttach(mFlutterEngine,this);
}
mFlutterView.attachToFlutterEngine(mFlutterEngine);
mEngineAttached = true;
if(stateListener != null) {
stateListener.afterEngineAttached(mFlutterEngine,this);
}
}
public void onDetach() {
Debuger.log("BoostFlutterView onDetach");
if(mNeedSnapshotWhenDetach) {
if(mSnapshot.getParent() != null) {
((ViewGroup)mSnapshot.getParent()).removeView(mSnapshot);
public void toggleSnapshot() {
mSnapshot.toggleSnapshot(this);
}
final Bitmap bitmap = mFlutterEngine.getRenderer().getBitmap();
if(bitmap != null) {
Debuger.log("BoostFlutterView snapshot "+bitmap.getByteCount());
public void toggleAttach() {
if(mEngineAttached) {
onDetach();
}else{
onAttach();
}
}
//Utils.saveBitmap(bitmap,"/sdcard/idlefish/fb/ss-"+ SystemClock.uptimeMillis());
public void onDetach() {
Debuger.log("BoostFlutterView onDetach");
mSnapshot.setImageBitmap(bitmap);
BoostFlutterView.this.addView(mSnapshot);
}
if(mNeedSnapshotWhenDetach) {
mSnapshot.showSnapshot(BoostFlutterView.this);
}
final IStateListener stateListener = FlutterBoost.sInstance.mStateListener;
......@@ -259,6 +259,7 @@ public class BoostFlutterView extends FrameLayout {
stateListener.beforeEngineDetach(mFlutterEngine,this);
}
mFlutterView.detachFromFlutterEngine();
mEngineAttached = false;
if(stateListener != null) {
stateListener.afterEngineDetached(mFlutterEngine,this);
}
......
package com.idlefish.flutterboost;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import java.util.LinkedList;
import java.util.List;
public class SnapshotView extends FrameLayout {
private ImageView mImg;
public SnapshotView(@NonNull Context context) {
super(context);
init();
}
public SnapshotView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init();
}
public SnapshotView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init(){
setBackgroundColor(Color.RED);
mImg = new ImageView(getContext());
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.gravity = Gravity.CENTER;
mImg.setScaleType(ImageView.ScaleType.FIT_XY);
mImg.setLayoutParams(params);
addView(mImg);
}
public void toggleSnapshot(BoostFlutterView flutterView){
if (!dismissSnapshot(flutterView)) {
showSnapshot(flutterView);
}
}
public boolean showSnapshot(BoostFlutterView flutterView){
if(flutterView == null) return false;
dismissSnapshot(flutterView);
final Bitmap bitmap = flutterView.getEngine().getRenderer().getBitmap();
if(bitmap == null || bitmap.isRecycled()) {
return false;
}
mImg.setImageBitmap(bitmap);
flutterView.addView(this,new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
Debuger.log("showSnapshot");
return true;
}
public boolean dismissSnapshot(BoostFlutterView flutterView){
List<View> snapshots = new LinkedList<>();
for(int index = 0;index < flutterView.getChildCount();index++){
View view = flutterView.getChildAt(index);
if(view instanceof SnapshotView) {
snapshots.add(view);
}
}
if(snapshots.isEmpty()) {
return false;
}else{
for(View v:snapshots) {
flutterView.removeView(v);
}
Debuger.log("dismissSnapshot");
return true;
}
}
}
......@@ -38,12 +38,12 @@ public class Utils {
}
}
public static void saveBitmap(Bitmap bm, String filePath) {
File f = new File(filePath);
public static void saveBitmap(Bitmap bm,File path, String name) {
try {
if (!f.exists()) {
if(!f.getParentFile().exists() && !f.getParentFile().mkdirs()) {
File f = new File(path,name);
if (!path.exists()) {
if(!path.mkdirs()) {
throw new Exception("mkdir except");
}
......@@ -56,6 +56,8 @@ public class Utils {
bm.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
Debuger.exception("saved bitmap:"+f.getAbsolutePath());
} catch (Throwable t){
throw new RuntimeException(t);
}
......
......@@ -27,6 +27,11 @@ public class MyApplication extends FlutterApplication {
return MyApplication.this;
}
@Override
public boolean isDebug() {
return true;
}
@Override
public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) {
PageRouter.openPageByUrl(context,url,urlParams,requestCode);
......
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