Browse Source

NavigationActivity implements PermissionAwareActivity (#470)

* NavigationActivity implements PermissionAwareActivity

* NavigationActivity implements PermissionAwareActivity

* Fixed code styling

* Removed Hungarian notation.

* Removed empty line
Chaitanya Bhagvan 8 years ago
parent
commit
490e66e458

+ 19
- 1
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java View File

1
 package com.reactnativenavigation.controllers;
1
 package com.reactnativenavigation.controllers;
2
 
2
 
3
+import android.annotation.TargetApi;
3
 import android.content.Intent;
4
 import android.content.Intent;
5
+import android.os.Build;
4
 import android.os.Bundle;
6
 import android.os.Bundle;
7
+import android.support.annotation.Nullable;
5
 import android.support.v7.app.AppCompatActivity;
8
 import android.support.v7.app.AppCompatActivity;
6
 import android.view.KeyEvent;
9
 import android.view.KeyEvent;
7
 
10
 
8
 import com.facebook.react.bridge.Callback;
11
 import com.facebook.react.bridge.Callback;
9
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
12
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
13
+import com.facebook.react.modules.core.PermissionAwareActivity;
14
+import com.facebook.react.modules.core.PermissionListener;
10
 import com.reactnativenavigation.NavigationApplication;
15
 import com.reactnativenavigation.NavigationApplication;
11
 import com.reactnativenavigation.events.Event;
16
 import com.reactnativenavigation.events.Event;
12
 import com.reactnativenavigation.events.EventBus;
17
 import com.reactnativenavigation.events.EventBus;
27
 
32
 
28
 import java.util.List;
33
 import java.util.List;
29
 
34
 
30
-public class NavigationActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler, Subscriber {
35
+public class NavigationActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler, Subscriber, PermissionAwareActivity {
31
 
36
 
32
     /**
37
     /**
33
      * Although we start multiple activities, we make sure to pass Intent.CLEAR_TASK | Intent.NEW_TASK
38
      * Although we start multiple activities, we make sure to pass Intent.CLEAR_TASK | Intent.NEW_TASK
42
     private ActivityParams activityParams;
47
     private ActivityParams activityParams;
43
     private ModalController modalController;
48
     private ModalController modalController;
44
     private Layout layout;
49
     private Layout layout;
50
+    @Nullable private PermissionListener mPermissionListener;
45
 
51
 
46
     @Override
52
     @Override
47
     protected void onCreate(Bundle savedInstanceState) {
53
     protected void onCreate(Bundle savedInstanceState) {
312
         modalController.destroy();
318
         modalController.destroy();
313
         layout.destroy();
319
         layout.destroy();
314
     }
320
     }
321
+
322
+    @TargetApi(Build.VERSION_CODES.M)
323
+    public void requestPermissions(String[] permissions, int requestCode, PermissionListener listener) {
324
+        mPermissionListener = listener;
325
+        requestPermissions(permissions, requestCode);
326
+    }
327
+
328
+    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
329
+        if (mPermissionListener != null && mPermissionListener.onRequestPermissionsResult(requestCode, permissions, grantResults)) {
330
+            mPermissionListener = null;
331
+        }
332
+    }
315
 }
333
 }