浏览代码

android: add JitsiMeetActivity.launch helper methods

They greatly simplify starting a JitsiMeetActivity by encapsulating the creation
of the Intent adn extras placement.

In order to make this possible JitsiMeetConferenceOptions now implements
Parcelable so it can be serialized and passed around when creating an Intent.
master
Saúl Ibarra Corretgé 6 年前
父节点
当前提交
61ed459971

+ 29
- 11
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java 查看文件

@@ -16,6 +16,7 @@
16 16
 
17 17
 package org.jitsi.meet.sdk;
18 18
 
19
+import android.content.Context;
19 20
 import android.content.Intent;
20 21
 import android.net.Uri;
21 22
 import android.os.Bundle;
@@ -37,6 +38,25 @@ public class JitsiMeetActivity extends FragmentActivity
37 38
 
38 39
     protected static final String TAG = JitsiMeetActivity.class.getSimpleName();
39 40
 
41
+    public static final String ACTION_JITSI_MEET_CONFERENCE = "org.jitsi.meet.CONFERENCE";
42
+    public static final String JITSI_MEET_CONFERENCE_OPTIONS = "JitsiMeetConferenceOptions";
43
+
44
+    // Helpers for starting the activity
45
+    //
46
+
47
+    public static void launch(Context context, JitsiMeetConferenceOptions options) {
48
+        Intent intent = new Intent(context, JitsiMeetActivity.class);
49
+        intent.setAction(ACTION_JITSI_MEET_CONFERENCE);
50
+        intent.putExtra(JITSI_MEET_CONFERENCE_OPTIONS, options);
51
+        context.startActivity(intent);
52
+    }
53
+
54
+    public static void launch(Context context, String url) {
55
+        JitsiMeetConferenceOptions options
56
+            = new JitsiMeetConferenceOptions.Builder().setRoom(url).build();
57
+        launch(context, options);
58
+    }
59
+
40 60
     // Overrides
41 61
     //
42 62
 
@@ -80,19 +100,17 @@ public class JitsiMeetActivity extends FragmentActivity
80 100
     }
81 101
 
82 102
     private @Nullable JitsiMeetConferenceOptions getConferenceOptions(Intent intent) {
83
-        Uri uri;
84
-
85
-        if (Intent.ACTION_VIEW.equals(intent.getAction())
86
-                && (uri = intent.getData()) != null) {
87
-            JitsiMeetConferenceOptions options
88
-                = new JitsiMeetConferenceOptions.Builder()
89
-                    .setRoom(uri.toString())
90
-                    .build();
91
-            return options;
103
+        String action = intent.getAction();
104
+
105
+        if (Intent.ACTION_VIEW.equals(action)) {
106
+            Uri uri = intent.getData();
107
+            if (uri != null) {
108
+                return new JitsiMeetConferenceOptions.Builder().setRoom(uri.toString()).build();
109
+            }
110
+        } else if (ACTION_JITSI_MEET_CONFERENCE.equals(action)) {
111
+            return intent.getParcelableExtra(JITSI_MEET_CONFERENCE_OPTIONS);
92 112
         }
93 113
 
94
-        // TODO: accept JitsiMeetConferenceOptions directly.
95
-
96 114
         return null;
97 115
     }
98 116
 

+ 48
- 1
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetConferenceOptions.java 查看文件

@@ -17,6 +17,8 @@
17 17
 package org.jitsi.meet.sdk;
18 18
 
19 19
 import android.os.Bundle;
20
+import android.os.Parcel;
21
+import android.os.Parcelable;
20 22
 
21 23
 import java.net.URL;
22 24
 
@@ -29,7 +31,7 @@ import java.net.URL;
29 31
  * The resulting {@link JitsiMeetConferenceOptions} object is immutable and represents how the
30 32
  * conference will be joined.
31 33
  */
32
-public class JitsiMeetConferenceOptions {
34
+public class JitsiMeetConferenceOptions implements Parcelable {
33 35
     /**
34 36
      * Server where the conference should take place.
35 37
      */
@@ -197,6 +199,20 @@ public class JitsiMeetConferenceOptions {
197 199
     private JitsiMeetConferenceOptions() {
198 200
     }
199 201
 
202
+    private JitsiMeetConferenceOptions(Parcel in) {
203
+        room = in.readString();
204
+        token = in.readString();
205
+        colorScheme = in.readBundle();
206
+        byte tmpAudioMuted = in.readByte();
207
+        audioMuted = tmpAudioMuted == 0 ? null : tmpAudioMuted == 1;
208
+        byte tmpAudioOnly = in.readByte();
209
+        audioOnly = tmpAudioOnly == 0 ? null : tmpAudioOnly == 1;
210
+        byte tmpVideoMuted = in.readByte();
211
+        videoMuted = tmpVideoMuted == 0 ? null : tmpVideoMuted == 1;
212
+        byte tmpWelcomePageEnabled = in.readByte();
213
+        welcomePageEnabled = tmpWelcomePageEnabled == 0 ? null : tmpWelcomePageEnabled == 1;
214
+    }
215
+
200 216
     Bundle asProps() {
201 217
         Bundle props = new Bundle();
202 218
 
@@ -246,4 +262,35 @@ public class JitsiMeetConferenceOptions {
246 262
 
247 263
         return props;
248 264
     }
265
+
266
+    // Parcelable interface
267
+    //
268
+
269
+    public static final Creator<JitsiMeetConferenceOptions> CREATOR = new Creator<JitsiMeetConferenceOptions>() {
270
+        @Override
271
+        public JitsiMeetConferenceOptions createFromParcel(Parcel in) {
272
+            return new JitsiMeetConferenceOptions(in);
273
+        }
274
+
275
+        @Override
276
+        public JitsiMeetConferenceOptions[] newArray(int size) {
277
+            return new JitsiMeetConferenceOptions[size];
278
+        }
279
+    };
280
+
281
+    @Override
282
+    public void writeToParcel(Parcel dest, int flags) {
283
+        dest.writeString(room);
284
+        dest.writeString(token);
285
+        dest.writeBundle(colorScheme);
286
+        dest.writeByte((byte) (audioMuted == null ? 0 : audioMuted ? 1 : 2));
287
+        dest.writeByte((byte) (audioOnly == null ? 0 : audioOnly ? 1 : 2));
288
+        dest.writeByte((byte) (videoMuted == null ? 0 : videoMuted ? 1 : 2));
289
+        dest.writeByte((byte) (welcomePageEnabled == null ? 0 : welcomePageEnabled ? 1 : 2));
290
+    }
291
+
292
+    @Override
293
+    public int describeContents() {
294
+        return 0;
295
+    }
249 296
 }

正在加载...
取消
保存