aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMenny Even Danan <menny@evendanan.net>2015-11-05 02:08:25 +0000
committerMenny Even Danan <menny@evendanan.net>2015-11-05 02:08:25 +0000
commitd827cf27c69e7ed839ee8fb3aad2a6d40117a3dd (patch)
treee5a7a11246a09b654dbb1af7b2148cc9b3ffcb82
parent598dd05780013e38e49057b8e1a1af58d81ffb91 (diff)
downloadAnySoftKeyboard-d827cf27c69e7ed839ee8fb3aad2a6d40117a3dd.tar.gz
AnySoftKeyboard-d827cf27c69e7ed839ee8fb3aad2a6d40117a3dd.tar.bz2
correctly handle swipe gestures to output SHIFT state. #506
-rw-r--r--src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java67
-rw-r--r--src/main/java/com/anysoftkeyboard/LayoutSwitchAnimationListener.java30
-rw-r--r--src/main/java/com/anysoftkeyboard/keyboards/views/AnyKeyboardView.java9
-rw-r--r--src/main/java/com/anysoftkeyboard/keyboards/views/AskGestureEventsListener.java16
4 files changed, 54 insertions, 68 deletions
diff --git a/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java b/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java
index bab8b3145..eb23533bf 100644
--- a/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java
+++ b/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java
@@ -1100,18 +1100,13 @@ public class AnySoftKeyboard extends InputMethodService implements
+ mHardKeyboardAction
.getKeyCodeWasChanged());
if (mHardKeyboardAction.getKeyCodeWasChanged()) {
- final int translatedChar = mHardKeyboardAction
- .getKeyCode();
+ final int translatedChar = mHardKeyboardAction.getKeyCode();
// typing my own.
onKey(translatedChar, null, -1, new int[]{translatedChar}, true/*faking from UI*/);
- // my handling
- // we are at a regular key press, so we'll
- // update
+ // my handling we are at a regular key press, so we'll update
// our meta-state member
- mMetaState = MyMetaKeyKeyListener
- .adjustMetaAfterKeypress(mMetaState);
- Log.d(TAG + "-meta-key",
- getMetaKeysStates("onKeyDown after adjust - translated"));
+ mMetaState = MyMetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
+ Log.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after adjust - translated"));
return true;
}
}
@@ -1477,12 +1472,24 @@ public class AnySoftKeyboard extends InputMethodService implements
}
break;
case KeyCodes.CTRL:
- if ((!mDistinctMultiTouch) || (!fromUI))
+ if (fromUI) {
handleControl();
+ } else {
+ //not from UI (user not actually pressed that button)
+ mControlKeyState.onPress();
+ handleControl();
+ mControlKeyState.onRelease(mAskPrefs.getMultiTapTimeout());
+ }
break;
case KeyCodes.SHIFT:
- if ((!mDistinctMultiTouch) || (!fromUI))
+ if (fromUI) {
+ handleShift();
+ } else {
+ //not from UI (user not actually pressed that button)
+ mShiftKeyState.onPress();
handleShift();
+ mShiftKeyState.onRelease(mAskPrefs.getMultiTapTimeout());
+ }
break;
case KeyCodes.ARROW_LEFT:
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT);
@@ -2531,60 +2538,46 @@ public class AnySoftKeyboard extends InputMethodService implements
public void onSwipeRight(boolean onSpaceBar, boolean twoFingersGesture) {
final int keyCode = mAskPrefs.getGestureSwipeRightKeyCode(onSpaceBar, twoFingersGesture);
- Log.d(TAG, "onSwipeRight " + ((onSpaceBar) ? " + space" : "") + ((twoFingersGesture) ? " + two-fingers" : "")
- + " => code " + keyCode);
- if (keyCode != 0)
- mSwitchAnimator
- .doSwitchAnimation(AnimationType.SwipeRight, keyCode);
+ Log.d(TAG, "onSwipeRight " + ((onSpaceBar) ? " + space" : "") + ((twoFingersGesture) ? " + two-fingers" : "") + " => code " + keyCode);
+ if (keyCode != 0) mSwitchAnimator.doSwitchAnimation(AnimationType.SwipeRight, keyCode);
}
public void onSwipeLeft(boolean onSpaceBar, boolean twoFingersGesture) {
final int keyCode = mAskPrefs.getGestureSwipeLeftKeyCode(onSpaceBar, twoFingersGesture);
- Log.d(TAG, "onSwipeLeft " + ((onSpaceBar) ? " + space" : "") + ((twoFingersGesture) ? " + two-fingers" : "")
- + " => code " + keyCode);
- if (keyCode != 0)
- mSwitchAnimator.doSwitchAnimation(AnimationType.SwipeLeft, keyCode);
+ Log.d(TAG, "onSwipeLeft " + ((onSpaceBar) ? " + space" : "") + ((twoFingersGesture) ? " + two-fingers" : "") + " => code " + keyCode);
+ if (keyCode != 0) mSwitchAnimator.doSwitchAnimation(AnimationType.SwipeLeft, keyCode);
}
public void onSwipeDown(boolean onSpaceBar) {
final int keyCode = mAskPrefs.getGestureSwipeDownKeyCode();
- Log.d(TAG, "onSwipeDown " + ((onSpaceBar) ? " + space" : "")
- + " => code " + keyCode);
- if (keyCode != 0)
- onKey(keyCode, null, -1, new int[]{keyCode}, false);
+ Log.d(TAG, "onSwipeDown " + ((onSpaceBar) ? " + space" : "") + " => code " + keyCode);
+ if (keyCode != 0) onKey(keyCode, null, -1, new int[]{keyCode}, false/*not directly pressed the UI key*/);
}
public void onSwipeUp(boolean onSpaceBar) {
final int keyCode = mAskPrefs.getGestureSwipeUpKeyCode(onSpaceBar);
- Log.d(TAG, "onSwipeUp " + ((onSpaceBar) ? " + space" : "")
- + " => code " + keyCode);
- if (keyCode != 0) {
- onKey(keyCode, null, -1, new int[]{keyCode}, false);
- }
+ Log.d(TAG, "onSwipeUp " + ((onSpaceBar) ? " + space" : "") + " => code " + keyCode);
+ if (keyCode != 0) onKey(keyCode, null, -1, new int[]{keyCode}, false/*not directly pressed the UI key*/);
}
public void onPinch() {
final int keyCode = mAskPrefs.getGesturePinchKeyCode();
Log.d(TAG, "onPinch => code " + keyCode);
- if (keyCode != 0)
- onKey(keyCode, null, -1, new int[]{keyCode}, false);
+ if (keyCode != 0) onKey(keyCode, null, -1, new int[]{keyCode}, false/*not directly pressed the UI key*/);
}
public void onSeparate() {
final int keyCode = mAskPrefs.getGestureSeparateKeyCode();
Log.d(TAG, "onSeparate => code " + keyCode);
- if (keyCode != 0)
- onKey(keyCode, null, -1, new int[]{keyCode}, false);
+ if (keyCode != 0) onKey(keyCode, null, -1, new int[]{keyCode}, false/*not directly pressed the UI key*/);
}
private void sendKeyDown(InputConnection ic, int key) {
- if (ic != null)
- ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, key));
+ if (ic != null) ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, key));
}
private void sendKeyUp(InputConnection ic, int key) {
- if (ic != null)
- ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, key));
+ if (ic != null) ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, key));
}
public void onPress(int primaryCode) {
diff --git a/src/main/java/com/anysoftkeyboard/LayoutSwitchAnimationListener.java b/src/main/java/com/anysoftkeyboard/LayoutSwitchAnimationListener.java
index b2a804190..654970590 100644
--- a/src/main/java/com/anysoftkeyboard/LayoutSwitchAnimationListener.java
+++ b/src/main/java/com/anysoftkeyboard/LayoutSwitchAnimationListener.java
@@ -57,23 +57,16 @@ public class LayoutSwitchAnimationListener implements
}
private void loadAnimations() {
- mSwitchAnimation = AnimationUtils.loadAnimation(mIme.getApplicationContext(),
- R.anim.layout_switch_fadeout);
+ mSwitchAnimation = AnimationUtils.loadAnimation(mIme.getApplicationContext(), R.anim.layout_switch_fadeout);
mSwitchAnimation.setAnimationListener(this);
- mSwitch2Animation = AnimationUtils.loadAnimation(mIme.getApplicationContext(),
- R.anim.layout_switch_fadein);
+ mSwitch2Animation = AnimationUtils.loadAnimation(mIme.getApplicationContext(), R.anim.layout_switch_fadein);
- mSwipeLeftAnimation = AnimationUtils.loadAnimation(mIme.getApplicationContext(),
- R.anim.layout_switch_slide_out_left);
+ mSwipeLeftAnimation = AnimationUtils.loadAnimation(mIme.getApplicationContext(), R.anim.layout_switch_slide_out_left);
mSwipeLeftAnimation.setAnimationListener(this);
- mSwipeLeft2Animation = AnimationUtils.loadAnimation(mIme.getApplicationContext(),
- R.anim.layout_switch_slide_in_right);
-
- mSwipeRightAnimation = AnimationUtils.loadAnimation(mIme.getApplicationContext(),
- R.anim.layout_switch_slide_out_right);
+ mSwipeLeft2Animation = AnimationUtils.loadAnimation(mIme.getApplicationContext(), R.anim.layout_switch_slide_in_right);
+ mSwipeRightAnimation = AnimationUtils.loadAnimation(mIme.getApplicationContext(), R.anim.layout_switch_slide_out_right);
mSwipeRightAnimation.setAnimationListener(this);
- mSwipeRight2Animation = AnimationUtils.loadAnimation(mIme.getApplicationContext(),
- R.anim.layout_switch_slide_in_left);
+ mSwipeRight2Animation = AnimationUtils.loadAnimation(mIme.getApplicationContext(), R.anim.layout_switch_slide_in_left);
}
private void unloadAnimations() {
@@ -91,13 +84,10 @@ public class LayoutSwitchAnimationListener implements
mCurrentAnimationType = type;
mTargetKeyCode = targetKeyCode;
final AnyKeyboardView view = mIme.getInputView();
- if (mSwitchAnimation != null && view != null
- && isKeyCodeCanUseAnimation(targetKeyCode)) {
+ if (mSwitchAnimation != null && view != null && isKeyCodeCanUseAnimation(targetKeyCode)) {
view.startAnimation(getStartAnimation(mCurrentAnimationType));
} else {
- mIme.onKey(mTargetKeyCode, null, -1, new int[]{
- mTargetKeyCode
- }, false);
+ mIme.onKey(mTargetKeyCode, null, -1, new int[]{mTargetKeyCode}, false/*not directly pressed the UI key*/);
}
}
@@ -105,9 +95,7 @@ public class LayoutSwitchAnimationListener implements
final AnyKeyboardView view = mIme.getInputView();
if (view != null)
view.requestInAnimation(getEndAnimation(mCurrentAnimationType));
- mIme.onKey(mTargetKeyCode, null, -1, new int[]{
- mTargetKeyCode
- }, false);
+ mIme.onKey(mTargetKeyCode, null, -1, new int[]{mTargetKeyCode}, false/*not directly pressed the UI key*/);
}
public void onAnimationRepeat(Animation animation) {
diff --git a/src/main/java/com/anysoftkeyboard/keyboards/views/AnyKeyboardView.java b/src/main/java/com/anysoftkeyboard/keyboards/views/AnyKeyboardView.java
index cb27a8e0b..3e263a319 100644
--- a/src/main/java/com/anysoftkeyboard/keyboards/views/AnyKeyboardView.java
+++ b/src/main/java/com/anysoftkeyboard/keyboards/views/AnyKeyboardView.java
@@ -174,7 +174,7 @@ public class AnyKeyboardView extends AnyKeyboardBaseView {
}
private boolean invokeOnKey(int primaryCode, Key key, int multiTapIndex) {
- getOnKeyboardActionListener().onKey(primaryCode, key, multiTapIndex, null, false);
+ getOnKeyboardActionListener().onKey(primaryCode, key, multiTapIndex, null, false/*not directly pressed the UI key*/);
return true;
}
@@ -190,8 +190,7 @@ public class AnyKeyboardView extends AnyKeyboardBaseView {
}
@Override
- protected boolean onLongPress(Context packageContext, Key key,
- boolean isSticky, boolean requireSlideInto) {
+ protected boolean onLongPress(Context packageContext, Key key, boolean isSticky, boolean requireSlideInto) {
if (key != null && key instanceof AnyKey) {
AnyKey anyKey = (AnyKey) key;
if (anyKey.longPressCode != 0) {
@@ -311,11 +310,9 @@ public class AnyKeyboardView extends AnyKeyboardBaseView {
} else {
return super.onTouchEvent(me);
}
- } else if (mExtensionVisible
- && me.getY() > mExtensionKeyboardYDismissPoint) {
+ } else if (mExtensionVisible && me.getY() > mExtensionKeyboardYDismissPoint) {
// closing the popup
dismissPopupKeyboard();
-
return true;
} else {
return super.onTouchEvent(me);
diff --git a/src/main/java/com/anysoftkeyboard/keyboards/views/AskGestureEventsListener.java b/src/main/java/com/anysoftkeyboard/keyboards/views/AskGestureEventsListener.java
index f9ae47f30..b17035a54 100644
--- a/src/main/java/com/anysoftkeyboard/keyboards/views/AskGestureEventsListener.java
+++ b/src/main/java/com/anysoftkeyboard/keyboards/views/AskGestureEventsListener.java
@@ -20,6 +20,7 @@ import android.view.MotionEvent;
import com.anysoftkeyboard.devicespecific.AskOnGestureListener;
import com.anysoftkeyboard.utils.Log;
+import com.menny.android.anysoftkeyboard.BuildConfig;
final class AskGestureEventsListener implements
AskOnGestureListener {
@@ -122,24 +123,31 @@ final class AskGestureEventsListener implements
final boolean isHorizontalFling = Math.abs(velocityX) > Math.abs(velocityY);
- Log.d(TAG, "onFling vx %f, vy %f, isHorizontalFling: %s", velocityX, velocityY, Boolean.toString(isHorizontalFling));
-
float deltaX = me2.getX() - me1.getX();
float deltaY = me2.getY() - me1.getY();
+
+ if (BuildConfig.DEBUG) {
+ Log.d(TAG, "mSwipeVelocityThreshold %d, mSwipeYDistanceThreshold %d", mKeyboardView.mSwipeVelocityThreshold, mKeyboardView.mSwipeYDistanceThreshold);
+ Log.d(TAG, "onFling vx %f, vy %f, deltaX %f, deltaY %f, isHorizontalFling: %s", velocityX, velocityY, deltaX, deltaY, Boolean.toString(isHorizontalFling));
+ }
final int swipeXDistance = mKeyboardView.isFirstDownEventInsideSpaceBar() ? mKeyboardView.mSwipeSpaceXDistanceThreshold : mKeyboardView.mSwipeXDistanceThreshold;
if (velocityX > mKeyboardView.mSwipeVelocityThreshold && isHorizontalFling && deltaX > swipeXDistance) {
+ Log.d(TAG, "onSwipeRight");
mKeyboardView.disableTouchesTillFingersAreUp();
mKeyboardView.mKeyboardActionListener.onSwipeRight(mKeyboardView.isFirstDownEventInsideSpaceBar(), mKeyboardView.isAtTwoFingersState());
return true;
} else if (velocityX < -mKeyboardView.mSwipeVelocityThreshold && isHorizontalFling && deltaX < -swipeXDistance) {
+ Log.d(TAG, "onSwipeLeft");
mKeyboardView.disableTouchesTillFingersAreUp();
mKeyboardView.mKeyboardActionListener.onSwipeLeft(mKeyboardView.isFirstDownEventInsideSpaceBar(), mKeyboardView.isAtTwoFingersState());
return true;
- } else if (velocityY < -mKeyboardView.mSwipeVelocityThreshold && !isHorizontalFling && deltaY < -mKeyboardView.mSwipeYDistanceThreshold) {
+ } else if (velocityY < -mKeyboardView.mSwipeVelocityThreshold && (!isHorizontalFling) && deltaY < -mKeyboardView.mSwipeYDistanceThreshold) {
+ Log.d(TAG, "onSwipeUp");
mKeyboardView.disableTouchesTillFingersAreUp();
mKeyboardView.mKeyboardActionListener.onSwipeUp(mKeyboardView.isFirstDownEventInsideSpaceBar());
return true;
- } else if (velocityY > mKeyboardView.mSwipeVelocityThreshold && !isHorizontalFling && deltaY > mKeyboardView.mSwipeYDistanceThreshold) {
+ } else if (velocityY > mKeyboardView.mSwipeVelocityThreshold && (!isHorizontalFling) && deltaY > mKeyboardView.mSwipeYDistanceThreshold) {
+ Log.d(TAG, "onSwipeDown");
mKeyboardView.disableTouchesTillFingersAreUp();
mKeyboardView.mKeyboardActionListener.onSwipeDown(mKeyboardView.isFirstDownEventInsideSpaceBar());
return true;