Browse Source

[Android] Implement DefaultHardwareBackBtnHandler

If the JS side chooses to not handle the back button press call
'super.onBackPressed()' to close the app.
j8
paweldomas 7 years ago
parent
commit
35dab19b30

+ 17
- 3
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java View File

@@ -26,6 +26,8 @@ import android.support.v7.app.AppCompatActivity;
26 26
 
27 27
 import java.net.URL;
28 28
 
29
+import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
30
+
29 31
 /**
30 32
  * Base Activity for applications integrating Jitsi Meet at a higher level. It
31 33
  * contains all the required wiring between the <tt>JKConferenceView</tt> and
@@ -37,10 +39,13 @@ import java.net.URL;
37 39
  * hooked to the React Native subsystem via proxy calls through the
38 40
  * <tt>JKConferenceView</tt> static methods.
39 41
  */
40
-public class JitsiMeetActivity extends AppCompatActivity {
42
+public class JitsiMeetActivity
43
+    extends AppCompatActivity
44
+    implements DefaultHardwareBackBtnHandler {
45
+
41 46
     /**
42 47
      * The request code identifying requests for the permission to draw on top
43
-     * of other apps. The value must be 16-bit and is arbitrarily chosen here. 
48
+     * of other apps. The value must be 16-bit and is arbitrarily chosen here.
44 49
      */
45 50
     private static final int OVERLAY_PERMISSION_REQUEST_CODE
46 51
         = (int) (Math.random() * Short.MAX_VALUE);
@@ -128,6 +133,15 @@ public class JitsiMeetActivity extends AppCompatActivity {
128 133
         }
129 134
     }
130 135
 
136
+    /**
137
+     * This method is called if the JS part does not handle the physical back
138
+     * button press.
139
+     */
140
+    @Override
141
+    public void invokeDefaultOnBackPressed() {
142
+        super.onBackPressed();
143
+    }
144
+
131 145
     /**
132 146
      * {@inheritDoc}
133 147
      */
@@ -201,7 +215,7 @@ public class JitsiMeetActivity extends AppCompatActivity {
201 215
     protected void onResume() {
202 216
         super.onResume();
203 217
 
204
-        JitsiMeetView.onHostResume(this);
218
+        JitsiMeetView.onHostResume(this, this);
205 219
     }
206 220
 
207 221
     /**

+ 8
- 2
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java View File

@@ -27,10 +27,12 @@ import android.support.annotation.Nullable;
27 27
 import android.widget.FrameLayout;
28 28
 
29 29
 import com.facebook.react.ReactInstanceManager;
30
+import com.facebook.react.ReactInstanceManagerBuilder;
30 31
 import com.facebook.react.ReactRootView;
31 32
 import com.facebook.react.bridge.NativeModule;
32 33
 import com.facebook.react.bridge.ReactApplicationContext;
33 34
 import com.facebook.react.common.LifecycleState;
35
+import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
34 36
 
35 37
 import java.net.URL;
36 38
 import java.util.Arrays;
@@ -184,10 +186,14 @@ public class JitsiMeetView extends FrameLayout {
184 186
      * <tt>Activity.onResume</tt> so we can do the required internal processing.
185 187
      *
186 188
      * @param activity - <tt>Activity</tt> being resumed.
189
+     * @param backHandler - a <tt>DefaultHardwareBackBtnHandler</tt> which
190
+     * will handle the back button press in case there's nothing to handle on
191
+     * the JS side.
187 192
      */
188
-    public static void onHostResume(Activity activity) {
193
+    public static void onHostResume(Activity activity,
194
+                                    DefaultHardwareBackBtnHandler backHandler) {
189 195
         if (reactInstanceManager != null) {
190
-            reactInstanceManager.onHostResume(activity, null);
196
+            reactInstanceManager.onHostResume(activity, backHandler);
191 197
         }
192 198
     }
193 199
 

Loading…
Cancel
Save