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
f9f4bf29
Commit
f9f4bf29
authored
Dec 25, 2019
by
yangwu.jia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
适配1.12
parent
2f523fd6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
215 deletions
+68
-215
android/src/main/java/com/idlefish/flutterboost/XFlutterTextureView.java
...n/java/com/idlefish/flutterboost/XFlutterTextureView.java
+0
-151
android/src/main/java/com/idlefish/flutterboost/XFlutterView.java
...src/main/java/com/idlefish/flutterboost/XFlutterView.java
+47
-32
android/src/main/java/com/idlefish/flutterboost/containers/BoostFlutterActivity.java
...dlefish/flutterboost/containers/BoostFlutterActivity.java
+5
-0
android/src/main/java/com/idlefish/flutterboost/containers/FlutterFragment.java
...com/idlefish/flutterboost/containers/FlutterFragment.java
+5
-0
android/src/main/java/com/idlefish/flutterboost/containers/FlutterSplashView.java
...m/idlefish/flutterboost/containers/FlutterSplashView.java
+10
-32
example/android/gradle.properties
example/android/gradle.properties
+1
-0
No files found.
android/src/main/java/com/idlefish/flutterboost/XFlutterTextureView.java
deleted
100644 → 0
View file @
2f523fd6
package
com.idlefish.flutterboost
;
import
android.content.Context
;
import
android.graphics.SurfaceTexture
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.util.AttributeSet
;
import
android.view.Surface
;
import
android.view.TextureView
;
import
io.flutter.Log
;
import
io.flutter.embedding.engine.renderer.FlutterRenderer
;
import
io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.Set
;
public
class
XFlutterTextureView
extends
TextureView
implements
FlutterRenderer
.
RenderSurface
{
private
static
final
String
TAG
=
"XFlutterTextureView"
;
private
boolean
isSurfaceAvailableForRendering
;
private
boolean
isAttachedToFlutterRenderer
;
@Nullable
private
FlutterRenderer
flutterRenderer
;
@NonNull
private
Set
<
OnFirstFrameRenderedListener
>
onFirstFrameRenderedListeners
;
private
final
SurfaceTextureListener
surfaceTextureListener
;
public
XFlutterTextureView
(
@NonNull
Context
context
)
{
this
(
context
,
(
AttributeSet
)
null
);
}
public
XFlutterTextureView
(
@NonNull
Context
context
,
@Nullable
AttributeSet
attrs
)
{
super
(
context
,
attrs
);
this
.
isSurfaceAvailableForRendering
=
false
;
this
.
isAttachedToFlutterRenderer
=
false
;
this
.
onFirstFrameRenderedListeners
=
new
HashSet
();
this
.
surfaceTextureListener
=
new
SurfaceTextureListener
()
{
public
void
onSurfaceTextureAvailable
(
SurfaceTexture
surfaceTexture
,
int
width
,
int
height
)
{
Log
.
v
(
"FlutterTextureView"
,
"SurfaceTextureListener.onSurfaceTextureAvailable()"
);
XFlutterTextureView
.
this
.
isSurfaceAvailableForRendering
=
true
;
if
(
XFlutterTextureView
.
this
.
isAttachedToFlutterRenderer
)
{
XFlutterTextureView
.
this
.
connectSurfaceToRenderer
();
}
}
public
void
onSurfaceTextureSizeChanged
(
@NonNull
SurfaceTexture
surface
,
int
width
,
int
height
)
{
Log
.
v
(
"FlutterTextureView"
,
"SurfaceTextureListener.onSurfaceTextureSizeChanged()"
);
if
(
XFlutterTextureView
.
this
.
isAttachedToFlutterRenderer
)
{
XFlutterTextureView
.
this
.
changeSurfaceSize
(
width
,
height
);
}
}
public
void
onSurfaceTextureUpdated
(
@NonNull
SurfaceTexture
surface
)
{
}
public
boolean
onSurfaceTextureDestroyed
(
@NonNull
SurfaceTexture
surface
)
{
Log
.
v
(
"FlutterTextureView"
,
"SurfaceTextureListener.onSurfaceTextureDestroyed()"
);
XFlutterTextureView
.
this
.
isSurfaceAvailableForRendering
=
false
;
if
(
XFlutterTextureView
.
this
.
isAttachedToFlutterRenderer
)
{
XFlutterTextureView
.
this
.
disconnectSurfaceFromRenderer
();
}
return
true
;
}
};
this
.
init
();
}
private
void
init
()
{
this
.
setSurfaceTextureListener
(
this
.
surfaceTextureListener
);
}
public
void
attachToRenderer
(
@NonNull
FlutterRenderer
flutterRenderer
)
{
Log
.
v
(
"FlutterTextureView"
,
"Attaching to FlutterRenderer."
);
if
(
this
.
flutterRenderer
!=
null
)
{
Log
.
v
(
"FlutterTextureView"
,
"Already connected to a FlutterRenderer. Detaching from old one and attaching to new one."
);
this
.
flutterRenderer
.
detachFromRenderSurface
();
}
this
.
flutterRenderer
=
flutterRenderer
;
this
.
isAttachedToFlutterRenderer
=
true
;
if
(
this
.
isSurfaceAvailableForRendering
)
{
Log
.
v
(
"FlutterTextureView"
,
"Surface is available for rendering. Connecting FlutterRenderer to Android surface."
);
this
.
connectSurfaceToRenderer
();
}
}
public
void
detachFromRenderer
()
{
if
(
this
.
flutterRenderer
!=
null
)
{
if
(
this
.
getWindowToken
()
!=
null
)
{
Log
.
v
(
"FlutterTextureView"
,
"Disconnecting FlutterRenderer from Android surface."
);
this
.
disconnectSurfaceFromRenderer
();
}
this
.
flutterRenderer
=
null
;
this
.
isAttachedToFlutterRenderer
=
false
;
}
else
{
Log
.
w
(
"FlutterTextureView"
,
"detachFromRenderer() invoked when no FlutterRenderer was attached."
);
}
}
private
void
connectSurfaceToRenderer
()
{
if
(
this
.
flutterRenderer
!=
null
&&
this
.
getSurfaceTexture
()
!=
null
)
{
Surface
surface
=
new
Surface
(
this
.
getSurfaceTexture
());
this
.
flutterRenderer
.
surfaceCreated
(
surface
);
surface
.
release
();
}
else
{
throw
new
IllegalStateException
(
"connectSurfaceToRenderer() should only be called when flutterRenderer and getSurfaceTexture() are non-null."
);
}
}
private
void
changeSurfaceSize
(
int
width
,
int
height
)
{
if
(
this
.
flutterRenderer
==
null
)
{
throw
new
IllegalStateException
(
"changeSurfaceSize() should only be called when flutterRenderer is non-null."
);
}
else
{
Log
.
v
(
"FlutterTextureView"
,
"Notifying FlutterRenderer that Android surface size has changed to "
+
width
+
" x "
+
height
);
this
.
flutterRenderer
.
surfaceChanged
(
width
,
height
);
}
}
private
void
disconnectSurfaceFromRenderer
()
{
if
(
this
.
flutterRenderer
==
null
)
{
throw
new
IllegalStateException
(
"disconnectSurfaceFromRenderer() should only be called when flutterRenderer is non-null."
);
}
else
{
this
.
flutterRenderer
.
surfaceDestroyed
();
}
}
public
void
addOnFirstFrameRenderedListener
(
@NonNull
OnFirstFrameRenderedListener
listener
)
{
this
.
onFirstFrameRenderedListeners
.
add
(
listener
);
}
public
void
removeOnFirstFrameRenderedListener
(
@NonNull
OnFirstFrameRenderedListener
listener
)
{
this
.
onFirstFrameRenderedListeners
.
remove
(
listener
);
}
public
void
onFirstFrameRendered
()
{
Log
.
v
(
"FlutterTextureView"
,
"onFirstFrameRendered()"
);
Iterator
var1
=
this
.
onFirstFrameRenderedListeners
.
iterator
();
while
(
var1
.
hasNext
())
{
OnFirstFrameRenderedListener
listener
=
(
OnFirstFrameRenderedListener
)
var1
.
next
();
listener
.
onFirstFrameRendered
();
}
}
}
\ No newline at end of file
android/src/main/java/com/idlefish/flutterboost/XFlutterView.java
View file @
f9f4bf29
...
...
@@ -36,7 +36,8 @@ import io.flutter.Log;
import
io.flutter.embedding.android.*
;
import
io.flutter.embedding.engine.FlutterEngine
;
import
io.flutter.embedding.engine.renderer.FlutterRenderer
;
import
io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener
;
import
io.flutter.embedding.engine.renderer.FlutterUiDisplayListener
;
import
io.flutter.embedding.engine.renderer.RenderSurface
;
import
io.flutter.embedding.engine.systemchannels.TextInputChannel
;
import
io.flutter.plugin.editing.TextInputPlugin
;
import
io.flutter.plugin.platform.PlatformViewsController
;
...
...
@@ -74,8 +75,10 @@ public class XFlutterView extends FrameLayout {
// Internal view hierarchy references.
@Nullable
private
FlutterRenderer
.
RenderSurface
renderSurface
;
private
final
Set
<
OnFirstFrameRenderedListener
>
onFirstFrameRenderedListeners
=
new
HashSet
<>();
private
RenderSurface
renderSurface
;
private
final
Set
<
FlutterUiDisplayListener
>
flutterUiDisplayListeners
=
new
HashSet
<>();
private
boolean
didRenderFirstFrame
;
// Connections to a Flutter execution context.
...
...
@@ -100,6 +103,9 @@ public class XFlutterView extends FrameLayout {
private
boolean
hasAddFirstFrameRenderedListener
=
false
;
private
boolean
isFlutterUiDisplayed
;
// Directly implemented View behavior that communicates with Flutter.
private
final
FlutterRenderer
.
ViewportMetrics
viewportMetrics
=
new
FlutterRenderer
.
ViewportMetrics
();
...
...
@@ -110,23 +116,32 @@ public class XFlutterView extends FrameLayout {
}
};
private
final
OnFirstFrameRenderedListener
onFirstFrameRenderedListener
=
new
OnFirstFrameRenderedListener
()
{
private
final
FlutterUiDisplayListener
flutterUiDisplayListener
=
new
FlutterUiDisplayListener
()
{
@Override
public
void
onF
irstFrameRender
ed
()
{
didRenderFirstFrame
=
true
;
public
void
onF
lutterUiDisplay
ed
()
{
isFlutterUiDisplayed
=
true
;
for
(
OnFirstFrameRenderedListener
listener
:
onFirstFrameRenderedListeners
)
{
listener
.
onFirstFrameRendered
();
for
(
FlutterUiDisplayListener
listener
:
flutterUiDisplayListeners
)
{
listener
.
onFlutterUiDisplayed
();
}
}
@Override
public
void
onFlutterUiNoLongerDisplayed
()
{
isFlutterUiDisplayed
=
false
;
for
(
FlutterUiDisplayListener
listener
:
flutterUiDisplayListeners
)
{
listener
.
onFlutterUiNoLongerDisplayed
();
}
}
};
/**
* Constructs a {@code FlutterView} programmatically, without any XML attributes.
* <p>
* <ul>
* <li>{@link #renderMode} defaults to {@link RenderMode#surface}.</li>
* <li>{@link #transparencyMode} defaults to {@link TransparencyMode#opaque}.</li>
* </ul>
* {@code FlutterView} requires an {@code Activity} instead of a generic {@code Context}
* to be compatible with {@link PlatformViewsController}.
...
...
@@ -202,7 +217,7 @@ public class XFlutterView extends FrameLayout {
break
;
case
texture:
Log
.
v
(
TAG
,
"Internally using a FlutterTextureView."
);
XFlutterTextureView
flutterTextureView
=
new
X
FlutterTextureView
(
getContext
());
FlutterTextureView
flutterTextureView
=
new
FlutterTextureView
(
getContext
());
renderSurface
=
flutterTextureView
;
addView
(
flutterTextureView
);
break
;
...
...
@@ -233,20 +248,20 @@ public class XFlutterView extends FrameLayout {
return
didRenderFirstFrame
;
}
/**
* Adds the given {@code listener} to this {@code FlutterView}, to be notified upon Flutter's
* first rendered frame.
*/
public
void
addOnFirstFrameRenderedListener
(
@NonNull
OnFirstFrameRendered
Listener
listener
)
{
onFirstFrameRendered
Listeners
.
add
(
listener
);
public
void
addOnFirstFrameRenderedListener
(
@NonNull
FlutterUiDisplay
Listener
listener
)
{
flutterUiDisplay
Listeners
.
add
(
listener
);
}
/**
* Removes the given {@code listener}, which was previously added with
* {@link #addOnFirstFrameRenderedListener(
OnFirstFrameRendered
Listener)}.
* {@link #addOnFirstFrameRenderedListener(
FlutterUiDisplay
Listener)}.
*/
public
void
removeOnFirstFrameRenderedListener
(
@NonNull
OnFirstFrameRendered
Listener
listener
)
{
onFirstFrameRendered
Listeners
.
remove
(
listener
);
public
void
removeOnFirstFrameRenderedListener
(
@NonNull
FlutterUiDisplay
Listener
listener
)
{
flutterUiDisplay
Listeners
.
remove
(
listener
);
}
//------- Start: Process View configuration that Flutter cares about. ------
...
...
@@ -587,17 +602,11 @@ public class XFlutterView extends FrameLayout {
}
this
.
flutterEngine
=
flutterEngine
;
// Instruct our FlutterRenderer that we are now its designated RenderSurface.
FlutterRenderer
flutterRenderer
=
this
.
flutterEngine
.
getRenderer
();
didRenderFirstFrame
=
flutterRenderer
.
hasRenderedFirstFrame
();
if
(!
hasAddFirstFrameRenderedListener
){
flutterRenderer
.
addOnFirstFrameRenderedListener
(
onFirstFrameRenderedListener
);
hasAddFirstFrameRenderedListener
=
true
;
}
flutterRenderer
.
attachToRenderSurface
(
renderSurface
);
isFlutterUiDisplayed
=
flutterRenderer
.
isDisplayingFlutterUi
();
renderSurface
.
attachToRenderer
(
flutterRenderer
);
flutterRenderer
.
addIsDisplayingFlutterUiListener
(
flutterUiDisplayListener
);
// Initialize various components that know how to process Android View I/O
// in a way that Flutter understands.
if
(
textInputPlugin
==
null
){
...
...
@@ -693,11 +702,17 @@ public class XFlutterView extends FrameLayout {
// TODO(mattcarroll): once this is proven to work, move this line ot TextInputPlugin
// Instruct our FlutterRenderer that we are no longer interested in being its RenderSurface.
FlutterRenderer
flutterRenderer
=
flutterEngine
.
getRenderer
();
// didRenderFirstFrame = false;
flutterRenderer
.
removeOnFirstFrameRenderedListener
(
onFirstFrameRenderedListener
);
flutterRenderer
.
detachFromRenderSurface
();
isFlutterUiDisplayed
=
false
;
flutterRenderer
.
removeIsDisplayingFlutterUiListener
(
flutterUiDisplayListener
);
flutterRenderer
.
stopRenderingToSurface
();
flutterRenderer
.
setSemanticsEnabled
(
false
);
renderSurface
.
detachFromRenderer
();
flutterEngine
=
null
;
}
public
void
release
(){
if
(
textInputPlugin
!=
null
){
...
...
android/src/main/java/com/idlefish/flutterboost/containers/BoostFlutterActivity.java
View file @
f9f4bf29
...
...
@@ -458,6 +458,11 @@ public class BoostFlutterActivity extends Activity
// No-op. Hook for subclasses.
}
@Override
public
void
cleanUpFlutterEngine
(
@NonNull
FlutterEngine
flutterEngine
)
{
}
@Override
public
boolean
shouldAttachEngineToActivity
()
{
...
...
android/src/main/java/com/idlefish/flutterboost/containers/FlutterFragment.java
View file @
f9f4bf29
...
...
@@ -482,6 +482,11 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
}
}
@Override
public
void
cleanUpFlutterEngine
(
@NonNull
FlutterEngine
flutterEngine
)
{
}
/**
* See {@link NewEngineFragmentBuilder#shouldAttachEngineToActivity()} and
* <p>
...
...
android/src/main/java/com/idlefish/flutterboost/containers/FlutterSplashView.java
View file @
f9f4bf29
...
...
@@ -4,8 +4,6 @@ import android.content.Context;
import
android.graphics.Color
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Parcel
;
import
android.os.Parcelable
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.util.AttributeSet
;
...
...
@@ -17,9 +15,8 @@ import io.flutter.Log;
import
io.flutter.embedding.android.FlutterView
;
import
io.flutter.embedding.android.SplashScreen
;
import
io.flutter.embedding.engine.FlutterEngine
;
import
io.flutter.embedding.engine.renderer.
OnFirstFrameRendered
Listener
;
import
io.flutter.embedding.engine.renderer.
FlutterUiDisplay
Listener
;
import
java.util.Date
;
/**
* {@code View} that displays a {@link SplashScreen} until a given {@link FlutterView}
...
...
@@ -57,39 +54,20 @@ public class FlutterSplashView extends FrameLayout {
};
@NonNull
private
final
OnFirstFrameRenderedListener
onFirstFrameRenderedListener
=
new
OnFirstFrameRenderedListener
()
{
int
i
=
0
;
private
final
FlutterUiDisplayListener
onFirstFrameRenderedListener
=
new
FlutterUiDisplayListener
()
{
@Override
public
void
onFirstFrameRendered
()
{
if
(
FlutterBoost
.
instance
().
platform
().
whenEngineStart
()
==
FlutterBoost
.
ConfigBuilder
.
FLUTTER_ACTIVITY_CREATED
)
{
long
now
=
new
Date
().
getTime
();
long
flutterPostFrameCallTime
=
FlutterBoost
.
instance
().
getFlutterPostFrameCallTime
();
if
(
flutterPostFrameCallTime
!=
0
&&
(
now
-
flutterPostFrameCallTime
)
>
800
)
{
if
(
splashScreen
!=
null
)
{
transitionToFlutter
();
}
return
;
}
handler
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
onFirstFrameRenderedListener
.
onFirstFrameRendered
();
}
},
200
);
}
else
{
if
(
splashScreen
!=
null
)
{
transitionToFlutter
();
}
public
void
onFlutterUiDisplayed
()
{
if
(
splashScreen
!=
null
)
{
transitionToFlutter
();
}
}
@Override
public
void
onFlutterUiNoLongerDisplayed
()
{
}
};
@NonNull
...
...
example/android/gradle.properties
View file @
f9f4bf29
org.gradle.jvmargs
=
-Xmx1536M
android.enableR8
=
true
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