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.
This commit is contained in:
parent
c30a4a0aa6
commit
61ed459971
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.jitsi.meet.sdk;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
@ -37,6 +38,25 @@ public class JitsiMeetActivity extends FragmentActivity
|
|||
|
||||
protected static final String TAG = JitsiMeetActivity.class.getSimpleName();
|
||||
|
||||
public static final String ACTION_JITSI_MEET_CONFERENCE = "org.jitsi.meet.CONFERENCE";
|
||||
public static final String JITSI_MEET_CONFERENCE_OPTIONS = "JitsiMeetConferenceOptions";
|
||||
|
||||
// Helpers for starting the activity
|
||||
//
|
||||
|
||||
public static void launch(Context context, JitsiMeetConferenceOptions options) {
|
||||
Intent intent = new Intent(context, JitsiMeetActivity.class);
|
||||
intent.setAction(ACTION_JITSI_MEET_CONFERENCE);
|
||||
intent.putExtra(JITSI_MEET_CONFERENCE_OPTIONS, options);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static void launch(Context context, String url) {
|
||||
JitsiMeetConferenceOptions options
|
||||
= new JitsiMeetConferenceOptions.Builder().setRoom(url).build();
|
||||
launch(context, options);
|
||||
}
|
||||
|
||||
// Overrides
|
||||
//
|
||||
|
||||
|
@ -80,19 +100,17 @@ public class JitsiMeetActivity extends FragmentActivity
|
|||
}
|
||||
|
||||
private @Nullable JitsiMeetConferenceOptions getConferenceOptions(Intent intent) {
|
||||
Uri uri;
|
||||
String action = intent.getAction();
|
||||
|
||||
if (Intent.ACTION_VIEW.equals(intent.getAction())
|
||||
&& (uri = intent.getData()) != null) {
|
||||
JitsiMeetConferenceOptions options
|
||||
= new JitsiMeetConferenceOptions.Builder()
|
||||
.setRoom(uri.toString())
|
||||
.build();
|
||||
return options;
|
||||
if (Intent.ACTION_VIEW.equals(action)) {
|
||||
Uri uri = intent.getData();
|
||||
if (uri != null) {
|
||||
return new JitsiMeetConferenceOptions.Builder().setRoom(uri.toString()).build();
|
||||
}
|
||||
} else if (ACTION_JITSI_MEET_CONFERENCE.equals(action)) {
|
||||
return intent.getParcelableExtra(JITSI_MEET_CONFERENCE_OPTIONS);
|
||||
}
|
||||
|
||||
// TODO: accept JitsiMeetConferenceOptions directly.
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
package org.jitsi.meet.sdk;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
|
@ -29,7 +31,7 @@ import java.net.URL;
|
|||
* The resulting {@link JitsiMeetConferenceOptions} object is immutable and represents how the
|
||||
* conference will be joined.
|
||||
*/
|
||||
public class JitsiMeetConferenceOptions {
|
||||
public class JitsiMeetConferenceOptions implements Parcelable {
|
||||
/**
|
||||
* Server where the conference should take place.
|
||||
*/
|
||||
|
@ -197,6 +199,20 @@ public class JitsiMeetConferenceOptions {
|
|||
private JitsiMeetConferenceOptions() {
|
||||
}
|
||||
|
||||
private JitsiMeetConferenceOptions(Parcel in) {
|
||||
room = in.readString();
|
||||
token = in.readString();
|
||||
colorScheme = in.readBundle();
|
||||
byte tmpAudioMuted = in.readByte();
|
||||
audioMuted = tmpAudioMuted == 0 ? null : tmpAudioMuted == 1;
|
||||
byte tmpAudioOnly = in.readByte();
|
||||
audioOnly = tmpAudioOnly == 0 ? null : tmpAudioOnly == 1;
|
||||
byte tmpVideoMuted = in.readByte();
|
||||
videoMuted = tmpVideoMuted == 0 ? null : tmpVideoMuted == 1;
|
||||
byte tmpWelcomePageEnabled = in.readByte();
|
||||
welcomePageEnabled = tmpWelcomePageEnabled == 0 ? null : tmpWelcomePageEnabled == 1;
|
||||
}
|
||||
|
||||
Bundle asProps() {
|
||||
Bundle props = new Bundle();
|
||||
|
||||
|
@ -246,4 +262,35 @@ public class JitsiMeetConferenceOptions {
|
|||
|
||||
return props;
|
||||
}
|
||||
|
||||
// Parcelable interface
|
||||
//
|
||||
|
||||
public static final Creator<JitsiMeetConferenceOptions> CREATOR = new Creator<JitsiMeetConferenceOptions>() {
|
||||
@Override
|
||||
public JitsiMeetConferenceOptions createFromParcel(Parcel in) {
|
||||
return new JitsiMeetConferenceOptions(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JitsiMeetConferenceOptions[] newArray(int size) {
|
||||
return new JitsiMeetConferenceOptions[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(room);
|
||||
dest.writeString(token);
|
||||
dest.writeBundle(colorScheme);
|
||||
dest.writeByte((byte) (audioMuted == null ? 0 : audioMuted ? 1 : 2));
|
||||
dest.writeByte((byte) (audioOnly == null ? 0 : audioOnly ? 1 : 2));
|
||||
dest.writeByte((byte) (videoMuted == null ? 0 : videoMuted ? 1 : 2));
|
||||
dest.writeByte((byte) (welcomePageEnabled == null ? 0 : welcomePageEnabled ? 1 : 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue