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
0
Merge Requests
0
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
bc34068b
Commit
bc34068b
authored
Jul 05, 2019
by
Yacumima
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dev
parent
5045f501
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
182 additions
and
24 deletions
+182
-24
android/src/main/java/com/idlefish/flutterboost/BoostFlutterEngine.java
...in/java/com/idlefish/flutterboost/BoostFlutterEngine.java
+165
-19
android/src/main/java/com/idlefish/flutterboost/BoostFlutterView.java
...main/java/com/idlefish/flutterboost/BoostFlutterView.java
+14
-5
android/src/main/java/com/idlefish/flutterboost/ContainerRecord.java
.../main/java/com/idlefish/flutterboost/ContainerRecord.java
+3
-0
No files found.
android/src/main/java/com/idlefish/flutterboost/BoostFlutterEngine.java
View file @
bc34068b
...
...
@@ -2,17 +2,24 @@ package com.idlefish.flutterboost;
import
android.app.Activity
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.view.Surface
;
import
com.idlefish.flutterboost.interfaces.IContainerRecord
;
import
com.idlefish.flutterboost.interfaces.IStateListener
;
import
java.lang.ref.WeakReference
;
import
java.lang.reflect.Field
;
import
java.nio.ByteBuffer
;
import
io.flutter.app.FlutterPluginRegistry
;
import
io.flutter.embedding.engine.FlutterEngine
;
import
io.flutter.embedding.engine.FlutterJNI
;
import
io.flutter.embedding.engine.dart.DartExecutor
;
import
io.flutter.embedding.engine.renderer.FlutterRenderer
;
import
io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener
;
import
io.flutter.plugin.common.BinaryMessenger
;
import
io.flutter.plugin.common.PluginRegistry
;
import
io.flutter.plugin.platform.PlatformViewRegistry
;
...
...
@@ -26,28 +33,41 @@ public class BoostFlutterEngine extends FlutterEngine {
protected
final
DartExecutor
.
DartEntrypoint
mEntrypoint
;
protected
final
String
mInitRoute
;
private
final
FakeRender
mFakeRender
;
protected
WeakReference
<
Activity
>
mCurrentActivityRef
;
public
BoostFlutterEngine
(
@NonNull
Context
context
)
{
this
(
context
,
null
,
null
);
this
(
context
,
null
,
null
);
}
public
BoostFlutterEngine
(
@NonNull
Context
context
,
DartExecutor
.
DartEntrypoint
entrypoint
,
String
initRoute
)
{
public
BoostFlutterEngine
(
@NonNull
Context
context
,
DartExecutor
.
DartEntrypoint
entrypoint
,
String
initRoute
)
{
super
(
context
);
mContext
=
context
.
getApplicationContext
();
mBoostPluginRegistry
=
new
BoostPluginRegistry
(
this
,
context
);
mBoostPluginRegistry
=
new
BoostPluginRegistry
(
this
,
context
);
if
(
entrypoint
!=
null
)
{
if
(
entrypoint
!=
null
)
{
mEntrypoint
=
entrypoint
;
}
else
{
}
else
{
mEntrypoint
=
defaultDartEntrypoint
(
context
);
}
if
(
initRoute
!=
null
)
{
if
(
initRoute
!=
null
)
{
mInitRoute
=
initRoute
;
}
else
{
}
else
{
mInitRoute
=
defaultInitialRoute
(
context
);
}
FlutterJNI
flutterJNI
=
null
;
try
{
Field
field
=
FlutterEngine
.
class
.
getDeclaredField
(
"flutterJNI"
);
field
.
setAccessible
(
true
);
flutterJNI
=
(
FlutterJNI
)
field
.
get
(
this
);
}
catch
(
Throwable
t
)
{
Debuger
.
exception
(
t
);
}
mFakeRender
=
new
FakeRender
(
flutterJNI
);
}
public
void
startRun
(
@Nullable
Activity
activity
)
{
...
...
@@ -61,7 +81,7 @@ public class BoostFlutterEngine extends FlutterEngine {
getDartExecutor
().
executeDartEntrypoint
(
mEntrypoint
);
final
IStateListener
stateListener
=
FlutterBoost
.
sInstance
.
mStateListener
;
if
(
stateListener
!=
null
)
{
if
(
stateListener
!=
null
)
{
stateListener
.
onEngineStarted
(
this
);
}
...
...
@@ -69,25 +89,45 @@ public class BoostFlutterEngine extends FlutterEngine {
}
}
protected
DartExecutor
.
DartEntrypoint
defaultDartEntrypoint
(
Context
context
){
protected
DartExecutor
.
DartEntrypoint
defaultDartEntrypoint
(
Context
context
)
{
return
new
DartExecutor
.
DartEntrypoint
(
context
.
getResources
().
getAssets
(),
FlutterMain
.
findAppBundlePath
(
context
),
"main"
);
}
protected
String
defaultInitialRoute
(
Context
context
){
protected
String
defaultInitialRoute
(
Context
context
)
{
return
"/"
;
}
public
BoostPluginRegistry
getBoostPluginRegistry
(){
public
BoostPluginRegistry
getBoostPluginRegistry
()
{
return
mBoostPluginRegistry
;
}
public
boolean
isRunning
(){
public
boolean
isRunning
()
{
return
getDartExecutor
().
isExecutingDart
();
}
@NonNull
@Override
public
FlutterRenderer
getRenderer
()
{
StackTraceElement
[]
stackTrace
=
Thread
.
currentThread
().
getStackTrace
();
boolean
hit
=
false
;
for
(
StackTraceElement
st
:
stackTrace
)
{
if
(
st
.
getMethodName
().
equals
(
"sendViewportMetricsToFlutter"
))
{
hit
=
true
;
break
;
}
}
if
(
hit
)
{
return
mFakeRender
;
}
else
{
return
super
.
getRenderer
();
}
}
public
class
BoostPluginRegistry
extends
FlutterPluginRegistry
{
private
final
FlutterEngine
mEngine
;
...
...
@@ -97,7 +137,7 @@ public class BoostFlutterEngine extends FlutterEngine {
}
public
PluginRegistry
.
Registrar
registrarFor
(
String
pluginKey
)
{
return
new
BoostRegistrar
(
mEngine
,
super
.
registrarFor
(
pluginKey
));
return
new
BoostRegistrar
(
mEngine
,
super
.
registrarFor
(
pluginKey
));
}
}
...
...
@@ -117,21 +157,21 @@ public class BoostFlutterEngine extends FlutterEngine {
IContainerRecord
record
;
record
=
FlutterBoost
.
singleton
().
containerManager
().
getCurrentTopRecord
();
if
(
record
==
null
)
{
if
(
record
==
null
)
{
record
=
FlutterBoost
.
singleton
().
containerManager
().
getLastGenerateRecord
();
}
if
(
record
==
null
)
{
if
(
record
==
null
)
{
activity
=
FlutterBoost
.
singleton
().
currentActivity
();
}
else
{
}
else
{
activity
=
record
.
getContainer
().
getContextActivity
();
}
if
(
activity
==
null
&&
mCurrentActivityRef
!=
null
)
{
if
(
activity
==
null
&&
mCurrentActivityRef
!=
null
)
{
activity
=
mCurrentActivityRef
.
get
();
}
if
(
activity
==
null
)
{
if
(
activity
==
null
)
{
throw
new
RuntimeException
(
"current has no valid Activity yet"
);
}
...
...
@@ -175,7 +215,7 @@ public class BoostFlutterEngine extends FlutterEngine {
@Override
public
String
lookupKeyForAsset
(
String
s
,
String
s1
)
{
return
mRegistrar
.
lookupKeyForAsset
(
s
,
s1
);
return
mRegistrar
.
lookupKeyForAsset
(
s
,
s1
);
}
@Override
...
...
@@ -208,4 +248,110 @@ public class BoostFlutterEngine extends FlutterEngine {
return
mRegistrar
.
addViewDestroyListener
(
viewDestroyListener
);
}
}
private
boolean
viewportMetricsEqual
(
FlutterRenderer
.
ViewportMetrics
a
,
FlutterRenderer
.
ViewportMetrics
b
)
{
return
a
!=
null
&&
b
!=
null
&&
a
.
height
==
b
.
height
&&
a
.
width
==
b
.
width
&&
a
.
devicePixelRatio
==
b
.
devicePixelRatio
&&
a
.
paddingBottom
==
b
.
paddingBottom
&&
a
.
paddingLeft
==
b
.
paddingLeft
&&
a
.
paddingRight
==
b
.
paddingRight
&&
a
.
paddingTop
==
b
.
paddingTop
&&
a
.
viewInsetLeft
==
b
.
viewInsetLeft
&&
a
.
viewInsetRight
==
b
.
viewInsetRight
&&
a
.
viewInsetTop
==
b
.
viewInsetTop
&&
a
.
viewInsetBottom
==
b
.
viewInsetBottom
;
}
class
FakeRender
extends
FlutterRenderer
{
private
ViewportMetrics
last
;
public
FakeRender
(
FlutterJNI
flutterJNI
)
{
super
(
flutterJNI
);
}
@Override
public
void
setViewportMetrics
(
@NonNull
ViewportMetrics
viewportMetrics
)
{
if
(
viewportMetrics
.
width
>
0
&&
viewportMetrics
.
height
>
0
&&
!
viewportMetricsEqual
(
last
,
viewportMetrics
))
{
last
=
viewportMetrics
;
Debuger
.
log
(
"setViewportMetrics w:"
+
viewportMetrics
.
width
+
" h:"
+
viewportMetrics
.
height
);
super
.
setViewportMetrics
(
viewportMetrics
);
}
}
@Override
public
void
attachToRenderSurface
(
@NonNull
RenderSurface
renderSurface
)
{
Debuger
.
exception
(
"should never called!"
);
}
@Override
public
void
detachFromRenderSurface
()
{
Debuger
.
exception
(
"should never called!"
);
}
@Override
public
void
addOnFirstFrameRenderedListener
(
@NonNull
OnFirstFrameRenderedListener
listener
)
{
Debuger
.
exception
(
"should never called!"
);
}
@Override
public
void
removeOnFirstFrameRenderedListener
(
@NonNull
OnFirstFrameRenderedListener
listener
)
{
Debuger
.
exception
(
"should never called!"
);
}
@Override
public
SurfaceTextureEntry
createSurfaceTexture
()
{
Debuger
.
exception
(
"should never called!"
);
return
null
;
}
@Override
public
void
surfaceCreated
(
Surface
surface
)
{
Debuger
.
exception
(
"should never called!"
);
}
@Override
public
void
surfaceChanged
(
int
width
,
int
height
)
{
Debuger
.
exception
(
"should never called!"
);
}
@Override
public
void
surfaceDestroyed
()
{
Debuger
.
exception
(
"should never called!"
);
}
@Override
public
Bitmap
getBitmap
()
{
Debuger
.
exception
(
"should never called!"
);
return
null
;
}
@Override
public
void
dispatchPointerDataPacket
(
ByteBuffer
buffer
,
int
position
)
{
Debuger
.
exception
(
"should never called!"
);
}
@Override
public
boolean
isSoftwareRenderingEnabled
()
{
Debuger
.
exception
(
"should never called!"
);
return
false
;
}
@Override
public
void
setAccessibilityFeatures
(
int
flags
)
{
Debuger
.
exception
(
"should never called!"
);
}
@Override
public
void
setSemanticsEnabled
(
boolean
enabled
)
{
Debuger
.
exception
(
"should never called!"
);
}
@Override
public
void
dispatchSemanticsAction
(
int
id
,
int
action
,
ByteBuffer
args
,
int
argsPosition
)
{
Debuger
.
exception
(
"should never called!"
);
}
}
}
android/src/main/java/com/idlefish/flutterboost/BoostFlutterView.java
View file @
bc34068b
...
...
@@ -26,24 +26,20 @@ package com.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.Environment
;
import
android.os.SystemClock
;
import
android.support.v4.view.ViewCompat
;
import
android.view.Gravity
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.FrameLayout
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.ProgressBar
;
import
android.widget.TextView
;
import
com.idlefish.flutterboost.interfaces.IStateListener
;
import
java.
io.File
;
import
java.
lang.reflect.Method
;
import
java.util.LinkedList
;
import
java.util.List
;
...
...
@@ -138,6 +134,19 @@ public class BoostFlutterView extends FrameLayout {
if
(
stateListener
!=
null
)
{
stateListener
.
onFlutterViewInited
(
mFlutterEngine
,
this
);
}
checkAssert
();
}
private
void
checkAssert
(){
try
{
Method
method
=
FlutterView
.
class
.
getDeclaredMethod
(
"sendViewportMetricsToFlutter"
);
if
(
method
==
null
)
{
throw
new
Exception
(
"method: FlutterView.sendViewportMetricsToFlutter not found!"
);
}
}
catch
(
Throwable
t
){
Debuger
.
exception
(
t
);
}
}
protected
View
createRenderingProgressCorver
(){
...
...
android/src/main/java/com/idlefish/flutterboost/ContainerRecord.java
View file @
bc34068b
...
...
@@ -108,6 +108,9 @@ public class ContainerRecord implements IContainerRecord {
mState
=
STATE_DISAPPEAR
;
mProxy
.
disappear
();
if
(
getContainer
().
getContextActivity
().
isFinishing
())
{
mProxy
.
destroy
();
}
mContainer
.
getBoostFlutterView
().
onDetach
();
...
...
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