Git Product home page Git Product logo

jump's Introduction

Android利用悬浮窗轻松实现微信跳一跳辅助

Alt text

实现思路

  • 透明悬浮窗
  • 手指滑动通过onTouch获取滑动的间距
  • 按比例计算出需要长按的时间
  • 使用shell命令模拟长按(需要ROOT权限)

主要代码

@Override
public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN: //按下
            Log.d(TAG, "开始位置: " + event.getRawX() + " " + event.getRawY());
            mStartX = event.getRawX();
            mStartY = event.getRawY();
            break;
        case MotionEvent.ACTION_UP: //松开
            Log.d(TAG, "结束位置: " + event.getRawX() + " " + event.getRawY());
            float endX = event.getRawX();
            float endY = event.getRawY();
            //三角形边长1
            float length1 = Math.abs(endX - mStartX);
            //三角形边长2
            float length2 = Math.abs(endY - mStartY);
            //通过勾股定理计算间距
            int distance = 
                    (int) Math.sqrt(Math.pow(length1, 2) + Math.pow(length2, 2));
            Log.d(TAG, "距离: " + distance);
            int temp = (int) (distance * 1.44); //这里需要多尝试几次 找到最佳时间
            exec("input swipe 600 1800 600 1800 " + (temp) + "\n");
            break;
    }
    return true;
}

项目Demo

感谢

jump's People

Contributors

lvkaixuan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.