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
9ee51db9
Commit
9ee51db9
authored
13 years ago
by
satok
Browse files
Options
Downloads
Patches
Plain Diff
Optimize InputLanguageSelection
Change-Id: I49117a1e5f7766fcfa0140ff602ff1e19ba1e3d2
parent
bdb3d690
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/deprecated/languageswitcher/InputLanguageSelection.java
+23
-32
23 additions, 32 deletions
...d/deprecated/languageswitcher/InputLanguageSelection.java
with
23 additions
and
32 deletions
java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java
+
23
−
32
View file @
9ee51db9
...
@@ -37,6 +37,7 @@ import android.preference.PreferenceActivity;
...
@@ -37,6 +37,7 @@ import android.preference.PreferenceActivity;
import
android.preference.PreferenceGroup
;
import
android.preference.PreferenceGroup
;
import
android.preference.PreferenceManager
;
import
android.preference.PreferenceManager
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
import
android.util.Pair
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.text.Collator
;
import
java.text.Collator
;
...
@@ -88,14 +89,17 @@ public class InputLanguageSelection extends PreferenceActivity {
...
@@ -88,14 +89,17 @@ public class InputLanguageSelection extends PreferenceActivity {
PreferenceGroup
parent
=
getPreferenceScreen
();
PreferenceGroup
parent
=
getPreferenceScreen
();
for
(
int
i
=
0
;
i
<
mAvailableLanguages
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
mAvailableLanguages
.
size
();
i
++)
{
Locale
locale
=
mAvailableLanguages
.
get
(
i
).
mLocale
;
Locale
locale
=
mAvailableLanguages
.
get
(
i
).
mLocale
;
if
(!
hasDictionary
(
locale
)
&&
!
hasLayout
(
locale
))
{
final
Pair
<
Boolean
,
Boolean
>
hasDictionaryOrLayout
=
hasDictionaryOrLayout
(
locale
);
final
boolean
hasDictionary
=
hasDictionaryOrLayout
.
first
;
final
boolean
hasLayout
=
hasDictionaryOrLayout
.
second
;
if
(!
hasDictionary
&&
!
hasLayout
)
{
continue
;
continue
;
}
}
CheckBoxPreference
pref
=
new
CheckBoxPreference
(
this
);
CheckBoxPreference
pref
=
new
CheckBoxPreference
(
this
);
pref
.
setTitle
(
SubtypeSwitcher
.
getFullDisplayName
(
locale
,
true
));
pref
.
setTitle
(
SubtypeSwitcher
.
getFullDisplayName
(
locale
,
true
));
boolean
checked
=
isLocaleIn
(
locale
,
languageList
);
boolean
checked
=
isLocaleIn
(
locale
,
languageList
);
pref
.
setChecked
(
checked
);
pref
.
setChecked
(
checked
);
if
(
hasDictionary
(
locale
)
)
{
if
(
hasDictionary
)
{
pref
.
setSummary
(
R
.
string
.
has_dictionary
);
pref
.
setSummary
(
R
.
string
.
has_dictionary
);
}
}
parent
.
addPreference
(
pref
);
parent
.
addPreference
(
pref
);
...
@@ -110,52 +114,39 @@ public class InputLanguageSelection extends PreferenceActivity {
...
@@ -110,52 +114,39 @@ public class InputLanguageSelection extends PreferenceActivity {
return
false
;
return
false
;
}
}
private
boolean
hasDictionary
(
Locale
locale
)
{
private
Pair
<
Boolean
,
Boolean
>
hasDictionaryOrLayout
(
Locale
locale
)
{
if
(
locale
==
null
)
return
new
Pair
<
Boolean
,
Boolean
>(
false
,
false
);
final
Resources
res
=
getResources
();
final
Resources
res
=
getResources
();
final
Configuration
conf
=
res
.
getConfiguration
();
final
Configuration
conf
=
res
.
getConfiguration
();
final
Locale
saveLocale
=
conf
.
locale
;
final
Locale
saveLocale
=
conf
.
locale
;
boolean
haveDictionary
=
false
;
conf
.
locale
=
locale
;
conf
.
locale
=
locale
;
res
.
updateConfiguration
(
conf
,
res
.
getDisplayMetrics
());
res
.
updateConfiguration
(
conf
,
res
.
getDisplayMetrics
());
boolean
hasDictionary
=
false
;
boolean
hasLayout
=
false
;
BinaryDictionary
bd
=
BinaryDictionary
.
initDictionaryFromManager
(
this
,
Suggest
.
DIC_MAIN
,
try
{
locale
,
Utils
.
getMainDictionaryResourceId
(
res
));
BinaryDictionary
bd
=
BinaryDictionary
.
initDictionaryFromManager
(
this
,
Suggest
.
DIC_MAIN
,
locale
,
Utils
.
getMainDictionaryResourceId
(
res
));
// Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of
// 4000-5000 words, whereas the LARGE_DICTIONARY is about 20000+ words.
if
(
bd
.
getSize
()
>
Suggest
.
LARGE_DICTIONARY_THRESHOLD
/
4
)
{
haveDictionary
=
true
;
}
bd
.
close
();
conf
.
locale
=
saveLocale
;
res
.
updateConfiguration
(
conf
,
res
.
getDisplayMetrics
());
return
haveDictionary
;
}
private
boolean
hasLayout
(
Locale
locale
)
{
// Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of
if
(
locale
==
null
)
return
false
;
// 4000-5000 words, whereas the LARGE_DICTIONARY is about 20000+ words.
final
Resources
res
=
getResources
();
if
(
bd
.
getSize
()
>
Suggest
.
LARGE_DICTIONARY_THRESHOLD
/
4
)
{
final
Configuration
conf
=
res
.
getConfiguration
();
hasDictionary
=
true
;
final
Locale
saveLocale
=
conf
.
locale
;
}
conf
.
locale
=
locale
;
bd
.
close
();
res
.
updateConfiguration
(
conf
,
res
.
getDisplayMetrics
());
try
{
final
String
countryCode
=
locale
.
getLanguage
();
final
String
countryCode
=
locale
.
getLanguage
();
final
String
layoutCountryCode
=
KeyboardParser
.
parseKeyboardLocale
(
final
String
layoutCountryCode
=
KeyboardParser
.
parseKeyboardLocale
(
this
,
R
.
xml
.
kbd_qwerty
);
this
,
R
.
xml
.
kbd_qwerty
);
if
(!
TextUtils
.
isEmpty
(
countryCode
)
&&
!
TextUtils
.
isEmpty
(
layoutCountryCode
))
{
if
(!
TextUtils
.
isEmpty
(
countryCode
)
&&
!
TextUtils
.
isEmpty
(
layoutCountryCode
))
{
return
countryCode
.
subSequence
(
0
,
2
).
equals
(
layoutCountryCode
.
substring
(
0
,
2
));
hasLayout
=
countryCode
.
subSequence
(
0
,
2
).
equals
(
layoutCountryCode
.
substring
(
0
,
2
));
}
}
return
false
;
}
catch
(
XmlPullParserException
e
)
{
}
catch
(
XmlPullParserException
e
)
{
return
false
;
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
return
false
;
}
finally
{
conf
.
locale
=
saveLocale
;
res
.
updateConfiguration
(
conf
,
res
.
getDisplayMetrics
());
}
}
conf
.
locale
=
saveLocale
;
res
.
updateConfiguration
(
conf
,
res
.
getDisplayMetrics
());
return
new
Pair
<
Boolean
,
Boolean
>(
hasDictionary
,
hasLayout
);
}
}
private
String
get5Code
(
Locale
locale
)
{
private
String
get5Code
(
Locale
locale
)
{
...
...
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