2012-05-10 5 views
0

こんにちは私はユーザーが画面上にジェスチャーを描き、画像ビュー内の画像が描画されたジェスチャーと同じであるかどうか比較します。私はあなたがドン何かが」そこだ画像が表示され、ユーザーはそれを画像で表示されるものとは別の何かを描画するたびに、それがうまくどのように行われると言うことです私はこの問題を解決することができますか?...とにかくここにコード身振りを認識するAndroid

package draw.letters; 

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.Random; 

import android.app.Activity; 
import android.content.Context; 
import android.gesture.Gesture; 
import android.gesture.GestureOverlayView; 
import android.media.AudioManager; 
import android.media.SoundPool; 
import android.os.Bundle; 
import android.widget.ImageView; 
import android.widget.Toast; 
import android.gesture.GestureLibraries; 
import android.gesture.GestureLibrary; 
import android.gesture.Prediction; 
import android.gesture.GestureOverlayView.OnGesturePerformedListener; 

public class DrawlettersActivity extends Activity implements OnGesturePerformedListener { 
    private SoundPool soundPool; 
    private HashMap<Integer, Integer> soundsMap; 
    private GestureLibrary gestureLib; 
    int soundOk=1; 
    int soundNot=2; 

    ImageView ShowImage; 

    public Integer[] showLetters={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d, 
     R.drawable.e,R.drawable.f,R.drawable.g,R.drawable.h,R.drawable.i 
     ,R.drawable.j,R.drawable.k,R.drawable.l,R.drawable.m,R.drawable.n, 
R.drawable.o,R.drawable.p,R.drawable.q,R.drawable.r,R.drawable.s,R.drawable.t 
     ,R.drawable.u,R.drawable.v,R.drawable.w,R.drawable.x,R.drawable.y,R.drawable.z}; 

    Random r = new Random(); 
    public int index = 0; 
    public String idGesture; 

/** Called when the activity is first created. */ 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100); 
     soundsMap = new HashMap<Integer, Integer>(); 
     soundsMap.put(soundOk, soundPool.load(this, R.raw.htc_notify_weight, 1)); 
     soundsMap.put(soundNot,soundPool.load(this, R.raw.buzzybuz, 1)); 
     gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures); 

     //Loads the gesture library 
     if (!gestureLib.load()) 
     { 
      finish(); 
     } 
     GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures); 
     gestures.addOnGesturePerformedListener(this); 
    }//end of OnCreate() 

    //Method to create the sounds 

    public void playSound(int sound) { 
     AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE); 
     float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC); 
     float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC); 
     float volume = streamVolumeCurrent/streamVolumeMax; 
     soundPool.play(soundsMap.get(sound), volume, volume, 1, 0, 1); 
    } 

    public String idImage (ImageView compara) { 
    String letterGesture = null; 
    switch(compara.getId()) { 
    case R.drawable.a: 
     letterGesture="A"; 
    case R.drawable.b: 
     letterGesture="B"; 
    case R.drawable.c: 
     letterGesture="C"; 
    } 
    return letterGesture; 
    } 

    public void malEscrito() { 
    Toast.makeText(this, "Wrong Try Again", Toast.LENGTH_SHORT).show(); 
    playSound(soundNot); 
    } 


    public void onGesturePerformed(GestureOverlayView overlay, Gesture gestures) { 
    //Calls the image to be displayed 
     index= r.nextInt(26); 
     ShowImage = (ImageView) findViewById(R.id.imageView1); 
     ShowImage.setImageResource(showLetters[index]); 
     idGesture=idImage(ShowImage); 

    ArrayList<Prediction> predictions = gestureLib.recognize(gestures); 
    if (predictions.size() > 0 && predictions.get(0).score > 1.0) 
     { 
      String prediction = predictions.get(0).name; 
      //compares the letters with the name of the gesture 
    if ("A".equals(prediction)) { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } else if ("B".equals(prediction)) { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } else if ("C".equals(prediction)) { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } else if ("D".equals(prediction)) { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } else if ("E".equals(prediction)) { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } else if ("F".equals(prediction)) { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("G".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("H".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("I".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("J".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("K".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("L".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("M".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("N".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
       else if ("~n".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("O".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("P".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("Q".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("R".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("S".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("T".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("U".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("V".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("W".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("X".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 
      else if ("Y".equals(prediction)) 
      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } else if ("Z".equals(prediction)) 

      { 
       Toast.makeText(this,"Well Done",Toast.LENGTH_SHORT).show(); 
       //index = r.nextInt(3); 
       ShowImage.setImageResource(showLetters[index]); 
       playSound(soundOk); 
      } 

      else 
       { 
       malEscrito(); 
       } 

      } 
     } 

} 

感謝を事前にお知らせください!

答えて

0

"I".equals(prediction)は、文字列を完全に分離したオブジェクトタイプandroid.gesture.Predictionに等しいと言っているため、間違っています。

私はしばらく前にこれに関連するカレンダーのために書いた、これを引くことができたいくつかのコードに掘っ

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

     // We want at least one prediction 
     if (predictions.size() > 0) { 
      Prediction prediction = predictions.get(0); 
      // We want at least some confidence in the result 
      if (prediction.score > 1.0) { 
       if (prediction.name.equals("gest_right")) { 
        // Toast.makeText(this, "previous month", 
        // Toast.LENGTH_SHORT).show(); 

        userMonth.set(Calendar.DAY_OF_MONTH, 1); 
        userMonth.add(Calendar.DATE, -1); 

        // goingForward = false; 
       } else { 
        // Toast.makeText(this, "next month", 
        // Toast.LENGTH_SHORT).show(); 

        userMonth.set(Calendar.DAY_OF_MONTH, 1); 
        userMonth.add(Calendar.DATE, userMonth 
          .getActualMaximum(Calendar.DAY_OF_MONTH)); 

        // goingForward = true; 
       } 
       updateCalendarUI(); 
      } 
     } 

私は実際に私がロードジェスチャーライブラリを作成するには、Googleのサンプルアプリケーションのいずれかを使用mLibraryに;これが何らかの形で役立つことを願っています...

+0

私は既にジェスチャーの名前ではなくジェスチャーのジェスチャーと比較する方法を見つけたいと思います私はイメージビューでイメージに値を付けることができます描画されたジェスチャーがイメージの値と同じであるかどうかを比較することができます...これまで達成できなかった – dalv839

+0

>作成されたジェスチャーで 私はよく分からない?ピクセルでは、ジェスチャーは、おそらく旅行をしていますか? – Blaskovicz

関連する問題