开发者

ANDROID: How to create an virtual area on screen on top of everything which user can press to perform actions?

开发者 https://www.devze.com 2023-04-01 17:48 出处:网络
i am trying to do something silmiar to apps like swipepad, taskxp, and taskie where the user swipes or touches an area of the phone screen like the edges and the program functions even if its activ开发

i am trying to do something silmiar to apps like swipepad, taskxp, and taskie where the user swipes

or touches an area of the phone screen like the edges and the program functions even if its activ开发者_开发技巧ity is not shown.

I have no idea where to start since i dont even know whats its called

Any help would be much appreciated!


Here's the answer to a similar question Get co-ordinates touch screen in a background service:

No, sorry. Your activities can pass information about touch events to a service, but a service cannot directly receive touch events

But you can only receive touch events with an activity running.

Here's how you would do a touch listener in an activity:

ImageView playLayout = (ImageView)findViewById(R.id.playLayout);
    playLayout.setKeepScreenOn(true);

    playLayout.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent me) {
            float newY = me.getY();
            float newX = me.getX();
            int action = me.getAction();

            if (action==0){
                Log.v(tag, "New Touch");
                Log.i(tag, String.valueOf("Action " + action +
                        " happened at X,Y: " + "("+newX+","+newY + ")"));
            }
            return true;
        }
    });     

Of course you can add more to it. There, I'm just logging the x and y coordinates of where the touch happened.

0

精彩评论

暂无评论...
验证码 换一张
取 消