Merge "Check user dictionary is enabled before showing touch-to-save"
commit
60c8eba634
|
@ -151,6 +151,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
private UserDictionary mUserDictionary;
|
private UserDictionary mUserDictionary;
|
||||||
private UserBigramDictionary mUserBigramDictionary;
|
private UserBigramDictionary mUserBigramDictionary;
|
||||||
private UserUnigramDictionary mUserUnigramDictionary;
|
private UserUnigramDictionary mUserUnigramDictionary;
|
||||||
|
private boolean mIsUserDictionaryAvaliable;
|
||||||
|
|
||||||
// TODO: Create an inner class to group options and pseudo-options to improve readability.
|
// TODO: Create an inner class to group options and pseudo-options to improve readability.
|
||||||
// These variables are initialized according to the {@link EditorInfo#inputType}.
|
// These variables are initialized according to the {@link EditorInfo#inputType}.
|
||||||
|
@ -436,6 +437,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
|
|
||||||
mUserDictionary = new UserDictionary(this, localeStr);
|
mUserDictionary = new UserDictionary(this, localeStr);
|
||||||
mSuggest.setUserDictionary(mUserDictionary);
|
mSuggest.setUserDictionary(mUserDictionary);
|
||||||
|
mIsUserDictionaryAvaliable = mUserDictionary.isEnabled();
|
||||||
|
|
||||||
resetContactsDictionary();
|
resetContactsDictionary();
|
||||||
|
|
||||||
|
@ -1691,7 +1693,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
// take a noticeable delay to update them which may feel uneasy.
|
// take a noticeable delay to update them which may feel uneasy.
|
||||||
}
|
}
|
||||||
if (showingAddToDictionaryHint) {
|
if (showingAddToDictionaryHint) {
|
||||||
mCandidateView.showAddToDictionaryHint(suggestion);
|
if (mIsUserDictionaryAvaliable) {
|
||||||
|
mCandidateView.showAddToDictionaryHint(suggestion);
|
||||||
|
} else {
|
||||||
|
mHandler.postUpdateSuggestions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ic != null) {
|
if (ic != null) {
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
|
|
|
@ -38,23 +38,24 @@ public class UserDictionary extends ExpandableDictionary {
|
||||||
Words.FREQUENCY,
|
Words.FREQUENCY,
|
||||||
Words.LOCALE,
|
Words.LOCALE,
|
||||||
};
|
};
|
||||||
|
|
||||||
private ContentObserver mObserver;
|
private ContentObserver mObserver;
|
||||||
private String mLocale;
|
private String mLocale;
|
||||||
|
|
||||||
public UserDictionary(Context context, String locale) {
|
public UserDictionary(Context context, String locale) {
|
||||||
super(context, Suggest.DIC_USER);
|
super(context, Suggest.DIC_USER);
|
||||||
mLocale = locale;
|
mLocale = locale;
|
||||||
// Perform a managed query. The Activity will handle closing and requerying the cursor
|
// Perform a managed query. The Activity will handle closing and re-querying the cursor
|
||||||
// when needed.
|
// when needed.
|
||||||
ContentResolver cres = context.getContentResolver();
|
ContentResolver cres = context.getContentResolver();
|
||||||
|
|
||||||
cres.registerContentObserver(Words.CONTENT_URI, true, mObserver = new ContentObserver(null) {
|
mObserver = new ContentObserver(null) {
|
||||||
@Override
|
@Override
|
||||||
public void onChange(boolean self) {
|
public void onChange(boolean self) {
|
||||||
setRequiresReload(true);
|
setRequiresReload(true);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
cres.registerContentObserver(Words.CONTENT_URI, true, mObserver);
|
||||||
|
|
||||||
loadDictionary();
|
loadDictionary();
|
||||||
}
|
}
|
||||||
|
@ -76,6 +77,17 @@ public class UserDictionary extends ExpandableDictionary {
|
||||||
addWords(cursor);
|
addWords(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
final ContentResolver cr = getContext().getContentResolver();
|
||||||
|
final ContentProviderClient client = cr.acquireContentProviderClient(Words.CONTENT_URI);
|
||||||
|
if (client != null) {
|
||||||
|
client.release();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a word to the dictionary and makes it persistent.
|
* Adds a word to the dictionary and makes it persistent.
|
||||||
* @param word the word to add. If the word is capitalized, then the dictionary will
|
* @param word the word to add. If the word is capitalized, then the dictionary will
|
||||||
|
|
Loading…
Reference in New Issue