From ffe858f2f9dc8f7599c5553a6cbfe430a692d588 Mon Sep 17 00:00:00 2001 From: zhuinden Date: Tue, 28 Feb 2017 14:20:44 +0100 Subject: [PATCH] 1.2.0: add StateBundle class for Bundleable --- .idea/codeStyleSettings.xml | 229 --- .idea/encodings.xml | 6 - .idea/markdown-navigator.xml | 67 - .../markdown-navigator/profiles_settings.xml | 3 - .idea/misc.xml | 16 - .idea/modules.xml | 2 +- CHANGELOG.md | 6 + README.md | 6 +- .../addoredittask/AddOrEditTaskPresenter.java | 9 +- .../paths/second/SecondPresenter.java | 11 +- .../paths/tasks/TasksPresenter.java | 10 +- .../paths/main/cloudsync/CloudSyncView.java | 10 +- .../AddOrEditTaskCoordinator.java | 6 +- .../addoredittask/AddOrEditTaskPresenter.java | 8 +- .../addoredittask/AddOrEditTaskView.java | 6 +- .../paths/first/FirstCoordinator.java | 8 +- .../presentation/paths/first/FirstView.java | 6 +- .../paths/second/SecondCoordinator.java | 6 +- .../paths/second/SecondPresenter.java | 8 +- .../presentation/paths/second/SecondView.java | 6 +- .../paths/tasks/TasksCoordinator.java | 6 +- .../paths/tasks/TasksPresenter.java | 8 +- .../presentation/paths/tasks/TasksView.java | 6 +- .../demo/FirstView.java | 8 +- .../simplestack/BackstackDelegate.java | 10 +- .../com/zhuinden/simplestack/Bundleable.java | 7 +- .../com/zhuinden/simplestack/SavedState.java | 11 +- .../com/zhuinden/simplestack/StateBundle.java | 1515 +++++++++++++++++ .../zhuinden/simplestack/StateBundleTest.java | 685 ++++++++ .../com/zhuinden/simplestack/TestSuite.java | 2 +- 30 files changed, 2290 insertions(+), 397 deletions(-) delete mode 100644 .idea/codeStyleSettings.xml delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/markdown-navigator.xml delete mode 100644 .idea/markdown-navigator/profiles_settings.xml create mode 100644 simple-stack/src/main/java/com/zhuinden/simplestack/StateBundle.java create mode 100644 simple-stack/src/test/java/com/zhuinden/simplestack/StateBundleTest.java diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml deleted file mode 100644 index 8d05bd4a..00000000 --- a/.idea/codeStyleSettings.xml +++ /dev/null @@ -1,229 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 97626ba4..00000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml deleted file mode 100644 index 9930bb53..00000000 --- a/.idea/markdown-navigator.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml deleted file mode 100644 index 674a5916..00000000 --- a/.idea/markdown-navigator/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index cca2cdae..fbb68289 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -43,20 +43,4 @@ - - - - - 1.8 - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index c5c4daef..d1a03eda 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,7 +3,7 @@ - + diff --git a/CHANGELOG.md b/CHANGELOG.md index c54a5602..de01cfb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change log +-Simple Stack 1.2.0 (2017-02-28) +-------------------------------- +- BREAKING CHANGE: `Bundleable` and `SavedState` now use `StateBundle` class. + +- ENHANCEMENT: Added `StateBundle` class to replace `android.os.Bundle`. + -Simple Stack 1.1.1 (2017-02-19) -------------------------------- - FIX: A bug that allowed the possibility that an uninitialized backstack could restore its history to be an empty list after process death. diff --git a/README.md b/README.md index 12fe5c8c..402ac5cb 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ In order to use Simple Stack, you need to add jitpack to your project root gradl and add the compile dependency to your module level gradle. - compile 'com.github.Zhuinden:simple-stack:1.1.1' + compile 'com.github.Zhuinden:simple-stack:1.2.0' ## How does it work? @@ -155,7 +155,7 @@ public class MainActivity - [BackstackDelegate](https://github.com/Zhuinden/simple-stack/blob/master/simple-stack/src/main/java/com/zhuinden/simplestack/BackstackDelegate.java): delegate class to hide Activity lifecycle integration, and provide view state persistence. -- [Bundleable](https://github.com/Zhuinden/simple-stack/blob/master/simple-stack/src/main/java/com/zhuinden/simplestack/Bundleable.java): interface that allows you to persist state directly from a custom View into a Bundle, using the delegate. +- [Bundleable](https://github.com/Zhuinden/simple-stack/blob/master/simple-stack/src/main/java/com/zhuinden/simplestack/Bundleable.java): interface that allows you to persist state directly from a custom View into a StateBundle, using the delegate. - [HistoryBuilder](https://github.com/Zhuinden/simple-stack/blob/master/simple-stack/src/main/java/com/zhuinden/simplestack/HistoryBuilder.java): Convenience class for building `ArrayList`. @@ -165,6 +165,8 @@ public class MainActivity - [PendingStateChange](https://github.com/Zhuinden/simple-stack/blob/master/simple-stack/src/main/java/com/zhuinden/simplestack/PendingStateChange.java): represents a change that will occur when possible. +- [StateBundle](https://github.com/Zhuinden/simple-stack/blob/master/simple-stack/src/main/java/com/zhuinden/simplestack/StateBundle.java): a class which works as a state storage, a replacement for `android.os.Bundle`. + - [StateChanger](https://github.com/Zhuinden/simple-stack/blob/master/simple-stack/src/main/java/com/zhuinden/simplestack/StateChanger.java): interface for a class that listens to changes inside the Backstack. - [StateChange](https://github.com/Zhuinden/simple-stack/blob/master/simple-stack/src/main/java/com/zhuinden/simplestack/StateChange.java): represents a state change inside the backstack, providing previous state, new state, and the direction of the change. diff --git a/simple-stack-example-fragments/src/main/java/com/zhuinden/simplestackdemoexamplefragments/presentation/paths/addoredittask/AddOrEditTaskPresenter.java b/simple-stack-example-fragments/src/main/java/com/zhuinden/simplestackdemoexamplefragments/presentation/paths/addoredittask/AddOrEditTaskPresenter.java index 40297906..765aa8ef 100644 --- a/simple-stack-example-fragments/src/main/java/com/zhuinden/simplestackdemoexamplefragments/presentation/paths/addoredittask/AddOrEditTaskPresenter.java +++ b/simple-stack-example-fragments/src/main/java/com/zhuinden/simplestackdemoexamplefragments/presentation/paths/addoredittask/AddOrEditTaskPresenter.java @@ -1,11 +1,11 @@ package com.zhuinden.simplestackdemoexamplefragments.presentation.paths.addoredittask; -import android.os.Bundle; import android.support.annotation.Nullable; import com.zhuinden.simplestack.Backstack; import com.zhuinden.simplestack.Bundleable; import com.zhuinden.simplestack.HistoryBuilder; +import com.zhuinden.simplestack.StateBundle; import com.zhuinden.simplestack.StateChange; import com.zhuinden.simplestackdemoexamplefragments.data.repository.TaskRepository; import com.zhuinden.simplestackdemoexamplefragments.presentation.objects.Task; @@ -78,15 +78,16 @@ protected void onDetach(AddOrEditTaskFragment coordinator) { } - public Bundle toBundle() { - Bundle bundle = new Bundle(); + @Override + public StateBundle toBundle() { + StateBundle bundle = new StateBundle(); bundle.putString("title", title); bundle.putString("description", description); return bundle; } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { title = bundle.getString("title"); description = bundle.getString("description"); diff --git a/simple-stack-example-fragments/src/main/java/com/zhuinden/simplestackdemoexamplefragments/presentation/paths/second/SecondPresenter.java b/simple-stack-example-fragments/src/main/java/com/zhuinden/simplestackdemoexamplefragments/presentation/paths/second/SecondPresenter.java index b9878cd2..7be7624d 100644 --- a/simple-stack-example-fragments/src/main/java/com/zhuinden/simplestackdemoexamplefragments/presentation/paths/second/SecondPresenter.java +++ b/simple-stack-example-fragments/src/main/java/com/zhuinden/simplestackdemoexamplefragments/presentation/paths/second/SecondPresenter.java @@ -1,11 +1,12 @@ package com.zhuinden.simplestackdemoexamplefragments.presentation.paths.second; -import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.jakewharton.rxrelay.BehaviorRelay; import com.zhuinden.simplestack.Backstack; import com.zhuinden.simplestack.Bundleable; +import com.zhuinden.simplestack.StateBundle; import com.zhuinden.simplestackdemoexamplefragments.presentation.paths.tasks.TasksKey; import com.zhuinden.simplestackdemoexamplefragments.util.BasePresenter; @@ -52,14 +53,16 @@ public void goToTodos() { backstack.goTo(TasksKey.create()); } - public Bundle toBundle() { - Bundle bundle = new Bundle(); + @Override + @NonNull + public StateBundle toBundle() { + StateBundle bundle = new StateBundle(); bundle.putString("state", state.getValue()); return bundle; } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { state.call(bundle.getString("state")); } diff --git a/simple-stack-example-fragments/src/main/java/com/zhuinden/simplestackdemoexamplefragments/presentation/paths/tasks/TasksPresenter.java b/simple-stack-example-fragments/src/main/java/com/zhuinden/simplestackdemoexamplefragments/presentation/paths/tasks/TasksPresenter.java index 66e1dad2..f754d9e6 100644 --- a/simple-stack-example-fragments/src/main/java/com/zhuinden/simplestackdemoexamplefragments/presentation/paths/tasks/TasksPresenter.java +++ b/simple-stack-example-fragments/src/main/java/com/zhuinden/simplestackdemoexamplefragments/presentation/paths/tasks/TasksPresenter.java @@ -1,12 +1,13 @@ package com.zhuinden.simplestackdemoexamplefragments.presentation.paths.tasks; import android.content.res.Resources; -import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.jakewharton.rxrelay.BehaviorRelay; import com.zhuinden.simplestack.Backstack; import com.zhuinden.simplestack.Bundleable; +import com.zhuinden.simplestack.StateBundle; import com.zhuinden.simplestackdemoexamplefragments.application.Key; import com.zhuinden.simplestackdemoexamplefragments.data.repository.TaskRepository; import com.zhuinden.simplestackdemoexamplefragments.presentation.objects.Task; @@ -94,14 +95,15 @@ public void setFiltering(TasksFilterType filterType) { } @Override - public Bundle toBundle() { - Bundle bundle = new Bundle(); + @NonNull + public StateBundle toBundle() { + StateBundle bundle = new StateBundle(); bundle.putString("FILTERING", filterType.getValue().name()); return bundle; } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { filterType.call(TasksFilterType.valueOf(bundle.getString("FILTERING"))); } diff --git a/simple-stack-example-multistack/src/main/java/com/zhuinden/simplestackdemomultistack/presentation/paths/main/cloudsync/CloudSyncView.java b/simple-stack-example-multistack/src/main/java/com/zhuinden/simplestackdemomultistack/presentation/paths/main/cloudsync/CloudSyncView.java index 040428d2..27462854 100644 --- a/simple-stack-example-multistack/src/main/java/com/zhuinden/simplestackdemomultistack/presentation/paths/main/cloudsync/CloudSyncView.java +++ b/simple-stack-example-multistack/src/main/java/com/zhuinden/simplestackdemomultistack/presentation/paths/main/cloudsync/CloudSyncView.java @@ -2,7 +2,7 @@ import android.annotation.TargetApi; import android.content.Context; -import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.util.Log; @@ -11,6 +11,7 @@ import com.zhuinden.simplestack.Backstack; import com.zhuinden.simplestack.Bundleable; +import com.zhuinden.simplestack.StateBundle; import com.zhuinden.simplestackdemomultistack.R; import com.zhuinden.simplestackdemomultistack.application.Key; import com.zhuinden.simplestackdemomultistack.presentation.paths.main.cloudsync.another.AnotherKey; @@ -68,14 +69,15 @@ protected void onFinishInflate() { } @Override - public Bundle toBundle() { - Bundle bundle = new Bundle(); + @NonNull + public StateBundle toBundle() { + StateBundle bundle = new StateBundle(); bundle.putString("HELLO", "WORLD"); return bundle; } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { Log.i(TAG, bundle.getString("HELLO")); } diff --git a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/addoredittask/AddOrEditTaskCoordinator.java b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/addoredittask/AddOrEditTaskCoordinator.java index ef74e551..2f07f611 100644 --- a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/addoredittask/AddOrEditTaskCoordinator.java +++ b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/addoredittask/AddOrEditTaskCoordinator.java @@ -1,12 +1,12 @@ package com.zhuinden.simplestackdemoexamplemvp.presentation.paths.addoredittask; -import android.os.Bundle; import android.support.annotation.Nullable; import android.text.Editable; import android.view.View; import android.widget.EditText; import com.zhuinden.simplestack.Bundleable; +import com.zhuinden.simplestack.StateBundle; import com.zhuinden.simplestackdemoexamplemvp.R; import com.zhuinden.simplestackdemoexamplemvp.util.BaseCoordinator; @@ -72,12 +72,12 @@ public void navigateBack() { } @Override - public Bundle toBundle() { + public StateBundle toBundle() { return addOrEditTaskPresenter.toBundle(); } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { addOrEditTaskPresenter.fromBundle(bundle); } diff --git a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/addoredittask/AddOrEditTaskPresenter.java b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/addoredittask/AddOrEditTaskPresenter.java index 88b62d88..edb45beb 100644 --- a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/addoredittask/AddOrEditTaskPresenter.java +++ b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/addoredittask/AddOrEditTaskPresenter.java @@ -1,11 +1,11 @@ package com.zhuinden.simplestackdemoexamplemvp.presentation.paths.addoredittask; -import android.os.Bundle; import android.support.annotation.Nullable; import com.zhuinden.simplestack.Backstack; import com.zhuinden.simplestack.Bundleable; import com.zhuinden.simplestack.HistoryBuilder; +import com.zhuinden.simplestack.StateBundle; import com.zhuinden.simplestack.StateChange; import com.zhuinden.simplestackdemoexamplemvp.data.repository.TaskRepository; import com.zhuinden.simplestackdemoexamplemvp.presentation.objects.Task; @@ -78,15 +78,15 @@ protected void onDetach(AddOrEditTaskCoordinator coordinator) { } - public Bundle toBundle() { - Bundle bundle = new Bundle(); + public StateBundle toBundle() { + StateBundle bundle = new StateBundle(); bundle.putString("title", title); bundle.putString("description", description); return bundle; } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { title = bundle.getString("title"); description = bundle.getString("description"); diff --git a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/addoredittask/AddOrEditTaskView.java b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/addoredittask/AddOrEditTaskView.java index 77837eac..aa9dfc7f 100644 --- a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/addoredittask/AddOrEditTaskView.java +++ b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/addoredittask/AddOrEditTaskView.java @@ -2,13 +2,13 @@ import android.annotation.TargetApi; import android.content.Context; -import android.os.Bundle; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.widget.ScrollView; import com.squareup.coordinators.Coordinators; import com.zhuinden.simplestack.Bundleable; +import com.zhuinden.simplestack.StateBundle; /** * Created by Owner on 2017. 01. 26.. @@ -35,13 +35,13 @@ public AddOrEditTaskView(Context context, AttributeSet attrs, int defStyleAttr, } @Override - public Bundle toBundle() { + public StateBundle toBundle() { AddOrEditTaskCoordinator coordinator = Coordinators.getCoordinator(this); return coordinator.toBundle(); } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { AddOrEditTaskCoordinator coordinator = Coordinators.getCoordinator(this); coordinator.fromBundle(bundle); } diff --git a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/first/FirstCoordinator.java b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/first/FirstCoordinator.java index 1e92b4c2..793d8051 100644 --- a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/first/FirstCoordinator.java +++ b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/first/FirstCoordinator.java @@ -1,11 +1,11 @@ package com.zhuinden.simplestackdemoexamplemvp.presentation.paths.first; -import android.os.Bundle; import android.support.annotation.Nullable; import android.util.Log; import android.view.View; import com.zhuinden.simplestack.Bundleable; +import com.zhuinden.simplestack.StateBundle; import com.zhuinden.simplestackdemoexamplemvp.R; import com.zhuinden.simplestackdemoexamplemvp.util.BaseCoordinator; @@ -52,14 +52,14 @@ protected Unbinder bindViews(View view) { } @Override - public Bundle toBundle() { - Bundle bundle = new Bundle(); + public StateBundle toBundle() { + StateBundle bundle = new StateBundle(); bundle.putString("HELLO", "WORLD"); return bundle; } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { Log.i(TAG, bundle.getString("HELLO")); } diff --git a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/first/FirstView.java b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/first/FirstView.java index 896bbf45..6a3c64d9 100644 --- a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/first/FirstView.java +++ b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/first/FirstView.java @@ -2,7 +2,6 @@ import android.annotation.TargetApi; import android.content.Context; -import android.os.Bundle; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.widget.RelativeLayout; @@ -10,6 +9,7 @@ import com.squareup.coordinators.Coordinators; import com.zhuinden.simplestack.Backstack; import com.zhuinden.simplestack.Bundleable; +import com.zhuinden.simplestack.StateBundle; import com.zhuinden.simplestackdemoexamplemvp.application.CustomApplication; import javax.inject.Inject; @@ -57,13 +57,13 @@ private void init(Context context) { } @Override - public Bundle toBundle() { + public StateBundle toBundle() { FirstCoordinator firstCoordinator = Coordinators.getCoordinator(this); return firstCoordinator.toBundle(); } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { FirstCoordinator firstCoordinator = Coordinators.getCoordinator(this); firstCoordinator.fromBundle(bundle); } diff --git a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/second/SecondCoordinator.java b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/second/SecondCoordinator.java index fe0c6773..65be4cce 100644 --- a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/second/SecondCoordinator.java +++ b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/second/SecondCoordinator.java @@ -1,12 +1,12 @@ package com.zhuinden.simplestackdemoexamplemvp.presentation.paths.second; -import android.os.Bundle; import android.support.annotation.Nullable; import android.text.Editable; import android.view.View; import android.widget.EditText; import com.zhuinden.simplestack.Bundleable; +import com.zhuinden.simplestack.StateBundle; import com.zhuinden.simplestackdemoexamplemvp.R; import com.zhuinden.simplestackdemoexamplemvp.util.BaseCoordinator; @@ -63,12 +63,12 @@ protected Unbinder bindViews(View view) { } @Override - public Bundle toBundle() { + public StateBundle toBundle() { return secondPresenter.toBundle(); } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { secondPresenter.fromBundle(bundle); } diff --git a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/second/SecondPresenter.java b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/second/SecondPresenter.java index 04e0bfb8..8f937daf 100644 --- a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/second/SecondPresenter.java +++ b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/second/SecondPresenter.java @@ -1,11 +1,11 @@ package com.zhuinden.simplestackdemoexamplemvp.presentation.paths.second; -import android.os.Bundle; import android.support.annotation.Nullable; import com.jakewharton.rxrelay.BehaviorRelay; import com.zhuinden.simplestack.Backstack; import com.zhuinden.simplestack.Bundleable; +import com.zhuinden.simplestack.StateBundle; import com.zhuinden.simplestackdemoexamplemvp.presentation.paths.tasks.TasksKey; import com.zhuinden.simplestackdemoexamplemvp.util.BasePresenter; @@ -51,14 +51,14 @@ public void goToTodos() { backstack.goTo(TasksKey.create()); } - public Bundle toBundle() { - Bundle bundle = new Bundle(); + public StateBundle toBundle() { + StateBundle bundle = new StateBundle(); bundle.putString("state", state.getValue()); return bundle; } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { } diff --git a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/second/SecondView.java b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/second/SecondView.java index 3595b5bd..a74c7da7 100644 --- a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/second/SecondView.java +++ b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/second/SecondView.java @@ -2,7 +2,6 @@ import android.annotation.TargetApi; import android.content.Context; -import android.os.Bundle; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.widget.RelativeLayout; @@ -10,6 +9,7 @@ import com.squareup.coordinators.Coordinators; import com.zhuinden.simplestack.Backstack; import com.zhuinden.simplestack.Bundleable; +import com.zhuinden.simplestack.StateBundle; import com.zhuinden.simplestackdemoexamplemvp.application.CustomApplication; import javax.inject.Inject; @@ -55,13 +55,13 @@ private void init(Context context) { SecondKey secondKey; @Override - public Bundle toBundle() { + public StateBundle toBundle() { SecondCoordinator coordinator = Coordinators.getCoordinator(this); return coordinator.toBundle(); } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { SecondCoordinator coordinator = Coordinators.getCoordinator(this); coordinator.fromBundle(bundle); } diff --git a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/tasks/TasksCoordinator.java b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/tasks/TasksCoordinator.java index a64122cc..5cde8422 100644 --- a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/tasks/TasksCoordinator.java +++ b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/tasks/TasksCoordinator.java @@ -1,7 +1,6 @@ package com.zhuinden.simplestackdemoexamplemvp.presentation.paths.tasks; import android.content.res.Resources; -import android.os.Bundle; import android.support.annotation.Nullable; import android.support.design.widget.Snackbar; import android.support.v4.content.ContextCompat; @@ -15,6 +14,7 @@ import android.widget.TextView; import com.zhuinden.simplestack.Bundleable; +import com.zhuinden.simplestack.StateBundle; import com.zhuinden.simplestackdemoexamplemvp.R; import com.zhuinden.simplestackdemoexamplemvp.application.MainActivity; import com.zhuinden.simplestackdemoexamplemvp.presentation.objects.Task; @@ -254,12 +254,12 @@ public void setFilterLabelText(int filterText) { } @Override - public Bundle toBundle() { + public StateBundle toBundle() { return tasksPresenter.toBundle(); } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { tasksPresenter.fromBundle(bundle); } diff --git a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/tasks/TasksPresenter.java b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/tasks/TasksPresenter.java index c8e270ba..d5e2eb82 100644 --- a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/tasks/TasksPresenter.java +++ b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/tasks/TasksPresenter.java @@ -1,12 +1,12 @@ package com.zhuinden.simplestackdemoexamplemvp.presentation.paths.tasks; import android.content.res.Resources; -import android.os.Bundle; import android.support.annotation.Nullable; import com.jakewharton.rxrelay.BehaviorRelay; import com.zhuinden.simplestack.Backstack; import com.zhuinden.simplestack.Bundleable; +import com.zhuinden.simplestack.StateBundle; import com.zhuinden.simplestackdemoexamplemvp.data.repository.TaskRepository; import com.zhuinden.simplestackdemoexamplemvp.presentation.objects.Task; import com.zhuinden.simplestackdemoexamplemvp.presentation.paths.addoredittask.AddOrEditTaskKey; @@ -97,14 +97,14 @@ public void setFiltering(TasksFilterType filterType) { } @Override - public Bundle toBundle() { - Bundle bundle = new Bundle(); + public StateBundle toBundle() { + StateBundle bundle = new StateBundle(); bundle.putString("FILTERING", filterType.getValue().name()); return bundle; } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { filterType.call(TasksFilterType.valueOf(bundle.getString("FILTERING"))); } diff --git a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/tasks/TasksView.java b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/tasks/TasksView.java index b2798fe6..2e4aa908 100644 --- a/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/tasks/TasksView.java +++ b/simple-stack-example-mvp/src/main/java/com/zhuinden/simplestackdemoexamplemvp/presentation/paths/tasks/TasksView.java @@ -1,13 +1,13 @@ package com.zhuinden.simplestackdemoexamplemvp.presentation.paths.tasks; import android.content.Context; -import android.os.Bundle; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.MenuItem; import com.squareup.coordinators.Coordinators; import com.zhuinden.simplestack.Bundleable; +import com.zhuinden.simplestack.StateBundle; import com.zhuinden.simplestack.StateChange; import com.zhuinden.simplestack.StateChanger; import com.zhuinden.simplestackdemoexamplemvp.R; @@ -63,13 +63,13 @@ public void handleStateChange(StateChange stateChange, Callback completionCallba } @Override - public Bundle toBundle() { + public StateBundle toBundle() { TasksCoordinator coordinator = Coordinators.getCoordinator(this); return coordinator.toBundle(); } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { TasksCoordinator coordinator = Coordinators.getCoordinator(this); coordinator.fromBundle(bundle); } diff --git a/simple-stack-example/src/main/java/com/zhuinden/simplestackdemoexample/demo/FirstView.java b/simple-stack-example/src/main/java/com/zhuinden/simplestackdemoexample/demo/FirstView.java index 20fb84eb..c7e102f6 100644 --- a/simple-stack-example/src/main/java/com/zhuinden/simplestackdemoexample/demo/FirstView.java +++ b/simple-stack-example/src/main/java/com/zhuinden/simplestackdemoexample/demo/FirstView.java @@ -2,7 +2,6 @@ import android.annotation.TargetApi; import android.content.Context; -import android.os.Bundle; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.util.Log; @@ -11,6 +10,7 @@ import com.zhuinden.simplestack.Backstack; import com.zhuinden.simplestack.Bundleable; +import com.zhuinden.simplestack.StateBundle; import com.zhuinden.simplestackdemoexample.R; import butterknife.ButterKnife; @@ -68,14 +68,14 @@ protected void onFinishInflate() { } @Override - public Bundle toBundle() { - Bundle bundle = new Bundle(); + public StateBundle toBundle() { + StateBundle bundle = new StateBundle(); bundle.putString("HELLO", "WORLD"); return bundle; } @Override - public void fromBundle(@Nullable Bundle bundle) { + public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { Log.i(TAG, bundle.getString("HELLO")); } diff --git a/simple-stack/src/main/java/com/zhuinden/simplestack/BackstackDelegate.java b/simple-stack/src/main/java/com/zhuinden/simplestack/BackstackDelegate.java index f037ef0a..0b0f1a29 100644 --- a/simple-stack/src/main/java/com/zhuinden/simplestack/BackstackDelegate.java +++ b/simple-stack/src/main/java/com/zhuinden/simplestack/BackstackDelegate.java @@ -39,7 +39,7 @@ private static class ParcelledState implements Parcelable { Parcelable parcelableKey; SparseArray viewHierarchyState; - Bundle bundle; + StateBundle bundle; private ParcelledState() { } @@ -50,7 +50,7 @@ protected ParcelledState(Parcel in) { viewHierarchyState = in.readSparseArray(getClass().getClassLoader()); boolean hasBundle = in.readByte() > 0; if(hasBundle) { - bundle = in.readBundle(getClass().getClassLoader()); + bundle = in.readParcelable(getClass().getClassLoader()); } } @@ -79,7 +79,7 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeSparseArray(sparseArray); dest.writeByte(bundle != null ? (byte) 0x01 : 0x00); if(bundle != null) { - dest.writeBundle(bundle); + dest.writeParcelable(bundle, 0); } } @@ -352,7 +352,7 @@ public Backstack getBackstack() { // ----- viewstate persistence /** - * Provides the means to save the provided view's hierarchy state, and its optional bundle via {@link Bundleable} into a {@link SavedState}. + * Provides the means to save the provided view's hierarchy state, and its optional {@link StateBundle} via {@link Bundleable} into a {@link SavedState}. * * @param view the view that belongs to a certain key */ @@ -364,7 +364,7 @@ public void persistViewToState(@Nullable View view) { } SparseArray viewHierarchyState = new SparseArray<>(); view.saveHierarchyState(viewHierarchyState); - Bundle bundle = null; + StateBundle bundle = null; if(view instanceof Bundleable) { bundle = ((Bundleable) view).toBundle(); } diff --git a/simple-stack/src/main/java/com/zhuinden/simplestack/Bundleable.java b/simple-stack/src/main/java/com/zhuinden/simplestack/Bundleable.java index 9c1b4cd5..9ef83f12 100644 --- a/simple-stack/src/main/java/com/zhuinden/simplestack/Bundleable.java +++ b/simple-stack/src/main/java/com/zhuinden/simplestack/Bundleable.java @@ -15,19 +15,18 @@ */ package com.zhuinden.simplestack; -import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.view.View; /** - * Specifies that the custom view that implements this also places its persisted state into a Bundle. + * Specifies that the custom view that implements this also places its persisted state into a {@link StateBundle}. * * This is used by {@link BackstackDelegate#persistViewToState(View)} and {@link BackstackDelegate#restoreViewFromState(View)}. */ public interface Bundleable { @NonNull - Bundle toBundle(); + StateBundle toBundle(); - void fromBundle(@Nullable Bundle bundle); + void fromBundle(@Nullable StateBundle bundle); } diff --git a/simple-stack/src/main/java/com/zhuinden/simplestack/SavedState.java b/simple-stack/src/main/java/com/zhuinden/simplestack/SavedState.java index 7cc5b250..5e1fd217 100644 --- a/simple-stack/src/main/java/com/zhuinden/simplestack/SavedState.java +++ b/simple-stack/src/main/java/com/zhuinden/simplestack/SavedState.java @@ -15,7 +15,6 @@ */ package com.zhuinden.simplestack; -import android.os.Bundle; import android.os.Parcelable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -30,7 +29,7 @@ public class SavedState { private Object key; private SparseArray viewHierarchyState; - private Bundle bundle; + private StateBundle bundle; private SavedState() { } @@ -47,11 +46,11 @@ public void setViewHierarchyState(SparseArray viewHierarchyState) { this.viewHierarchyState = viewHierarchyState; } - public Bundle getBundle() { + public StateBundle getBundle() { return bundle; } - public void setBundle(Bundle bundle) { + public void setBundle(StateBundle bundle) { this.bundle = bundle; } @@ -67,7 +66,7 @@ public static Builder builder() { public static class Builder { private Object key; private SparseArray viewHierarchyState = new SparseArray<>(); - private Bundle bundle; + private StateBundle bundle; Builder() { } @@ -88,7 +87,7 @@ public Builder setViewHierarchyState(@NonNull SparseArray viewHierar return this; } - public Builder setBundle(@Nullable Bundle bundle) { + public Builder setBundle(@Nullable StateBundle bundle) { this.bundle = bundle; return this; } diff --git a/simple-stack/src/main/java/com/zhuinden/simplestack/StateBundle.java b/simple-stack/src/main/java/com/zhuinden/simplestack/StateBundle.java new file mode 100644 index 00000000..85416201 --- /dev/null +++ b/simple-stack/src/main/java/com/zhuinden/simplestack/StateBundle.java @@ -0,0 +1,1515 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.zhuinden.simplestack; + +import android.os.Parcel; +import android.os.Parcelable; +import android.support.annotation.Nullable; +import android.util.SparseArray; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; + +/** + * Parcelable representation of Bundle, independent from the Android framework. + * + * Used as the contract for {@link Bundleable}. + */ +public class StateBundle + implements Parcelable { + static class TypeElement + implements Parcelable { + String key; + int type; + + TypeElement() { + } + + TypeElement(String key, int type) { + this.key = key; + this.type = type; + } + + protected TypeElement(Parcel in) { + key = in.readString(); + type = in.readInt(); + } + + public static final Creator CREATOR = new Creator() { + @Override + public TypeElement createFromParcel(Parcel in) { + return new TypeElement(in); + } + + @Override + public TypeElement[] newArray(int size) { + return new TypeElement[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(key); + dest.writeInt(type); + } + } + + static final int type_boolean = 0; + static final int type_byte = 1; + static final int type_char = 2; + static final int type_short = 3; + static final int type_int = 4; + static final int type_long = 5; + static final int type_float = 6; + static final int type_double = 7; + static final int type_String = 8; + static final int type_CharSequence = 9; + static final int type_Serializable = 10; + static final int type_IntegerArrayList = 11; + static final int type_StringArrayList = 12; + static final int type_CharSequenceArrayList = 13; + static final int type_BooleanArray = 14; + static final int type_ByteArray = 15; + static final int type_ShortArray = 16; + static final int type_CharArray = 17; + static final int type_IntArray = 18; + static final int type_LongArray = 19; + static final int type_FloatArray = 20; + static final int type_DoubleArray = 21; + + static final int type_StateBundle = 26; + static final int type_Parcelable = 27; + static final int type_ParcelableArrayList = 29; + static final int type_SparseParcelableArray = 30; + + //static final int type_StringArray = 22; + //static final int type_CharSequenceArray = 23; + //static final int type_ParcelableArray = 28; + //static final int type_Size = 24; + //static final int type_SizeF = 25; + + private static final String TAG = "StateBundle"; + + Map map = new LinkedHashMap<>(); + Map typeMap = new LinkedHashMap<>(); + + /** + * Constructs a new, empty Bundle. + */ + public StateBundle() { + } + + /** + * Constructs a Bundle containing a copy of the mappings from the given + * Bundle. + * + * @param bundle a Bundle to be copied. + */ + public StateBundle(StateBundle bundle) { + putAll(bundle); + } + + protected StateBundle(Parcel in) { + int size = in.readInt(); + for(int i = 0; i < size; i++) { + TypeElement typeElement = in.readParcelable(TypeElement.class.getClassLoader()); + Object object = in.readValue(getClass().getClassLoader()); + switch(typeElement.type) { + case type_boolean: + putBoolean(typeElement.key, (Boolean) object); + break; + case type_byte: + putByte(typeElement.key, (Byte) object); + break; + case type_char: + putChar(typeElement.key, (Character) object); + break; + case type_short: + putShort(typeElement.key, (Short) object); + break; + case type_int: + putInt(typeElement.key, (Integer) object); + break; + case type_long: + putLong(typeElement.key, (Long) object); + break; + case type_float: + putFloat(typeElement.key, (Float) object); + break; + case type_double: + putDouble(typeElement.key, (Double) object); + break; + case type_String: + putString(typeElement.key, (String) object); + break; + case type_CharSequence: + putCharSequence(typeElement.key, (CharSequence) object); + break; + case type_Serializable: + putSerializable(typeElement.key, (Serializable) object); + break; + case type_IntegerArrayList: + putIntegerArrayList(typeElement.key, (ArrayList) object); + break; + case type_StringArrayList: + putStringArrayList(typeElement.key, (ArrayList) object); + break; + case type_CharSequenceArrayList: + putCharSequenceArrayList(typeElement.key, (ArrayList) object); + break; + case type_BooleanArray: + putBooleanArray(typeElement.key, (boolean[]) object); + break; + case type_ByteArray: + putByteArray(typeElement.key, (byte[]) object); + break; + case type_ShortArray: + putShortArray(typeElement.key, (short[]) object); + break; + case type_CharArray: + putCharArray(typeElement.key, (char[]) object); + break; + case type_IntArray: + putIntArray(typeElement.key, (int[]) object); + break; + case type_LongArray: + putLongArray(typeElement.key, (long[]) object); + break; + case type_FloatArray: + putFloatArray(typeElement.key, (float[]) object); + break; + case type_DoubleArray: + putDoubleArray(typeElement.key, (double[]) object); + break; + case type_StateBundle: + putBundle(typeElement.key, (StateBundle) object); + break; + case type_Parcelable: + putParcelable(typeElement.key, (Parcelable) object); + break; + case type_ParcelableArrayList: + putParcelableArrayList(typeElement.key, (ArrayList) object); + break; + case type_SparseParcelableArray: + putSparseParcelableArray(typeElement.key, (SparseArray) object); + break; + } + } + } + + public static final Creator CREATOR = new Creator() { + @Override + public StateBundle createFromParcel(Parcel in) { + return new StateBundle(in); + } + + @Override + public StateBundle[] newArray(int size) { + return new StateBundle[size]; + } + }; + + /** + * Returns the number of mappings contained in this Bundle. + * + * @return the number of mappings as an int. + */ + public int size() { + return map.size(); + } + + /** + * Returns true if the mapping of this Bundle is empty, false otherwise. + */ + public boolean isEmpty() { + return map.isEmpty(); + } + + /** + * Removes all elements from the mapping of this Bundle. + */ + public void clear() { + map.clear(); + typeMap.clear(); + } + + /** + * Returns true if the given key is contained in the mapping + * of this Bundle. + * + * @param key a String key + * @return true if the key is part of the mapping, false otherwise + */ + public boolean containsKey(String key) { + return map.containsKey(key); + } + + /** + * Returns the entry with the given key as an object. + * + * @param key a String key + * @return an Object, or null + */ + @Nullable + public Object get(String key) { + return map.get(key); + } + + /** + * Removes any entry with the given key from the mapping of this Bundle. + * + * @param key a String key + */ + public void remove(String key) { + map.remove(key); + typeMap.remove(key); + } + + /** + * Inserts all mappings from the given StateBundle into this StateBundle. + * + * @param bundle a {@link StateBundle} + */ + public void putAll(StateBundle bundle) { + if(bundle.map != null) { + map.putAll(bundle.map); + typeMap.putAll(bundle.typeMap); + } + } + + /** + * Returns a Set containing the Strings used as keys in this Bundle. + * + * @return a Set of String keys + */ + public Set keySet() { + return map.keySet(); + } + + /** + * Inserts a Boolean value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a boolean + */ + public void putBoolean(@Nullable String key, boolean value) { + map.put(key, value); + typeMap.put(key, type_boolean); + } + + /** + * Inserts a byte value into the mapping of this Bundle, replacing + * any existing value for the given key. + * + * @param key a String, or null + * @param value a byte + */ + public void putByte(@Nullable String key, byte value) { + map.put(key, value); + typeMap.put(key, type_byte); + } + + /** + * Inserts a char value into the mapping of this Bundle, replacing + * any existing value for the given key. + * + * @param key a String, or null + * @param value a char + */ + public void putChar(@Nullable String key, char value) { + map.put(key, value); + typeMap.put(key, type_char); + } + + /** + * Inserts a short value into the mapping of this Bundle, replacing + * any existing value for the given key. + * + * @param key a String, or null + * @param value a short + */ + public void putShort(@Nullable String key, short value) { + map.put(key, value); + typeMap.put(key, type_short); + } + + /** + * Inserts an int value into the mapping of this Bundle, replacing + * any existing value for the given key. + * + * @param key a String, or null + * @param value an int + */ + public void putInt(@Nullable String key, int value) { + map.put(key, value); + typeMap.put(key, type_int); + } + + /** + * Inserts a long value into the mapping of this Bundle, replacing + * any existing value for the given key. + * + * @param key a String, or null + * @param value a long + */ + public void putLong(@Nullable String key, long value) { + map.put(key, value); + typeMap.put(key, type_long); + } + + /** + * Inserts a float value into the mapping of this Bundle, replacing + * any existing value for the given key. + * + * @param key a String, or null + * @param value a float + */ + public void putFloat(@Nullable String key, float value) { + map.put(key, value); + typeMap.put(key, type_float); + } + + /** + * Inserts a double value into the mapping of this Bundle, replacing + * any existing value for the given key. + * + * @param key a String, or null + * @param value a double + */ + public void putDouble(@Nullable String key, double value) { + map.put(key, value); + typeMap.put(key, type_double); + } + + /** + * Inserts a String value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a String, or null + */ + public void putString(@Nullable String key, @Nullable String value) { + map.put(key, value); + typeMap.put(key, type_String); + } + + /** + * Inserts a CharSequence value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a CharSequence, or null + */ + public void putCharSequence(@Nullable String key, @Nullable CharSequence value) { + map.put(key, value); + typeMap.put(key, type_CharSequence); + } + + /** + * Inserts an ArrayList value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value an ArrayList object, or null + */ + public void putIntegerArrayList(@Nullable String key, @Nullable ArrayList value) { + map.put(key, value); + typeMap.put(key, type_IntegerArrayList); + } + + /** + * Inserts an ArrayList value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value an ArrayList object, or null + */ + public void putStringArrayList(@Nullable String key, @Nullable ArrayList value) { + map.put(key, value); + typeMap.put(key, type_StringArrayList); + } + + /** + * Inserts an ArrayList value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value an ArrayList object, or null + */ + public void putCharSequenceArrayList(@Nullable String key, @Nullable ArrayList value) { + map.put(key, value); + typeMap.put(key, type_CharSequenceArrayList); + } + + /** + * Inserts a Serializable value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a Serializable object, or null + */ + public void putSerializable(@Nullable String key, @Nullable Serializable value) { + map.put(key, value); + typeMap.put(key, type_Serializable); + } + + /** + * Inserts a boolean array value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a boolean array object, or null + */ + public void putBooleanArray(@Nullable String key, @Nullable boolean[] value) { + map.put(key, value); + typeMap.put(key, type_BooleanArray); + } + + /** + * Inserts a byte array value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a byte array object, or null + */ + public void putByteArray(@Nullable String key, @Nullable byte[] value) { + map.put(key, value); + typeMap.put(key, type_ByteArray); + } + + /** + * Inserts a short array value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a short array object, or null + */ + public void putShortArray(@Nullable String key, @Nullable short[] value) { + map.put(key, value); + typeMap.put(key, type_ShortArray); + } + + /** + * Inserts a char array value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a char array object, or null + */ + public void putCharArray(@Nullable String key, @Nullable char[] value) { + map.put(key, value); + typeMap.put(key, type_CharArray); + } + + /** + * Inserts an int array value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value an int array object, or null + */ + public void putIntArray(@Nullable String key, @Nullable int[] value) { + map.put(key, value); + typeMap.put(key, type_IntArray); + } + + /** + * Inserts a long array value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a long array object, or null + */ + public void putLongArray(@Nullable String key, @Nullable long[] value) { + map.put(key, value); + typeMap.put(key, type_LongArray); + } + + /** + * Inserts a float array value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a float array object, or null + */ + public void putFloatArray(@Nullable String key, @Nullable float[] value) { + map.put(key, value); + typeMap.put(key, type_FloatArray); + } + + /** + * Inserts a double array value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a double array object, or null + */ + public void putDoubleArray(@Nullable String key, @Nullable double[] value) { + map.put(key, value); + typeMap.put(key, type_DoubleArray); + } + + /** + * Inserts a String array value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a String array object, or null + */ +// public void putStringArray(@Nullable String key, @Nullable String[] value) { +// map.put(key, value); +// typeMap.put(key, type_StringArray); +// } + + /** + * Inserts a CharSequence array value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a CharSequence array object, or null + */ +// public void putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value) { +// map.put(key, value); +// typeMap.put(key, type_CharSequenceArray); +// } + + + /** + * Inserts a Parcelable value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a Parcelable object, or null + */ + public void putParcelable(@Nullable String key, @Nullable Parcelable value) { + map.put(key, value); + typeMap.put(key, type_Parcelable); + } + + /** + * Inserts a Size value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a Size object, or null + */ +// public void putSize(@Nullable String key, @Nullable Size value) { +// map.put(key, value); +// typeMap.put(key, type_Size); +// } + + /** + * Inserts a SizeF value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a SizeF object, or null + */ +// public void putSizeF(@Nullable String key, @Nullable SizeF value) { +// map.put(key, value); +// typeMap.put(key, type_SizeF); +// } + + /** + * Inserts an array of Parcelable values into the mapping of this Bundle, + * replacing any existing value for the given key. Either key or value may + * be null. + * + * @param key a String, or null + * @param value an array of Parcelable objects, or null + */ +// public void putParcelableArray(@Nullable String key, @Nullable Parcelable[] value) { +// map.put(key, value); +// typeMap.put(key, type_ParcelableArray); +// } + + /** + * Inserts a List of Parcelable values into the mapping of this Bundle, + * replacing any existing value for the given key. Either key or value may + * be null. + * + * @param key a String, or null + * @param value an ArrayList of Parcelable objects, or null + */ + public void putParcelableArrayList(@Nullable String key, @Nullable ArrayList value) { + map.put(key, value); + typeMap.put(key, type_ParcelableArrayList); + } + + /** + * Inserts a SparceArray of Parcelable values into the mapping of this + * Bundle, replacing any existing value for the given key. Either key + * or value may be null. + * + * @param key a String, or null + * @param value a SparseArray of Parcelable objects, or null + */ + public void putSparseParcelableArray(@Nullable String key, @Nullable SparseArray value) { + map.put(key, value); + typeMap.put(key, type_SparseParcelableArray); + } + + /** + * Inserts a Bundle value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a Bundle object, or null + */ + public void putBundle(@Nullable String key, @Nullable StateBundle value) { + map.put(key, value); + typeMap.put(key, type_StateBundle); + } + + /** + * Returns the value associated with the given key, or false if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @return a boolean value + */ + public boolean getBoolean(String key) { + return getBoolean(key, false); + } + + /** + * Returns the value associated with the given key, or defaultValue if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a boolean value + */ + public boolean getBoolean(String key, boolean defaultValue) { + Object o = map.get(key); + if(o == null) { + return defaultValue; + } + try { + return (Boolean) o; + } catch(ClassCastException e) { + typeWarning(key, o, "Boolean", defaultValue, e); + return defaultValue; + } + } + + /** + * Returns the value associated with the given key, or (byte) 0 if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @return a byte value + */ + public byte getByte(String key) { + return getByte(key, (byte) 0); + } + + /** + * Returns the value associated with the given key, or defaultValue if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a byte value + */ + public Byte getByte(String key, byte defaultValue) { + Object o = map.get(key); + if(o == null) { + return defaultValue; + } + try { + return (Byte) o; + } catch(ClassCastException e) { + typeWarning(key, o, "Byte", defaultValue, e); + return defaultValue; + } + } + + /** + * Returns the value associated with the given key, or (char) 0 if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @return a char value + */ + public char getChar(String key) { + return getChar(key, (char) 0); + } + + /** + * Returns the value associated with the given key, or defaultValue if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a char value + */ + public char getChar(String key, char defaultValue) { + Object o = map.get(key); + if(o == null) { + return defaultValue; + } + try { + return (Character) o; + } catch(ClassCastException e) { + typeWarning(key, o, "Character", defaultValue, e); + return defaultValue; + } + } + + /** + * Returns the value associated with the given key, or (short) 0 if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @return a short value + */ + public short getShort(String key) { + return getShort(key, (short) 0); + } + + /** + * Returns the value associated with the given key, or defaultValue if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a short value + */ + public short getShort(String key, short defaultValue) { + Object o = map.get(key); + if(o == null) { + return defaultValue; + } + try { + return (Short) o; + } catch(ClassCastException e) { + typeWarning(key, o, "Short", defaultValue, e); + return defaultValue; + } + } + + /** + * Returns the value associated with the given key, or 0 if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @return an int value + */ + public int getInt(String key) { + return getInt(key, 0); + } + + /** + * Returns the value associated with the given key, or defaultValue if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return an int value + */ + public int getInt(String key, int defaultValue) { + Object o = map.get(key); + if(o == null) { + return defaultValue; + } + try { + return (Integer) o; + } catch(ClassCastException e) { + typeWarning(key, o, "Integer", defaultValue, e); + return defaultValue; + } + } + + /** + * Returns the value associated with the given key, or 0L if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @return a long value + */ + public long getLong(String key) { + return getLong(key, 0L); + } + + /** + * Returns the value associated with the given key, or defaultValue if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a long value + */ + public long getLong(String key, long defaultValue) { + Object o = map.get(key); + if(o == null) { + return defaultValue; + } + try { + return (Long) o; + } catch(ClassCastException e) { + typeWarning(key, o, "Long", defaultValue, e); + return defaultValue; + } + } + + /** + * Returns the value associated with the given key, or 0.0f if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @return a float value + */ + public float getFloat(String key) { + return getFloat(key, 0.0f); + } + + /** + * Returns the value associated with the given key, or defaultValue if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a float value + */ + public float getFloat(String key, float defaultValue) { + Object o = map.get(key); + if(o == null) { + return defaultValue; + } + try { + return (Float) o; + } catch(ClassCastException e) { + typeWarning(key, o, "Float", defaultValue, e); + return defaultValue; + } + } + + /** + * Returns the value associated with the given key, or 0.0 if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @return a double value + */ + public double getDouble(String key) { + return getDouble(key, 0.0); + } + + /** + * Returns the value associated with the given key, or defaultValue if + * no mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a double value + */ + public double getDouble(String key, double defaultValue) { + Object o = map.get(key); + if(o == null) { + return defaultValue; + } + try { + return (Double) o; + } catch(ClassCastException e) { + typeWarning(key, o, "Double", defaultValue, e); + return defaultValue; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a String value, or null + */ + @Nullable + public String getString(@Nullable String key) { + final Object o = map.get(key); + try { + return (String) o; + } catch(ClassCastException e) { + typeWarning(key, o, "String", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or defaultValue if + * no mapping of the desired type exists for the given key or if a null + * value is explicitly associated with the given key. + * + * @param key a String, or null + * @param defaultValue Value to return if key does not exist or if a null + * value is associated with the given key. + * @return the String value associated with the given key, or defaultValue + * if no valid String object is currently mapped to that key. + */ + public String getString(@Nullable String key, String defaultValue) { + final String s = getString(key); + return (s == null) ? defaultValue : s; + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a CharSequence value, or null + */ + @Nullable + public CharSequence getCharSequence(@Nullable String key) { + final Object o = map.get(key); + try { + return (CharSequence) o; + } catch(ClassCastException e) { + typeWarning(key, o, "CharSequence", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or defaultValue if + * no mapping of the desired type exists for the given key or if a null + * value is explicitly associated with the given key. + * + * @param key a String, or null + * @param defaultValue Value to return if key does not exist or if a null + * value is associated with the given key. + * @return the CharSequence value associated with the given key, or defaultValue + * if no valid CharSequence object is currently mapped to that key. + */ + public CharSequence getCharSequence(@Nullable String key, CharSequence defaultValue) { + final CharSequence cs = getCharSequence(key); + return (cs == null) ? defaultValue : cs; + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a Serializable value, or null + */ + @Nullable + public Serializable getSerializable(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (Serializable) o; + } catch(ClassCastException e) { + typeWarning(key, o, "Serializable", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return an ArrayList value, or null + */ + @Nullable + public ArrayList getIntegerArrayList(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (ArrayList) o; + } catch(ClassCastException e) { + typeWarning(key, o, "ArrayList", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return an ArrayList value, or null + */ + @Nullable + public ArrayList getStringArrayList(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (ArrayList) o; + } catch(ClassCastException e) { + typeWarning(key, o, "ArrayList", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return an ArrayList value, or null + */ + @Nullable + public ArrayList getCharSequenceArrayList(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (ArrayList) o; + } catch(ClassCastException e) { + typeWarning(key, o, "ArrayList", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a boolean[] value, or null + */ + @Nullable + public boolean[] getBooleanArray(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (boolean[]) o; + } catch(ClassCastException e) { + typeWarning(key, o, "byte[]", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a byte[] value, or null + */ + @Nullable + public byte[] getByteArray(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (byte[]) o; + } catch(ClassCastException e) { + typeWarning(key, o, "byte[]", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a short[] value, or null + */ + @Nullable + public short[] getShortArray(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (short[]) o; + } catch(ClassCastException e) { + typeWarning(key, o, "short[]", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a char[] value, or null + */ + @Nullable + public char[] getCharArray(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (char[]) o; + } catch(ClassCastException e) { + typeWarning(key, o, "char[]", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return an int[] value, or null + */ + @Nullable + public int[] getIntArray(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (int[]) o; + } catch(ClassCastException e) { + typeWarning(key, o, "int[]", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a long[] value, or null + */ + @Nullable + public long[] getLongArray(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (long[]) o; + } catch(ClassCastException e) { + typeWarning(key, o, "long[]", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a float[] value, or null + */ + @Nullable + public float[] getFloatArray(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (float[]) o; + } catch(ClassCastException e) { + typeWarning(key, o, "float[]", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a double[] value, or null + */ + @Nullable + public double[] getDoubleArray(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (double[]) o; + } catch(ClassCastException e) { + typeWarning(key, o, "double[]", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a String[] value, or null + */ +// @Nullable +// public String[] getStringArray(@Nullable String key) { +// Object o = map.get(key); +// if(o == null) { +// return null; +// } +// try { +// return (String[]) o; +// } catch(ClassCastException e) { +// typeWarning(key, o, "String[]", e); +// return null; +// } +// } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a CharSequence[] value, or null + */ +// @Nullable +// public CharSequence[] getCharSequenceArray(@Nullable String key) { +// Object o = map.get(key); +// if(o == null) { +// return null; +// } +// try { +// return (CharSequence[]) o; +// } catch(ClassCastException e) { +// typeWarning(key, o, "CharSequence[]", e); +// return null; +// } +// } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a Size value, or null + */ +// @Nullable +// public Size getSize(@Nullable String key) { +// final Object o = map.get(key); +// try { +// return (Size) o; +// } catch(ClassCastException e) { +// typeWarning(key, o, "Size", e); +// return null; +// } +// } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a Size value, or null + */ +// @Nullable +// public SizeF getSizeF(@Nullable String key) { +// final Object o = map.get(key); +// try { +// return (SizeF) o; +// } catch(ClassCastException e) { +// typeWarning(key, o, "SizeF", e); +// return null; +// } +// } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a Bundle value, or null + */ + @Nullable + public StateBundle getBundle(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (StateBundle) o; + } catch(ClassCastException e) { + typeWarning(key, o, "Bundle", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a Parcelable value, or null + */ + @Nullable + public T getParcelable(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (T) o; + } catch(ClassCastException e) { + typeWarning(key, o, "Parcelable", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a Parcelable[] value, or null + */ +// @Nullable +// public Parcelable[] getParcelableArray(@Nullable String key) { +// Object o = map.get(key); +// if(o == null) { +// return null; +// } +// try { +// return (Parcelable[]) o; +// } catch(ClassCastException e) { +// typeWarning(key, o, "Parcelable[]", e); +// return null; +// } +// } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return an ArrayList value, or null + */ + @Nullable + public ArrayList getParcelableArrayList(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (ArrayList) o; + } catch(ClassCastException e) { + typeWarning(key, o, "ArrayList", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a SparseArray of T values, or null + */ + @Nullable + public SparseArray getSparseParcelableArray(@Nullable String key) { + Object o = map.get(key); + if(o == null) { + return null; + } + try { + return (SparseArray) o; + } catch(ClassCastException e) { + typeWarning(key, o, "SparseArray", e); + return null; + } + } + + // Log a message if the value was non-null but not of the expected type + void typeWarning(String key, Object value, String className, Object defaultValue, ClassCastException e) { + StringBuilder sb = new StringBuilder(); + sb.append("Key "); + sb.append(key); + sb.append(" expected "); + sb.append(className); + sb.append(" but value was a "); + sb.append(value.getClass().getName()); + sb.append(". The default value "); + sb.append(defaultValue); + sb.append(" was returned."); + System.out.println(sb.toString()); + } + + void typeWarning(String key, Object value, String className, ClassCastException e) { + typeWarning(key, value, className, "", e); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(map.keySet().size()); + for(String key : map.keySet()) { + TypeElement typeElement = new TypeElement(key, typeMap.get(key)); + dest.writeParcelable(typeElement, 0); + dest.writeValue(get(key)); + } + } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder(); + for(Map.Entry entry : map.entrySet()) { + stringBuilder.append("[["); + stringBuilder.append(entry.getKey()); + stringBuilder.append("] :: ["); + stringBuilder.append(entry.getValue()); + stringBuilder.append("]]\n"); + } + return stringBuilder.toString(); + } +} \ No newline at end of file diff --git a/simple-stack/src/test/java/com/zhuinden/simplestack/StateBundleTest.java b/simple-stack/src/test/java/com/zhuinden/simplestack/StateBundleTest.java new file mode 100644 index 00000000..22753b45 --- /dev/null +++ b/simple-stack/src/test/java/com/zhuinden/simplestack/StateBundleTest.java @@ -0,0 +1,685 @@ +package com.zhuinden.simplestack; + +import android.os.Parcelable; +import android.util.SparseArray; + +import org.junit.Test; +import org.mockito.Mockito; + +import java.io.Serializable; +import java.util.ArrayList; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Created by Owner on 2017. 02. 21.. + */ + +public class StateBundleTest { + @Test + public void testBooleanIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", false); + boolean val = stateBundle.getBoolean("key"); + assertThat(val).isEqualTo(false); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_boolean); + } + + @Test + public void testByteIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putByte("key", (byte) 0x01); + byte val = stateBundle.getByte("key"); + assertThat(val).isEqualTo((byte) 0x01); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_byte); + } + + @Test + public void testCharIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putChar("key", 'C'); + char val = stateBundle.getChar("key"); + assertThat(val).isEqualTo('C'); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_char); + } + + @Test + public void testShortIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putShort("key", (short) 5); + short val = stateBundle.getShort("key"); + assertThat(val).isEqualTo((short) 5); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_short); + } + + @Test + public void testIntIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putInt("key", 5); + int val = stateBundle.getInt("key"); + assertThat(val).isEqualTo(5); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_int); + } + + @Test + public void testLongIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putLong("key", 4L); + long val = stateBundle.getLong("key"); + assertThat(val).isEqualTo(4L); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_long); + } + + @Test + public void testFloatIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putFloat("key", 0.25f); + float val = stateBundle.getFloat("key"); + assertThat(val).isEqualTo(0.25f); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_float); + } + + @Test + public void testDoubleIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putDouble("key", 0.25); + double val = stateBundle.getDouble("key"); + assertThat(val).isEqualTo(0.25); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_double); + } + + @Test + public void testStringIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putString("key", "asd"); + String val = stateBundle.getString("key"); + assertThat(val).isEqualTo("asd"); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_String); + } + + @Test + public void testCharSequenceIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putCharSequence("key", "asd"); + CharSequence val = stateBundle.getCharSequence("key"); + assertThat(val).isEqualTo("asd"); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_CharSequence); + } + + @Test + public void testSerializableIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putSerializable("key", 5); + Serializable val = stateBundle.getSerializable("key"); + assertThat(val).isEqualTo(5); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_Serializable); + } + + @Test + public void testIntegerArrayListIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putIntegerArrayList("key", new ArrayList() {{ + add(5); + }}); + ArrayList val = stateBundle.getIntegerArrayList("key"); + assertThat(val).containsExactly(5); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_IntegerArrayList); + } + + @Test + public void testStringArrayListIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putStringArrayList("key", new ArrayList() {{ + add("asd"); + add("def"); + }}); + ArrayList val = stateBundle.getStringArrayList("key"); + assertThat(val).containsExactly("asd", "def"); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_StringArrayList); + } + + @Test + public void testCharSequenceArrayListIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putCharSequenceArrayList("key", new ArrayList() {{ + add("asd"); + add("def"); + }}); + ArrayList val = stateBundle.getCharSequenceArrayList("key"); + assertThat(val).containsExactly("asd", "def"); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_CharSequenceArrayList); + } + + @Test + public void testBooleanArrayIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBooleanArray("key", new boolean[]{true, false}); + boolean[] val = stateBundle.getBooleanArray("key"); + assertThat(val).containsExactly(true, false); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_BooleanArray); + } + + @Test + public void testByteArrayIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putByteArray("key", new byte[]{(byte) 0x01, (byte) 0x02}); + byte[] val = stateBundle.getByteArray("key"); + assertThat(val).containsExactly((byte) 0x01, (byte) 0x02); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_ByteArray); + } + + @Test + public void testShortArrayIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putShortArray("key", new short[]{(short) 1, (short) 2}); + short[] val = stateBundle.getShortArray("key"); + assertThat(val).containsExactly((short) 1, (short) 2); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_ShortArray); + } + + @Test + public void testCharArrayIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putCharArray("key", new char[]{'A', 'B'}); + char[] val = stateBundle.getCharArray("key"); + assertThat(val).containsExactly('A', 'B'); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_CharArray); + } + + @Test + public void testIntArrayIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putIntArray("key", new int[]{1, 2}); + int[] val = stateBundle.getIntArray("key"); + assertThat(val).containsExactly(1, 2); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_IntArray); + } + + @Test + public void testLongArrayIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putLongArray("key", new long[]{1L, 2L}); + long[] val = stateBundle.getLongArray("key"); + assertThat(val).containsExactly(1L, 2L); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_LongArray); + } + + @Test + public void testFloatArrayIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putFloatArray("key", new float[]{0.25f, 0.5f}); + float[] val = stateBundle.getFloatArray("key"); + assertThat(val).containsExactly(0.25f, 0.5f); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_FloatArray); + } + + @Test + public void testDoubleArrayIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putDoubleArray("key", new double[]{0.25, 0.5}); + double[] val = stateBundle.getDoubleArray("key"); + assertThat(val).containsExactly(0.25, 0.5); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_DoubleArray); + } + +// @Test +// public void testStringArrayIsPutAndRetrieved() { +// StateBundle stateBundle = new StateBundle(); +// stateBundle.putStringArray("key", new String[]{"asd", "def"}); +// String[] val = stateBundle.getStringArray("key"); +// assertThat(val).containsExactly("asd", "def"); +// assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_StringArray); +// } +// +// @Test +// public void testCharSequenceArrayIsPutAndRetrieved() { +// StateBundle stateBundle = new StateBundle(); +// stateBundle.putCharSequenceArray("key", new String[]{"asd", "def"}); +// CharSequence[] val = stateBundle.getCharSequenceArray("key"); +// assertThat(val).containsExactly("asd", "def"); +// assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_CharSequenceArray); +// } + + @Test + public void testStateBundleIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + StateBundle otherBundle = new StateBundle(); + otherBundle.putString("hello", "world"); + stateBundle.putBundle("key", otherBundle); + StateBundle val = stateBundle.getBundle("key"); + assertThat(val).isEqualTo(otherBundle); + assertThat(val.getString("hello")).isEqualTo("world"); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_StateBundle); + } + + @Test + public void testParcelableIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + TestKey testKey = new TestKey("hello"); + stateBundle.putParcelable("key", testKey); + Parcelable val = stateBundle.getParcelable("key"); + assertThat(val).isEqualTo(testKey); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_Parcelable); + } + +// @Test +// public void testParcelableArrayIsPutAndRetrieved() { +// StateBundle stateBundle = new StateBundle(); +// TestKey testKey = new TestKey("hello"); +// TestKey testKey2 = new TestKey("world"); +// stateBundle.putParcelableArray("key", new Parcelable[]{testKey, testKey2}); +// Parcelable[] val = stateBundle.getParcelableArray("key"); +// assertThat(val).containsExactly(testKey, testKey2); +// assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_ParcelableArray); +// } + + @Test + public void testParcelableArrayListIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + final TestKey testKey = new TestKey("hello"); + final TestKey testKey2 = new TestKey("world"); + stateBundle.putParcelableArrayList("key", new ArrayList() {{ + add(testKey); + add(testKey2); + }}); + ArrayList val = stateBundle.getParcelableArrayList("key"); + assertThat(val).containsExactly(testKey, testKey2); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_ParcelableArrayList); + } + + @Test + public void testSparseParcelableArrayIsPutAndRetrieved() { + StateBundle stateBundle = new StateBundle(); + final TestKey testKey = new TestKey("hello"); + final TestKey testKey2 = new TestKey("world"); + SparseArray parcelableSparseArray = Mockito.mock(SparseArray.class); + Mockito.when(parcelableSparseArray.get(1)).thenReturn(testKey); + Mockito.when(parcelableSparseArray.get(2)).thenReturn(testKey2); + parcelableSparseArray.put(1, testKey); + parcelableSparseArray.put(2, testKey); + stateBundle.putSparseParcelableArray("key", parcelableSparseArray); + SparseArray val = stateBundle.getSparseParcelableArray("key"); + assertThat(val.get(1)).isEqualTo(testKey); + assertThat(val.get(2)).isEqualTo(testKey2); + assertThat(stateBundle.typeMap.get("key")).isEqualTo(StateBundle.type_SparseParcelableArray); + } + + // + + @Test + public void testGetBooleanReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getBoolean("key")).isFalse(); + } + + @Test + public void testGetByteReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getByte("key")).isEqualTo((byte) 0); + } + + @Test + public void testGetCharReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getChar("key")).isEqualTo((char) 0); + } + + @Test + public void testGetShortReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getShort("key")).isEqualTo((short) 0); + } + + @Test + public void testGetIntReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getInt("key")).isEqualTo(0); + } + + @Test + public void testGetLongReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getLong("key")).isEqualTo(0); + } + + @Test + public void testGetFloatReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getFloat("key")).isEqualTo(0.0f); + } + + @Test + public void testGetDoubleReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getDouble("key")).isEqualTo(0.0); + } + + @Test + public void testGetStringReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getString("key")).isNull(); + } + + @Test + public void testGetCharSequenceReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getCharSequence("key")).isNull(); + } + + @Test + public void testGetSerializableReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getSerializable("key")).isNull(); + } + + @Test + public void testGetIntegerArrayListReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getIntegerArrayList("key")).isNull(); + } + + @Test + public void testGetStringArrayListReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getStringArrayList("key")).isNull(); + } + + @Test + public void testGetCharSequenceArrayListReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getCharSequenceArrayList("key")).isNull(); + } + + @Test + public void testGetBooleanArrayReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getBooleanArray("key")).isNull(); + } + + @Test + public void testGetByteArrayReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getByteArray("key")).isNull(); + } + + @Test + public void testGetShortArrayReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getShortArray("key")).isNull(); + } + + @Test + public void testGetCharArrayReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getCharArray("key")).isNull(); + } + + @Test + public void testGetIntArrayReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getIntArray("key")).isNull(); + } + + @Test + public void testGetLongArrayReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getLongArray("key")).isNull(); + } + + @Test + public void testGetFloatArrayReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getFloatArray("key")).isNull(); + } + + @Test + public void testGetDoubleArrayReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getDoubleArray("key")).isNull(); + } + +// @Test +// public void testGetStringArrayReturnsDefault() { +// StateBundle stateBundle = new StateBundle(); +// assertThat(stateBundle.getStringArray("key")).isNull(); +// } +// +// @Test +// public void testGetCharSequenceArrayReturnsDefault() { +// StateBundle stateBundle = new StateBundle(); +// assertThat(stateBundle.getCharSequenceArray("key")).isNull(); +// } + + @Test + public void testGetStateBundleReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getBundle("key")).isNull(); + } + + @Test + public void testGetParcelableReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getParcelable("key")).isNull(); + } + +// @Test +// public void testGetParcelableArrayReturnsDefault() { +// StateBundle stateBundle = new StateBundle(); +// assertThat(stateBundle.getParcelableArray("key")).isNull(); +// } + + @Test + public void testGetParcelableArrayListReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getParcelableArrayList("key")).isNull(); + } + + @Test + public void testGetSparseParcelableArrayReturnsDefault() { + StateBundle stateBundle = new StateBundle(); + assertThat(stateBundle.getSparseParcelableArray("key")).isNull(); + } + + @Test + public void testStringAsBooleanReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putString("key", "true"); + assertThat(stateBundle.getBoolean("key")).isFalse(); + } + + @Test + public void testBooleanAsByteReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getByte("key")).isEqualTo((byte) 0); + } + + @Test + public void testBooleanAsCharReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getChar("key")).isEqualTo((char) 0); + } + + @Test + public void testBooleanAsShortReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getShort("key")).isEqualTo((short) 0); + } + + @Test + public void testBooleanAsIntReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getInt("key")).isEqualTo(0); + } + + @Test + public void testBooleanAsLongReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getLong("key")).isEqualTo(0L); + } + + @Test + public void testBooleanAsFloatReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getFloat("key")).isEqualTo(0.0f); + } + + @Test + public void testBooleanAsDoubleReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getDouble("key")).isEqualTo(0.0); + } + + @Test + public void testBooleanAsStringReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getString("key")).isNull(); + } + + @Test + public void testBooleanAsCharSequenceReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getCharSequence("key")).isNull(); + } + + @Test + public void testBooleanAsSerializableReturnsBoolean() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat((Boolean) stateBundle.getSerializable("key")).isTrue(); + } + + @Test + public void testBooleanAsIntegerArrayListReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getIntegerArrayList("key")).isNull(); + } + + @Test + public void testBooleanAsStringArrayListReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getStringArrayList("key")).isNull(); + } + + @Test + public void testBooleanAsCharSequenceArrayListReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getCharSequenceArrayList("key")).isNull(); + } + + @Test + public void testBooleanAsBooleanArrayReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getBooleanArray("key")).isNull(); + } + + @Test + public void testBooleanAsByteArrayReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getByteArray("key")).isNull(); + } + + @Test + public void testBooleanAsShortArrayReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getShortArray("key")).isNull(); + } + + @Test + public void testBooleanAsCharArrayReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getCharArray("key")).isNull(); + } + + @Test + public void testBooleanAsIntArrayReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getIntArray("key")).isNull(); + } + + @Test + public void testBooleanAsLongArrayReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getLongArray("key")).isNull(); + } + + @Test + public void testBooleanAsFloatArrayReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getFloatArray("key")).isNull(); + } + + @Test + public void testBooleanAsDoubleArrayReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getDoubleArray("key")).isNull(); + } + +// @Test +// public void testBooleanAsStringArrayReturnsDefaultValue() { +// StateBundle stateBundle = new StateBundle(); +// stateBundle.putBoolean("key", true); +// assertThat(stateBundle.getStringArray("key")).isNull(); +// } +// +// @Test +// public void testBooleanAsCharSequenceArrayReturnsDefaultValue() { +// StateBundle stateBundle = new StateBundle(); +// stateBundle.putBoolean("key", true); +// assertThat(stateBundle.getCharSequenceArray("key")).isNull(); +// } + + @Test + public void testBooleanAsStateBundleReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getBundle("key")).isNull(); + } + + @Test + public void testBooleanAsParcelableReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getParcelable("key")).isNull(); + } + +// @Test +// public void testBooleanAsParcelableArrayReturnsDefaultValue() { +// StateBundle stateBundle = new StateBundle(); +// stateBundle.putBoolean("key", true); +// assertThat(stateBundle.getParcelableArray("key")).isNull(); +// } + + @Test + public void testBooleanAsParcelableArrayListReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getParcelableArrayList("key")).isNull(); + } + + @Test + public void testBooleanAsSparseParcelableArrayReturnsDefaultValue() { + StateBundle stateBundle = new StateBundle(); + stateBundle.putBoolean("key", true); + assertThat(stateBundle.getSparseParcelableArray("key")).isNull(); + } +} diff --git a/simple-stack/src/test/java/com/zhuinden/simplestack/TestSuite.java b/simple-stack/src/test/java/com/zhuinden/simplestack/TestSuite.java index ba22c702..9a9cbb65 100644 --- a/simple-stack/src/test/java/com/zhuinden/simplestack/TestSuite.java +++ b/simple-stack/src/test/java/com/zhuinden/simplestack/TestSuite.java @@ -23,6 +23,6 @@ * Created by Owner on 2017. 01. 17.. */ @RunWith(Suite.class) -@Suite.SuiteClasses({StateChangerTest.class, FlowTest.class, ReentranceTest.class, BackstackTest.class, HistoryBuilderTest.class, BackstackDelegateTest.class}) +@Suite.SuiteClasses({StateChangerTest.class, FlowTest.class, ReentranceTest.class, BackstackTest.class, HistoryBuilderTest.class, BackstackDelegateTest.class, StateBundleTest.class}) public class TestSuite { }