Skip to content

Commit

Permalink
update to 1.5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
JavaNoober committed Aug 23, 2019
1 parent 4ffd451 commit 99a8655
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 89 deletions.
4 changes: 2 additions & 2 deletions README-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ A framework for directly generating shape through Tags, no need to write shape.x
Add this to your app's build.gradle:

implementation "com.android.support:appcompat-v7:$supportVersion"
implementation 'com.noober.background:core:1.5.5'
implementation 'com.noober.background:core:1.5.6'

if use androidx:

implementation "androidx.appcompat:appcompat:$supportVersion"
implementation 'com.noober.background:core:1.5.5'
implementation 'com.noober.background:core:1.5.6'


## Example effect
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ A framework for directly generating shape through Tags, no need to write shape.x
依赖方式:

implementation "com.android.support:appcompat-v7:$supportVersion"
implementation 'com.noober.background:core:1.5.5'
implementation 'com.noober.background:core:1.5.6'

如果项目使用了androidx:

implementation "androidx.appcompat:appcompat:$supportVersion"
implementation 'com.noober.background:core:1.5.5'
implementation 'com.noober.background:core:1.5.6'


## 使用文档
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
compileSdkVersion 29
defaultConfig {
applicationId "com.noober.backgroudlibrary"
minSdkVersion 14
targetSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -37,7 +37,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.noober.background:core:1.5.5'
implementation 'com.noober.background:core:1.5.6'
// implementation project(':library')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ext {
userOrg = 'noober'
groupId = 'com.noober.background'
uploadName = 'LibraryForBackground'
publishVersion = '1.5.5'
publishVersion = '1.5.6'
desc = "A framework for directly generating shape through Tags, no need to write shape.xml again(通过标签直接生成shape,无需再写shape.xml)"
website = 'https://github.com/JavaNoober/BackgroundLibrary'
// gradlew clean build bintrayUpload -PbintrayUser=xiaoqiandroid -PbintrayKey=xxxxxxxxxxxxxxxx -PdryRun=false
Expand Down
53 changes: 13 additions & 40 deletions library/src/main/java/com/noober/background/BackgroundLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

Expand Down Expand Up @@ -36,7 +37,7 @@ public static LayoutInflater inject(Context context) {
BackgroundFactory factory = setDelegateFactory(context);
inflater.setFactory2(factory);
} else if (!(inflater.getFactory2() instanceof BackgroundFactory)) {
forceSetFactory2(inflater, context);
forceSetFactory2(inflater);
}
return inflater;
}
Expand Down Expand Up @@ -72,19 +73,11 @@ public static LayoutInflater inject2(Context context) {
if (inflater == null) {
return null;
}
forceSetFactory2(inflater, context);
forceSetFactory2(inflater);
return inflater;
}

/**
* 通过LayoutInflaterCompat去规避非SDK接口在Android Q 中的受限。
* 首先:设置LayoutInflaterCompat的sCheckedField为false, 保证可以设置当前mFactory2的值
* 第二:设置LayoutInflater的 mFactory 为空,保证LayoutInflaterCompat调用setFactory的时候不进行FactoryMerger操作
* 第三:反射调用LayoutInflaterCompat的forceSetFactory2方法
* 第四:重新设置LayoutInflater的mFactory值,防止调用Fragment的时候fragment会进行FactoryMerger操作
* 经过上述步骤,在Activity以及Activity中的Fragment就会变成我们想要的factory类
*/
private static void forceSetFactory2(LayoutInflater inflater, Context context) {
private static void forceSetFactory2(LayoutInflater inflater) {
Class<LayoutInflaterCompat> compatClass = LayoutInflaterCompat.class;
Class<LayoutInflater> inflaterClass = LayoutInflater.class;
try {
Expand All @@ -93,40 +86,20 @@ private static void forceSetFactory2(LayoutInflater inflater, Context context) {
sCheckedField.setBoolean(inflater, false);
Field mFactory = inflaterClass.getDeclaredField("mFactory");
mFactory.setAccessible(true);
mFactory.set(inflater, null);

Method method = compatClass.getDeclaredMethod("forceSetFactory2", LayoutInflater.class, LayoutInflater.Factory2.class);
method.setAccessible(true);
BackgroundFactory factory = setDelegateFactory(context);
method.invoke(null, inflater, factory);
Field mFactory2 = inflaterClass.getDeclaredField("mFactory2");
mFactory2.setAccessible(true);
BackgroundFactory factory = new BackgroundFactory();
if (inflater.getFactory2() != null) {
factory.setInterceptFactory2(inflater.getFactory2());
} else if (inflater.getFactory() != null) {
factory.setInterceptFactory(inflater.getFactory());
}
mFactory2.set(inflater, factory);
mFactory.set(inflater, factory);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
// try {
// Field field = LayoutInflater.class.getDeclaredField("mFactorySet");
// field.setAccessible(true);
// field.setBoolean(inflater, false);
//
// BackgroundFactory factory = new BackgroundFactory();
// if (inflater.getFactory2() != null) {
// factory.setInterceptFactory2(inflater.getFactory2());
// } else if (inflater.getFactory() != null) {
// factory.setInterceptFactory(inflater.getFactory());
// }
// inflater.setFactory2(factory);
// } catch (NoSuchFieldException e) {
// e.printStackTrace();
// } catch (IllegalArgumentException e) {
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// e.printStackTrace();
// }
}
}
53 changes: 12 additions & 41 deletions libraryx/src/main/java/com/noober/background/BackgroundLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static LayoutInflater inject(Context context) {
BackgroundFactory factory = setDelegateFactory(context);
inflater.setFactory2(factory);
} else if (!(inflater.getFactory2() instanceof BackgroundFactory)) {
forceSetFactory2(inflater, context);
forceSetFactory2(inflater);
}
return inflater;
}
Expand Down Expand Up @@ -73,19 +73,11 @@ public static LayoutInflater inject2(Context context) {
if (inflater == null) {
return null;
}
forceSetFactory2(inflater, context);
forceSetFactory2(inflater);
return inflater;
}

/**
* 通过LayoutInflaterCompat去规避非SDK接口在Android Q 中的受限。
* 首先:设置LayoutInflaterCompat的sCheckedField为false, 保证可以设置当前mFactory2的值
* 第二:设置LayoutInflater的 mFactory 为空,保证LayoutInflaterCompat调用setFactory的时候不进行FactoryMerger操作
* 第三:反射调用LayoutInflaterCompat的forceSetFactory2方法
* 第四:重新设置LayoutInflater的mFactory值,防止调用Fragment的时候fragment会进行FactoryMerger操作
* 经过上述步骤,在Activity以及Activity中的Fragment就会变成我们想要的factory类
*/
private static void forceSetFactory2(LayoutInflater inflater, Context context) {
private static void forceSetFactory2(LayoutInflater inflater) {
Class<LayoutInflaterCompat> compatClass = LayoutInflaterCompat.class;
Class<LayoutInflater> inflaterClass = LayoutInflater.class;
try {
Expand All @@ -94,41 +86,20 @@ private static void forceSetFactory2(LayoutInflater inflater, Context context) {
sCheckedField.setBoolean(inflater, false);
Field mFactory = inflaterClass.getDeclaredField("mFactory");
mFactory.setAccessible(true);
mFactory.set(inflater, null);

Method method = compatClass.getDeclaredMethod("forceSetFactory2", LayoutInflater.class, LayoutInflater.Factory2.class);
method.setAccessible(true);
BackgroundFactory factory = setDelegateFactory(context);
method.invoke(null, inflater, factory);
Field mFactory2 = inflaterClass.getDeclaredField("mFactory2");
mFactory2.setAccessible(true);
BackgroundFactory factory = new BackgroundFactory();
if (inflater.getFactory2() != null) {
factory.setInterceptFactory2(inflater.getFactory2());
} else if (inflater.getFactory() != null) {
factory.setInterceptFactory(inflater.getFactory());
}
mFactory2.set(inflater, factory);
mFactory.set(inflater, factory);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
// try {
// Field field = LayoutInflater.class.getDeclaredField("mFactorySet");
// field.setAccessible(true);
// field.setBoolean(inflater, false);
//
// BackgroundFactory factory = new BackgroundFactory();
// if (inflater.getFactory2() != null) {
// factory.setInterceptFactory2(inflater.getFactory2());
// } else if (inflater.getFactory() != null) {
// factory.setInterceptFactory(inflater.getFactory());
// }
// inflater.setFactory2(factory);
// } catch (NoSuchFieldException e) {
// e.printStackTrace();
// } catch (IllegalArgumentException e) {
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// e.printStackTrace();
// }
// LayoutInflaterCompat.setFactory2(inflater.cloneInContext(context), setDelegateFactory(context));
}
}

0 comments on commit 99a8655

Please sign in to comment.