##Importing to your project Add this dependency to your build.gradle file:
dependencies {
compile'me.panavtec:wizard:1.2'
}##Basic usage
Create a WizardPage for each fragment you need to present, the only mandatory method to override is "createFragment()":
publicclassWizardPage1extendsWizardPage<Fragment1> {
@OverridepublicFragment1createFragment() {
returnnewFragment1();
}
}Create a wizard in your activity in this way:
@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
wizard = newWizard.Builder(this, newWizardPage1())
.build();
...
...And call init:
wizard.init();Now the wizard is initalized, to use navigation just call, "navigatePrevious", "navigateNext" or "returnToFirst". You can get the current fragment by calling "getCurrentFragment"
##Advanced usage
###Animation transitions You can declare animations for entering/exiting fragments when creating Wizard in this way:
newWizard.Builder(this, newWizardPage1(), newWizardPage2(), newWizardPage3())
.containerId(android.R.id.content)
.enterAnimation(R.anim.card_slide_right_in)
.exitAnimation(R.anim.card_slide_left_out)
.popEnterAnimation(R.anim.card_slide_left_in)
.popExitAnimation(R.anim.card_slide_right_out)
.build();This xml animations are uploaded to the sample project.
###Provide a custom container for fragment navigation if you don't set the containerId attribute, Wizard uses android.R.id.content by default but you can personalize a custom container by calling:
newWizard.Builder(this, newWizardPage1())
.containerId(R.id.my_container)###Customize ActionBar in navigation In the wizard page you can override method "setupActionBar" to customize your actionbar on each navigated fragment, ex:
@OverridepublicvoidsetupActionBar(ActionBarsupportActionBar) {
super.setupActionBar(supportActionBar);
supportActionBar.hide();
}In this example when the fragment is navigated, the actionbar will be hidden.
###Option menu in Actionbar
If you have a Fragment that uses actionbar option menus, you can override "hasOptionMenu" and return true to invalidate the option menus when navigating.
###Blocking Fragment
Do you need to block the back navigation of your wizard in determinate steps? It's so easy, just override "allowsBackNavigation" in your WizardPage and add this in your activity:
@OverridepublicvoidonBackPressed() {
if (wizard.onBackPressed()) {
super.onBackPressed();
}
}###Listeners You can declare listeners for page changed and for wizard finished events:
WizardPage[] wizardPages = { newWizardPage1(), newWizardPage2(), newWizardPage3() };
newWizard.Builder(this, wizardPages)
.containerId(android.R.id.content)
.pageListener(newWizardPageListener() {
@OverridepublicvoidonPageChanged(intcurrentPageIndex, WizardPagepage) {
//Your code for page changed
}
})
.wizardListener(newWizardListener() {
@OverridepublicvoidonWizardFinished() {
//Your code for wizard finished
}
})
.build();###Dagger Tips If you are using Dagger in your project I suggest to use Wizard in this way. ActivityModule:
@Provides@SingletonWizardprovideWizard(ActionBarActivityactivity,
SampleWizardPagepage) {
returnnewWizard.Builder(activity, page)
.containerId(android.R.id.content)
.build();
}
@Provides@SingletonSampleWizardPageprovideSampleWizardPage(ActionBarActivityactivity) {
returnnewSampleWizardPage(activity);
}Activity:
@InjectWizardwizard;
@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
wizard.init();
}Fragment:
@InjectWizardwizard;
@OverrideprotectedvoidsomeOnClickAction() {
wizard.navigateNext();
}Christian Panadero Martinez - http://panavtec.me - @PaNaVTEC
Copyright 2015 Christian Panadero Martinez
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.

