2

Now I am using Gluon plugin and it is very helpful to start working with JavaFXPorts. I have my application ready and I can use it on computers and phones. I tested on phone with system android. Application is working good but only with my server.

I take care of the different resolutions and I think that it is good for now.

I want to have Turn-based Multiplayer Application but I have still big problem with using Google Play Service. Tutorial which show how to use this services for turn-based multiplayer application is written in pure android and use Activity. My question is maybe very simple but If I have my application view from "fxml" how to use it as an tutorial Activity?

I want to do auto-matching for my application and next I want override method takeTurn() to suit it to my application.

For example, how can I change thing like that (code below) to application in JavaFX?

I must use google services from my JavaFX(src/main/java folder) class in addition AndroidPlatformProvider.java and all methods must be in src/android/java folder. I know that I must use PlatformService and PlatformProvider. I did it as in the examples: HelloPlatform and SMSTracker .

I use methods from my interface PlatformProvider but application still crashes. :(

I only use Provider from my code of JavaFX and I don't have android Activity. I don't know how to use these method without Activity or View:

- public void onActivityResult(int request, int response, Intent data)

- public void playTurn(View view)

Can I call from google service methods to methods from my controller for view (fxml). I don't know how these methods should working with JavaFX.

public class TbmpGameActivity extends Activity {
...

@Override
public void onActivityResult(int request, int response, Intent data) {
    super.onActivityResult(request, response, data);
    ...

    if (request == RC_SELECT_PLAYERS) {
        if (response != Activity.RESULT_OK) {
            // user canceled
            return;
        }

        // Get the invitee list.
        final ArrayList<String> invitees =
                data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);

        // Get auto-match criteria.
        Bundle autoMatchCriteria = null;
        int minAutoMatchPlayers = data.getIntExtra(
                Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
        int maxAutoMatchPlayers = data.getIntExtra(
                Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);
        if (minAutoMatchPlayers > 0) {
            autoMatchCriteria = RoomConfig.createAutoMatchCriteria(
                    minAutoMatchPlayers, maxAutoMatchPlayers, 0);
        } else {
            autoMatchCriteria = null;
        }

        TurnBasedMatchConfig tbmc = TurnBasedMatchConfig.builder()
                .addInvitedPlayers(invitees)
                .setAutoMatchCriteria(autoMatchCriteria)
                .build();

        // Create and start the match.
        Games.TurnBasedMultiplayer
            .createMatch(mGoogleApiClient, tbmc)
            .setResultCallback(new MatchInitiatedCallback());
    }
}
}

or something like that:

// Call this method when a player has completed his turn and wants to
// go onto the next player, which may be himself.
public void playTurn(View view) {

    // Get the next participant in the game-defined way, possibly round-robin.
    String nextParticipantId = getNextParticipantId();

    // Get the updated state. In this example, we simply retrieve a
    // text string from the view. In your game, there may be more
    // complicated state.
    mTurnData = mDataView.getText().toString();

    // At this point, you might want to show a waiting dialog so that
    // the current player does not try to submit turn actions twice.
    showSpinner();

    // Invoke the next turn. We are converting our data to a byte array.
    Games.TurnBasedMultiplayer
    .takeTurn(mGoogleApiClient, mMatch.getMatchId(),
             mTurnData.getBytes(Charset.forName("UTF-16")),
             nextParticipantId)
    .setResultCallback(this);
}
Łukasz M
  • 53
  • 3

1 Answers1

0

Latest version of the jfxmobile plugin (1.0.3) includes recent changes in Dalvik SDK that contains the port of JavaFX 8 to android.

In FXActivity class, it has been added a very convenient method to listen to results of intents: setOnActivityResultHandler().

This means you shouldn't add new activities to your app, and only use FXActivity. You should add an Intent to it, and set a proper result handler to the FXActivity.

Have a look at this recent post at Gluon's site. It explains how to access native services, based on the case of taking a picture with the device's camera, and waiting to get the result of it to resume the app.

Basically, this is what it is required in this case:

public void takePicture() {
    // create intent
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    ...

    // Add result handler 
    FXActivity.getInstance().setOnActivityResultHandler((requestCode, resultCode, data) -> {
        if (requestCode == TAKE_PICTURE && resultCode == RESULT_OK) {
            ...
        }
    });

    // launch activity
    FXActivity.getInstance().startActivityForResult(intent, TAKE_PICTURE);
}

Try this approach with your app.

José Pereda
  • 44,311
  • 7
  • 104
  • 132