[Android] Coding style: comments, consistency, formatting, sorting order

Moves all IncomingCallXXX classes in the package incoming_call in order
to not explode the package org.jitsi.meet.sdk, to be consistent with the
JavaScript source code (but, unfortunately, incoming-call cannot be used
as a Java package name), and bring clarity to which are the "incoming
call"-related Java classes/APIs.
This commit is contained in:
Lyubo Marinov 2018-05-21 12:49:59 -05:00 committed by Saúl Ibarra Corretgé
parent 102d4237a5
commit 4906453cb9
9 changed files with 195 additions and 101 deletions

View File

@ -18,7 +18,6 @@ package org.jitsi.meet.sdk;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.UiThreadUtil;
@ -31,9 +30,11 @@ import java.util.Locale;
import java.util.Map;
import java.util.regex.Pattern;
abstract class AbstractExternalAPIModule<T> extends ReactContextBaseJavaModule {
public abstract class AbstractExternalAPIModule<T>
extends ReactContextBaseJavaModule {
private static Map<String, Method> createAPIMethodMap(Class<?> listenerClass) {
private static Map<String, Method> createAPIMethodMap(
Class<?> listenerClass) {
Map<String, Method> result = new HashMap<>();
// Figure out the mapping between the JitsiMeetViewListener methods
// and the events i.e. redux action types.
@ -81,18 +82,23 @@ abstract class AbstractExternalAPIModule<T> extends ReactContextBaseJavaModule {
private final Map<String, Method> methodMap;
/**
* Initializes a new module instance. There shall be a single instance of
* this module throughout the lifetime of the application.
* Initializes a new {@code AbstractExternalAPIModule} instance. There shall
* be a single instance of a module throughout the lifetime of the
* application.
*
* @param reactContext the {@link ReactApplicationContext} where this module
* is created.
*/
AbstractExternalAPIModule(ReactApplicationContext reactContext,
Class<T> listenerClass) {
public AbstractExternalAPIModule(
ReactApplicationContext reactContext,
Class<T> listenerClass) {
super(reactContext);
this.methodMap = createAPIMethodMap(listenerClass);
}
protected abstract T findListenerByExternalAPIScope(String scope);
/**
* Dispatches an event that occurred on the JavaScript side of the SDK to
* the specified {@code View}'s listener on the UI thread.
@ -102,14 +108,13 @@ abstract class AbstractExternalAPIModule<T> extends ReactContextBaseJavaModule {
* by/associated with the specified {@code name}.
* @param scope
*/
@ReactMethod
public void sendEvent(
final String name,
final ReadableMap data,
final String scope) {
// Make sure listener is invoked on the UI thread. It was requested by
// SDK consumers.
if (!UiThreadUtil.isOnUiThread()) {
if (UiThreadUtil.isOnUiThread()) {
sendEventOnUiThread(name, data, scope);
} else {
UiThreadUtil.runOnUiThread(new Runnable() {
@ -153,8 +158,6 @@ abstract class AbstractExternalAPIModule<T> extends ReactContextBaseJavaModule {
}
}
public abstract T findListenerByExternalAPIScope(String scope);
/**
* Initializes a new {@code HashMap} instance with the key-value
* associations of a specific {@code ReadableMap}.

View File

@ -10,10 +10,13 @@ import com.facebook.react.bridge.ReadableMap;
* object it will dim the screen and disable touch controls. The functionality
* is used with the conference audio-only mode.
*/
class ExternalAPIModule extends AbstractExternalAPIModule<JitsiMeetViewListener> {
class ExternalAPIModule
extends AbstractExternalAPIModule<JitsiMeetViewListener> {
/**
* Initializes a new module instance. There shall be a single instance of
* this module throughout the lifetime of the application.
* Initializes a new {@code ExternalAPIModule} instance. There shall be a
* single instance of this module throughout the lifetime of the
* application.
*
* @param reactContext the {@link ReactApplicationContext} where this module
* is created.
@ -22,6 +25,17 @@ class ExternalAPIModule extends AbstractExternalAPIModule<JitsiMeetViewListener>
super(reactContext, JitsiMeetViewListener.class);
}
@Override
protected JitsiMeetViewListener findListenerByExternalAPIScope(
String scope) {
// The JavaScript App needs to provide uniquely identifying information
// to the native ExternalAPI module so that the latter may match the
// former to the native JitsiMeetView which hosts it.
JitsiMeetView view = JitsiMeetView.findViewByExternalAPIScope(scope);
return view != null ? view.getListener() : null;
}
/**
* Gets the name of this module to be used in the React Native bridge.
*
@ -62,16 +76,6 @@ class ExternalAPIModule extends AbstractExternalAPIModule<JitsiMeetViewListener>
}
}
@Override
public JitsiMeetViewListener findListenerByExternalAPIScope(String scope) {
// The JavaScript App needs to provide uniquely identifying information
// to the native ExternalAPI module so that the latter may match the
// former to the native JitsiMeetView which hosts it.
JitsiMeetView view = JitsiMeetView.findViewByExternalAPIScope(scope);
return view != null ? view.getListener() : null;
}
/**
* Dispatches an event that occurred on the JavaScript side of the SDK to
* the specified {@link JitsiMeetView}'s listener.

View File

@ -1,42 +0,0 @@
package org.jitsi.meet.sdk;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
class IncomingCallExternalAPIModule extends AbstractExternalAPIModule<IncomingCallViewListener> {
/**
* Initializes a new module instance. There shall be a single instance of
* this module throughout the lifetime of the application.
*
* @param reactContext the {@link ReactApplicationContext} where this module
* is created.
*/
public IncomingCallExternalAPIModule(ReactApplicationContext reactContext) {
super(reactContext, IncomingCallViewListener.class);
}
/**
* Gets the name of this module to be used in the React Native bridge.
*
* @return The name of this module to be used in the React Native bridge.
*/
@Override
public String getName() {
return "IncomingCallExternalAPI";
}
@Override
public IncomingCallViewListener findListenerByExternalAPIScope(String scope) {
IncomingCallView view = IncomingCallView.findViewByExternalAPIScope(scope);
return view != null ? view.getListener() : null;
}
@Override
@ReactMethod
public void sendEvent(String name, ReadableMap data, String scope) {
super.sendEvent(name, data, scope);
}
}

View File

@ -1,9 +0,0 @@
package org.jitsi.meet.sdk;
import java.util.Map;
public interface IncomingCallViewListener {
void onIncomingCallAnswered(Map<String, Object> data);
void onIncomingCallDeclined(Map<String, Object> data);
}

View File

@ -42,10 +42,10 @@ public class ReactInstanceManagerHolder {
new AppInfoModule(reactContext),
new AudioModeModule(reactContext),
new ExternalAPIModule(reactContext),
new IncomingCallExternalAPIModule(reactContext),
new PictureInPictureModule(reactContext),
new ProximityModule(reactContext),
new WiFiStatsModule(reactContext),
new org.jitsi.meet.sdk.incoming_call.IncomingCallExternalAPIModule(reactContext),
new org.jitsi.meet.sdk.invite.InviteModule(reactContext),
new org.jitsi.meet.sdk.net.NAT64AddrInfoModule(reactContext)
);
@ -98,7 +98,7 @@ public class ReactInstanceManagerHolder {
? reactContext.getNativeModule(nativeModuleClass) : null;
}
static ReactInstanceManager getReactInstanceManager() {
public static ReactInstanceManager getReactInstanceManager() {
return reactInstanceManager;
}
@ -110,7 +110,7 @@ public class ReactInstanceManagerHolder {
*
* @param application {@code Application} instance which is running.
*/
static void initReactInstanceManager(Application application) {
public static void initReactInstanceManager(Application application) {
if (reactInstanceManager != null) {
return;
}

View File

@ -0,0 +1,75 @@
/*
* Copyright @ 2018-present Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jitsi.meet.sdk.incoming_call;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import org.jitsi.meet.sdk.AbstractExternalAPIModule;
public class IncomingCallExternalAPIModule
extends AbstractExternalAPIModule<IncomingCallViewListener> {
/**
* Initializes a new {@code IncomingCallExternalAPIModule} instance. There
* shall be a single instance of this module throughout the lifetime of the
* application.
*
* @param reactContext The {@link ReactApplicationContext} where this module
* is created.
*/
public IncomingCallExternalAPIModule(ReactApplicationContext reactContext) {
super(reactContext, IncomingCallViewListener.class);
}
@Override
protected IncomingCallViewListener findListenerByExternalAPIScope(
String scope) {
IncomingCallView view
= IncomingCallView.findViewByExternalAPIScope(scope);
return view != null ? view.getListener() : null;
}
/**
* Gets the name of this module to be used in the React Native bridge.
*
* @return The name of this module to be used in the React Native bridge.
*/
@Override
public String getName() {
return "IncomingCallExternalAPI";
}
/**
* Dispatches an event that occurred on the JavaScript side of the SDK to
* the specified {@link IncomingCallView}'s listener.
*
* @param name The name of the event.
* @param data The details/specifics of the event to send determined
* by/associated with the specified {@code name}.
* @param scope
*/
@Override
@ReactMethod
public void sendEvent(String name, ReadableMap data, String scope) {
// XXX Overrides the super implementation to exposes it as a
// react-native module method to the JavaScript source code.
super.sendEvent(name, data, scope);
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright @ 2018-present Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jitsi.meet.sdk.incoming_call;
import android.support.annotation.NonNull;
public class IncomingCallInfo {
private final String callerAvatarUrl;
private final String callerName;
public IncomingCallInfo(
@NonNull String callerName,
@NonNull String callerAvatarUrl) {
this.callerName = callerName;
this.callerAvatarUrl = callerAvatarUrl;
}
public String getCallerAvatarUrl() {
return callerAvatarUrl;
}
public String getCallerName() {
return callerName;
}
}

View File

@ -1,4 +1,20 @@
package org.jitsi.meet.sdk;
/*
* Copyright @ 2018-present Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jitsi.meet.sdk.incoming_call;
import android.app.Activity;
import android.content.Context;
@ -8,13 +24,14 @@ import android.widget.FrameLayout;
import com.facebook.react.ReactRootView;
import org.jitsi.meet.sdk.ReactInstanceManagerHolder;
import java.util.Collections;
import java.util.Set;
import java.util.UUID;
import java.util.WeakHashMap;
public class IncomingCallView extends FrameLayout {
private static final int BACKGROUND_COLOR = 0xFF111111;
private static final Set<IncomingCallView> views
@ -32,24 +49,6 @@ public class IncomingCallView extends FrameLayout {
return null;
}
public static final class IncomingCallInfo {
private final String callerName;
private final String callerAvatarUrl;
public IncomingCallInfo(@NonNull String callerName, @NonNull String callerAvatarUrl) {
this.callerName = callerName;
this.callerAvatarUrl = callerAvatarUrl;
}
public String getCallerName() {
return callerName;
}
public String getCallerAvatarUrl() {
return callerAvatarUrl;
}
}
private final String externalAPIScope;
private IncomingCallViewListener listener;
private ReactRootView reactRootView;
@ -57,9 +56,8 @@ public class IncomingCallView extends FrameLayout {
public IncomingCallView(@NonNull Context context) {
super(context);
if (ReactInstanceManagerHolder.getReactInstanceManager() == null) {
ReactInstanceManagerHolder.initReactInstanceManager(((Activity) context).getApplication());
}
ReactInstanceManagerHolder.initReactInstanceManager(((Activity) context).getApplication());
setBackgroundColor(BACKGROUND_COLOR);
externalAPIScope = UUID.randomUUID().toString();
synchronized (views) {

View File

@ -0,0 +1,25 @@
/*
* Copyright @ 2018-present Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jitsi.meet.sdk.incoming_call;
import java.util.Map;
public interface IncomingCallViewListener {
void onIncomingCallAnswered(Map<String, Object> data);
void onIncomingCallDeclined(Map<String, Object> data);
}