Remove LatinKeyboardBaseView.isShifted() and setShifted() for refactoring

Change-Id: I9a1106b679a9ffb3ae959d90377eef096e5af842
main
Ken Wakasa 2010-10-25 18:34:19 +09:00
parent 55952c9868
commit 29ff343f77
3 changed files with 42 additions and 42 deletions

View File

@ -392,7 +392,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
public void setShifted(boolean shifted) {
if (mInputView != null) {
mInputView.setShifted(shifted);
LatinKeyboard latinKeyboard = mInputView.getLatinKeyboard();
if (latinKeyboard != null && latinKeyboard.setShifted(shifted)) {
mInputView.invalidateAllKeys();
}
}
}

View File

@ -993,7 +993,8 @@ public class LatinIME extends InputMethodService
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
// Enable shift key and DPAD to do selections
if (inputView != null && inputView.isShown()
&& inputView.isShifted()) {
&& inputView.getLatinKeyboard() != null
&& inputView.getLatinKeyboard().isShifted()) {
event = new KeyEvent(event.getDownTime(), event.getEventTime(),
event.getAction(), event.getKeyCode(), event.getRepeatCount(),
event.getDeviceId(), event.getScanCode(),
@ -1372,7 +1373,10 @@ public class LatinIME extends InputMethodService
mCapsLock = false;
switcher.setShifted(false);
} else if (inputView != null) {
switcher.setShifted(!inputView.isShifted());
LatinKeyboard latinKeyboard = inputView.getLatinKeyboard();
if (latinKeyboard != null) {
switcher.setShifted(!latinKeyboard.isShifted());
}
}
} else {
switcher.toggleShift();
@ -1425,7 +1429,8 @@ public class LatinIME extends InputMethodService
mWord.reset();
}
}
if (mKeyboardSwitcher.getInputView().isShifted()) {
LatinKeyboard latinKeyboard = mKeyboardSwitcher.getInputView().getLatinKeyboard();
if (latinKeyboard != null && latinKeyboard.isShifted()) {
if (keyCodes == null || keyCodes[0] < Character.MIN_CODE_POINT
|| keyCodes[0] > Character.MAX_CODE_POINT) {
return;
@ -1444,7 +1449,7 @@ public class LatinIME extends InputMethodService
}
}
if (mPredicting) {
if (mKeyboardSwitcher.getInputView().isShifted()
if (latinKeyboard != null && latinKeyboard.isShifted()
&& mKeyboardSwitcher.isAlphabetMode()
&& mComposing.length() == 0) {
mWord.setFirstCharCapitalized(true);
@ -1739,7 +1744,8 @@ public class LatinIME extends InputMethodService
final List<CharSequence> nBest = new ArrayList<CharSequence>();
boolean capitalizeFirstWord = preferCapitalization()
|| (mKeyboardSwitcher.isAlphabetMode()
&& mKeyboardSwitcher.getInputView().isShifted());
&& mKeyboardSwitcher.getInputView().getLatinKeyboard() != null
&& mKeyboardSwitcher.getInputView().getLatinKeyboard().isShifted());
for (String c : mVoiceResults.candidates) {
if (capitalizeFirstWord) {
c = Character.toUpperCase(c.charAt(0)) + c.substring(1, c.length());
@ -1791,7 +1797,10 @@ public class LatinIME extends InputMethodService
private void updateSuggestions() {
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
inputView.getLatinKeyboard().setPreferredLetters(null);
LatinKeyboard latinKeyboard = inputView.getLatinKeyboard();
if (latinKeyboard != null) {
latinKeyboard.setPreferredLetters(null);
}
// Check if we have a suggestion engine attached.
if ((mSuggest == null || !isPredictionOn()) && !mVoiceInputHighlighted) {
@ -1813,7 +1822,10 @@ public class LatinIME extends InputMethodService
private void showCorrections(WordAlternatives alternatives) {
List<CharSequence> stringList = alternatives.getAlternatives();
mKeyboardSwitcher.getInputView().getLatinKeyboard().setPreferredLetters(null);
LatinKeyboard latinKeyboard = mKeyboardSwitcher.getInputView().getLatinKeyboard();
if (latinKeyboard != null) {
latinKeyboard.setPreferredLetters(null);
}
showSuggestions(stringList, alternatives.getOriginalWord(), false, false);
}
@ -1829,8 +1841,10 @@ public class LatinIME extends InputMethodService
int[] nextLettersFrequencies = mSuggest.getNextLettersFrequencies();
mKeyboardSwitcher.getInputView().getLatinKeyboard().setPreferredLetters(
nextLettersFrequencies);
LatinKeyboard latinKeyboard = mKeyboardSwitcher.getInputView().getLatinKeyboard();
if (latinKeyboard != null) {
latinKeyboard.setPreferredLetters(nextLettersFrequencies);
}
boolean correctionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasMinimalCorrection();
//|| mCorrectionMode == mSuggest.CORRECTION_FULL;
@ -2002,11 +2016,12 @@ public class LatinIME extends InputMethodService
*/
private void pickSuggestion(CharSequence suggestion, boolean correcting) {
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
LatinKeyboard latinKeyboard = inputView.getLatinKeyboard();
if (mCapsLock) {
suggestion = suggestion.toString().toUpperCase();
} else if (preferCapitalization()
|| (mKeyboardSwitcher.isAlphabetMode()
&& inputView.isShifted())) {
&& latinKeyboard != null && latinKeyboard.isShifted())) {
suggestion = suggestion.toString().toUpperCase().charAt(0)
+ suggestion.subSequence(1, suggestion.length()).toString();
}
@ -2018,7 +2033,9 @@ public class LatinIME extends InputMethodService
saveWordInHistory(suggestion);
mPredicting = false;
mCommittedLength = suggestion.length();
inputView.getLatinKeyboard().setPreferredLetters(null);
if (latinKeyboard != null) {
latinKeyboard.setPreferredLetters(null);
}
// If we just corrected a word, then don't show punctuations
if (!correcting) {
setNextSuggestions();
@ -2321,7 +2338,10 @@ public class LatinIME extends InputMethodService
public void onRelease(int primaryCode) {
// Reset any drag flags in the keyboard
mKeyboardSwitcher.getInputView().getLatinKeyboard().keyReleased();
LatinKeyboard latinKeyboard = mKeyboardSwitcher.getInputView().getLatinKeyboard();
if (latinKeyboard != null) {
latinKeyboard.keyReleased();
}
//vibrate();
final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch();
if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_SHIFT) {

View File

@ -638,34 +638,6 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
return mHasDistinctMultitouch;
}
/**
* Sets the state of the shift key of the keyboard, if any.
* @param shifted whether or not to enable the state of the shift key
* @return true if the shift key state changed, false if there was no change
*/
public boolean setShifted(boolean shifted) {
if (mKeyboard != null) {
if (mKeyboard.setShifted(shifted)) {
// The whole keyboard probably needs to be redrawn
invalidateAllKeys();
return true;
}
}
return false;
}
/**
* Returns the state of the shift key of the keyboard, if any.
* @return true if the shift is in a pressed state, false otherwise. If there is
* no shift key on the keyboard or there is no keyboard attached, it returns false.
*/
public boolean isShifted() {
if (mKeyboard != null) {
return mKeyboard.isShifted();
}
return false;
}
/**
* Enables or disables the key feedback popup. This is a popup that shows a magnified
* version of the depressed key. By default the preview is enabled.
@ -1247,7 +1219,12 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
mMiniKeyboardOriginX = adjustedX + container.getPaddingLeft() - mWindowOffset[0];
mMiniKeyboardOriginY = y + container.getPaddingTop() - mWindowOffset[1];
mMiniKeyboard.setPopupOffset(adjustedX, y);
mMiniKeyboard.setShifted(isShifted());
// TODO: change the below line to use getLatinKeyboard() instead of getKeyboard()
BaseKeyboard baseMiniKeyboard = mMiniKeyboard.getKeyboard();
if (baseMiniKeyboard != null && baseMiniKeyboard.setShifted(mKeyboard == null
? false : mKeyboard.isShifted())) {
mMiniKeyboard.invalidateAllKeys();
}
// Mini keyboard needs no pop-up key preview displayed.
mMiniKeyboard.setPreviewEnabled(false);
mMiniKeyboardPopup.setContentView(container);