ライブ壁紙でジェスチャ操作を検知する
public class LiveSample extends WallpaperService {
@Override
public void onCreate() {
super.onCreate();
this.context = getApplicationContext();
// 初期化
detector = new GestureDetectorCompat(context, listener);
}
GestureDetectorCompat detector;
// ジェスチャイベント
GestureDetector.OnGestureListener listener = new GestureDetector.OnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
@Override
public boolean onDown(MotionEvent e) {
return false;
}
};
public class LiveEngine extends Engine{
@Override
public void onTouchEvent(MotionEvent event) {
// ジェスチャー検出にイベント流す
detector.onTouchEvent(event);
super.onTouchEvent(event);
}
Comments are currently closed.