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 8 years ago
parent
commit
35dab19b30

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

26
 
26
 
27
 import java.net.URL;
27
 import java.net.URL;
28
 
28
 
29
+import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
30
+
29
 /**
31
 /**
30
  * Base Activity for applications integrating Jitsi Meet at a higher level. It
32
  * Base Activity for applications integrating Jitsi Meet at a higher level. It
31
  * contains all the required wiring between the <tt>JKConferenceView</tt> and
33
  * contains all the required wiring between the <tt>JKConferenceView</tt> and
37
  * hooked to the React Native subsystem via proxy calls through the
39
  * hooked to the React Native subsystem via proxy calls through the
38
  * <tt>JKConferenceView</tt> static methods.
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
      * The request code identifying requests for the permission to draw on top
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
     private static final int OVERLAY_PERMISSION_REQUEST_CODE
50
     private static final int OVERLAY_PERMISSION_REQUEST_CODE
46
         = (int) (Math.random() * Short.MAX_VALUE);
51
         = (int) (Math.random() * Short.MAX_VALUE);
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
      * {@inheritDoc}
146
      * {@inheritDoc}
133
      */
147
      */
201
     protected void onResume() {
215
     protected void onResume() {
202
         super.onResume();
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
 import android.widget.FrameLayout;
27
 import android.widget.FrameLayout;
28
 
28
 
29
 import com.facebook.react.ReactInstanceManager;
29
 import com.facebook.react.ReactInstanceManager;
30
+import com.facebook.react.ReactInstanceManagerBuilder;
30
 import com.facebook.react.ReactRootView;
31
 import com.facebook.react.ReactRootView;
31
 import com.facebook.react.bridge.NativeModule;
32
 import com.facebook.react.bridge.NativeModule;
32
 import com.facebook.react.bridge.ReactApplicationContext;
33
 import com.facebook.react.bridge.ReactApplicationContext;
33
 import com.facebook.react.common.LifecycleState;
34
 import com.facebook.react.common.LifecycleState;
35
+import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
34
 
36
 
35
 import java.net.URL;
37
 import java.net.URL;
36
 import java.util.Arrays;
38
 import java.util.Arrays;
184
      * <tt>Activity.onResume</tt> so we can do the required internal processing.
186
      * <tt>Activity.onResume</tt> so we can do the required internal processing.
185
      *
187
      *
186
      * @param activity - <tt>Activity</tt> being resumed.
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
         if (reactInstanceManager != null) {
195
         if (reactInstanceManager != null) {
190
-            reactInstanceManager.onHostResume(activity, null);
196
+            reactInstanceManager.onHostResume(activity, backHandler);
191
         }
197
         }
192
     }
198
     }
193
 
199
 

Loading…
Cancel
Save