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
67c34f5b
Commit
67c34f5b
authored
Oct 15, 2019
by
yangwu.jia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resolve Memory Leaks
parent
dd87a8bf
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
930 deletions
+37
-930
android/src/main/java/com/idlefish/flutterboost/Utils.java
android/src/main/java/com/idlefish/flutterboost/Utils.java
+3
-4
android/src/main/java/com/idlefish/flutterboost/XAndroidKeyProcessor.java
.../java/com/idlefish/flutterboost/XAndroidKeyProcessor.java
+0
-99
android/src/main/java/com/idlefish/flutterboost/XFlutterView.java
...src/main/java/com/idlefish/flutterboost/XFlutterView.java
+31
-5
android/src/main/java/com/idlefish/flutterboost/XInputConnectionAdaptor.java
...va/com/idlefish/flutterboost/XInputConnectionAdaptor.java
+0
-208
android/src/main/java/com/idlefish/flutterboost/XPlatformPlugin.java
.../main/java/com/idlefish/flutterboost/XPlatformPlugin.java
+0
-257
android/src/main/java/com/idlefish/flutterboost/XTextInputPlugin.java
...main/java/com/idlefish/flutterboost/XTextInputPlugin.java
+0
-357
android/src/main/java/com/idlefish/flutterboost/containers/FlutterActivityAndFragmentDelegate.java
...rboost/containers/FlutterActivityAndFragmentDelegate.java
+3
-0
No files found.
android/src/main/java/com/idlefish/flutterboost/Utils.java
View file @
67c34f5b
...
...
@@ -272,14 +272,13 @@ public class Utils {
f
=
imm
.
getClass
().
getDeclaredField
(
param
);
if
(
f
.
isAccessible
()
==
false
)
{
f
.
setAccessible
(
true
);
}
// author: sodino mail:sodino@qq.com
}
obj_get
=
f
.
get
(
imm
);
if
(
obj_get
!=
null
&&
obj_get
instanceof
View
)
{
View
v_get
=
(
View
)
obj_get
;
if
(
v_get
.
getContext
()
==
destContext
)
{
// 被InputMethodManager持有引用的context是想要目标销毁的
f
.
set
(
imm
,
null
);
// 置空,破坏掉path to gc节点
if
(
v_get
.
getContext
()
==
destContext
)
{
f
.
set
(
imm
,
null
);
}
else
{
// 不是想要目标销毁的,即为又进了另一层界面了,不要处理,避免影响原逻辑,也就不用继续for循环了
break
;
}
}
...
...
android/src/main/java/com/idlefish/flutterboost/XAndroidKeyProcessor.java
deleted
100644 → 0
View file @
dd87a8bf
package
com.idlefish.flutterboost
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.view.KeyCharacterMap
;
import
android.view.KeyEvent
;
import
io.flutter.embedding.engine.systemchannels.KeyEventChannel
;
import
io.flutter.plugin.editing.TextInputPlugin
;
public
class
XAndroidKeyProcessor
{
@NonNull
private
final
KeyEventChannel
keyEventChannel
;
@NonNull
private
final
XTextInputPlugin
textInputPlugin
;
private
int
combiningCharacter
;
public
XAndroidKeyProcessor
(
@NonNull
KeyEventChannel
keyEventChannel
,
@NonNull
XTextInputPlugin
textInputPlugin
)
{
this
.
keyEventChannel
=
keyEventChannel
;
this
.
textInputPlugin
=
textInputPlugin
;
}
public
void
onKeyUp
(
@NonNull
KeyEvent
keyEvent
)
{
Character
complexCharacter
=
applyCombiningCharacterToBaseCharacter
(
keyEvent
.
getUnicodeChar
());
keyEventChannel
.
keyUp
(
new
KeyEventChannel
.
FlutterKeyEvent
(
keyEvent
,
complexCharacter
)
);
}
public
void
onKeyDown
(
@NonNull
KeyEvent
keyEvent
)
{
if
(
textInputPlugin
.
getLastInputConnection
()
!=
null
&&
textInputPlugin
.
getInputMethodManager
().
isAcceptingText
())
{
textInputPlugin
.
getLastInputConnection
().
sendKeyEvent
(
keyEvent
);
}
Character
complexCharacter
=
applyCombiningCharacterToBaseCharacter
(
keyEvent
.
getUnicodeChar
());
keyEventChannel
.
keyDown
(
new
KeyEventChannel
.
FlutterKeyEvent
(
keyEvent
,
complexCharacter
)
);
}
/**
* Applies the given Unicode character in {@code newCharacterCodePoint} to a previously
* entered Unicode combining character and returns the combination of these characters
* if a combination exists.
* <p>
* This method mutates {@link #combiningCharacter} over time to combine characters.
* <p>
* One of the following things happens in this method:
* <ul>
* <li>If no previous {@link #combiningCharacter} exists and the {@code newCharacterCodePoint}
* is not a combining character, then {@code newCharacterCodePoint} is returned.</li>
* <li>If no previous {@link #combiningCharacter} exists and the {@code newCharacterCodePoint}
* is a combining character, then {@code newCharacterCodePoint} is saved as the
* {@link #combiningCharacter} and null is returned.</li>
* <li>If a previous {@link #combiningCharacter} exists and the {@code newCharacterCodePoint}
* is also a combining character, then the {@code newCharacterCodePoint} is combined with
* the existing {@link #combiningCharacter} and null is returned.</li>
* <li>If a previous {@link #combiningCharacter} exists and the {@code newCharacterCodePoint}
* is not a combining character, then the {@link #combiningCharacter} is applied to the
* regular {@code newCharacterCodePoint} and the resulting complex character is returned. The
* {@link #combiningCharacter} is cleared.</li>
* </ul>
* <p>
* The following reference explains the concept of a "combining character":
* https://en.wikipedia.org/wiki/Combining_character
*/
@Nullable
private
Character
applyCombiningCharacterToBaseCharacter
(
int
newCharacterCodePoint
)
{
if
(
newCharacterCodePoint
==
0
)
{
return
null
;
}
Character
complexCharacter
=
(
char
)
newCharacterCodePoint
;
boolean
isNewCodePointACombiningCharacter
=
(
newCharacterCodePoint
&
KeyCharacterMap
.
COMBINING_ACCENT
)
!=
0
;
if
(
isNewCodePointACombiningCharacter
)
{
// If a combining character was entered before, combine this one with that one.
int
plainCodePoint
=
newCharacterCodePoint
&
KeyCharacterMap
.
COMBINING_ACCENT_MASK
;
if
(
combiningCharacter
!=
0
)
{
combiningCharacter
=
KeyCharacterMap
.
getDeadChar
(
combiningCharacter
,
plainCodePoint
);
}
else
{
combiningCharacter
=
plainCodePoint
;
}
}
else
{
// The new character is a regular character. Apply combiningCharacter to it, if it exists.
if
(
combiningCharacter
!=
0
)
{
int
combinedChar
=
KeyCharacterMap
.
getDeadChar
(
combiningCharacter
,
newCharacterCodePoint
);
if
(
combinedChar
>
0
)
{
complexCharacter
=
(
char
)
combinedChar
;
}
combiningCharacter
=
0
;
}
}
return
complexCharacter
;
}
}
\ No newline at end of file
android/src/main/java/com/idlefish/flutterboost/XFlutterView.java
View file @
67c34f5b
...
...
@@ -25,6 +25,7 @@ import android.view.inputmethod.EditorInfo;
import
android.view.inputmethod.InputConnection
;
import
android.widget.FrameLayout
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
...
...
@@ -36,6 +37,7 @@ 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.systemchannels.TextInputChannel
;
import
io.flutter.plugin.editing.TextInputPlugin
;
import
io.flutter.plugin.platform.PlatformViewsController
;
import
io.flutter.view.AccessibilityBridge
;
...
...
@@ -586,12 +588,12 @@ public class XFlutterView extends FrameLayout {
// in a way that Flutter understands.
if
(
this
.
textInputPlugin
!=
null
){
this
.
textInputPlugin
.
destroy
();
resolveMemoryLeaks
();
}
this
.
textInputPlugin
=
new
TextInputPlugin
(
this
,
this
.
flutterEngine
.
getDartExecutor
(),
this
.
flutterEngine
.
getPlatformViewsController
());
this
.
textInputPlugin
.
getInputMethodManager
().
restartInput
(
this
);
this
.
androidKeyProcessor
=
new
AndroidKeyProcessor
(
this
.
flutterEngine
.
getKeyEventChannel
(),
...
...
@@ -619,7 +621,7 @@ public class XFlutterView extends FrameLayout {
// Inform the Android framework that it should retrieve a new InputConnection
// now that an engine is attached.
// TODO(mattcarroll): once this is proven to work, move this line ot TextInputPlugin
//
textInputPlugin.getInputMethodManager().restartInput(this);
textInputPlugin
.
getInputMethodManager
().
restartInput
(
this
);
// Push View and Context related information from Android to Flutter.
sendUserSettingsToFlutter
();
...
...
@@ -673,8 +675,8 @@ public class XFlutterView extends FrameLayout {
// signifies that this View does not process input (until a new engine is attached).
// TODO(mattcarroll): once this is proven to work, move this line ot TextInputPlugin
textInputPlugin
.
getInputMethodManager
().
restartInput
(
this
);
//
textInputPlugin.destroy();
textInputPlugin
.
destroy
();
resolveMemoryLeaks
();
// Instruct our FlutterRenderer that we are no longer interested in being its RenderSurface.
FlutterRenderer
flutterRenderer
=
flutterEngine
.
getRenderer
();
didRenderFirstFrame
=
false
;
...
...
@@ -683,6 +685,30 @@ public class XFlutterView extends FrameLayout {
flutterEngine
=
null
;
}
public
void
resolveMemoryLeaks
(){
try
{
Class
clazz
=
TextInputPlugin
.
class
;
for
(
Field
f
:
clazz
.
getDeclaredFields
())
{
System
.
out
.
println
(
f
.
isAccessible
());
f
.
setAccessible
(
true
);
if
(
f
.
get
(
this
.
textInputPlugin
)
instanceof
TextInputChannel
){
System
.
out
.
println
(
"xxxxxx:"
+
f
.
getName
());
TextInputChannel
channel
=(
TextInputChannel
)
f
.
get
(
this
.
textInputPlugin
);
channel
.
setTextInputMethodHandler
(
null
);
}
}
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
}
}
/**
* Returns true if this {@code FlutterView} is currently attached to a {@link FlutterEngine}.
*/
...
...
android/src/main/java/com/idlefish/flutterboost/XInputConnectionAdaptor.java
deleted
100644 → 0
View file @
dd87a8bf
package
com.idlefish.flutterboost
;
import
android.content.Context
;
import
android.text.Editable
;
import
android.text.Selection
;
import
android.view.KeyEvent
;
import
android.view.View
;
import
android.view.inputmethod.BaseInputConnection
;
import
android.view.inputmethod.EditorInfo
;
import
android.view.inputmethod.InputMethodManager
;
import
io.flutter.embedding.engine.systemchannels.TextInputChannel
;
import
io.flutter.plugin.common.ErrorLogResult
;
import
io.flutter.plugin.common.MethodChannel
;
class
XInputConnectionAdaptor
extends
BaseInputConnection
{
private
final
View
mFlutterView
;
private
final
int
mClient
;
private
final
TextInputChannel
textInputChannel
;
private
final
Editable
mEditable
;
private
int
mBatchCount
;
private
InputMethodManager
mImm
;
private
static
final
MethodChannel
.
Result
logger
=
new
ErrorLogResult
(
"FlutterTextInput"
);
public
XInputConnectionAdaptor
(
View
view
,
int
client
,
TextInputChannel
textInputChannel
,
Editable
editable
)
{
super
(
view
,
true
);
mFlutterView
=
view
;
mClient
=
client
;
this
.
textInputChannel
=
textInputChannel
;
mEditable
=
editable
;
mBatchCount
=
0
;
mImm
=
(
InputMethodManager
)
view
.
getContext
().
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
}
// Send the current state of the editable to Flutter.
private
void
updateEditingState
()
{
// If the IME is in the middle of a batch edit, then wait until it completes.
if
(
mBatchCount
>
0
)
return
;
int
selectionStart
=
Selection
.
getSelectionStart
(
mEditable
);
int
selectionEnd
=
Selection
.
getSelectionEnd
(
mEditable
);
int
composingStart
=
BaseInputConnection
.
getComposingSpanStart
(
mEditable
);
int
composingEnd
=
BaseInputConnection
.
getComposingSpanEnd
(
mEditable
);
mImm
.
updateSelection
(
mFlutterView
,
selectionStart
,
selectionEnd
,
composingStart
,
composingEnd
);
textInputChannel
.
updateEditingState
(
mClient
,
mEditable
.
toString
(),
selectionStart
,
selectionEnd
,
composingStart
,
composingEnd
);
}
@Override
public
Editable
getEditable
()
{
return
mEditable
;
}
@Override
public
boolean
beginBatchEdit
()
{
mBatchCount
++;
return
super
.
beginBatchEdit
();
}
@Override
public
boolean
endBatchEdit
()
{
boolean
result
=
super
.
endBatchEdit
();
mBatchCount
--;
updateEditingState
();
return
result
;
}
@Override
public
boolean
commitText
(
CharSequence
text
,
int
newCursorPosition
)
{
boolean
result
=
super
.
commitText
(
text
,
newCursorPosition
);
updateEditingState
();
return
result
;
}
@Override
public
boolean
deleteSurroundingText
(
int
beforeLength
,
int
afterLength
)
{
if
(
Selection
.
getSelectionStart
(
mEditable
)
==
-
1
)
return
true
;
boolean
result
=
super
.
deleteSurroundingText
(
beforeLength
,
afterLength
);
updateEditingState
();
return
result
;
}
@Override
public
boolean
setComposingRegion
(
int
start
,
int
end
)
{
boolean
result
=
super
.
setComposingRegion
(
start
,
end
);
updateEditingState
();
return
result
;
}
@Override
public
boolean
setComposingText
(
CharSequence
text
,
int
newCursorPosition
)
{
boolean
result
;
if
(
text
.
length
()
==
0
)
{
result
=
super
.
commitText
(
text
,
newCursorPosition
);
}
else
{
result
=
super
.
setComposingText
(
text
,
newCursorPosition
);
}
updateEditingState
();
return
result
;
}
@Override
public
boolean
setSelection
(
int
start
,
int
end
)
{
boolean
result
=
super
.
setSelection
(
start
,
end
);
updateEditingState
();
return
result
;
}
@Override
public
boolean
sendKeyEvent
(
KeyEvent
event
)
{
if
(
event
.
getAction
()
==
KeyEvent
.
ACTION_DOWN
)
{
if
(
event
.
getKeyCode
()
==
KeyEvent
.
KEYCODE_DEL
)
{
int
selStart
=
Selection
.
getSelectionStart
(
mEditable
);
int
selEnd
=
Selection
.
getSelectionEnd
(
mEditable
);
if
(
selEnd
>
selStart
)
{
// Delete the selection.
Selection
.
setSelection
(
mEditable
,
selStart
);
mEditable
.
delete
(
selStart
,
selEnd
);
updateEditingState
();
return
true
;
}
else
if
(
selStart
>
0
)
{
// Delete to the left of the cursor.
int
newSel
=
Math
.
max
(
selStart
-
1
,
0
);
Selection
.
setSelection
(
mEditable
,
newSel
);
mEditable
.
delete
(
newSel
,
selStart
);
updateEditingState
();
return
true
;
}
}
else
if
(
event
.
getKeyCode
()
==
KeyEvent
.
KEYCODE_DPAD_LEFT
)
{
int
selStart
=
Selection
.
getSelectionStart
(
mEditable
);
int
newSel
=
Math
.
max
(
selStart
-
1
,
0
);
setSelection
(
newSel
,
newSel
);
return
true
;
}
else
if
(
event
.
getKeyCode
()
==
KeyEvent
.
KEYCODE_DPAD_RIGHT
)
{
int
selStart
=
Selection
.
getSelectionStart
(
mEditable
);
int
newSel
=
Math
.
min
(
selStart
+
1
,
mEditable
.
length
());
setSelection
(
newSel
,
newSel
);
return
true
;
}
else
{
// Enter a character.
int
character
=
event
.
getUnicodeChar
();
if
(
character
!=
0
)
{
int
selStart
=
Math
.
max
(
0
,
Selection
.
getSelectionStart
(
mEditable
));
int
selEnd
=
Math
.
max
(
0
,
Selection
.
getSelectionEnd
(
mEditable
));
if
(
selEnd
!=
selStart
)
mEditable
.
delete
(
selStart
,
selEnd
);
mEditable
.
insert
(
selStart
,
String
.
valueOf
((
char
)
character
));
setSelection
(
selStart
+
1
,
selStart
+
1
);
updateEditingState
();
}
return
true
;
}
}
return
false
;
}
@Override
public
boolean
performEditorAction
(
int
actionCode
)
{
switch
(
actionCode
)
{
case
EditorInfo
.
IME_ACTION_NONE
:
textInputChannel
.
newline
(
mClient
);
break
;
case
EditorInfo
.
IME_ACTION_UNSPECIFIED
:
textInputChannel
.
unspecifiedAction
(
mClient
);
break
;
case
EditorInfo
.
IME_ACTION_GO
:
textInputChannel
.
go
(
mClient
);
break
;
case
EditorInfo
.
IME_ACTION_SEARCH
:
textInputChannel
.
search
(
mClient
);
break
;
case
EditorInfo
.
IME_ACTION_SEND
:
textInputChannel
.
send
(
mClient
);
break
;
case
EditorInfo
.
IME_ACTION_NEXT
:
textInputChannel
.
next
(
mClient
);
break
;
case
EditorInfo
.
IME_ACTION_PREVIOUS
:
textInputChannel
.
previous
(
mClient
);
break
;
default
:
case
EditorInfo
.
IME_ACTION_DONE
:
textInputChannel
.
done
(
mClient
);
break
;
}
return
true
;
}
}
\ No newline at end of file
android/src/main/java/com/idlefish/flutterboost/XPlatformPlugin.java
deleted
100644 → 0
View file @
dd87a8bf
This diff is collapsed.
Click to expand it.
android/src/main/java/com/idlefish/flutterboost/XTextInputPlugin.java
deleted
100644 → 0
View file @
dd87a8bf
This diff is collapsed.
Click to expand it.
android/src/main/java/com/idlefish/flutterboost/containers/FlutterActivityAndFragmentDelegate.java
View file @
67c34f5b
...
...
@@ -19,6 +19,7 @@ import java.util.Map;
import
com.idlefish.flutterboost.NewFlutterBoost
;
import
com.idlefish.flutterboost.Utils
;
import
com.idlefish.flutterboost.XFlutterView
;
import
com.idlefish.flutterboost.interfaces.IFlutterViewContainer
;
import
com.idlefish.flutterboost.interfaces.IOperateSyncer
;
...
...
@@ -271,6 +272,8 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
platformPlugin
=
null
;
}
Utils
.
fixInputMethodManagerLeak
(
host
.
getActivity
());
// Destroy our FlutterEngine if we're not set to retain it.
// if (host.shouldDestroyEngineWithHost()) {
// flutterEngine.destroy();
...
...
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