Code Monkey home page Code Monkey logo

introduction's Introduction

Introduction Download Licence

Android Gems Android Arsenal AndroidLibs

Show a beautiful Intro to your users with ease.

Include in your Project

Add this to your build.gradle:

dependencies {
    compile ('com.rubengees:introduction:1.1.0@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" }
}

If you want to use asynchronous image laoding, introduced in the new version 1.1.0, than you will need Glide or some other image loading library. If you want to use GIFs you will also need it.

Usage

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.

Options

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.

Use Gifs as images

This library supports GIFs. You need to load them asynchronously as the loading may take a while:

new IntroductionBuilder(this).withSlides(slides)
                .withOnSlideListener(new OnSlideListener() {
                    @Override
                    protected void onSlideInit(Fragment context, int position, TextView title,
                                               ImageView image, TextView description) {
                        if (position == 1) { //Assume we want to load the GIF at Slide 2 (index 1)
                            Glide.with(context).load(R.drawable.image3).into(image);
                        }

                    }
                }).introduceMyself();

This will add the GIF, which will be automatically played when the users navigates to the Slide.

Runtime Premissions

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!

Styles

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.

Further reading

A much more detailed explanation with all available APIs can be found in the Wiki.

Minimum Sdk

The minimum required sdk is 10 (2.3.3 Gingerbread)

Upgrade Guide

1.0.x to 1.1.0+

  • The 'OnSlideChangedListener' was renamed to 'OnSlideListener'. Just rename it and it's working again.
  • Asynchronous image loading is now available (and recomended!). See the 'Use GIFs as drawables' section for more info. It applies for all types of images. GIFs won't work without asynchronous loading from now on!

Libraries used in this project

Acknowledgments

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

introduction's People

Contributors

akeshihiro avatar liaohuqiu avatar rubengees avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.