제스처 관련 질문입니다.
구현하고자하는 방향은
키보드위에 제스처를 입히는것입니다.
현재 코드입니다.
1) 키보드위에 제스처오버레이뷰를 넣었습니다.
public View onCreateInputView() {
GestureOverlayView gv = (GestureOverlayView) getLayoutInflater().inflate(
R.layout.input, null);
mInputView = (KeyboardView)gv.findViewById(R.id.keyboard);
mInputView.setOnKeyboardActionListener(this);
mInputView.setKeyboard(mHanBoard);
gv.addOnGesturePerformedListener(new GestureOverlayView.OnGesturePerformedListener() {
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
Log.i("onCreateInputView", "제스처가입력되었습니다.");
}
});
return gv;
}
2) R.layout.input의 상황입니다.
<?xml version="1.0" encoding="utf-8"?>
<android.gesture.GestureOverlayView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gestureOverlayView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gestureColor="@color/candidate_other">
<exam.anerimkeyboard.AnerimKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keyboard"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:keyBackground="@color/candidate_other"
/>
</android.gesture.GestureOverlayView>
3) 제스처 구현창입니다.
public class GestureActivity extends Activity implements GestureDetector.OnGestureListener {
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private GestureDetector gestureScanner;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.input);
gestureScanner = new GestureDetector(this, this);}
@Override
public boolean onTouchEvent(MotionEvent me) {
return gestureScanner.onTouchEvent(me);
}
public boolean onDown(MotionEvent e) {
Log.i("onCreateInputView", "제스처가 입력된거냐?");
return true;
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(getApplicationContext(), "Left Swipe", Toast.LENGTH_SHORT).show();
}
// left to right swipe
else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(getApplicationContext(), "Right Swipe", Toast.LENGTH_SHORT).show();
}
// down to up swipe
else if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(getApplicationContext(), "Swipe up", Toast.LENGTH_SHORT).show();
}
// up to down swipe
else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(getApplicationContext(), "Swipe down", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
}
return true;
}
public void onLongPress(MotionEvent e) {
mInputView.closing();
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Log.i("onCreateInputView", "제스처가 입력된거냐?");
return true;
}
public void onShowPress(MotionEvent e) {
Log.i("onCreateInputView", "제스처가 입력된거냐?");
}
public boolean onSingleTapUp(MotionEvent e) {
Log.i("onCreateInputView", "제스처가 입력된거냐?");
return true;
}
}
제스처오버레이뷰와 제스처구현이 연결이 안된것같은데...
무언가 연결이 안된것같은데... 어떻게 풀어나가야할지 감이안잡힙니다..
초보자이므로 조금 쉽게 설명해주시면 감사하겠습니다!!