Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
flutter_boost_1.22.4
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李增强
flutter_boost_1.22.4
Commits
ceb75b14
Commit
ceb75b14
authored
Jul 01, 2019
by
Yacumima
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dev
parent
5d05f740
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
134 additions
and
29 deletions
+134
-29
android/src/main/java/com/idlefish/flutterboost/BoostFlutterView.java
...main/java/com/idlefish/flutterboost/BoostFlutterView.java
+25
-24
android/src/main/java/com/idlefish/flutterboost/SnapshotView.java
...src/main/java/com/idlefish/flutterboost/SnapshotView.java
+97
-0
android/src/main/java/com/idlefish/flutterboost/Utils.java
android/src/main/java/com/idlefish/flutterboost/Utils.java
+7
-5
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/MyApplication.java
...om/taobao/idlefish/flutterboostexample/MyApplication.java
+5
-0
No files found.
android/src/main/java/com/idlefish/flutterboost/BoostFlutterView.java
View file @
ceb75b14
...
...
@@ -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
Image
View
mSnapshot
;
private
Snapshot
View
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
toggleSnapshot
()
{
mSnapshot
.
toggleSnapshot
(
this
);
}
public
void
toggleAttach
()
{
if
(
mEngineAttached
)
{
onDetach
();
}
else
{
onAttach
();
}
}
public
void
onDetach
()
{
Debuger
.
log
(
"BoostFlutterView onDetach"
);
if
(
mNeedSnapshotWhenDetach
)
{
if
(
mSnapshot
.
getParent
()
!=
null
)
{
((
ViewGroup
)
mSnapshot
.
getParent
()).
removeView
(
mSnapshot
);
}
final
Bitmap
bitmap
=
mFlutterEngine
.
getRenderer
().
getBitmap
();
if
(
bitmap
!=
null
)
{
Debuger
.
log
(
"BoostFlutterView snapshot "
+
bitmap
.
getByteCount
());
//Utils.saveBitmap(bitmap,"/sdcard/idlefish/fb/ss-"+ SystemClock.uptimeMillis());
mSnapshot
.
setImageBitmap
(
bitmap
);
BoostFlutterView
.
this
.
addView
(
mSnapshot
);
}
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
);
}
...
...
android/src/main/java/com/idlefish/flutterboost/SnapshotView.java
0 → 100644
View file @
ceb75b14
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
;
}
}
}
android/src/main/java/com/idlefish/flutterboost/Utils.java
View file @
ceb75b14
...
...
@@ -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
);
}
...
...
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/MyApplication.java
View file @
ceb75b14
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment