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
0e7d161c
Commit
0e7d161c
authored
Jun 21, 2019
by
Yacumima
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve
parent
c97e6421
Changes
26
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
716 additions
and
387 deletions
+716
-387
android/build.gradle
android/build.gradle
+1
-1
android/src/main/java/com/taobao/idlefish/flutterboost/BoostEngineProvider.java
...com/taobao/idlefish/flutterboost/BoostEngineProvider.java
+15
-38
android/src/main/java/com/taobao/idlefish/flutterboost/BoostFlutterEngine.java
.../com/taobao/idlefish/flutterboost/BoostFlutterEngine.java
+187
-0
android/src/main/java/com/taobao/idlefish/flutterboost/BoostFlutterView.java
...va/com/taobao/idlefish/flutterboost/BoostFlutterView.java
+119
-14
android/src/main/java/com/taobao/idlefish/flutterboost/ContainerRecord.java
...ava/com/taobao/idlefish/flutterboost/ContainerRecord.java
+1
-0
android/src/main/java/com/taobao/idlefish/flutterboost/Debuger.java
...c/main/java/com/taobao/idlefish/flutterboost/Debuger.java
+1
-1
android/src/main/java/com/taobao/idlefish/flutterboost/FlutterBoostPlugin.java
.../com/taobao/idlefish/flutterboost/FlutterBoostPlugin.java
+89
-152
android/src/main/java/com/taobao/idlefish/flutterboost/FlutterViewContainerManager.java
...ao/idlefish/flutterboost/FlutterViewContainerManager.java
+3
-5
android/src/main/java/com/taobao/idlefish/flutterboost/NavigationService/NavigationService_closePage.java
...rboost/NavigationService/NavigationService_closePage.java
+1
-2
android/src/main/java/com/taobao/idlefish/flutterboost/NavigationService/NavigationService_onFlutterPageResult.java
...igationService/NavigationService_onFlutterPageResult.java
+0
-2
android/src/main/java/com/taobao/idlefish/flutterboost/NavigationService/NavigationService_onShownContainerChanged.java
...ionService/NavigationService_onShownContainerChanged.java
+1
-2
android/src/main/java/com/taobao/idlefish/flutterboost/NavigationService/NavigationService_openPage.java
...erboost/NavigationService/NavigationService_openPage.java
+9
-1
android/src/main/java/com/taobao/idlefish/flutterboost/NavigationService/NavigationService_pageOnStart.java
...oost/NavigationService/NavigationService_pageOnStart.java
+2
-4
android/src/main/java/com/taobao/idlefish/flutterboost/PageResultHandler.java
...a/com/taobao/idlefish/flutterboost/PageResultHandler.java
+0
-30
android/src/main/java/com/taobao/idlefish/flutterboost/PageResultMediator.java
.../com/taobao/idlefish/flutterboost/PageResultMediator.java
+0
-102
android/src/main/java/com/taobao/idlefish/flutterboost/StateListener.java
.../java/com/taobao/idlefish/flutterboost/StateListener.java
+40
-0
android/src/main/java/com/taobao/idlefish/flutterboost/containers/BoostFlutterActivity.java
...dlefish/flutterboost/containers/BoostFlutterActivity.java
+98
-8
android/src/main/java/com/taobao/idlefish/flutterboost/containers/BoostFlutterFragment.java
...dlefish/flutterboost/containers/BoostFlutterFragment.java
+21
-7
android/src/main/java/com/taobao/idlefish/flutterboost/interfaces/IFlutterEngineProvider.java
...efish/flutterboost/interfaces/IFlutterEngineProvider.java
+3
-2
android/src/main/java/com/taobao/idlefish/flutterboost/interfaces/IPlatform.java
...om/taobao/idlefish/flutterboost/interfaces/IPlatform.java
+13
-7
android/src/main/java/com/taobao/idlefish/flutterboost/interfaces/IStateListener.java
...obao/idlefish/flutterboost/interfaces/IStateListener.java
+14
-0
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/FlutterFragmentPageActivity.java
...fish/flutterboostexample/FlutterFragmentPageActivity.java
+47
-2
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/FlutterPageActivity.java
...bao/idlefish/flutterboostexample/FlutterPageActivity.java
+2
-2
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/MainActivity.java
...com/taobao/idlefish/flutterboostexample/MainActivity.java
+0
-3
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/MyApplication.java
...om/taobao/idlefish/flutterboostexample/MyApplication.java
+6
-2
example/android/app/src/main/res/layout/flutter_fragment_page.xml
...android/app/src/main/res/layout/flutter_fragment_page.xml
+43
-0
No files found.
android/build.gradle
View file @
0e7d161c
...
...
@@ -42,6 +42,6 @@ dependencies {
ext
{
groupId
=
'com.taobao.fleamarket'
artifactId
=
"FlutterBoost"
artifactId
=
"FlutterBoost
Plugin
"
}
android/src/main/java/com/taobao/idlefish/flutterboost/BoostEngineProvider.java
View file @
0e7d161c
...
...
@@ -23,36 +23,23 @@
*/
package
com.taobao.idlefish.flutterboost
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.os.Looper
;
import
android.support.annotation.NonNull
;
import
com.taobao.idlefish.flutterboost.interfaces.IFlutterEngineProvider
;
import
com.taobao.idlefish.flutterboost.interfaces.IStateListener
;
import
io.flutter.app.FlutterPluginRegistry
;
import
io.flutter.embedding.engine.FlutterEngine
;
import
io.flutter.embedding.engine.FlutterShellArgs
;
import
io.flutter.embedding.engine.dart.DartExecutor
;
import
io.flutter.plugin.common.BinaryMessenger
;
import
io.flutter.plugin.common.PluginRegistry
;
import
io.flutter.plugin.platform.PlatformViewRegistry
;
import
io.flutter.view.FlutterMain
;
import
io.flutter.view.FlutterNativeView
;
import
io.flutter.view.FlutterView
;
import
io.flutter.view.TextureRegistry
;
public
class
BoostEngineProvider
implements
IFlutterEngineProvider
{
static
final
BoostEngineProvider
sInstance
=
new
BoostEngineProvider
()
;
private
BoostFlutterEngine
mEngine
=
null
;
private
BoostEngine
mEngine
=
null
;
private
BoostEngineProvider
()
{
BoostEngineProvider
()
{
}
@Override
public
FlutterEngine
createEngine
(
Context
context
)
{
public
Boost
FlutterEngine
createEngine
(
Context
context
)
{
Utils
.
assertCallOnMainThread
();
...
...
@@ -61,35 +48,25 @@ public class BoostEngineProvider implements IFlutterEngineProvider {
FlutterMain
.
ensureInitializationComplete
(
context
.
getApplicationContext
(),
flutterShellArgs
.
toArray
());
mEngine
=
new
BoostEngine
(
context
.
getApplicationContext
());
mEngine
.
startRun
();
mEngine
=
new
BoostFlutterEngine
(
context
.
getApplicationContext
());
final
IStateListener
stateListener
=
FlutterBoostPlugin
.
sInstance
.
mStateListener
;
if
(
stateListener
!=
null
)
{
stateListener
.
onEngineCreated
(
mEngine
);
}
}
return
mEngine
;
}
@Override
public
FlutterEngine
tryGetEngine
()
{
public
Boost
FlutterEngine
tryGetEngine
()
{
return
mEngine
;
}
public
static
class
BoostEngine
extends
FlutterEngine
{
final
Context
mContext
;
public
BoostEngine
(
@NonNull
Context
context
)
{
super
(
context
);
mContext
=
context
;
}
public
void
startRun
()
{
if
(!
getDartExecutor
().
isExecutingDart
())
{
getNavigationChannel
().
setInitialRoute
(
"/"
);
DartExecutor
.
DartEntrypoint
entryPoint
=
new
DartExecutor
.
DartEntrypoint
(
mContext
.
getResources
().
getAssets
(),
FlutterMain
.
findAppBundlePath
(
mContext
),
"main"
);
getDartExecutor
().
executeDartEntrypoint
(
entryPoint
);
}
public
static
void
assertEngineRunning
(){
final
BoostFlutterEngine
engine
=
FlutterBoostPlugin
.
singleton
().
engineProvider
().
tryGetEngine
();
if
(
engine
==
null
||
!
engine
.
isRunning
())
{
throw
new
RuntimeException
(
"engine is not running yet!"
);
}
}
}
android/src/main/java/com/taobao/idlefish/flutterboost/Boost
PluginRegistry
.java
→
android/src/main/java/com/taobao/idlefish/flutterboost/Boost
FlutterEngine
.java
View file @
0e7d161c
...
...
@@ -2,44 +2,116 @@ package com.taobao.idlefish.flutterboost;
import
android.app.Activity
;
import
android.content.Context
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
com.taobao.idlefish.flutterboost.interfaces.IContainerRecord
;
import
com.taobao.idlefish.flutterboost.interfaces.IStateListener
;
import
java.lang.ref.WeakReference
;
import
io.flutter.app.FlutterPluginRegistry
;
import
io.flutter.embedding.engine.FlutterEngine
;
import
io.flutter.embedding.engine.dart.DartExecutor
;
import
io.flutter.plugin.common.BinaryMessenger
;
import
io.flutter.plugin.common.PluginRegistry
;
import
io.flutter.plugin.platform.PlatformViewRegistry
;
import
io.flutter.view.FlutterMain
;
import
io.flutter.view.FlutterView
;
import
io.flutter.view.TextureRegistry
;
public
class
BoostPluginRegistry
extends
FlutterPluginRegistry
{
private
final
FlutterEngine
mEngine
;
private
final
Activity
mActivity
;
public
class
BoostFlutterEngine
extends
FlutterEngine
{
protected
final
Context
mContext
;
protected
final
BoostPluginRegistry
mBoostPluginRegistry
;
protected
WeakReference
<
Activity
>
mCurrentActivityRef
;
public
BoostFlutterEngine
(
@NonNull
Context
context
)
{
super
(
context
);
mContext
=
context
.
getApplicationContext
();
mBoostPluginRegistry
=
new
BoostPluginRegistry
(
this
,
context
);
}
public
void
startRun
(
@Nullable
Activity
activity
)
{
mCurrentActivityRef
=
new
WeakReference
<>(
activity
);
if
(!
getDartExecutor
().
isExecutingDart
())
{
public
BoostPluginRegistry
(
FlutterEngine
engine
,
Activity
activity
)
{
super
(
engine
,
activity
);
mEngine
=
engine
;
mActivity
=
activity
;
Debuger
.
log
(
"engine start running..."
);
getNavigationChannel
().
setInitialRoute
(
"/"
);
DartExecutor
.
DartEntrypoint
entryPoint
=
new
DartExecutor
.
DartEntrypoint
(
mContext
.
getResources
().
getAssets
(),
FlutterMain
.
findAppBundlePath
(
mContext
),
"main"
);
getDartExecutor
().
executeDartEntrypoint
(
entryPoint
);
final
IStateListener
stateListener
=
FlutterBoostPlugin
.
sInstance
.
mStateListener
;
if
(
stateListener
!=
null
)
{
stateListener
.
onEngineStarted
(
this
);
}
FlutterBoostPlugin
.
singleton
().
platform
().
onRegisterPlugins
(
mBoostPluginRegistry
);
}
}
public
PluginRegistry
.
Registrar
registrarFor
(
String
pluginKey
)
{
return
new
BoostRegistrar
(
mActivity
,
mEngine
,
super
.
registrarFor
(
pluginKey
))
;
public
BoostPluginRegistry
getBoostPluginRegistry
()
{
return
mBoostPluginRegistry
;
}
public
static
class
BoostRegistrar
implements
PluginRegistry
.
Registrar
{
public
boolean
isRunning
(){
return
getDartExecutor
().
isExecutingDart
();
}
public
class
BoostPluginRegistry
extends
FlutterPluginRegistry
{
private
final
FlutterEngine
mEngine
;
public
BoostPluginRegistry
(
FlutterEngine
engine
,
Context
context
)
{
super
(
engine
,
context
);
mEngine
=
engine
;
}
public
PluginRegistry
.
Registrar
registrarFor
(
String
pluginKey
)
{
return
new
BoostRegistrar
(
mEngine
,
super
.
registrarFor
(
pluginKey
));
}
}
public
class
BoostRegistrar
implements
PluginRegistry
.
Registrar
{
private
final
PluginRegistry
.
Registrar
mRegistrar
;
private
final
FlutterEngine
mEngine
;
private
final
Activity
mActivity
;
BoostRegistrar
(
Activity
activity
,
FlutterEngine
engine
,
PluginRegistry
.
Registrar
registrar
)
{
BoostRegistrar
(
FlutterEngine
engine
,
PluginRegistry
.
Registrar
registrar
)
{
mRegistrar
=
registrar
;
mEngine
=
engine
;
mActivity
=
activity
;
}
@Override
public
Activity
activity
()
{
return
mActivity
;
Activity
activity
;
IContainerRecord
record
;
record
=
FlutterBoostPlugin
.
singleton
().
containerManager
().
getCurrentTopRecord
();
if
(
record
==
null
)
{
record
=
FlutterBoostPlugin
.
singleton
().
containerManager
().
getLastGenerateRecord
();
}
if
(
record
==
null
){
activity
=
FlutterBoostPlugin
.
singleton
().
currentActivity
();
}
else
{
activity
=
record
.
getContainer
().
getContextActivity
();
}
if
(
activity
==
null
&&
mCurrentActivityRef
!=
null
)
{
activity
=
mCurrentActivityRef
.
get
();
}
if
(
activity
==
null
)
{
throw
new
RuntimeException
(
"current has no valid Activity yet"
);
}
return
activity
;
}
@Override
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/BoostFlutterView.java
View file @
0e7d161c
...
...
@@ -26,22 +26,30 @@ package com.taobao.idlefish.flutterboost;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.graphics.Color
;
import
android.os.Bundle
;
import
android.support.v4.view.ViewCompat
;
import
android.util.Log
;
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.taobao.idlefish.flutterboost.interfaces.IStateListener
;
import
java.util.LinkedList
;
import
java.util.List
;
import
io.flutter.embedding.android.FlutterView
;
import
io.flutter.embedding.engine.FlutterEngine
;
import
io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener
;
import
io.flutter.plugin.platform.PlatformPlugin
;
public
class
BoostFlutterView
extends
FrameLayout
{
private
FlutterEngine
mFlutterEngine
;
private
Boost
FlutterEngine
mFlutterEngine
;
private
FlutterView
mFlutterView
;
...
...
@@ -49,24 +57,35 @@ public class BoostFlutterView extends FrameLayout {
private
Bundle
mArguments
;
private
BoostPluginRegistry
mBoostPluginRegistry
;
private
RenderingProgressCoverCreator
mRenderingProgressCoverCreator
;
private
View
mRenderingProgressCover
;
private
final
List
<
OnFirstFrameRenderedListener
>
mFirstFrameRenderedListeners
=
new
LinkedList
<>();
private
final
OnFirstFrameRenderedListener
mOnFirstFrameRenderedListener
=
new
OnFirstFrameRenderedListener
()
{
private
boolean
mNeedSnapshotWhenDetach
=
true
;
private
ImageView
mSnapshot
;
private
final
io
.
flutter
.
embedding
.
engine
.
renderer
.
OnFirstFrameRenderedListener
mOnFirstFrameRenderedListener
=
new
io
.
flutter
.
embedding
.
engine
.
renderer
.
OnFirstFrameRenderedListener
()
{
@Override
public
void
onFirstFrameRendered
()
{
if
(
mRenderingProgressCover
!=
null
&&
mRenderingProgressCover
.
getParent
()
!=
null
)
{
((
ViewGroup
)
mRenderingProgressCover
.
getParent
()).
removeView
(
mRenderingProgressCover
);
}
final
Object
[]
listeners
=
mFirstFrameRenderedListeners
.
toArray
();
for
(
Object
obj
:
listeners
)
{
((
OnFirstFrameRenderedListener
)
obj
).
onFirstFrameRendered
();
((
OnFirstFrameRenderedListener
)
obj
).
onFirstFrameRendered
(
BoostFlutterView
.
this
);
}
}
};
public
BoostFlutterView
(
Context
context
,
FlutterEngine
engine
,
Bundle
args
)
{
public
BoostFlutterView
(
Context
context
,
BoostFlutterEngine
engine
,
Bundle
args
,
RenderingProgressCoverCreator
creator
)
{
super
(
context
);
mFlutterEngine
=
engine
;
mArguments
=
args
;
mRenderingProgressCoverCreator
=
creator
;
init
();
}
...
...
@@ -85,14 +104,63 @@ public class BoostFlutterView extends FrameLayout {
addView
(
mFlutterView
,
new
FrameLayout
.
LayoutParams
(
ViewGroup
.
LayoutParams
.
MATCH_PARENT
,
ViewGroup
.
LayoutParams
.
MATCH_PARENT
));
if
(
mRenderingProgressCoverCreator
!=
null
)
{
mRenderingProgressCover
=
mRenderingProgressCoverCreator
.
createRenderingProgressCover
(
getContext
());
}
else
{
mRenderingProgressCover
=
createRenderingProgressCorver
();
}
if
(
mRenderingProgressCover
!=
null
)
{
addView
(
mRenderingProgressCover
,
new
FrameLayout
.
LayoutParams
(
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
);
mBoostPluginRegistry
=
new
BoostPluginRegistry
(
mFlutterEngine
,(
Activity
)
getContext
());
FlutterBoostPlugin
.
platform
().
onRegisterPlugins
(
mBoostPluginRegistry
);
mFlutterEngine
.
startRun
((
Activity
)
getContext
());
final
IStateListener
stateListener
=
FlutterBoostPlugin
.
sInstance
.
mStateListener
;
if
(
stateListener
!=
null
)
{
stateListener
.
onFlutterViewInited
(
mFlutterEngine
,
this
);
}
}
protected
FlutterEngine
createFlutterEngine
(
Context
context
)
{
return
BoostEngineProvider
.
sInstance
.
createEngine
(
context
);
protected
View
createRenderingProgressCorver
(){
FrameLayout
frameLayout
=
new
FrameLayout
(
getContext
());
frameLayout
.
setBackgroundColor
(
Color
.
WHITE
);
LinearLayout
linearLayout
=
new
LinearLayout
(
getContext
());
linearLayout
.
setOrientation
(
LinearLayout
.
VERTICAL
);
FrameLayout
.
LayoutParams
layoutParams
=
new
FrameLayout
.
LayoutParams
(
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
);
layoutParams
.
gravity
=
Gravity
.
CENTER
;
frameLayout
.
addView
(
linearLayout
,
layoutParams
);
ProgressBar
progressBar
=
new
ProgressBar
(
getContext
());
LinearLayout
.
LayoutParams
params
=
new
LinearLayout
.
LayoutParams
(
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
);
params
.
gravity
=
Gravity
.
CENTER_HORIZONTAL
;
linearLayout
.
addView
(
progressBar
,
params
);
TextView
textView
=
new
TextView
(
getContext
());
params
=
new
LinearLayout
.
LayoutParams
(
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
);
params
.
gravity
=
Gravity
.
CENTER_HORIZONTAL
;
textView
.
setText
(
"Frame Rendering..."
);
linearLayout
.
addView
(
textView
,
params
);
return
frameLayout
;
}
protected
BoostFlutterEngine
createFlutterEngine
(
Context
context
)
{
return
FlutterBoostPlugin
.
singleton
().
engineProvider
().
createEngine
(
context
);
}
public
void
addFirstFrameRendered
(
OnFirstFrameRenderedListener
listener
)
{
...
...
@@ -119,6 +187,11 @@ public class BoostFlutterView extends FrameLayout {
protected
void
onAttachedToWindow
()
{
super
.
onAttachedToWindow
();
mPlatformPlugin
.
onPostResume
();
ViewCompat
.
requestApplyInsets
(
this
);
}
public
BoostFlutterEngine
getEngine
(){
return
mFlutterEngine
;
}
public
void
onResume
()
{
...
...
@@ -143,13 +216,32 @@ public class BoostFlutterView extends FrameLayout {
public
void
onAttach
()
{
Debuger
.
log
(
"BoostFlutterView onAttach"
);
final
IStateListener
stateListener
=
FlutterBoostPlugin
.
sInstance
.
mStateListener
;
if
(
stateListener
!=
null
)
{
stateListener
.
beforeEngineAttach
(
mFlutterEngine
,
this
);
}
mFlutterView
.
attachToFlutterEngine
(
mFlutterEngine
);
if
(
stateListener
!=
null
)
{
stateListener
.
afterEngineAttached
(
mFlutterEngine
,
this
);
}
}
public
void
onDetach
()
{
Debuger
.
log
(
"BoostFlutterView onDetach"
);
if
(
mNeedSnapshotWhenDetach
)
{
//mFlutterView.
}
mFlutterView
.
removeOnFirstFrameRenderedListener
(
mOnFirstFrameRenderedListener
);
final
IStateListener
stateListener
=
FlutterBoostPlugin
.
sInstance
.
mStateListener
;
if
(
stateListener
!=
null
)
{
stateListener
.
beforeEngineDetach
(
mFlutterEngine
,
this
);
}
mFlutterView
.
detachFromFlutterEngine
();
if
(
stateListener
!=
null
)
{
stateListener
.
afterEngineDetached
(
mFlutterEngine
,
this
);
}
}
public
void
onDestroy
()
{
...
...
@@ -226,9 +318,10 @@ public class BoostFlutterView extends FrameLayout {
public
static
class
Builder
{
private
Context
context
;
private
FlutterEngine
engine
;
private
Boost
FlutterEngine
engine
;
private
FlutterView
.
RenderMode
renderMode
;
private
FlutterView
.
TransparencyMode
transparencyMode
;
private
RenderingProgressCoverCreator
renderingProgressCoverCreator
;
public
Builder
(
Context
ctx
)
{
this
.
context
=
ctx
;
...
...
@@ -236,7 +329,7 @@ public class BoostFlutterView extends FrameLayout {
transparencyMode
=
FlutterView
.
TransparencyMode
.
transparent
;
}
public
Builder
flutterEngine
(
FlutterEngine
engine
)
{
public
Builder
flutterEngine
(
Boost
FlutterEngine
engine
)
{
this
.
engine
=
engine
;
return
this
;
}
...
...
@@ -247,6 +340,10 @@ public class BoostFlutterView extends FrameLayout {
return
this
;
}
public
Builder
renderingProgressCoverCreator
(
RenderingProgressCoverCreator
creator
)
{
this
.
renderingProgressCoverCreator
=
creator
;
return
this
;
}
public
Builder
transparencyMode
(
FlutterView
.
TransparencyMode
transparencyMode
)
{
this
.
transparencyMode
=
transparencyMode
;
...
...
@@ -258,7 +355,15 @@ public class BoostFlutterView extends FrameLayout {
args
.
putString
(
"flutterview_render_mode"
,
renderMode
!=
null
?
renderMode
.
name
()
:
FlutterView
.
RenderMode
.
surface
.
name
());
args
.
putString
(
"flutterview_transparency_mode"
,
transparencyMode
!=
null
?
transparencyMode
.
name
()
:
FlutterView
.
TransparencyMode
.
transparent
.
name
());
return
new
BoostFlutterView
(
context
,
engine
,
args
);
return
new
BoostFlutterView
(
context
,
engine
,
args
,
renderingProgressCoverCreator
);
}
}
public
interface
OnFirstFrameRenderedListener
{
void
onFirstFrameRendered
(
BoostFlutterView
view
);
}
public
interface
RenderingProgressCoverCreator
{
View
createRenderingProgressCover
(
Context
context
);
}
}
android/src/main/java/com/taobao/idlefish/flutterboost/ContainerRecord.java
View file @
0e7d161c
...
...
@@ -66,6 +66,7 @@ public class ContainerRecord implements IContainerRecord {
@Override
public
void
onCreate
()
{
Utils
.
assertCallOnMainThread
();
BoostEngineProvider
.
assertEngineRunning
();
if
(
mState
!=
STATE_UNKNOW
)
{
Debuger
.
exception
(
"state error"
);
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/Debuger.java
View file @
0e7d161c
...
...
@@ -60,7 +60,7 @@ public class Debuger {
public
static
boolean
isDebug
(){
try
{
return
FlutterBoostPlugin
.
platform
().
isDebug
();
return
FlutterBoostPlugin
.
singleton
().
platform
().
isDebug
();
}
catch
(
Throwable
t
){
return
false
;
}
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/FlutterBoostPlugin.java
View file @
0e7d161c
This diff is collapsed.
Click to expand it.
android/src/main/java/com/taobao/idlefish/flutterboost/FlutterViewContainerManager.java
View file @
0e7d161c
...
...
@@ -52,8 +52,6 @@ public class FlutterViewContainerManager implements IContainerManager {
public
IOperateSyncer
generateSyncer
(
IFlutterViewContainer
container
)
{
Utils
.
assertCallOnMainThread
();
BoostEngineProvider
.
sInstance
.
createEngine
(
container
.
getContextActivity
());
ContainerRecord
record
=
new
ContainerRecord
(
this
,
container
);
if
(
mRecordMap
.
put
(
container
,
record
)
!=
null
)
{
Debuger
.
exception
(
"container:"
+
container
.
getContainerName
()
+
" already exists!"
);
...
...
@@ -64,7 +62,7 @@ public class FlutterViewContainerManager implements IContainerManager {
return
record
;
}
public
void
pushRecord
(
IContainerRecord
record
)
{
void
pushRecord
(
IContainerRecord
record
)
{
if
(!
mRecordMap
.
containsValue
(
record
))
{
Debuger
.
exception
(
"invalid record!"
);
}
...
...
@@ -72,13 +70,13 @@ public class FlutterViewContainerManager implements IContainerManager {
mRecordStack
.
push
(
record
);
}
public
void
popRecord
(
IContainerRecord
record
)
{
void
popRecord
(
IContainerRecord
record
)
{
if
(
mRecordStack
.
peek
()
==
record
)
{
mRecordStack
.
pop
();
}
}
public
void
removeRecord
(
IContainerRecord
record
)
{
void
removeRecord
(
IContainerRecord
record
)
{
mRecordStack
.
remove
(
record
);
mRecordMap
.
remove
(
record
.
getContainer
());
}
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/NavigationService/NavigationService_closePage.java
View file @
0e7d161c
...
...
@@ -25,7 +25,6 @@
package
com.taobao.idlefish.flutterboost.NavigationService
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
com.taobao.idlefish.flutterboost.FlutterViewContainerManager
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -39,7 +38,7 @@
private
boolean
onCall
(
MessageResult
<
Boolean
>
result
,
String
uniqueId
,
String
pageName
,
Map
params
,
Boolean
animated
){
FlutterBoostPlugin
.
containerManager
().
closeContainer
(
uniqueId
,
null
);
FlutterBoostPlugin
.
singleton
().
containerManager
().
closeContainer
(
uniqueId
,
null
);
result
.
success
(
true
);
return
true
;
}
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/NavigationService/NavigationService_onFlutterPageResult.java
View file @
0e7d161c
...
...
@@ -24,8 +24,6 @@
package
com.taobao.idlefish.flutterboost.NavigationService
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/NavigationService/NavigationService_onShownContainerChanged.java
View file @
0e7d161c
...
...
@@ -24,7 +24,6 @@
package
com.taobao.idlefish.flutterboost.NavigationService
;
import
com.taobao.idlefish.flutterboost.Debuger
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
java.util.ArrayList
;
...
...
@@ -40,7 +39,7 @@
private
boolean
onCall
(
MessageResult
<
Boolean
>
result
,
String
now
,
String
old
,
Map
params
){
//Add your handler code here.
FlutterBoostPlugin
.
containerManager
().
onShownContainerChanged
(
old
,
now
);
FlutterBoostPlugin
.
singleton
().
containerManager
().
onShownContainerChanged
(
old
,
now
);
return
true
;
}
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/NavigationService/NavigationService_openPage.java
View file @
0e7d161c
...
...
@@ -24,6 +24,8 @@
package
com.taobao.idlefish.flutterboost.NavigationService
;
import
android.content.Context
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
java.util.ArrayList
;
...
...
@@ -44,7 +46,13 @@
requestCode
=
(
int
)
params
.
get
(
"requestCode"
);
}
FlutterBoostPlugin
.
openPage
(
null
,
pageName
,
params
,
0
);
Context
ctx
=
FlutterBoostPlugin
.
singleton
().
currentActivity
();
if
(
ctx
==
null
)
{
ctx
=
FlutterBoostPlugin
.
singleton
().
platform
().
getApplication
();
}
FlutterBoostPlugin
.
singleton
().
platform
().
startActivity
(
ctx
,
pageName
,
params
,
requestCode
);
if
(
result
!=
null
){
result
.
success
(
true
);
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/NavigationService/NavigationService_pageOnStart.java
View file @
0e7d161c
...
...
@@ -25,9 +25,7 @@
package
com.taobao.idlefish.flutterboost.NavigationService
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
com.taobao.idlefish.flutterboost.FlutterViewContainerManager
;
import
com.taobao.idlefish.flutterboost.interfaces.IContainerRecord
;
import
com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
...
...
@@ -44,11 +42,11 @@
Map
<
String
,
Object
>
pageInfo
=
new
HashMap
<>();
try
{
IContainerRecord
record
=
FlutterBoostPlugin
IContainerRecord
record
=
FlutterBoostPlugin
.
singleton
()
.
containerManager
().
getCurrentTopRecord
();
if
(
record
==
null
)
{
record
=
FlutterBoostPlugin
.
containerManager
().
getLastGenerateRecord
();
record
=
FlutterBoostPlugin
.
singleton
().
containerManager
().
getLastGenerateRecord
();
}
pageInfo
.
put
(
"name"
,
record
.
getContainer
().
getContainerName
());
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/PageResultHandler.java
deleted
100755 → 0
View file @
c97e6421
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package
com.taobao.idlefish.flutterboost
;
import
java.util.Map
;
public
interface
PageResultHandler
{
void
onResult
(
String
key
,
Map
resultData
);
}
android/src/main/java/com/taobao/idlefish/flutterboost/PageResultMediator.java
deleted
100755 → 0
View file @
c97e6421
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package
com.taobao.idlefish.flutterboost
;
import
com.taobao.idlefish.flutterboost.NavigationService.NavigationService
;
import
java.util.HashMap
;
import
java.util.Map
;
import
fleamarket.taobao.com.xservicekit.handler.MessageResult
;
class
PageResultMediator
{
private
Map
<
String
,
PageResultHandler
>
_handlers
=
new
HashMap
<>();
void
onPageResult
(
String
key
,
Map
resultData
,
Map
params
){
if
(
key
==
null
)
return
;
if
(
_handlers
.
containsKey
(
key
)){
_handlers
.
get
(
key
).
onResult
(
key
,
resultData
);
_handlers
.
remove
(
key
);
}
else
{
if
(
params
==
null
||
!
params
.
containsKey
(
"forward"
)){
if
(
params
==
null
){
params
=
new
HashMap
();
}
params
.
put
(
"forward"
,
1
);
NavigationService
.
onNativePageResult
(
new
MessageResult
<
Boolean
>()
{
@Override
public
void
success
(
Boolean
var1
)
{
}
@Override
public
void
error
(
String
var1
,
String
var2
,
Object
var3
)
{
}
@Override
public
void
notImplemented
()
{
}
},
key
,
key
,
resultData
,
params
);
}
else
{
int
forward
=
(
Integer
)
params
.
get
(
"forward"
);
params
.
put
(
"forward"
,++
forward
);
if
(
forward
<=
2
){
NavigationService
.
onNativePageResult
(
new
MessageResult
<
Boolean
>()
{
@Override
public
void
success
(
Boolean
var1
)
{
}
@Override
public
void
error
(
String
var1
,
String
var2
,
Object
var3
)
{
}
@Override
public
void
notImplemented
()
{
}
},
key
,
key
,
resultData
,
params
);
}
}
}
}
void
setHandler
(
String
key
,
PageResultHandler
handler
){
if
(
key
==
null
||
handler
==
null
)
return
;
_handlers
.
put
(
key
,
handler
);
}
void
removeHandler
(
String
key
){
if
(
key
==
null
)
return
;;
_handlers
.
remove
(
key
);
}
}
android/src/main/java/com/taobao/idlefish/flutterboost/StateListener.java
0 → 100644
View file @
0e7d161c
package
com.taobao.idlefish.flutterboost
;
import
com.taobao.idlefish.flutterboost.interfaces.IStateListener
;
public
class
StateListener
implements
IStateListener
{
@Override
public
void
onEngineCreated
(
BoostFlutterEngine
engine
)
{
Debuger
.
log
(
">>onEngineCreated"
);
}
@Override
public
void
onEngineStarted
(
BoostFlutterEngine
engine
)
{
Debuger
.
log
(
">>onEngineStarted"
);
}
@Override
public
void
onFlutterViewInited
(
BoostFlutterEngine
engine
,
BoostFlutterView
flutterView
)
{
Debuger
.
log
(
">>onFlutterViewInited"
);
}
@Override
public
void
beforeEngineAttach
(
BoostFlutterEngine
engine
,
BoostFlutterView
flutterView
)
{
Debuger
.
log
(
">>beforeEngineAttach"
);
}
@Override
public
void
afterEngineAttached
(
BoostFlutterEngine
engine
,
BoostFlutterView
flutterView
)
{
Debuger
.
log
(
">>afterEngineAttached"
);
}
@Override
public
void
beforeEngineDetach
(
BoostFlutterEngine
engine
,
BoostFlutterView
flutterView
)
{
Debuger
.
log
(
">>beforeEngineDetach"
);
}
@Override
public
void
afterEngineDetached
(
BoostFlutterEngine
engine
,
BoostFlutterView
flutterView
)
{
Debuger
.
log
(
">>afterEngineDetached"
);
}
}
android/src/main/java/com/taobao/idlefish/flutterboost/containers/BoostFlutterActivity.java
View file @
0e7d161c
...
...
@@ -24,9 +24,23 @@
package
com.taobao.idlefish.flutterboost.containers
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.graphics.Color
;
import
android.graphics.drawable.ColorDrawable
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.view.Gravity
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.Window
;
import
android.view.WindowManager
;
import
android.widget.FrameLayout
;
import
android.widget.LinearLayout
;
import
android.widget.ProgressBar
;
import
android.widget.TextView
;
import
com.taobao.idlefish.flutterboost.BoostFlutterEngine
;
import
com.taobao.idlefish.flutterboost.BoostFlutterView
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer
;
...
...
@@ -35,25 +49,101 @@ import com.taobao.idlefish.flutterboost.interfaces.IOperateSyncer;
import
java.util.HashMap
;
import
io.flutter.embedding.android.FlutterView
;
import
io.flutter.plugin.platform.PlatformPlugin
;
public
abstract
class
BoostFlutterActivity
extends
Activity
implements
IFlutterViewContainer
{
private
BoostFlutterView
mFlutterView
;
private
IOperateSyncer
mSyncer
;
protected
BoostFlutterEngine
mFlutterEngine
;
protected
BoostFlutterView
mFlutterView
;
protected
IOperateSyncer
mSyncer
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
BoostFlutterView
.
Builder
builder
=
new
BoostFlutterView
.
Builder
(
this
);
mFlutterView
=
builder
.
renderMode
(
FlutterView
.
RenderMode
.
texture
)
.
transparencyMode
(
FlutterView
.
TransparencyMode
.
opaque
)
.
build
();
configureWindowForTransparency
();
mSyncer
=
FlutterBoostPlugin
.
singleton
().
containerManager
().
generateSyncer
(
this
);
mFlutterEngine
=
createFlutterEngine
();
mFlutterView
=
createFlutterView
(
mFlutterEngine
);
setContentView
(
mFlutterView
);
mSyncer
=
FlutterBoostPlugin
.
containerManager
().
generateSyncer
(
this
);
mSyncer
.
onCreate
();
configureStatusBarForFullscreenFlutterExperience
();
}
protected
void
configureWindowForTransparency
()
{
if
(
isBackgroundTransparent
())
{
getWindow
().
setBackgroundDrawable
(
new
ColorDrawable
(
Color
.
TRANSPARENT
));
getWindow
().
setFlags
(
WindowManager
.
LayoutParams
.
FLAG_LAYOUT_NO_LIMITS
,
WindowManager
.
LayoutParams
.
FLAG_LAYOUT_NO_LIMITS
);
}
}
protected
void
configureStatusBarForFullscreenFlutterExperience
()
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
Window
window
=
getWindow
();
window
.
addFlags
(
WindowManager
.
LayoutParams
.
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
);
window
.
setStatusBarColor
(
0x40000000
);
window
.
getDecorView
().
setSystemUiVisibility
(
PlatformPlugin
.
DEFAULT_SYSTEM_UI
);
}
}
protected
BoostFlutterEngine
createFlutterEngine
(){
return
FlutterBoostPlugin
.
singleton
().
engineProvider
().
createEngine
(
this
);
}
protected
BoostFlutterView
createFlutterView
(
BoostFlutterEngine
engine
){
BoostFlutterView
.
Builder
builder
=
new
BoostFlutterView
.
Builder
(
this
);
return
builder
.
flutterEngine
(
engine
)
.
renderMode
(
FlutterView
.
RenderMode
.
texture
)
.
transparencyMode
(
isBackgroundTransparent
()
?
FlutterView
.
TransparencyMode
.
transparent
:
FlutterView
.
TransparencyMode
.
opaque
)
.
renderingProgressCoverCreator
(
new
BoostFlutterView
.
RenderingProgressCoverCreator
()
{
@Override
public
View
createRenderingProgressCover
(
Context
context
)
{
return
BoostFlutterActivity
.
this
.
createRenderingProgressCover
();
}
})
.
build
();
}
protected
boolean
isBackgroundTransparent
(){
return
false
;
}
protected
View
createRenderingProgressCover
(){
FrameLayout
frameLayout
=
new
FrameLayout
(
this
);
LinearLayout
linearLayout
=
new
LinearLayout
(
this
);
linearLayout
.
setOrientation
(
LinearLayout
.
VERTICAL
);
FrameLayout
.
LayoutParams
layoutParams
=
new
FrameLayout
.
LayoutParams
(
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
);
layoutParams
.
gravity
=
Gravity
.
CENTER
;
frameLayout
.
addView
(
linearLayout
,
layoutParams
);
ProgressBar
progressBar
=
new
ProgressBar
(
this
);
LinearLayout
.
LayoutParams
params
=
new
LinearLayout
.
LayoutParams
(
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
);
params
.
gravity
=
Gravity
.
CENTER_HORIZONTAL
;
linearLayout
.
addView
(
progressBar
,
params
);
TextView
textView
=
new
TextView
(
this
);
params
=
new
LinearLayout
.
LayoutParams
(
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
);
params
.
gravity
=
Gravity
.
CENTER_HORIZONTAL
;
textView
.
setText
(
"Frame Rendering..."
);
linearLayout
.
addView
(
textView
,
params
);
return
frameLayout
;
}
@Override
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/containers/BoostFlutterFragment.java
View file @
0e7d161c
...
...
@@ -32,6 +32,7 @@ import android.view.LayoutInflater;
import
android.view.View
;
import
android.view.ViewGroup
;
import
com.taobao.idlefish.flutterboost.BoostFlutterEngine
;
import
com.taobao.idlefish.flutterboost.BoostFlutterView
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer
;
...
...
@@ -43,23 +44,36 @@ import io.flutter.embedding.android.FlutterView;
abstract
public
class
BoostFlutterFragment
extends
Fragment
implements
IFlutterViewContainer
{
private
BoostFlutterView
mFlutterView
;
private
IOperateSyncer
mSyncer
;
protected
BoostFlutterEngine
mFlutterEngine
;
protected
BoostFlutterView
mFlutterView
;
protected
IOperateSyncer
mSyncer
;
@Nullable
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
BoostFlutterView
.
Builder
builder
=
new
BoostFlutterView
.
Builder
(
getContextActivity
()
);
mFlutterView
=
builder
.
renderMode
(
FlutterView
.
RenderMode
.
texture
)
.
transparencyMode
(
FlutterView
.
TransparencyMode
.
opaque
)
.
build
(
);
mSyncer
=
FlutterBoostPlugin
.
singleton
().
containerManager
().
generateSyncer
(
this
);
mFlutterEngine
=
createFlutterEngine
();
mFlutterView
=
createFlutterView
(
mFlutterEngine
);
mSyncer
=
FlutterBoostPlugin
.
containerManager
().
generateSyncer
(
this
);
mSyncer
.
onCreate
();
return
mFlutterView
;
}
protected
BoostFlutterEngine
createFlutterEngine
(){
return
FlutterBoostPlugin
.
singleton
().
engineProvider
().
createEngine
(
getContext
());
}
protected
BoostFlutterView
createFlutterView
(
BoostFlutterEngine
engine
){
BoostFlutterView
.
Builder
builder
=
new
BoostFlutterView
.
Builder
(
getContextActivity
());
return
builder
.
flutterEngine
(
engine
)
.
renderMode
(
FlutterView
.
RenderMode
.
texture
)
.
transparencyMode
(
FlutterView
.
TransparencyMode
.
opaque
)
.
build
();
}
@Override
public
void
onResume
()
{
super
.
onResume
();
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/interfaces/IFlutterEngineProvider.java
View file @
0e7d161c
...
...
@@ -25,6 +25,7 @@ package com.taobao.idlefish.flutterboost.interfaces;
import
android.content.Context
;
import
com.taobao.idlefish.flutterboost.BoostFlutterEngine
;
import
com.taobao.idlefish.flutterboost.BoostFlutterView
;
import
io.flutter.embedding.engine.FlutterEngine
;
...
...
@@ -38,11 +39,11 @@ public interface IFlutterEngineProvider {
* @param context
* @return
*/
FlutterEngine
createEngine
(
Context
context
);
Boost
FlutterEngine
createEngine
(
Context
context
);
/**
* may return null
* @return
*/
FlutterEngine
tryGetEngine
();
Boost
FlutterEngine
tryGetEngine
();
}
android/src/main/java/com/taobao/idlefish/flutterboost/interfaces/IPlatform.java
View file @
0e7d161c
...
...
@@ -23,7 +23,6 @@
*/
package
com.taobao.idlefish.flutterboost.interfaces
;
import
android.app.Activity
;
import
android.app.Application
;
import
android.content.Context
;
...
...
@@ -36,6 +35,10 @@ import io.flutter.plugin.common.PluginRegistry;
*/
public
interface
IPlatform
{
int
IMMEDIATELY
=
0
;
//立即启动引擎
int
ANY_ACTIVITY_CREATED
=
1
;
//当有任何Activity创建时,启动引擎
int
LAZY
=
2
;
//尽可能延后启动引擎(通常是首页Flutter页面加载时)
/**
* get current application
* @return
...
...
@@ -43,16 +46,16 @@ public interface IPlatform {
Application
getApplication
();
/**
*
register plugins
*
debug or not
* @return
*/
void
onRegisterPlugins
(
PluginRegistry
registry
);
boolean
isDebug
(
);
/**
*
debug or not
*
register plugins
* @return
*/
boolean
isDebug
(
);
void
onRegisterPlugins
(
PluginRegistry
registry
);
/**
* start a new activity from flutter page, you may need a page router with url
...
...
@@ -65,8 +68,11 @@ public interface IPlatform {
/**
* settings, no use
* @return
*
* IMMEDIATELY //立即
* ANY_ACTIVITY_CREATED //当有任何Activity创建的时候
* LAZY //懒加载,尽可能延后
*/
Map
getSettings
();
int
whenEngineStart
();
}
android/src/main/java/com/taobao/idlefish/flutterboost/interfaces/IStateListener.java
0 → 100644
View file @
0e7d161c
package
com.taobao.idlefish.flutterboost.interfaces
;
import
com.taobao.idlefish.flutterboost.BoostFlutterEngine
;
import
com.taobao.idlefish.flutterboost.BoostFlutterView
;
public
interface
IStateListener
{
void
onEngineCreated
(
BoostFlutterEngine
engine
);
void
onEngineStarted
(
BoostFlutterEngine
engine
);
void
onFlutterViewInited
(
BoostFlutterEngine
engine
,
BoostFlutterView
flutterView
);
void
beforeEngineAttach
(
BoostFlutterEngine
engine
,
BoostFlutterView
flutterView
);
void
afterEngineAttached
(
BoostFlutterEngine
engine
,
BoostFlutterView
flutterView
);
void
beforeEngineDetach
(
BoostFlutterEngine
engine
,
BoostFlutterView
flutterView
);
void
afterEngineDetached
(
BoostFlutterEngine
engine
,
BoostFlutterView
flutterView
);
}
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/FlutterFragmentPageActivity.java
View file @
0e7d161c
package
com.taobao.idlefish.flutterboostexample
;
import
android.graphics.Color
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.support.v7.app.ActionBar
;
import
android.support.v7.app.AppCompatActivity
;
import
android.view.View
;
import
android.view.Window
;
import
android.view.WindowManager
;
import
io.flutter.plugin.platform.PlatformPlugin
;
public
class
FlutterFragmentPageActivity
extends
AppCompatActivity
{
public
class
FlutterFragmentPageActivity
extends
AppCompatActivity
implements
View
.
OnClickListener
{
private
FlutterFragment
mFragment
;
private
View
mTab1
;
private
View
mTab2
;
private
View
mTab3
;
private
View
mTab4
;
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
supportRequestWindowFeature
(
Window
.
FEATURE_NO_TITLE
);
...
...
@@ -32,11 +39,49 @@ public class FlutterFragmentPageActivity extends AppCompatActivity {
setContentView
(
R
.
layout
.
flutter_fragment_page
);
mFragment
=
FlutterFragment
.
instance
(
"hello"
);
mTab1
=
findViewById
(
R
.
id
.
tab1
);
mTab2
=
findViewById
(
R
.
id
.
tab2
);
mTab3
=
findViewById
(
R
.
id
.
tab3
);
mTab4
=
findViewById
(
R
.
id
.
tab4
);
mTab1
.
setOnClickListener
(
this
);
mTab2
.
setOnClickListener
(
this
);
mTab3
.
setOnClickListener
(
this
);
mTab4
.
setOnClickListener
(
this
);
}
@Override
public
void
onClick
(
View
v
)
{
mTab1
.
setBackgroundColor
(
Color
.
WHITE
);
mTab2
.
setBackgroundColor
(
Color
.
WHITE
);
mTab3
.
setBackgroundColor
(
Color
.
WHITE
);
mTab4
.
setBackgroundColor
(
Color
.
WHITE
);
if
(
mTab1
==
v
)
{
mTab1
.
setBackgroundColor
(
Color
.
YELLOW
);
mFragment
=
FlutterFragment
.
instance
(
"tab1"
);
}
else
if
(
mTab2
==
v
)
{
mTab2
.
setBackgroundColor
(
Color
.
YELLOW
);
mFragment
=
FlutterFragment
.
instance
(
"tab2"
);
}
else
if
(
mTab3
==
v
)
{
mTab3
.
setBackgroundColor
(
Color
.
YELLOW
);
mFragment
=
FlutterFragment
.
instance
(
"tab3"
);
}
else
{
mTab4
.
setBackgroundColor
(
Color
.
YELLOW
);
mFragment
=
FlutterFragment
.
instance
(
"tab4"
);
}
getSupportFragmentManager
()
.
beginTransaction
()
.
replace
(
R
.
id
.
fragment_stub
,
mFragment
)
.
commit
();
}
@Override
protected
void
onResume
()
{
super
.
onResume
();
mTab1
.
performClick
();
}
}
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/FlutterPageActivity.java
View file @
0e7d161c
...
...
@@ -15,7 +15,7 @@ public class FlutterPageActivity extends BoostFlutterActivity {
* 混合栈将会在flutter层根据这个名字,在注册的Route表中查找对应的Widget
*
* 在flutter层有注册函数:
* FlutterBoost.singleton.registerPageBuilders({
* FlutterBoost
Plugin
.singleton.registerPageBuilders({
* 'first': (pageName, params, _) => FirstRouteWidget(),
* 'second': (pageName, params, _) => SecondRouteWidget(),
* ...
...
...
@@ -34,7 +34,7 @@ public class FlutterPageActivity extends BoostFlutterActivity {
* 该方法返回的参数将会传递给上层的flutter对应的Widget
*
* 在flutter层有注册函数:
* FlutterBoost.singleton.registerPageBuilders({
* FlutterBoost
Plugin
.singleton.registerPageBuilders({
* 'first': (pageName, params, _) => FirstRouteWidget(),
* 'second': (pageName, params, _) => SecondRouteWidget(),
* ...
...
...
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/MainActivity.java
View file @
0e7d161c
...
...
@@ -6,8 +6,6 @@ import android.support.v7.app.AppCompatActivity;
import
android.view.View
;
import
android.widget.TextView
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
java.lang.ref.WeakReference
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -52,7 +50,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
PageRouter
.
openPageByUrl
(
this
,
PageRouter
.
NATIVE_PAGE_URL
,
params
);
}
else
if
(
v
==
mOpenFlutter
)
{
PageRouter
.
openPageByUrl
(
this
,
PageRouter
.
FLUTTER_PAGE_URL
,
params
);
FlutterBoostPlugin
.
onPageResult
(
"result_id_100"
,
new
HashMap
(),
new
HashMap
());
}
else
if
(
v
==
mOpenFlutterFragment
)
{
PageRouter
.
openPageByUrl
(
this
,
PageRouter
.
FLUTTER_FRAGMENT_PAGE_URL
,
params
);
}
...
...
example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/MyApplication.java
View file @
0e7d161c
...
...
@@ -3,9 +3,13 @@ package com.taobao.idlefish.flutterboostexample;
import
android.app.Application
;
import
android.content.Context
;
import
com.taobao.idlefish.flutterboost.BoostFlutterEngine
;
import
com.taobao.idlefish.flutterboost.BoostFlutterView
;
import
com.taobao.idlefish.flutterboost.Debuger
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
com.taobao.idlefish.flutterboost.StateListener
;
import
com.taobao.idlefish.flutterboost.interfaces.IPlatform
;
import
com.taobao.idlefish.flutterboost.interfaces.IStateListener
;
import
java.util.Map
;
...
...
@@ -54,8 +58,8 @@ public class MyApplication extends FlutterApplication {
}
@Override
public
Map
getSettings
()
{
return
null
;
public
int
whenEngineStart
()
{
return
IMMEDIATELY
;
}
});
}
...
...
example/android/app/src/main/res/layout/flutter_fragment_page.xml
View file @
0e7d161c
...
...
@@ -11,4 +11,47 @@
android:layout_weight=
"1"
android:id=
"@+id/fragment_stub"
/>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
>
<TextView
android:layout_width=
"0dp"
android:layout_height=
"56dp"
android:text=
"tab1"
android:id=
"@+id/tab1"
android:gravity=
"center"
android:textColor=
"@android:color/background_dark"
android:layout_weight=
"1"
/>
<TextView
android:layout_width=
"0dp"
android:layout_height=
"56dp"
android:text=
"tab2"
android:id=
"@+id/tab2"
android:gravity=
"center"
android:textColor=
"@android:color/background_dark"
android:layout_weight=
"1"
/>
<TextView
android:layout_width=
"0dp"
android:layout_height=
"56dp"
android:text=
"tab3"
android:id=
"@+id/tab3"
android:gravity=
"center"
android:textColor=
"@android:color/background_dark"
android:layout_weight=
"1"
/>
<TextView
android:layout_width=
"0dp"
android:layout_height=
"56dp"
android:text=
"tab4"
android:id=
"@+id/tab4"
android:gravity=
"center"
android:textColor=
"@android:color/background_dark"
android:layout_weight=
"1"
/>
</LinearLayout>
</LinearLayout>
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