Skip to content

Commit

Permalink
Modified the implementation to support invoke hidden methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dkzwm committed Oct 24, 2019
1 parent 3d0e550 commit 15ba1ed
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 58 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ allprojects {
maven { url 'https://jitpack.io' }
google()
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs.add('-Xbootclasspath/p:core/libs/classes.jar')
}
}
}

subprojects {
Expand Down
36 changes: 32 additions & 4 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import groovy.xml.XmlUtil

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

group = rootProject.ext.bintray['groupId']
version=rootProject.ext.android['versionName']
version = rootProject.ext.android['versionName']

android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
Expand All @@ -24,6 +26,7 @@ android {
}

dependencies {
compileOnly files('libs/classes.jar')
compileOnly rootProject.ext.libs.annotation
compileOnly rootProject.ext.libs.recyclerview
compileOnly rootProject.ext.libs.viewpager
Expand Down Expand Up @@ -87,10 +90,9 @@ install {
}
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.key")

Expand All @@ -105,3 +107,29 @@ bintray {
publish = true
}
}

gradle.buildFinished { project ->
Thread.start {
def imlFile = file("core.iml")
println 'We need invoke the hidden api, so we must keep the custom jar in front of the android.jar'
try {
def parsedXml = (new XmlParser()).parse(imlFile)
def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' }
def jdkName = jdkNode.attributes()['jdkName']
def jdkType = jdkNode.attributes()['jdkType']
parsedXml.component[1].remove(jdkNode)
new Node(parsedXml.component[1], 'orderEntry',
[
'type' : 'jdk',
'jdkName': jdkName,
'jdkType': jdkType
])
def text=XmlUtil.serialize(parsedXml)
imlFile.withWriter("UTF8") { writer ->
writer.write(text)
}
} catch (FileNotFoundException e) {
e.printStackTrace()
}
}
}
Binary file added core/libs/classes.jar
Binary file not shown.
13 changes: 4 additions & 9 deletions core/src/main/java/me/dkzwm/widget/srl/SmoothRefreshLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -3586,15 +3586,13 @@ private void ensureTargetView() {
*
* @see ViewGroup source code
*/
private boolean isTransformedTouchPointInView(float x, float y, View group, View child) {
private boolean isTransformedTouchPointInView(float x, float y, ViewGroup group, View child) {
if (child.getVisibility() != VISIBLE || child.getAnimation() != null) {
return false;
}
mCachedFloatPoint[0] = x;
mCachedFloatPoint[1] = y;
mCachedFloatPoint[0] += group.getScrollX() - child.getLeft();
mCachedFloatPoint[1] += group.getScrollY() - child.getTop();
mapTheInverseMatrix(child, mCachedFloatPoint);
group.transformPointToViewLocal(mCachedFloatPoint, child);
final boolean isInView =
mCachedFloatPoint[0] >= 0
&& mCachedFloatPoint[1] >= 0
Expand All @@ -3607,9 +3605,6 @@ private boolean isTransformedTouchPointInView(float x, float y, View group, View
return isInView;
}

/** 如果内部视图进行了矩阵变换,则需要重载本方法,使用SRReflectUtil的compatMapTheInverseMatrix方法,进行兼容处理。 */
protected void mapTheInverseMatrix(View child, float[] point) {}

protected View ensureScrollTargetView(View target, boolean noTransform, float x, float y) {
if (target instanceof IRefreshView
|| target.getVisibility() != VISIBLE
Expand Down Expand Up @@ -4167,7 +4162,7 @@ && isEnabledKeepRefreshView()
if (isHeaderInProcessing()
&& !isDisabledPerformRefresh()
&& isMovingHeader()
&& mIndicator.isOverOffsetToKeepHeaderWhileLoading()) {
&& mIndicator.isOverOffsetToRefresh()) {
if (!mIndicator.isAlreadyHere(mIndicator.getOffsetToKeepHeaderWhileLoading())) {
mScrollChecker.scrollTo(
mIndicator.getOffsetToKeepHeaderWhileLoading(),
Expand All @@ -4177,7 +4172,7 @@ && isMovingHeader()
} else if (isFooterInProcessing()
&& !isDisabledPerformLoadMore()
&& isMovingFooter()
&& mIndicator.isOverOffsetToKeepFooterWhileLoading()) {
&& mIndicator.isOverOffsetToLoadMore()) {
if (!mIndicator.isAlreadyHere(mIndicator.getOffsetToKeepFooterWhileLoading())) {
mScrollChecker.scrollTo(
mIndicator.getOffsetToKeepFooterWhileLoading(),
Expand Down
5 changes: 2 additions & 3 deletions ext-classics/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ install {
}
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.key")

Expand Down
5 changes: 2 additions & 3 deletions ext-horizontal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ install {
}
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.key")

Expand Down
5 changes: 2 additions & 3 deletions ext-material/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ install {
}
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.key")

Expand Down
5 changes: 2 additions & 3 deletions ext-two-level/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ install {
}
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.key")

Expand Down
5 changes: 2 additions & 3 deletions ext-util/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ install {
}
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.key")

Expand Down
30 changes: 0 additions & 30 deletions ext-util/src/main/java/me/dkzwm/widget/srl/util/SRReflectUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
*/
package me.dkzwm.widget.srl.util;

import android.graphics.Matrix;
import android.view.View;
import android.widget.AbsListView;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand All @@ -38,8 +36,6 @@ public class SRReflectUtil {
private static Method sReportScrollStateChangeMethod;
private static Method sFlingRunnableStartMethod;
private static Constructor sFlingRunnableConstructor;
private static Method sHasIdentityMatrixMethod;
private static Method sGetInverseMatrixMethod;
private static boolean sFound = false;

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -105,30 +101,4 @@ public static void compatOlderAbsListViewFling(AbsListView view, int velocityY)
// ignore exception
}
}

public static void compatMapTheInverseMatrix(View view, float[] point) {
try {
if (sHasIdentityMatrixMethod == null) {
sHasIdentityMatrixMethod = View.class.getDeclaredMethod("hasIdentityMatrix");
sHasIdentityMatrixMethod.setAccessible(true);
}
if (sHasIdentityMatrixMethod != null) {
Object obj = sHasIdentityMatrixMethod.invoke(view);
if (obj instanceof Boolean && !(boolean) obj) {
if (sGetInverseMatrixMethod == null) {
sGetInverseMatrixMethod = View.class.getDeclaredMethod("getInverseMatrix");
sGetInverseMatrixMethod.setAccessible(true);
}
if (sGetInverseMatrixMethod != null) {
Matrix matrix = (Matrix) sGetInverseMatrixMethod.invoke(view);
if (matrix != null) {
matrix.mapPoints(point);
}
}
}
}
} catch (Exception e) {
// ignore exception
}
}
}

0 comments on commit 15ba1ed

Please sign in to comment.