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
23726dbd
Commit
23726dbd
authored
13 years ago
by
satok
Browse files
Options
Downloads
Patches
Plain Diff
Refactor of SuggestionSpanUtils
Change-Id: Id266062831e8c28a346e129168b883ee3d5622bf
parent
064e21bb
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/compat/SuggestionSpanUtils.java
+11
-10
11 additions, 10 deletions
...c/com/android/inputmethod/compat/SuggestionSpanUtils.java
with
11 additions
and
10 deletions
java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
+
11
−
10
View file @
23726dbd
...
...
@@ -30,12 +30,14 @@ import java.util.ArrayList;
import
java.util.Locale
;
public
class
SuggestionSpanUtils
{
// TODO: Use reflection to get field values
public
static
final
String
ACTION_SUGGESTION_PICKED
=
"android.text.style.SUGGESTION_PICKED"
;
public
static
final
String
SUGGESTION_SPAN_PICKED_AFTER
=
"after"
;
public
static
final
String
SUGGESTION_SPAN_PICKED_BEFORE
=
"before"
;
public
static
final
String
SUGGESTION_SPAN_PICKED_HASHCODE
=
"hashcode"
;
public
static
final
int
SUGGESTION_MAX_SIZE
=
5
;
public
static
final
boolean
SUGGESTION_SPAN_IS_SUPPORTED
;
private
static
final
Class
<?>
CLASS_SuggestionSpan
=
CompatUtils
.
getClass
(
"android.text.style.SuggestionSpan"
);
...
...
@@ -43,24 +45,23 @@ public class SuggestionSpanUtils {
Context
.
class
,
Locale
.
class
,
String
[].
class
,
int
.
class
,
Class
.
class
};
private
static
final
Constructor
<?>
CONSTRUCTOR_SuggestionSpan
=
CompatUtils
.
getConstructor
(
CLASS_SuggestionSpan
,
INPUT_TYPE_SuggestionSpan
);
public
static
final
boolean
SUGGESTION_SPAN_IS_SUPPORTED
;
static
{
SUGGESTION_SPAN_IS_SUPPORTED
=
CLASS_SuggestionSpan
!=
null
&&
CONSTRUCTOR_SuggestionSpan
!=
null
;
}
public
static
CharSequence
getTextWithSuggestionSpan
(
Context
context
,
CharSequence
suggestion
,
SuggestedWords
suggestedWords
)
{
if
(
TextUtils
.
isEmpty
(
suggestion
)
||
CONSTRUCTOR_SuggestionSpan
==
null
CharSequence
pickedWord
,
SuggestedWords
suggestedWords
)
{
if
(
TextUtils
.
isEmpty
(
pickedWord
)
||
CONSTRUCTOR_SuggestionSpan
==
null
||
suggestedWords
==
null
||
suggestedWords
.
size
()
==
0
)
{
return
suggestion
;
return
pickedWord
;
}
final
Spannable
spannable
;
if
(
suggestion
instanceof
Spannable
)
{
spannable
=
(
Spannable
)
suggestion
;
if
(
pickedWord
instanceof
Spannable
)
{
spannable
=
(
Spannable
)
pickedWord
;
}
else
{
spannable
=
new
SpannableString
(
suggestion
);
spannable
=
new
SpannableString
(
pickedWord
);
}
final
ArrayList
<
String
>
suggestionsList
=
new
ArrayList
<
String
>();
for
(
int
i
=
0
;
i
<
suggestedWords
.
size
();
++
i
)
{
...
...
@@ -68,7 +69,7 @@ public class SuggestionSpanUtils {
break
;
}
final
CharSequence
word
=
suggestedWords
.
getWord
(
i
);
if
(!
TextUtils
.
equals
(
suggestion
,
word
))
{
if
(!
TextUtils
.
equals
(
pickedWord
,
word
))
{
suggestionsList
.
add
(
word
.
toString
());
}
}
...
...
@@ -78,9 +79,9 @@ public class SuggestionSpanUtils {
(
Class
<?>)
SuggestionSpanPickedNotificationReceiver
.
class
};
final
Object
ss
=
CompatUtils
.
newInstance
(
CONSTRUCTOR_SuggestionSpan
,
args
);
if
(
ss
==
null
)
{
return
suggestion
;
return
pickedWord
;
}
spannable
.
setSpan
(
ss
,
0
,
suggestion
.
length
(),
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
spannable
.
setSpan
(
ss
,
0
,
pickedWord
.
length
(),
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
return
spannable
;
}
}
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