diff --git a/.gitignore b/.gitignore index afbdab3..50f0b56 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,51 @@ /.idea/libraries .DS_Store /build + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index f65cffb..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -TutorialViewApp \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 217af47..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/dictionaries/braunster.xml b/.idea/dictionaries/braunster.xml deleted file mode 100644 index b8bee26..0000000 --- a/.idea/dictionaries/braunster.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - animtaing - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index e206d70..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 9137773..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 9076de5..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index bfe8ee9..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b..0000000 --- a/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index c80f219..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/README.md b/README.md index 9681e80..97ce610 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,26 @@ [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-TutorialView-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1408) -##TutorialView + +[![Release](https://img.shields.io/github/release/itzikBraun/TutorialView.svg?label=JitPack)](https://jitpack.io/#itzikBraun/TutorialView) + +TutorialView +=============== +[![Join the chat at https://gitter.im/itzikBraun/TutorialView](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/itzikBraun/TutorialView?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ![alt tag](http://raw.github.com/ItzikBraun/TutorialView/master/screen_shots/example.gif) -An Android library project providing `Activity` with explanation about views in your app. +An Android library project providing `Activity` with an explanation about views in your app. -The `TutorialActivity` can be used as a walk through for the entire screen that is currently visible, Or just for one view on the screen. +The `TutorialActivity` can be used as a walkthrough for the entire screen that is currently visible, Or just for one view on the screen. To get the intent to start the `TutorialActivity` you need to use the `TutorialIntentBuilder`, The builder will help you build the intent to start the activity, You would have to pass a `Tutorial` object to the intent builder. -###Usage -####Tutorial +If you use any kind of analytics to track your user behavior in your app you can start the `TutorialActivity` for result and +so when it returns you can collect the data whether the user skipped the tutorials or watched it fully. +You can also retrieve the amount of tutorials the user have viewed before skipping the walkthrough using `TutorialActivity.VIEWED_TUTORIALS`. + +### Usage +#### Tutorial The tutorial object holds the tutorial info and attributes. You can create a Tutorial by using the `TutorialBuilder`. You can customize the following: * Title - Will appear on the top of the view, If the view that is surrounded is on top it will be shown below it. @@ -21,12 +30,17 @@ You can customize the following: * TypefaceName - The path to the wanted typeface to use for all text view in the tutorial, Example: "/fonts/arial.ttf". * AnimationDuration - the duration time in milliseconds that will be used for the animation. * InfoPosition - The position of the info text, This could be Above, Below, LeftOf and Right of all relevant to the view that need to be surrounded. Values are stored in `Tutorial.InfoPosition` -* GotItPosition - The position of the "GotIt" button, This could be Top(If has title it will be below it) and Bottom. Values are stored in `Tutorial.GotItPosition` +* GotItPosition - The position of the "GotIt" button, This could be Top(If has a title it will be below it) and Bottom. Values are stored in `Tutorial.GotItPosition` * ~~AnimationType - the animation that will be used for showing and hiding the tutorial~~ This is a work in progress currently not working. -Each tutorial that was passed holds it's position on screen, title, background color, the text explenation and more customizable attributes. +Each tutorial that was passed holds it's position on the screen, title, background color, the text explanation and more customizable attributes. +By default the "StatusBar" and the "NavigationBar" are also being colored on Lollipop devices, You can change the default behavior by using: +``` +TutorialIntentBuilder builder = new TutorialIntentBuilder(MainActivity.this); -######Example of creating a simple tutorial. +builder.changeSystemUiColor(false); +``` +###### Example of creating a simple tutorial. ``` java TutorialIntentBuilder builder = new TutorialIntentBuilder(MainActivity.this); @@ -50,7 +64,7 @@ startActivity(builder.getIntent()); // This will allow the nice wrapping of the view by the tutorial activity. overridePendingTransition(R.anim.dummy, R.anim.dummy); ``` -######Example of creating a walk through from two Tutorials. +###### Example of creating a walk through from two Tutorials. ```java ArrayList tutorials = new ArrayList<>(); @@ -68,7 +82,7 @@ startActivity(builder.getIntent()); overridePendingTransition(R.anim.dummy, R.anim.dummy); ``` -####Important! +#### Important! You should override the `Activity` pending transition animation like this, If you wont override it the `TutorialActivity` would animate itself in and will ruin the view animation. (Call it after you call `startActivity(Intent)` ). @@ -79,8 +93,20 @@ overridePendingTransition(R.anim.dummy, R.anim.dummy); ``` -###INCLUDING IN YOUR PROJECT -Import the "tutorial_view" module to your project, Then in your build.gradle file add this.(You probably already have the *dependencies* so just add the "*compile project(':tutorial_view')*" ). +### INCLUDING IN YOUR PROJECT +###### From Maven Central + +Add as a dependency to your build.gradle: + +```` +dependencies{ + compile 'com.github.itzikbraun:TutorialView:0.8.1' +} +```` + +###### Downloading the source code +Import the "tutorial_view" module to your project, +Then in your build.gradle file add this.(You probably already have the *dependencies* so just add the "*compile project(':tutorial_view')*" ). ``` dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) @@ -90,17 +116,18 @@ dependencies { You can also copy past it to your project and before adding it to your dependencies you need to add it to *settings.gradle* so the system will understand it's a module like this: ``` -// Notice that in your settings file there would be more names so dont delete them, This are your other modules. +// Notice that in your settings file there would be more names so don't delete them, Those are your other modules. include':tutorial_view' ``` -###TODO: -* Return result when `TutorialActivity` finishes so you could know when it was done and if was skipped. +### TODO: +* add the roboto font family to the app assets so it will work on lower versions +* Make a sample app and publish it on Google Play -###Author +### Author [Itzik Braun - Google+](https://plus.google.com/+ItzikBraunster) -###LICENSE +### LICENSE Copyright (C) 2014 Itzik Braun This program is free software: you can redistribute it and/or modify diff --git a/TutorialView.iml b/TutorialView.iml deleted file mode 100644 index 2a02201..0000000 --- a/TutorialView.iml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/TutorialViewApp.iml b/TutorialViewApp.iml deleted file mode 100644 index 5550340..0000000 --- a/TutorialViewApp.iml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/app/.gitignore b/app/.gitignore index 796b96d..50f0b56 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1 +1,54 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store /build + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties diff --git a/app/app.iml b/app/app.iml deleted file mode 100644 index 3cf6bd9..0000000 --- a/app/app.iml +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/build.gradle b/app/build.gradle index 72706c0..bdde61c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,24 +1,39 @@ apply plugin: 'com.android.application' +def versionMajor = 0 +def versionMinor = 8 +def versionPatch = 2 +def versionBuild = 2 // bump for dogfood builds, public betas, etc. + android { - compileSdkVersion 21 - buildToolsVersion "21.1.2" + compileSdkVersion 23 + buildToolsVersion "23.0.0" defaultConfig { applicationId "com.braunster.tutorialviewapp" minSdkVersion 15 - targetSdkVersion 21 - versionCode 1 - versionName "1.0" + targetSdkVersion 23 + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + + + versionCode versionMajor * 1000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild + versionName "${versionMajor}.${versionMinor}.${versionPatch}" } - buildTypes { - release { - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } + + packagingOptions { + + exclude 'META-INF/LICENSE.txt' + exclude 'LICENSE.txt' } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':tutorial_view') + + // Testing-only dependencies + androidTestCompile 'com.android.support.test:runner:0.2' + androidTestCompile 'com.android.support.test:rules:0.2' + androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1' } diff --git a/app/src/androidTest/java/com/braunster/tutorialviewapp/ApplicationTest.java b/app/src/androidTest/java/com/braunster/tutorialviewapp/ApplicationTest.java deleted file mode 100644 index 577d1ac..0000000 --- a/app/src/androidTest/java/com/braunster/tutorialviewapp/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.braunster.tutorialviewapp; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/app/src/androidTest/java/com/braunster/tutorialviewapp/MainActivityTest.java b/app/src/androidTest/java/com/braunster/tutorialviewapp/MainActivityTest.java new file mode 100644 index 0000000..326f47c --- /dev/null +++ b/app/src/androidTest/java/com/braunster/tutorialviewapp/MainActivityTest.java @@ -0,0 +1,155 @@ +package com.braunster.tutorialviewapp; + +import android.content.Intent; +import android.graphics.Color; +import android.test.ActivityInstrumentationTestCase2; +import android.test.TouchUtils; +import android.test.suitebuilder.annotation.SmallTest; +import android.view.View; + +import com.braunster.tutorialview.TutorialActivity; +import com.braunster.tutorialview.object.Tutorial; +import com.braunster.tutorialview.object.TutorialBuilder; +import com.braunster.tutorialview.object.TutorialIntentBuilder; + +import java.util.Random; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist; +import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; + +/** + * Created by braunster on 08.05.15. + */ +public class MainActivityTest extends ActivityInstrumentationTestCase2 { + + MainActivity activity; + + TutorialActivity tutorialActivity; + + private boolean startTutorialForResult = false; + + public MainActivityTest() { + super(MainActivity.class); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + + activity = getActivity(); + } + + @SmallTest + public void testWalkThrough(){ + + assertNotNull(activity); + + onView(withText("T")).check(matches(isDisplayed())); + + startWalkThrough(); + + checkWalkThroughOpen(); + } + + @SmallTest + public void testClick(){ + TouchUtils.clickView(this, activity.findViewById(R.id.view_almost_top_right)); + + + onView(withId(R.id.view_almost_top_right)).check(doesNotExist()); + } + + + + + public void checkWalkThroughOpen(){ + + // Tutorial should be open thus the button should not exist. + onView(withText("T")).check(doesNotExist()); + + assertNotNull(tutorialActivity); + + try { + runTestOnUiThread(new Runnable() { + @Override + public void run() { + getInstrumentation().callActivityOnDestroy(tutorialActivity); + + getInstrumentation().callActivityOnResume(activity); + + onView(withText("T")).check(matches(isDisplayed())); + } + }); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + + } + + public void startWalkThrough(){ + + + Tutorial t1 = getBasicBuilderForTest(activity.findViewById(R.id.view_bottom_left)) + .setTutorialInfoTextPosition(Tutorial.InfoPosition.ABOVE) + .setTutorialGotItPosition(Tutorial.GotItPosition.BOTTOM) + .build(); + + Tutorial t2 = getBasicBuilderForTest(activity.findViewById(R.id.view_top_right)) + .setTutorialInfoTextPosition(Tutorial.InfoPosition.LEFT_OF) + .build(); + + Tutorial t3 = getBasicBuilderForTest(activity.findViewById(R.id.view_almost_top_right)) + .setTutorialInfoTextPosition(Tutorial.InfoPosition.RIGHT_OF) + .build(); + + Tutorial t4 = getBasicBuilderForTest(activity.findViewById(R.id.view_top_left)) + .setTutorialInfoTextPosition(Tutorial.InfoPosition.BELOW) + .build(); + + Tutorial t5 = getBasicBuilderForTest(activity.findViewById(R.id.view_center)) + .setTutorialInfoTextPosition(Tutorial.InfoPosition.BELOW) + .setTutorialGotItPosition(Tutorial.GotItPosition.BOTTOM) + .build(); + + + final TutorialIntentBuilder builder = new TutorialIntentBuilder(activity); + + // if true the status bar and navigation bar will be colored on Lollipop devices. + builder.changeSystemUiColor(true); + + builder.setWalkThroughList(t1, t2, t3, t4, t5); + + final Intent intent = builder.getIntent(); + intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); + + tutorialActivity = (TutorialActivity) getInstrumentation().startActivitySync(intent); + + assertNotNull(tutorialActivity); + + assertEquals(tutorialActivity.getClass(), TutorialActivity.class); + } + + private TutorialBuilder getBasicBuilderForTest(View v){ + TutorialBuilder tBuilder = new TutorialBuilder(); + + tBuilder.setTitle("The Title") + .setViewToSurround(v) + .setInfoText("This is the explanation about the view.") + .setBackgroundColor(randomColor()) + .setTutorialTextColor(Color.WHITE) + .setTutorialTextTypeFaceName("fonts/roboto-light.ttf") + .setTutorialTextSize(30) + .setAnimationDuration(500); + + return tBuilder; + } + + private int randomColor(){ + Random rnd = new Random(); + return Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9e0eee0..21b5f7e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,9 +17,6 @@ - - diff --git a/app/src/main/java/com/braunster/tutorialviewapp/MainActivity.java b/app/src/main/java/com/braunster/tutorialviewapp/MainActivity.java index 528e907..04bd6d1 100644 --- a/app/src/main/java/com/braunster/tutorialviewapp/MainActivity.java +++ b/app/src/main/java/com/braunster/tutorialviewapp/MainActivity.java @@ -1,12 +1,16 @@ package com.braunster.tutorialviewapp; import android.app.Activity; +import android.content.Intent; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.view.Menu; import android.view.View; +import android.widget.TextView; +import android.widget.Toast; +import com.braunster.tutorialview.TutorialActivity; import com.braunster.tutorialview.object.Tutorial; import com.braunster.tutorialview.object.TutorialBuilder; import com.braunster.tutorialview.object.TutorialIntentBuilder; @@ -19,6 +23,11 @@ public class MainActivity extends Activity implements View.OnClickListener { private TutorialView tutorialView; + private static final int TUTORIAL_REQUEST = 1991; + + // For switching between startActivityForResult and startActivity + private boolean startTutorialForResult = false; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -30,6 +39,11 @@ protected void onCreate(Bundle savedInstanceState) { // getWindow().requestFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); + + // Setting the version name. + ((TextView) findViewById(R.id.txt_version)).setText(String.format("Version: %s", BuildConfig.VERSION_NAME)); + + tutorialView = (TutorialView) findViewById(R.id.tutorial_view); findViewById(R.id.view_bottom_left).setOnClickListener(this); @@ -41,6 +55,7 @@ protected void onCreate(Bundle savedInstanceState) { if (getActionBar() != null) getActionBar().setBackgroundDrawable(new ColorDrawable(Color.DKGRAY)); + //Using the tutorial view // This is used for the tutorial view that should be in your root view. // This may lead to problems when used inside LinearLayout and maybe other view. @@ -52,6 +67,10 @@ protected void onCreate(Bundle savedInstanceState) { tutorialView.setTutorialTextTypeFace("fonts/roboto_light.ttf"); tutorialView.setHasStatusBar(true); tutorialView.setTutorialText("This is some general text that is not that long but also not so short."); + + // Only show the walk through when the activity is first created. +// if (savedInstanceState == null) +// startWalkThrough(); } @Override @@ -61,6 +80,40 @@ public boolean onCreateOptionsMenu(Menu menu) { return true; } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + if (requestCode == TUTORIAL_REQUEST) + { + boolean isWalkThrough = data.getBooleanExtra(TutorialActivity.IS_WALKTHROUGH, false); + + if (resultCode == RESULT_OK) + { + if (isWalkThrough) + Toast.makeText(this, "The walkthrough was viewed fully", Toast.LENGTH_SHORT).show(); + else + Toast.makeText(this, "The user GotIt", Toast.LENGTH_SHORT).show(); + } + else if (resultCode == RESULT_CANCELED) + { + if (isWalkThrough) + { + Toast.makeText(this, + String.format("Tutorial was skipped, User viewed %s Tutorials", data.getIntExtra(TutorialActivity.VIEWED_TUTORIALS, 0)), + Toast.LENGTH_SHORT).show(); + } + else + { + Toast.makeText(this, + "Tutorial was skipped" , + Toast.LENGTH_SHORT).show(); + } + + } + } + } + private int randomColor(){ Random rnd = new Random(); return Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); @@ -82,7 +135,7 @@ private TutorialBuilder getBasicBuilderForTest(View v){ .setInfoText("This is the explanation about the view.") .setBackgroundColor(randomColor()) .setTutorialTextColor(Color.WHITE) - .setTutorialTextTypeFaceName("fonts/olivier.ttf") +// .setTutorialTextTypeFaceName("fonts/roboto_light.ttf") .setTutorialTextSize(30) .setAnimationDuration(500); @@ -94,6 +147,9 @@ public void onClick(View v) { TutorialIntentBuilder builder = new TutorialIntentBuilder(MainActivity.this); + // if true the status bar and navigation bar will be colored on Lollipop devices. + builder.changeSystemUiColor(true); + TutorialBuilder tBuilder = getBasicBuilderForTest(v); switch (v.getId()) @@ -133,10 +189,64 @@ public void onClick(View v) { builder.setTutorial(tBuilder.build()); - startActivity(builder.getIntent()); + if (startTutorialForResult) + startActivityForResult(builder.getIntent(), TUTORIAL_REQUEST); + else + startActivity(builder.getIntent()); // Override the default animation of the entering activity. // This will allow the nice wrapping of the view by the tutorial activity. overridePendingTransition(R.anim.dummy, R.anim.dummy); } + + public void startWalkThrough(){ + + // Running a walk through as the activity is opened, Tutorial + // building should be wrapped in a runnable that is posted so + // all views will have their positions on the screen. + getWindow().getDecorView().post(new Runnable() { + @Override + public void run() { + + Tutorial t1 = getBasicBuilderForTest(findViewById(R.id.view_bottom_left)) + .setTutorialInfoTextPosition(Tutorial.InfoPosition.ABOVE) + .setTutorialGotItPosition(Tutorial.GotItPosition.BOTTOM) + .build(); + + Tutorial t2 = getBasicBuilderForTest(findViewById(R.id.view_top_right)) + .setTutorialInfoTextPosition(Tutorial.InfoPosition.LEFT_OF) + .build(); + + Tutorial t3 = getBasicBuilderForTest(findViewById(R.id.view_almost_top_right)) + .setTutorialInfoTextPosition(Tutorial.InfoPosition.RIGHT_OF) + .build(); + + Tutorial t4 = getBasicBuilderForTest(findViewById(R.id.view_top_left)) + .setTutorialInfoTextPosition(Tutorial.InfoPosition.BELOW) + .build(); + + Tutorial t5 = getBasicBuilderForTest(findViewById(R.id.view_center)) + .setTutorialInfoTextPosition(Tutorial.InfoPosition.BELOW) + .setTutorialGotItPosition(Tutorial.GotItPosition.BOTTOM) + .build(); + + + TutorialIntentBuilder builder = new TutorialIntentBuilder(MainActivity.this); + + // if true the status bar and navigation bar will be colored on Lollipop devices. + builder.changeSystemUiColor(true); + + builder.setWalkThroughList(t1, t2, t3, t4, t5); + + if (startTutorialForResult) + startActivityForResult(builder.getIntent(), TUTORIAL_REQUEST); + else + startActivity(builder.getIntent()); + + // Override the default animation of the entering activity. + // This will allow the nice wrapping of the view by the tutorial activity. + overridePendingTransition(R.anim.dummy, R.anim.dummy); + } + }); + } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 7c71bfa..2be4f58 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -84,4 +84,16 @@ android:layout_marginTop="50dp" android:id="@+id/view_top_right"/> + + diff --git a/build.gradle b/build.gradle index 6356aab..1da0039 100644 --- a/build.gradle +++ b/build.gradle @@ -3,17 +3,26 @@ buildscript { repositories { jcenter() + mavenCentral() + } dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath 'com.android.tools.build:gradle:1.2.3' } } + allprojects { + repositories { jcenter() + mavenCentral() + + } + // Fix for a conflict with support library that included with espresso + configurations.all { + resolutionStrategy.force 'com.android.support:support-annotations:23.0.0' } } + + diff --git a/gradle.properties b/gradle.properties index 1d3591c..a33f991 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,20 @@ # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true \ No newline at end of file +# org.gradle.parallel=true + + +VERSION_NAME=0.8.2 +VERSION_CODE=82 +GROUP=com.github.itzikbraun + +POM_DESCRIPTION=A showcase library +POM_URL=https://github.com/itzikBraun/TutorialView +POM_SCM_URL=https://github.com/itzikBraun/TutorialView +POM_SCM_CONNECTION=scm:git@github.com:itzikbraun/TutorialView.git +POM_SCM_DEV_CONNECTION=scm:git@github.com:itzikbraun/TutorialView.git +POM_LICENCE_NAME=The Apache Software License, Version 2.0 +POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt +POM_LICENCE_DIST=repo +POM_DEVELOPER_ID=ItzikBraun +POM_DEVELOPER_NAME=Itzik Braun diff --git a/tutorial_view/.gitignore b/tutorial_view/.gitignore index 796b96d..50f0b56 100644 --- a/tutorial_view/.gitignore +++ b/tutorial_view/.gitignore @@ -1 +1,54 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store /build + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties diff --git a/tutorial_view/build.gradle b/tutorial_view/build.gradle index 409ef72..b8dc1c6 100644 --- a/tutorial_view/build.gradle +++ b/tutorial_view/build.gradle @@ -1,15 +1,24 @@ apply plugin: 'com.android.library' +def versionMajor = 0 +def versionMinor = 8 +def versionPatch = 1 +def versionBuild = 0 // bump for dogfood builds, public betas, etc. + +version = "${versionMajor}.${versionMinor}.${versionPatch}" + android { - compileSdkVersion 21 - buildToolsVersion "21.1.2" + compileSdkVersion 23 + buildToolsVersion "23.0.0" defaultConfig { minSdkVersion 15 - targetSdkVersion 21 - versionCode 1 - versionName "0.7.1" + targetSdkVersion 23 + + versionCode versionMajor * 1000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild + versionName version } + buildTypes { release { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' @@ -17,6 +26,11 @@ android { } } + dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) + + compile 'com.android.support:support-annotations:23.0.0' } + +//apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle' diff --git a/tutorial_view/src/main/AndroidManifest.xml b/tutorial_view/src/main/AndroidManifest.xml index 8e63cac..f720c10 100644 --- a/tutorial_view/src/main/AndroidManifest.xml +++ b/tutorial_view/src/main/AndroidManifest.xml @@ -1,8 +1,10 @@ - + + + diff --git a/tutorial_view/src/main/assets/fonts/olivier.ttf b/tutorial_view/src/main/assets/fonts/olivier.ttf deleted file mode 100644 index 6d56f71..0000000 Binary files a/tutorial_view/src/main/assets/fonts/olivier.ttf and /dev/null differ diff --git a/tutorial_view/src/main/java/com/braunster/tutorialview/TutorialActivity.java b/tutorial_view/src/main/java/com/braunster/tutorialview/TutorialActivity.java index 39d60ce..2e4db5c 100644 --- a/tutorial_view/src/main/java/com/braunster/tutorialview/TutorialActivity.java +++ b/tutorial_view/src/main/java/com/braunster/tutorialview/TutorialActivity.java @@ -1,26 +1,50 @@ package com.braunster.tutorialview; import android.app.Activity; +import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.content.res.Configuration; +import android.os.Build; import android.os.Bundle; +import android.util.Log; +import com.braunster.tutorialview.object.Debug; +import com.braunster.tutorialview.object.Tutorial; import com.braunster.tutorialview.object.TutorialIntentBuilder; +import com.braunster.tutorialview.view.AbstractTutorialView; import com.braunster.tutorialview.view.TutorialLayout; import com.braunster.tutorialview.view.TutorialView; +import java.util.ArrayList; + /** * Created by braunster on 02/12/14. */ public class TutorialActivity extends Activity { public static final String TAG = TutorialActivity.class.getSimpleName(); - public static final boolean DEBUG = true; + public static final boolean DEBUG = Debug.TutorialActivity; private TutorialLayout mTutorialLayout; + private Tutorial mTutorial; + + private int mCurrentTutorialPos = 0; + + private static final String CURRENT_TUTORIAL = "current_tutorial"; + + private Bundle savedInstanceState; + + public static final String VIEWED_TUTORIALS= "viewed_tutorials", IS_WALKTHROUGH = "is_tutorial"; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + this.savedInstanceState = savedInstanceState; + + lockOrientation(); + setContentView(R.layout.activity_tutorial_layout); mTutorialLayout = (TutorialLayout) findViewById(R.id.tutorial_layout); @@ -30,13 +54,20 @@ protected void onCreate(Bundle savedInstanceState) { throw new NullPointerException("You must provide extras to the activity to set up the tutorial view."); } + mTutorialLayout.setHasStatusBar(TutorialIntentBuilder.hasStatusBar(getIntent())); + + mTutorial = TutorialIntentBuilder.getTutorial(getIntent()); + // Finish the activity when the tutorial is closed. + // In case the tutorial view is showing a walkthrough this would be ignored. mTutorialLayout.setTutorialClosedListener(new TutorialView.TutorialClosedListener() { @Override public void onClosed() { - finish(); + resultDone(); } }); + + updateSystemUIColors(); } /** @@ -46,14 +77,44 @@ public void onClosed() { @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); + + if (TutorialIntentBuilder.isWalkThrough(getIntent())) + { + ArrayList tutorials = TutorialIntentBuilder.getWalkThroughData(getIntent()); + + // If the activity is re created we should start + // from the last tutorial that was visible + if (savedInstanceState != null) + { + mCurrentTutorialPos = savedInstanceState.getInt(CURRENT_TUTORIAL); + + if (DEBUG) Log.d(TAG, String.format("mCurrentTutorialPos: %s, Tutorial list size: %s", + mCurrentTutorialPos, tutorials.size())); + + // Removing tutorials that was already shown. + int i = 0; + while (i < mCurrentTutorialPos) + { + i++; + tutorials.remove(0); + } + + // Setting the current tutorial to be the new first tutorial + mTutorial = tutorials.get(0); + } + + mTutorialLayout.setWalkThroughData(tutorials); + } + else + { + mTutorialLayout.setTutorial(mTutorial, false); + } if (hasFocus && !mTutorialLayout.isShowing()) mTutorialLayout.post(new Runnable() { @Override public void run() { { - TutorialIntentBuilder.updateTutorialViewFromIntent(mTutorialLayout, getIntent()); - TutorialIntentBuilder.showTutorial(mTutorialLayout, getIntent()); // If the tutorial is a walk through we would need to set a WalkThroughListener. @@ -61,19 +122,25 @@ public void run() { { mTutorialLayout.setWalkThroughListener(new TutorialLayout.WalkThroughListener() { @Override - public void onNextTutorialShown() { + public void onNextTutorialShown(Tutorial tutorial) { + // Keeping track of the position in the tutorial list. + // Used for a situation that the activity was killed and we need + // to re-create it from the last visible tutorial. + mCurrentTutorialPos++; + + mTutorial = tutorial; + updateSystemUIColors(); } @Override public void onWalkTroughSkipped() { -// Toast.makeText(TutorialActivity.this, "Walk through was skipped.", Toast.LENGTH_LONG).show(); - finish(); + resultSkipped(); } @Override public void onWalkThroughDone() { - finish(); + resultDone(); } }); } @@ -82,6 +149,13 @@ public void onWalkThroughDone() { }); } + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + outState.putInt(CURRENT_TUTORIAL, mCurrentTutorialPos); + } + /** * Back press will close the tutorial which will trigger the * {@link com.braunster.tutorialview.view.TutorialView.TutorialClosedListener#onClosed() onClosed()} method @@ -95,11 +169,122 @@ public void onWalkThroughDone() { * */ @Override public void onBackPressed() { - if (TutorialIntentBuilder.skipOnBackPressed(getIntent())) + // Skipping the walkthrough if requested. + if (mTutorialLayout.isWalkThrough() && TutorialIntentBuilder.skipOnBackPressed(getIntent())) { mTutorialLayout.skip(); } - else mTutorialLayout.closeTutorial(); + else { + // Setting a new TutorialCloseListener so we could return + // a result to the calling activity that the tutorial was closed using the back press. + if (!mTutorialLayout.isWalkThrough()) + { + mTutorialLayout.setTutorialClosedListener(new AbstractTutorialView.TutorialClosedListener() { + @Override + public void onClosed() { + resultSkipped(); + } + }); + } + + mTutorialLayout.closeTutorial(); + } + } + + private void updateSystemUIColors(){ + + if (isFinishing()) + return; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) + if (isDestroyed()) + return; + + // coloring the status bar and navigation bar from lollipop. + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) + { + if (TutorialIntentBuilder.changesSystemUiColors(getIntent()) && mTutorial != null) + { + getWindow().setStatusBarColor(mTutorial.getTutorialBackgroundColor()); + getWindow().setNavigationBarColor(mTutorial.getTutorialBackgroundColor()); + } + } + } + + /** + * Locking the orientation so the activity will stay in the same orientation as it was entered. + * The position of the place that need to stay visible is pre-calculated so currently there + * is no other way to handle orientation changes. + * + * Code was taken from this stackoverflow answer: + * http://stackoverflow.com/a/8450316/2568492 + * */ + private void lockOrientation(){ + switch (getResources().getConfiguration().orientation){ + case Configuration.ORIENTATION_PORTRAIT: + if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO){ + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } else { + int rotation = getWindowManager().getDefaultDisplay().getRotation(); + if(rotation == android.view.Surface.ROTATION_90|| rotation == android.view.Surface.ROTATION_180){ + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); + } else { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } + } + break; + + case Configuration.ORIENTATION_LANDSCAPE: + if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO){ + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } else { + int rotation = getWindowManager().getDefaultDisplay().getRotation(); + if(rotation == android.view.Surface.ROTATION_0 || rotation == android.view.Surface.ROTATION_90){ + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } else { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); + } + } + break; + } + } + + private void resultSkipped(){ + + if (getCallingActivity() != null) + { + Intent intent = getResultIntent(); + + // Adding the amount of tutorials that was shown before skipping. + if (mTutorialLayout.isWalkThrough()){ + intent.putExtra(VIEWED_TUTORIALS, mCurrentTutorialPos); + } + + setResult(RESULT_CANCELED, intent); + } + + finish(); + } + + private void resultDone(){ + + if (getCallingActivity() != null) + { + Intent intent = getResultIntent(); + setResult(RESULT_OK, intent); + } + + + finish(); } + private Intent getResultIntent(){ + + + Intent intent = new Intent(); + + intent.putExtra(IS_WALKTHROUGH, mTutorialLayout.isWalkThrough()); + + return intent; + } } diff --git a/tutorial_view/src/main/java/com/braunster/tutorialview/TutorialInterface.java b/tutorial_view/src/main/java/com/braunster/tutorialview/TutorialInterface.java index 9ce2d03..22434e8 100644 --- a/tutorial_view/src/main/java/com/braunster/tutorialview/TutorialInterface.java +++ b/tutorial_view/src/main/java/com/braunster/tutorialview/TutorialInterface.java @@ -10,6 +10,8 @@ public interface TutorialInterface { /** * The Layout id of the view that will be used to show the tutorial text or information. + * + * @param tutorialInfoLayoutId the id of the layout that should be used for the info text. * */ public void setTutorialInfoLayoutId(int tutorialInfoLayoutId); @@ -17,6 +19,8 @@ public interface TutorialInterface { /** * The background color for the tutorial. + * + * @param mTutorialBackgroundColor the backgrond color to use for the background * */ public void setTutorialBackgroundColor(int mTutorialBackgroundColor); @@ -24,7 +28,9 @@ public interface TutorialInterface { /** * The text that will be used for the {@link com.braunster.tutorialview.view.TutorialView#mTutorialInfoView mTutorialInfoView}. - * Only if the layout that is used is the default layout ({@link com.braunster.tutorialview.R.layout#tutorial_text tutorial_text}). + * Only if the layout that is used is the default layout com.braunster.tutorialview.R.layout#tutorial_text. + * + * @param tutorialText The explenation text about the view. * * @see com.braunster.tutorialview.view.TutorialView#setTutorialTextTypeFace(String) * @see com.braunster.tutorialview.view.TutorialView#setTutorialTextColor(int) @@ -39,6 +45,8 @@ public interface TutorialInterface { * Set the size that will be used for the default info view text view. * The size of the title and other button won't be changed. * + * @param mTutorialTextSize the size that would be used for the info text. + * * @see com.braunster.tutorialview.view.TutorialView#setTutorialText(String) * @see com.braunster.tutorialview.view.TutorialView#setTutorialTextColor(int) * @see com.braunster.tutorialview.view.TutorialView#setTutorialTextTypeFace(String) @@ -49,10 +57,11 @@ public interface TutorialInterface { public int getTutorialTextSize(); /** - * Set the color that will be used for the default info view text view. + * @param mTutorialTextColor the color that will be used for the default info view text view. * * This color will also be used for the "Got It" button. * + * * @see com.braunster.tutorialview.view.TutorialView#setTutorialTextSize(int) * @see com.braunster.tutorialview.view.TutorialView#setTutorialText(String) * @see com.braunster.tutorialview.view.TutorialView#setTutorialTextTypeFace(String) @@ -63,7 +72,7 @@ public interface TutorialInterface { public int getTutorialTextColor(); /** - * Set the typeface that will be used for the default info view text view. + * @param tutorialTextTypeFaceName the typeface name that will be used for the default info view text view. * * @see com.braunster.tutorialview.view.TutorialView#setTutorialTextSize(int) * @see com.braunster.tutorialview.view.TutorialView#setTutorialText(String) @@ -75,14 +84,14 @@ public interface TutorialInterface { public String getTutorialTextTypeFace(); /** - * Setting the animation type that will be used to show and hide the tutorial. + * @param animationType the animation type that will be used to show and hide the tutorial. * */ - public void setAnimationType(AbstractTutorialView.AnimationType mAnimationType); + public void setAnimationType(AbstractTutorialView.AnimationType animationType); public AbstractTutorialView.AnimationType getAnimationType(); /** - * Set the time that will be used for the animation + * @param duration the time that will be used for the animation * */ public void setAnimationDuration(long duration); diff --git a/tutorial_view/src/main/java/com/braunster/tutorialview/object/Debug.java b/tutorial_view/src/main/java/com/braunster/tutorialview/object/Debug.java new file mode 100644 index 0000000..e6cbf6f --- /dev/null +++ b/tutorial_view/src/main/java/com/braunster/tutorialview/object/Debug.java @@ -0,0 +1,10 @@ +package com.braunster.tutorialview.object; + +/** + * Created by braunster on 03.05.15. + */ +public class Debug { + + public static final boolean TutorialActivity = false; + public static final boolean TutorialIntentBuilder = false; +} diff --git a/tutorial_view/src/main/java/com/braunster/tutorialview/object/TutorialBuilder.java b/tutorial_view/src/main/java/com/braunster/tutorialview/object/TutorialBuilder.java index d215dd5..bdd67d0 100644 --- a/tutorial_view/src/main/java/com/braunster/tutorialview/object/TutorialBuilder.java +++ b/tutorial_view/src/main/java/com/braunster/tutorialview/object/TutorialBuilder.java @@ -168,8 +168,9 @@ public TutorialBuilder setTutorialInfoTextPosition(int infoTextPosition) { return this; } - public void setTutorialGotItPosition(int gotItPosition) { + public TutorialBuilder setTutorialGotItPosition(int gotItPosition) { this.mTutorialGotItPosition = gotItPosition; + return this; } public Tutorial build(){ diff --git a/tutorial_view/src/main/java/com/braunster/tutorialview/object/TutorialIntentBuilder.java b/tutorial_view/src/main/java/com/braunster/tutorialview/object/TutorialIntentBuilder.java index 276e275..6246eee 100644 --- a/tutorial_view/src/main/java/com/braunster/tutorialview/object/TutorialIntentBuilder.java +++ b/tutorial_view/src/main/java/com/braunster/tutorialview/object/TutorialIntentBuilder.java @@ -17,8 +17,8 @@ */ public class TutorialIntentBuilder { - public static final String TAG = TutorialIntentBuilder.class.getSimpleName(); - public static final boolean DEBUG = false; + private static final String TAG = TutorialIntentBuilder.class.getSimpleName(); + private static final boolean DEBUG = Debug.TutorialIntentBuilder; private static final String TUTORIAL_OBJ = "tutorial_obj"; @@ -28,7 +28,9 @@ public class TutorialIntentBuilder { private static final String SKIP_TUTORIAL_ON_BACK_PRESSED = "skip_tutorial_on_back_pressed"; - private Intent intent; + private static final String CHANGE_SYSTEM_UI_COLOR = "change_system_ui_colors"; + + private final Intent intent; public TutorialIntentBuilder(Context context){ intent = new Intent(context, TutorialActivity.class ); @@ -43,6 +45,15 @@ public TutorialIntentBuilder(Intent intent){ this.intent = intent; } + /** + * @param change if true changes the color of the status and navigation + * bars on devices running API 21 (Lollipop) and up. + * * * */ + public TutorialIntentBuilder changeSystemUiColor(boolean change){ + intent.putExtra(CHANGE_SYSTEM_UI_COLOR, change); + + return this; + } public TutorialIntentBuilder hasStatusBar(boolean hasStatusBar){ intent.putExtra(HAS_STATUS_BAR, hasStatusBar); @@ -78,6 +89,7 @@ public TutorialIntentBuilder skipTutorialOnBackPressed(boolean skip){ return this; } + /** * @return the intent that was build and populated with all attributes. * */ @@ -85,6 +97,25 @@ public Intent getIntent(){ return intent; } + + + + + + + + public static boolean changesSystemUiColors(Intent intent){ + return intent.getBooleanExtra(CHANGE_SYSTEM_UI_COLOR, true); + } + + /** + * @return the value passed in the intent, Default value is true as most apps has a status bar. + * */ + public static boolean hasStatusBar(Intent intent){ + return intent.getBooleanExtra(HAS_STATUS_BAR, true); + + } + /** * @return true if should skip the walk through when user press on the back button. * */ @@ -107,6 +138,9 @@ public static void showTutorial(TutorialViewInterface tutorial, Intent intent){ if (intent.getExtras().containsKey(WALK_THROUGH_DATA)) { + ArrayList tutorials = intent.getExtras().getParcelableArrayList(WALK_THROUGH_DATA); + + ((WalkThroughInterface) tutorial).setWalkThroughData(tutorials); ((WalkThroughInterface) tutorial).startWalkThrough(); return; } @@ -127,19 +161,42 @@ public static void showTutorial(TutorialViewInterface tutorial, Intent intent){ } /** - * Setup tutorial from data saved in the intent. + * @return true if the intent contains a walk through data (List of tutorials) * */ - public static void updateTutorialViewFromIntent(final TutorialViewInterface tutorial, Intent intent){ - tutorial.setHasStatusBar(intent.getBooleanExtra(HAS_STATUS_BAR, true)); + public static boolean isWalkThrough(Intent intent){ + if (intent.getExtras().containsKey(WALK_THROUGH_DATA)) + return true; - /** - * Update the tutorial with data from the intent. - * */ - if (intent.getExtras().containsKey(TUTORIAL_OBJ)) + + return false; + } + + /** + * Get the tutorial passed in the intent, If a list of tutorial had been passed as + * a walk through the first in the list will be returned. + * */ + public static Tutorial getTutorial(Intent intent){ + + // Showing the first tutorial in the list. + if (intent.getExtras().containsKey(WALK_THROUGH_DATA)) { - tutorial.setTutorial((Tutorial) intent.getParcelableExtra(TUTORIAL_OBJ), false); + ArrayList tutorials = intent.getExtras().getParcelableArrayList(WALK_THROUGH_DATA); + + return tutorials.get(0); } - else throw new IllegalArgumentException("You must pass at least on Tutorial object to the intent builder."); + else return (Tutorial) intent.getParcelableExtra(TUTORIAL_OBJ); + } + /** + * Getting the list of tutorials that will be used for the walk through + * */ + public static ArrayList getWalkThroughData(Intent intent){ + if (intent.getExtras().containsKey(WALK_THROUGH_DATA)) + { + return intent.getExtras().getParcelableArrayList(WALK_THROUGH_DATA); + } + + return new ArrayList<>(); + } } diff --git a/tutorial_view/src/main/java/com/braunster/tutorialview/view/AbstractTutorialView.java b/tutorial_view/src/main/java/com/braunster/tutorialview/view/AbstractTutorialView.java index 3eff875..4f134e9 100644 --- a/tutorial_view/src/main/java/com/braunster/tutorialview/view/AbstractTutorialView.java +++ b/tutorial_view/src/main/java/com/braunster/tutorialview/view/AbstractTutorialView.java @@ -8,6 +8,8 @@ import android.graphics.RectF; import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; +import android.support.annotation.NonNull; +import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; import android.util.TypedValue; @@ -154,7 +156,7 @@ public AbstractTutorialView(Context context, AttributeSet attrs, int defStyleAtt } public interface TutorialClosedListener{ - public void onClosed(); + void onClosed(); } public abstract void closeTutorial(); @@ -292,8 +294,8 @@ public void setTutorial(Tutorial tutorial, boolean show){ protected void onDraw(Canvas canvas) { super.onDraw(canvas); - if (isInEditMode()) - return; + /*if (isInEditMode()) + return;*/ /* // No need to draw if does not have any view to surround, // Or the view size is null (in case we do not use a view but only its coordinates). @@ -342,10 +344,9 @@ protected void inflateTutorialInfo(){ // Inflating the "Got It" button. mGotItButton = inflate(getContext(), R.layout.got_it_button_view, null); ((TextView) mGotItButton).setTextColor(mTutorial.getTutorialTextColor()); - if (mTutorialTextTypeFace != null) - { - ((TextView) mGotItButton).setTypeface(mTutorialTextTypeFace); - } + + + setTypeFaceOnTextView(((TextView) mGotItButton)); // Adding skip button if the tutorial is a part of a Walkthrough. if (isWalkThrough()) @@ -353,10 +354,8 @@ protected void inflateTutorialInfo(){ // Inflating the "Skip" button. mSkipButton = inflate(getContext(), R.layout.skip_button_view, null); ((TextView) mSkipButton).setTextColor(mTutorial.getTutorialTextColor()); - if (mTutorialTextTypeFace != null) - { - ((TextView) mSkipButton).setTypeface(mTutorialTextTypeFace); - } + + setTypeFaceOnTextView(((TextView) mSkipButton)); } // Inflating the Title for the tutorial if has any. @@ -365,11 +364,8 @@ protected void inflateTutorialInfo(){ mTitleView = inflate(getContext(), R.layout.title_view, null); ((TextView) mTitleView).setTextColor(mTutorial.getTutorialTextColor()); ((TextView) mTitleView).setText(mTutorial.getTitle()); - - if (mTutorialTextTypeFace != null) - { - ((TextView) mTitleView).setTypeface(mTutorialTextTypeFace); - } + + setTypeFaceOnTextView(((TextView) mTitleView)); } mTutorialInfoView.post(tutorialInfoViewPost); @@ -401,10 +397,7 @@ private void checkTutorialDefault(){ txtTutorial.setTextColor(mTutorial.getTutorialTextColor()); - if (mTutorialTextTypeFace != null) - { - txtTutorial.setTypeface(mTutorialTextTypeFace); - } + setTypeFaceOnTextView((txtTutorial)); } } @@ -463,7 +456,10 @@ protected void dispatchTutorialClosed(){ * Initialize the type face object from the mTutorial object type face name. ***/ protected void initTypeFace (){ - mTutorialTextTypeFace = Typeface.createFromAsset(getResources().getAssets(), mTutorial.getTutorialTextTypeFace()); + if (!TextUtils.isEmpty(mTutorial.getTutorialTextTypeFace())){ + mTutorialTextTypeFace = + Typeface.createFromAsset(getResources().getAssets(), mTutorial.getTutorialTextTypeFace()); + } } protected void initActionBar(String title){ @@ -523,7 +519,7 @@ protected void drawInnerCircles(Canvas canvas){ /** * OnClickListener for hiding the tutorial when clicked. * */ - private OnClickListener closeTutorialClickListener = new OnClickListener() { + private final OnClickListener closeTutorialClickListener = new OnClickListener() { @Override public void onClick(View v) { closeTutorial(); @@ -533,7 +529,7 @@ public void onClick(View v) { /** * OnClickListener for skipping the walk through tutorial. * */ - private OnClickListener skipWalkThroughClickListener = new OnClickListener() { + private final OnClickListener skipWalkThroughClickListener = new OnClickListener() { @Override public void onClick(View v) { ((WalkThroughInterface) getParent()).skip(); @@ -626,7 +622,7 @@ public void setHasActionBar(boolean hasActionBar){ /** * The text that will be used for the {@link TutorialView#mTutorialInfoView mTutorialInfoView}. - * Only if the layout that is used is the default layout ({@link com.braunster.tutorialview.R.layout#tutorial_text tutorial_text}). + * Only if the layout that is used is the default layout R.layout.tutorial_text. * * @see TutorialView#setTutorialTextTypeFace(String) * @see TutorialView#setTutorialTextColor(int) @@ -782,9 +778,9 @@ && getParent() instanceof WalkThroughInterface } /** - * Posted on the tutorial info view to do ajustment and animation to the view. + * Posted on the tutorial info view to do adjustment and animation to the view. * */ - private Runnable tutorialInfoViewPost = new Runnable() { + private final Runnable tutorialInfoViewPost = new Runnable() { RelativeLayout.LayoutParams skipButtonParams = null; RelativeLayout.LayoutParams titleParams = null; @@ -913,7 +909,7 @@ private void autoInfoPosition(){ // The view to surround is in the top half of the screen so the info will be below it. if (isTopHalf) { - placeInfoAbove(); + placeInfoBelow(); } // The view to surround is in the bottom half of the screen. else { @@ -1015,4 +1011,10 @@ private void animate(){ animation.start(); } }; + + private void setTypeFaceOnTextView(@NonNull TextView textView){ + if (mTutorialTextTypeFace != null){ + textView.setTypeface(mTutorialTextTypeFace); + } + } } diff --git a/tutorial_view/src/main/java/com/braunster/tutorialview/view/RippleTutorialView.java b/tutorial_view/src/main/java/com/braunster/tutorialview/view/RippleTutorialView.java index 3ca347d..29059e0 100644 --- a/tutorial_view/src/main/java/com/braunster/tutorialview/view/RippleTutorialView.java +++ b/tutorial_view/src/main/java/com/braunster/tutorialview/view/RippleTutorialView.java @@ -15,15 +15,15 @@ */ public class RippleTutorialView extends AbstractTutorialView { - public static final String TAG = RippleTutorialView.class.getSimpleName(); - public static final boolean DEBUG = false; + private static final String TAG = RippleTutorialView.class.getSimpleName(); + private static final boolean DEBUG = false; private int mAnimatedRadius = -1; private int mAnimationRadiusMax = -1; - private static PorterDuffXfermode sXfermodeClear = new PorterDuffXfermode(PorterDuff.Mode.CLEAR); - private static PorterDuffXfermode sXfermodeNormal = new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER); + private static final PorterDuffXfermode sXfermodeClear = new PorterDuffXfermode(PorterDuff.Mode.CLEAR); + private static final PorterDuffXfermode sXfermodeNormal = new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER); public RippleTutorialView(Context context) { super(context); @@ -76,6 +76,8 @@ protected boolean shouldDraw() { return super.shouldDraw() && showing && mAnimatedRadius != -1; } + // To remove a warning regrading using maxHeight as an x parameter. + @SuppressWarnings("all") @Override public void beforeFirstDraw(){ if (DEBUG) Log.d(TAG, "FirstDraw, Width: " + getMeasuredWidth() + ", Height: " + getMeasuredHeight()); diff --git a/tutorial_view/src/main/java/com/braunster/tutorialview/view/TutorialLayout.java b/tutorial_view/src/main/java/com/braunster/tutorialview/view/TutorialLayout.java index 529b61e..c0225cf 100644 --- a/tutorial_view/src/main/java/com/braunster/tutorialview/view/TutorialLayout.java +++ b/tutorial_view/src/main/java/com/braunster/tutorialview/view/TutorialLayout.java @@ -102,7 +102,9 @@ public void setActionBar(ActionBar actionBar) { } /** - * Set the listener on the tutorial view, If walk through is used this will be overriden and you should set a {@link com.braunster.tutorialview.view.TutorialLayout.WalkThroughListener WalkThroughListener} instead. + * Set the listener on the tutorial view, + * If walk through is used this will be overridden and you should set a + * {@link com.braunster.tutorialview.view.TutorialLayout.WalkThroughListener WalkThroughListener} instead. * * @see #setWalkThroughListener(com.braunster.tutorialview.view.TutorialLayout.WalkThroughListener) * */ @@ -240,7 +242,7 @@ public void setWalkThroughListener(WalkThroughListener walkThroughListener) { @Override public void nextTutorial(Tutorial tutorial) { setTutorial(tutorial, true); - dispatchNextTutorialShown(); + dispatchNextTutorialShown(tutorial); } @Override @@ -327,9 +329,9 @@ private void dispatchWalkThroughSkipped(){ walkThroughListener.onWalkTroughSkipped(); } - private void dispatchNextTutorialShown(){ + private void dispatchNextTutorialShown(Tutorial tutorial){ if (walkThroughListener != null) - walkThroughListener.onNextTutorialShown(); + walkThroughListener.onNextTutorialShown(tutorial); } private void dispatchWalkThroughDone(){ @@ -340,7 +342,7 @@ private void dispatchWalkThroughDone(){ public interface WalkThroughListener { - public void onNextTutorialShown(); + public void onNextTutorialShown(Tutorial tutorial); public void onWalkTroughSkipped(); diff --git a/tutorial_view/src/main/res/drawable-hdpi/ic_launcher.png b/tutorial_view/src/main/res/drawable-hdpi/ic_launcher.png deleted file mode 100644 index 96a442e..0000000 Binary files a/tutorial_view/src/main/res/drawable-hdpi/ic_launcher.png and /dev/null differ diff --git a/tutorial_view/src/main/res/drawable-mdpi/ic_launcher.png b/tutorial_view/src/main/res/drawable-mdpi/ic_launcher.png deleted file mode 100644 index 359047d..0000000 Binary files a/tutorial_view/src/main/res/drawable-mdpi/ic_launcher.png and /dev/null differ diff --git a/tutorial_view/src/main/res/drawable-xhdpi/ic_launcher.png b/tutorial_view/src/main/res/drawable-xhdpi/ic_launcher.png deleted file mode 100644 index 71c6d76..0000000 Binary files a/tutorial_view/src/main/res/drawable-xhdpi/ic_launcher.png and /dev/null differ diff --git a/tutorial_view/src/main/res/drawable-xxhdpi/ic_launcher.png b/tutorial_view/src/main/res/drawable-xxhdpi/ic_launcher.png deleted file mode 100644 index 4df1894..0000000 Binary files a/tutorial_view/src/main/res/drawable-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/tutorial_view/src/main/res/values-v21/styles.xml b/tutorial_view/src/main/res/values-v21/styles.xml new file mode 100644 index 0000000..aac20df --- /dev/null +++ b/tutorial_view/src/main/res/values-v21/styles.xml @@ -0,0 +1,10 @@ + + + + diff --git a/tutorial_view/src/main/res/values/strings.xml b/tutorial_view/src/main/res/values/strings.xml index d3c349f..3b38fc7 100644 --- a/tutorial_view/src/main/res/values/strings.xml +++ b/tutorial_view/src/main/res/values/strings.xml @@ -1,5 +1,4 @@ - TutorialView Got It Skip diff --git a/tutorial_view/tutorial_view.iml b/tutorial_view/tutorial_view.iml deleted file mode 100644 index 3aaa42b..0000000 --- a/tutorial_view/tutorial_view.iml +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -