Skip to content

Commit

Permalink
hzuapps#90 hzuapps#125 实验4 界面设计编程
Browse files Browse the repository at this point in the history
  • Loading branch information
WCTNOC committed Apr 27, 2016
1 parent 0a2c3cc commit 5420958
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 0 deletions.
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() {
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions app/src/main/res/layout/net1314080903112activity_main.xml
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.

0 comments on commit 5420958

Please sign in to comment.