4
4
import android .content .Context ;
5
5
import android .content .Intent ;
6
6
import android .content .IntentFilter ;
7
+ import android .content .SharedPreferences ;
7
8
import android .content .pm .PackageManager ;
9
+ import android .graphics .Typeface ;
8
10
import android .net .Uri ;
9
11
import android .os .Build ;
10
12
import android .os .Bundle ;
13
+ import android .os .Handler ;
11
14
import android .support .annotation .NonNull ;
12
15
import android .support .design .widget .BottomSheetBehavior ;
13
16
import android .support .v4 .app .FragmentTransaction ;
14
17
import android .support .v7 .app .AlertDialog ;
18
+
15
19
import android .view .Menu ;
16
20
import android .view .MenuInflater ;
17
21
import android .view .MenuItem ;
25
29
import java .util .List ;
26
30
27
31
import javax .inject .Inject ;
32
+ import javax .inject .Named ;
28
33
29
34
import butterknife .BindView ;
30
35
import butterknife .ButterKnife ;
41
46
import io .reactivex .disposables .Disposable ;
42
47
import io .reactivex .schedulers .Schedulers ;
43
48
import timber .log .Timber ;
49
+ import uk .co .deanwild .materialshowcaseview .IShowcaseListener ;
50
+ import uk .co .deanwild .materialshowcaseview .MaterialShowcaseView ;
44
51
45
52
46
53
public class NearbyActivity extends NavigationBaseActivity implements LocationUpdateListener {
@@ -56,12 +63,15 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
56
63
LinearLayout bottomSheetDetails ;
57
64
@ BindView (R .id .transparentView )
58
65
View transparentView ;
66
+ @ BindView (R .id .fab_recenter )
67
+ View fabRecenter ;
59
68
60
69
@ Inject
61
70
LocationServiceManager locationManager ;
62
71
@ Inject
63
72
NearbyController nearbyController ;
64
-
73
+ @ Inject
74
+ @ Named ("application_preferences" ) SharedPreferences applicationPrefs ;
65
75
private LatLng curLatLng ;
66
76
private Bundle bundle ;
67
77
private Disposable placesDisposable ;
@@ -72,11 +82,18 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
72
82
private NearbyListFragment nearbyListFragment ;
73
83
private static final String TAG_RETAINED_MAP_FRAGMENT = NearbyMapFragment .class .getSimpleName ();
74
84
private static final String TAG_RETAINED_LIST_FRAGMENT = NearbyListFragment .class .getSimpleName ();
85
+ private View listButton ; // Reference to list button to use in tutorial
75
86
76
87
private final String NETWORK_INTENT_ACTION = "android.net.conn.CONNECTIVITY_CHANGE" ;
77
88
private BroadcastReceiver broadcastReceiver ;
89
+
90
+ private boolean isListShowcaseAdded = false ;
91
+ private boolean isMapShowCaseAdded = false ;
92
+
78
93
private LatLng lastKnownLocation ;
79
94
95
+ private MaterialShowcaseView secondSingleShowCaseView ;
96
+
80
97
@ Override
81
98
protected void onCreate (Bundle savedInstanceState ) {
82
99
super .onCreate (savedInstanceState );
@@ -126,6 +143,39 @@ public boolean onCreateOptionsMenu(Menu menu) {
126
143
MenuInflater inflater = getMenuInflater ();
127
144
inflater .inflate (R .menu .menu_nearby , menu );
128
145
146
+ new Handler ().post (() -> {
147
+
148
+ listButton = findViewById (R .id .action_display_list );
149
+
150
+ secondSingleShowCaseView = new MaterialShowcaseView .Builder (this )
151
+ .setTarget (listButton )
152
+ .setDismissText (getString (R .string .showcase_view_got_it_button ))
153
+ .setContentText (getString (R .string .showcase_view_list_icon ))
154
+ .setDelay (500 ) // optional but starting animations immediately in onCreate can make them choppy
155
+ .singleUse (ViewUtil .SHOWCASE_VIEW_ID_1 ) // provide a unique ID used to ensure it is only shown once
156
+ .setDismissStyle (Typeface .defaultFromStyle (Typeface .BOLD ))
157
+ .setListener (new IShowcaseListener () {
158
+ @ Override
159
+ public void onShowcaseDisplayed (MaterialShowcaseView materialShowcaseView ) {
160
+
161
+ }
162
+
163
+ // If dismissed, we can inform fragment to start showcase sequence there
164
+ @ Override
165
+ public void onShowcaseDismissed (MaterialShowcaseView materialShowcaseView ) {
166
+ nearbyMapFragment .onNearbyMaterialShowcaseDismissed ();
167
+ }
168
+ })
169
+ .build ();
170
+
171
+ isListShowcaseAdded = true ;
172
+
173
+ if (isMapShowCaseAdded ) { // If map showcase is also ready, start ShowcaseSequence
174
+ // Probably this case is not possible. Just added to be careful
175
+ setMapViewTutorialShowCase ();
176
+ }
177
+ });
178
+
129
179
return super .onCreateOptionsMenu (menu );
130
180
}
131
181
@@ -420,6 +470,45 @@ private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo)
420
470
updateMapFragment (false );
421
471
updateListFragment ();
422
472
}
473
+
474
+ isMapShowCaseAdded = true ;
475
+ }
476
+
477
+ public void setMapViewTutorialShowCase () {
478
+ /*
479
+ *This showcase view will be the first step of our nearbyMaterialShowcaseSequence. The reason we use a
480
+ * single item instead of adding another step to nearbyMaterialShowcaseSequence is that we are not able to
481
+ * call withoutShape() method on steps. For mapView we need an showcase view without
482
+ * any circle on it, it should cover the whole page.
483
+ * */
484
+ MaterialShowcaseView firstSingleShowCaseView = new MaterialShowcaseView .Builder (this )
485
+ .setTarget (nearbyMapFragment .mapView )
486
+ .setDismissText (getString (R .string .showcase_view_got_it_button ))
487
+ .setContentText (getString (R .string .showcase_view_whole_nearby_activity ))
488
+ .setDelay (500 ) // optional but starting animations immediately in onCreate can make them choppy
489
+ .singleUse (ViewUtil .SHOWCASE_VIEW_ID_2 ) // provide a unique ID used to ensure it is only shown once
490
+ .withoutShape () // no shape on map view since there are no view to focus on
491
+ .setDismissStyle (Typeface .defaultFromStyle (Typeface .BOLD ))
492
+ .setListener (new IShowcaseListener () {
493
+ @ Override
494
+ public void onShowcaseDisplayed (MaterialShowcaseView materialShowcaseView ) {
495
+
496
+ }
497
+
498
+ @ Override
499
+ public void onShowcaseDismissed (MaterialShowcaseView materialShowcaseView ) {
500
+ /* Add other nearbyMaterialShowcaseSequence here, it will make the user feel as they are a
501
+ * nearbyMaterialShowcaseSequence whole together.
502
+ * */
503
+ secondSingleShowCaseView .show (NearbyActivity .this );
504
+ }
505
+ })
506
+ .build ();
507
+
508
+ if (applicationPrefs .getBoolean ("firstRunNearby" , true )) {
509
+ applicationPrefs .edit ().putBoolean ("firstRunNearby" , false ).apply ();
510
+ firstSingleShowCaseView .show (this );
511
+ }
423
512
}
424
513
425
514
private void lockNearbyView (boolean lock ) {
0 commit comments