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
0e7d161c
Commit
0e7d161c
authored
Jun 21, 2019
by
Yacumima
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve
parent
c97e6421
Changes
26
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 {
...
@@ -42,6 +42,6 @@ dependencies {
ext
{
ext
{
groupId
=
'com.taobao.fleamarket'
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 @@
...
@@ -23,36 +23,23 @@
*/
*/
package
com.taobao.idlefish.flutterboost
;
package
com.taobao.idlefish.flutterboost
;
import
android.app.Activity
;
import
android.content.Context
;
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.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.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.FlutterMain
;
import
io.flutter.view.FlutterNativeView
;
import
io.flutter.view.FlutterView
;
import
io.flutter.view.TextureRegistry
;
public
class
BoostEngineProvider
implements
IFlutterEngineProvider
{
public
class
BoostEngineProvider
implements
IFlutterEngineProvider
{
static
final
BoostEngineProvider
sInstance
=
new
BoostEngineProvider
()
;
private
BoostFlutterEngine
mEngine
=
null
;
private
BoostEngine
mEngine
=
null
;
BoostEngineProvider
()
{
private
BoostEngineProvider
()
{
}
}
@Override
@Override
public
FlutterEngine
createEngine
(
Context
context
)
{
public
Boost
FlutterEngine
createEngine
(
Context
context
)
{
Utils
.
assertCallOnMainThread
();
Utils
.
assertCallOnMainThread
();
...
@@ -61,35 +48,25 @@ public class BoostEngineProvider implements IFlutterEngineProvider {
...
@@ -61,35 +48,25 @@ public class BoostEngineProvider implements IFlutterEngineProvider {
FlutterMain
.
ensureInitializationComplete
(
FlutterMain
.
ensureInitializationComplete
(
context
.
getApplicationContext
(),
flutterShellArgs
.
toArray
());
context
.
getApplicationContext
(),
flutterShellArgs
.
toArray
());
mEngine
=
new
BoostEngine
(
context
.
getApplicationContext
());
mEngine
=
new
BoostFlutterEngine
(
context
.
getApplicationContext
());
mEngine
.
startRun
();
final
IStateListener
stateListener
=
FlutterBoostPlugin
.
sInstance
.
mStateListener
;
if
(
stateListener
!=
null
)
{
stateListener
.
onEngineCreated
(
mEngine
);
}
}
}
return
mEngine
;
return
mEngine
;
}
}
@Override
@Override
public
FlutterEngine
tryGetEngine
()
{
public
Boost
FlutterEngine
tryGetEngine
()
{
return
mEngine
;
return
mEngine
;
}
}
public
static
class
BoostEngine
extends
FlutterEngine
{
public
static
void
assertEngineRunning
(){
final
Context
mContext
;
final
BoostFlutterEngine
engine
=
FlutterBoostPlugin
.
singleton
().
engineProvider
().
tryGetEngine
();
if
(
engine
==
null
||
!
engine
.
isRunning
())
{
public
BoostEngine
(
@NonNull
Context
context
)
{
throw
new
RuntimeException
(
"engine is not running yet!"
);
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
);
}
}
}
}
}
}
}
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;
...
@@ -2,44 +2,116 @@ package com.taobao.idlefish.flutterboost;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.content.Context
;
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.app.FlutterPluginRegistry
;
import
io.flutter.embedding.engine.FlutterEngine
;
import
io.flutter.embedding.engine.FlutterEngine
;
import
io.flutter.embedding.engine.dart.DartExecutor
;
import
io.flutter.plugin.common.BinaryMessenger
;
import
io.flutter.plugin.common.BinaryMessenger
;
import
io.flutter.plugin.common.PluginRegistry
;
import
io.flutter.plugin.common.PluginRegistry
;
import
io.flutter.plugin.platform.PlatformViewRegistry
;
import
io.flutter.plugin.platform.PlatformViewRegistry
;
import
io.flutter.view.FlutterMain
;
import
io.flutter.view.FlutterView
;
import
io.flutter.view.FlutterView
;
import
io.flutter.view.TextureRegistry
;
import
io.flutter.view.TextureRegistry
;
public
class
BoostPluginRegistry
extends
FlutterPluginRegistry
{
public
class
BoostFlutterEngine
extends
FlutterEngine
{
private
final
FlutterEngine
mEngine
;
protected
final
Context
mContext
;
private
final
Activity
mActivity
;
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
)
{
Debuger
.
log
(
"engine start running..."
);
super
(
engine
,
activity
);
mEngine
=
engine
;
getNavigationChannel
().
setInitialRoute
(
"/"
);
mActivity
=
activity
;
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
)
{
public
BoostPluginRegistry
getBoostPluginRegistry
()
{
return
new
BoostRegistrar
(
mActivity
,
mEngine
,
super
.
registrarFor
(
pluginKey
))
;
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
PluginRegistry
.
Registrar
mRegistrar
;
private
final
FlutterEngine
mEngine
;
private
final
FlutterEngine
mEngine
;
private
final
Activity
mActivity
;
BoostRegistrar
(
Activity
activity
,
FlutterEngine
engine
,
PluginRegistry
.
Registrar
registrar
)
{
BoostRegistrar
(
FlutterEngine
engine
,
PluginRegistry
.
Registrar
registrar
)
{
mRegistrar
=
registrar
;
mRegistrar
=
registrar
;
mEngine
=
engine
;
mEngine
=
engine
;
mActivity
=
activity
;
}
}
@Override
@Override
public
Activity
activity
()
{
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
@Override
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/BoostFlutterView.java
View file @
0e7d161c
...
@@ -26,22 +26,30 @@ package com.taobao.idlefish.flutterboost;
...
@@ -26,22 +26,30 @@ package com.taobao.idlefish.flutterboost;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.graphics.Color
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.v4.view.ViewCompat
;
import
android.util.Log
;
import
android.util.Log
;
import
android.view.Gravity
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
android.widget.FrameLayout
;
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.LinkedList
;
import
java.util.List
;
import
java.util.List
;
import
io.flutter.embedding.android.FlutterView
;
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
;
import
io.flutter.plugin.platform.PlatformPlugin
;
public
class
BoostFlutterView
extends
FrameLayout
{
public
class
BoostFlutterView
extends
FrameLayout
{
private
FlutterEngine
mFlutterEngine
;
private
Boost
FlutterEngine
mFlutterEngine
;
private
FlutterView
mFlutterView
;
private
FlutterView
mFlutterView
;
...
@@ -49,24 +57,35 @@ public class BoostFlutterView extends FrameLayout {
...
@@ -49,24 +57,35 @@ public class BoostFlutterView extends FrameLayout {
private
Bundle
mArguments
;
private
Bundle
mArguments
;
private
BoostPluginRegistry
mBoostPluginRegistry
;
private
RenderingProgressCoverCreator
mRenderingProgressCoverCreator
;
private
View
mRenderingProgressCover
;
private
final
List
<
OnFirstFrameRenderedListener
>
mFirstFrameRenderedListeners
=
new
LinkedList
<>();
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
@Override
public
void
onFirstFrameRendered
()
{
public
void
onFirstFrameRendered
()
{
if
(
mRenderingProgressCover
!=
null
&&
mRenderingProgressCover
.
getParent
()
!=
null
)
{
((
ViewGroup
)
mRenderingProgressCover
.
getParent
()).
removeView
(
mRenderingProgressCover
);
}
final
Object
[]
listeners
=
mFirstFrameRenderedListeners
.
toArray
();
final
Object
[]
listeners
=
mFirstFrameRenderedListeners
.
toArray
();
for
(
Object
obj
:
listeners
)
{
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
);
super
(
context
);
mFlutterEngine
=
engine
;
mFlutterEngine
=
engine
;
mArguments
=
args
;
mArguments
=
args
;
mRenderingProgressCoverCreator
=
creator
;
init
();
init
();
}
}
...
@@ -85,14 +104,63 @@ public class BoostFlutterView extends FrameLayout {
...
@@ -85,14 +104,63 @@ 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
));
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
);
mFlutterView
.
addOnFirstFrameRenderedListener
(
mOnFirstFrameRenderedListener
);
mBoostPluginRegistry
=
new
BoostPluginRegistry
(
mFlutterEngine
,(
Activity
)
getContext
());
mFlutterEngine
.
startRun
((
Activity
)
getContext
());
FlutterBoostPlugin
.
platform
().
onRegisterPlugins
(
mBoostPluginRegistry
);
final
IStateListener
stateListener
=
FlutterBoostPlugin
.
sInstance
.
mStateListener
;
if
(
stateListener
!=
null
)
{
stateListener
.
onFlutterViewInited
(
mFlutterEngine
,
this
);
}
}
}
protected
FlutterEngine
createFlutterEngine
(
Context
context
)
{
protected
View
createRenderingProgressCorver
(){
return
BoostEngineProvider
.
sInstance
.
createEngine
(
context
);
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
)
{
public
void
addFirstFrameRendered
(
OnFirstFrameRenderedListener
listener
)
{
...
@@ -119,6 +187,11 @@ public class BoostFlutterView extends FrameLayout {
...
@@ -119,6 +187,11 @@ public class BoostFlutterView extends FrameLayout {
protected
void
onAttachedToWindow
()
{
protected
void
onAttachedToWindow
()
{
super
.
onAttachedToWindow
();
super
.
onAttachedToWindow
();
mPlatformPlugin
.
onPostResume
();
mPlatformPlugin
.
onPostResume
();
ViewCompat
.
requestApplyInsets
(
this
);
}
public
BoostFlutterEngine
getEngine
(){
return
mFlutterEngine
;
}
}
public
void
onResume
()
{
public
void
onResume
()
{
...
@@ -143,13 +216,32 @@ public class BoostFlutterView extends FrameLayout {
...
@@ -143,13 +216,32 @@ public class BoostFlutterView extends FrameLayout {
public
void
onAttach
()
{
public
void
onAttach
()
{
Debuger
.
log
(
"BoostFlutterView onAttach"
);
Debuger
.
log
(
"BoostFlutterView onAttach"
);
final
IStateListener
stateListener
=
FlutterBoostPlugin
.
sInstance
.
mStateListener
;
if
(
stateListener
!=
null
)
{
stateListener
.
beforeEngineAttach
(
mFlutterEngine
,
this
);
}
mFlutterView
.
attachToFlutterEngine
(
mFlutterEngine
);
mFlutterView
.
attachToFlutterEngine
(
mFlutterEngine
);
if
(
stateListener
!=
null
)
{
stateListener
.
afterEngineAttached
(
mFlutterEngine
,
this
);
}
}
}
public
void
onDetach
()
{
public
void
onDetach
()
{
Debuger
.
log
(
"BoostFlutterView onDetach"
);
Debuger
.
log
(
"BoostFlutterView onDetach"
);
if
(
mNeedSnapshotWhenDetach
)
{
//mFlutterView.
}
mFlutterView
.
removeOnFirstFrameRenderedListener
(
mOnFirstFrameRenderedListener
);
mFlutterView
.
removeOnFirstFrameRenderedListener
(
mOnFirstFrameRenderedListener
);
final
IStateListener
stateListener
=
FlutterBoostPlugin
.
sInstance
.
mStateListener
;
if
(
stateListener
!=
null
)
{
stateListener
.
beforeEngineDetach
(
mFlutterEngine
,
this
);
}
mFlutterView
.
detachFromFlutterEngine
();
mFlutterView
.
detachFromFlutterEngine
();
if
(
stateListener
!=
null
)
{
stateListener
.
afterEngineDetached
(
mFlutterEngine
,
this
);
}
}
}
public
void
onDestroy
()
{
public
void
onDestroy
()
{
...
@@ -226,9 +318,10 @@ public class BoostFlutterView extends FrameLayout {
...
@@ -226,9 +318,10 @@ public class BoostFlutterView extends FrameLayout {
public
static
class
Builder
{
public
static
class
Builder
{
private
Context
context
;
private
Context
context
;
private
FlutterEngine
engine
;
private
Boost
FlutterEngine
engine
;
private
FlutterView
.
RenderMode
renderMode
;
private
FlutterView
.
RenderMode
renderMode
;
private
FlutterView
.
TransparencyMode
transparencyMode
;
private
FlutterView
.
TransparencyMode
transparencyMode
;
private
RenderingProgressCoverCreator
renderingProgressCoverCreator
;
public
Builder
(
Context
ctx
)
{
public
Builder
(
Context
ctx
)
{
this
.
context
=
ctx
;
this
.
context
=
ctx
;
...
@@ -236,7 +329,7 @@ public class BoostFlutterView extends FrameLayout {
...
@@ -236,7 +329,7 @@ public class BoostFlutterView extends FrameLayout {
transparencyMode
=
FlutterView
.
TransparencyMode
.
transparent
;
transparencyMode
=
FlutterView
.
TransparencyMode
.
transparent
;
}
}
public
Builder
flutterEngine
(
FlutterEngine
engine
)
{
public
Builder
flutterEngine
(
Boost
FlutterEngine
engine
)
{
this
.
engine
=
engine
;
this
.
engine
=
engine
;
return
this
;
return
this
;
}
}
...
@@ -247,6 +340,10 @@ public class BoostFlutterView extends FrameLayout {
...
@@ -247,6 +340,10 @@ public class BoostFlutterView extends FrameLayout {
return
this
;
return
this
;
}
}
public
Builder
renderingProgressCoverCreator
(
RenderingProgressCoverCreator
creator
)
{
this
.
renderingProgressCoverCreator
=
creator
;
return
this
;
}
public
Builder
transparencyMode
(
FlutterView
.
TransparencyMode
transparencyMode
)
{
public
Builder
transparencyMode
(
FlutterView
.
TransparencyMode
transparencyMode
)
{
this
.
transparencyMode
=
transparencyMode
;
this
.
transparencyMode
=
transparencyMode
;
...
@@ -258,7 +355,15 @@ public class BoostFlutterView extends FrameLayout {
...
@@ -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_render_mode"
,
renderMode
!=
null
?
renderMode
.
name
()
:
FlutterView
.
RenderMode
.
surface
.
name
());
args
.
putString
(
"flutterview_transparency_mode"
,
transparencyMode
!=
null
?
transparencyMode
.
name
()
:
FlutterView
.
TransparencyMode
.
transparent
.
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 {
...
@@ -66,6 +66,7 @@ public class ContainerRecord implements IContainerRecord {
@Override
@Override
public
void
onCreate
()
{
public
void
onCreate
()
{
Utils
.
assertCallOnMainThread
();
Utils
.
assertCallOnMainThread
();
BoostEngineProvider
.
assertEngineRunning
();
if
(
mState
!=
STATE_UNKNOW
)
{
if
(
mState
!=
STATE_UNKNOW
)
{
Debuger
.
exception
(
"state error"
);
Debuger
.
exception
(
"state error"
);
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/Debuger.java
View file @
0e7d161c
...
@@ -60,7 +60,7 @@ public class Debuger {
...
@@ -60,7 +60,7 @@ public class Debuger {
public
static
boolean
isDebug
(){
public
static
boolean
isDebug
(){
try
{
try
{
return
FlutterBoostPlugin
.
platform
().
isDebug
();
return
FlutterBoostPlugin
.
singleton
().
platform
().
isDebug
();
}
catch
(
Throwable
t
){
}
catch
(
Throwable
t
){
return
false
;
return
false
;
}
}
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/FlutterBoostPlugin.java
View file @
0e7d161c
...
@@ -25,96 +25,68 @@ package com.taobao.idlefish.flutterboost;
...
@@ -25,96 +25,68 @@ package com.taobao.idlefish.flutterboost;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.app.Application
;
import
android.app.Application
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
com.alibaba.fastjson.JSON
;
import
com.taobao.idlefish.flutterboost.NavigationService.NavigationService
;
import
com.taobao.idlefish.flutterboost.NavigationService.NavigationService
;
import
com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer
;
import
com.taobao.idlefish.flutterboost.loader.ServiceLoader
;
import
com.taobao.idlefish.flutterboost.interfaces.IContainerManager
;
import
com.taobao.idlefish.flutterboost.interfaces.IContainerManager
;
import
com.taobao.idlefish.flutterboost.interfaces.IFlutterEngineProvider
;
import
com.taobao.idlefish.flutterboost.interfaces.IFlutterEngineProvider
;
import
com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer
;
import
com.taobao.idlefish.flutterboost.interfaces.IPlatform
;
import
com.taobao.idlefish.flutterboost.interfaces.IPlatform
;
import
com.taobao.idlefish.flutterboost.interfaces.IStateListener
;
import
com.taobao.idlefish.flutterboost.loader.ServiceLoader
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.List
;
import
fleamarket.taobao.com.xservicekit.handler.MessageResult
;
import
io.flutter.plugin.common.MethodCall
;
import
io.flutter.plugin.common.MethodCall
;
import
io.flutter.plugin.common.MethodChannel
;
import
io.flutter.plugin.common.MethodChannel
;
import
io.flutter.plugin.common.PluginRegistry
;
import
io.flutter.plugin.common.PluginRegistry
;
public
class
FlutterBoostPlugin
implements
MethodChannel
.
MethodCallHandler
,
Application
.
ActivityLifecycleCallbacks
{
public
class
FlutterBoostPlugin
implements
MethodChannel
.
MethodCallHandler
{
private
static
FlutterBoostPlugin
sInstance
=
null
;
static
FlutterBoostPlugin
sInstance
=
null
;
private
static
int
kRid
=
0
;
public
static
synchronized
void
init
(
IPlatform
platform
)
{
public
static
synchronized
void
init
(
IPlatform
platform
)
{
if
(
sInstance
==
null
)
{
if
(
sInstance
==
null
)
{
sInstance
=
new
FlutterBoostPlugin
(
platform
);
sInstance
=
new
FlutterBoostPlugin
(
platform
);
platform
.
getApplication
().
registerActivityLifecycleCallbacks
(
sInstance
);
ServiceLoader
.
load
();
ServiceLoader
.
load
();
}
}
}
public
static
void
registerWith
(
PluginRegistry
.
Registrar
registrar
)
{
if
(
platform
.
whenEngineStart
()
==
IPlatform
.
IMMEDIATELY
)
{
final
MethodChannel
channel
=
new
MethodChannel
(
registrar
.
messenger
(),
"flutter_boost"
);
sInstance
.
mEngineProvider
channel
.
setMethodCallHandler
(
sInstance
);
.
createEngine
(
platform
.
getApplication
())
}
.
startRun
(
null
);
public
static
IFlutterEngineProvider
engineProvider
()
{
if
(
sInstance
==
null
)
{
throw
new
RuntimeException
(
"FlutterBoostPlugin not init yet"
);
}
}
return
BoostEngineProvider
.
sInstance
;
}
public
static
IContainerManager
containerManager
()
{
if
(
sInstance
==
null
)
{
throw
new
RuntimeException
(
"FlutterBoostPlugin not init yet"
);
}
return
sInstance
.
mManager
;
}
}
public
static
IPlatform
platform
()
{
public
static
FlutterBoostPlugin
singleton
()
{
if
(
sInstance
==
null
)
{
if
(
sInstance
==
null
)
{
throw
new
RuntimeException
(
"FlutterBoostPlugin not init yet"
);
throw
new
RuntimeException
(
"FlutterBoostPlugin not init yet"
);
}
}
return
sInstance
.
mPlatform
;
return
sInstance
;
}
}
public
static
Activity
currentActivity
()
{
public
static
void
registerWith
(
PluginRegistry
.
Registrar
registrar
)
{
if
(
sInstance
==
null
)
{
final
MethodChannel
channel
=
new
MethodChannel
(
registrar
.
messenger
(),
"flutter_boost"
);
throw
new
RuntimeException
(
"FlutterBoostPlugin not init yet"
);
channel
.
setMethodCallHandler
(
singleton
());
}
return
sInstance
.
mCurrentActiveActivity
;
}
}
private
final
IPlatform
mPlatform
;
private
final
IPlatform
mPlatform
;
private
final
IContainerManager
mManager
;
private
final
IContainerManager
mManager
;
private
final
PageResultMediator
mMediato
r
;
private
final
IFlutterEngineProvider
mEngineProvide
r
;
IStateListener
mStateListener
;
private
Activity
mCurrentActiveActivity
;
private
Activity
mCurrentActiveActivity
;
private
FlutterBoostPlugin
(
IPlatform
platform
)
{
private
FlutterBoostPlugin
(
IPlatform
platform
)
{
mPlatform
=
platform
;
mPlatform
=
platform
;
mManager
=
new
FlutterViewContainerManager
();
mManager
=
new
FlutterViewContainerManager
();
mMediator
=
new
PageResultMediator
();
mEngineProvider
=
new
BoostEngineProvider
();
}
platform
.
getApplication
().
registerActivityLifecycleCallbacks
(
new
ActivityLifecycleCallbacks
());
public
IFlutterViewContainer
findContainerById
(
String
id
)
{
return
mManager
.
findContainerById
(
id
);
}
}
@Override
@Override
...
@@ -126,139 +98,114 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
...
@@ -126,139 +98,114 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
}
}
}
}
public
static
void
openPage
(
Context
context
,
String
url
,
final
Map
params
,
int
requestCode
)
{
if
(
sInstance
==
null
)
{
throw
new
RuntimeException
(
"FlutterBoostPlugin not init yet!"
);
}
Context
ctx
=
context
;
public
IFlutterEngineProvider
engineProvider
()
{
if
(
ctx
==
null
)
{
if
(
sInstance
==
null
)
{
ctx
=
currentActivity
(
);
throw
new
RuntimeException
(
"FlutterBoostPlugin not init yet"
);
}
}
if
(
ctx
==
null
)
{
return
sInstance
.
mEngineProvider
;
ctx
=
sInstance
.
mPlatform
.
getApplication
();
}
sInstance
.
mPlatform
.
startActivity
(
ctx
,
url
,
params
,
requestCode
);
}
}
public
static
void
openPage
(
Context
context
,
String
url
,
final
Map
params
,
int
requestCode
,
PageResultHandler
handler
)
{
public
IContainerManager
containerManager
()
{
if
(
sInstance
==
null
)
{
if
(
handler
!=
null
){
throw
new
RuntimeException
(
"FlutterBoostPlugin not init yet"
);
String
rid
=
createResultId
();
sInstance
.
mMediator
.
setHandler
(
rid
,
handler
);
params
.
put
(
"result_id"
,
rid
);
}
}
openPage
(
context
,
url
,
params
,
requestCode
);
return
sInstance
.
mManager
;
}
private
static
String
createResultId
(){
kRid
+=
2
;
return
"result_id_"
+
kRid
;
}
}
public
static
void
onPageResult
(
String
key
,
Map
resultData
,
Map
params
){
public
IPlatform
platform
()
{
if
(
sInstance
==
null
)
{
if
(
sInstance
==
null
)
{
throw
new
RuntimeException
(
"FlutterBoostPlugin not init yet
!
"
);
throw
new
RuntimeException
(
"FlutterBoostPlugin not init yet"
);
}
}
sInstance
.
mMediator
.
onPageResult
(
key
,
resultData
,
params
)
;
return
sInstance
.
mPlatform
;
}
}
public
static
void
setHandler
(
String
key
,
PageResultHandler
handler
)
{
public
Activity
currentActivity
(
)
{
if
(
sInstance
==
null
)
{
if
(
sInstance
==
null
)
{
throw
new
RuntimeException
(
"FlutterBoostPlugin not init yet
!
"
);
throw
new
RuntimeException
(
"FlutterBoostPlugin not init yet"
);
}
}
sInstance
.
mMediator
.
setHandler
(
key
,
handler
)
;
return
sInstance
.
mCurrentActiveActivity
;
}
}
public
static
void
removeHandler
(
String
key
)
{
public
IFlutterViewContainer
findContainerById
(
String
id
)
{
if
(
sInstance
==
null
)
{
return
mManager
.
findContainerById
(
id
);
throw
new
RuntimeException
(
"FlutterBoostPlugin not init yet!"
);
}
sInstance
.
mMediator
.
removeHandler
(
key
);
}
}
public
void
setStateListener
(
@Nullable
IStateListener
listener
){
mStateListener
=
listener
;
}
@Override
class
ActivityLifecycleCallbacks
implements
Application
.
ActivityLifecycleCallbacks
{
public
void
onActivityCreated
(
Activity
activity
,
Bundle
savedInstanceState
)
{
@Override
public
void
onActivityCreated
(
Activity
activity
,
Bundle
savedInstanceState
)
{
if
(
platform
().
whenEngineStart
()
==
IPlatform
.
ANY_ACTIVITY_CREATED
)
{
sInstance
.
mEngineProvider
.
createEngine
(
activity
)
.
startRun
(
activity
);
}
}
}
@Override
public
void
onActivityStarted
(
Activity
activity
)
{
if
(
mCurrentActiveActivity
==
null
)
{
Debuger
.
log
(
"Application entry foreground"
);
@Override
if
(
mEngineProvider
.
tryGetEngine
()
!=
null
)
{
public
void
onActivityStarted
(
Activity
activity
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
if
(
mCurrentActiveActivity
==
null
)
{
map
.
put
(
"type"
,
"foreground"
);
Debuger
.
log
(
"Application entry foreground"
);
NavigationService
.
getService
().
emitEvent
(
map
);
}
if
(
BoostEngineProvider
.
sInstance
.
tryGetEngine
()
!=
null
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"type"
,
"foreground"
);
NavigationService
.
getService
().
emitEvent
(
map
);
}
}
mCurrentActiveActivity
=
activity
;
}
}
mCurrentActiveActivity
=
activity
;
}
@Override
@Override
public
void
onActivityResumed
(
Activity
activity
)
{
public
void
onActivityResumed
(
Activity
activity
)
{
mCurrentActiveActivity
=
activity
;
mCurrentActiveActivity
=
activity
;
}
}
@Override
@Override
public
void
onActivityPaused
(
Activity
activity
)
{
public
void
onActivityPaused
(
Activity
activity
)
{
}
}
@Override
@Override
public
void
onActivityStopped
(
Activity
activity
)
{
public
void
onActivityStopped
(
Activity
activity
)
{
if
(
mCurrentActiveActivity
==
activity
)
{
if
(
mCurrentActiveActivity
==
activity
)
{
Debuger
.
log
(
"Application entry background"
);
Debuger
.
log
(
"Application entry background"
);
if
(
BoostEngineProvider
.
sInstance
.
tryGetEngine
()
!=
null
)
{
if
(
mEngineProvider
.
tryGetEngine
()
!=
null
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"type"
,
"background"
);
map
.
put
(
"type"
,
"background"
);
NavigationService
.
getService
().
emitEvent
(
map
);
NavigationService
.
getService
().
emitEvent
(
map
);
}
mCurrentActiveActivity
=
null
;
}
}
mCurrentActiveActivity
=
null
;
}
}
}
@Override
@Override
public
void
onActivitySaveInstanceState
(
Activity
activity
,
Bundle
outState
)
{
public
void
onActivitySaveInstanceState
(
Activity
activity
,
Bundle
outState
)
{
}
@Override
public
void
onActivityDestroyed
(
Activity
activity
)
{
if
(
mCurrentActiveActivity
==
activity
)
{
Debuger
.
log
(
"Application entry background"
);
if
(
BoostEngineProvider
.
sInstance
.
tryGetEngine
()
!=
null
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"type"
,
"background"
);
NavigationService
.
getService
().
emitEvent
(
map
);
}
mCurrentActiveActivity
=
null
;
}
}
@Override
public
void
onActivityDestroyed
(
Activity
activity
)
{
if
(
mCurrentActiveActivity
==
activity
)
{
Debuger
.
log
(
"Application entry background"
);
//reset view provider when single instance context is destroyed
if
(
mEngineProvider
.
tryGetEngine
()
!=
null
)
{
// final FlutterView flutterView = mViewProvider.tryGetFlutterView();
Map
<
String
,
String
>
map
=
new
HashMap
<>();
// if(flutterView != null) {
map
.
put
(
"type"
,
"background"
);
// Activity ctxActivity = (Activity)flutterView.getContext();
NavigationService
.
getService
().
emitEvent
(
map
);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
}
// if((ctxActivity.isDestroyed() || ctxActivity == activity) &&
mCurrentActiveActivity
=
null
;
// mManager.getLastRecord() == null) {
}
// mViewProvider.reset();
}
// }
// }
// }
}
}
public
static
void
setBoostResult
(
Activity
activity
,
HashMap
result
)
{
public
static
void
setBoostResult
(
Activity
activity
,
HashMap
result
)
{
...
@@ -268,16 +215,6 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
...
@@ -268,16 +215,6 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
}
}
activity
.
setResult
(
Activity
.
RESULT_OK
,
intent
);
activity
.
setResult
(
Activity
.
RESULT_OK
,
intent
);
}
}
// public static void onBoostResult(IFlutterViewContainer container, int requestCode, int resultCode, Intent intent) {
// Map map = new HashMap();
// if (intent != null) {
// map.put("result", intent.getSerializableExtra(IFlutterViewContainer.RESULT_KEY));
// }
// map.put("requestCode", requestCode);
// map.put("responseCode", resultCode);
// containerManager().onContainerResult(container, map);
// }
}
}
android/src/main/java/com/taobao/idlefish/flutterboost/FlutterViewContainerManager.java
View file @
0e7d161c
...
@@ -52,8 +52,6 @@ public class FlutterViewContainerManager implements IContainerManager {
...
@@ -52,8 +52,6 @@ public class FlutterViewContainerManager implements IContainerManager {
public
IOperateSyncer
generateSyncer
(
IFlutterViewContainer
container
)
{
public
IOperateSyncer
generateSyncer
(
IFlutterViewContainer
container
)
{
Utils
.
assertCallOnMainThread
();
Utils
.
assertCallOnMainThread
();
BoostEngineProvider
.
sInstance
.
createEngine
(
container
.
getContextActivity
());
ContainerRecord
record
=
new
ContainerRecord
(
this
,
container
);
ContainerRecord
record
=
new
ContainerRecord
(
this
,
container
);
if
(
mRecordMap
.
put
(
container
,
record
)
!=
null
)
{
if
(
mRecordMap
.
put
(
container
,
record
)
!=
null
)
{
Debuger
.
exception
(
"container:"
+
container
.
getContainerName
()
+
" already exists!"
);
Debuger
.
exception
(
"container:"
+
container
.
getContainerName
()
+
" already exists!"
);
...
@@ -64,7 +62,7 @@ public class FlutterViewContainerManager implements IContainerManager {
...
@@ -64,7 +62,7 @@ public class FlutterViewContainerManager implements IContainerManager {
return
record
;
return
record
;
}
}
public
void
pushRecord
(
IContainerRecord
record
)
{
void
pushRecord
(
IContainerRecord
record
)
{
if
(!
mRecordMap
.
containsValue
(
record
))
{
if
(!
mRecordMap
.
containsValue
(
record
))
{
Debuger
.
exception
(
"invalid record!"
);
Debuger
.
exception
(
"invalid record!"
);
}
}
...
@@ -72,13 +70,13 @@ public class FlutterViewContainerManager implements IContainerManager {
...
@@ -72,13 +70,13 @@ public class FlutterViewContainerManager implements IContainerManager {
mRecordStack
.
push
(
record
);
mRecordStack
.
push
(
record
);
}
}
public
void
popRecord
(
IContainerRecord
record
)
{
void
popRecord
(
IContainerRecord
record
)
{
if
(
mRecordStack
.
peek
()
==
record
)
{
if
(
mRecordStack
.
peek
()
==
record
)
{
mRecordStack
.
pop
();
mRecordStack
.
pop
();
}
}
}
}
public
void
removeRecord
(
IContainerRecord
record
)
{
void
removeRecord
(
IContainerRecord
record
)
{
mRecordStack
.
remove
(
record
);
mRecordStack
.
remove
(
record
);
mRecordMap
.
remove
(
record
.
getContainer
());
mRecordMap
.
remove
(
record
.
getContainer
());
}
}
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/NavigationService/NavigationService_closePage.java
View file @
0e7d161c
...
@@ -25,7 +25,6 @@
...
@@ -25,7 +25,6 @@
package
com.taobao.idlefish.flutterboost.NavigationService
;
package
com.taobao.idlefish.flutterboost.NavigationService
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
com.taobao.idlefish.flutterboost.FlutterViewContainerManager
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -39,7 +38,7 @@
...
@@ -39,7 +38,7 @@
private
boolean
onCall
(
MessageResult
<
Boolean
>
result
,
String
uniqueId
,
String
pageName
,
Map
params
,
Boolean
animated
){
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
);
result
.
success
(
true
);
return
true
;
return
true
;
}
}
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/NavigationService/NavigationService_onFlutterPageResult.java
View file @
0e7d161c
...
@@ -24,8 +24,6 @@
...
@@ -24,8 +24,6 @@
package
com.taobao.idlefish.flutterboost.NavigationService
;
package
com.taobao.idlefish.flutterboost.NavigationService
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/NavigationService/NavigationService_onShownContainerChanged.java
View file @
0e7d161c
...
@@ -24,7 +24,6 @@
...
@@ -24,7 +24,6 @@
package
com.taobao.idlefish.flutterboost.NavigationService
;
package
com.taobao.idlefish.flutterboost.NavigationService
;
import
com.taobao.idlefish.flutterboost.Debuger
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -40,7 +39,7 @@
...
@@ -40,7 +39,7 @@
private
boolean
onCall
(
MessageResult
<
Boolean
>
result
,
String
now
,
String
old
,
Map
params
){
private
boolean
onCall
(
MessageResult
<
Boolean
>
result
,
String
now
,
String
old
,
Map
params
){
//Add your handler code here.
//Add your handler code here.
FlutterBoostPlugin
.
containerManager
().
onShownContainerChanged
(
old
,
now
);
FlutterBoostPlugin
.
singleton
().
containerManager
().
onShownContainerChanged
(
old
,
now
);
return
true
;
return
true
;
}
}
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/NavigationService/NavigationService_openPage.java
View file @
0e7d161c
...
@@ -24,6 +24,8 @@
...
@@ -24,6 +24,8 @@
package
com.taobao.idlefish.flutterboost.NavigationService
;
package
com.taobao.idlefish.flutterboost.NavigationService
;
import
android.content.Context
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -44,7 +46,13 @@
...
@@ -44,7 +46,13 @@
requestCode
=
(
int
)
params
.
get
(
"requestCode"
);
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
){
if
(
result
!=
null
){
result
.
success
(
true
);
result
.
success
(
true
);
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/NavigationService/NavigationService_pageOnStart.java
View file @
0e7d161c
...
@@ -25,9 +25,7 @@
...
@@ -25,9 +25,7 @@
package
com.taobao.idlefish.flutterboost.NavigationService
;
package
com.taobao.idlefish.flutterboost.NavigationService
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
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.IContainerRecord
;
import
com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -44,11 +42,11 @@
...
@@ -44,11 +42,11 @@
Map
<
String
,
Object
>
pageInfo
=
new
HashMap
<>();
Map
<
String
,
Object
>
pageInfo
=
new
HashMap
<>();
try
{
try
{
IContainerRecord
record
=
FlutterBoostPlugin
IContainerRecord
record
=
FlutterBoostPlugin
.
singleton
()
.
containerManager
().
getCurrentTopRecord
();
.
containerManager
().
getCurrentTopRecord
();
if
(
record
==
null
)
{
if
(
record
==
null
)
{
record
=
FlutterBoostPlugin
.
containerManager
().
getLastGenerateRecord
();
record
=
FlutterBoostPlugin
.
singleton
().
containerManager
().
getLastGenerateRecord
();
}
}
pageInfo
.
put
(
"name"
,
record
.
getContainer
().
getContainerName
());
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 @@
...
@@ -24,9 +24,23 @@
package
com.taobao.idlefish.flutterboost.containers
;
package
com.taobao.idlefish.flutterboost.containers
;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.graphics.Color
;
import
android.graphics.drawable.ColorDrawable
;
import
android.os.Build
;
import
android.os.Bundle
;
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.BoostFlutterView
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer
;
import
com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer
;
...
@@ -35,25 +49,101 @@ import com.taobao.idlefish.flutterboost.interfaces.IOperateSyncer;
...
@@ -35,25 +49,101 @@ import com.taobao.idlefish.flutterboost.interfaces.IOperateSyncer;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
io.flutter.embedding.android.FlutterView
;
import
io.flutter.embedding.android.FlutterView
;
import
io.flutter.plugin.platform.PlatformPlugin
;
public
abstract
class
BoostFlutterActivity
extends
Activity
implements
IFlutterViewContainer
{
public
abstract
class
BoostFlutterActivity
extends
Activity
implements
IFlutterViewContainer
{
private
BoostFlutterView
mFlutterView
;
protected
BoostFlutterEngine
mFlutterEngine
;
private
IOperateSyncer
mSyncer
;
protected
BoostFlutterView
mFlutterView
;
protected
IOperateSyncer
mSyncer
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
BoostFlutterView
.
Builder
builder
=
new
BoostFlutterView
.
Builder
(
this
);
configureWindowForTransparency
();
mFlutterView
=
builder
.
renderMode
(
FlutterView
.
RenderMode
.
texture
)
.
transparencyMode
(
FlutterView
.
TransparencyMode
.
opaque
)
mSyncer
=
FlutterBoostPlugin
.
singleton
().
containerManager
().
generateSyncer
(
this
);
.
build
();
mFlutterEngine
=
createFlutterEngine
();
mFlutterView
=
createFlutterView
(
mFlutterEngine
);
setContentView
(
mFlutterView
);
setContentView
(
mFlutterView
);
mSyncer
=
FlutterBoostPlugin
.
containerManager
().
generateSyncer
(
this
);
mSyncer
.
onCreate
();
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
@Override
...
...
android/src/main/java/com/taobao/idlefish/flutterboost/containers/BoostFlutterFragment.java
View file @
0e7d161c
...
@@ -32,6 +32,7 @@ import android.view.LayoutInflater;
...
@@ -32,6 +32,7 @@ import android.view.LayoutInflater;
import
android.view.View
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
com.taobao.idlefish.flutterboost.BoostFlutterEngine
;
import
com.taobao.idlefish.flutterboost.BoostFlutterView
;
import
com.taobao.idlefish.flutterboost.BoostFlutterView
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer
;
import
com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer
;
...
@@ -43,23 +44,36 @@ import io.flutter.embedding.android.FlutterView;
...
@@ -43,23 +44,36 @@ import io.flutter.embedding.android.FlutterView;
abstract
public
class
BoostFlutterFragment
extends
Fragment
implements
IFlutterViewContainer
{
abstract
public
class
BoostFlutterFragment
extends
Fragment
implements
IFlutterViewContainer
{
private
BoostFlutterView
mFlutterView
;
protected
BoostFlutterEngine
mFlutterEngine
;
private
IOperateSyncer
mSyncer
;
protected
BoostFlutterView
mFlutterView
;
protected
IOperateSyncer
mSyncer
;
@Nullable
@Nullable
@Override
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
public
View
onCreateView
(
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
BoostFlutterView
.
Builder
builder
=
new
BoostFlutterView
.
Builder
(
getContextActivity
()
);
mSyncer
=
FlutterBoostPlugin
.
singleton
().
containerManager
().
generateSyncer
(
this
);
mFlutterView
=
builder
.
renderMode
(
FlutterView
.
RenderMode
.
texture
)
.
transparencyMode
(
FlutterView
.
TransparencyMode
.
opaque
)
mFlutterEngine
=
createFlutterEngine
();
.
build
(
);
mFlutterView
=
createFlutterView
(
mFlutterEngine
);
mSyncer
=
FlutterBoostPlugin
.
containerManager
().
generateSyncer
(
this
);
mSyncer
.
onCreate
();
mSyncer
.
onCreate
();
return
mFlutterView
;
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
@Override
public
void
onResume
()
{
public
void
onResume
()
{
super
.
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;
...
@@ -25,6 +25,7 @@ package com.taobao.idlefish.flutterboost.interfaces;
import
android.content.Context
;
import
android.content.Context
;
import
com.taobao.idlefish.flutterboost.BoostFlutterEngine
;
import
com.taobao.idlefish.flutterboost.BoostFlutterView
;
import
com.taobao.idlefish.flutterboost.BoostFlutterView
;
import
io.flutter.embedding.engine.FlutterEngine
;
import
io.flutter.embedding.engine.FlutterEngine
;
...
@@ -38,11 +39,11 @@ public interface IFlutterEngineProvider {
...
@@ -38,11 +39,11 @@ public interface IFlutterEngineProvider {
* @param context
* @param context
* @return
* @return
*/
*/
FlutterEngine
createEngine
(
Context
context
);
Boost
FlutterEngine
createEngine
(
Context
context
);
/**
/**
* may return null
* may return null
* @return
* @return
*/
*/
FlutterEngine
tryGetEngine
();
Boost
FlutterEngine
tryGetEngine
();
}
}
android/src/main/java/com/taobao/idlefish/flutterboost/interfaces/IPlatform.java
View file @
0e7d161c
...
@@ -23,7 +23,6 @@
...
@@ -23,7 +23,6 @@
*/
*/
package
com.taobao.idlefish.flutterboost.interfaces
;
package
com.taobao.idlefish.flutterboost.interfaces
;
import
android.app.Activity
;
import
android.app.Application
;
import
android.app.Application
;
import
android.content.Context
;
import
android.content.Context
;
...
@@ -36,6 +35,10 @@ import io.flutter.plugin.common.PluginRegistry;
...
@@ -36,6 +35,10 @@ import io.flutter.plugin.common.PluginRegistry;
*/
*/
public
interface
IPlatform
{
public
interface
IPlatform
{
int
IMMEDIATELY
=
0
;
//立即启动引擎
int
ANY_ACTIVITY_CREATED
=
1
;
//当有任何Activity创建时,启动引擎
int
LAZY
=
2
;
//尽可能延后启动引擎(通常是首页Flutter页面加载时)
/**
/**
* get current application
* get current application
* @return
* @return
...
@@ -43,16 +46,16 @@ public interface IPlatform {
...
@@ -43,16 +46,16 @@ public interface IPlatform {
Application
getApplication
();
Application
getApplication
();
/**
/**
*
register plugins
*
debug or not
* @return
* @return
*/
*/
void
onRegisterPlugins
(
PluginRegistry
registry
);
boolean
isDebug
(
);
/**
/**
*
debug or not
*
register plugins
* @return
* @return
*/
*/
boolean
isDebug
(
);
void
onRegisterPlugins
(
PluginRegistry
registry
);
/**
/**
* start a new activity from flutter page, you may need a page router with url
* start a new activity from flutter page, you may need a page router with url
...
@@ -65,8 +68,11 @@ public interface IPlatform {
...
@@ -65,8 +68,11 @@ public interface IPlatform {
/**
/**
* settings, no use
* @return
* @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
;
package
com.taobao.idlefish.flutterboostexample
;
import
android.graphics.Color
;
import
android.os.Build
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.Nullable
;
import
android.support.v7.app.ActionBar
;
import
android.support.v7.app.ActionBar
;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.app.AppCompatActivity
;
import
android.view.View
;
import
android.view.Window
;
import
android.view.Window
;
import
android.view.WindowManager
;
import
android.view.WindowManager
;
import
io.flutter.plugin.platform.PlatformPlugin
;
import
io.flutter.plugin.platform.PlatformPlugin
;
public
class
FlutterFragmentPageActivity
extends
AppCompatActivity
{
public
class
FlutterFragmentPageActivity
extends
AppCompatActivity
implements
View
.
OnClickListener
{
private
FlutterFragment
mFragment
;
private
FlutterFragment
mFragment
;
private
View
mTab1
;
private
View
mTab2
;
private
View
mTab3
;
private
View
mTab4
;
@Override
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
supportRequestWindowFeature
(
Window
.
FEATURE_NO_TITLE
);
supportRequestWindowFeature
(
Window
.
FEATURE_NO_TITLE
);
...
@@ -32,11 +39,49 @@ public class FlutterFragmentPageActivity extends AppCompatActivity {
...
@@ -32,11 +39,49 @@ public class FlutterFragmentPageActivity extends AppCompatActivity {
setContentView
(
R
.
layout
.
flutter_fragment_page
);
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
()
getSupportFragmentManager
()
.
beginTransaction
()
.
beginTransaction
()
.
replace
(
R
.
id
.
fragment_stub
,
mFragment
)
.
replace
(
R
.
id
.
fragment_stub
,
mFragment
)
.
commit
();
.
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 {
...
@@ -15,7 +15,7 @@ public class FlutterPageActivity extends BoostFlutterActivity {
* 混合栈将会在flutter层根据这个名字,在注册的Route表中查找对应的Widget
* 混合栈将会在flutter层根据这个名字,在注册的Route表中查找对应的Widget
*
*
* 在flutter层有注册函数:
* 在flutter层有注册函数:
* FlutterBoost.singleton.registerPageBuilders({
* FlutterBoost
Plugin
.singleton.registerPageBuilders({
* 'first': (pageName, params, _) => FirstRouteWidget(),
* 'first': (pageName, params, _) => FirstRouteWidget(),
* 'second': (pageName, params, _) => SecondRouteWidget(),
* 'second': (pageName, params, _) => SecondRouteWidget(),
* ...
* ...
...
@@ -34,7 +34,7 @@ public class FlutterPageActivity extends BoostFlutterActivity {
...
@@ -34,7 +34,7 @@ public class FlutterPageActivity extends BoostFlutterActivity {
* 该方法返回的参数将会传递给上层的flutter对应的Widget
* 该方法返回的参数将会传递给上层的flutter对应的Widget
*
*
* 在flutter层有注册函数:
* 在flutter层有注册函数:
* FlutterBoost.singleton.registerPageBuilders({
* FlutterBoost
Plugin
.singleton.registerPageBuilders({
* 'first': (pageName, params, _) => FirstRouteWidget(),
* 'first': (pageName, params, _) => FirstRouteWidget(),
* 'second': (pageName, params, _) => SecondRouteWidget(),
* '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;
...
@@ -6,8 +6,6 @@ import android.support.v7.app.AppCompatActivity;
import
android.view.View
;
import
android.view.View
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
import
java.lang.ref.WeakReference
;
import
java.lang.ref.WeakReference
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -52,7 +50,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
...
@@ -52,7 +50,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
PageRouter
.
openPageByUrl
(
this
,
PageRouter
.
NATIVE_PAGE_URL
,
params
);
PageRouter
.
openPageByUrl
(
this
,
PageRouter
.
NATIVE_PAGE_URL
,
params
);
}
else
if
(
v
==
mOpenFlutter
)
{
}
else
if
(
v
==
mOpenFlutter
)
{
PageRouter
.
openPageByUrl
(
this
,
PageRouter
.
FLUTTER_PAGE_URL
,
params
);
PageRouter
.
openPageByUrl
(
this
,
PageRouter
.
FLUTTER_PAGE_URL
,
params
);
FlutterBoostPlugin
.
onPageResult
(
"result_id_100"
,
new
HashMap
(),
new
HashMap
());
}
else
if
(
v
==
mOpenFlutterFragment
)
{
}
else
if
(
v
==
mOpenFlutterFragment
)
{
PageRouter
.
openPageByUrl
(
this
,
PageRouter
.
FLUTTER_FRAGMENT_PAGE_URL
,
params
);
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;
...
@@ -3,9 +3,13 @@ package com.taobao.idlefish.flutterboostexample;
import
android.app.Application
;
import
android.app.Application
;
import
android.content.Context
;
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.Debuger
;
import
com.taobao.idlefish.flutterboost.FlutterBoostPlugin
;
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.IPlatform
;
import
com.taobao.idlefish.flutterboost.interfaces.IStateListener
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -54,8 +58,8 @@ public class MyApplication extends FlutterApplication {
...
@@ -54,8 +58,8 @@ public class MyApplication extends FlutterApplication {
}
}
@Override
@Override
public
Map
getSettings
()
{
public
int
whenEngineStart
()
{
return
null
;
return
IMMEDIATELY
;
}
}
});
});
}
}
...
...
example/android/app/src/main/res/layout/flutter_fragment_page.xml
View file @
0e7d161c
...
@@ -11,4 +11,47 @@
...
@@ -11,4 +11,47 @@
android:layout_weight=
"1"
android:layout_weight=
"1"
android:id=
"@+id/fragment_stub"
/>
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>
</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