From 26b8f905ed6f7a427688dfd0cfef913872ba26e7 Mon Sep 17 00:00:00 2001 From: Zhongyi Tong Date: Sat, 16 Jan 2016 15:31:48 +0800 Subject: [PATCH] Merge with Github stable. --- .../java/com/miui/hongbao/HongbaoService.java | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/miui/hongbao/HongbaoService.java b/app/src/main/java/com/miui/hongbao/HongbaoService.java index 1a41c8d4..347ed71d 100644 --- a/app/src/main/java/com/miui/hongbao/HongbaoService.java +++ b/app/src/main/java/com/miui/hongbao/HongbaoService.java @@ -14,8 +14,7 @@ public class HongbaoService extends AccessibilityService { - private List mReceiveNode; - private AccessibilityNodeInfo mUnpackNode; + private AccessibilityNodeInfo mReceiveNode, mUnpackNode; private boolean mLuckyMoneyPicked, mLuckyMoneyReceived, mNeedUnpack, mNeedBack; @@ -75,25 +74,22 @@ public void onAccessibilityEvent(AccessibilityEvent event) { /* 如果已经接收到红包并且还没有戳开 */ if (mLuckyMoneyReceived && !mLuckyMoneyPicked && (mReceiveNode != null)) { - int size = mReceiveNode.size(); - if (size > 0) { - String id = getHongbaoText(mReceiveNode.get(size - 1)); + String id = getHongbaoText(mReceiveNode); - long now = System.currentTimeMillis(); + long now = System.currentTimeMillis(); - if (this.shouldReturn(id, now - lastFetchedTime)) - return; + if (this.shouldReturn(id, now - lastFetchedTime)) + return; - mCycle = true; + mCycle = true; - lastFetchedHongbaoId = id; - lastFetchedTime = now; + lastFetchedHongbaoId = id; + lastFetchedTime = now; - AccessibilityNodeInfo cellNode = mReceiveNode.get(size - 1); - cellNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK); - mLuckyMoneyReceived = false; - mLuckyMoneyPicked = true; - } + AccessibilityNodeInfo cellNode = mReceiveNode; + cellNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK); + mLuckyMoneyReceived = false; + mLuckyMoneyPicked = true; } /* 如果戳开但还未领取 */ if (mNeedUnpack && (mUnpackNode != null)) { @@ -130,7 +126,7 @@ private void checkNodeInfo() { String nodeId = Integer.toHexString(System.identityHashCode(this.rootNodeInfo)); if (!nodeId.equals(lastFetchedHongbaoId)) { mLuckyMoneyReceived = true; - mReceiveNode = nodes1; + mReceiveNode = nodes1.get(nodes1.size() - 1); } return; }