捕获屏幕上点击的所有点

x33g5p2x  于 2021-07-05  发布在  Java
关注(0)|答案(0)|浏览(238)

我正在开发一个应用程序,从用户那里获取节拍并搜索音乐。问题是获取给定时间段内的所有点并存储生成的矩阵。以下是我的部分代码。

SurfaceView surfaceView;
public final int Listen_time;

{
    Listen_time = 8000;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /**
     * Set a time difference between first and last tap
     * figure out variation in the beats
     * form a data structure e.g. matrix or array to represent the tapped out beat
     */
    surfaceView=findViewById(R.id.surfaceView);
    surfaceView.setOnTouchListener(new View.OnTouchListener() {
        @Override 
        public boolean onTouch(View view, MotionEvent motionEvent) {
                long startListen=System.currentTimeMillis();
                long endListen=System.currentTimeMillis()+Listen_time;
                while((endListen-startListen)>=Listen_time){
                    int pointerId=motionEvent.getPointerId(0);
                    int pointerIndex=motionEvent.findPointerIndex(pointerId);
                    float x=motionEvent.getX(pointerIndex);
                    float y=motionEvent.getY(pointerIndex);

                    Log.d("X",String.valueOf(x));
                    Log.d("Y",String.valueOf(y));
                    ArrayList touchPoint=new ArrayList();
                    touchPoint.add(x);
                    touchPoint.add(y);
                    Queue<String> queue=new LinkedList<>();
                    queue.add(String.valueOf(x));
                    queue.add(String.valueOf(y));

                    System.out.println(queue);
                    while (queue.size()>0){
                        System.out.println(queue.remove()+"");
                    }
                   System.out.println(queue.peek());
                    buildBeat(queue);

                }

            Log.d("touch_point",String.valueOf(touchPoint));
            return false;
        }
    });

}

private void buildBeat(Queue queue) {
    float[] beat_qr;

            SearchService myBeatSearch=new SearchService();

            String now_is=String.valueOf(System.currentTimeMillis());
            Log.d("MATRIX", "touched "+ finalBeat +" at "+now_is);
            myBeatSearch.receiveSpot(queue,System.currentTimeMillis());

    }

问题是,我的arraylist一次只能存储一个坐标,而我希望收集所有坐标,以便将它们合并到一个节拍中。关于在哪里进行更改有什么提示和建议吗?非常感谢。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题