OSDN Git Service

フリック動作の検証終了。各モードの変換テーブル要設定
[nicownn/NicoWnn.git] / src / com / hiroshica / android / input / nicownn2 / DefaultSoftKeyboard.java
index b360cf2..e5c4cd2 100644 (file)
@@ -33,9 +33,11 @@ import android.content.Context;
 import android.view.GestureDetector;
 import android.view.GestureDetector.OnGestureListener;
 import android.util.DisplayMetrics;
-import java.lang.Math;
 import android.util.FloatMath;
 
+import java.lang.Math;
+import java.util.HashMap;
+
 import android.util.Log;
 
 
@@ -167,16 +169,39 @@ public class DefaultSoftKeyboard implements InputViewManager, KeyboardView.OnKey
        /** Input restraint */
        protected boolean mDisableKeyInput = true;
 
-       /** flick mode **/
-       protected boolean mIsEnableFlick   = false;
-       protected boolean mIsHookFlick     = false;
-       protected int     mStockFlickCode;
+       /**
+        * flick mode works
+        */
+       public boolean mNicoFirst = false;
+
+       /** Previous input character code */
+       public int mPrevInputKeyCode = 0;
 
+       /** flick nicoinput **/
+       public static final int NICOFLICK_NONE       = 0;
+       public static final int NICOFLICK_1STROKE    = 1;
+       public static final int NICOFLICK_NICOSTROKE = 2;
+       
+       public int mFlickNicoInput = 0;
+       public boolean mNicoFlick = false;
+       public static final HashMap<String, Integer> flickModeTable = new HashMap<String, Integer>() {
+               /**
+                * 
+                */
+               private static final long serialVersionUID = 1L;
+               {
+                       put("none_flick", 0);
+                       put("normal_stroke", 1);
+                       put("nico_stroke", 2);
+               }};
+       
        /** gecture  **/
        private static final DisplayMetrics mMetrics = new DisplayMetrics();
-       GestureDetector   mDetector;
-       float             mStartX, mStartY;
-       float             mGestureX, mGestureY;
+       private GestureDetector   mDetector;
+       private float             mStartX, mStartY;
+       private float             mGestureX, mGestureY;
+       private static final int ya_flick[] = { 0, 2, -1, 1, -1 };
+       private static final int wa_flick[] = { 0, -1, 1, 2, 5 };
 
        /**
         * Keyboard surfaces 
@@ -607,9 +632,9 @@ public class DefaultSoftKeyboard implements InputViewManager, KeyboardView.OnKey
                createKeyboards(parent);
 
                SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(parent);
-               String skin = pref.getString("keyboard_skin",
-                                                                        mWnn.getResources().getString(R.string.keyboard_skin_id_default));
+               String skin = pref.getString("keyboard_skin", mWnn.getResources().getString(R.string.keyboard_skin_id_default));
                int id = parent.getResources().getIdentifier(skin, "layout", "com.hiroshica.android.input.nicownn2");
+               mFlickNicoInput        = flickModeTable.get(pref.getString("nicoflick_mode", "none_flick"));
 
                mKeyboardView = (KeyboardView) mWnn.getLayoutInflater().inflate(id, null);
                mKeyboardView.setOnKeyboardActionListener(this);
@@ -728,7 +753,6 @@ public class DefaultSoftKeyboard implements InputViewManager, KeyboardView.OnKey
                                if (!mNoInput) {
                                        /* when the mode changed to "no input" */
                                        mNoInput = true;
-                                       mIsHookFlick = false;
                                        Keyboard newKeyboard = getKeyboardInputed(false);
                                        if (mCurrentKeyboard != newKeyboard) {
                                                changeKeyboard(newKeyboard);
@@ -772,6 +796,7 @@ public class DefaultSoftKeyboard implements InputViewManager, KeyboardView.OnKey
                } catch (Exception ex) {
                        Log.d("NicoWnn", "NO SOUND");
                }
+               mFlickNicoInput        = flickModeTable.get(pref.getString("nicoflick_mode", "none_flick"));
 
                /* pop-up preview */
                mKeyboardView.setPreviewEnabled(pref.getBoolean("popup_preview", true));
@@ -793,19 +818,15 @@ public class DefaultSoftKeyboard implements InputViewManager, KeyboardView.OnKey
 
        /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#swipeRight */
        public void swipeRight() {
-               mIsHookFlick = false;
        }
        /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#swipeLeft */
        public void swipeLeft() {
-               mIsHookFlick = false;
        }
        /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#swipeDown */
        public void swipeDown() {
-               mIsHookFlick = false;
        }
        /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#swipeUp */
        public void swipeUp() {
-               mIsHookFlick = false;
        }
        /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#onRelease */
        public void onRelease(int primaryCode) {
@@ -814,16 +835,16 @@ public class DefaultSoftKeyboard implements InputViewManager, KeyboardView.OnKey
        /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#onPress */
        public void onPress(int primaryCode) {
                /* key click sound & vibration */
-               if (true == mIsEnableFlick) {
-                       mIsHookFlick = true;
-               }
-
                if (mVibrator != null) {
                        try { mVibrator.vibrate(30); } catch (Exception ex) { }
                }
                if (mSound != null) {
                        try { mSound.seekTo(0); mSound.start(); } catch (Exception ex) { }
                }
+               // check flick
+               if (false == mNicoFirst) {
+                       mPrevInputKeyCode = primaryCode;
+               }
        }
     
        /** @see android.inputmethodservice.KeyboardView.OnKeyboardActionListener#onText */
@@ -932,7 +953,7 @@ public class DefaultSoftKeyboard implements InputViewManager, KeyboardView.OnKey
                mStartY = ev.getRawY();
                mGestureX = mStartX;
                mGestureY = mStartY;
-               Log.d("NicoWnn", "onDown " + mStartX + "/" + mStartY);
+               //Log.d("NicoWnn", "onDown " + mStartX + "/" + mStartY);
                return true;
        }
        public boolean onFling(MotionEvent ev1, MotionEvent ev2, float getX, float getY){
@@ -943,7 +964,7 @@ public class DefaultSoftKeyboard implements InputViewManager, KeyboardView.OnKey
        public boolean onScroll(MotionEvent ev1, MotionEvent ev2, float distX, float distY){
                mGestureX = ev2.getRawX();
                mGestureY = ev2.getRawY();
-               Log.d("NicoWnn", "get " + (mGestureX - mStartX) + "/" + (mGestureY - mStartY));
+               //Log.d("NicoWnn", "get " + (mGestureX - mStartX) + "/" + (mGestureY - mStartY));
                return true;
        }
        public void    onShowPress(MotionEvent ev){
@@ -954,9 +975,19 @@ public class DefaultSoftKeyboard implements InputViewManager, KeyboardView.OnKey
        /**
         * calc. flick keycode
         */
-       public int checkFlickKeyCode(boolean checkFlick, int prevkeycode) {
-               int retcode = -1;
-
+       public int checkFlickKeyCode() {
+               if (NICOFLICK_NONE == mFlickNicoInput) {
+                       return -1;
+               }
+               if (mCurrentKeyMode != KEYMODE_JA_FULL_NICO) {
+                       return -1;
+               }
+               if (true == mNicoFirst) {
+                       return -1;
+               }
+               /**
+                * creation flick keys
+                */
                float calcx, calcy;
                calcx = (mGestureX - mStartX) * mMetrics.scaledDensity;
                calcy = (mGestureY - mStartY) * mMetrics.scaledDensity;
@@ -971,7 +1002,8 @@ public class DefaultSoftKeyboard implements InputViewManager, KeyboardView.OnKey
                // change rotate -> keycode
                int keycode = -1;
                if (length < 30.0) {
-                       keycode = 0;
+                       //keycode = 0;
+                       keycode = -1;
                }
                else {
                        if (getrot >= 45.0f && getrot < 135.0f) {
@@ -986,25 +1018,26 @@ public class DefaultSoftKeyboard implements InputViewManager, KeyboardView.OnKey
                        else {
                                keycode = 4;
                        }
+                       // convert keycode
+                       switch (mPrevInputKeyCode) {
+                       case KEYCODE_JP12_1:    // A
+                       case KEYCODE_JP12_2:    // Ka
+                       case KEYCODE_JP12_3:    // Sa
+                       case KEYCODE_JP12_4:    // Ta
+                       case KEYCODE_JP12_5:    // Na
+                       case KEYCODE_JP12_6:    // Ha
+                       case KEYCODE_JP12_7:    // Ma
+                       case KEYCODE_JP12_9:    // Ra
+                               break;
+                       case KEYCODE_JP12_8:    // Ya
+                               keycode = ya_flick[keycode];
+                               break;
+                       case KEYCODE_JP12_0:    // Wa
+                               keycode = wa_flick[keycode];
+                               break;
+                       }
                }
-               // convert keycode
-               switch (prevkeycode) {
-               case KEYCODE_JP12_1:
-               case KEYCODE_JP12_2:
-               case KEYCODE_JP12_3:
-               case KEYCODE_JP12_4:
-               case KEYCODE_JP12_5:
-               case KEYCODE_JP12_6:
-               case KEYCODE_JP12_7:
-               case KEYCODE_JP12_8:
-               case KEYCODE_JP12_9:
-               case KEYCODE_JP12_0:
-                       retcode = keycode;
-                       break;
-               }
-               Log.d("NicoWnn", "Now retcode = " + retcode);
-               //return retcode;
-               return -1;
+               return keycode;
        }
 }
 /**************** end of file ****************/