1
1
package com .profete162 .WebcamWallonnes ;
2
2
3
+ import android .Manifest ;
3
4
import android .content .Context ;
4
5
import android .content .Intent ;
5
6
import android .content .SharedPreferences ;
14
15
import android .net .Uri ;
15
16
import android .os .Bundle ;
16
17
import android .preference .PreferenceManager ;
17
- import android .support .v4 .app .ActionBarDrawerToggle ;
18
- import android .support .v4 .app .Fragment ;
19
- import android .support .v4 .app .FragmentActivity ;
20
- import android .support .v4 .app .FragmentManager ;
21
- import android .support .v4 .app .FragmentTransaction ;
22
- import android .support .v4 .widget .DrawerLayout ;
18
+
19
+ import androidx .core .app .ActivityCompat ;
20
+ import androidx .legacy .app .ActionBarDrawerToggle ;
21
+ import androidx .fragment .app .Fragment ;
22
+ import androidx .fragment .app .FragmentActivity ;
23
+ import androidx .fragment .app .FragmentManager ;
24
+ import androidx .fragment .app .FragmentTransaction ;
25
+ import androidx .drawerlayout .widget .DrawerLayout ;
26
+
23
27
import android .text .format .DateUtils ;
24
28
import android .util .Log ;
25
29
import android .view .Menu ;
30
34
import android .widget .FrameLayout ;
31
35
import android .widget .ListView ;
32
36
33
- import com .google .android .gms .gcm .GoogleCloudMessaging ;
37
+ import com .google .android .material .snackbar .Snackbar ;
38
+ import com .google .firebase .messaging .FirebaseMessaging ;
34
39
import com .profete162 .WebcamWallonnes .Adapter .MenuAdapter ;
35
40
import com .profete162 .WebcamWallonnes .Utils .GPS ;
36
41
import com .profete162 .WebcamWallonnes .Utils .NumberedFragment ;
41
46
public class DrawerActivity extends FragmentActivity {
42
47
43
48
public static final String TAG = "WazaBe" ;
44
- int count = 0 ;
49
+ int count = 0 ;
45
50
public static final String EXTRA_MESSAGE = "message" ;
46
51
public static final String PROPERTY_REG_ID = "registration_id" ;
47
52
public static final String PROPERTY_APP_VERSION = "appVersion" ;
@@ -62,7 +67,7 @@ public class DrawerActivity extends FragmentActivity {
62
67
* Substitute you own sender ID here.
63
68
*/
64
69
String SENDER_ID = "570622304067" ;
65
- GoogleCloudMessaging gcm ;
70
+ FirebaseMessaging fcm ;
66
71
AtomicInteger msgId = new AtomicInteger ();
67
72
SharedPreferences prefs ;
68
73
String regid ;
@@ -106,10 +111,10 @@ public void onDrawerClosed(View view) {
106
111
/** Called when a drawer has settled in a completely open state. */
107
112
public void onDrawerOpened (View drawerView ) {
108
113
count ++;
109
- if (count > 5 ) {
114
+ if (count > 5 ) {
110
115
Intent browserIntent = new Intent (Intent .ACTION_VIEW , Uri .parse ("http://www.youtube.com/watch?v=dQw4w9WgXcQ" ));
111
116
startActivity (browserIntent );
112
- count = 0 ;
117
+ count = 0 ;
113
118
}
114
119
getActionBar ().setTitle (getString (R .string .app_name ));
115
120
getActionBar ().setIcon (R .drawable .ic_launcher );
@@ -147,7 +152,7 @@ public void onClick(View view) {
147
152
148
153
}
149
154
});
150
- // mDrawerList.addFooterView(b);
155
+ // mDrawerList.addFooterView(b);
151
156
mDrawerList .setAdapter (new MenuAdapter (this ,
152
157
R .layout .row_menu , mMenuTitles ));
153
158
@@ -204,9 +209,43 @@ public void onProviderDisabled(String provider) {
204
209
}
205
210
};
206
211
207
- // Register the listener with the Location Manager to receive location updates
212
+ // Register the listener with the Location Manager to receive location updates
208
213
209
214
try {
215
+ if (ActivityCompat .checkSelfPermission (this , android .Manifest .permission .ACCESS_FINE_LOCATION ) != PackageManager .PERMISSION_GRANTED && ActivityCompat .checkSelfPermission (this , android .Manifest .permission .ACCESS_COARSE_LOCATION ) != PackageManager .PERMISSION_GRANTED ) {
216
+ // TODO: Consider calling
217
+ // ActivityCompat#requestPermissions
218
+ // here to request the missing permissions, and then overriding
219
+ // public void onRequestPermissionsResult(int requestCode, String[] permissions,
220
+ // int[] grantResults)
221
+ // to handle the case where the user grants the permission. See the documentation
222
+ // for ActivityCompat#requestPermissions for more details.
223
+ if (ActivityCompat .shouldShowRequestPermissionRationale (this ,
224
+ Manifest .permission .READ_CONTACTS )
225
+ || ActivityCompat .shouldShowRequestPermissionRationale (this ,
226
+ Manifest .permission .WRITE_CONTACTS )) {
227
+
228
+ // Provide an additional rationale to the user if the permission was not granted
229
+ // and the user would benefit from additional context for the use of the permission.
230
+ // For example, if the request has been denied previously.
231
+ Log .i (TAG ,
232
+ "Displaying contacts permission rationale to provide additional context." );
233
+
234
+ // Display a SnackBar with an explanation and a button to trigger the request.
235
+ Snackbar .make (mDrawerLayout , R .string .permission_location_rationale ,
236
+ Snackbar .LENGTH_INDEFINITE )
237
+ .setAction (R .string .ok , new View .OnClickListener () {
238
+ @ Override
239
+ public void onClick (View view ) {
240
+ ActivityCompat .requestPermissions (DrawerActivity .this , new String []{Manifest .permission .ACCESS_FINE_LOCATION , Manifest .permission .ACCESS_COARSE_LOCATION }, 0 );
241
+ }
242
+ })
243
+ .show ();
244
+ } else {
245
+ ActivityCompat .requestPermissions (this , new String []{Manifest .permission .ACCESS_FINE_LOCATION , Manifest .permission .ACCESS_COARSE_LOCATION }, 0 );
246
+ }
247
+ return ;
248
+ }
210
249
locationManager .requestLocationUpdates (LocationManager .GPS_PROVIDER , 0 , 0 , locationListener );
211
250
} catch (Exception e ) {
212
251
e .printStackTrace ();
@@ -239,8 +278,9 @@ public void onBackStackChanged() {
239
278
if (f instanceof MyMapFragment ) {
240
279
DrawerActivity .this .mapFragment = (MyMapFragment ) f ;
241
280
show = true ;
242
- } else
281
+ } else {
243
282
show = false ;
283
+ }
244
284
245
285
Log .e ("" , "STACK: " + mapFragment );
246
286
0 commit comments