Skip to content

Commit

Permalink
Second Update
Browse files Browse the repository at this point in the history
  • Loading branch information
anikl9705 committed Jul 17, 2017
1 parent 9de9a1d commit 60afa40
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "www.contentholmes.com.content_holmes"
applicationId 'www.contentholmes.com.content_holmes'
minSdkVersion 19
targetSdkVersion 25
versionCode 1
Expand All @@ -17,10 +17,12 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".ScreenReaderService">
<service android:name=".ScreenReaderService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService"/>
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,77 @@
*/

import android.accessibilityservice.AccessibilityService;
import android.app.Notification;
import android.os.Parcelable;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.view.accessibility.AccessibilityNodeInfo;

import java.util.Date;

public class ScreenReaderService extends AccessibilityService{
String AppName = "Content-Holmes";
AccessibilityServiceInfo info;
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
AccessibilityNodeInfo source = event.getSource();
// Log.v("Content-Holmes", "start event");
// Log.v("Content-Holmes", "asdasdasd");
if (source == null) {
return;
}
Log.i("Event", event.toString()+"-event");
Log.i("Source", source.toString()+"-source");
Log.i("Children", source.getChildCount()+"-children");
if(source.getPackageName().toString().equals("com.android.systemui")){
return;
}
if(event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED){
getNotificationFromView(event);
}else{
getTextFromView(source);
}
Log.v(AppName, source.getPackageName().toString());
Log.v(AppName, new Date(event.getEventTime()).toString());
// Log.v(AppName, source.getPackageName().toString());
// Log.v("Content-Holmes", event.toString()+"-event");
// Log.v("Content-Holmes", source.toString()+"-source");
// Log.v("Content-Holmes", source.getChildCount()+"-children");
}

public void getNotificationFromView(AccessibilityEvent event){
if(event == null){
return;
}
Parcelable data = event.getParcelableData();
if(data instanceof Notification){
Notification n = (Notification) data;
Log.v(AppName, "Notification-"+n.tickerText.toString());
Log.v(AppName, "Notification text-"+n.toString());
}

}

public void getTextFromView(AccessibilityNodeInfo source){
if (source == null){
return;
}
//Log.d(AppName, "source is " + source.toString());
if (source.getChildCount() > 0){
for(int i=0; i<source.getChildCount(); i++){
getTextFromView(source.getChild(i));
}
} else {
if(source.getClassName().equals("android.widget.TextView") && source.getText() != null && !source.getText().toString().isEmpty()){
Log.v(AppName, "text-" + source.getText().toString());
} else if(source.getClassName().equals("android.widget.EditText") && source.getText() != null && !source.getText().toString().isEmpty()){
Log.v(AppName, "input text-" + source.getText().toString());
} else if(source.getClassName().equals("android.widget.ImageView")) {
Log.v(AppName, "image");
} else if(source.getClassName().equals("android.widget.Button") && source.getText() != null && !source.getText().toString().isEmpty()){
Log.v(AppName, "button-" + source.getText().toString());
} else if(source.getText() != null && !source.getText().toString().isEmpty()){
Log.v(AppName, "other-" + source.getText().toString());
}
}
}

@Override
Expand All @@ -31,13 +86,17 @@ public void onInterrupt() {
@Override
protected void onServiceConnected() {
super.onServiceConnected();
info.eventTypes = AccessibilityEvent.TYPE_WINDOWS_CHANGED | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED;
info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_WINDOWS_CHANGED | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED | AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
info.flags = AccessibilityServiceInfo.DEFAULT;
info.flags = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS; info.flags = AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS;
info.flags = AccessibilityServiceInfo.FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY; info.flags = AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS;
info.flags = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
info.flags = AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS;
info.flags = AccessibilityServiceInfo.FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY;
info.flags = AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS;
info.notificationTimeout = 0;
this.setServiceInfo(info);
Log.v("Content-Holmes", "Connected");
}


Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/screenserviceconfig.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<accessibility-service android:accessibilityEventTypes="typeWindowContentChanged|typeWindowStateChanged"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="0"
android:settingsActivity="com.example.android.apis.accessibility.TestBackActivity"
android:settingsActivity="www.contentholmes.com.content_holmes.LoginActivity"
android:canRetrieveWindowContent="true"
android:accessibilityFlags="flagDefault|flagIncludeNotImportantViews|flagReportViewIds|flagRequestEnhancedWebAccessibility|flagRetrieveInteractiveWindows"
xmlns:android="http://schemas.android.com/apk/res/android" />

0 comments on commit 60afa40

Please sign in to comment.