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
e5a8615d
Commit
e5a8615d
authored
10 years ago
by
Jean Chalard
Browse files
Options
Downloads
Patches
Plain Diff
[CS6] Cut out methods to clarify what we are doing
Bug: 13238601 Change-Id: I99cc62e91b1e89130358fded572987023d919507
parent
96793630
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/src/com/android/inputmethod/latin/Suggest.java
+45
-39
45 additions, 39 deletions
java/src/com/android/inputmethod/latin/Suggest.java
with
45 additions
and
39 deletions
java/src/com/android/inputmethod/latin/Suggest.java
+
45
−
39
View file @
e5a8615d
...
...
@@ -87,6 +87,40 @@ public final class Suggest {
}
}
private
static
ArrayList
<
SuggestedWordInfo
>
getTransformedSuggestedWordInfoList
(
final
WordComposer
wordComposer
,
final
SuggestionResults
results
,
final
int
trailingSingleQuotesCount
)
{
final
boolean
shouldMakeSuggestionsAllUpperCase
=
wordComposer
.
isAllUpperCase
()
&&
!
wordComposer
.
isResumed
();
final
boolean
isOnlyFirstCharCapitalized
=
wordComposer
.
isOrWillBeOnlyFirstCharCapitalized
();
final
ArrayList
<
SuggestedWordInfo
>
suggestionsContainer
=
new
ArrayList
<>(
results
);
final
int
suggestionsCount
=
suggestionsContainer
.
size
();
if
(
isOnlyFirstCharCapitalized
||
shouldMakeSuggestionsAllUpperCase
||
0
!=
trailingSingleQuotesCount
)
{
for
(
int
i
=
0
;
i
<
suggestionsCount
;
++
i
)
{
final
SuggestedWordInfo
wordInfo
=
suggestionsContainer
.
get
(
i
);
final
SuggestedWordInfo
transformedWordInfo
=
getTransformedSuggestedWordInfo
(
wordInfo
,
results
.
mLocale
,
shouldMakeSuggestionsAllUpperCase
,
isOnlyFirstCharCapitalized
,
trailingSingleQuotesCount
);
suggestionsContainer
.
set
(
i
,
transformedWordInfo
);
}
}
return
suggestionsContainer
;
}
private
static
String
getWhitelistedWordOrNull
(
final
ArrayList
<
SuggestedWordInfo
>
suggestions
)
{
if
(
suggestions
.
isEmpty
())
{
return
null
;
}
final
SuggestedWordInfo
firstSuggestedWordInfo
=
suggestions
.
get
(
0
);
if
(!
firstSuggestedWordInfo
.
isKindOf
(
SuggestedWordInfo
.
KIND_WHITELIST
))
{
return
null
;
}
return
firstSuggestedWordInfo
.
mWord
;
}
// Retrieves suggestions for the typing input
// and calls the callback function with the suggestions.
private
void
getSuggestedWordsForTypingInput
(
final
WordComposer
wordComposer
,
...
...
@@ -103,42 +137,14 @@ public final class Suggest {
final
SuggestionResults
suggestionResults
=
mDictionaryFacilitator
.
getSuggestionResults
(
wordComposer
,
prevWordsInfo
,
proximityInfo
,
blockOffensiveWords
,
additionalFeaturesOptions
,
SESSION_TYPING
);
final
boolean
isPrediction
=
!
wordComposer
.
isComposingWord
();
final
boolean
shouldMakeSuggestionsAllUpperCase
=
wordComposer
.
isAllUpperCase
()
&&
!
wordComposer
.
isResumed
();
final
boolean
isOnlyFirstCharCapitalized
=
wordComposer
.
isOrWillBeOnlyFirstCharCapitalized
();
final
ArrayList
<
SuggestedWordInfo
>
suggestionsContainer
=
new
ArrayList
<>(
suggestionResults
);
final
int
suggestionsCount
=
suggestionsContainer
.
size
();
if
(
isOnlyFirstCharCapitalized
||
shouldMakeSuggestionsAllUpperCase
||
0
!=
trailingSingleQuotesCount
)
{
for
(
int
i
=
0
;
i
<
suggestionsCount
;
++
i
)
{
final
SuggestedWordInfo
wordInfo
=
suggestionsContainer
.
get
(
i
);
final
SuggestedWordInfo
transformedWordInfo
=
getTransformedSuggestedWordInfo
(
wordInfo
,
suggestionResults
.
mLocale
,
shouldMakeSuggestionsAllUpperCase
,
isOnlyFirstCharCapitalized
,
trailingSingleQuotesCount
);
suggestionsContainer
.
set
(
i
,
transformedWordInfo
);
}
}
getTransformedSuggestedWordInfoList
(
wordComposer
,
suggestionResults
,
trailingSingleQuotesCount
);
final
boolean
didRemoveTypedWord
=
SuggestedWordInfo
.
removeDups
(
t
ypedWord
,
suggestionsContainer
);
SuggestedWordInfo
.
removeDups
(
wordComposer
.
getT
ypedWord
()
,
suggestionsContainer
);
final
SuggestedWordInfo
firstSuggestedWordInfo
;
final
String
whitelistedWord
;
if
(
suggestionsContainer
.
isEmpty
())
{
firstSuggestedWordInfo
=
null
;
whitelistedWord
=
null
;
}
else
{
firstSuggestedWordInfo
=
suggestionsContainer
.
get
(
0
);
if
(!
firstSuggestedWordInfo
.
isKindOf
(
SuggestedWordInfo
.
KIND_WHITELIST
))
{
whitelistedWord
=
null
;
}
else
{
whitelistedWord
=
firstSuggestedWordInfo
.
mWord
;
}
}
final
String
whitelistedWord
=
getWhitelistedWordOrNull
(
suggestionsContainer
);
final
boolean
resultsArePredictions
=
!
wordComposer
.
isComposingWord
();
// We allow auto-correction if we have a whitelisted word, or if the word had more than
// one char and was not suggested.
...
...
@@ -151,11 +157,11 @@ public final class Suggest {
// same time, it feels wrong that the SuggestedWord object includes information about
// the current settings. It may also be useful to know, when the setting is off, whether
// the word *would* have been auto-corrected.
if
(!
isCorrectionEnabled
||
!
allowsToBeAutoCorrected
||
is
Prediction
||
null
==
firstSuggestedWordInfo
||
wordComposer
.
hasDigits
()
if
(!
isCorrectionEnabled
||
!
allowsToBeAutoCorrected
||
resultsAre
Prediction
s
||
suggestionResults
.
isEmpty
()
||
wordComposer
.
hasDigits
()
||
wordComposer
.
isMostlyCaps
()
||
wordComposer
.
isResumed
()
||
!
mDictionaryFacilitator
.
hasInitializedMainDictionary
()
||
firstSuggestedWordInfo
.
isKindOf
(
SuggestedWordInfo
.
KIND_SHORTCUT
))
{
||
suggestionResults
.
first
()
.
isKindOf
(
SuggestedWordInfo
.
KIND_SHORTCUT
))
{
// If we don't have a main dictionary, we never want to auto-correct. The reason for
// this is, the user may have a contact whose name happens to match a valid word in
// their language, and it will unexpectedly auto-correct. For example, if the user
...
...
@@ -167,7 +173,7 @@ public final class Suggest {
hasAutoCorrection
=
false
;
}
else
{
hasAutoCorrection
=
AutoCorrectionUtils
.
suggestionExceedsAutoCorrectionThreshold
(
firstSuggestedWordInfo
,
consideredWord
,
mAutoCorrectionThreshold
);
suggestionResults
.
first
()
,
consideredWord
,
mAutoCorrectionThreshold
);
}
if
(!
TextUtils
.
isEmpty
(
typedWord
))
{
...
...
@@ -190,9 +196,9 @@ public final class Suggest {
// TODO: this first argument is lying. If this is a whitelisted word which is an
// actual word, it says typedWordValid = false, which looks wrong. We should either
// rename the attribute or change the value.
!
is
Prediction
&&
!
allowsToBeAutoCorrected
/* typedWordValid */
,
!
resultsAre
Prediction
s
&&
!
allowsToBeAutoCorrected
/* typedWordValid */
,
hasAutoCorrection
/* willAutoCorrect */
,
false
/* isObsoleteSuggestions */
,
is
Prediction
,
sequenceNumber
));
false
/* isObsoleteSuggestions */
,
resultsAre
Prediction
s
,
sequenceNumber
));
}
// Retrieves suggestions for the batch input
...
...
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