Log and UI fix

- add Log entry for the setting of auto completion
- fix the parameter names
- reduce the time to commit
- copy popup window's resources from framework
- change extention window to use the current layout

Change-Id: I5f52c41dc8027c28a874ba8f198471eb3c9bdd1e
diff --git a/java/res/drawable-hdpi/btn_close_normal.png b/java/res/drawable-hdpi/btn_close_normal.png
new file mode 100644
index 0000000..38b49f1
--- /dev/null
+++ b/java/res/drawable-hdpi/btn_close_normal.png
Binary files differ
diff --git a/java/res/drawable-hdpi/btn_close_pressed.png b/java/res/drawable-hdpi/btn_close_pressed.png
new file mode 100644
index 0000000..aa9ea49
--- /dev/null
+++ b/java/res/drawable-hdpi/btn_close_pressed.png
Binary files differ
diff --git a/java/res/drawable-hdpi/btn_close_selected.png b/java/res/drawable-hdpi/btn_close_selected.png
new file mode 100644
index 0000000..870c670
--- /dev/null
+++ b/java/res/drawable-hdpi/btn_close_selected.png
Binary files differ
diff --git a/java/res/drawable-hdpi/keyboard_popup_panel_background.9.png b/java/res/drawable-hdpi/keyboard_popup_panel_background.9.png
new file mode 100644
index 0000000..8e2461b
--- /dev/null
+++ b/java/res/drawable-hdpi/keyboard_popup_panel_background.9.png
Binary files differ
diff --git a/java/res/drawable-hdpi/keyboard_popup_panel_trans_background.9.png b/java/res/drawable-hdpi/keyboard_popup_panel_trans_background.9.png
new file mode 100644
index 0000000..fd7366e
--- /dev/null
+++ b/java/res/drawable-hdpi/keyboard_popup_panel_trans_background.9.png
Binary files differ
diff --git a/java/res/drawable-mdpi/btn_close_normal.png b/java/res/drawable-mdpi/btn_close_normal.png
new file mode 100644
index 0000000..4c6e79d
--- /dev/null
+++ b/java/res/drawable-mdpi/btn_close_normal.png
Binary files differ
diff --git a/java/res/drawable-mdpi/btn_close_pressed.png b/java/res/drawable-mdpi/btn_close_pressed.png
new file mode 100644
index 0000000..fc983af
--- /dev/null
+++ b/java/res/drawable-mdpi/btn_close_pressed.png
Binary files differ
diff --git a/java/res/drawable-mdpi/btn_close_selected.png b/java/res/drawable-mdpi/btn_close_selected.png
new file mode 100644
index 0000000..f2bf91a
--- /dev/null
+++ b/java/res/drawable-mdpi/btn_close_selected.png
Binary files differ
diff --git a/java/res/drawable-mdpi/keyboard_popup_panel_background.9.png b/java/res/drawable-mdpi/keyboard_popup_panel_background.9.png
new file mode 100644
index 0000000..36d75df
--- /dev/null
+++ b/java/res/drawable-mdpi/keyboard_popup_panel_background.9.png
Binary files differ
diff --git a/java/res/drawable-mdpi/keyboard_popup_panel_trans_background.9.png b/java/res/drawable-mdpi/keyboard_popup_panel_trans_background.9.png
new file mode 100644
index 0000000..4ba2a49
--- /dev/null
+++ b/java/res/drawable-mdpi/keyboard_popup_panel_trans_background.9.png
Binary files differ
diff --git a/java/res/drawable/btn_close.xml b/java/res/drawable/btn_close.xml
new file mode 100644
index 0000000..ee58138
--- /dev/null
+++ b/java/res/drawable/btn_close.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item android:state_pressed="false" android:state_focused="false"
+        android:drawable="@drawable/btn_close_normal" />
+
+    <item android:state_pressed="true"
+        android:drawable="@drawable/btn_close_pressed" />
+
+    <item android:state_focused="true"
+        android:drawable="@drawable/btn_close_selected" />
+</selector>
diff --git a/java/res/drawable/keyboard_background_2.jpg b/java/res/drawable/keyboard_background_2.jpg
deleted file mode 100644
index 400aa27..0000000
--- a/java/res/drawable/keyboard_background_2.jpg
+++ /dev/null
Binary files differ
diff --git a/java/res/drawable/keyboard_background_3.jpg b/java/res/drawable/keyboard_background_3.jpg
deleted file mode 100644
index 4e64844..0000000
--- a/java/res/drawable/keyboard_background_3.jpg
+++ /dev/null
Binary files differ
diff --git a/java/res/drawable/keyboard_background_4.jpg b/java/res/drawable/keyboard_background_4.jpg
deleted file mode 100755
index 5998f48..0000000
--- a/java/res/drawable/keyboard_background_4.jpg
+++ /dev/null
Binary files differ
diff --git a/java/res/drawable/keyboard_background_4.png b/java/res/drawable/keyboard_background_4.png
new file mode 100644
index 0000000..74fc2e7
--- /dev/null
+++ b/java/res/drawable/keyboard_background_4.png
Binary files differ
diff --git a/java/res/drawable/keyboard_background_5.jpg b/java/res/drawable/keyboard_background_5.jpg
deleted file mode 100644
index 2fe7c5f..0000000
--- a/java/res/drawable/keyboard_background_5.jpg
+++ /dev/null
Binary files differ
diff --git a/java/res/drawable/keyboard_background_5.png b/java/res/drawable/keyboard_background_5.png
new file mode 100644
index 0000000..2e0fb28
--- /dev/null
+++ b/java/res/drawable/keyboard_background_5.png
Binary files differ
diff --git a/java/res/layout/input7.xml b/java/res/layout/input7.xml
index 111d87b..91697b6 100755
--- a/java/res/layout/input7.xml
+++ b/java/res/layout/input7.xml
@@ -29,5 +29,5 @@
         android:keyTextColor="@color/latinkeyboard_key_color_black"
         android:shadowColor="@color/latinkeyboard_key_color_white"
         android:keyTextSize="22dip"
-        />
-<!--         android:keyBackground="@drawable/btn_keyboard_normal_metal"-->
+        android:popupLayout="@layout/input7_popup"
+    />
diff --git a/java/res/layout/input7_popup.xml b/java/res/layout/input7_popup.xml
new file mode 100755
index 0000000..56e2fbd
--- /dev/null
+++ b/java/res/layout/input7_popup.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2010, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<LinearLayout
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        android:background="@drawable/keyboard_popup_panel_background"
+        >
+    <android.inputmethodservice.KeyboardView
+            xmlns:android="http://schemas.android.com/apk/res/android"
+            android:id="@android:id/keyboardView"
+            android:layout_alignParentBottom="true"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:keyBackground="@drawable/btn_keyboard_key_ginger"
+            android:background="@drawable/background_gradient"
+            android:keyTextColor="@color/latinkeyboard_key_color_black"
+            android:shadowColor="@color/latinkeyboard_key_color_white"
+            android:keyTextSize="22dip"
+            android:popupLayout="@layout/input7_popup"
+        />
+    <ImageButton android:id="@android:id/closeButton"
+        android:background="@android:color/transparent"
+        android:src="@drawable/btn_close"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:layout_marginLeft="8dp"
+        android:clickable="true"
+        />
+</LinearLayout>
\ No newline at end of file
diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
index d902619..c8e226d 100644
--- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
@@ -378,6 +378,7 @@
             }
             mInputView = (LatinKeyboardView) mInputMethodService.getLayoutInflater().inflate(
                     LAYOUTS[newLayout], null);
+            mInputView.setExtentionLayoutResId(LAYOUTS[newLayout]);
             mInputView.setOnKeyboardActionListener(mInputMethodService);
             mLayoutId = newLayout;
         }
diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java
index dcd1962..747340e 100644
--- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java
+++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java
@@ -35,18 +35,21 @@
 
     private static final long MINIMUMSENDINTERVAL = 300 * DateUtils.SECOND_IN_MILLIS; // 300 sec
     private static final long MINIMUMCOUNTINTERVAL = 20 * DateUtils.SECOND_IN_MILLIS; // 20 sec
+    private static final long MINIMUMSENDSIZE = 40;
     private static final char SEPARATER = ';';
     private static final int ID_CLICKSUGGESTION = 0;
-    private static final int ID_AUTOSUGGESTION = 1;
-    private static final int ID_AUTOSUGGESTIONCANCELED = 2;
+    private static final int ID_AUTOSUGGESTIONCANCELLED = 1;
+    private static final int ID_AUTOSUGGESTION = 2;
     private static final int ID_INPUT_COUNT = 3;
     private static final int ID_DELETE_COUNT = 4;
     private static final int ID_WORD_COUNT = 5;
     private static final int ID_ACTUAL_CHAR_COUNT = 6;
     private static final int ID_THEME_ID = 7;
+    private static final int ID_SETTING_AUTO_COMPLETE = 8;
 
     private static final String PREF_ENABLE_LOG = "enable_logging";
     private static final String PREF_DEBUG_MODE = "debug_mode";
+    private static final String PREF_AUTO_COMPLETE = "auto_complete";
 
     public static boolean sLogEnabled = true;
     private static LatinImeLogger sLatinImeLogger = new LatinImeLogger();
@@ -132,12 +135,7 @@
         if (sDBG) {
             Log.d(TAG, "Check String safety: " + s);
         }
-        for (int i = 0; i < s.length(); ++i) {
-            if (!Character.isDigit(s.charAt(i))) {
-                return true;
-            }
-        }
-        return false;
+        return !TextUtils.isDigitsOnly(s);
     }
 
     private void addCountEntry(long time) {
@@ -167,6 +165,16 @@
                 new String[] {mThemeId}));
     }
 
+    private void addSettingsEntry(long time) {
+        if (sDBG) {
+            Log.d(TAG, "Log settings. (1)");
+        }
+        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
+        mLogBuffer.add(new LogEntry (time, ID_SETTING_AUTO_COMPLETE,
+                new String[] {String.valueOf(prefs.getBoolean(PREF_AUTO_COMPLETE,
+                        mContext.getResources().getBoolean(R.bool.enable_autocorrect)))}));
+    }
+
     private void flushPrivacyLogSafely() {
         if (sDBG) {
             Log.d(TAG, "Log theme Id. (" + mPrivacyLogBuffer.size() + ")");
@@ -191,7 +199,6 @@
                 if (((mLastTimeActive - mLastTimeCountEntry) > MINIMUMCOUNTINTERVAL)
                         || (mDeleteCount == 0 && mInputCount == 0)) {
                     addCountEntry(mLastTimeActive);
-                    addThemeIdEntry(mLastTimeActive);
                 }
                 mDeleteCount += (Integer)data;
                 break;
@@ -199,7 +206,6 @@
                 if (((mLastTimeActive - mLastTimeCountEntry) > MINIMUMCOUNTINTERVAL)
                         || (mDeleteCount == 0 && mInputCount == 0)) {
                     addCountEntry(mLastTimeActive);
-                    addThemeIdEntry(mLastTimeActive);
                 }
                 mInputCount += (Integer)data;
                 break;
@@ -223,7 +229,7 @@
                     }
                 }
                 break;
-            case ID_AUTOSUGGESTIONCANCELED:
+            case ID_AUTOSUGGESTIONCANCELLED:
                 --mWordCount;
                 dataStrings = (String[]) data;
                 if (dataStrings.length < 2) {
@@ -258,6 +264,7 @@
         long now = System.currentTimeMillis();
         addCountEntry(now);
         addThemeIdEntry(now);
+        addSettingsEntry(now);
         String s = LogSerializer.createStringFromEntries(mLogBuffer);
         if (!TextUtils.isEmpty(s)) {
             if (sDBG) {
@@ -307,6 +314,7 @@
         } else if (KeyboardSwitcher.PREF_KEYBOARD_LAYOUT.equals(key)) {
             mThemeId = sharedPreferences.getString(KeyboardSwitcher.PREF_KEYBOARD_LAYOUT,
                     KeyboardSwitcher.DEFAULT_LAYOUT_ID);
+            addThemeIdEntry(mLastTimeActive);
         } else if (PREF_DEBUG_MODE.equals(key)) {
             sDBG = sharedPreferences.getBoolean(PREF_DEBUG_MODE, sDBG);
         }
@@ -318,7 +326,11 @@
 
     public static void commit() {
         if (sLogEnabled) {
-            sLatinImeLogger.commitInternal();
+            if (System.currentTimeMillis() - sLatinImeLogger.mLastTimeActive > MINIMUMCOUNTINTERVAL
+                        || (sLatinImeLogger.mLogBuffer.size()
+                                + sLatinImeLogger.mPrivacyLogBuffer.size() > MINIMUMSENDSIZE)) {
+                sLatinImeLogger.commitInternal();
+            }
         }
     }
 
@@ -337,7 +349,7 @@
                 sLastAutoSuggestBefore = before;
                 sLastAutoSuggestAfter = after;
             }
-            sLatinImeLogger.sendLogToDropBox(ID_AUTOSUGGESTIONCANCELED, strings);
+            sLatinImeLogger.sendLogToDropBox(ID_AUTOSUGGESTION, strings);
         }
     }
 
@@ -345,7 +357,7 @@
         if (sLogEnabled) {
             if (sLastAutoSuggestBefore != null && sLastAutoSuggestAfter != null) {
                 String[] strings = new String[] {sLastAutoSuggestBefore, sLastAutoSuggestAfter};
-                sLatinImeLogger.sendLogToDropBox(ID_AUTOSUGGESTION, strings);
+                sLatinImeLogger.sendLogToDropBox(ID_AUTOSUGGESTIONCANCELLED, strings);
             }
         }
     }
diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
index 323f4bf..6e3226a 100644
--- a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
@@ -65,6 +65,8 @@
     /** The y coordinate of the last row */
     private int mLastRowY;
 
+    private int mExtensionLayoutResId = 0;
+
     public LatinKeyboardView(Context context, AttributeSet attrs) {
         super(context, attrs);
     }
@@ -77,6 +79,10 @@
         mPhoneKeyboard = phoneKeyboard;
     }
 
+    public void setExtentionLayoutResId (int id) {
+        mExtensionLayoutResId = id;
+    }
+
     @Override
     public void setKeyboard(Keyboard k) {
         super.setKeyboard(k);
@@ -294,7 +300,8 @@
             mExtensionPopup.setBackgroundDrawable(null);
             LayoutInflater li = (LayoutInflater) getContext().getSystemService(
                     Context.LAYOUT_INFLATER_SERVICE);
-            mExtension = (LatinKeyboardView) li.inflate(R.layout.input_trans, null);
+            mExtension = (LatinKeyboardView) li.inflate(mExtensionLayoutResId == 0 ?
+                    R.layout.input_trans : mExtensionLayoutResId, null);
             mExtension.setExtensionType(true);
             mExtension.setOnKeyboardActionListener(
                     new ExtensionKeyboardListener(getOnKeyboardActionListener()));