Remove LatinKeyboard class

Change-Id: I68c667b00dadf2ed9f1c62fb7da37d2cf499cd81
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
index e15ce06..f64ac84 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
@@ -24,6 +24,8 @@
 import android.util.Xml;
 import android.view.inputmethod.EditorInfo;
 
+import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
+import com.android.inputmethod.keyboard.internal.KeyboardParams;
 import com.android.inputmethod.keyboard.internal.XmlParseUtils;
 import com.android.inputmethod.latin.LatinIME;
 import com.android.inputmethod.latin.LatinImeLogger;
@@ -72,8 +74,8 @@
         Params() {}
     }
 
-    private static final HashMap<KeyboardId, SoftReference<LatinKeyboard>> sKeyboardCache =
-            new HashMap<KeyboardId, SoftReference<LatinKeyboard>>();
+    private static final HashMap<KeyboardId, SoftReference<Keyboard>> sKeyboardCache =
+            new HashMap<KeyboardId, SoftReference<Keyboard>>();
 
     public static void clearKeyboardCache() {
         sKeyboardCache.clear();
@@ -84,16 +86,16 @@
         mParams = params;
     }
 
-    public LatinKeyboard getMainKeyboard() {
+    public Keyboard getMainKeyboard() {
         return getKeyboard(false, false);
     }
 
-    public LatinKeyboard getSymbolsKeyboard() {
+    public Keyboard getSymbolsKeyboard() {
         return getKeyboard(true, false);
     }
 
-    public LatinKeyboard getSymbolsShiftedKeyboard() {
-        final LatinKeyboard keyboard = getKeyboard(true, true);
+    public Keyboard getSymbolsShiftedKeyboard() {
+        final Keyboard keyboard = getKeyboard(true, true);
         // TODO: Remove this logic once we introduce initial keyboard shift state attribute.
         // Symbol shift keyboard may have a shift key that has a caps lock style indicator (a.k.a.
         // sticky shift key). To show or dismiss the indicator, we need to call setShiftLocked()
@@ -102,11 +104,11 @@
         return keyboard;
     }
 
-    private LatinKeyboard getKeyboard(boolean isSymbols, boolean isShift) {
+    private Keyboard getKeyboard(boolean isSymbols, boolean isShift) {
         final int elementState = Builder.getElementState(mParams.mMode, isSymbols, isShift);
         final int xmlId = mParams.mElementKeyboards.get(elementState);
         final KeyboardId id = Builder.getKeyboardId(elementState, isSymbols, mParams);
-        final LatinKeyboard keyboard = getKeyboard(mContext, xmlId, id);
+        final Keyboard keyboard = getKeyboard(mContext, xmlId, id);
         return keyboard;
     }
 
@@ -115,15 +117,16 @@
         return Builder.getKeyboardId(elementState, false, mParams);
     }
 
-    private static LatinKeyboard getKeyboard(Context context, int xmlId, KeyboardId id) {
+    private static Keyboard getKeyboard(Context context, int xmlId, KeyboardId id) {
         final Resources res = context.getResources();
         final SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance();
-        final SoftReference<LatinKeyboard> ref = sKeyboardCache.get(id);
-        LatinKeyboard keyboard = (ref == null) ? null : ref.get();
+        final SoftReference<Keyboard> ref = sKeyboardCache.get(id);
+        Keyboard keyboard = (ref == null) ? null : ref.get();
         if (keyboard == null) {
             final Locale savedLocale = LocaleUtils.setSystemLocale(res, id.mLocale);
             try {
-                final LatinKeyboard.Builder builder = new LatinKeyboard.Builder(context);
+                final KeyboardBuilder<KeyboardParams> builder =
+                        new KeyboardBuilder<KeyboardParams>(context, new KeyboardParams());
                 builder.load(xmlId, id);
                 builder.setTouchPositionCorrectionEnabled(
                         subtypeSwitcher.currentSubtypeContainsExtraValueKey(
@@ -132,7 +135,7 @@
             } finally {
                 LocaleUtils.setSystemLocale(res, savedLocale);
             }
-            sKeyboardCache.put(id, new SoftReference<LatinKeyboard>(keyboard));
+            sKeyboardCache.put(id, new SoftReference<Keyboard>(keyboard));
 
             if (DEBUG_CACHE) {
                 Log.d(TAG, "keyboard cache size=" + sKeyboardCache.size() + ": "
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 1625d22..e839fe7 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -171,7 +171,7 @@
     }
 
     public boolean isAlphabetMode() {
-        final Keyboard keyboard = getLatinKeyboard();
+        final Keyboard keyboard = getKeyboard();
         return keyboard != null && keyboard.mId.isAlphabetKeyboard();
     }
 
@@ -180,12 +180,12 @@
     }
 
     public boolean isShiftedOrShiftLocked() {
-        final Keyboard keyboard = getLatinKeyboard();
+        final Keyboard keyboard = getKeyboard();
         return keyboard != null && keyboard.isShiftedOrShiftLocked();
     }
 
     public boolean isManualTemporaryUpperCase() {
-        final Keyboard keyboard = getLatinKeyboard();
+        final Keyboard keyboard = getKeyboard();
         return keyboard != null && keyboard.isManualTemporaryUpperCase();
     }
 
@@ -195,11 +195,9 @@
         return false;
     }
 
-    public LatinKeyboard getLatinKeyboard() {
+    public Keyboard getKeyboard() {
         if (mKeyboardView != null) {
-            final Keyboard keyboard = mKeyboardView.getKeyboard();
-            if (keyboard instanceof LatinKeyboard)
-                return (LatinKeyboard)keyboard;
+            return mKeyboardView.getKeyboard();
         }
         return null;
     }
@@ -208,11 +206,11 @@
     @Override
     public void setShifted(int shiftMode) {
         mInputMethodService.mHandler.cancelUpdateShiftState();
-        LatinKeyboard latinKeyboard = getLatinKeyboard();
-        if (latinKeyboard == null)
+        Keyboard keyboard = getKeyboard();
+        if (keyboard == null)
             return;
         if (shiftMode == AUTOMATIC_SHIFT) {
-            latinKeyboard.setAutomaticTemporaryUpperCase();
+            keyboard.setAutomaticTemporaryUpperCase();
         } else {
             final boolean shifted = (shiftMode == MANUAL_SHIFT);
             // On non-distinct multi touch panel device, we should also turn off the shift locked
@@ -220,9 +218,9 @@
             // On the other hand, on distinct multi touch panel device, turning off the shift
             // locked state with shift key pressing is handled by onReleaseShift().
             if (!hasDistinctMultitouch() && !shifted && mState.isShiftLocked()) {
-                latinKeyboard.setShiftLocked(false);
+                keyboard.setShiftLocked(false);
             }
-            latinKeyboard.setShifted(shifted);
+            keyboard.setShifted(shifted);
         }
         mKeyboardView.invalidateAllKeys();
     }
@@ -231,10 +229,10 @@
     @Override
     public void setShiftLocked(boolean shiftLocked) {
         mInputMethodService.mHandler.cancelUpdateShiftState();
-        LatinKeyboard latinKeyboard = getLatinKeyboard();
-        if (latinKeyboard == null)
+        Keyboard keyboard = getKeyboard();
+        if (keyboard == null)
             return;
-        latinKeyboard.setShiftLocked(shiftLocked);
+        keyboard.setShiftLocked(shiftLocked);
         mKeyboardView.invalidateAllKeys();
         if (!shiftLocked) {
             // To be able to turn off caps lock by "double tap" on shift key, we should ignore
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
deleted file mode 100644
index 54118f4..0000000
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-package com.android.inputmethod.keyboard;
-
-import android.content.Context;
-
-import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
-import com.android.inputmethod.keyboard.internal.KeyboardParams;
-
-// TODO: We should remove this class
-public class LatinKeyboard extends Keyboard {
-    private LatinKeyboard(KeyboardParams params) {
-        super(params);
-    }
-
-    public static class Builder extends KeyboardBuilder<KeyboardParams> {
-        public Builder(Context context) {
-            super(context, new KeyboardParams());
-        }
-
-        @Override
-        public Builder load(int xmlId, KeyboardId id) {
-            super.load(xmlId, id);
-            return this;
-        }
-
-        @Override
-        public LatinKeyboard build() {
-            return new LatinKeyboard(mParams);
-        }
-    }
-
-    @Override
-    public Key[] getNearestKeys(int x, int y) {
-        // Avoid dead pixels at edges of the keyboard
-        return super.getNearestKeys(Math.max(0, Math.min(x, mOccupiedWidth - 1)),
-                Math.max(0, Math.min(y, mOccupiedHeight - 1)));
-    }
-}
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
index 10a544c..aefa50b 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -220,8 +220,7 @@
         @Override
         public boolean onDoubleTap(MotionEvent firstDown) {
             final Keyboard keyboard = getKeyboard();
-            if (ENABLE_CAPSLOCK_BY_DOUBLETAP && keyboard instanceof LatinKeyboard
-                    && ((LatinKeyboard) keyboard).mId.isAlphabetKeyboard()) {
+            if (ENABLE_CAPSLOCK_BY_DOUBLETAP && keyboard.mId.isAlphabetKeyboard()) {
                 final int pointerIndex = firstDown.getActionIndex();
                 final int id = firstDown.getPointerId(pointerIndex);
                 final PointerTracker tracker = getPointerTracker(id);
@@ -452,29 +451,26 @@
     protected boolean onLongPress(Key parentKey, PointerTracker tracker) {
         final int primaryCode = parentKey.mCode;
         final Keyboard keyboard = getKeyboard();
-        if (keyboard instanceof LatinKeyboard) {
-            final LatinKeyboard latinKeyboard = (LatinKeyboard) keyboard;
-            if (primaryCode == Keyboard.CODE_DIGIT0 && latinKeyboard.mId.isPhoneKeyboard()) {
+        if (primaryCode == Keyboard.CODE_DIGIT0 && keyboard.mId.isPhoneKeyboard()) {
+            tracker.onLongPressed();
+            // Long pressing on 0 in phone number keypad gives you a '+'.
+            invokeCodeInput(Keyboard.CODE_PLUS);
+            invokeReleaseKey(primaryCode);
+            return true;
+        }
+        if (primaryCode == Keyboard.CODE_SHIFT && keyboard.mId.isAlphabetKeyboard()) {
+            tracker.onLongPressed();
+            invokeCodeInput(Keyboard.CODE_CAPSLOCK);
+            invokeReleaseKey(primaryCode);
+            return true;
+        }
+        if (primaryCode == Keyboard.CODE_SPACE) {
+            // Long pressing the space key invokes IME switcher dialog.
+            if (invokeCustomRequest(LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) {
                 tracker.onLongPressed();
-                // Long pressing on 0 in phone number keypad gives you a '+'.
-                invokeCodeInput(Keyboard.CODE_PLUS);
                 invokeReleaseKey(primaryCode);
                 return true;
             }
-            if (primaryCode == Keyboard.CODE_SHIFT && latinKeyboard.mId.isAlphabetKeyboard()) {
-                tracker.onLongPressed();
-                invokeCodeInput(Keyboard.CODE_CAPSLOCK);
-                invokeReleaseKey(primaryCode);
-                return true;
-            }
-            if (primaryCode == Keyboard.CODE_SPACE) {
-                // Long pressing the space key invokes IME switcher dialog.
-                if (invokeCustomRequest(LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) {
-                    tracker.onLongPressed();
-                    invokeReleaseKey(primaryCode);
-                    return true;
-                }
-            }
         }
         return openMoreKeysPanel(parentKey, tracker);
     }
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index c868f14..59d394b 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -65,7 +65,6 @@
 import com.android.inputmethod.keyboard.KeyboardId;
 import com.android.inputmethod.keyboard.KeyboardSwitcher;
 import com.android.inputmethod.keyboard.KeyboardView;
-import com.android.inputmethod.keyboard.LatinKeyboard;
 import com.android.inputmethod.keyboard.LatinKeyboardView;
 import com.android.inputmethod.latin.suggestions.SuggestionsView;
 
@@ -293,13 +292,13 @@
             case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR:
                 setSpacebarTextFadeFactor(inputView,
                         (1.0f + mFinalFadeoutFactorOfLanguageOnSpacebar) / 2,
-                        (LatinKeyboard)msg.obj);
+                        (Keyboard)msg.obj);
                 sendMessageDelayed(obtainMessage(MSG_DISMISS_LANGUAGE_ON_SPACEBAR, msg.obj),
                         mDurationOfFadeoutLanguageOnSpacebar);
                 break;
             case MSG_DISMISS_LANGUAGE_ON_SPACEBAR:
                 setSpacebarTextFadeFactor(inputView, mFinalFadeoutFactorOfLanguageOnSpacebar,
-                        (LatinKeyboard)msg.obj);
+                        (Keyboard)msg.obj);
                 break;
             }
         }
@@ -340,10 +339,10 @@
         }
 
         private static void setSpacebarTextFadeFactor(LatinKeyboardView inputView,
-                float fadeFactor, LatinKeyboard oldKeyboard) {
+                float fadeFactor, Keyboard oldKeyboard) {
             if (inputView == null) return;
             final Keyboard keyboard = inputView.getKeyboard();
-            if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) {
+            if (keyboard == oldKeyboard) {
                 inputView.updateSpacebar(fadeFactor,
                         SubtypeSwitcher.getInstance().needsToDisplayLanguage(
                                 keyboard.mId.mLocale));
@@ -356,7 +355,7 @@
             removeMessages(MSG_DISMISS_LANGUAGE_ON_SPACEBAR);
             final LatinKeyboardView inputView = latinIme.mKeyboardSwitcher.getKeyboardView();
             if (inputView != null) {
-                final LatinKeyboard keyboard = latinIme.mKeyboardSwitcher.getLatinKeyboard();
+                final Keyboard keyboard = latinIme.mKeyboardSwitcher.getKeyboard();
                 // The language is always displayed when the delay is negative.
                 final boolean needsToDisplayLanguage = localeChanged
                         || mDelayBeforeFadeoutLanguageOnSpacebar < 0;
@@ -1718,7 +1717,7 @@
         }
         // getSuggestedWordBuilder handles gracefully a null value of prevWord
         final SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(mWordComposer,
-                prevWord, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo(), mCorrectionMode);
+                prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCorrectionMode);
 
         boolean autoCorrectionAvailable = !mInputAttributes.mInputTypeNoAutoCorrect
                 && mSuggest.hasAutoCorrection();
@@ -1867,7 +1866,7 @@
             // pressed space on purpose of displaying the suggestion strip punctuation.
             final int rawPrimaryCode = suggestion.charAt(0);
             // Maybe apply the "bidi mirrored" conversions for parentheses
-            final LatinKeyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
+            final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
             final boolean isRtl = keyboard != null && keyboard.mIsRtlKeyboard;
             final int primaryCode = Key.getRtlParenthesisCode(rawPrimaryCode, isRtl);
 
@@ -1969,7 +1968,7 @@
         final CharSequence prevWord = EditingUtils.getThisWord(getCurrentInputConnection(),
                 mSettingsValues.mWordSeparators);
         SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(sEmptyWordComposer,
-                prevWord, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo(), mCorrectionMode);
+                prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCorrectionMode);
 
         if (builder.size() > 0) {
             // Explicitly supply an empty typed word (the no-second-arg version of
@@ -2095,7 +2094,7 @@
     // "ic" must not be null
     private void restartSuggestionsOnWordBeforeCursor(final InputConnection ic,
             final CharSequence word) {
-        mWordComposer.setComposingWord(word, mKeyboardSwitcher.getLatinKeyboard());
+        mWordComposer.setComposingWord(word, mKeyboardSwitcher.getKeyboard());
         mComposingStateManager.onStartComposingText();
         ic.deleteSurroundingText(word.length(), 0);
         ic.setComposingText(word, 1);
@@ -2436,7 +2435,7 @@
 
         final Printer p = new PrintWriterPrinter(fout);
         p.println("LatinIME state :");
-        final Keyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
+        final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
         final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
         p.println("  Keyboard mode = " + keyboardMode);
         p.println("  mIsSuggestionsRequested=" + mInputAttributes.mIsSettingsSuggestionStripOn);
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index b88e73f..9d6803e 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -16,10 +16,9 @@
 
 package com.android.inputmethod.latin;
 
-import com.android.inputmethod.keyboard.Keyboard;
 import com.android.inputmethod.keyboard.Key;
 import com.android.inputmethod.keyboard.KeyDetector;
-import com.android.inputmethod.keyboard.LatinKeyboard;
+import com.android.inputmethod.keyboard.Keyboard;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -174,7 +173,7 @@
     /**
      * Internal method to retrieve reasonable proximity info for a character.
      */
-    private void addKeyInfo(final int codePoint, final LatinKeyboard keyboard,
+    private void addKeyInfo(final int codePoint, final Keyboard keyboard,
             final KeyDetector keyDetector) {
         for (final Key key : keyboard.mKeys) {
             if (key.mCode == codePoint) {
@@ -194,7 +193,7 @@
      * Set the currently composing word to the one passed as an argument.
      * This will register NOT_A_COORDINATE for X and Ys, and use the passed keyboard for proximity.
      */
-    public void setComposingWord(final CharSequence word, final LatinKeyboard keyboard,
+    public void setComposingWord(final CharSequence word, final Keyboard keyboard,
             final KeyDetector keyDetector) {
         reset();
         final int length = word.length();
@@ -208,7 +207,7 @@
     /**
      * Shortcut for the above method, this will create a new KeyDetector for the passed keyboard.
      */
-    public void setComposingWord(final CharSequence word, final LatinKeyboard keyboard) {
+    public void setComposingWord(final CharSequence word, final Keyboard keyboard) {
         final KeyDetector keyDetector = new KeyDetector(0);
         keyDetector.setKeyboard(keyboard, 0, 0);
         keyDetector.setProximityCorrectionEnabled(true);
diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
index eeabb30..b479ff4 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
@@ -179,7 +179,7 @@
 
         public Builder layout(SuggestedWords suggestions, int fromPos, int maxWidth,
                 int minWidth, int maxRow) {
-            final Keyboard keyboard = KeyboardSwitcher.getInstance().getLatinKeyboard();
+            final Keyboard keyboard = KeyboardSwitcher.getInstance().getKeyboard();
             final int xmlId = R.xml.kbd_suggestions_pane_template;
             load(xmlId, keyboard.mId);
             mParams.mVerticalGap = mParams.mTopPadding = keyboard.mVerticalGap / 2;
diff --git a/tests/src/com/android/inputmethod/latin/SuggestHelper.java b/tests/src/com/android/inputmethod/latin/SuggestHelper.java
index 4d123e5..77496db 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestHelper.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestHelper.java
@@ -20,8 +20,10 @@
 import android.text.TextUtils;
 
 import com.android.inputmethod.keyboard.KeyDetector;
+import com.android.inputmethod.keyboard.Keyboard;
 import com.android.inputmethod.keyboard.KeyboardId;
-import com.android.inputmethod.keyboard.LatinKeyboard;
+import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
+import com.android.inputmethod.keyboard.internal.KeyboardParams;
 
 import java.io.File;
 import java.util.Locale;
@@ -29,7 +31,7 @@
 public class SuggestHelper {
     protected final Suggest mSuggest;
     protected int mCorrectionMode;
-    protected final LatinKeyboard mKeyboard;
+    protected final Keyboard mKeyboard;
     private final KeyDetector mKeyDetector;
 
     public static final int ALPHABET_KEYBOARD = com.android.inputmethod.latin.R.xml.kbd_qwerty;
@@ -38,7 +40,8 @@
         // Use null as the locale for Suggest so as to force it to use the internal dictionary
         // (and not try to find a dictionary provider for a specified locale)
         mSuggest = new Suggest(context, dictionaryId, null);
-        mKeyboard = new LatinKeyboard.Builder(context).load(ALPHABET_KEYBOARD, keyboardId).build();
+        mKeyboard = new KeyboardBuilder<KeyboardParams>(context, new KeyboardParams())
+                .load(ALPHABET_KEYBOARD, keyboardId).build();
         mKeyDetector = new KeyDetector(0);
         init();
     }
@@ -47,7 +50,8 @@
             final long startOffset, final long length, final KeyboardId keyboardId,
             final Locale locale) {
         mSuggest = new Suggest(context, dictionaryPath, startOffset, length, null, locale);
-        mKeyboard = new LatinKeyboard.Builder(context).load(ALPHABET_KEYBOARD, keyboardId).build();
+        mKeyboard = new KeyboardBuilder<KeyboardParams>(context, new KeyboardParams())
+                .load(ALPHABET_KEYBOARD, keyboardId).build();
         mKeyDetector = new KeyDetector(0);
         init();
     }