Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
keyboard
LatinIME
Commits
0547b331
Commit
0547b331
authored
11 years ago
by
Jean Chalard
Browse files
Options
Downloads
Patches
Plain Diff
[IL29] Move retryResetCaches and tryFixLyingCursorPosition
Bug: 8636060 Change-Id: I45b322e4844f023e91b80f9c2e0f7fa0166bcc59
parent
81e8d160
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
java/src/com/android/inputmethod/latin/LatinIME.java
+5
-66
5 additions, 66 deletions
java/src/com/android/inputmethod/latin/LatinIME.java
java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+68
-0
68 additions, 0 deletions
.../com/android/inputmethod/latin/inputlogic/InputLogic.java
with
73 additions
and
66 deletions
java/src/com/android/inputmethod/latin/LatinIME.java
+
5
−
66
View file @
0547b331
...
@@ -219,8 +219,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
...
@@ -219,8 +219,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
latinIme
.
onEndBatchInputAsyncInternal
((
SuggestedWords
)
msg
.
obj
);
latinIme
.
onEndBatchInputAsyncInternal
((
SuggestedWords
)
msg
.
obj
);
break
;
break
;
case
MSG_RESET_CACHES:
case
MSG_RESET_CACHES:
latinIme
.
retryResetCaches
(
msg
.
arg1
==
1
/* tryResumeSuggestions */
,
latinIme
.
mInputLogic
.
retryResetCaches
(
latinIme
.
mSettings
.
getCurrent
(),
msg
.
arg2
/* remainingTries */
);
msg
.
arg1
==
1
/* tryResumeSuggestions */
,
msg
.
arg2
/* remainingTries */
,
latinIme
.
mKeyboardSwitcher
,
this
);
break
;
break
;
}
}
}
}
...
@@ -812,7 +814,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
...
@@ -812,7 +814,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mInputLogic
.
mLastSelectionEnd
=
editorInfo
.
initialSelEnd
;
mInputLogic
.
mLastSelectionEnd
=
editorInfo
.
initialSelEnd
;
// In some cases (namely, after rotation of the device) editorInfo.initialSelStart is lying
// In some cases (namely, after rotation of the device) editorInfo.initialSelStart is lying
// so we try using some heuristics to find out about these and fix them.
// so we try using some heuristics to find out about these and fix them.
tryFixLyingCursorPosition
();
mInputLogic
.
tryFixLyingCursorPosition
();
mHandler
.
cancelUpdateSuggestionStrip
();
mHandler
.
cancelUpdateSuggestionStrip
();
mHandler
.
cancelDoubleSpacePeriodTimer
();
mHandler
.
cancelDoubleSpacePeriodTimer
();
...
@@ -831,44 +833,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
...
@@ -831,44 +833,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if
(
TRACE
)
Debug
.
startMethodTracing
(
"/data/trace/latinime"
);
if
(
TRACE
)
Debug
.
startMethodTracing
(
"/data/trace/latinime"
);
}
}
/**
* Try to get the text from the editor to expose lies the framework may have been
* telling us. Concretely, when the device rotates, the frameworks tells us about where the
* cursor used to be initially in the editor at the time it first received the focus; this
* may be completely different from the place it is upon rotation. Since we don't have any
* means to get the real value, try at least to ask the text view for some characters and
* detect the most damaging cases: when the cursor position is declared to be much smaller
* than it really is.
*/
private
void
tryFixLyingCursorPosition
()
{
final
CharSequence
textBeforeCursor
=
mInputLogic
.
mConnection
.
getTextBeforeCursor
(
Constants
.
EDITOR_CONTENTS_CACHE_SIZE
,
0
);
if
(
null
==
textBeforeCursor
)
{
mInputLogic
.
mLastSelectionStart
=
mInputLogic
.
mLastSelectionEnd
=
Constants
.
NOT_A_CURSOR_POSITION
;
}
else
{
final
int
textLength
=
textBeforeCursor
.
length
();
if
(
textLength
>
mInputLogic
.
mLastSelectionStart
||
(
textLength
<
Constants
.
EDITOR_CONTENTS_CACHE_SIZE
&&
mInputLogic
.
mLastSelectionStart
<
Constants
.
EDITOR_CONTENTS_CACHE_SIZE
))
{
// It should not be possible to have only one of those variables be
// NOT_A_CURSOR_POSITION, so if they are equal, either the selection is zero-sized
// (simple cursor, no selection) or there is no cursor/we don't know its pos
final
boolean
wasEqual
=
mInputLogic
.
mLastSelectionStart
==
mInputLogic
.
mLastSelectionEnd
;
mInputLogic
.
mLastSelectionStart
=
textLength
;
// We can't figure out the value of mLastSelectionEnd :(
// But at least if it's smaller than mLastSelectionStart something is wrong,
// and if they used to be equal we also don't want to make it look like there is a
// selection.
if
(
wasEqual
||
mInputLogic
.
mLastSelectionStart
>
mInputLogic
.
mLastSelectionEnd
)
{
mInputLogic
.
mLastSelectionEnd
=
mInputLogic
.
mLastSelectionStart
;
}
}
}
}
@Override
@Override
public
void
onWindowHidden
()
{
public
void
onWindowHidden
()
{
super
.
onWindowHidden
();
super
.
onWindowHidden
();
...
@@ -1894,31 +1858,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
...
@@ -1894,31 +1858,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mHandler
.
showSuggestionStripWithTypedWord
(
suggestedWords
,
typedWord
);
mHandler
.
showSuggestionStripWithTypedWord
(
suggestedWords
,
typedWord
);
}
}
/**
* Retry resetting caches in the rich input connection.
*
* When the editor can't be accessed we can't reset the caches, so we schedule a retry.
* This method handles the retry, and re-schedules a new retry if we still can't access.
* We only retry up to 5 times before giving up.
*
* @param tryResumeSuggestions Whether we should resume suggestions or not.
* @param remainingTries How many times we may try again before giving up.
*/
private
void
retryResetCaches
(
final
boolean
tryResumeSuggestions
,
final
int
remainingTries
)
{
if
(!
mInputLogic
.
mConnection
.
resetCachesUponCursorMoveAndReturnSuccess
(
mInputLogic
.
mLastSelectionStart
,
mInputLogic
.
mLastSelectionEnd
,
false
))
{
if
(
0
<
remainingTries
)
{
mHandler
.
postResetCaches
(
tryResumeSuggestions
,
remainingTries
-
1
);
return
;
}
// If remainingTries is 0, we should stop waiting for new tries, but it's still
// better to load the keyboard (less things will be broken).
}
tryFixLyingCursorPosition
();
mKeyboardSwitcher
.
loadKeyboard
(
getCurrentInputEditorInfo
(),
mSettings
.
getCurrent
());
if
(
tryResumeSuggestions
)
mHandler
.
postResumeSuggestions
();
}
// TODO: Make this private
// TODO: Make this private
// Outside LatinIME, only used by the {@link InputTestsBase} test suite.
// Outside LatinIME, only used by the {@link InputTestsBase} test suite.
@UsedForTesting
@UsedForTesting
...
...
This diff is collapsed.
Click to expand it.
java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+
68
−
0
View file @
0547b331
...
@@ -1528,4 +1528,72 @@ public final class InputLogic {
...
@@ -1528,4 +1528,72 @@ public final class InputLogic {
mWordComposer
.
discardPreviousWordForSuggestion
();
mWordComposer
.
discardPreviousWordForSuggestion
();
}
}
}
}
/**
* Try to get the text from the editor to expose lies the framework may have been
* telling us. Concretely, when the device rotates, the frameworks tells us about where the
* cursor used to be initially in the editor at the time it first received the focus; this
* may be completely different from the place it is upon rotation. Since we don't have any
* means to get the real value, try at least to ask the text view for some characters and
* detect the most damaging cases: when the cursor position is declared to be much smaller
* than it really is.
*/
// TODO: make this private
public
void
tryFixLyingCursorPosition
()
{
final
CharSequence
textBeforeCursor
=
mConnection
.
getTextBeforeCursor
(
Constants
.
EDITOR_CONTENTS_CACHE_SIZE
,
0
);
if
(
null
==
textBeforeCursor
)
{
mLastSelectionStart
=
mLastSelectionEnd
=
Constants
.
NOT_A_CURSOR_POSITION
;
}
else
{
final
int
textLength
=
textBeforeCursor
.
length
();
if
(
textLength
>
mLastSelectionStart
||
(
textLength
<
Constants
.
EDITOR_CONTENTS_CACHE_SIZE
&&
mLastSelectionStart
<
Constants
.
EDITOR_CONTENTS_CACHE_SIZE
))
{
// It should not be possible to have only one of those variables be
// NOT_A_CURSOR_POSITION, so if they are equal, either the selection is zero-sized
// (simple cursor, no selection) or there is no cursor/we don't know its pos
final
boolean
wasEqual
=
mLastSelectionStart
==
mLastSelectionEnd
;
mLastSelectionStart
=
textLength
;
// We can't figure out the value of mLastSelectionEnd :(
// But at least if it's smaller than mLastSelectionStart something is wrong,
// and if they used to be equal we also don't want to make it look like there is a
// selection.
if
(
wasEqual
||
mLastSelectionStart
>
mLastSelectionEnd
)
{
mLastSelectionEnd
=
mLastSelectionStart
;
}
}
}
}
/**
* Retry resetting caches in the rich input connection.
*
* When the editor can't be accessed we can't reset the caches, so we schedule a retry.
* This method handles the retry, and re-schedules a new retry if we still can't access.
* We only retry up to 5 times before giving up.
*
* @param settingsValues the current values of the settings.
* @param tryResumeSuggestions Whether we should resume suggestions or not.
* @param remainingTries How many times we may try again before giving up.
*/
// TODO: make this private
public
void
retryResetCaches
(
final
SettingsValues
settingsValues
,
final
boolean
tryResumeSuggestions
,
final
int
remainingTries
,
// TODO: remove these arguments
final
KeyboardSwitcher
keyboardSwitcher
,
final
LatinIME
.
UIHandler
handler
)
{
if
(!
mConnection
.
resetCachesUponCursorMoveAndReturnSuccess
(
mLastSelectionStart
,
mLastSelectionEnd
,
false
))
{
if
(
0
<
remainingTries
)
{
handler
.
postResetCaches
(
tryResumeSuggestions
,
remainingTries
-
1
);
return
;
}
// If remainingTries is 0, we should stop waiting for new tries, but it's still
// better to load the keyboard (less things will be broken).
}
tryFixLyingCursorPosition
();
keyboardSwitcher
.
loadKeyboard
(
getCurrentInputEditorInfo
(),
settingsValues
);
if
(
tryResumeSuggestions
)
{
handler
.
postResumeSuggestions
();
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment