Skip to content

Commit

Permalink
refactor double tap copy
Browse files Browse the repository at this point in the history
  • Loading branch information
nondanee committed Jun 1, 2019
1 parent e799e81 commit fe7aab1
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 81 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
/.idea
.DS_Store
/build
/captures
Expand Down
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>keyakimsgassistant-xposed</name>
<comment>Project keyakimsgassistant-xposed created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions .settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=
eclipse.preferences.version=1
6 changes: 6 additions & 0 deletions app/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
23 changes: 23 additions & 0 deletions app/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>app</name>
<comment>Project app created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions app/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=..
eclipse.preferences.version=1
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId "com.nondanee.keyakimsgassistant"
minSdkVersion 21
targetSdkVersion 26
versionCode 17
versionName "3.3"
versionCode 18
versionName "3.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static boolean isMiuiRom() {

public static boolean storageAccessible(Context context) {
if (Build.VERSION.SDK_INT < 23) return true;
else if (ContextCompat.checkSelfPermission(context,android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) return true;
else if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) return true;
else return false;
}

Expand Down
201 changes: 128 additions & 73 deletions app/src/main/java/com/nondanee/keyakimsgassistant/Sniffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public class Sniffer implements IXposedHookLoadPackage {

private final GestureListener gestureListener = new GestureListener();
// private final GestureListener gestureListener = new GestureListener();

@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
Expand All @@ -41,7 +41,7 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam)
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Context context = AndroidAppHelper.currentApplication().getApplicationContext();
gestureListener.bind(context);
// gestureListener.bind(context);
Receiver.onLaunch(context);
}
}
Expand All @@ -59,7 +59,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// String id = activity.getIntent().getStringExtra("CONTENT_KEY");
// String url = activity.getIntent().getStringExtra("CONTENT_URL");
// Context context = activity.getApplicationContext();
// Notifier.onMedia(context,id,url,1);
// Notifier.onMedia(context, id, url, 1);
// }
// }
// );
Expand All @@ -78,7 +78,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
String id = (String) param.args[1];
String url = (String) param.args[2];
Context context = AndroidAppHelper.currentApplication().getApplicationContext();
Receiver.onMedia(context,id,url,1);
Receiver.onMedia(context, id, url, 1);
}
}
);
Expand All @@ -95,7 +95,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// String id = activity.getIntent().getStringExtra("CONTENT_ID");
// String url = activity.getIntent().getStringExtra("CONTENT_URL");
// Context context = activity.getApplicationContext();
// Notifier.onMedia(context,id,url,3);
// Notifier.onMedia(context, id, url, 3);
// }
// }
// );
Expand All @@ -115,7 +115,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
String id = (String) param.args[1];
String url = (String) param.args[2];
Context context = AndroidAppHelper.currentApplication().getApplicationContext();
Receiver.onMedia(context,id,url,3);
Receiver.onMedia(context, id, url, 3);
}
}
);
Expand All @@ -130,26 +130,93 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
String id = (String) XposedHelpers.callMethod(param.args[0],"getTalkId");
String id = (String) XposedHelpers.callMethod(param.args[0], "getTalkId");
String url = (String) param.args[1];
Context context = AndroidAppHelper.currentApplication().getApplicationContext();
Receiver.onMedia(context,id,url,2);
Receiver.onMedia(context, id, url, 2);
}
}
);

//TEXT
// XposedHelpers.findAndHookMethod(
// TextView.class,
// "onTouchEvent",
// MotionEvent.class,
// new XC_MethodHook() {
// @Override
// protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// Log.d(Constant.DEBUG_TAG, "TextView onTouchEvent" );
// super.afterHookedMethod(param);
// View view = (View) param.thisObject;
// MotionEvent event = (MotionEvent) param.args[0];
// gestureListener.onTouchEvent(view, event);
// }
// }
// );

//TEXT
// XposedHelpers.findAndHookMethod(
// TextView.class,
// "onTouchEvent",
// MotionEvent.class,
// new XC_MethodHook() {
// @Override
// protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// super.afterHookedMethod(param);
// View view = (View) param.thisObject;
// MotionEvent event = (MotionEvent) param.args[0];
// gestureListener.onTouchEvent(view, event);
// }
// }
// );

//TEXT
// XposedHelpers.findAndHookMethod(
// "jp.co.sonymusic.communication.keyakizaka.view.talk.TalkItemTextContent",
// loadPackageParam.classLoader,
// "a",
// loadPackageParam.classLoader.loadClass("jp.co.sonymusic.communication.keyakizaka.db.dto.TalkInfo"),
// new XC_MethodHook() {
// @Override
// protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// Log.d(Constant.DEBUG_TAG, "TextView create" );
// super.afterHookedMethod(param);
// TextView textView = (TextView) XposedHelpers.getObjectField(param.thisObject, "c");
// }
// }
// );

//TEXT
XposedHelpers.findAndHookMethod(
View.class,
"dispatchTouchEvent",
MotionEvent.class,
TextView.class,
"setText",
CharSequence.class,
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
View view = (View) param.thisObject;
MotionEvent event = (MotionEvent) param.args[0];
gestureListener.onTouchEvent(view, event);
final TextView textView = (TextView) param.thisObject;
int resourceId = textView.getId();
if (resourceId == View.NO_ID) return;
String viewName = textView.getContext().getResources().getResourceEntryName(resourceId);
if (!(viewName.equals("text") || viewName.equals("singleLineText"))) return;

final GestureDetector gestureDetector = new GestureDetector(textView.getContext(), new GestureDetector.SimpleOnGestureListener() {
public boolean onDown(MotionEvent e) {
return true;
}
public boolean onDoubleTap(MotionEvent e) {
Receiver.onText(textView.getContext(), textView.getText().toString());
return true;
}
});
textView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View view, MotionEvent event) {
gestureDetector.onTouchEvent(event);
return false;
}
});
}
}
);
Expand Down Expand Up @@ -181,7 +248,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// String url = (String) param.args[0];
// Context context = AndroidAppHelper.currentApplication().getApplicationContext();
// Notifier.onMedia(context,url,1);
// Notifier.onMedia(context, url, 1);
// }
// @Override
// protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Expand All @@ -200,7 +267,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// String url = (String) param.args[0];
// Context context = AndroidAppHelper.currentApplication().getApplicationContext();
// Notifier.onMedia(context,url,2);
// Notifier.onMedia(context, url, 2);
// }
// @Override
// protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Expand All @@ -219,7 +286,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// String url = (String) param.args[0];
// Context context = AndroidAppHelper.currentApplication().getApplicationContext();
// Notifier.onMedia(context,url,3);
// Notifier.onMedia(context, url, 3);
// }
// @Override
// protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Expand All @@ -228,61 +295,49 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// );
}

private class GestureListener {

private GestureDetector detector;
private View target;

public void bind(Context context) {
detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
// TODO Auto-generated method stub
return false;
}
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
return;
}
public boolean onDoubleTap(MotionEvent e) {
// TODO Auto-generated method stub
trigger();
return true;
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
// TODO Auto-generated method stub
return false;
}
});
}

private void trigger() {
if (!(target instanceof TextView)) return;
TextView textView = (TextView) target;
int resourceId = textView.getId();
if (resourceId == View.NO_ID) return;
String viewName = target.getContext().getResources().getResourceEntryName(resourceId);
if (viewName.equals("text") || viewName.equals("singleLineText")) {
String text = textView.getText().toString();
Receiver.onText(target.getContext(), text);
}
}

public void onTouchEvent(View view, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) target = view;
detector.onTouchEvent(event);
}

}
// private class GestureListener {
//
// private GestureDetector detector;
// private View target;
//
// public void bind(Context context) {
// detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
// public boolean onDown(MotionEvent e) {
// return true;
// }
// public boolean onSingleTapUp(MotionEvent e) {
// return false;
// }
// public boolean onSingleTapConfirmed(MotionEvent e) {
// return true;
// }
// public boolean onDoubleTap(MotionEvent e) {
// trigger();
// return true;
// }
// public boolean onDoubleTapEvent(MotionEvent e) {
// return true;
// }
// });
// }
//
// private void trigger() {
// if (!(target instanceof TextView)) return;
// TextView textView = (TextView) target;
// int resourceId = textView.getId();
// if (resourceId == View.NO_ID) return;
// String viewName = target.getContext().getResources().getResourceEntryName(resourceId);
// if (viewName.equals("text") || viewName.equals("singleLineText")) {
// String text = textView.getText().toString();
// Receiver.onText(target.getContext(), text);
// }
// }
//
// public void onTouchEvent(View view, MotionEvent event) {
// if (event.getAction() == MotionEvent.ACTION_DOWN) target = view;
// detector.onTouchEvent(event);
// }
//
// }

}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:3.4.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Mar 28 01:42:02 CST 2019
#Fri May 31 10:37:32 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

0 comments on commit fe7aab1

Please sign in to comment.