1

我创建了一个在移动设备上运行良好的代码,但它强制在模拟器上停止。该代码用于处理向上、向下滑动。这是我的代码:

horiz.setOnTouchListener(new OnSwipeTouchListener() 
        {
            public void onSwipeTop() 
            {
                Toast.makeText(ArtLauncher.this, "top", Toast.LENGTH_SHORT).show();
            }
            public void onSwipeBottom() 
            {
                Object sbservice = getSystemService( "statusbar" );
                Class<?> statusbarManager;
                try 
                {
                    statusbarManager = Class.forName( "android.app.StatusBarManager" );
                    Method showsb = statusbarManager.getMethod("expand" );
                    showsb.invoke( sbservice );
                } 
                catch (Exception e) 
                {
                    e.printStackTrace();
                }
            }
        });

OnSwipeTouchListener 类是:

class OnSwipeTouchListener implements OnTouchListener 
{
    @SuppressWarnings("deprecation")
    private final GestureDetector gestureDetector = new GestureDetector(new GestureListener());

    public boolean onTouch(final View v, final MotionEvent event) 
    {
        return gestureDetector.onTouchEvent(event);
    }

    private final class GestureListener extends SimpleOnGestureListener implements OnGestureListener 
    {
        private static final int SWIPE_THRESHOLD = 50;
        private static final int SWIPE_VELOCITY_THRESHOLD = 50;
        @Override
        public boolean onDown(MotionEvent e)
        {
            return true;
        }
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) 
        {
            boolean result = false;
            try
            {
                float diffY = e2.getY() - e1.getY();
                    if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
                        if (diffY > 0) 
                        {
                            onSwipeBottom();
                        } else 
                        {
                            onSwipeTop();
                        }
                    }

            } catch (Exception exception) 
            {
                exception.printStackTrace();
            }
            return result;
        }
        @Override
        public void onLongPress(MotionEvent arg0) 
        {   
            Toast.makeText(ArtLauncher.instance, "HELLO WORLD", Toast.LENGTH_LONG).show();
        }
        @Override
        public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
                float arg3) 
        {
            return false;
        }
        @Override
        public void onShowPress(MotionEvent arg0) 
        {
            //Toast.makeText(ArtLauncher.instance, "hhhhhhhhhhhhhh", Toast.LENGTH_LONG).show();
        }
        @Override
        public boolean onSingleTapUp(MotionEvent arg0) 
        {
            return false;
        }
    }
    public void onSwipeTop() 
    {
    }

    public void onSwipeBottom() 
    {
    }
}

任何人都知道为什么我的应用程序停止并给出 IllegalArgumentsException?

4

0 回答 0