마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

키보드와 제스처 관련 질문입니다 [closed]

0 추천
public class CustomKeyboardView extends View {
	public CustomKeyboardView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public CustomKeyboardView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}
}
public class CustomKeyboardService extends InputMethodService {

	CustomKeyboardView mInputView;
	GestureDetector mGestureDetector;
	View.OnTouchListener gestureListener;

	ArrayList<Coordinate> coordinateList= new ArrayList<Coordinate>();

	
	public void onInitializeInterface() {//1
		Log.i("onInitializeInterface", "");
	}

	public View onCreateInputView() {//2
		mInputView = (CustomKeyboardView) getLayoutInflater().inflate(R.layout.minikeyboard, null);
		mGestureDetector = new GestureDetector(new CustomGesture());
		gestureListener = new View.OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				return mGestureDetector.onTouchEvent(event);
			}
		};
		mInputView.setOnTouchListener(gestureListener);
		return mInputView;
	}
	public void onStartInput(EditorInfo attribute, boolean restarting) {
		super.onStartInput(attribute, restarting);
		Log.i("onStartInput", "");
	}
	public void onFinishInput() {
		super.onFinishInput();
		Log.i("onFinishInput", "");
	}
	public void onStartInputView(EditorInfo attribute, boolean restarting) {
		super.onStartInputView(attribute, restarting);
		Log.i("onStartInputView", "");
	}

	public void swipeDown() {
		Log.i("swipeDown", "");
	}

	public void swipeLeft() {
		Log.i("swipeLeft", "");
	}

	public void swipeRight() {
		Log.i("swipeRight", "");
	}

	public void swipeUp() {
		Log.i("swipeUp", "");
	}
	
	private class CustomGesture extends GestureDetector.SimpleOnGestureListener {
		private static final int SWIPE_MIN_DISTANCE = 50;
		private static final int SWIPE_THRESHOLD_VELOCITY = 200;

		@Override
		public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
		                       float velocityY) {
			try {
				// right to left swipe
				if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
					CustomKeyboardService.this.swipeLeft();
				}
				// left to right swipe
				else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
					CustomKeyboardService.this.swipeRight();
				}
				// down to up swipe
				else if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
					CustomKeyboardService.this.swipeUp();
				}
				// up to down swipe
				else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
					CustomKeyboardService.this.swipeDown();
				}
			} catch (Exception e) {

			}
			return true;
		}
		@Override
		public boolean onDown(MotionEvent e) {
			Log.i("onDown", "onDown");
			return super.onDown(e);
		}
		public void onLongPress(MotionEvent e) {
			Log.i("onLongPress", "onLongPress");
		}
		public boolean onSingleTapUp(MotionEvent e) {
			Log.i("onSingleTapUp", "onSingleTapUp");
			return false;
		}
		public boolean onDoubleTap(MotionEvent e) {
			Log.i("onDoubleTap", "onDoubleTap");
			return false;
		}

	}
}

키보드 앱을 만들어 보려고 하는데

일반적으로 쓰는 키보드 뷰를 안쓰고 하려 합니다.

뷰를 터치하면 그냥 터치해도 롱터치로 인식하고

롱터치 함수 없애면 온다운 메소드만 인식하네요

저기 있는 제스처를 상황에 맞는 제스처를 인식하게 하려면 어떡해야 할까요?

질문을 종료한 이유: 해결함
익명사용자 님이 2015년 8월 4일 질문
2015년 8월 5일 closed
...