2011-07-31 56 views
0

ジェスチャーの例をインポートして自分のアプリを作成しました。レイアウトにはボタンとジェスチャーオーバーレイビューがあります。ボタンはGestureBuilderActivity.classを開始し、ジェスチャを追加または削除できます(これは例です)。ボタンの下にあるGestureOverlayViewでは、ジェスチャーを描画できます。レイアウト:ジェスチャーはを/ mnt /に保存されていること(例ではまだ)Android認識ジェスチャー

final String path = new File(Environment.getExternalStorageDirectory(), 
        "gestures").getAbsolutePath(); 

とトーストMSGショー:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <Button 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Click to see gestures" 
    android:id="@+id/Button01" 
    /> 
    <android.gesture.GestureOverlayView 
    android:id="@+id/gestures" 
    android:layout_width="fill_parent" 
    android:layout_height="0dip" 
    android:layout_weight="1.0" /> 
</LinearLayout> 

例から、私はジェスチャーを見つけるところ、これがあることを知っていますSDカード/ジェスチャー:

Toast.makeText(this, getString(R.string.save_success, path), Toast.LENGTH_LONG).show(); 

にはどうすればアプリはトーストMSGに私が描くジェスチャーを認識し、私にその名を表示することができますか?

+0

あなたは、単一のストロークジェスチャ認識のための作業コードを持っているhttp://stackoverflow.com/questions/18165847/android-multi-stroke-gesture-not-working。あなたがしなければならないことはすべてあります。複数のストロークシンボルの場合と同じです。それは自分自身で苦労しています。 – LoveMeow

答えて

0

まず、私はジェスチャーの使い方を説明しているshort articleを読んでいます。

ジェスチャを認識するには、GestureOverlayViewにOnGesturePerformedListenerを提供する必要があります。この例では、アクティビティにOnGesturePerformedListenerを実装させました。この質問に

public class MyActivity extends Activity implements OnGesturePerformedListener { 

private GestureLibrary mGestures; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    // I use resources but you may want to use GestureLibraries.fromFile(path) 
    mGestures = GestureLibraries.fromRawResource(this, R.raw.gestures); 
    if (!mGestures.load()) { 
     showDialog(DIALOG_LOAD_FAIL); 
     finish(); 
    } 

    // register the OnGesturePerformedListener (i.e. this activity) 
    GestureOverlayView gesturesView = (GestureOverlayView) findViewById(R.id.gestures); 
    gesturesView.addOnGesturePerformedListener(this); 
} 

public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { 
    ArrayList<Prediction> predictions = mGestures.recognize(gesture); 

     // Determine if a gesture was performed. 
     // This can be tricky, here is a simple approach. 
    Prediction prediction = (predictions.size() != 0) ? predictions.get(0) : null; 
    prediction = (prediction.score >= 1.0) ? prediction: null; 

    if (prediction != null) { 
      // do something with the prediction 
      Toast.makeText(this, prediction.name + "(" + prediction.score + ")", Toast.LENGTH_LONG).show(); 
    } 
} 
関連する問題