Delphi Android Java-класс, наследующий от интерфейса

Я пытаюсь внедрить последнюю версию Службы Google Play (15.01) в Delphi. Я объединил соответствующие библиотеки в один файл jar и извлек файл моста с помощью java2op. Все было довольно гладко, пока я не столкнулся с этим шоу-шоу:

У меня этот класс:

JRoomConfigClass = interface(JObjectClass)
['{88F39239-F51D-4BA0-8131-24EBF070A584}']
{class} function builder(P1: JRoomUpdateListener): JRoomConfig_Builder; 
cdecl; overload;
{class} function builder(P1: JRoomUpdateCallback): JRoomConfig_Builder; 
cdecl; overload;
{class} function createAutoMatchCriteria(P1: Integer; P2: Integer; P3: 
Int64): JBundle; cdecl;
end;

[JavaSignature('com/google/android/gms/games/multiplayer/realtime/
RoomConfig')]
JRoomConfig = interface(JObject)
['{EF764B81-BF25-490C-8562-D9DC6BB337AD}']
function getAutoMatchCriteria: JBundle; cdecl;
function getInvitationId: JString; cdecl;
function getInvitedPlayerIds: TJavaObjectArray<JString>; cdecl;
function getMessageReceivedListener: JRealTimeMessageReceivedListener; cdecl;
function getOnMessageReceivedListener: JOnRealTimeMessageReceivedListener; 
cdecl;
function getRoomStatusUpdateCallback: JRoomStatusUpdateCallback; cdecl;
function getRoomStatusUpdateListener: JRoomStatusUpdateListener; cdecl;
function getRoomUpdateCallback: JRoomUpdateCallback; cdecl;
function getRoomUpdateListener: JRoomUpdateListener; cdecl;
function getVariant: Integer; cdecl;
function zzch: Jrealtime_zzh; cdecl;
end;
TJRoomConfig = class(TJavaGenericImport<JRoomConfigClass, JRoomConfig>) end;

я вызываю метод «строитель»:

rtmConfigBuilder := TJRoomConfig.JavaClass.builder(RoomUpdateCallback);

Но RoomUpdateCallback определяется следующим образом:

JRoomUpdateCallbackClass = interface(JRoomUpdateListenerClass)
['{B7973699-780A-4D76-9585-D113DD245CC5}']
{class} function init: JRoomUpdateCallback; cdecl;
end;
[JavaSignature('com/google/android/gms/games/multiplayer/realtime/
RoomUpdateCallback')]

JRoomUpdateCallback = interface(JRoomUpdateListener)
['{0CA35AB2-8AA9-4604-909B-68DE93112867}']
procedure onJoinedRoom(P1: Integer; P2: JRoom); cdecl;
procedure onLeftRoom(P1: Integer; P2: JString); cdecl;
procedure onRoomConnected(P1: Integer; P2: JRoom); cdecl;
procedure onRoomCreated(P1: Integer; P2: JRoom); cdecl;
end;
TJRoomUpdateCallback = class(TJavaGenericImport<JRoomUpdateCallbackClass, 
JRoomUpdateCallback>) end;

Таким образом, это не интерфейс, а это значит, что я не могу использовать обычный подход слушателя:

TRoomUpdateListener = class(TJavaLocal, JRoomUpdateCallback)
  procedure onJoinedRoom(P1: Integer; P2: JRoom); cdecl;
  procedure onLeftRoom(P1: Integer; P2: JString); cdecl;
  procedure onRoomConnected(P1: Integer; P2: JRoom); cdecl;
  procedure onRoomCreated(P1: Integer; P2: JRoom); cdecl;
 end;

Но JRoomUpdateCallback является потомком JRoomUpdateListener, который является интерфейсом:

JRoomUpdateListenerClass = interface(IJavaClass)
['{62795DB4-DDD0-48F2-AABA-644CC96D5E6E}']
end;

[JavaSignature('com/google/android/gms/games/multiplayer/realtime/
RoomUpdateListener')]
JRoomUpdateListener = interface(IJavaInstance)
['{236212AF-A72A-4DEC-BB73-E0B42E80F7A1}']
procedure onJoinedRoom(P1: Integer; P2: JRoom); cdecl;
procedure onLeftRoom(P1: Integer; P2: JString); cdecl;
procedure onRoomConnected(P1: Integer; P2: JRoom); cdecl;
procedure onRoomCreated(P1: Integer; P2: JRoom); cdecl;
end;
TJRoomUpdateListener = class(TJavaGenericImport<JRoomUpdateListenerClass, 
JRoomUpdateListener>) end;

Как это реализовать? Возможно ли это?

java,android,delphi,

-1

Ответов: 1


1

Об этом нет. Мне пришлось закодировать некоторые java. это то, что я вложил в свою java-библиотеку, если кто-то может извлечь из этого выгоду.

package cometsoft.com.roomconfiglib;

import 
com.google.android.gms.games.multiplayer.realtime.OnRealTimeMessageReceivedListener;
import com.google.android.gms.games.multiplayer.realtime.RealTimeMessage;
import com.google.android.gms.games.multiplayer.realtime.Room;
import com.google.android.gms.games.multiplayer.realtime.RoomConfig;
import com.google.android.gms.games.multiplayer.realtime.RoomStatusUpdateCallback;
import com.google.android.gms.games.multiplayer.realtime.RoomUpdateCallback;

import android.os.Bundle;
import android.support.annotation.NonNull;

import java.util.ArrayList;
import java.util.List;

interface RoomConfigListener {
    public abstract void onRoomConnecting(@android.support.annotation.Nullable 
com.google.android.gms.games.multiplayer.realtime.Room room);

public abstract void onRoomAutoMatching(@android.support.annotation.Nullable 
com.google.android.gms.games.multiplayer.realtime.Room room);

public abstract void onPeerInvitedToRoom(@android.support.annotation.Nullable 
com.google.android.gms.games.multiplayer.realtime.Room room, 
   @android.support.annotation.NonNull java.util.List<java.lang.String> list);

public abstract void onPeerDeclined(@android.support.annotation.Nullable 
com.google.android.gms.games.multiplayer.realtime.Room room, 
@android.support.annotation.NonNull java.util.List<java.lang.String> list);

public abstract void onPeerJoined(@android.support.annotation.Nullable 
   com.google.android.gms.games.multiplayer.realtime.Room room, 
   @android.support.annotation.NonNull java.util.List<java.lang.String> list);

public abstract void onPeerLeft(@android.support.annotation.Nullable 
   com.google.android.gms.games.multiplayer.realtime.Room room, 
   @android.support.annotation.NonNull java.util.List<java.lang.String> list);

public abstract void onConnectedToRoom(@android.support.annotation.Nullable 
   com.google.android.gms.games.multiplayer.realtime.Room room);

public abstract void onDisconnectedFromRoom(@android.support.annotation.Nullable 
   com.google.android.gms.games.multiplayer.realtime.Room room);

public abstract void onPeersConnected(@android.support.annotation.Nullable 
   com.google.android.gms.games.multiplayer.realtime.Room room, 
   @android.support.annotation.NonNull java.util.List<java.lang.String> list);

public abstract void onPeersDisconnected(@android.support.annotation.Nullable 
   com.google.android.gms.games.multiplayer.realtime.Room room, 
   @android.support.annotation.NonNull java.util.List<java.lang.String> list);

public abstract void onP2PConnected(@android.support.annotation.NonNull 
   java.lang.String s);

public abstract void onP2PDisconnected(@android.support.annotation.NonNull 
   java.lang.String s);

public abstract void onRoomCreated(int i, @android.support.annotation.Nullable 
   com.google.android.gms.games.multiplayer.realtime.Room room);

public abstract void onJoinedRoom(int i, @android.support.annotation.Nullable 
   com.google.android.gms.games.multiplayer.realtime.Room room);

public abstract void onLeftRoom(int i, @android.support.annotation.NonNull 
   java.lang.String s);

public abstract void onRoomConnected(int i, @android.support.annotation.Nullable 
   com.google.android.gms.games.multiplayer.realtime.Room room);

void onRealTimeMessageReceived(@android.support.annotation.NonNull 
   com.google.android.gms.games.multiplayer.realtime.RealTimeMessage 
   realTimeMessage);

}

public class RoomConfigBuilder {

    private RoomConfigListener mRoomConfigListener;
    private Bundle mautoMatchCriteria;

    private RoomUpdateCallback mRoomUpdateCallback = new RoomUpdateCallback() {

        @Override
        public void onRoomCreated(int statusCode, Room room) {
            mRoomConfigListener.onRoomCreated(statusCode, room);
        }

        @Override
        public void onRoomConnected(int statusCode, Room room) {
            mRoomConfigListener.onRoomConnected(statusCode, room);
        }

        @Override
        public void onJoinedRoom(int statusCode, Room room) {
            mRoomConfigListener.onJoinedRoom(statusCode, room);
        }

        @Override
        public void onLeftRoom(int statusCode, @NonNull String roomId) {
            mRoomConfigListener.onLeftRoom(statusCode, roomId);
        }

    };

    private RoomStatusUpdateCallback mRoomStatusUpdateCallback = new 
       RoomStatusUpdateCallback() {

        @Override
        public void onConnectedToRoom(Room room) {
            mRoomConfigListener.onConnectedToRoom(room);
        }

        @Override
        public void onDisconnectedFromRoom(Room room) {
            mRoomConfigListener.onDisconnectedFromRoom(room);
        }

        @Override
        public void onPeerDeclined(Room room, @NonNull List<String> arg1) {
            mRoomConfigListener.onPeerDeclined(room, arg1);
        }

        @Override
        public void onPeerInvitedToRoom(Room room, @NonNull List<String> arg1) {
            mRoomConfigListener.onPeerInvitedToRoom(room, arg1);
        }

        @Override
        public void onP2PDisconnected(@NonNull String participant) {
            mRoomConfigListener.onP2PDisconnected(participant);
        }

        @Override
        public void onP2PConnected(@NonNull String participant) {
            mRoomConfigListener.onP2PConnected(participant);
        }

        @Override
        public void onPeerJoined(Room room, @NonNull List<String> arg1) {
            mRoomConfigListener.onPeerJoined(room, arg1);
        }

        @Override
        public void onPeerLeft(Room room, @NonNull List<String> peersWhoLeft) {
            mRoomConfigListener.onPeerLeft(room, peersWhoLeft);
        }

        @Override
        public void onRoomAutoMatching(Room room) {
            mRoomConfigListener.onRoomAutoMatching(room);
        }

        @Override
        public void onRoomConnecting(Room room) {
            mRoomConfigListener.onRoomConnecting(room);
        }

        @Override
        public void onPeersConnected(Room room, @NonNull List<String> peers) {
            mRoomConfigListener.onPeersConnected(room, peers);
        }

        @Override
        public void onPeersDisconnected(Room room, @NonNull List<String> peers) {
            mRoomConfigListener.onPeersDisconnected(room, peers);
        }
    };

    private OnRealTimeMessageReceivedListener mOnRealTimeMessageReceivedListener = 
       new OnRealTimeMessageReceivedListener() {
        @Override
        public void onRealTimeMessageReceived(@NonNull RealTimeMessage 
           realTimeMessage) {
            mRoomConfigListener.onRealTimeMessageReceived(realTimeMessage);
        }
    };

    public RoomConfig BuildRoomConfig(RoomConfigListener listener, Bundle 
           autoMatchCriteria, ArrayList<String> invitees, String invitationId) {
        mRoomConfigListener = listener;
        mautoMatchCriteria = autoMatchCriteria;
        RoomConfig.Builder mRoomConfigBuilder;

        mRoomConfigBuilder = 
           RoomConfig.builder(mRoomUpdateCallback)
           .setRoomStatusUpdateCallback(mRoomStatusUpdateCallback)
           .setOnMessageReceivedListener(mOnRealTimeMessageReceivedListener);

        if (invitees != null){
           mRoomConfigBuilder.addPlayersToInvite(invitees);
        }

        if (autoMatchCriteria != null){
            mRoomConfigBuilder.setAutoMatchCriteria(mautoMatchCriteria);
        }

        if (invitationId != null){
            mRoomConfigBuilder.setInvitationIdToAccept(invitationId);
        }

        return mRoomConfigBuilder.build();
    }
}
Java, Android, Дельфы,
Похожие вопросы
Яндекс.Метрика