Commit ceb75b14 authored by Yacumima's avatar Yacumima

dev

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