From ca26f20fa4903de46e374babbfba8c8a1a5cac93 Mon Sep 17 00:00:00 2001
From: satok <satok@google.com>
Date: Thu, 11 Nov 2010 13:37:18 +0900
Subject: [PATCH] Fix states for showing PunctuationList and correction

- Fixed the visibility of the suggestion strip

Change-Id: I63ad561c71464657521661dbd25c72dd34841834
---
 .../android/inputmethod/latin/LatinIME.java   | 25 +++++++++++--------
 .../inputmethod/latin/TextEntryState.java     | 17 +++++++++++--
 2 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index cb50cfb00e..60828c3728 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -667,7 +667,7 @@ public class LatinIME extends InputMethodService
                 mVoiceButtonOnPrimary);
         updateShiftKeyState(attribute);
 
-        setCandidatesViewShownInternal(isCandidateStripVisible() || mCompletionOn,
+        setCandidatesViewShownInternal(isCandidateStripVisible(),
                 false /* needsInputViewShown */ );
         updateSuggestions();
 
@@ -827,7 +827,7 @@ public class LatinIME extends InputMethodService
                         if (mCandidateView != null
                                 && !mSuggestPuncList.equals(mCandidateView.getSuggestions())
                                         && !mCandidateView.isShowingAddToDictionaryHint()) {
-                            setNextSuggestions();
+                            setPunctuationSuggestions();
                         }
                     }
                 }
@@ -1408,6 +1408,8 @@ public class LatinIME extends InputMethodService
 
     private void abortCorrection(boolean force) {
         if (force || TextEntryState.isCorrecting()) {
+            TextEntryState.onAbortCorrection();
+            setCandidatesViewShown(isCandidateStripVisible());
             getCurrentInputConnection().finishComposingText();
             clearSuggestions();
         }
@@ -1598,7 +1600,8 @@ public class LatinIME extends InputMethodService
     }
 
     private boolean isCandidateStripVisible() {
-        return isPredictionOn() && mShowSuggestions;
+        return (isPredictionOn() && mShowSuggestions) || mCompletionOn
+                || mCandidateView.isShowingAddToDictionaryHint() || TextEntryState.isCorrecting();
     }
 
     public void onCancelVoice() {
@@ -1614,7 +1617,7 @@ public class LatinIME extends InputMethodService
               if (mKeyboardSwitcher.getInputView() != null) {
                 setInputView(mKeyboardSwitcher.getInputView());
               }
-              setCandidatesViewShown(true);
+              setCandidatesViewShown(isCandidateStripVisible());
               updateInputViewShown();
               postUpdateSuggestions();
           }});
@@ -1815,7 +1818,7 @@ public class LatinIME extends InputMethodService
         }
 
         if (!mPredicting) {
-            setNextSuggestions();
+            setPunctuationSuggestions();
             return;
         }
         showSuggestions(mWord);
@@ -1883,7 +1886,7 @@ public class LatinIME extends InputMethodService
         } else {
             mBestWord = null;
         }
-        setCandidatesViewShown(isCandidateStripVisible() || mCompletionOn);
+        setCandidatesViewShown(isCandidateStripVisible());
     }
 
     private boolean pickDefaultSuggestion() {
@@ -1977,7 +1980,7 @@ public class LatinIME extends InputMethodService
             // we just did a correction, in which case we need to stay in
             // TextEntryState.State.PICKED_SUGGESTION state.
             TextEntryState.typedCharacter((char) KEYCODE_SPACE, true);
-            setNextSuggestions();
+            setPunctuationSuggestions();
         } else if (!showingAddToDictionaryHint) {
             // If we're not showing the "Touch again to save", then show corrections again.
             // In case the cursor position doesn't change, make sure we show the suggestions again.
@@ -2039,7 +2042,7 @@ public class LatinIME extends InputMethodService
         }
         // If we just corrected a word, then don't show punctuations
         if (!correcting) {
-            setNextSuggestions();
+            setPunctuationSuggestions();
         }
         updateShiftKeyState(getCurrentInputEditorInfo());
     }
@@ -2148,14 +2151,16 @@ public class LatinIME extends InputMethodService
                 ic.endBatchEdit();
             } else {
                 abortCorrection(true);
-                setNextSuggestions();  // Show the punctuation suggestions list
+                setPunctuationSuggestions();  // Show the punctuation suggestions list
             }
         } else {
             abortCorrection(true);
         }
     }
 
-    private void setNextSuggestions() {
+    private void setPunctuationSuggestions() {
+        TextEntryState.onShowPunctuationsList();
+        setCandidatesViewShown(isCandidateStripVisible());
         setSuggestions(mSuggestPuncList, false, false, false);
     }
 
diff --git a/java/src/com/android/inputmethod/latin/TextEntryState.java b/java/src/com/android/inputmethod/latin/TextEntryState.java
index 1d7659ca37..48a7734949 100644
--- a/java/src/com/android/inputmethod/latin/TextEntryState.java
+++ b/java/src/com/android/inputmethod/latin/TextEntryState.java
@@ -62,7 +62,8 @@ public class TextEntryState {
         SPACE_AFTER_PICKED,
         UNDO_COMMIT,
         CORRECTING,
-        PICKED_CORRECTION;
+        PICKED_CORRECTION,
+        SHOWING_PUNCTUATIONS_LIST;
     }
 
     private static State sState = State.UNKNOWN;
@@ -97,7 +98,7 @@ public class TextEntryState {
         }
         try {
             sKeyLocationFile.close();
-            // Write to log file            
+            // Write to log file
             // Write timestamp, settings,
             String out = DateFormat.format("MM:dd hh:mm:ss", Calendar.getInstance().getTime())
                     .toString()
@@ -169,6 +170,18 @@ public class TextEntryState {
         displayState();
     }
 
+    public static void onAbortCorrection() {
+        if (isCorrecting()) {
+            sState = State.START;
+        }
+        displayState();
+    }
+
+    public static void onShowPunctuationsList() {
+        sState = State.SHOWING_PUNCTUATIONS_LIST;
+        displayState();
+    }
+
     public static void typedCharacter(char c, boolean isSeparator) {
         boolean isSpace = c == ' ';
         switch (sState) {
-- 
GitLab