Skip to content

Commit 72d0705

Browse files
committed
- Added an option to get a result from the tutorial, The result will proved feedback of how the user handled the tutorial or walkthrough.
- Updated the README file.
1 parent 5df0cbb commit 72d0705

File tree

6 files changed

+140
-15
lines changed

6 files changed

+140
-15
lines changed

.idea/dictionaries/braunster.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55

66
![alt tag](http://raw.github.com/ItzikBraun/TutorialView/master/screen_shots/example.gif)
77

8-
An Android library project providing `Activity` with explanation about views in your app.
8+
An Android library project providing `Activity` with an explanation about views in your app.
99

10-
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.
10+
The `TutorialActivity` can be used as a walkthrough for the entire screen that is currently visible, Or just for one view on the screen.
1111

1212
To get the intent to start the `TutorialActivity` you need to use the `TutorialIntentBuilder`,
1313
The builder will help you build the intent to start the activity, You would have to pass a `Tutorial` object to the intent builder.
1414

15+
If you use any kind of analytics to track your user behavior in your app you can start the `TutorialActivity` for result and
16+
so when it returns you can collect the data whether the user skipped the tutorials or watched it fully.
17+
You can also retrieve the amount of tutorials the user have viewed before skipping the walkthrough using `TutorialActivity.VIEWED_TUTORIALS`.
18+
1519
###Usage
1620
####Tutorial
1721
The tutorial object holds the tutorial info and attributes. You can create a Tutorial by using the `TutorialBuilder`.
@@ -23,11 +27,16 @@ You can customize the following:
2327
* TypefaceName - The path to the wanted typeface to use for all text view in the tutorial, Example: "/fonts/arial.ttf".
2428
* AnimationDuration - the duration time in milliseconds that will be used for the animation.
2529
* 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`
26-
* 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`
30+
* 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`
2731
* ~~AnimationType - the animation that will be used for showing and hiding the tutorial~~ This is a work in progress currently not working.
2832

29-
Each tutorial that was passed holds it's position on screen, title, background color, the text explenation and more customizable attributes.
33+
Each tutorial that was passed holds it's position on the screen, title, background color, the text explanation and more customizable attributes.
34+
By default the "StatusBar" and the "NavigationBar" are also being colored on Lollipop devices, You can change the default behavior by using:
35+
```
36+
TutorialIntentBuilder builder = new TutorialIntentBuilder(MainActivity.this);
3037
38+
builder.changeSystemUiColor(false);
39+
```
3140
######Example of creating a simple tutorial.
3241

3342
``` java
@@ -92,12 +101,11 @@ dependencies {
92101

93102
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:
94103
```
95-
// Notice that in your settings file there would be more names so don't delete them, This are your other modules.
104+
// Notice that in your settings file there would be more names so don't delete them, Those are your other modules.
96105
include':tutorial_view'
97106
```
98107

99108
###TODO:
100-
* Return result when `TutorialActivity` finishes so you could know when it was done and if was skipped.
101109
* add the roboto font family to the app assets so it will work on lower versions
102110
* Make a sample app and publish it on Google Play
103111

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
22

33
def versionMajor = 0
44
def versionMinor = 8
5-
def versionPatch = 1
5+
def versionPatch = 2
66
def versionBuild = 0 // bump for dogfood builds, public betas, etc.
77

88
android {

app/src/main/java/com/braunster/tutorialviewapp/MainActivity.java

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package com.braunster.tutorialviewapp;
22

33
import android.app.Activity;
4+
import android.content.Intent;
45
import android.graphics.Color;
56
import android.graphics.drawable.ColorDrawable;
67
import android.os.Bundle;
78
import android.view.Menu;
89
import android.view.View;
910
import android.widget.TextView;
11+
import android.widget.Toast;
1012

13+
import com.braunster.tutorialview.TutorialActivity;
1114
import com.braunster.tutorialview.object.Tutorial;
1215
import com.braunster.tutorialview.object.TutorialBuilder;
1316
import com.braunster.tutorialview.object.TutorialIntentBuilder;
@@ -20,6 +23,11 @@ public class MainActivity extends Activity implements View.OnClickListener {
2023

2124
private TutorialView tutorialView;
2225

26+
private static final int TUTORIAL_REQUEST = 1991;
27+
28+
// For switching between startActivityForResult and startActivity
29+
private boolean startTutorialForResult = false;
30+
2331
@Override
2432
protected void onCreate(Bundle savedInstanceState) {
2533
super.onCreate(savedInstanceState);
@@ -72,6 +80,40 @@ public boolean onCreateOptionsMenu(Menu menu) {
7280
return true;
7381
}
7482

83+
@Override
84+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
85+
super.onActivityResult(requestCode, resultCode, data);
86+
87+
if (requestCode == TUTORIAL_REQUEST)
88+
{
89+
boolean isWalkThrough = data.getBooleanExtra(TutorialActivity.IS_WALKTHROUGH, false);
90+
91+
if (resultCode == RESULT_OK)
92+
{
93+
if (isWalkThrough)
94+
Toast.makeText(this, "The walkthrough was viewed fully", Toast.LENGTH_SHORT).show();
95+
else
96+
Toast.makeText(this, "The user GotIt", Toast.LENGTH_SHORT).show();
97+
}
98+
else if (resultCode == RESULT_CANCELED)
99+
{
100+
if (isWalkThrough)
101+
{
102+
Toast.makeText(this,
103+
String.format("Tutorial was skipped, User viewed %s Tutorials", data.getIntExtra(TutorialActivity.VIEWED_TUTORIALS, 0)),
104+
Toast.LENGTH_SHORT).show();
105+
}
106+
else
107+
{
108+
Toast.makeText(this,
109+
"Tutorial was skipped" ,
110+
Toast.LENGTH_SHORT).show();
111+
}
112+
113+
}
114+
}
115+
}
116+
75117
private int randomColor(){
76118
Random rnd = new Random();
77119
return Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
@@ -105,6 +147,9 @@ public void onClick(View v) {
105147

106148
TutorialIntentBuilder builder = new TutorialIntentBuilder(MainActivity.this);
107149

150+
// if true the status bar and navigation bar will be colored on Lollipop devices.
151+
builder.changeSystemUiColor(true);
152+
108153
TutorialBuilder tBuilder = getBasicBuilderForTest(v);
109154

110155
switch (v.getId())
@@ -144,7 +189,10 @@ public void onClick(View v) {
144189

145190
builder.setTutorial(tBuilder.build());
146191

147-
startActivity(builder.getIntent());
192+
if (startTutorialForResult)
193+
startActivityForResult(builder.getIntent(), TUTORIAL_REQUEST);
194+
else
195+
startActivity(builder.getIntent());
148196

149197
// Override the default animation of the entering activity.
150198
// This will allow the nice wrapping of the view by the tutorial activity.
@@ -185,8 +233,15 @@ public void run() {
185233

186234
TutorialIntentBuilder builder = new TutorialIntentBuilder(MainActivity.this);
187235

236+
// if true the status bar and navigation bar will be colored on Lollipop devices.
237+
builder.changeSystemUiColor(true);
238+
188239
builder.setWalkThroughList(t1, t2, t3, t4, t5);
189-
startActivity(builder.getIntent());
240+
241+
if (startTutorialForResult)
242+
startActivityForResult(builder.getIntent(), TUTORIAL_REQUEST);
243+
else
244+
startActivity(builder.getIntent());
190245

191246
// Override the default animation of the entering activity.
192247
// This will allow the nice wrapping of the view by the tutorial activity.

tutorial_view/src/main/java/com/braunster/tutorialview/TutorialActivity.java

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.braunster.tutorialview;
22

33
import android.app.Activity;
4+
import android.content.Intent;
45
import android.content.pm.ActivityInfo;
56
import android.content.res.Configuration;
67
import android.os.Build;
@@ -10,6 +11,7 @@
1011
import com.braunster.tutorialview.object.Debug;
1112
import com.braunster.tutorialview.object.Tutorial;
1213
import com.braunster.tutorialview.object.TutorialIntentBuilder;
14+
import com.braunster.tutorialview.view.AbstractTutorialView;
1315
import com.braunster.tutorialview.view.TutorialLayout;
1416
import com.braunster.tutorialview.view.TutorialView;
1517

@@ -33,6 +35,8 @@ public class TutorialActivity extends Activity {
3335

3436
private Bundle savedInstanceState;
3537

38+
public static final String VIEWED_TUTORIALS= "viewed_tutorials", IS_WALKTHROUGH = "is_tutorial";
39+
3640
@Override
3741
protected void onCreate(Bundle savedInstanceState) {
3842
super.onCreate(savedInstanceState);
@@ -55,10 +59,11 @@ protected void onCreate(Bundle savedInstanceState) {
5559
mTutorial = TutorialIntentBuilder.getTutorial(getIntent());
5660

5761
// Finish the activity when the tutorial is closed.
62+
// In case the tutorial view is showing a walkthrough this would be ignored.
5863
mTutorialLayout.setTutorialClosedListener(new TutorialView.TutorialClosedListener() {
5964
@Override
6065
public void onClosed() {
61-
finish();
66+
resultDone();
6267
}
6368
});
6469

@@ -130,12 +135,12 @@ public void onNextTutorialShown(Tutorial tutorial) {
130135

131136
@Override
132137
public void onWalkTroughSkipped() {
133-
finish();
138+
resultSkipped();
134139
}
135140

136141
@Override
137142
public void onWalkThroughDone() {
138-
finish();
143+
resultDone();
139144
}
140145
});
141146
}
@@ -164,11 +169,26 @@ protected void onSaveInstanceState(Bundle outState) {
164169
* */
165170
@Override
166171
public void onBackPressed() {
167-
if (TutorialIntentBuilder.skipOnBackPressed(getIntent()))
172+
// Skipping the walkthrough if requested.
173+
if (mTutorialLayout.isWalkThrough() && TutorialIntentBuilder.skipOnBackPressed(getIntent()))
168174
{
169175
mTutorialLayout.skip();
170176
}
171-
else mTutorialLayout.closeTutorial();
177+
else {
178+
// Setting a new TutorialCloseListener so we could return
179+
// a result to the calling activity that the tutorial was closed using the back press.
180+
if (!mTutorialLayout.isWalkThrough())
181+
{
182+
mTutorialLayout.setTutorialClosedListener(new AbstractTutorialView.TutorialClosedListener() {
183+
@Override
184+
public void onClosed() {
185+
resultSkipped();
186+
}
187+
});
188+
}
189+
190+
mTutorialLayout.closeTutorial();
191+
}
172192
}
173193

174194
private void updateSystemUIColors(){
@@ -228,4 +248,43 @@ private void lockOrientation(){
228248
break;
229249
}
230250
}
251+
252+
private void resultSkipped(){
253+
254+
if (getCallingActivity() != null)
255+
{
256+
Intent intent = getResultIntent();
257+
258+
// Adding the amount of tutorials that was shown before skipping.
259+
if (mTutorialLayout.isWalkThrough()){
260+
intent.putExtra(VIEWED_TUTORIALS, mCurrentTutorialPos);
261+
}
262+
263+
setResult(RESULT_CANCELED, intent);
264+
}
265+
266+
finish();
267+
}
268+
269+
private void resultDone(){
270+
271+
if (getCallingActivity() != null)
272+
{
273+
Intent intent = getResultIntent();
274+
setResult(RESULT_OK, intent);
275+
}
276+
277+
278+
finish();
279+
}
280+
281+
private Intent getResultIntent(){
282+
283+
284+
Intent intent = new Intent();
285+
286+
intent.putExtra(IS_WALKTHROUGH, mTutorialLayout.isWalkThrough());
287+
288+
return intent;
289+
}
231290
}

tutorial_view/src/main/java/com/braunster/tutorialview/view/TutorialLayout.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ public void setActionBar(ActionBar actionBar) {
102102
}
103103

104104
/**
105-
* 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.
105+
* Set the listener on the tutorial view,
106+
* If walk through is used this will be overridden and you should set a
107+
* {@link com.braunster.tutorialview.view.TutorialLayout.WalkThroughListener WalkThroughListener} instead.
106108
*
107109
* @see #setWalkThroughListener(com.braunster.tutorialview.view.TutorialLayout.WalkThroughListener)
108110
* */

0 commit comments

Comments
 (0)