Skip to content

Commit 3ff4b6e

Browse files
committed
Option to set the position of the InfoText in the Tutorial was added, Position could be auto(default behavior), above, below, right of and left of the view to surround.
Option to set the position of the "GotIt" button was added, Position could be autu(default behavior), top (below title if has any) and bottom. Some cleaning in the MainActivity.
1 parent a0d2fe2 commit 3ff4b6e

File tree

3 files changed

+69
-89
lines changed

3 files changed

+69
-89
lines changed

app/app.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
8080
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
8181
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
82+
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
8283
</content>
8384
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
8485
<orderEntry type="sourceFolder" forTests="false" />

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

Lines changed: 63 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
import android.view.Menu;
88
import android.view.View;
99

10+
import com.braunster.tutorialview.object.Tutorial;
1011
import com.braunster.tutorialview.object.TutorialBuilder;
1112
import com.braunster.tutorialview.object.TutorialIntentBuilder;
1213
import com.braunster.tutorialview.view.TutorialView;
1314

1415
import java.util.Random;
1516

1617

17-
public class MainActivity extends Activity {
18+
public class MainActivity extends Activity implements View.OnClickListener {
1819

1920
private TutorialView tutorialView;
2021

@@ -31,11 +32,11 @@ protected void onCreate(Bundle savedInstanceState) {
3132
setContentView(R.layout.activity_main);
3233
tutorialView = (TutorialView) findViewById(R.id.tutorial_view);
3334

34-
findViewById(R.id.btn_test_button).setOnClickListener(tutorialClickListener);
35-
findViewById(R.id.btn_test_button2).setOnClickListener(tutorialClickListener);
36-
findViewById(R.id.view_to_surround).setOnClickListener(tutorialClickListener);
37-
findViewById(R.id.view_to_surround2).setOnClickListener(tutorialClickListener);
38-
findViewById(R.id.linear_test).setOnClickListener(tutorialClickListener);
35+
findViewById(R.id.view_bottom_left).setOnClickListener(this);
36+
findViewById(R.id.view_top_right).setOnClickListener(this);
37+
findViewById(R.id.view_almost_top_right).setOnClickListener(this);
38+
findViewById(R.id.view_top_left).setOnClickListener(this);
39+
findViewById(R.id.view_center).setOnClickListener(this);
3940

4041
if (getActionBar() != null)
4142
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.DKGRAY));
@@ -60,61 +61,6 @@ public boolean onCreateOptionsMenu(Menu menu) {
6061
return true;
6162
}
6263

63-
@Override
64-
public void onWindowFocusChanged(boolean hasFocus) {
65-
super.onWindowFocusChanged(hasFocus);
66-
67-
if (hasFocus)
68-
{
69-
70-
}
71-
}
72-
73-
74-
private View.OnClickListener tutorialClickListener = new View.OnClickListener() {
75-
@Override
76-
public void onClick(View v) {
77-
78-
// This is used for the tutorial view that should be in your root view.
79-
// This may lead to problems when used inside LinearLayout and maybe other view.
80-
// The best thing to do is to use the TutorialActivity.
81-
82-
// Set the background color.
83-
// tutorialView.setTutorialBackgroundColor(randomColor());
84-
85-
// Setting the view that should be surrounded.
86-
// tutorialView.setViewToSurround(v, v instanceof TextView ? ((TextView) v).getText().toString() : "Fixed Title");
87-
88-
// Using the tutorial Activity for simple tutorial.
89-
int color = randomColor();
90-
91-
TutorialIntentBuilder builder = new TutorialIntentBuilder(MainActivity.this);
92-
93-
TutorialBuilder tBuilder = new TutorialBuilder();
94-
95-
tBuilder.setTitle("The Title")
96-
.setViewToSurround(v)
97-
.setInfoText("This is the explanation about the view.")
98-
.setBackgroundColor(randomColor())
99-
.setTutorialTextColor(Color.WHITE)
100-
.setTutorialTextTypeFaceName("fonts/olivier.ttf")
101-
.setTutorialTextSize(25)
102-
.setAnimationDuration(500);
103-
104-
builder.setTutorial(tBuilder.build());
105-
106-
startActivity(builder.getIntent());
107-
108-
// Using the tutorial activity as a walk through
109-
// startActivity(walkThroughIntent());
110-
111-
112-
// Override the default animation of the entering activity.
113-
// This will allow the nice wrapping of the view by the tutorial activity.
114-
overridePendingTransition(R.anim.dummy, R.anim.dummy);
115-
}
116-
};
117-
11864
private int randomColor(){
11965
Random rnd = new Random();
12066
return Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
@@ -128,36 +74,69 @@ public void onBackPressed() {
12874
super.onBackPressed();
12975
}
13076

131-
/*private Intent walkThroughIntent(){
77+
private TutorialBuilder getBasicBuilderForTest(View v){
78+
TutorialBuilder tBuilder = new TutorialBuilder();
79+
80+
tBuilder.setTitle("The Title")
81+
.setViewToSurround(v)
82+
.setInfoText("This is the explanation about the view.")
83+
.setBackgroundColor(randomColor())
84+
.setTutorialTextColor(Color.WHITE)
85+
.setTutorialTextTypeFaceName("fonts/olivier.ttf")
86+
.setTutorialTextSize(30)
87+
.setAnimationDuration(500);
88+
89+
return tBuilder;
90+
}
91+
92+
@Override
93+
public void onClick(View v) {
94+
95+
TutorialIntentBuilder builder = new TutorialIntentBuilder(MainActivity.this);
96+
97+
TutorialBuilder tBuilder = getBasicBuilderForTest(v);
98+
99+
switch (v.getId())
100+
{
101+
case R.id.view_bottom_left:
102+
103+
tBuilder.setTutorialInfoTextPosition(Tutorial.InfoPosition.ABOVE);
104+
tBuilder.setTutorialGotItPosition(Tutorial.GotItPosition.BOTTOM);
105+
106+
break;
132107

133-
TutorialIntentBuilder builder = new TutorialIntentBuilder(this);
108+
case R.id.view_top_right:
109+
110+
tBuilder.setTutorialInfoTextPosition(Tutorial.InfoPosition.LEFT_OF);
134111

135-
Tutorial tutorial = new Tutorial(findViewById(R.id.view_to_surround2), "Top Left");
136-
tutorial.setInfoText("This view is on the top left");
137-
tutorial.setBackgroundColor(Color.BLACK);
112+
break;
138113

139-
Tutorial tutorial2 = new Tutorial(findViewById(R.id.btn_test_button), "Bottom Left");
140-
tutorial2 .setInfoText("This view is on the bottom left");
141-
tutorial2.setBackgroundColor(Color.BLUE);
114+
case R.id.view_almost_top_right:
142115

143-
Tutorial tutorial3 = new Tutorial(findViewById(R.id.btn_test_button2), "Right");
144-
tutorial3.setInfoText("this view is on the right");
145-
tutorial3.setBackgroundColor(Color.RED);
116+
tBuilder.setTutorialInfoTextPosition(Tutorial.InfoPosition.RIGHT_OF);
146117

147-
Tutorial tutorial4 = new Tutorial(findViewById(R.id.linear_test));
148-
tutorial4.setInfoText("This is a centered view");
149-
tutorial4.setBackgroundColor(Color.GREEN);
118+
break;
150119

151-
ArrayList<Tutorial> tutorials = new ArrayList<>();
152-
tutorials.add(tutorial);
153-
tutorials.add(tutorial2);
154-
tutorials.add(tutorial3);
155-
tutorials.add(tutorial4);
120+
case R.id.view_top_left:
156121

157-
builder.skipTutorialOnBackPressed(true);
122+
tBuilder.setTutorialInfoTextPosition(Tutorial.InfoPosition.BELOW);
158123

159-
builder.setWalkThroughList(tutorials);
124+
break;
160125

161-
return builder.getIntent();
162-
}*/
126+
case R.id.view_center:
127+
128+
tBuilder.setTutorialInfoTextPosition(Tutorial.InfoPosition.BELOW);
129+
tBuilder.setTutorialGotItPosition(Tutorial.GotItPosition.BOTTOM);
130+
131+
break;
132+
}
133+
134+
builder.setTutorial(tBuilder.build());
135+
136+
startActivity(builder.getIntent());
137+
138+
// Override the default animation of the entering activity.
139+
// This will allow the nice wrapping of the view by the tutorial activity.
140+
overridePendingTransition(R.anim.dummy, R.anim.dummy);
141+
}
163142
}

app/src/main/res/layout/activity_main.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
android:textSize="30sp"
1717

1818
android:background="@drawable/circle_button"
19-
android:id="@+id/view_to_surround"
19+
android:id="@+id/view_almost_top_right"
2020
android:gravity="center"
2121
android:layout_marginLeft="100dp"
2222
android:textColor="@android:color/white"
@@ -29,7 +29,7 @@
2929
android:orientation="vertical"
3030
android:gravity="center"
3131
android:layout_centerInParent="true"
32-
android:id="@+id/linear_test">
32+
android:id="@+id/view_center">
3333

3434
<TextView
3535
android:layout_width="wrap_content"
@@ -59,7 +59,7 @@
5959
android:layout_margin="5dp"
6060
android:background="@android:color/holo_purple"
6161
android:padding="5dp"
62-
android:id="@+id/view_to_surround2"
62+
android:id="@+id/view_top_left"
6363
android:gravity="center"
6464
android:layout_alignParentLeft="true"
6565
android:layout_alignParentTop="true"
@@ -73,7 +73,7 @@
7373
android:layout_alignParentBottom="true"
7474
android:layout_marginLeft="20dp"
7575
android:layout_margin="5dp"
76-
android:id="@+id/btn_test_button"/>
76+
android:id="@+id/view_bottom_left"/>
7777

7878
<Button
7979
android:layout_width="wrap_content"
@@ -82,6 +82,6 @@
8282
android:background="@android:color/holo_blue_dark"
8383
android:layout_alignParentRight="true"
8484
android:layout_marginTop="50dp"
85-
android:id="@+id/btn_test_button2"/>
85+
android:id="@+id/view_top_right"/>
8686

8787
</RelativeLayout>

0 commit comments

Comments
 (0)