7
7
import android .view .Menu ;
8
8
import android .view .View ;
9
9
10
+ import com .braunster .tutorialview .object .Tutorial ;
10
11
import com .braunster .tutorialview .object .TutorialBuilder ;
11
12
import com .braunster .tutorialview .object .TutorialIntentBuilder ;
12
13
import com .braunster .tutorialview .view .TutorialView ;
13
14
14
15
import java .util .Random ;
15
16
16
17
17
- public class MainActivity extends Activity {
18
+ public class MainActivity extends Activity implements View . OnClickListener {
18
19
19
20
private TutorialView tutorialView ;
20
21
@@ -31,11 +32,11 @@ protected void onCreate(Bundle savedInstanceState) {
31
32
setContentView (R .layout .activity_main );
32
33
tutorialView = (TutorialView ) findViewById (R .id .tutorial_view );
33
34
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 );
39
40
40
41
if (getActionBar () != null )
41
42
getActionBar ().setBackgroundDrawable (new ColorDrawable (Color .DKGRAY ));
@@ -60,61 +61,6 @@ public boolean onCreateOptionsMenu(Menu menu) {
60
61
return true ;
61
62
}
62
63
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
-
118
64
private int randomColor (){
119
65
Random rnd = new Random ();
120
66
return Color .argb (255 , rnd .nextInt (256 ), rnd .nextInt (256 ), rnd .nextInt (256 ));
@@ -128,36 +74,69 @@ public void onBackPressed() {
128
74
super .onBackPressed ();
129
75
}
130
76
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 ;
132
107
133
- TutorialIntentBuilder builder = new TutorialIntentBuilder(this);
108
+ case R .id .view_top_right :
109
+
110
+ tBuilder .setTutorialInfoTextPosition (Tutorial .InfoPosition .LEFT_OF );
134
111
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 ;
138
113
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 :
142
115
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 );
146
117
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 ;
150
119
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 :
156
121
157
- builder.skipTutorialOnBackPressed(true );
122
+ tBuilder . setTutorialInfoTextPosition ( Tutorial . InfoPosition . BELOW );
158
123
159
- builder.setWalkThroughList(tutorials) ;
124
+ break ;
160
125
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
+ }
163
142
}
0 commit comments