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
18fa4872
Commit
18fa4872
authored
13 years ago
by
Jean Chalard
Committed by
Android (Google) Code Review
13 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Fix crash on adding a word in the user dictionary."
parents
ad2a3bd6
092826c8
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/UserDictionary.java
+26
-14
26 additions, 14 deletions
java/src/com/android/inputmethod/latin/UserDictionary.java
with
26 additions
and
14 deletions
java/src/com/android/inputmethod/latin/UserDictionary.java
+
26
−
14
View file @
18fa4872
...
...
@@ -16,12 +16,14 @@
package
com.android.inputmethod.latin
;
import
android.content.ContentProviderClient
;
import
android.content.ContentResolver
;
import
android.content.ContentValues
;
import
android.content.Context
;
import
android.database.ContentObserver
;
import
android.database.Cursor
;
import
android.net.Uri
;
import
android.os.RemoteException
;
import
android.provider.UserDictionary.Words
;
public
class
UserDictionary
extends
ExpandableDictionary
{
...
...
@@ -99,24 +101,34 @@ public class UserDictionary extends ExpandableDictionary {
values
.
put
(
Words
.
APP_ID
,
0
);
final
ContentResolver
contentResolver
=
getContext
().
getContentResolver
();
final
ContentProviderClient
client
=
contentResolver
.
acquireContentProviderClient
(
Words
.
CONTENT_URI
);
if
(
null
==
client
)
return
;
new
Thread
(
"addWord"
)
{
@Override
public
void
run
()
{
Cursor
cursor
=
contentResolver
.
query
(
Words
.
CONTENT_URI
,
PROJECTION_ADD
,
"word=? and ((locale IS NULL) or (locale=?))"
,
new
String
[]
{
word
,
mLocale
},
null
);
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
())
{
String
locale
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
Words
.
LOCALE
));
// If locale is null, we will not override the entry.
if
(
locale
!=
null
&&
locale
.
equals
(
mLocale
.
toString
()))
{
long
id
=
cursor
.
getLong
(
cursor
.
getColumnIndex
(
Words
.
_ID
));
Uri
uri
=
Uri
.
withAppendedPath
(
Words
.
CONTENT_URI
,
Long
.
toString
(
id
));
// Update the entry with new frequency value.
contentResolver
.
update
(
uri
,
values
,
null
,
null
);
try
{
final
Cursor
cursor
=
client
.
query
(
Words
.
CONTENT_URI
,
PROJECTION_ADD
,
"word=? and ((locale IS NULL) or (locale=?))"
,
new
String
[]
{
word
,
mLocale
},
null
);
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
())
{
final
String
locale
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
Words
.
LOCALE
));
// If locale is null, we will not override the entry.
if
(
locale
!=
null
&&
locale
.
equals
(
mLocale
.
toString
()))
{
final
long
id
=
cursor
.
getLong
(
cursor
.
getColumnIndex
(
Words
.
_ID
));
final
Uri
uri
=
Uri
.
withAppendedPath
(
Words
.
CONTENT_URI
,
Long
.
toString
(
id
));
// Update the entry with new frequency value.
client
.
update
(
uri
,
values
,
null
,
null
);
}
}
else
{
// Insert new entry.
client
.
insert
(
Words
.
CONTENT_URI
,
values
);
}
}
else
{
// Insert new entry.
contentResolver
.
insert
(
Words
.
CONTENT_URI
,
values
);
}
catch
(
RemoteException
e
)
{
// If we come here, the activity is already about to be killed, and we
// have no means of contacting the content provider any more.
// See ContentResolver#insert, inside the catch(){}
}
}
}.
start
();
...
...
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