Show a beautiful Intro to your users with ease.
Add this to your build.gradle:
dependencies {
compile ('com.rubengees:introduction:1.0.3@aar'){
transitive = true;
}
}
If that doesn't work, look if there is a new version and the Readme was not updated yet. If there is no new version and it still doesn't work, try to add this to your build.gradle:
repositories {
maven { url "http://dl.bintray.com/rubengees/maven" }
}
Create an IntroductionBuilder
like the following:
new IntroductionBuilder(this) //this is the Activity you want to start from.
Then add some Slides to your Introduction:
new IntroductionBuilder(this).withSlides(generateSlides())
private List<Slide> generateSlides() {
List<Slide> result = new ArrayList<>();
result.add(new Slide().withTitle("Some title").withDescription("Some description").
withColorResource(R.color.green).withImage(R.drawable.myImage));
result.add(new Slide().withTitle("Another title").withDescription("Another description")
.withColorResource(R.color.indigo).withImage(R.drawable.myImage2));
return result;
}
Finally introduce yourself!
new IntroductionBuilder(this).withSlides(generateSlides()).introduceMyself();
That was easy right?
You can do many customizations, which will be covered by the following.
You can let the user make decisions, which you can use like settings. To do that you add an Option to your slide:
new Slide().withTitle("Feature is doing something").withOption(new Option("Enable the feature"))
.withColorResource(R.color.orange).withImage(R.drawable.image));
When the user completes the intro, you will receive the selected Options in onActivityResult
.
To read the result:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == IntroductionBuilder.INTRODUCTION_REQUEST_CODE &&
resultCode == RESULT_OK) {
String result = "User chose: ";
for (Option option : data.<Option>getParcelableArrayListExtra(IntroductionActivity.
OPTION_RESULT)) {
result += option.getPosition() //The position of the Slide
+ (option.isActivated() ? " enabled" : " disabled");
}
}
}
The constant value of the requst is 32142, so don't use that yourself.
It is possible that the user cancels the intro. If that happens, the resultCode is RESULT_CANCELLED
and no Options are passed back.
This library supports GIFs. Just add them like normal drawables:
result.add(new Slide().withTitle("Some title").withDescription("Some description").
withColorResource(R.color.green).withImageResource(R.drawable.myGIF));
This will add the GIF, which will be automatically played when the users navigates to the Slide.
Android Marshmallow introduced Runtime Permissions, which can be requested easily with this lib. To do that, you can add a global listener like the following:
new IntroductionBuilder(this).withSlides(slides)
.withOnSlideChangedListener(new IntroductionConfiguration.OnSlideChangedListener() {
@Override
public void onSlideChanged(int from, int to) {
if (from == 0 && to == 1) {
if (ActivityCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
12);
}
}
}
}).introduceMyself();
You can check if the permissions were granted like the following:
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 12) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Permission was successfully granted!", Toast.LENGTH_LONG)
.show();
}
}
}
You can use that listener for different things too, of course!
There are two available styles: Translucent
and Fullscreen
.
To apply one of those styles, do the following:
new IntroductionBuilder(this).withSlides(generateSlides())
.withStyle(IntroductionBuilder.STYLE_FULLSCREEN).introduceMyself();
Translucent
is the default style.
A much more detailed explanation with all available APIs can be found in the Wiki.
- android-gif-drawable For the GIFs.
- SystemBarTint For the translucent style.
The images in the samples are taken from the following webpages (I do not own any of the images, all rights are reserved to their respective owners):
Some images and ideas are from this Repo: AppIntro by Paolo Rotolo