Skip to content

Commit b2fda37

Browse files
author
xiaoqi
committed
update to 2.2.6
1 parent 9473c7f commit b2fda37

13 files changed

Lines changed: 92 additions & 64 deletions

File tree

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@
2121
2.0.4 修复枚举类型保存的时候不能识别的问题
2222

2323
2.1.0 增加对PersistableBundle的支持,NeedSave注解中设置isPersistable = true则说明该参数保存到PersistableBundle
24-
24+
2.2.6 增加对自定义view的数据保存以及恢复
2525

2626
引入方式,在app的gradle中加入下面依赖即可:
2727

2828

29-
implementation 'com.noober:savehelper:2.1.0'
30-
implementation 'com.noober:savehelper-api:2.1.0'
31-
annotationProcessor 'com.noober:processor:2.1.0'
29+
implementation 'com.noober:savehelper:2.2.6'
30+
implementation 'com.noober:savehelper-api:2.2.6'
31+
annotationProcessor 'com.noober:processor:2.2.6'
3232

3333
kotlin的依赖方式
3434

3535
apply plugin: 'kotlin-kapt'
3636
apply plugin: 'kotlin-android-extensions'
3737
apply plugin: 'kotlin-android'
3838

39-
implementation 'com.noober:savehelper:2.1.0'
40-
kapt 'com.noober:processor:2.1.0'
41-
implementation 'com.noober:savehelper-api:2.1.0'
39+
implementation 'com.noober:savehelper:2.2.6'
40+
kapt 'com.noober:processor:2.2.6'
41+
implementation 'com.noober:savehelper-api:2.2.6'
4242
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
4343

4444
混淆配置:
@@ -140,6 +140,43 @@ android 内存被回收是一个开发者的常见问题。当我们**跳转到
140140

141141
这样就不会因为这种太多的重复的操作去导致代码逻辑的混乱,同时也避免了敲代码时因为key写错导致的错误。
142142

143+
自定义view的变量保存示例:
144+
145+
public class CustomView extends View {
146+
147+
@NeedSave
148+
int a;
149+
150+
public CustomView(Context context) {
151+
super(context);
152+
}
153+
154+
public CustomView(Context context, @Nullable AttributeSet attrs) {
155+
super(context, attrs);
156+
}
157+
158+
159+
public CustomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
160+
super(context, attrs, defStyleAttr);
161+
}
162+
163+
164+
@Override
165+
protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) {
166+
SaveHelper.save(this, container);
167+
super.dispatchSaveInstanceState(container);
168+
}
169+
170+
@Override
171+
protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
172+
super.dispatchRestoreInstanceState(container);
173+
SaveHelper.recover(this, container);
174+
}
175+
}
176+
177+
178+
重写dispatchSaveInstanceState,dispatchRestoreInstanceState即可。
179+
注意SaveHelper.save(this, container)要在super.dispatchSaveInstanceState(container);**之前调用**
143180
# 效果展示
144181
我们来看一下测试代码:
145182
## 不进行数据保存操作

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ allprojects {
2626
name 'Google'
2727
}
2828
}
29+
tasks.withType(Javadoc) {
30+
options.addStringOption('Xdoclint:none', '-quiet')
31+
options.addStringOption('encoding', 'UTF-8')
32+
}
2933
}
3034

3135
task clean(type: Delete) {
@@ -37,7 +41,7 @@ ext {
3741
userOrg = 'noober'
3842
groupId = 'com.noober'
3943
uploadName = 'AutoSaver'
40-
publishVersion = '2.1.1'
44+
publishVersion = '2.2.6'
4145
desc = "A light weight framework can automatically generate 'OnSaveInstanceState' code"
4246
website = 'https://github.com/JavaNoober/AutoSave'
4347
// gradlew clean build bintrayUpload -PbintrayUser=xiaoqiandroid -PbintrayKey=xxxxxxxxxxxxxxxx -PdryRun=false

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
# Specifies the JVM arguments used for the daemon process.
1111
# The setting is particularly useful for tweaking memory settings.
1212
#org.gradle.jvmargs=-Xmx1536m
13-
org.gradle.jvmargs= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
13+
#org.gradle.jvmargs= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005;
14+
org.gradle.jvmargs=-Xmx512m
1415
org.gradle.parallel=true
1516
# When configured, Gradle will run in incubating parallel mode.
1617
# This option should only be used with decoupled projects. More details, visit

sample/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ dependencies {
3131
exclude group: 'com.android.support', module: 'support-annotations'
3232
})
3333
implementation 'com.android.support:appcompat-v7:26.0.1'
34-
testImplementation 'junit:junit:4.12'
35-
implementation 'com.noober:savehelper:2.1.0'
36-
kapt 'com.noober:processor:2.1.0'
37-
implementation 'com.noober:savehelper-api:2.1.0'
34+
// testImplementation 'junit:junit:4.12'
35+
implementation 'com.noober:savehelper:2.2.6'
36+
kapt 'com.noober:processor:2.2.6'
37+
implementation 'com.noober:savehelper-api:2.2.6'
3838
// implementation project(':savehelper')
3939
// implementation project(':savehelper-api')
4040
// kapt project(':savehelper-processor')

sample/src/main/AndroidManifest.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
<activity
1111
android:name=".SampleActivity"
1212
android:persistableMode="persistAcrossReboots">
13-
14-
</activity>
15-
<activity android:name=".TestActivity"></activity>
16-
<activity android:name=".KotlinActivity">
1713
<intent-filter>
1814
<action android:name="android.intent.action.MAIN" />
1915

2016
<category android:name="android.intent.category.LAUNCHER" />
2117
</intent-filter>
2218
</activity>
19+
<activity android:name=".TestActivity"></activity>
20+
<activity android:name=".KotlinActivity">
21+
22+
</activity>
2323
</application>
2424

2525
</manifest>

sample/src/main/java/com/recover/autosavesample/CustomView.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,15 @@ public CustomView(Context context, @Nullable AttributeSet attrs, int defStyleAtt
3434
}
3535

3636

37-
@Nullable
38-
@Override
39-
protected Parcelable onSaveInstanceState() {
40-
Log.e("CustomView", "onSaveInstanceState");
41-
return super.onSaveInstanceState();
42-
}
43-
4437
@Override
4538
protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) {
46-
4739
SaveHelper.save(this, container);
48-
a = 2;
49-
50-
Bundle bundle = new Bundle();
51-
bundle.putInt("A", a);
52-
container.put(1, bundle);
5340
super.dispatchSaveInstanceState(container);
54-
Log.e("CustomView", "dispatchSaveInstanceState");
55-
}
56-
57-
@Override
58-
protected void onRestoreInstanceState(Parcelable state) {
59-
super.onRestoreInstanceState(state);
60-
Log.e("CustomView", "onRestoreInstanceState");
6141
}
6242

6343
@Override
6444
protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
6545
super.dispatchRestoreInstanceState(container);
6646
SaveHelper.recover(this, container);
67-
Bundle bundle = (Bundle) container.get(1);
68-
a = bundle.getInt("A");
69-
Log.e("CustomView", "dispatchRestoreInstanceState");
7047
}
7148
}

sample/src/main/java/com/recover/autosavesample/SampleActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ public class SampleActivity extends AppCompatActivity {
7878
// SecondSExample2 secondSExample2;
7979

8080

81+
// CustomView customView;
8182

8283
@Override
8384
protected void onCreate(Bundle savedInstanceState) {
8485
super.onCreate(savedInstanceState);
8586
setContentView(R.layout.activity_main);
87+
// customView = findViewById(R.id.view);
8688
initData();
8789
Log.e("Sample", i + "");
8890
if(savedInstanceState != null){
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout
3-
xmlns:android="http://schemas.android.com/apk/res/android"
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
43
xmlns:tools="http://schemas.android.com/tools"
54
android:id="@+id/activity_main"
65
android:layout_width="match_parent"
@@ -10,8 +9,9 @@
109
android:paddingRight="@dimen/activity_horizontal_margin"
1110
android:paddingTop="@dimen/activity_vertical_margin"
1211
tools:context="com.recover.autosavesample.SampleActivity">
13-
<com.recover.autosavesample.CustomView
14-
android:id="@+id/view"
15-
android:layout_width="match_parent"
16-
android:layout_height="match_parent" />
12+
13+
<com.recover.autosavesample.CustomView
14+
android:id="@+id/view"
15+
android:layout_width="match_parent"
16+
android:layout_height="match_parent" />
1717
</RelativeLayout>

0 commit comments

Comments
 (0)