diff --git a/.gitignore b/.gitignore index c6dc1daa..fdd42c17 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ -/.gradle/ +.gradle/ .settings/ bin/ +gen/ build/ .project .DS_Store -/.idea +.idea/ +*.iml +local.properties diff --git a/BasicSamples/.gitignore b/BasicSamples/.gitignore deleted file mode 100644 index ef624861..00000000 --- a/BasicSamples/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.gradle/ -.idea/ -*.iml -local.properties diff --git a/BasicSamples/.gradle/1.6/taskArtifacts/cache.properties b/BasicSamples/.gradle/1.6/taskArtifacts/cache.properties deleted file mode 100644 index bf2f2993..00000000 --- a/BasicSamples/.gradle/1.6/taskArtifacts/cache.properties +++ /dev/null @@ -1 +0,0 @@ -#Wed Dec 11 17:04:15 PST 2013 diff --git a/BasicSamples/.gradle/1.6/taskArtifacts/cache.properties.lock b/BasicSamples/.gradle/1.6/taskArtifacts/cache.properties.lock deleted file mode 100644 index 40fdece9..00000000 --- a/BasicSamples/.gradle/1.6/taskArtifacts/cache.properties.lock +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/BasicSamples/.gradle/1.6/taskArtifacts/fileHashes.bin b/BasicSamples/.gradle/1.6/taskArtifacts/fileHashes.bin deleted file mode 100644 index 594d724b..00000000 Binary files a/BasicSamples/.gradle/1.6/taskArtifacts/fileHashes.bin and /dev/null differ diff --git a/BasicSamples/.gradle/1.6/taskArtifacts/fileSnapshots.bin b/BasicSamples/.gradle/1.6/taskArtifacts/fileSnapshots.bin deleted file mode 100644 index 5061886d..00000000 Binary files a/BasicSamples/.gradle/1.6/taskArtifacts/fileSnapshots.bin and /dev/null differ diff --git a/BasicSamples/.gradle/1.6/taskArtifacts/outputFileStates.bin b/BasicSamples/.gradle/1.6/taskArtifacts/outputFileStates.bin deleted file mode 100644 index d1f78e1f..00000000 Binary files a/BasicSamples/.gradle/1.6/taskArtifacts/outputFileStates.bin and /dev/null differ diff --git a/BasicSamples/.gradle/1.6/taskArtifacts/taskArtifacts.bin b/BasicSamples/.gradle/1.6/taskArtifacts/taskArtifacts.bin deleted file mode 100644 index 973ed6ba..00000000 Binary files a/BasicSamples/.gradle/1.6/taskArtifacts/taskArtifacts.bin and /dev/null differ diff --git a/BasicSamples/ButtonClicker/.gitignore b/BasicSamples/ButtonClicker/.gitignore deleted file mode 100644 index 9006481f..00000000 --- a/BasicSamples/ButtonClicker/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/bin/ -/gen/ -*.iml -/build/ diff --git a/BasicSamples/CollectAllTheStars2/.gitignore b/BasicSamples/CollectAllTheStars2/.gitignore deleted file mode 100644 index 47036e4a..00000000 --- a/BasicSamples/CollectAllTheStars2/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/build/ -/bin/ -/gen/ diff --git a/BasicSamples/SkeletonTbmp/.classpath b/BasicSamples/SkeletonTbmp/.classpath deleted file mode 100644 index 51769745..00000000 --- a/BasicSamples/SkeletonTbmp/.classpath +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/BasicSamples/SkeletonTbmp/.gitignore b/BasicSamples/SkeletonTbmp/.gitignore deleted file mode 100644 index 84c048a7..00000000 --- a/BasicSamples/SkeletonTbmp/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build/ diff --git a/BasicSamples/SkeletonTbmp/.project b/BasicSamples/SkeletonTbmp/.project deleted file mode 100644 index 905b5424..00000000 --- a/BasicSamples/SkeletonTbmp/.project +++ /dev/null @@ -1,33 +0,0 @@ - - - TbmpSkeleton - - - - - - com.android.ide.eclipse.adt.ResourceManagerBuilder - - - - - com.android.ide.eclipse.adt.PreCompilerBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - com.android.ide.eclipse.adt.ApkBuilder - - - - - - com.android.ide.eclipse.adt.AndroidNature - org.eclipse.jdt.core.javanature - - diff --git a/BasicSamples/TypeANumber/.gitignore b/BasicSamples/TypeANumber/.gitignore deleted file mode 100644 index 47036e4a..00000000 --- a/BasicSamples/TypeANumber/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/build/ -/bin/ -/gen/ diff --git a/BasicSamples/CollectAllTheStars2/build.gradle b/ButtonClicker/build.gradle similarity index 71% rename from BasicSamples/CollectAllTheStars2/build.gradle rename to ButtonClicker/build.gradle index cfbc3a59..849ba361 100644 --- a/BasicSamples/CollectAllTheStars2/build.gradle +++ b/ButtonClicker/build.gradle @@ -22,13 +22,17 @@ android { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt') } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } } dependencies { - implementation "com.android.support:appcompat-v7:${appcompat_library_version}" - implementation "com.android.support:support-v4:${support_library_version}" - implementation "com.google.android.gms:play-services-games:${gms_library_version}" + implementation 'androidx.appcompat:appcompat:1.0.0' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation "com.google.android.gms:play-services-games:20.0.1" implementation "com.google.android.gms:play-services-auth:${gms_library_version}" } @@ -36,4 +40,4 @@ buildscript { repositories { jcenter() } -} +} \ No newline at end of file diff --git a/BasicSamples/ButtonClicker/src/main/AndroidManifest.xml b/ButtonClicker/src/main/AndroidManifest.xml similarity index 100% rename from BasicSamples/ButtonClicker/src/main/AndroidManifest.xml rename to ButtonClicker/src/main/AndroidManifest.xml diff --git a/BasicSamples/ButtonClicker/src/main/java/com/google/example/games/bc/MainActivity.java b/ButtonClicker/src/main/java/com/google/example/games/bc/MainActivity.java similarity index 99% rename from BasicSamples/ButtonClicker/src/main/java/com/google/example/games/bc/MainActivity.java rename to ButtonClicker/src/main/java/com/google/example/games/bc/MainActivity.java index 1b0c2cf7..593b3ff3 100644 --- a/BasicSamples/ButtonClicker/src/main/java/com/google/example/games/bc/MainActivity.java +++ b/ButtonClicker/src/main/java/com/google/example/games/bc/MainActivity.java @@ -20,7 +20,7 @@ import android.content.Intent; import android.os.Bundle; import android.os.Handler; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.util.Log; import android.view.KeyEvent; import android.view.View; @@ -631,14 +631,16 @@ private void onConnected(GoogleSignInAccount googleSignInAccount) { // get the playerId from the PlayersClient PlayersClient playersClient = Games.getPlayersClient(this, googleSignInAccount); - playersClient.getCurrentPlayer().addOnSuccessListener( - new OnSuccessListener() { + playersClient.getCurrentPlayer() + .addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(Player player) { mPlayerId = player.getPlayerId(); + + switchToMainScreen(); } - } - ); + }) + .addOnFailureListener(createFailureListener("There was a problem getting the player id!")); } // register listener so we are notified if we receive an invitation to play @@ -654,7 +656,7 @@ public void onSuccess(Player player) { public void onSuccess(Bundle hint) { if (hint != null) { Invitation invitation = - hint.getParcelable(Multiplayer.EXTRA_TURN_BASED_MATCH); + hint.getParcelable(Multiplayer.EXTRA_INVITATION); if (invitation != null && invitation.getInvitationId() != null) { // retrieve and cache the invitation ID @@ -665,8 +667,6 @@ public void onSuccess(Bundle hint) { } }) .addOnFailureListener(createFailureListener("There was a problem getting the activation hint!")); - - switchToMainScreen(); } private OnFailureListener createFailureListener(final String string) { diff --git a/BasicSamples/ButtonClicker/src/main/res/drawable-hdpi/ic_launcher.png b/ButtonClicker/src/main/res/drawable-hdpi/ic_launcher.png similarity index 100% rename from BasicSamples/ButtonClicker/src/main/res/drawable-hdpi/ic_launcher.png rename to ButtonClicker/src/main/res/drawable-hdpi/ic_launcher.png diff --git a/BasicSamples/ButtonClicker/src/main/res/drawable-ldpi/ic_launcher.png b/ButtonClicker/src/main/res/drawable-ldpi/ic_launcher.png similarity index 100% rename from BasicSamples/ButtonClicker/src/main/res/drawable-ldpi/ic_launcher.png rename to ButtonClicker/src/main/res/drawable-ldpi/ic_launcher.png diff --git a/BasicSamples/ButtonClicker/src/main/res/drawable-mdpi/ic_launcher.png b/ButtonClicker/src/main/res/drawable-mdpi/ic_launcher.png similarity index 100% rename from BasicSamples/ButtonClicker/src/main/res/drawable-mdpi/ic_launcher.png rename to ButtonClicker/src/main/res/drawable-mdpi/ic_launcher.png diff --git a/BasicSamples/ButtonClicker/src/main/res/drawable-xhdpi/ic_launcher.png b/ButtonClicker/src/main/res/drawable-xhdpi/ic_launcher.png similarity index 100% rename from BasicSamples/ButtonClicker/src/main/res/drawable-xhdpi/ic_launcher.png rename to ButtonClicker/src/main/res/drawable-xhdpi/ic_launcher.png diff --git a/BasicSamples/ButtonClicker/src/main/res/drawable-xxhdpi/ic_launcher.png b/ButtonClicker/src/main/res/drawable-xxhdpi/ic_launcher.png similarity index 100% rename from BasicSamples/ButtonClicker/src/main/res/drawable-xxhdpi/ic_launcher.png rename to ButtonClicker/src/main/res/drawable-xxhdpi/ic_launcher.png diff --git a/BasicSamples/ButtonClicker/src/main/res/layout/activity_main.xml b/ButtonClicker/src/main/res/layout/activity_main.xml similarity index 100% rename from BasicSamples/ButtonClicker/src/main/res/layout/activity_main.xml rename to ButtonClicker/src/main/res/layout/activity_main.xml diff --git a/BasicSamples/ButtonClicker/src/main/res/values-v13/styles.xml b/ButtonClicker/src/main/res/values-v13/styles.xml similarity index 89% rename from BasicSamples/ButtonClicker/src/main/res/values-v13/styles.xml rename to ButtonClicker/src/main/res/values-v13/styles.xml index 997965b5..03b93037 100644 --- a/BasicSamples/ButtonClicker/src/main/res/values-v13/styles.xml +++ b/ButtonClicker/src/main/res/values-v13/styles.xml @@ -16,5 +16,5 @@ --> - diff --git a/BasicSamples/CollectAllTheStars2/src/main/res/values-v14/styles.xml b/CollectAllTheStars2/src/main/res/values-v14/styles.xml similarity index 92% rename from BasicSamples/CollectAllTheStars2/src/main/res/values-v14/styles.xml rename to CollectAllTheStars2/src/main/res/values-v14/styles.xml index 9e1013d7..54a8dc22 100644 --- a/BasicSamples/CollectAllTheStars2/src/main/res/values-v14/styles.xml +++ b/CollectAllTheStars2/src/main/res/values-v14/styles.xml @@ -22,7 +22,7 @@ AppBaseTheme from BOTH res/values/styles.xml and res/values-v11/styles.xml on API 14+ devices. --> - diff --git a/BasicSamples/CollectAllTheStars2/src/main/res/values/ids.xml b/CollectAllTheStars2/src/main/res/values/ids.xml similarity index 100% rename from BasicSamples/CollectAllTheStars2/src/main/res/values/ids.xml rename to CollectAllTheStars2/src/main/res/values/ids.xml diff --git a/BasicSamples/CollectAllTheStars2/src/main/res/values/strings.xml b/CollectAllTheStars2/src/main/res/values/strings.xml similarity index 100% rename from BasicSamples/CollectAllTheStars2/src/main/res/values/strings.xml rename to CollectAllTheStars2/src/main/res/values/strings.xml diff --git a/BasicSamples/CollectAllTheStars2/src/main/res/values/styles.xml b/CollectAllTheStars2/src/main/res/values/styles.xml similarity index 100% rename from BasicSamples/CollectAllTheStars2/src/main/res/values/styles.xml rename to CollectAllTheStars2/src/main/res/values/styles.xml diff --git a/FAQ.txt b/FAQ.txt deleted file mode 100644 index aa88dfa7..00000000 --- a/FAQ.txt +++ /dev/null @@ -1,46 +0,0 @@ -GOOGLE PLAY GAMES - ANDROID SAMPLES -FREQUENTLY ASKED QUESTIONS - - -[1] How should I compile BaseGameUtils into my project? - - Include BaseGameUtils as a library project. Consult your build system's - documentation as to how to accomplish this, since this varies by IDE. - If you are using Gradle, you can add the BaseGameUtils directory to - your project and adjust your project's build.gradle files to reflect - a dependency on BaseGameUtils. For an example, see the build.gradle - files in the sample. Particularly, the BasicSamples is set up as - a gradle multi-project where several different apps (the samples) - depend on the BaseGameUtils library. - - You should NOT compile the BaseGameUtils classes as stand-alone JAR files - into your project. Doing so will cause them not to be able to find their - resources, and might cause problems. - - If you want more simplicity and don't want to deal with build system - red tape, you can adopt the less organized approach of dropping in - the BaseGameUtil java files into your project; if you do, remember to - also copy the BaseGameUtil resources into your project's res/ - directory. - - -[6] I think the default error dialogs are ugly. I want to make my own. -How can I do this? - - For convenience, BaseGameActivity and GameHelper show error dialogs - with appropriate error messages for each kind of error. If you want - to disable that behavior and make your own dialog boxes, you can - call GameHelper.setShowErrorDialogs(false) to inhibit the default - dialog boxes, then show your own when you get an onSignInFailed(). - To retrieve details about the failure, you can call - GameHelper.getSignInError(). - - -[7] I need to localize the sign-in failure message (and other error messages -shown by BaseGameActivity and GameHelper). How can I do that? - - Simply translate the string resources found in - res/values/gamehelper_strings.xml into the corresponding locale folders, - as you would any other string resouce in Android. - - diff --git a/README.md b/README.md index 79927d6c..1ccfc9c1 100644 --- a/README.md +++ b/README.md @@ -6,45 +6,26 @@ Copyright (C) 2014 Google Inc. These are the Android samples for Google Play game services. -* **BasicSamples** - a set of basic samples, including a convenience library (BaseGameUtils): +* **ButtonClicker**. Represents the new generation in modern button-clicking excitement. A simple multiplayer game sample that shows how to set up the Google Play real-time multiplayer API, invite friends, automatch, accept invitations, use the waiting room UI, send and receive messages and other multiplayer topics. - * **BaseGameUtils**. Utilities used on all samples, which you can use in your projects too. This is not a stand-alone sample, it's a library project. +* **CollectAllTheStars2**. Demonstrates how to use the Snapshots feature to save game data. The sample signs the user in, synchronizes their data from a named Snapshot, then updates the UI to reflect the game state saved in the Snapshot. - * **ButtonClicker2000**. Represents the new generation in modern button-clicking excitement. A simple multiplayer game sample that shows how to set up the Google Play real-time multiplayer API, invite friends, automatch, accept invitations, use the waiting room UI, send and receive messages and other multiplayer topics. +* **TypeANumber**. Demonstrates how to use leaderboards, achievements, events, and friends. In this exciting game, you type the score you think you deserve. But wait! There is a twist. If you are playing in easy mode, you get the score you requested. However, if you are playing in hard mode, you only get half! (tough game, we know). You can also check how your friends perform in this game by checking out social leaderboards. - * **CollectAllTheStars2**. Demonstrates how to use the Snapshots feature to save game data. The sample signs the user in, synchronizes their data from a named Snapshot, then updates the UI to reflect the game state saved in the Snapshot. +* **SkeletonTbmp** A trivial turn-based-multiplayer game. In this thrilling game, you can invite many friends, then send a shared gamestate string back and forth until someone finishes, cancels, or the second-to-last player leaves. - * **TrivialQuest2**. Demonstrates how to use the Events and Quests features of Google Play Services. The sample presents a sign in button and four buttons to simulate killing monsters in-game. When you click the buttons, an event is -created and sent to Google Play Games to track what the player is doing in game. - - * **TrivialQuest**. The simplest possible single-player game. Shows how to sign in and how to unlock one achievement. Sign-in and click the button to win the game. Are you ready for this epic adventure? - - * **TypeANumber**. Shows leaderboards and achievements. In this exciting game, you type the score you think you deserve. But wait! There is a twist. If you are playing in easy mode, you get the score you requested. However, if you are playing in hard mode, you only get half! (tough game, we know). - - * **SkeletonTbmp** A trivial turn-based-multiplayer game. In this thrilling game, you can invite many friends, then send a shared gamestate string back and forth until someone finishes, cancels, or the second-to-last player leaves. - - * **BeGenerous** Send gifts and game requests to other players of BeGenerous. - - * **SavedGames**. Demonstrates the used of Saved Games (Snapshots) feature and how to migrate data from the older Cloud Save (AppState) service to the newer service. The sample allows the user to save/load data from both Cloud Save and Saved Games. - -**Note:** the samples that have corresponding counterparts for iOS and web (particularly, CollectAllTheStars and TypeANumber) are compatible across the platforms. This means that you can play some levels on CollectAllTheStars on your Android device, and then pick up your iOS device and continue where you left off! For TypeANumber, you will see your achievements and leaderboards on all platforms, and progress obtained on one will be reflected on the others. - -

Frequently Asked Questions

- -If you have questions about the samples (particularly, about *BaseGameActivity* and *GameHelper*), please -take a look at [our FAQ](https://github.com/playgameservices/android-samples/blob/master/FAQ.txt). +> **Warning:** Real-time and turn-based multiplayer services are deprecated as of September 16th, 2019. These services are unavailable for new games. For more information, see [Ending support for multiplayer APIs in Play Games Services](https://support.google.com/googleplay/android-developer/answer/9469745).

How to run a sample

-1. Set up the project in Developer Console. For more info: - - https://developers.google.com/games/services/console/enabling +1. Set up the project in the Developer Console by following [these instructions](https://developers.google.com/games/services/console/enabling). + Note your **package name** and the **application ID** of the project! - Note your package name and the APP ID of the project. - -1. Create leaderboards/achievements as appropriate for the sample (see the ones that the sample needs in its res/values/ids.xml). You can do this automatically by clicking the link below for the sample you want to configure: - 1. [Type a Number](http://playgameservices.github.io/android-basic-samples/config-magic/index.html?sample=typeanumber) - 1. [Trivial Quest](http://playgameservices.github.io/android-basic-samples/config-magic/index.html?sample=trivialquest) +1. For the **Type a Number sample**, you need to create leaderboards/achievements. +(You can see the ones that the sample needs in its [res/values/ids.xml](TypeANumber/src/main/res/values/ids.xml) file.) + You can create them two ways: + 1. Add them via the [Developer console](https://play.google.com/apps/publish/#GameListPlace). + 1. Use [this utility](http://playgameservices.github.io/android-basic-samples/config-magic/index.html?sample=typeanumber), which will automatically create them for you.

Building using Android Studio...

@@ -54,19 +35,20 @@ take a look at [our FAQ](https://github.com/playgameservices/android-samples/blo 1. *Android Support Repository* 1. *Google Repository* 1. Return to Android Studio and select *Open an existing Android Studio project* -1. Select the **BasicSamples** directory +1. Select the **android-basic-samples** directory.

Modify IDs, compile and run

To set up a sample: -1. Change the *application id* in the build.gradle file to your own **package name** (ie - com.example.package.name) +1. Change the *applicationId* in the build.gradle file to your own **package name** (ie - com.example.package.name) (the same one you registered in Developer Console!). You will have to update - the build.gradle file for each sample you want to run. There is no need to + the build.gradle file for *each* sample you want to run. There is no need to edit the AndroidManifest.xml file. 1. In the Developer console, select a resource type (Achievements, Events, Leaderboards) and click "Get Resources". Copy the contents from the console and replace the contents of res/values/ids.xml. + 1. If you are running Android Studio, check the TODO window to see if there are any remaining tasks. 1. Compile and run. **IMPORTANT**: make sure to sign your apk with the same certificate @@ -80,11 +62,11 @@ section), otherwise the server will act as though your project did not exist and return errors like 'Failed to sign in. Please check your network connection and try again.'

Building

-To build the samples after you have applied the changes above, you can use the build/run option in Android Studio, or build directly from the command line if you prefer. +To build the samples after you have applied the changes above, you can use the build/run option in Android Studio, or build directly from the command line if you prefer. **IMPORTANT** Ensure you have set the ANDROID_HOME environment variable. - cd /path/to/BasicSamples + cd /path/to/android-basic-samples export ANDROID_HOME = /path/to/android/sdk ./gradlew build @@ -92,11 +74,9 @@ To build the samples after you have applied the changes above, you can use the b First of all, take a look at our [troubleshooting guide](https://developers.google.com/games/services/android/troubleshooting). Most setup issues can be solved by following this guide. -If your question is not answered by the troubleshooting guide, we encourage you to post your question to [stackoverflow.com](stackoverflow.com). Our team answers questions there reguarly. - -*Samples written by [Bruno Oliveira](http://plus.google.com/+BrunoOliveira) with contributions from [Wolff](http://plus.google.com/+WolffDobson).* Feel free to add us to your circles on Google Plus and pester us to fix stuff that's broken or answer a question on stackoverflow :-) +If your question is not answered by the troubleshooting guide, we encourage you to post your question to [stackoverflow.com](https://stackoverflow.com/questions/tagged/google-play-games). Our team answers questions there regularly. -*Samples written by [Bruno Oliveira](http://plus.google.com/+BrunoOliveira).* Feel free to add me to your circles on Google Plus and pester me to fix anything that's broken or answer a question on stackoverflow! +Samples written by [Bruno Oliveira](https://plus.google.com/102451193315916178828) with contributions from [Wolff](http://plus.google.com/+WolffDobson).* Feel free to add us to your circles on Google Plus and pester us to fix stuff that's broken or answer a question on stackoverflow :-)

Special Thanks

diff --git a/BasicSamples/SkeletonTbmp/build.gradle b/SkeletonTbmp/build.gradle similarity index 85% rename from BasicSamples/SkeletonTbmp/build.gradle rename to SkeletonTbmp/build.gradle index 82ad2eba..261419c4 100644 --- a/BasicSamples/SkeletonTbmp/build.gradle +++ b/SkeletonTbmp/build.gradle @@ -25,8 +25,8 @@ android { } dependencies { - implementation "com.android.support:appcompat-v7:${appcompat_library_version}" - implementation "com.android.support:support-v4:${support_library_version}" + implementation 'androidx.appcompat:appcompat:1.0.0' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation "com.google.android.gms:play-services-games:${gms_library_version}" implementation "com.google.android.gms:play-services-auth:${gms_library_version}" } diff --git a/BasicSamples/SkeletonTbmp/src/main/AndroidManifest.xml b/SkeletonTbmp/src/main/AndroidManifest.xml similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/AndroidManifest.xml rename to SkeletonTbmp/src/main/AndroidManifest.xml diff --git a/BasicSamples/SkeletonTbmp/src/main/java/com/google/example/games/tbmpskeleton/SkeletonActivity.java b/SkeletonTbmp/src/main/java/com/google/example/games/tbmpskeleton/SkeletonActivity.java similarity index 99% rename from BasicSamples/SkeletonTbmp/src/main/java/com/google/example/games/tbmpskeleton/SkeletonActivity.java rename to SkeletonTbmp/src/main/java/com/google/example/games/tbmpskeleton/SkeletonActivity.java index 307af0af..40edb29e 100644 --- a/BasicSamples/SkeletonTbmp/src/main/java/com/google/example/games/tbmpskeleton/SkeletonActivity.java +++ b/SkeletonTbmp/src/main/java/com/google/example/games/tbmpskeleton/SkeletonActivity.java @@ -17,16 +17,18 @@ package com.google.example.games.tbmpskeleton; import android.app.Activity; -import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; import android.util.Log; import android.view.View; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; + import com.google.android.gms.auth.api.signin.GoogleSignIn; import com.google.android.gms.auth.api.signin.GoogleSignInAccount; import com.google.android.gms.auth.api.signin.GoogleSignInClient; @@ -71,7 +73,7 @@ * * @author Wolff (wolff@google.com), 2013 */ -public class SkeletonActivity extends Activity implements +public class SkeletonActivity extends AppCompatActivity implements View.OnClickListener { public static final String TAG = "SkeletonActivity"; diff --git a/BasicSamples/SkeletonTbmp/src/main/java/com/google/example/games/tbmpskeleton/SkeletonTurn.java b/SkeletonTbmp/src/main/java/com/google/example/games/tbmpskeleton/SkeletonTurn.java similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/java/com/google/example/games/tbmpskeleton/SkeletonTurn.java rename to SkeletonTbmp/src/main/java/com/google/example/games/tbmpskeleton/SkeletonTurn.java diff --git a/BasicSamples/SkeletonTbmp/src/main/res/drawable-hdpi/ic_launcher.png b/SkeletonTbmp/src/main/res/drawable-hdpi/ic_launcher.png similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/drawable-hdpi/ic_launcher.png rename to SkeletonTbmp/src/main/res/drawable-hdpi/ic_launcher.png diff --git a/BasicSamples/SkeletonTbmp/src/main/res/drawable-ldpi/ic_launcher.png b/SkeletonTbmp/src/main/res/drawable-ldpi/ic_launcher.png similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/drawable-ldpi/ic_launcher.png rename to SkeletonTbmp/src/main/res/drawable-ldpi/ic_launcher.png diff --git a/BasicSamples/SkeletonTbmp/src/main/res/drawable-mdpi/grey_background_pattern_tile.png b/SkeletonTbmp/src/main/res/drawable-mdpi/grey_background_pattern_tile.png similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/drawable-mdpi/grey_background_pattern_tile.png rename to SkeletonTbmp/src/main/res/drawable-mdpi/grey_background_pattern_tile.png diff --git a/BasicSamples/SkeletonTbmp/src/main/res/drawable-mdpi/ic_launcher.png b/SkeletonTbmp/src/main/res/drawable-mdpi/ic_launcher.png similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/drawable-mdpi/ic_launcher.png rename to SkeletonTbmp/src/main/res/drawable-mdpi/ic_launcher.png diff --git a/BasicSamples/SkeletonTbmp/src/main/res/drawable-xhdpi/button_default.9.png b/SkeletonTbmp/src/main/res/drawable-xhdpi/button_default.9.png similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/drawable-xhdpi/button_default.9.png rename to SkeletonTbmp/src/main/res/drawable-xhdpi/button_default.9.png diff --git a/BasicSamples/SkeletonTbmp/src/main/res/drawable-xhdpi/button_focused.9.png b/SkeletonTbmp/src/main/res/drawable-xhdpi/button_focused.9.png similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/drawable-xhdpi/button_focused.9.png rename to SkeletonTbmp/src/main/res/drawable-xhdpi/button_focused.9.png diff --git a/BasicSamples/SkeletonTbmp/src/main/res/drawable-xhdpi/button_pressed.9.png b/SkeletonTbmp/src/main/res/drawable-xhdpi/button_pressed.9.png similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/drawable-xhdpi/button_pressed.9.png rename to SkeletonTbmp/src/main/res/drawable-xhdpi/button_pressed.9.png diff --git a/BasicSamples/SkeletonTbmp/src/main/res/drawable-xhdpi/grey_background_pattern_tile.png b/SkeletonTbmp/src/main/res/drawable-xhdpi/grey_background_pattern_tile.png similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/drawable-xhdpi/grey_background_pattern_tile.png rename to SkeletonTbmp/src/main/res/drawable-xhdpi/grey_background_pattern_tile.png diff --git a/BasicSamples/SkeletonTbmp/src/main/res/drawable-xhdpi/ic_launcher.png b/SkeletonTbmp/src/main/res/drawable-xhdpi/ic_launcher.png similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/drawable-xhdpi/ic_launcher.png rename to SkeletonTbmp/src/main/res/drawable-xhdpi/ic_launcher.png diff --git a/BasicSamples/SkeletonTbmp/src/main/res/drawable-xxhdpi/ic_launcher.png b/SkeletonTbmp/src/main/res/drawable-xxhdpi/ic_launcher.png similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/drawable-xxhdpi/ic_launcher.png rename to SkeletonTbmp/src/main/res/drawable-xxhdpi/ic_launcher.png diff --git a/BasicSamples/SkeletonTbmp/src/main/res/drawable/button.xml b/SkeletonTbmp/src/main/res/drawable/button.xml similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/drawable/button.xml rename to SkeletonTbmp/src/main/res/drawable/button.xml diff --git a/BasicSamples/SkeletonTbmp/src/main/res/drawable/grey_background_pattern.xml b/SkeletonTbmp/src/main/res/drawable/grey_background_pattern.xml similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/drawable/grey_background_pattern.xml rename to SkeletonTbmp/src/main/res/drawable/grey_background_pattern.xml diff --git a/BasicSamples/SkeletonTbmp/src/main/res/layout/activity_main.xml b/SkeletonTbmp/src/main/res/layout/activity_main.xml similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/layout/activity_main.xml rename to SkeletonTbmp/src/main/res/layout/activity_main.xml diff --git a/BasicSamples/SkeletonTbmp/src/main/res/values-sw600dp/dimens.xml b/SkeletonTbmp/src/main/res/values-sw600dp/dimens.xml similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/values-sw600dp/dimens.xml rename to SkeletonTbmp/src/main/res/values-sw600dp/dimens.xml diff --git a/BasicSamples/SkeletonTbmp/src/main/res/values-sw720dp-land/dimens.xml b/SkeletonTbmp/src/main/res/values-sw720dp-land/dimens.xml similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/values-sw720dp-land/dimens.xml rename to SkeletonTbmp/src/main/res/values-sw720dp-land/dimens.xml diff --git a/BasicSamples/SkeletonTbmp/src/main/res/values-v11/styles.xml b/SkeletonTbmp/src/main/res/values-v11/styles.xml similarity index 79% rename from BasicSamples/SkeletonTbmp/src/main/res/values-v11/styles.xml rename to SkeletonTbmp/src/main/res/values-v11/styles.xml index 3c02242a..a4a95bc4 100644 --- a/BasicSamples/SkeletonTbmp/src/main/res/values-v11/styles.xml +++ b/SkeletonTbmp/src/main/res/values-v11/styles.xml @@ -4,7 +4,7 @@ Base application theme for API 11+. This theme completely replaces AppBaseTheme from res/values/styles.xml on API 11+ devices. --> - diff --git a/BasicSamples/SkeletonTbmp/src/main/res/values-v14/styles.xml b/SkeletonTbmp/src/main/res/values-v14/styles.xml similarity index 79% rename from BasicSamples/SkeletonTbmp/src/main/res/values-v14/styles.xml rename to SkeletonTbmp/src/main/res/values-v14/styles.xml index a91fd037..664f4f16 100644 --- a/BasicSamples/SkeletonTbmp/src/main/res/values-v14/styles.xml +++ b/SkeletonTbmp/src/main/res/values-v14/styles.xml @@ -5,7 +5,7 @@ AppBaseTheme from BOTH res/values/styles.xml and res/values-v11/styles.xml on API 14+ devices. --> - diff --git a/BasicSamples/SkeletonTbmp/src/main/res/values-v16/styles.xml b/SkeletonTbmp/src/main/res/values-v16/styles.xml similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/values-v16/styles.xml rename to SkeletonTbmp/src/main/res/values-v16/styles.xml diff --git a/BasicSamples/SkeletonTbmp/src/main/res/values/dimens.xml b/SkeletonTbmp/src/main/res/values/dimens.xml similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/values/dimens.xml rename to SkeletonTbmp/src/main/res/values/dimens.xml diff --git a/BasicSamples/SkeletonTbmp/src/main/res/values/ids.xml b/SkeletonTbmp/src/main/res/values/ids.xml similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/values/ids.xml rename to SkeletonTbmp/src/main/res/values/ids.xml diff --git a/BasicSamples/SkeletonTbmp/src/main/res/values/strings.xml b/SkeletonTbmp/src/main/res/values/strings.xml similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/values/strings.xml rename to SkeletonTbmp/src/main/res/values/strings.xml diff --git a/BasicSamples/SkeletonTbmp/src/main/res/values/styles.xml b/SkeletonTbmp/src/main/res/values/styles.xml similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/values/styles.xml rename to SkeletonTbmp/src/main/res/values/styles.xml diff --git a/BasicSamples/SkeletonTbmp/src/main/res/values/tbmp_helper_strings.xml b/SkeletonTbmp/src/main/res/values/tbmp_helper_strings.xml similarity index 100% rename from BasicSamples/SkeletonTbmp/src/main/res/values/tbmp_helper_strings.xml rename to SkeletonTbmp/src/main/res/values/tbmp_helper_strings.xml diff --git a/BasicSamples/TypeANumber/build.gradle b/TypeANumber/build.gradle similarity index 68% rename from BasicSamples/TypeANumber/build.gradle rename to TypeANumber/build.gradle index cfbc3a59..0f516a0b 100644 --- a/BasicSamples/TypeANumber/build.gradle +++ b/TypeANumber/build.gradle @@ -26,9 +26,12 @@ android { } dependencies { - implementation "com.android.support:appcompat-v7:${appcompat_library_version}" - implementation "com.android.support:support-v4:${support_library_version}" - implementation "com.google.android.gms:play-services-games:${gms_library_version}" + implementation 'androidx.appcompat:appcompat:1.3.0-alpha01' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation "androidx.activity:activity:1.2.0-alpha08" + implementation "androidx.activity:activity-ktx:1.2.0-alpha03" + implementation "androidx.fragment:fragment:1.3.0-alpha08" + implementation "com.google.android.gms:play-services-games:20.0.1" implementation "com.google.android.gms:play-services-auth:${gms_library_version}" } diff --git a/BasicSamples/TypeANumber/src/main/AndroidManifest.xml b/TypeANumber/src/main/AndroidManifest.xml similarity index 100% rename from BasicSamples/TypeANumber/src/main/AndroidManifest.xml rename to TypeANumber/src/main/AndroidManifest.xml diff --git a/TypeANumber/src/main/java/com/google/example/games/tanc/FriendsFragment.java b/TypeANumber/src/main/java/com/google/example/games/tanc/FriendsFragment.java new file mode 100644 index 00000000..5cd5b601 --- /dev/null +++ b/TypeANumber/src/main/java/com/google/example/games/tanc/FriendsFragment.java @@ -0,0 +1,188 @@ +package com.google.example.games.tanc; + +import static com.google.example.games.tanc.MainActivity.RC_FRIEND_PROFILE; + +import android.app.Activity; +import android.app.PendingIntent; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageButton; +import android.widget.ListView; +import android.widget.TextView; +import androidx.activity.result.ActivityResult; +import androidx.activity.result.ActivityResultCallback; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.IntentSenderRequest; +import androidx.activity.result.contract.ActivityResultContracts; +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import com.google.android.gms.common.api.ResolvableApiException; +import com.google.android.gms.common.data.DataBufferUtils; +import com.google.android.gms.games.AnnotatedData; +import com.google.android.gms.games.Player; +import com.google.android.gms.games.PlayerBuffer; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.OnSuccessListener; +import com.google.android.gms.tasks.Task; +import java.util.ArrayList; + +/** Fragment that shows the list of friends. */ +public class FriendsFragment extends Fragment { + private static final String TAG = "FriendsFragment"; + private static final int PAGE_SIZE = 200; + + interface Listener { + // called when the user presses the `Back` button + void onBackButtonClicked(); + } + + private View mView; + private ListView mListView; + private View mSpinner; + private ArrayAdapter mAdapter; + private MainActivity mActivity; + private ActivityResultLauncher resolveLauncherFriendsConsent; + private ActivityResultLauncher resolveLauncherCompareProfile; + + private Listener mListener = null; + private OnCompleteListener> onCompleteListener = + new OnCompleteListener>() { + @Override + public void onComplete(@NonNull Task> task) { + if (task.isSuccessful()) { + if (task.getResult() == null) { + mListener.onBackButtonClicked(); + } + PlayerBuffer playerBuffer = task.getResult().get(); + try { + if (DataBufferUtils.hasNextPage(playerBuffer)) { + mActivity + .getPlayersClient() + .loadMoreFriends(PAGE_SIZE) + .addOnCompleteListener(mActivity, onCompleteListener); + } else { + LayoutInflater inflater = LayoutInflater.from(getContext()); + mAdapter = getAdapter(playerBuffer, inflater); + mListView.setAdapter(mAdapter); + mSpinner.setVisibility(View.GONE); + mListView.setVisibility(View.VISIBLE); + } + } finally { + playerBuffer.release(); + } + } else { + Log.e(TAG, "Getting friends failed with exception: " + task.getException()); + try { + if (task.getException() instanceof ResolvableApiException) { + PendingIntent pendingIntent = + ((ResolvableApiException) task.getException()).getResolution(); + resolveLauncherFriendsConsent.launch( + new IntentSenderRequest.Builder(pendingIntent).build()); + } + } catch (Exception e) { + Log.e(TAG, "Getting consent failed with exception: " + e); + mListener.onBackButtonClicked(); + } + } + } + }; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { + mView = inflater.inflate(R.layout.friends_screen, container, /* attachToRoot= */ false); + mListView = mView.findViewById(R.id.load_friends_game_list); + mSpinner = mView.findViewById(R.id.progress_bar); + mActivity = (MainActivity) getActivity(); + mView + .findViewById(R.id.back_button) + .setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View view) { + mListener.onBackButtonClicked(); + } + }); + resolveLauncherFriendsConsent = + registerForActivityResult( + new ActivityResultContracts.StartIntentSenderForResult(), + new ActivityResultCallback() { + @Override + public void onActivityResult(ActivityResult result) { + if (result.getResultCode() == Activity.RESULT_OK) { + refreshFriends(); + } else { + mListener.onBackButtonClicked(); + } + } + }); + resolveLauncherCompareProfile = + registerForActivityResult( + new ActivityResultContracts.StartActivityForResult(), + new ActivityResultCallback() { + @Override + public void onActivityResult(ActivityResult result) { + if (result.getResultCode() == Activity.RESULT_OK) { + refreshFriends(); + } + } + }); + refreshFriends(); + return mView; + } + + void setListener(Listener listener) { + mListener = listener; + } + + @NonNull + private ArrayAdapter getAdapter( + PlayerBuffer playerBuffer, final LayoutInflater inflater) { + ArrayList players = new ArrayList<>(); + for (int i = 0; i < playerBuffer.getCount(); i++) { + players.add(playerBuffer.get(i).freeze()); + } + return new ArrayAdapter(mActivity, R.layout.friends_row, players) { + @Override + public View getView(int position, View convertView, ViewGroup viewGroup) { + View rowView = inflater.inflate(R.layout.friends_row, viewGroup, /* attachToRoot= */ false); + final Player player = getItem(position); + TextView textView = rowView.findViewById(R.id.friend_name); + textView.setText(player.getDisplayName()); + ImageButton showProfileButton = rowView.findViewById(R.id.show_profile); + showProfileButton.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + mActivity + .getPlayersClient() + .getCompareProfileIntentWithAlternativeNameHints( + player.getPlayerId(), player.getDisplayName(), mActivity.getDisplayName()) + .addOnSuccessListener( + mActivity, + new OnSuccessListener() { + @Override + public void onSuccess(Intent intent) { + resolveLauncherCompareProfile.launch(intent); + } + }); + } + }); + return rowView; + } + }; + } + + void refreshFriends() { + mListView.setAdapter(null); + mSpinner.setVisibility(View.VISIBLE); + mActivity + .getPlayersClient() + .loadFriends(PAGE_SIZE, /* forceReload= */ false) + .addOnCompleteListener(mActivity, onCompleteListener); + } +} \ No newline at end of file diff --git a/BasicSamples/TypeANumber/src/main/java/com/google/example/games/tanc/GameplayFragment.java b/TypeANumber/src/main/java/com/google/example/games/tanc/GameplayFragment.java similarity index 98% rename from BasicSamples/TypeANumber/src/main/java/com/google/example/games/tanc/GameplayFragment.java rename to TypeANumber/src/main/java/com/google/example/games/tanc/GameplayFragment.java index 2c58b734..6102f582 100644 --- a/BasicSamples/TypeANumber/src/main/java/com/google/example/games/tanc/GameplayFragment.java +++ b/TypeANumber/src/main/java/com/google/example/games/tanc/GameplayFragment.java @@ -17,14 +17,13 @@ package com.google.example.games.tanc; import android.os.Bundle; -import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; - +import androidx.fragment.app.Fragment; import java.util.Locale; /** diff --git a/BasicSamples/TypeANumber/src/main/java/com/google/example/games/tanc/MainActivity.java b/TypeANumber/src/main/java/com/google/example/games/tanc/MainActivity.java similarity index 91% rename from BasicSamples/TypeANumber/src/main/java/com/google/example/games/tanc/MainActivity.java rename to TypeANumber/src/main/java/com/google/example/games/tanc/MainActivity.java index 75b94023..0bea89fa 100644 --- a/BasicSamples/TypeANumber/src/main/java/com/google/example/games/tanc/MainActivity.java +++ b/TypeANumber/src/main/java/com/google/example/games/tanc/MainActivity.java @@ -16,15 +16,15 @@ package com.google.example.games.tanc; -import android.app.AlertDialog; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; import android.util.Log; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import com.google.android.gms.auth.api.signin.GoogleSignIn; import com.google.android.gms.auth.api.signin.GoogleSignInAccount; import com.google.android.gms.auth.api.signin.GoogleSignInClient; @@ -46,28 +46,30 @@ /** * Our main activity for the game. - *

- * IMPORTANT: Before attempting to run this sample, please change + * + *

IMPORTANT: Before attempting to run this sample, please change * the package name to your own package name (not com.android.*) and * replace the IDs on res/values/ids.xml by your own IDs (you must * create a game in the developer console to get those IDs). - *

- * This is a very simple game where the user selects "easy mode" or + * + *

This is a very simple game where the user selects "easy mode" or * "hard mode" and then the "gameplay" consists of inputting the - * desired score (0 to 9999). In easy mode, you get the score you - * request; in hard mode, you get half. + * desired score (0 to 9999). In easy mode, you get the score + * you request; in hard mode, you get half. * * @author Bruno Oliveira */ public class MainActivity extends FragmentActivity implements MainMenuFragment.Listener, GameplayFragment.Callback, - WinFragment.Listener { + WinFragment.Listener, + FriendsFragment.Listener { // Fragments private MainMenuFragment mMainMenuFragment; private GameplayFragment mGameplayFragment; private WinFragment mWinFragment; + public FriendsFragment mFriendsFragment; // Client used to sign in with Google APIs private GoogleSignInClient mGoogleSignInClient; @@ -82,12 +84,17 @@ public class MainActivity extends FragmentActivity implements private static final int RC_UNUSED = 5001; private static final int RC_SIGN_IN = 9001; + static final int RC_FRIEND_PROFILE = 9002; + // tag for debug logging private static final String TAG = "TanC"; // playing on hard mode? private boolean mHardMode = false; + // The diplay name of the signed in user. + private String mDisplayName = ""; + // achievements and scores we're pending to push to the cloud // (waiting for the user to sign in, for instance) private final AccomplishmentsOutbox mOutbox = new AccomplishmentsOutbox(); @@ -106,11 +113,13 @@ public void onCreate(Bundle savedInstanceState) { mMainMenuFragment = new MainMenuFragment(); mGameplayFragment = new GameplayFragment(); mWinFragment = new WinFragment(); + mFriendsFragment = new FriendsFragment(); // Set the listeners and callbacks of fragment events. mMainMenuFragment.setListener(this); mGameplayFragment.setCallback(this); mWinFragment.setListener(this); + mFriendsFragment.setListener(this); // Add initial Main Menu fragment. // IMPORTANT: if this Activity supported rotation, we'd have to be @@ -120,7 +129,6 @@ public void onCreate(Bundle savedInstanceState) { // we don't deal with that for code simplicity. getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, mMainMenuFragment).commit(); - checkPlaceholderIds(); } @@ -225,7 +233,7 @@ public void onComplete(@NonNull Task task) { onDisconnected(); } } - }); + }); } private void startSignInIntent() { @@ -259,7 +267,7 @@ public void onComplete(@NonNull Task task) { onDisconnected(); } - }); + }); } @Override @@ -277,10 +285,10 @@ public void onSuccess(Intent intent) { } }) .addOnFailureListener(new OnFailureListener() { - @Override - public void onFailure(@NonNull Exception e) { - handleException(e, getString(R.string.achievements_exception)); - } + @Override + public void onFailure(@NonNull Exception e) { + handleException(e, getString(R.string.achievements_exception)); + } }); } @@ -429,6 +437,7 @@ private void pushAccomplishments() { if (mOutbox.mBoredSteps > 0) { mAchievementsClient.increment(getString(R.string.achievement_really_bored), mOutbox.mBoredSteps); + mAchievementsClient.increment(getString(R.string.achievement_bored), mOutbox.mBoredSteps); mOutbox.mBoredSteps = 0; @@ -445,6 +454,14 @@ private void pushAccomplishments() { } } + public PlayersClient getPlayersClient() { + return mPlayersClient; + } + + public String getDisplayName() { + return mDisplayName; + } + /** * Update leaderboards with the user's score. * @@ -467,8 +484,7 @@ public void onWinScreenDismissed() { protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (requestCode == RC_SIGN_IN) { - Task task = - GoogleSignIn.getSignedInAccountFromIntent(intent); + Task task = GoogleSignIn.getSignedInAccountFromIntent(intent); try { GoogleSignInAccount account = task.getResult(ApiException.class); @@ -516,16 +532,16 @@ public void onComplete(@NonNull Task task) { handleException(e, getString(R.string.players_exception)); displayName = "???"; } + mDisplayName = displayName; mMainMenuFragment.setGreeting("Hello, " + displayName); } }); - // if we have accomplishments to push, push them if (!mOutbox.isEmpty()) { pushAccomplishments(); - Toast.makeText(this, getString(R.string.your_progress_will_be_uploaded), - Toast.LENGTH_LONG).show(); + Toast.makeText(this, + getString(R.string.your_progress_will_be_uploaded), Toast.LENGTH_LONG).show(); } loadAndPrintEvents(); @@ -557,6 +573,16 @@ public void onSignOutButtonClicked() { signOut(); } + @Override + public void onShowFriendsButtonClicked() { + switchToFragment(mFriendsFragment); + } + + @Override + public void onBackButtonClicked() { + switchToFragment(mMainMenuFragment); + } + private class AccomplishmentsOutbox { boolean mPrimeAchievement = false; boolean mHumbleAchievement = false; @@ -567,9 +593,9 @@ private class AccomplishmentsOutbox { int mHardModeScore = -1; boolean isEmpty() { - return !mPrimeAchievement && !mHumbleAchievement && !mLeetAchievement && - !mArrogantAchievement && mBoredSteps == 0 && mEasyModeScore < 0 && - mHardModeScore < 0; + return !mPrimeAchievement && !mHumbleAchievement && !mLeetAchievement + && !mArrogantAchievement && mBoredSteps == 0 && mEasyModeScore < 0 + && mHardModeScore < 0; } } diff --git a/BasicSamples/TypeANumber/src/main/java/com/google/example/games/tanc/MainMenuFragment.java b/TypeANumber/src/main/java/com/google/example/games/tanc/MainMenuFragment.java similarity index 90% rename from BasicSamples/TypeANumber/src/main/java/com/google/example/games/tanc/MainMenuFragment.java rename to TypeANumber/src/main/java/com/google/example/games/tanc/MainMenuFragment.java index 9cd7b524..ac7b2ba8 100644 --- a/BasicSamples/TypeANumber/src/main/java/com/google/example/games/tanc/MainMenuFragment.java +++ b/TypeANumber/src/main/java/com/google/example/games/tanc/MainMenuFragment.java @@ -16,12 +16,12 @@ package com.google.example.games.tanc; import android.os.Bundle; -import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.TextView; +import androidx.fragment.app.Fragment; /** * Fragment with the main menu for the game. The main menu allows the player @@ -37,6 +37,7 @@ public class MainMenuFragment extends Fragment implements OnClickListener { private View mSignOutBarView; private View mShowAchievementsButton; private View mShowLeaderboardsButton; + private View mShowFriendsButton; interface Listener { // called when the user presses the `Easy` or `Okay` button; will pass in which via `hardMode` @@ -53,6 +54,9 @@ interface Listener { // called when the user presses the `Sign Out` button void onSignOutButtonClicked(); + + // called when the user presses the `Friends` button + void onShowFriendsButtonClicked(); } private Listener mListener = null; @@ -71,7 +75,8 @@ public View onCreateView(LayoutInflater inflater, R.id.show_achievements_button, R.id.show_leaderboards_button, R.id.sign_in_button, - R.id.sign_out_button + R.id.sign_out_button, + R.id.show_friends_button }; for (int clickableId : clickableIds) { @@ -81,6 +86,7 @@ public View onCreateView(LayoutInflater inflater, // cache views mShowAchievementsButton = view.findViewById(R.id.show_achievements_button); mShowLeaderboardsButton = view.findViewById(R.id.show_leaderboards_button); + mShowFriendsButton = view.findViewById(R.id.show_friends_button); mGreetingTextView = view.findViewById(R.id.text_greeting); mSignInBarView = view.findViewById(R.id.sign_in_bar); @@ -104,6 +110,7 @@ private void updateUI() { mGreetingTextView.setText(mGreeting); mShowAchievementsButton.setEnabled(!mShowSignInButton); mShowLeaderboardsButton.setEnabled(!mShowSignInButton); + mShowFriendsButton.setEnabled(!mShowSignInButton); mSignInBarView.setVisibility(mShowSignInButton ? View.VISIBLE : View.GONE); mSignOutBarView.setVisibility(mShowSignInButton ? View.GONE : View.VISIBLE); } @@ -123,6 +130,9 @@ public void onClick(View view) { case R.id.show_leaderboards_button: mListener.onShowLeaderboardsRequested(); break; + case R.id.show_friends_button: + mListener.onShowFriendsButtonClicked(); + break; case R.id.sign_in_button: mListener.onSignInButtonClicked(); break; diff --git a/BasicSamples/TypeANumber/src/main/java/com/google/example/games/tanc/WinFragment.java b/TypeANumber/src/main/java/com/google/example/games/tanc/WinFragment.java similarity index 98% rename from BasicSamples/TypeANumber/src/main/java/com/google/example/games/tanc/WinFragment.java rename to TypeANumber/src/main/java/com/google/example/games/tanc/WinFragment.java index 860eadaf..1d4e03ba 100644 --- a/BasicSamples/TypeANumber/src/main/java/com/google/example/games/tanc/WinFragment.java +++ b/TypeANumber/src/main/java/com/google/example/games/tanc/WinFragment.java @@ -17,12 +17,12 @@ package com.google.example.games.tanc; import android.os.Bundle; -import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.TextView; +import androidx.fragment.app.Fragment; /** * Fragment that shows the 'You won' message. Apart from congratulating the user @@ -123,4 +123,4 @@ public void setShowSignInButton(boolean showSignIn) { mShowSignIn = showSignIn; updateUI(); } -} +} \ No newline at end of file diff --git a/BasicSamples/TypeANumber/src/main/res/drawable-hdpi/ic_launcher.png b/TypeANumber/src/main/res/drawable-hdpi/ic_launcher.png similarity index 100% rename from BasicSamples/TypeANumber/src/main/res/drawable-hdpi/ic_launcher.png rename to TypeANumber/src/main/res/drawable-hdpi/ic_launcher.png diff --git a/TypeANumber/src/main/res/drawable-hdpi/pgs_signed_in_friend.png b/TypeANumber/src/main/res/drawable-hdpi/pgs_signed_in_friend.png new file mode 100644 index 00000000..ef8a5084 Binary files /dev/null and b/TypeANumber/src/main/res/drawable-hdpi/pgs_signed_in_friend.png differ diff --git a/BasicSamples/TypeANumber/src/main/res/drawable-ldpi/ic_launcher.png b/TypeANumber/src/main/res/drawable-ldpi/ic_launcher.png similarity index 100% rename from BasicSamples/TypeANumber/src/main/res/drawable-ldpi/ic_launcher.png rename to TypeANumber/src/main/res/drawable-ldpi/ic_launcher.png diff --git a/TypeANumber/src/main/res/drawable-ldpi/pgs_signed_in_friend.png b/TypeANumber/src/main/res/drawable-ldpi/pgs_signed_in_friend.png new file mode 100644 index 00000000..fd2c6063 Binary files /dev/null and b/TypeANumber/src/main/res/drawable-ldpi/pgs_signed_in_friend.png differ diff --git a/BasicSamples/TypeANumber/src/main/res/drawable-mdpi/ic_launcher.png b/TypeANumber/src/main/res/drawable-mdpi/ic_launcher.png similarity index 100% rename from BasicSamples/TypeANumber/src/main/res/drawable-mdpi/ic_launcher.png rename to TypeANumber/src/main/res/drawable-mdpi/ic_launcher.png diff --git a/TypeANumber/src/main/res/drawable-mdpi/pgs_signed_in_friend.png b/TypeANumber/src/main/res/drawable-mdpi/pgs_signed_in_friend.png new file mode 100644 index 00000000..299b359d Binary files /dev/null and b/TypeANumber/src/main/res/drawable-mdpi/pgs_signed_in_friend.png differ diff --git a/BasicSamples/TypeANumber/src/main/res/drawable-xhdpi/ic_launcher.png b/TypeANumber/src/main/res/drawable-xhdpi/ic_launcher.png similarity index 100% rename from BasicSamples/TypeANumber/src/main/res/drawable-xhdpi/ic_launcher.png rename to TypeANumber/src/main/res/drawable-xhdpi/ic_launcher.png diff --git a/TypeANumber/src/main/res/drawable-xhdpi/pgs_signed_in_friend.png b/TypeANumber/src/main/res/drawable-xhdpi/pgs_signed_in_friend.png new file mode 100644 index 00000000..7a953a8c Binary files /dev/null and b/TypeANumber/src/main/res/drawable-xhdpi/pgs_signed_in_friend.png differ diff --git a/BasicSamples/TypeANumber/src/main/res/drawable-xxhdpi/ic_launcher.png b/TypeANumber/src/main/res/drawable-xxhdpi/ic_launcher.png similarity index 100% rename from BasicSamples/TypeANumber/src/main/res/drawable-xxhdpi/ic_launcher.png rename to TypeANumber/src/main/res/drawable-xxhdpi/ic_launcher.png diff --git a/BasicSamples/TypeANumber/src/main/res/layout/activity_main.xml b/TypeANumber/src/main/res/layout/activity_main.xml similarity index 100% rename from BasicSamples/TypeANumber/src/main/res/layout/activity_main.xml rename to TypeANumber/src/main/res/layout/activity_main.xml diff --git a/BasicSamples/TypeANumber/src/main/res/layout/fragment_gameplay.xml b/TypeANumber/src/main/res/layout/fragment_gameplay.xml similarity index 100% rename from BasicSamples/TypeANumber/src/main/res/layout/fragment_gameplay.xml rename to TypeANumber/src/main/res/layout/fragment_gameplay.xml diff --git a/BasicSamples/TypeANumber/src/main/res/layout/fragment_mainmenu.xml b/TypeANumber/src/main/res/layout/fragment_mainmenu.xml similarity index 95% rename from BasicSamples/TypeANumber/src/main/res/layout/fragment_mainmenu.xml rename to TypeANumber/src/main/res/layout/fragment_mainmenu.xml index 0bae8ccd..1a427642 100644 --- a/BasicSamples/TypeANumber/src/main/res/layout/fragment_mainmenu.xml +++ b/TypeANumber/src/main/res/layout/fragment_mainmenu.xml @@ -86,7 +86,13 @@