2014-01-20 5 views
1

Android에서 제스처가있는 앱을 개발했습니다. 그것은 단순히 네 가지 제스처가 있습니다. 위, 아래, 왼쪽, 오른쪽. 왼쪽과 오른쪽이 잘 작동하지만 위아래는 인식되지 않습니다. 또한 직접적으로 불확실 해집니다 (색상을 빨간색으로 설정하면 더 빠른 방법으로 디버깅 할 수 있습니다).Android Gesture Recognition bad

import java.util.ArrayList; 

import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.gesture.Gesture; 
import android.gesture.GestureLibraries; 
import android.gesture.GestureLibrary; 
import android.gesture.GestureOverlayView; 
import android.gesture.GestureOverlayView.OnGesturePerformedListener; 
import android.gesture.Prediction; 
import android.graphics.Color; 
import android.util.Log; 
import android.view.Menu; 
import android.view.View; 
import android.view.Window; 
import android.widget.ImageView; 
import android.widget.TextView; 
import android.widget.Toast; 


public class PreperationActivity extends Activity implements OnGesturePerformedListener { 

    private GestureLibrary gestureLib; 
    private ImageView ivProfileImage; 
    private TextView list1, list2, list3, list4; 
    private TextView tvUsername; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 

     GestureOverlayView gestureOverlayView = new GestureOverlayView(this); 
     View inflate = getLayoutInflater().inflate(R.layout.activity_preperation, null); 
     gestureOverlayView.addView(inflate); 
//  gestureOverlayView.setGestureVisible(false); 
     gestureOverlayView.setGestureColor(Color.BLACK); 
     gestureOverlayView.setUncertainGestureColor(Color.RED); 
     gestureOverlayView.addOnGesturePerformedListener(this); 
     gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures); 
     if (!gestureLib.load()) { 
      finish(); 
     } 

     setContentView(gestureOverlayView); 
     ivProfileImage = (ImageView) findViewById(R.id.ivProfileImage); 
     ivProfileImage.setImageBitmap(ListActivity.friends.peek().profileImage); 

     Intent intent = getIntent(); 

     list1 = (TextView) findViewById(R.id.list1); 
     list2 = (TextView) findViewById(R.id.list2); 
     list3 = (TextView) findViewById(R.id.list3); 
     list4 = (TextView) findViewById(R.id.list4); 

     list1.setText(intent.getStringExtra("list1")); 
     list2.setText(intent.getStringExtra("list2")); 
     list3.setText(intent.getStringExtra("list3")); 
     list4.setText(intent.getStringExtra("list4")); 

     tvUsername = (TextView) findViewById(R.id.tvUsername); 
     tvUsername.setText(ListActivity.friends.peek().username); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.preperation, menu); 
     return true; 
    } 

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); 
    } 

    @Override 
    public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { 

     ArrayList<Prediction> predictions = gestureLib.recognize(gesture); 

     for (Prediction prediction : predictions) { 
      Log.i("ced", "PREDICTION: " + prediction.score); 
      if (prediction.score > 1.0) { 
       Friend friend =ListActivity.friends.pop(); 
       ivProfileImage.setImageBitmap(friend.profileImage); 
       tvUsername.setText(friend.username); 
       Toast.makeText(getBaseContext(), prediction.name, Toast.LENGTH_SHORT).show(); 
      } 
     } 
    } 
} 

그리고 내보기 :

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@color/background" 
tools:context=".PreperationActivity" > 

<TextView 
    android:id="@+id/list1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="top" 
    android:background="@color/list_area_background" 
    android:gravity="center" 
    android:text="" 
    android:textAlignment="center" /> 

<TextView 
    android:id="@+id/list2" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_gravity="right" 
    android:background="@color/list_area_background" 
    android:gravity="center" 
    android:text="" 
    android:textAlignment="center" /> 

<TextView 
    android:id="@+id/list3" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" 
    android:background="@color/list_area_background" 
    android:gravity="center" 
    android:text="" 
    android:textAlignment="center" /> 

<TextView 
    android:id="@+id/list4" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_gravity="left" 
    android:background="@color/list_area_background" 
    android:gravity="center" 
    android:text="" 
    android:textAlignment="center" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center" 
    android:gravity="center" 
    android:orientation="vertical" > 

    <ImageView 
    android:id="@+id/ivProfileImage" 
    android:layout_width="183dp" 
    android:layout_height="183dp" 
    android:src="@drawable/com_facebook_profile_picture_blank_square" /> 

    <TextView 
    android:id="@+id/tvUsername" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Medium Text" 
    android:textColor="#ffffff" 
    android:layout_marginTop="5pt" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 
</LinearLayout> 

My gestures from the Gesture Builder

R이 작동하는지 그냥 그래, 그것은 않습니다

여기 내 컨트롤러 코드입니다.

아이디어가 있으십니까? 고맙습니다!

답변

0

이 방법을 호출 한 사람이 있습니까 : addOnGesturePerformedListener?

레거시 데모를 실행 한 결과, OnGesturePerformedListener은 단일 동작을 나타 내기 때문에 & 다운 제스처가 인식되지 않습니다.