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
7a8dac55
Commit
7a8dac55
authored
13 years ago
by
satok
Browse files
Options
Downloads
Patches
Plain Diff
Move Recorrection functions to Recorrection.java
Change-Id: I309d78c50074cd6fb02a9d6f51b675b158a56202
parent
ec5ae3a1
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
+21
-76
21 additions, 76 deletions
java/src/com/android/inputmethod/latin/LatinIME.java
java/src/com/android/inputmethod/latin/Recorrection.java
+130
-0
130 additions, 0 deletions
java/src/com/android/inputmethod/latin/Recorrection.java
with
151 additions
and
76 deletions
java/src/com/android/inputmethod/latin/LatinIME.java
+
21
−
76
View file @
7a8dac55
...
@@ -68,7 +68,6 @@ import android.view.WindowManager;
...
@@ -68,7 +68,6 @@ import android.view.WindowManager;
import
android.view.inputmethod.CompletionInfo
;
import
android.view.inputmethod.CompletionInfo
;
import
android.view.inputmethod.EditorInfo
;
import
android.view.inputmethod.EditorInfo
;
import
android.view.inputmethod.ExtractedText
;
import
android.view.inputmethod.ExtractedText
;
import
android.view.inputmethod.ExtractedTextRequest
;
import
android.view.inputmethod.InputConnection
;
import
android.view.inputmethod.InputConnection
;
import
android.widget.LinearLayout
;
import
android.widget.LinearLayout
;
...
@@ -152,6 +151,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
...
@@ -152,6 +151,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private
KeyboardSwitcher
mKeyboardSwitcher
;
private
KeyboardSwitcher
mKeyboardSwitcher
;
private
SubtypeSwitcher
mSubtypeSwitcher
;
private
SubtypeSwitcher
mSubtypeSwitcher
;
private
VoiceProxy
mVoiceProxy
;
private
VoiceProxy
mVoiceProxy
;
private
Recorrection
mRecorrection
;
private
UserDictionary
mUserDictionary
;
private
UserDictionary
mUserDictionary
;
private
UserBigramDictionary
mUserBigramDictionary
;
private
UserBigramDictionary
mUserBigramDictionary
;
...
@@ -176,7 +176,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
...
@@ -176,7 +176,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// punctuation on punctuation insertion, and become a real space on alpha char insertion.
// punctuation on punctuation insertion, and become a real space on alpha char insertion.
private
boolean
mJustAddedMagicSpace
;
// This indicates whether the last char is a magic space.
private
boolean
mJustAddedMagicSpace
;
// This indicates whether the last char is a magic space.
private
boolean
mAutoCorrectEnabled
;
private
boolean
mAutoCorrectEnabled
;
private
boolean
mRecorrectionEnabled
;
// Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary
// Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary
private
boolean
mBigramSuggestionEnabled
;
private
boolean
mBigramSuggestionEnabled
;
// Prediction: use bigrams to predict the next word when there is no input for it yet
// Prediction: use bigrams to predict the next word when there is no input for it yet
...
@@ -403,6 +402,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
...
@@ -403,6 +402,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
SubtypeSwitcher
.
init
(
this
,
prefs
);
SubtypeSwitcher
.
init
(
this
,
prefs
);
KeyboardSwitcher
.
init
(
this
,
prefs
);
KeyboardSwitcher
.
init
(
this
,
prefs
);
AccessibilityUtils
.
init
(
this
,
prefs
);
AccessibilityUtils
.
init
(
this
,
prefs
);
Recorrection
.
init
(
this
,
prefs
);
super
.
onCreate
();
super
.
onCreate
();
...
@@ -411,19 +411,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
...
@@ -411,19 +411,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mSubtypeSwitcher
=
SubtypeSwitcher
.
getInstance
();
mSubtypeSwitcher
=
SubtypeSwitcher
.
getInstance
();
mKeyboardSwitcher
=
KeyboardSwitcher
.
getInstance
();
mKeyboardSwitcher
=
KeyboardSwitcher
.
getInstance
();
mAccessibilityUtils
=
AccessibilityUtils
.
getInstance
();
mAccessibilityUtils
=
AccessibilityUtils
.
getInstance
();
mRecorrection
=
Recorrection
.
getInstance
();
final
Resources
res
=
getResources
();
final
Resources
res
=
getResources
();
mResources
=
res
;
mResources
=
res
;
// If the option should not be shown, do not read the recorrection preference
// but always use the default setting defined in the resources.
if
(
res
.
getBoolean
(
R
.
bool
.
config_enable_show_recorrection_option
))
{
mRecorrectionEnabled
=
prefs
.
getBoolean
(
Settings
.
PREF_RECORRECTION_ENABLED
,
res
.
getBoolean
(
R
.
bool
.
config_default_recorrection_enabled
));
}
else
{
mRecorrectionEnabled
=
res
.
getBoolean
(
R
.
bool
.
config_default_recorrection_enabled
);
}
mConfigEnableShowSubtypeSettings
=
res
.
getBoolean
(
mConfigEnableShowSubtypeSettings
=
res
.
getBoolean
(
R
.
bool
.
config_enable_show_subtype_settings
);
R
.
bool
.
config_enable_show_subtype_settings
);
mConfigSwipeDownDismissKeyboardEnabled
=
res
.
getBoolean
(
mConfigSwipeDownDismissKeyboardEnabled
=
res
.
getBoolean
(
...
@@ -624,7 +616,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
...
@@ -624,7 +616,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
inputView
.
setProximityCorrectionEnabled
(
true
);
inputView
.
setProximityCorrectionEnabled
(
true
);
inputView
.
setAccessibilityEnabled
(
accessibilityEnabled
);
inputView
.
setAccessibilityEnabled
(
accessibilityEnabled
);
// If we just entered a text field, maybe it has some old text that requires correction
// If we just entered a text field, maybe it has some old text that requires correction
checkRecorrectionOnStart
();
mRecorrection
.
checkRecorrectionOnStart
();
inputView
.
setForeground
(
true
);
inputView
.
setForeground
(
true
);
voiceIme
.
onStartInputView
(
inputView
.
getWindowToken
());
voiceIme
.
onStartInputView
(
inputView
.
getWindowToken
());
...
@@ -687,34 +679,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
...
@@ -687,34 +679,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
}
}
private
void
checkRecorrectionOnStart
()
{
if
(!
mRecorrectionEnabled
)
return
;
final
InputConnection
ic
=
getCurrentInputConnection
();
if
(
ic
==
null
)
return
;
// There could be a pending composing span. Clean it up first.
ic
.
finishComposingText
();
if
(
isShowingSuggestionsStrip
()
&&
isSuggestionsRequested
())
{
// First get the cursor position. This is required by setOldSuggestions(), so that
// it can pass the correct range to setComposingRegion(). At this point, we don't
// have valid values for mLastSelectionStart/End because onUpdateSelection() has
// not been called yet.
ExtractedTextRequest
etr
=
new
ExtractedTextRequest
();
etr
.
token
=
0
;
// anything is fine here
ExtractedText
et
=
ic
.
getExtractedText
(
etr
,
0
);
if
(
et
==
null
)
return
;
mLastSelectionStart
=
et
.
startOffset
+
et
.
selectionStart
;
mLastSelectionEnd
=
et
.
startOffset
+
et
.
selectionEnd
;
// Then look for possible corrections in a delayed fashion
if
(!
TextUtils
.
isEmpty
(
et
.
text
)
&&
isCursorTouchingWord
())
{
mHandler
.
postUpdateOldSuggestions
();
}
}
}
@Override
@Override
public
void
onFinishInput
()
{
public
void
onFinishInput
()
{
super
.
onFinishInput
();
super
.
onFinishInput
();
...
@@ -808,34 +772,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
...
@@ -808,34 +772,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mLastSelectionStart
=
newSelStart
;
mLastSelectionStart
=
newSelStart
;
mLastSelectionEnd
=
newSelEnd
;
mLastSelectionEnd
=
newSelEnd
;
if
(
mRecorrectionEnabled
&&
isShowingSuggestionsStrip
())
{
mRecorrection
.
updateRecorrectionSelection
(
mKeyboardSwitcher
,
// Don't look for corrections if the keyboard is not visible
mCandidateView
,
candidatesStart
,
candidatesEnd
,
newSelStart
,
if
(
mKeyboardSwitcher
.
isInputViewShown
())
{
newSelEnd
,
oldSelStart
,
mLastSelectionStart
,
// Check if we should go in or out of correction mode.
mLastSelectionEnd
,
mHasUncommittedTypedChars
);
if
(
isSuggestionsRequested
()
}
&&
(
candidatesStart
==
candidatesEnd
||
newSelStart
!=
oldSelStart
||
TextEntryState
.
isRecorrecting
())
public
void
setLastSelection
(
int
start
,
int
end
)
{
&&
(
newSelStart
<
newSelEnd
-
1
||
!
mHasUncommittedTypedChars
))
{
mLastSelectionStart
=
start
;
if
(
isCursorTouchingWord
()
||
mLastSelectionStart
<
mLastSelectionEnd
)
{
mLastSelectionEnd
=
end
;
mHandler
.
cancelUpdateBigramPredictions
();
mHandler
.
postUpdateOldSuggestions
();
}
else
{
abortRecorrection
(
false
);
// If showing the "touch again to save" hint, do not replace it. Else,
// show the bigrams if we are at the end of the text, punctuation otherwise.
if
(
mCandidateView
!=
null
&&
!
mCandidateView
.
isShowingAddToDictionaryHint
())
{
InputConnection
ic
=
getCurrentInputConnection
();
if
(
null
==
ic
||
!
TextUtils
.
isEmpty
(
ic
.
getTextAfterCursor
(
1
,
0
)))
{
if
(!
isShowingPunctuationList
())
setPunctuationSuggestions
();
}
else
{
mHandler
.
postUpdateBigramPredictions
();
}
}
}
}
}
}
}
}
/**
/**
...
@@ -848,7 +793,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
...
@@ -848,7 +793,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
*/
*/
@Override
@Override
public
void
onExtractedTextClicked
()
{
public
void
onExtractedTextClicked
()
{
if
(
mRecorrectionEnabled
&&
isSuggestionsRequested
())
return
;
if
(
mRecorrection
.
isRecorrection
Enabled
()
&&
isSuggestionsRequested
())
return
;
super
.
onExtractedTextClicked
();
super
.
onExtractedTextClicked
();
}
}
...
@@ -864,7 +809,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
...
@@ -864,7 +809,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
*/
*/
@Override
@Override
public
void
onExtractedCursorMovement
(
int
dx
,
int
dy
)
{
public
void
onExtractedCursorMovement
(
int
dx
,
int
dy
)
{
if
(
mRecorrectionEnabled
&&
isSuggestionsRequested
())
return
;
if
(
mRecorrection
.
isRecorrection
Enabled
()
&&
isSuggestionsRequested
())
return
;
super
.
onExtractedCursorMovement
(
dx
,
dy
);
super
.
onExtractedCursorMovement
(
dx
,
dy
);
}
}
...
@@ -1318,7 +1263,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
...
@@ -1318,7 +1263,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
}
}
p
rivate
void
abortRecorrection
(
boolean
force
)
{
p
ublic
void
abortRecorrection
(
boolean
force
)
{
if
(
force
||
TextEntryState
.
isRecorrecting
())
{
if
(
force
||
TextEntryState
.
isRecorrecting
())
{
TextEntryState
.
onAbortRecorrection
();
TextEntryState
.
onAbortRecorrection
();
setCandidatesViewShown
(
isCandidateStripVisible
());
setCandidatesViewShown
(
isCandidateStripVisible
());
...
@@ -1495,16 +1440,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
...
@@ -1495,16 +1440,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mWordHistory
.
add
(
entry
);
mWordHistory
.
add
(
entry
);
}
}
p
rivate
boolean
isSuggestionsRequested
()
{
p
ublic
boolean
isSuggestionsRequested
()
{
return
mIsSettingsSuggestionStripOn
return
mIsSettingsSuggestionStripOn
&&
(
mCorrectionMode
>
0
||
isShowingSuggestionsStrip
());
&&
(
mCorrectionMode
>
0
||
isShowingSuggestionsStrip
());
}
}
p
rivate
boolean
isShowingPunctuationList
()
{
p
ublic
boolean
isShowingPunctuationList
()
{
return
mSuggestPuncList
==
mCandidateView
.
getSuggestions
();
return
mSuggestPuncList
==
mCandidateView
.
getSuggestions
();
}
}
p
rivate
boolean
isShowingSuggestionsStrip
()
{
p
ublic
boolean
isShowingSuggestionsStrip
()
{
return
(
mSuggestionVisibility
==
SUGGESTION_VISIBILILTY_SHOW_VALUE
)
return
(
mSuggestionVisibility
==
SUGGESTION_VISIBILILTY_SHOW_VALUE
)
||
(
mSuggestionVisibility
==
SUGGESTION_VISIBILILTY_SHOW_ONLY_PORTRAIT_VALUE
||
(
mSuggestionVisibility
==
SUGGESTION_VISIBILILTY_SHOW_ONLY_PORTRAIT_VALUE
&&
mOrientation
==
Configuration
.
ORIENTATION_PORTRAIT
);
&&
mOrientation
==
Configuration
.
ORIENTATION_PORTRAIT
);
...
@@ -1877,7 +1822,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
...
@@ -1877,7 +1822,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
}
}
p
rivate
void
setPunctuationSuggestions
()
{
p
ublic
void
setPunctuationSuggestions
()
{
setSuggestions
(
mSuggestPuncList
);
setSuggestions
(
mSuggestPuncList
);
setCandidatesViewShown
(
isCandidateStripVisible
());
setCandidatesViewShown
(
isCandidateStripVisible
());
}
}
...
@@ -1925,7 +1870,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
...
@@ -1925,7 +1870,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
}
}
p
rivate
boolean
isCursorTouchingWord
()
{
p
ublic
boolean
isCursorTouchingWord
()
{
InputConnection
ic
=
getCurrentInputConnection
();
InputConnection
ic
=
getCurrentInputConnection
();
if
(
ic
==
null
)
return
false
;
if
(
ic
==
null
)
return
false
;
CharSequence
toLeft
=
ic
.
getTextBeforeCursor
(
1
,
0
);
CharSequence
toLeft
=
ic
.
getTextBeforeCursor
(
1
,
0
);
...
...
This diff is collapsed.
Click to expand it.
java/src/com/android/inputmethod/latin/Recorrection.java
0 → 100644
+
130
−
0
View file @
7a8dac55
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package
com.android.inputmethod.latin
;
import
com.android.inputmethod.keyboard.KeyboardSwitcher
;
import
android.content.SharedPreferences
;
import
android.content.res.Resources
;
import
android.text.TextUtils
;
import
android.view.inputmethod.ExtractedText
;
import
android.view.inputmethod.ExtractedTextRequest
;
import
android.view.inputmethod.InputConnection
;
/**
* Manager of re-correction functionalities
*/
public
class
Recorrection
{
private
static
final
Recorrection
sInstance
=
new
Recorrection
();
private
LatinIME
mService
;
private
boolean
mRecorrectionEnabled
=
false
;
public
static
Recorrection
getInstance
()
{
return
sInstance
;
}
public
static
void
init
(
LatinIME
context
,
SharedPreferences
prefs
)
{
if
(
context
==
null
||
prefs
==
null
)
{
return
;
}
sInstance
.
initInternal
(
context
,
prefs
);
}
private
Recorrection
()
{
}
public
boolean
isRecorrectionEnabled
()
{
return
mRecorrectionEnabled
;
}
private
void
initInternal
(
LatinIME
context
,
SharedPreferences
prefs
)
{
final
Resources
res
=
context
.
getResources
();
// If the option should not be shown, do not read the re-correction preference
// but always use the default setting defined in the resources.
if
(
res
.
getBoolean
(
R
.
bool
.
config_enable_show_recorrection_option
))
{
mRecorrectionEnabled
=
prefs
.
getBoolean
(
Settings
.
PREF_RECORRECTION_ENABLED
,
res
.
getBoolean
(
R
.
bool
.
config_default_recorrection_enabled
));
}
else
{
mRecorrectionEnabled
=
res
.
getBoolean
(
R
.
bool
.
config_default_recorrection_enabled
);
}
mService
=
context
;
}
public
void
checkRecorrectionOnStart
()
{
if
(!
mRecorrectionEnabled
)
return
;
final
InputConnection
ic
=
mService
.
getCurrentInputConnection
();
if
(
ic
==
null
)
return
;
// There could be a pending composing span. Clean it up first.
ic
.
finishComposingText
();
if
(
mService
.
isShowingSuggestionsStrip
()
&&
mService
.
isSuggestionsRequested
())
{
// First get the cursor position. This is required by setOldSuggestions(), so that
// it can pass the correct range to setComposingRegion(). At this point, we don't
// have valid values for mLastSelectionStart/End because onUpdateSelection() has
// not been called yet.
ExtractedTextRequest
etr
=
new
ExtractedTextRequest
();
etr
.
token
=
0
;
// anything is fine here
ExtractedText
et
=
ic
.
getExtractedText
(
etr
,
0
);
if
(
et
==
null
)
return
;
mService
.
setLastSelection
(
et
.
startOffset
+
et
.
selectionStart
,
et
.
startOffset
+
et
.
selectionEnd
);
// Then look for possible corrections in a delayed fashion
if
(!
TextUtils
.
isEmpty
(
et
.
text
)
&&
mService
.
isCursorTouchingWord
())
{
mService
.
mHandler
.
postUpdateOldSuggestions
();
}
}
}
public
void
updateRecorrectionSelection
(
KeyboardSwitcher
keyboardSwitcher
,
CandidateView
candidateView
,
int
candidatesStart
,
int
candidatesEnd
,
int
newSelStart
,
int
newSelEnd
,
int
oldSelStart
,
int
lastSelectionStart
,
int
lastSelectionEnd
,
boolean
hasUncommittedTypedChars
)
{
if
(
mRecorrectionEnabled
&&
mService
.
isShowingSuggestionsStrip
())
{
// Don't look for corrections if the keyboard is not visible
if
(
keyboardSwitcher
.
isInputViewShown
())
{
// Check if we should go in or out of correction mode.
if
(
mService
.
isSuggestionsRequested
()
&&
(
candidatesStart
==
candidatesEnd
||
newSelStart
!=
oldSelStart
||
TextEntryState
.
isRecorrecting
())
&&
(
newSelStart
<
newSelEnd
-
1
||
!
hasUncommittedTypedChars
))
{
if
(
mService
.
isCursorTouchingWord
()
||
lastSelectionStart
<
lastSelectionEnd
)
{
mService
.
mHandler
.
cancelUpdateBigramPredictions
();
mService
.
mHandler
.
postUpdateOldSuggestions
();
}
else
{
mService
.
abortRecorrection
(
false
);
// If showing the "touch again to save" hint, do not replace it. Else,
// show the bigrams if we are at the end of the text, punctuation otherwise.
if
(
candidateView
!=
null
&&
!
candidateView
.
isShowingAddToDictionaryHint
())
{
InputConnection
ic
=
mService
.
getCurrentInputConnection
();
if
(
null
==
ic
||
!
TextUtils
.
isEmpty
(
ic
.
getTextAfterCursor
(
1
,
0
)))
{
if
(!
mService
.
isShowingPunctuationList
())
{
mService
.
setPunctuationSuggestions
();
}
}
else
{
mService
.
mHandler
.
postUpdateBigramPredictions
();
}
}
}
}
}
}
}
}
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