Giter Club home page Giter Club logo

introduction's Introduction

Introduction Download API CircleCI

Show a beautiful Intro to your users with ease.

You can download the latest sample app here.

Table of contents

Include in your Project

Add this to your root build.gradle (usually in the root of your project):

repositories {
    maven { url "https://jitpack.io" }
}

And this to your module build.gradle (usually in the app directory):

dependencies {
    implementation 'com.github.rubengees:introduction:2.0.0'
}

If that doesn't work, look if there is a new version and the Readme was not updated yet.

If you want to use asynchronous image loading, introduced in the new version 1.1.0, 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() + (option.isActivated() ? " enabled" : " disabled");
        }
     }
}

The constant value of the request 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
            public void onSlideInit(int position, @Nullable TextView title, @NonNull ImageView image,
                                    @Nullable TextView description) {
                if (position == 1) { // Assume we want to load the GIF at Slide 2 (index 1).
                    Glide.with(image.getContext())
                            .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 Permissions

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)
        .withOnSlideListener(new OnSlideListener() {
            @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(new FullscreenStyle())
                .introduceMyself();

Translucent is the default style.

Custom Views

You can supply your own View to a Slide instead of just setting the title, image and description.
This is done like follows:

Create a class which implements CustomViewBuilder:

public class CustomViewBuilderImpl implements Slide.CustomViewBuilder {

    @NonNull
    @Override
    public View buildView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        return inflater.inflate(R.layout.layout_custom, parent, false);
    }
}

Then set it to your Slide:

new IntroductionBuilder(this)
        .withSlides(new Slide()
                .withCustomViewBuilder(new CustomViewBuilderImpl())
                .withColorResource(R.color.cyan)
        ).introduceMyself();

If you set a CustomViewBuilder to your Slide, all other values aside from the color are overridden. You have to manage all on your own.

Further reading

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

Upgrade Guide

1.4.0+ to 2.0.0+

  • This library now requires Java 8 (available in the new Android Studio 3 toolchain).
  • Behaviour change: Not passing a title, description or option hides the respective views. This way you can show fullscreen images.
    • The title and description parameters of the onSlideInit callback are now @Nullable
  • CustomViewBuilder is now in a different package and has been converted into an interface.

1.3.9 to 1.4.0+

  • Slide and Option have been moved into a different package. Just let Android Studio re-import them.
  • The OnSlideListener is now an interface on its own. Remove IntroductionConfig before each and let Android Studio re-import. Furthermore @NotNull annotations have been added; You should add them to the signature.

1.1.0 to 1.1.1+

  • The OnSlideInit method in the OnSlideListener now comes without the Fragment context. If you need a Context, call image.getContext().
  • There is now a class for Styles instead of an Integer. If you apply no Style, you have to do nothing, if you use one, change it to the following e.g.: .withStyle(new FullscreenStyle()).

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 recommended!). 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!

Metrics


Contributions and contributors

A guide for contribution can be found here.

  • @Akeshihiro for proper licencing and a small Gradle related adjustment.
  • @cafedeaqua for a small code improvement

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 cafedeaqua avatar liaohuqiu avatar rubengees avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

introduction's Issues

RTL support

  • [checked] I have verified that I am using the latest version and searched for exisiting issues (If this checkbox is not ticked, the issue might be ignored).

I am using version: 1.3.7
My device (if relevant) is: multiple devices
It runs Android version (if relevant): 4.1 - 7.0

This is what happens:

When using RTL device on 4.3 or above
The back and next buttons are reversed (Just adding drawable-rtl) will fix it I think

When using RTL device on below 4.3
The buttons come on top of each other
adding start and end with right and left I think will fix the problem
Thanks

screenshot_20170224-140037

whatsapp image 2017-02-24 at 2 06 18 pm

Unable to find explicit activity class

Please check if you are running the latest version and there are no existing Issues for your problem. Delete this line when submitting the Issue.

I am using version: 1.4.1
My device (if relevant) is: Galaxy s5
It runs Android version (if relevant): 6.0.1

This is what happens:

RuntimeException
Unable to find explicit activity class
{com.test.app/com.rubengees.introduction.IntroductionActivity}; have you declared this activity in your AndroidManifest.xml?

Any reason for this to happen ?

i'm calling like this
new IntroductionBuilder(this)
.withSlides(generateSlides())
.withPreviousButtonEnabled(false)
.withAllowBackPress(false)
.withForcedOrientation(IntroductionBuilder.ORIENTATION_PORTRAIT)
.withStyle(new CustomIntroStyle())
.introduceMyself();

Is this really API 11? Could it go lower?

Cool project! This looks like it may help a lot of people who have to deal with the new permissions model..

I notice that the library dependencies seem to be SDK 8 (froyo)... Just perusing the code here I didn't see anything in build.gradle specifying a minimum sdk level-- is there some reason why it's listed as being for sdk 11?

app crash after clicking tick sign in the last slide on older android versions

I am using version: 2.0.0

This is what happens:

I noticed that my app crash after clicking tick sign in the last slide on older android versions ( android 7.0 and android 8.1) I don't know about other version though it works well with no problem on Android 11.

I determined the following steps to reproduce:

go through the introduction slides and when in the last slide if I click the tick sign or swipe my app crashes .

Enhancement Request: Skip Button/Build Problems

Rubengees,

No Skip button feature could be found inthe Wiki for the Introduction library. Would it be possible to add a Skip Button to add Slides to allow the user to exit more easily?

Thanks,
Jeff

Typeface support

  • I have verified that I am using the latest version and searched for exisiting issues (If this checkbox is not ticked, the issue might be ignored).

I am using version: 1.3

Is it possible to add the support of changing the typeface of the title and description? I really didn't liked all the other intro libraries. Your's s simply the best in my use case. It works great. Thanks in advance if that would be possible. (The Intro would fit then better to the rest of my app.)

withView? in addition to withImage for Slide?

I want to add a bit of functionality (kinda like Google Maps first start) to show the icon and links to the privacy document as well as the app requirements, etc). Here is an example, not so much the button, but you get the gist I think.
start-screen1

onActivityResult from Activity is never called

Hi,

I really would like to use your library but I have the above mentioned issue.
Here's the code I'm using:

public class SplashActivity extends AppCompatActivity {

    static final Map<Integer, Integer> mImages;
    static {
        final Map<Integer, Integer> map = new HashMap<>();
        map.put(0, R.drawable.overview);
        map.put(1, R.drawable.bring_color);
        map.put(2, R.drawable.detail);
        mImages = Collections.unmodifiableMap(map);
    }

    @Override
    protected void onCreate(final Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        new IntroductionBuilder(this)
                .withSlides(generateSlides())
                .withStyle(IntroductionBuilder.STYLE_FULLSCREEN)
                .withOnSlideListener(new IntroductionConfiguration.OnSlideListener() {
                    @Override
                    protected void onSlideInit(final Fragment context, final int position, final TextView title, final ImageView image, final TextView description) {

                        ImageLoader.getInstance().displayImage(String.format("drawable://%s", mImages.get(position)), image);
                    }
                })
                .introduceMyself();
    }

    private List<Slide> generateSlides() {
        List<Slide> result = new ArrayList<>();

        result.add(new Slide().withTitle("Behalte den Überblick")
                .withDescription("Ordne deine Bücher in virtuellen Regalen.")
                .withColorResource(R.color.primary));
        result.add(new Slide().withTitle("Bring Farbe ins Spiel")
                .withOption(new Option("Nutze dynamische Farbgebung", true))
                .withColorResource(R.color.primary_dark));
        result.add(new Slide().withTitle("Detail").withDescription("Another description")
                .withColorResource(R.color.accent));

        return result;
    }

    void proceed() {

        final Intent i = new Intent(App.getContext(), MainActivity.class);
        startActivity(i);
        finish();
    }

    @Override
    protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {

        if (requestCode == IntroductionBuilder.INTRODUCTION_REQUEST_CODE &&
                resultCode == RESULT_OK) {

            for (final Option option : data.<Option>getParcelableArrayListExtra(IntroductionActivity.OPTION_RESULT)) {
                if (option.getPosition() == 1) {

                    PreferencesHelper.setBooleanPreference(R.string.settings_category_ui_dynamic_coloring_key, option.isActivated());

                }
            }

            proceed();

        } else {
            //Disable Feature A.
            //Handle other request codes.

            proceed();
        }

        proceed();
    }
}

Is there any error in my code?

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.