forked from hzuapps/android-labs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
...uapps/androidworks/homeworks/net1314080903112/Net1314080903112MyAccessibilityService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package edu.hzuapps.androidworks.homeworks.net1314080903112; | ||
|
||
import android.accessibilityservice.AccessibilityService; | ||
import android.util.Log; | ||
import android.view.accessibility.AccessibilityEvent; | ||
import android.view.accessibility.AccessibilityNodeInfo; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
|
||
public class Net1314080903112MyAccessibilityService extends AccessibilityService { | ||
|
||
Map<Integer, Boolean> handledMap = new HashMap<>(); | ||
|
||
public Net1314080903112MyAccessibilityService() { | ||
} | ||
|
||
@Override | ||
public void onAccessibilityEvent(AccessibilityEvent event) { | ||
AccessibilityNodeInfo nodeInfo = event.getSource(); | ||
if (nodeInfo != null) { | ||
int eventType = event.getEventType(); | ||
if (eventType== AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED || | ||
eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { | ||
if (handledMap.get(event.getWindowId()) == null) { | ||
boolean handled = iterateNodesAndHandle(nodeInfo); | ||
if (handled) { | ||
handledMap.put(event.getWindowId(), true); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private boolean iterateNodesAndHandle(AccessibilityNodeInfo nodeInfo) { | ||
if (nodeInfo != null) { | ||
int childCount = nodeInfo.getChildCount(); | ||
if ("android.widget.Button".equals(nodeInfo.getClassName())) { | ||
String nodeContent = nodeInfo.getText().toString(); | ||
Log.d("TAG", "content is " + nodeContent); | ||
if ("安装".equals(nodeContent) | ||
|| "完成".equals(nodeContent) | ||
|| "确定".equals(nodeContent)) { | ||
nodeInfo.performAction(AccessibilityNodeInfo.ACTION_CLICK); | ||
return true; | ||
} | ||
} else if ("android.widget.ScrollView".equals(nodeInfo.getClassName())) { | ||
nodeInfo.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD); | ||
} | ||
for (int i = 0; i < childCount; i++) { | ||
AccessibilityNodeInfo childNodeInfo = nodeInfo.getChild(i); | ||
if (iterateNodesAndHandle(childNodeInfo)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void onInterrupt() { | ||
} | ||
|
||
} |
Binary file added
BIN
+110 KB
app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903112/界面设计成效图.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
tools:context=".Net1314080903112MainActivity" | ||
android:weightSum="1" | ||
android:background="@mipmap/net1314080903112ground"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="0.03"> | ||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:onClick="onChooseApkFile" | ||
android:text="选择安装包" | ||
android:background="#fbf704" /> | ||
|
||
<TextView | ||
android:id="@+id/apkPathText" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:layout_gravity="center_vertical" | ||
android:textColor="#ffffff" /> | ||
|
||
</LinearLayout> | ||
|
||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="1dp" | ||
android:background="@android:color/darker_gray" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="1dp" | ||
android:background="@android:color/darker_gray" /> | ||
|
||
<LinearLayout | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="0.04"> | ||
|
||
<Button | ||
android:layout_width="96dp" | ||
android:layout_height="wrap_content" | ||
android:onClick="onForwardToAccessibility" | ||
android:text="开启智能安装服务" | ||
android:background="#0af946" /> | ||
</LinearLayout> | ||
|
||
<LinearLayout | ||
android:orientation="horizontal" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:weightSum="1"> | ||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:onClick="onSmartInstall" | ||
android:text="智能安装" | ||
android:background="#03fbb5" | ||
android:layout_weight="0.07" /> | ||
|
||
<LinearLayout | ||
android:orientation="vertical" | ||
android:layout_width="wrap_content" | ||
android:layout_height="71dp" | ||
android:layout_weight="0.81"></LinearLayout> | ||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:onClick="onSilentInstall" | ||
android:text="秒装" | ||
android:background="#03fbb5" | ||
android:layout_weight="0.06" /> | ||
</LinearLayout> | ||
|
||
</LinearLayout> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.