私にとっては、次のような LDGame というクラスがあります。
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
public class LDGame extends Game implements ApplicationListener {
private static RequestHandler requestHandler;
private static GoogleInterface platformInterface;
public LDGame(RequestHandler requestHandler, GoogleInterface anInterface) {
this.requestHandler = requestHandler;
this.platformInterface = anInterface;
}
@Override
public void create() {
Assets.loadAll();
//platformInterface.LogOut();
setScreen(new MainLogin(this, false));
}
@Override
public void resume() {
super.resume();
// Relase static resources
Assets.loadAll();
}
public GoogleInterface getPlatformInterface() {
return platformInterface;
}
public RequestHandler getRequestHandler(){
return requestHandler;
}
}
ここで、インターフェイス セットを取得するための基本を処理します。(あなたのdogejumpと同じ)
次に、私の MainActivity は Android 側でこれを行います
public class MainActivity extends AndroidApplication implements RequestHandler, GameHelperListener,
GoogleInterface, RealTimeMessageReceivedListener, RoomStatusUpdateListener, RoomUpdateListener,
OnInvitationReceivedListener, RealTimeReliableMessageSentListener, OnImageLoadedListener, OnStateLoadedListener, ConnectionCallbacks{
private View gameView;
private GameHelper mHelper;
private GameHelperInterface mGHInterface = null;
private LoginInterface mLoginInterface = null;
private ConfirmInterface mConfirmInterface = null;
private OnLeaderboardScoresLoadedListener theLeaderboardListener;
private RoomUpdateListener mRoomUpdateListener= this;
private Handler libGDXHandler;
// Debug tag
final static String TAG = "Liars Dice Multi";
// Request codes for the UIs that we show with startActivityForResult:
final static int RC_SELECT_PLAYERS = 10000;
final static int RC_INVITATION_INBOX = 10001;
final static int RC_WAITING_ROOM = 10002;
final static int RC_SETTINGS = 10004;
// Request Key for AppStateClient Slot
final static int ASC_SLOT_UNFINISHED_GAMES = 0;
static final int ASC_SLOT_SERVER_UNFINISHED_GAMES = 1;
// Room ID where the currently active game is taking place; null if we're
// not playing.
String mRoomId = null;
Room mRoomCurrent = null;
int mCurrentToken = 1;
// Are we playing in multiplayer mode?
boolean mMultiplayer = false;
// The participants in the currently active game
ArrayList<Participant> mParticipants = null;
ArrayList<String> listIgnoreTheseIDs = new ArrayList<String>();
// My participant ID in the currently active game
String mMyId = null;
//Token Trackers
ArrayList<Integer> readyToPlayTokens = new ArrayList<Integer>();
// If non-null, this is the id of the invitation we received via the
// invitation listener
String mIncomingInvitationId = null;
// Message buffer for sending messages
byte[] mMsgBuf = new byte[2];
ArrayList<String> messagesRecieved = new ArrayList<String>();
ArrayList<tokenInfo> listTokensSent = new ArrayList<MainActivity.tokenInfo>();
HashMap<Integer, tokenInfo> mapTokensSent = new HashMap<Integer, MainActivity.tokenInfo>();
// flag indicating whether we're dismissing the waiting room because the
// game is starting
boolean mWaitRoomDismissedFromCode = false;
Context activityContext;
MainActivity mA;
private AdHubView adView;
private boolean bCheckingTimes;
boolean bAnyRoomEvent = false;
private long oldCreationTime;
private Intent previousMatch;
private int iServerBadAttempts = -1;
public MainActivity(){
libGDXHandler = new Handler();
mHelper = new GameHelper(this);
mHelper.enableDebugLog(true, "Helper");
//create a listener for getting raw data back from leaderboard
theLeaderboardListener = new OnLeaderboardScoresLoadedListener() {
@Override
public void onLeaderboardScoresLoaded(int arg0, LeaderboardBuffer arg1,
LeaderboardScoreBuffer arg2) {
}
};
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SearchLayout layout = new SearchLayout(this);
SearchLayout.setSearchActivity(this);
// starts libGDX render thread
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
gameView = initializeForView(new LDGame(this, this), true);
adView = new AdHubView(this, "2011000001_001", AdSize.BANNER);
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layout.addView(gameView);
layout.addView(adView, adParams);
setContentView(layout);
//mHelper.setup(this);
mHelper.setup(this, GameHelper.CLIENT_GAMES | GameHelper.CLIENT_APPSTATE | GameHelper.CLIENT_PLUS, null);
mHelper.getPlusClient().registerConnectionCallbacks(this);
activityContext = this;
mA = this;
}
これにより、Game Servives や Google Cloud とやり取りできるようになります...
私の画面 (LDGame クラスからわかるように) では、これを行うだけです。
game.getPlatformInterface().anycallinYourInterface();
私の呼び出しを家の libgdx 側に送信するには..(ハンドラーを忘れないでください)
そしてアクティブな画面が何であれ、次のように libGDX 側に新しいインターフェイスを呼び出します。
//this will set the ConfirmInterface in the Android Activity
//and allow for future calls to call any implemented methods
//that are set inside the ConfirmInterface
private void setCallbackHandler(){
game.getRequestHandler().confirm(new ConfirmInterface() {
@Override
public void yes() {
Gdx.app.log("LDGame", "Clicked Yes");
dLog("have a direct invite, so waiting for it to process");
startNextScreen();
}
public void no() {
Gdx.app.log("LDGame", "Clicked No");
}
@Override
public void loginFailed(final boolean failedForPreviousNumberOfAttemtps, final long timeElapsed) {
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
setGoogleButtonImage(false);
if(failedForPreviousNumberOfAttemtps){
showFailedLoginForBadAttempts(timeElapsed);
}
}
});
}
@Override
public void loginSucceeded() {
//this means the login for both services is good, and the data returned meets
//whatever sign in criteria is set
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
setGoogleButtonImage(true);
game.getPlatformInterface().loadInvitations();
}
});
}
@Override
public void firstLogin() {
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
showFirstLogin();
}
});
}
@Override
public void googleSucceeded() {
//this means that google just returned a valid hit
game.getPlatformInterface().checkIfServerTimesAreValid();
showSignOutBar();
}
@Override
public void needToCheckTimesOnServer() {
//this means that there are three times or more on the server for incomplete games
//the only way to clear this is to try and do a quick check against a room login
Timer.schedule(new Timer.Task() {
@Override
public void run() {
game.getPlatformInterface().checkIfServerTimesAreValid();
}
}, 1f);
}
@Override
public void onInvitationReceived() {
game.getPlatformInterface().loadInvitations();
Assets.soundArrive.play();
}
@Override
public void haveInvitations(int count) {
// TODO Auto-generated method stub
}
});
}
私のAndroidでこれを行うことができるように:
@Override
public void onSignInFailed() {
mConfirmInterface.loginFailed(false, 0);
}
}