Android Stepper Library
Steppers are used to display progress of logically separated sections normally referred to as steps. Checkout this library I have been working on Neat Android Stepper Library. Its open source and you can use it in any of your android app. The library is still under development with more features with future releases
Download (From GitHub Packages)
This library is available as a git package Neat Stepper Packages. At the moment GitHub requires you to authenticate to download Android Libraries hosted on GitHub packages. To do so you will need your personal access token and your GitHub username. Follow these steps to add the library as a dependency to your app.
Step 1 : Generate a Personal Access Token for GitHub How to generate GitHub personal access token
Step 2 : Store your GitHub — Personal Access Token details Create a file github.properties inside the root directory of your project. (Add this file to .gitignore file for public repositories to keep your secrets safe)
Add these content to the file.
gpr.usr=YOUR_GITHUB_USERID gpr.key=YOUR_PERSONAL_ACCESS_TOKEN
Step 3 : Update build.gradle for the application module
//For publishing dependency to GitHub package
def githubProperties = new Properties()
//Read the github properties content
githubProperties.load(new FileInputStream(rootProject.file("github.properties")))
android {
//...
// include inside the android closure
repositories {
maven {
name = "GitHubPackages"
/**
* Configure path of the package repository on Github using the GITHUB_USER_ID and * Git Repository */
url = uri("https://maven.pkg.github.com/ellykits/neat-android-stepper")
credentials {
/** get credentials from github.properties in root project folder file with
** gpr.usr=GITHUB_USER_ID & gpr.key=PERSONAL_ACCESS_TOKEN otherwise ** Set env variable GPR_USER & GPR_API_KEY**/
username = githubProperties['gpr.usr'] ?: System.getenv("GPR_USER")
password = githubProperties['gpr.key'] ?: System.getenv("GPR_API_KEY")
}
}
}
//...
}
Add the library in the dependency section of your application's build.gradle file. Update the version accordingly
dependencies {
//consume library - use the latest version available on github packages
implementation "com.nerdstone:neat-android-stepper:1.0.0"
//....
}
Create layout in XML
The layout can only be used as a root view and should not be nested inside other views.
<?xml version="1.0" encoding="utf-8"?>
<com.nerdstone.neatandroidstepper.core.widget.NeatStepperLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/neatStepperLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:bottom_navigation_background_color="@color/colorBlueGrey"
app:dot_indicator_default_color="@color/colorWhite"
app:dot_indicator_selected_color="@color/colorYellow"
app:indicator_type="dot_indicator" />
Create step Fragment(s)
Step fragments must extend androidx.fragment.app.Fragment and implement com.nerdstone.neatandroidstepper.core.stepper.Step
class StepOneFragment : Step {
constructor()
constructor(stepModel: StepModel) : super(stepModel)
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_step_one_fragment, container, false)
val linearLayout = view.findViewById<LinearLayout>(R.id.fragmentLinearLayout)
for (i in 1..200) {
val text = TextView(context)
text.setPadding(16, 16, 16, 16)
text.text = "Current count $i"
linearLayout.addView(text)
}
return view
}
override fun verifyStep(): StepVerificationState {
TODO("not implemented")
}
override fun onSelected() {
TODO("not implemented")
}
override fun onError(stepVerificationState: StepVerificationState) {
TODO("not implemented")
}
}
Set adapter in Activity
Activity must extend androidx.fragment.app.FragmentActivity
You can also choose to implement stepper callback methods declared in com.nerdstone.neatandroidstepper.core.domain.StepperActions on the activity . The callback methods are called anytime the user interacts with the stepper for instance when the user clicks a button. Use the callbacks to handle any operations like saving data to database, requesting resource etc.
Call the method setUpViewWithAdapter of the stepper layout and pass the list of fragments to the constructor of com.nerdstone.neatandroidstepper.core.stepper.StepperPagerAdapter. This will set up the stepper view with the provided list of Fragments.
class MainActivity : FragmentActivity(), StepperActions {
lateinit var neatStepperLayout: NeatStepperLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
neatStepperLayout = findViewById(R.id.neatStepperLayout)
neatStepperLayout.stepperActions = this
neatStepperLayout.setUpViewWithAdapter(
StepperPagerAdapter(
supportFragmentManager,
mutableListOf(
StepOneFragment(StepModel.Builder().title("Step Sample").subTitle("One").build()),
StepOneFragment(StepModel.Builder().title("Step Sample").subTitle("Two").build()),
StepOneFragment(StepModel.Builder().title("Step Sample").subTitle("Three").build())
)
)
)
}
override fun onStepError(stepVerificationState: StepVerificationState) {
}
override fun onButtonNextClick(step: Step) {
}
override fun onButtonPreviousClick(step: Step) {
}
override fun onStepComplete(step: Step) {
Toast.makeText(this, "Stepper completed", Toast.LENGTH_SHORT).show()
}
override fun onExitStepper() {
val confirmCloseDialog = AlertDialog.Builder(this)
confirmCloseDialog.apply {
setTitle("Confirm close")
setMessage("All the unsaved data will get lost if you quit")
setPositiveButton("Exit") { _, _ -> finish() }
setNegativeButton("Cancel") { _, _ -> return@setNegativeButton }
create()
}
confirmCloseDialog.show()
}
override fun onCompleteStepper() {
Toast.makeText(this, "Completed entire step", Toast.LENGTH_SHORT).show()
}
}
Here is a sample.
Nice job bro! Off to extending it.