メソッドで Bluetooth ゲームパッド コントローラーから軸の位置を受け取りdispatchGenericMotionEvent(android.view. MotionEvent)
ます。私の方法:
@Override
public boolean dispatchGenericMotionEvent(final MotionEvent event) {
if( mPadListener==null ||
(event.getSource()&InputDeviceCompat.SOURCE_JOYSTICK)!=InputDeviceCompat.SOURCE_JOYSTICK ){
return super.dispatchGenericMotionEvent(event);
}
int historySize = event.getHistorySize();
for (int i = 0; i < historySize; i++) {
// Process the event at historical position i
Log.d("JOYSTICKMOVE",event.getHistoricalAxisValue(MotionEvent.AXIS_Y,i)+" "+event.getHistoricalAxisValue(MotionEvent.AXIS_Z,i));
}
// Process current position
Log.d("JOYSTICKMOVE",event.getAxisValue(MotionEvent.AXIS_Y)+" "+event.getAxisValue(MotionEvent.AXIS_Z));
return true;
}
問題は、すべてのジョイスティックの軸を離したときに、ログに最後の軸の値 (0,0) が表示されないことです。たとえば (0.23,0.11) で停止し、適切な値が次の移動イベントの後にのみ logcat に表示されます。しかも、通常のボタンを押しても状況は同じ(ボタンイベントは全く別の方法でキャッチdispatchKeyEvent(android.view.KeyEvent)
)
どうしたの ?