Skip to content

Commit 99a8655

Browse files
committed
update to 1.5.6
1 parent 4ffd451 commit 99a8655

File tree

6 files changed

+33
-89
lines changed

6 files changed

+33
-89
lines changed

README-EN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ A framework for directly generating shape through Tags, no need to write shape.x
77
Add this to your app's build.gradle:
88

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

1212
if use androidx:
1313

1414
implementation "androidx.appcompat:appcompat:$supportVersion"
15-
implementation 'com.noober.background:core:1.5.5'
15+
implementation 'com.noober.background:core:1.5.6'
1616

1717

1818
## Example effect

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ A framework for directly generating shape through Tags, no need to write shape.x
1010
依赖方式:
1111

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

1515
如果项目使用了androidx:
1616

1717
implementation "androidx.appcompat:appcompat:$supportVersion"
18-
implementation 'com.noober.background:core:1.5.5'
18+
implementation 'com.noober.background:core:1.5.6'
1919

2020

2121
## 使用文档

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44

55
android {
6-
compileSdkVersion 28
6+
compileSdkVersion 29
77
defaultConfig {
88
applicationId "com.noober.backgroudlibrary"
99
minSdkVersion 14
10-
targetSdkVersion 28
10+
targetSdkVersion 29
1111
versionCode 1
1212
versionName "1.0"
1313
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -37,7 +37,7 @@ dependencies {
3737
testImplementation 'junit:junit:4.12'
3838
androidTestImplementation 'com.android.support.test:runner:1.0.2'
3939
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
40-
implementation 'com.noober.background:core:1.5.5'
40+
implementation 'com.noober.background:core:1.5.6'
4141
// implementation project(':library')
4242
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4343
}

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ext {
3636
userOrg = 'noober'
3737
groupId = 'com.noober.background'
3838
uploadName = 'LibraryForBackground'
39-
publishVersion = '1.5.5'
39+
publishVersion = '1.5.6'
4040
desc = "A framework for directly generating shape through Tags, no need to write shape.xml again(通过标签直接生成shape,无需再写shape.xml)"
4141
website = 'https://github.com/JavaNoober/BackgroundLibrary'
4242
// gradlew clean build bintrayUpload -PbintrayUser=xiaoqiandroid -PbintrayKey=xxxxxxxxxxxxxxxx -PdryRun=false

library/src/main/java/com/noober/background/BackgroundLibrary.java

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.support.v7.app.AppCompatActivity;
88
import android.support.v7.app.AppCompatDelegate;
99
import android.util.AttributeSet;
10+
import android.util.Log;
1011
import android.view.LayoutInflater;
1112
import android.view.View;
1213

@@ -36,7 +37,7 @@ public static LayoutInflater inject(Context context) {
3637
BackgroundFactory factory = setDelegateFactory(context);
3738
inflater.setFactory2(factory);
3839
} else if (!(inflater.getFactory2() instanceof BackgroundFactory)) {
39-
forceSetFactory2(inflater, context);
40+
forceSetFactory2(inflater);
4041
}
4142
return inflater;
4243
}
@@ -72,19 +73,11 @@ public static LayoutInflater inject2(Context context) {
7273
if (inflater == null) {
7374
return null;
7475
}
75-
forceSetFactory2(inflater, context);
76+
forceSetFactory2(inflater);
7677
return inflater;
7778
}
7879

79-
/**
80-
* 通过LayoutInflaterCompat去规避非SDK接口在Android Q 中的受限。
81-
* 首先:设置LayoutInflaterCompat的sCheckedField为false, 保证可以设置当前mFactory2的值
82-
* 第二:设置LayoutInflater的 mFactory 为空,保证LayoutInflaterCompat调用setFactory的时候不进行FactoryMerger操作
83-
* 第三:反射调用LayoutInflaterCompat的forceSetFactory2方法
84-
* 第四:重新设置LayoutInflater的mFactory值,防止调用Fragment的时候fragment会进行FactoryMerger操作
85-
* 经过上述步骤,在Activity以及Activity中的Fragment就会变成我们想要的factory类
86-
*/
87-
private static void forceSetFactory2(LayoutInflater inflater, Context context) {
80+
private static void forceSetFactory2(LayoutInflater inflater) {
8881
Class<LayoutInflaterCompat> compatClass = LayoutInflaterCompat.class;
8982
Class<LayoutInflater> inflaterClass = LayoutInflater.class;
9083
try {
@@ -93,40 +86,20 @@ private static void forceSetFactory2(LayoutInflater inflater, Context context) {
9386
sCheckedField.setBoolean(inflater, false);
9487
Field mFactory = inflaterClass.getDeclaredField("mFactory");
9588
mFactory.setAccessible(true);
96-
mFactory.set(inflater, null);
97-
98-
Method method = compatClass.getDeclaredMethod("forceSetFactory2", LayoutInflater.class, LayoutInflater.Factory2.class);
99-
method.setAccessible(true);
100-
BackgroundFactory factory = setDelegateFactory(context);
101-
method.invoke(null, inflater, factory);
89+
Field mFactory2 = inflaterClass.getDeclaredField("mFactory2");
90+
mFactory2.setAccessible(true);
91+
BackgroundFactory factory = new BackgroundFactory();
92+
if (inflater.getFactory2() != null) {
93+
factory.setInterceptFactory2(inflater.getFactory2());
94+
} else if (inflater.getFactory() != null) {
95+
factory.setInterceptFactory(inflater.getFactory());
96+
}
97+
mFactory2.set(inflater, factory);
10298
mFactory.set(inflater, factory);
103-
} catch (NoSuchMethodException e) {
104-
e.printStackTrace();
10599
} catch (IllegalAccessException e) {
106100
e.printStackTrace();
107-
} catch (InvocationTargetException e) {
108-
e.printStackTrace();
109101
} catch (NoSuchFieldException e) {
110102
e.printStackTrace();
111103
}
112-
// try {
113-
// Field field = LayoutInflater.class.getDeclaredField("mFactorySet");
114-
// field.setAccessible(true);
115-
// field.setBoolean(inflater, false);
116-
//
117-
// BackgroundFactory factory = new BackgroundFactory();
118-
// if (inflater.getFactory2() != null) {
119-
// factory.setInterceptFactory2(inflater.getFactory2());
120-
// } else if (inflater.getFactory() != null) {
121-
// factory.setInterceptFactory(inflater.getFactory());
122-
// }
123-
// inflater.setFactory2(factory);
124-
// } catch (NoSuchFieldException e) {
125-
// e.printStackTrace();
126-
// } catch (IllegalArgumentException e) {
127-
// e.printStackTrace();
128-
// } catch (IllegalAccessException e) {
129-
// e.printStackTrace();
130-
// }
131104
}
132105
}

libraryx/src/main/java/com/noober/background/BackgroundLibrary.java

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static LayoutInflater inject(Context context) {
3737
BackgroundFactory factory = setDelegateFactory(context);
3838
inflater.setFactory2(factory);
3939
} else if (!(inflater.getFactory2() instanceof BackgroundFactory)) {
40-
forceSetFactory2(inflater, context);
40+
forceSetFactory2(inflater);
4141
}
4242
return inflater;
4343
}
@@ -73,19 +73,11 @@ public static LayoutInflater inject2(Context context) {
7373
if (inflater == null) {
7474
return null;
7575
}
76-
forceSetFactory2(inflater, context);
76+
forceSetFactory2(inflater);
7777
return inflater;
7878
}
7979

80-
/**
81-
* 通过LayoutInflaterCompat去规避非SDK接口在Android Q 中的受限。
82-
* 首先:设置LayoutInflaterCompat的sCheckedField为false, 保证可以设置当前mFactory2的值
83-
* 第二:设置LayoutInflater的 mFactory 为空,保证LayoutInflaterCompat调用setFactory的时候不进行FactoryMerger操作
84-
* 第三:反射调用LayoutInflaterCompat的forceSetFactory2方法
85-
* 第四:重新设置LayoutInflater的mFactory值,防止调用Fragment的时候fragment会进行FactoryMerger操作
86-
* 经过上述步骤,在Activity以及Activity中的Fragment就会变成我们想要的factory类
87-
*/
88-
private static void forceSetFactory2(LayoutInflater inflater, Context context) {
80+
private static void forceSetFactory2(LayoutInflater inflater) {
8981
Class<LayoutInflaterCompat> compatClass = LayoutInflaterCompat.class;
9082
Class<LayoutInflater> inflaterClass = LayoutInflater.class;
9183
try {
@@ -94,41 +86,20 @@ private static void forceSetFactory2(LayoutInflater inflater, Context context) {
9486
sCheckedField.setBoolean(inflater, false);
9587
Field mFactory = inflaterClass.getDeclaredField("mFactory");
9688
mFactory.setAccessible(true);
97-
mFactory.set(inflater, null);
98-
99-
Method method = compatClass.getDeclaredMethod("forceSetFactory2", LayoutInflater.class, LayoutInflater.Factory2.class);
100-
method.setAccessible(true);
101-
BackgroundFactory factory = setDelegateFactory(context);
102-
method.invoke(null, inflater, factory);
89+
Field mFactory2 = inflaterClass.getDeclaredField("mFactory2");
90+
mFactory2.setAccessible(true);
91+
BackgroundFactory factory = new BackgroundFactory();
92+
if (inflater.getFactory2() != null) {
93+
factory.setInterceptFactory2(inflater.getFactory2());
94+
} else if (inflater.getFactory() != null) {
95+
factory.setInterceptFactory(inflater.getFactory());
96+
}
97+
mFactory2.set(inflater, factory);
10398
mFactory.set(inflater, factory);
104-
} catch (NoSuchMethodException e) {
105-
e.printStackTrace();
10699
} catch (IllegalAccessException e) {
107100
e.printStackTrace();
108-
} catch (InvocationTargetException e) {
109-
e.printStackTrace();
110101
} catch (NoSuchFieldException e) {
111102
e.printStackTrace();
112103
}
113-
// try {
114-
// Field field = LayoutInflater.class.getDeclaredField("mFactorySet");
115-
// field.setAccessible(true);
116-
// field.setBoolean(inflater, false);
117-
//
118-
// BackgroundFactory factory = new BackgroundFactory();
119-
// if (inflater.getFactory2() != null) {
120-
// factory.setInterceptFactory2(inflater.getFactory2());
121-
// } else if (inflater.getFactory() != null) {
122-
// factory.setInterceptFactory(inflater.getFactory());
123-
// }
124-
// inflater.setFactory2(factory);
125-
// } catch (NoSuchFieldException e) {
126-
// e.printStackTrace();
127-
// } catch (IllegalArgumentException e) {
128-
// e.printStackTrace();
129-
// } catch (IllegalAccessException e) {
130-
// e.printStackTrace();
131-
// }
132-
// LayoutInflaterCompat.setFactory2(inflater.cloneInContext(context), setDelegateFactory(context));
133104
}
134105
}

0 commit comments

Comments
 (0)