安卓版微信跳一跳輔助,java實現,具體內容如下

已經看到網上有大神用各種方式實現了,我這是屬于簡易版ADB命令式實現。
操作方法
1.光標移動到起始點,點擊FORM
2.光標移動到目標點,點擊TO
3.小人已經跳過去了
原理說明
安裝APP,通過設置起點和目標點位置,獲得彈跳的毫秒數,發送請求到連接手機的電腦中,電腦執行adb命令起跳。
具體實現
本人的測試設備是Mate9,android版本為7.0,由于在非Root環境下,普通安卓應用并不能通過Runtime.getRuntime().exec()來點擊本應用外的區域,所以將手機直接通過USB調試模式連接到電腦,在點擊TO按鈕后,
int a = Math.abs(mToX - mFromX); int b = Math.abs(mToY - mFromY); double c = Math.sqrt(a * a + b * b);
已知起點和終點的坐標,得到兩條直角邊長度,用勾股定理很容易就求出了斜邊長度,經過測試,mate9每ms的彈跳距離是0.75像素,長度除0.75得到time的毫秒數,直接發起一次GET請求到電腦中發布的Servlet,然后電腦執行Runtime.getRuntime().exec("adb shell input swipe 100 100 100 100 " + time)來控制起跳,一次完美的起跳就完成了。
源代碼
源代碼非常簡單,就直接放在這里了
//寫在安卓APP中的起跳
public class Jump {
private static final String TAG = "Jump";
private Context mContext;
private int mFromX = 0;
private int mFromY = 0;
private int mToX = 0;
private int mToY = 0;
/**
* 每毫秒的距離
*/
private static final double MS_DISTANCE = 0.75;
private WindowManager wm;
private View mIndicatorView;
private View mIndicator;
private WindowManager.LayoutParams params;
private TextView mTv_time;
public Jump(Context context) {
mContext = context;
init();
}
private void init() {
wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
mIndicatorView = LayoutInflater.from(mContext).inflate(R.layout.indicator, null, false);
mIndicatorView.measure(0, 0);
mIndicator = mIndicatorView.findViewById(R.id.indicator);
mTv_time = mIndicatorView.findViewById(R.id.tv_time);
mIndicatorView.findViewById(R.id.btnForm)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setForm();
}
});
mIndicatorView.findViewById(R.id.btnTo)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setTo();
}
});
mIndicatorView.setOnTouchListener(new View.OnTouchListener() {
int startX;
int startY;
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
startX = (int) event.getRawX();
startY = (int) event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
int newX = (int) event.getRawX();
int newY = (int) event.getRawY();
int dx = newX - startX;
int dy = newY - startY;
params.x += dx;
params.y += dy;
wm.updateViewLayout(mIndicatorView, params);
startX = (int) event.getRawX();
startY = (int) event.getRawY();
break;
default:
break;
}
return true;
}
});
params = new WindowManager.LayoutParams();
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
params.format = PixelFormat.TRANSLUCENT;
params.gravity = Gravity.TOP + Gravity.LEFT;
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
wm.addView(mIndicatorView, params);
}
public void setForm() {
int[] mLocation = new int[2];
mIndicator.getLocationOnScreen(mLocation);
int wOffset = mIndicator.getMeasuredWidth() / 2;
int hOffset = mIndicator.getMeasuredHeight() / 2;
mFromX = mLocation[0] + wOffset;
mFromY = mLocation[1] + hOffset;
}
public void setTo() {
int[] mLocation = new int[2];
mIndicator.getLocationOnScreen(mLocation);
int wOffset = mIndicator.getMeasuredWidth() / 2;
int hOffset = mIndicator.getMeasuredHeight() / 2;
mToX = mLocation[0] + wOffset;
mToY = mLocation[1] + hOffset;
int a = Math.abs(mToX - mFromX);
int b = Math.abs(mToY - mFromY);
double c = Math.sqrt(a * a + b * b);
final int time = (int) (c / MS_DISTANCE);
mTv_time.setText(String.valueOf(time));
mFromX = 0;
mFromY = 0;
mToX = 0;
mToY = 0;
new Thread(new Runnable() {
@Override
public void run() {
requestGet(time);
}
}).start();
}
private void requestGet(int time) {
try {
StringBuilder requestUrl = new StringBuilder("http://192.168.1.140:8080/jump/JumpTime").append("?").append("time=").append(time);
// 新建一個URL對象
URL url = new URL(requestUrl.toString());
// 打開一個HttpURLConnection連接
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
// 設置連接主機超時時間
urlConn.setConnectTimeout(5 * 1000);
//設置從主機讀取數據超時
urlConn.setReadTimeout(5 * 1000);
// 設置是否使用緩存 默認是true
urlConn.setUseCaches(true);
// 設置為Post請求
urlConn.setRequestMethod("GET");
//urlConn設置請求頭信息
//設置請求中的媒體類型信息。
urlConn.setRequestProperty("Content-Type", "application/json");
//設置客戶端與服務連接類型
urlConn.addRequestProperty("Connection", "Keep-Alive");
// 開始連接
urlConn.connect();
// 判斷請求是否成功
if (urlConn.getResponseCode() == 200) {
// 獲取返回的數據
Log.e(TAG, "Get方式請求成功,result--->");
} else {
Log.e(TAG, "Get方式請求失敗");
Log.e(TAG, urlConn.getResponseMessage());
}
// 關閉連接
urlConn.disconnect();
} catch (Exception e) {
Log.e(TAG, e.toString());
}
}
}
//標靶的布局文件 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="150dp"> <RelativeLayout android:layout_width="100dp" android:layout_height="wrap_content"> <TextView android:id="@+id/tv_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true"/> <RelativeLayout android:id="@+id/rl" android:layout_width="100dp" android:layout_height="100dp" android:layout_below="@id/tv_time"> <View android:layout_width="match_parent" android:layout_height="1dp" android:layout_centerVertical="true" android:background="@android:color/black"/> <View android:layout_width="1dp" android:layout_height="match_parent" android:layout_centerHorizontal="true" android:background="@android:color/black"/> <View android:id="@+id/indicator" android:layout_width="30dp" android:layout_height="30dp" android:layout_centerInParent="true" android:background="@drawable/mid"/> </RelativeLayout> <Button android:id="@+id/btnForm" android:layout_width="50dp" android:layout_height="wrap_content" android:layout_below="@id/rl" android:onClick="setForm" android:text="form" android:textSize="8sp"/> <Button android:id="@+id/btnTo" android:layout_width="50dp" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_below="@id/rl" android:onClick="setTo" android:text="to" android:textSize="8sp"/> </RelativeLayout> </FrameLayout>
//Servlet文件
public class Jump extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
int time = Integer.parseInt(req.getParameter("time"));
Runtime.getRuntime().exec("adb shell input swipe 100 100 100 100 " + time);
}
}
以上就是此Java版跳一跳輔助的核心內容,從此制霸排行榜不是夢φ(>ω<*)--->(告訴一個秘密:跳太多分數會被直接刪除的喲  ̄へ ̄)
更多內容大家可以參考專題《微信跳一跳》進行學習。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。