Merge "Introduce CandidateView.Listener"
This commit is contained in:
commit
91b9a6808c
2 changed files with 16 additions and 8 deletions
|
@ -49,6 +49,11 @@ import java.util.List;
|
||||||
|
|
||||||
public class CandidateView extends LinearLayout implements OnClickListener, OnLongClickListener {
|
public class CandidateView extends LinearLayout implements OnClickListener, OnLongClickListener {
|
||||||
|
|
||||||
|
public interface Listener {
|
||||||
|
public boolean addWordToDictionary(String word);
|
||||||
|
public void pickSuggestionManually(int index, CharSequence word);
|
||||||
|
}
|
||||||
|
|
||||||
private static final CharacterStyle BOLD_SPAN = new StyleSpan(Typeface.BOLD);
|
private static final CharacterStyle BOLD_SPAN = new StyleSpan(Typeface.BOLD);
|
||||||
private static final CharacterStyle UNDERLINE_SPAN = new UnderlineSpan();
|
private static final CharacterStyle UNDERLINE_SPAN = new UnderlineSpan();
|
||||||
private static final int MAX_SUGGESTIONS = 16;
|
private static final int MAX_SUGGESTIONS = 16;
|
||||||
|
@ -67,7 +72,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
||||||
private final PopupWindow mPreviewPopup;
|
private final PopupWindow mPreviewPopup;
|
||||||
private final TextView mPreviewText;
|
private final TextView mPreviewText;
|
||||||
|
|
||||||
private LatinIME mService;
|
private Listener mListener;
|
||||||
private SuggestedWords mSuggestions = SuggestedWords.EMPTY;
|
private SuggestedWords mSuggestions = SuggestedWords.EMPTY;
|
||||||
private boolean mShowingAutoCorrectionInverted;
|
private boolean mShowingAutoCorrectionInverted;
|
||||||
private boolean mShowingAddToDictionary;
|
private boolean mShowingAddToDictionary;
|
||||||
|
@ -160,11 +165,11 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A connection back to the service to communicate with the text field
|
* A connection back to the input method.
|
||||||
* @param listener
|
* @param listener
|
||||||
*/
|
*/
|
||||||
public void setService(LatinIME listener) {
|
public void setListener(Listener listener) {
|
||||||
mService = listener;
|
mListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSuggestions(SuggestedWords suggestions) {
|
public void setSuggestions(SuggestedWords suggestions) {
|
||||||
|
@ -337,7 +342,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToDictionary(CharSequence word) {
|
private void addToDictionary(CharSequence word) {
|
||||||
if (mService.addWordToDictionary(word.toString())) {
|
if (mListener.addWordToDictionary(word.toString())) {
|
||||||
showPreview(0, getContext().getString(R.string.added_word, word));
|
showPreview(0, getContext().getString(R.string.added_word, word));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -359,7 +364,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
||||||
if (mShowingAddToDictionary && index == 0) {
|
if (mShowingAddToDictionary && index == 0) {
|
||||||
addToDictionary(word);
|
addToDictionary(word);
|
||||||
} else {
|
} else {
|
||||||
mService.pickSuggestionManually(index, word);
|
mListener.pickSuggestionManually(index, word);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,8 @@ import java.util.Locale;
|
||||||
/**
|
/**
|
||||||
* Input method implementation for Qwerty'ish keyboard.
|
* Input method implementation for Qwerty'ish keyboard.
|
||||||
*/
|
*/
|
||||||
public class LatinIME extends InputMethodServiceCompatWrapper implements KeyboardActionListener {
|
public class LatinIME extends InputMethodServiceCompatWrapper implements KeyboardActionListener,
|
||||||
|
CandidateView.Listener {
|
||||||
private static final String TAG = LatinIME.class.getSimpleName();
|
private static final String TAG = LatinIME.class.getSimpleName();
|
||||||
private static final boolean PERF_DEBUG = false;
|
private static final boolean PERF_DEBUG = false;
|
||||||
private static final boolean TRACE = false;
|
private static final boolean TRACE = false;
|
||||||
|
@ -491,7 +492,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
super.setInputView(view);
|
super.setInputView(view);
|
||||||
mCandidateViewContainer = view.findViewById(R.id.candidates_container);
|
mCandidateViewContainer = view.findViewById(R.id.candidates_container);
|
||||||
mCandidateView = (CandidateView) view.findViewById(R.id.candidates);
|
mCandidateView = (CandidateView) view.findViewById(R.id.candidates);
|
||||||
mCandidateView.setService(this);
|
mCandidateView.setListener(this);
|
||||||
mCandidateStripHeight = (int)mResources.getDimension(R.dimen.candidate_strip_height);
|
mCandidateStripHeight = (int)mResources.getDimension(R.dimen.candidate_strip_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1000,6 +1001,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean addWordToDictionary(String word) {
|
public boolean addWordToDictionary(String word) {
|
||||||
mUserDictionary.addWord(word, 128);
|
mUserDictionary.addWord(word, 128);
|
||||||
// Suggestion strip should be updated after the operation of adding word to the
|
// Suggestion strip should be updated after the operation of adding word to the
|
||||||
|
@ -1523,6 +1525,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void pickSuggestionManually(int index, CharSequence suggestion) {
|
public void pickSuggestionManually(int index, CharSequence suggestion) {
|
||||||
SuggestedWords suggestions = mCandidateView.getSuggestions();
|
SuggestedWords suggestions = mCandidateView.getSuggestions();
|
||||||
mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion,
|
mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion,
|
||||||
|
|
Loading…
Reference in a new issue