2011-10-15 60 views
3

嗨創建手勢我下面這個教程android系統

http://www.vogella.de/articles/AndroidGestures/article.html 我想創造一個用戶可以添加自己的姿態inmy應用程序,然後用它來authentication.i知道使用此代碼我可以檢查是否應用程序由他輸入的手勢是否正確。

package de.vogella.android.gestures;

import java.util.ArrayList;

public class GestureTest extends Activity implements OnGesturePerformedListener { 
    private GestureLibrary gestureLib; 


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

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     GestureOverlayView gestureOverlayView = new GestureOverlayView(this); 
     View inflate = getLayoutInflater().inflate(R.layout.main, null); 
     gestureOverlayView.addView(inflate); 
     gestureOverlayView.addOnGesturePerformedListener(this); 
     gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures); 
     if (!gestureLib.load()) { 
      finish(); 
     } 
     setContentView(gestureOverlayView); 
    } 

    @Override 
    public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { 
     ArrayList<Prediction> predictions = gestureLib.recognize(gesture); 
     for (Prediction prediction : predictions) { 
      if (prediction.score > 1.0) { 
       Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT) 
         .show(); 
      } 
     } 
    } 
} 

確定,但請幫助我,如何在姿態加入R.raw.animate file.please建議任何方式或鏈接,在Android應用程序添加手勢。

回答

7

here提取:

Android 1.6及更高的SDK平臺包括一個新的應用 在模擬器上,稱爲手勢生成器預裝。您可以使用 這個應用程序來創建一組預定義手勢爲自己 應用 ...

...

正如你所看到的,一個手勢總是與相關一個名字。該名稱 非常重要,因爲它可以識別您的 應用程序中的每個手勢。名稱不必是唯一的。其實它可以是 非常有用,有幾個手勢同名,可以提高識別的精度。 每次在手勢生成器中添加或編輯手勢 時,都會在仿真器的SD卡012/卡/ sdcard /手勢上生成一個文件。該文件包含所有手勢的描述,您需要將其打包到您的應用程序 內資源目錄中的/ res/raw

Here你有

手勢生成器安裝在仿真手勢生成器的源代碼,但你可以從here

和手勢源代碼示例here

+0

我需要手勢生成器的源代碼,你可以請提供一個鏈接手勢建設者和感謝做了迴應 –

+0

的源代碼,請不要忘記勾選:d THX –

0

下載另外,您可能需要在使用之前調用gestureLib.load()

+0

是什麼這是錯誤的原因,因爲這發生在我身上。仍試圖找出原因? –