Cloud save: working save/load dialog
This commit is contained in:
@@ -23,6 +23,8 @@ import android.graphics.BitmapFactory;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.util.concurrent.Semaphore;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import com.google.android.gms.common.api.GoogleApiClient;
|
import com.google.android.gms.common.api.GoogleApiClient;
|
||||||
import com.google.android.gms.common.api.ResultCallback;
|
import com.google.android.gms.common.api.ResultCallback;
|
||||||
@@ -45,12 +47,15 @@ public class CloudSave implements GameHelper.GameHelperListener {
|
|||||||
|
|
||||||
MainActivity parent;
|
MainActivity parent;
|
||||||
|
|
||||||
|
Semaphore semaphore;
|
||||||
|
|
||||||
// ===== Public API =====
|
// ===== Public API =====
|
||||||
|
|
||||||
public CloudSave(MainActivity p)
|
public CloudSave(MainActivity p)
|
||||||
{
|
{
|
||||||
Log.i("SDL", "CloudSave: initializing");
|
Log.i("SDL", "CloudSave: initializing");
|
||||||
parent = p;
|
parent = p;
|
||||||
|
semaphore = new Semaphore(0);
|
||||||
mHelper = new GameHelper(parent, GameHelper.CLIENT_SNAPSHOT);
|
mHelper = new GameHelper(parent, GameHelper.CLIENT_SNAPSHOT);
|
||||||
mHelper.setMaxAutoSignInAttempts(0);
|
mHelper.setMaxAutoSignInAttempts(0);
|
||||||
mHelper.setup(this);
|
mHelper.setup(this);
|
||||||
@@ -66,9 +71,29 @@ public class CloudSave implements GameHelper.GameHelperListener {
|
|||||||
mHelper.onStop();
|
mHelper.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onActivityResult(int request, int response, Intent data)
|
SnapshotMetadata crapshotMetadata = null;
|
||||||
|
boolean createNewSave = false;
|
||||||
|
public void onActivityResult(int request, int response, Intent intent)
|
||||||
{
|
{
|
||||||
mHelper.onActivityResult(request, response, data);
|
Log.d("SDL", "CloudSave: onActivityResult() response " + response + " intent " + (intent != null));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (intent != null && intent.hasExtra(Snapshots.EXTRA_SNAPSHOT_NEW))
|
||||||
|
{
|
||||||
|
createNewSave = true;
|
||||||
|
}
|
||||||
|
if (intent != null && intent.hasExtra(Snapshots.EXTRA_SNAPSHOT_METADATA))
|
||||||
|
{
|
||||||
|
crapshotMetadata = (SnapshotMetadata)
|
||||||
|
intent.getParcelableExtra(Snapshots.EXTRA_SNAPSHOT_METADATA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.w("SDL", "CloudSave: onActivityResult(): error: " + e.toString());
|
||||||
|
}
|
||||||
|
//mHelper.onActivityResult(request, response, data);
|
||||||
|
semaphore.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean save(String filename, String saveId, String dialogTitle, String description, String imageFile, long playedTimeMs)
|
public synchronized boolean save(String filename, String saveId, String dialogTitle, String description, String imageFile, long playedTimeMs)
|
||||||
@@ -87,8 +112,27 @@ public class CloudSave implements GameHelper.GameHelperListener {
|
|||||||
{
|
{
|
||||||
if( saveId == null || saveId.length() == 0 )
|
if( saveId == null || saveId.length() == 0 )
|
||||||
{
|
{
|
||||||
Log.i("SDL", "CloudSave: save: user dialog is not supported yet");
|
// Show dialog to the user
|
||||||
return false;
|
// Specifying Snapshots.DISPLAY_LIMIT_NONE will cause the dialog to hide "New game" button for some reason
|
||||||
|
final Intent snapshotIntent = Games.Snapshots.getSelectSnapshotIntent(getApiClient(), dialogTitle, true, true, 1000);
|
||||||
|
semaphore.drainPermits();
|
||||||
|
crapshotMetadata = null;
|
||||||
|
createNewSave = false;
|
||||||
|
parent.runOnUiThread(new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
parent.startActivityForResult(snapshotIntent, 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
semaphore.acquireUninterruptibly();
|
||||||
|
Log.d("SDL", "CloudSave: save: user selected: " + (crapshotMetadata == null ? "null" : crapshotMetadata.getUniqueName()) + " new " + createNewSave);
|
||||||
|
if( createNewSave )
|
||||||
|
saveId = "" + System.currentTimeMillis() + "-" + new Random().nextInt(100000);
|
||||||
|
else if( crapshotMetadata != null )
|
||||||
|
saveId = crapshotMetadata.getUniqueName();
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Snapshots.OpenSnapshotResult result = Games.Snapshots.open(getApiClient(), saveId, true).await();
|
Snapshots.OpenSnapshotResult result = Games.Snapshots.open(getApiClient(), saveId, true).await();
|
||||||
@@ -141,8 +185,23 @@ public class CloudSave implements GameHelper.GameHelperListener {
|
|||||||
{
|
{
|
||||||
if( saveId == null || saveId.length() == 0 )
|
if( saveId == null || saveId.length() == 0 )
|
||||||
{
|
{
|
||||||
Log.i("SDL", "CloudSave: load: user dialog is not supported yet");
|
// Show dialog to the user
|
||||||
return false;
|
final Intent snapshotIntent = Games.Snapshots.getSelectSnapshotIntent(getApiClient(), dialogTitle, false, true, 1000);
|
||||||
|
semaphore.drainPermits();
|
||||||
|
crapshotMetadata = null;
|
||||||
|
createNewSave = false;
|
||||||
|
parent.runOnUiThread(new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
parent.startActivityForResult(snapshotIntent, 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
semaphore.acquireUninterruptibly();
|
||||||
|
Log.d("SDL", "CloudSave: load: user selected: " + (crapshotMetadata == null ? "null" : crapshotMetadata.getUniqueName()) + " new " + createNewSave);
|
||||||
|
if( crapshotMetadata == null )
|
||||||
|
return false;
|
||||||
|
saveId = crapshotMetadata.getUniqueName();
|
||||||
}
|
}
|
||||||
|
|
||||||
Snapshots.OpenSnapshotResult result = Games.Snapshots.open(getApiClient(), saveId, false).await();
|
Snapshots.OpenSnapshotResult result = Games.Snapshots.open(getApiClient(), saveId, false).await();
|
||||||
@@ -175,12 +234,9 @@ public class CloudSave implements GameHelper.GameHelperListener {
|
|||||||
signInSucceeded = false;
|
signInSucceeded = false;
|
||||||
signInFailed = false;
|
signInFailed = false;
|
||||||
Log.i("SDL", "CloudSave: beginUserInitiatedSignIn()");
|
Log.i("SDL", "CloudSave: beginUserInitiatedSignIn()");
|
||||||
|
semaphore.drainPermits();
|
||||||
beginUserInitiatedSignIn();
|
beginUserInitiatedSignIn();
|
||||||
Log.i("SDL", "CloudSave: beginUserInitiatedSignIn() exit");
|
semaphore.acquireUninterruptibly();
|
||||||
while (!signInSucceeded && !signInFailed)
|
|
||||||
{
|
|
||||||
try { Thread.sleep(300); } catch( Exception e ) {}
|
|
||||||
}
|
|
||||||
return signInSucceeded;
|
return signInSucceeded;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -190,11 +246,13 @@ public class CloudSave implements GameHelper.GameHelperListener {
|
|||||||
public void onSignInSucceeded() {
|
public void onSignInSucceeded() {
|
||||||
Log.i("SDL", "CloudSave: onSignInSucceeded()");
|
Log.i("SDL", "CloudSave: onSignInSucceeded()");
|
||||||
signInSucceeded = true;
|
signInSucceeded = true;
|
||||||
|
semaphore.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSignInFailed() {
|
public void onSignInFailed() {
|
||||||
Log.i("SDL", "CloudSave: onSignInFailed()");
|
Log.i("SDL", "CloudSave: onSignInFailed()");
|
||||||
signInFailed = true;
|
signInFailed = true;
|
||||||
|
semaphore.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Snapshot processSnapshotOpenResult(Snapshots.OpenSnapshotResult result, int retryCount)
|
public Snapshot processSnapshotOpenResult(Snapshots.OpenSnapshotResult result, int retryCount)
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ AppName="Biniax2"
|
|||||||
AppFullName=com.biniax.sdl
|
AppFullName=com.biniax.sdl
|
||||||
|
|
||||||
# Application version code (integer)
|
# Application version code (integer)
|
||||||
AppVersionCode=1405
|
AppVersionCode=1406
|
||||||
|
|
||||||
# Application user-visible version name (string)
|
# Application user-visible version name (string)
|
||||||
AppVersionName="1.4.05"
|
AppVersionName="1.4.06"
|
||||||
|
|
||||||
# Specify path to download application data in zip archive in the form 'Description|URL|MirrorURL^Description2|URL2|MirrorURL2^...'
|
# Specify path to download application data in zip archive in the form 'Description|URL|MirrorURL^Description2|URL2|MirrorURL2^...'
|
||||||
# If you'll start Description with '!' symbol it will be enabled by default, other downloads should be selected by user from startup config menu
|
# If you'll start Description with '!' symbol it will be enabled by default, other downloads should be selected by user from startup config menu
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ int main( int argc, char *argv[] )
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case cDoSave :
|
case cDoSave :
|
||||||
saveGame( &Game );
|
//saveGame( &Game );
|
||||||
enterState = cStateMainMenu;
|
enterState = cStateMainMenu;
|
||||||
break;
|
break;
|
||||||
case cDoRestart :
|
case cDoRestart :
|
||||||
@@ -1252,7 +1252,7 @@ BNX_BOOL saveGame( BNX_GAME *game )
|
|||||||
|
|
||||||
fclose( file );
|
fclose( file );
|
||||||
SDL_SaveBMP(SDL_GetVideoSurface(), "screenshot.bmp");
|
SDL_SaveBMP(SDL_GetVideoSurface(), "screenshot.bmp");
|
||||||
SDL_ANDROID_CloudSave( sysGetFullFileName( csSaveGameName ), "save", "Biniax2", "savegame", "screenshot.bmp", game->moves );
|
SDL_ANDROID_CloudSave( sysGetFullFileName( csSaveGameName ), "", "Biniax2", "savegame", "screenshot.bmp", game->moves );
|
||||||
|
|
||||||
return BNX_TRUE;
|
return BNX_TRUE;
|
||||||
}
|
}
|
||||||
@@ -1263,7 +1263,7 @@ BNX_BOOL loadGame( BNX_GAME *game )
|
|||||||
BNX_INT32 i;
|
BNX_INT32 i;
|
||||||
BNX_INT32 j;
|
BNX_INT32 j;
|
||||||
|
|
||||||
SDL_ANDROID_CloudLoad( sysGetFullFileName( csSaveGameName ), "save", "Biniax2" );
|
SDL_ANDROID_CloudLoad( sysGetFullFileName( csSaveGameName ), "", "Biniax2" );
|
||||||
|
|
||||||
if ( sysGetFileLen( sysGetFullFileName( csSaveGameName ) ) != cSaveFileSize )
|
if ( sysGetFileLen( sysGetFullFileName( csSaveGameName ) ) != cSaveFileSize )
|
||||||
return BNX_FALSE;
|
return BNX_FALSE;
|
||||||
|
|||||||
@@ -493,7 +493,7 @@ int SDLCALL SDL_ANDROID_CloudSave(const char *filename, const char *saveId, cons
|
|||||||
jstring s3 = (*JavaEnv)->NewStringUTF(JavaEnv, dialogTitle);
|
jstring s3 = (*JavaEnv)->NewStringUTF(JavaEnv, dialogTitle);
|
||||||
jstring s4 = (*JavaEnv)->NewStringUTF(JavaEnv, description);
|
jstring s4 = (*JavaEnv)->NewStringUTF(JavaEnv, description);
|
||||||
jstring s5 = (*JavaEnv)->NewStringUTF(JavaEnv, screenshotFile);
|
jstring s5 = (*JavaEnv)->NewStringUTF(JavaEnv, screenshotFile);
|
||||||
int result = (*JavaEnv)->CallBooleanMethod( JavaEnv, JavaRenderer, JavaRequestCloudSave, s1, s2, s3, s4, s5, playedTimeMs );
|
int result = (*JavaEnv)->CallBooleanMethod( JavaEnv, JavaRenderer, JavaRequestCloudSave, s1, s2, s3, s4, s5, &playedTimeMs );
|
||||||
(*JavaEnv)->DeleteLocalRef(JavaEnv, s5);
|
(*JavaEnv)->DeleteLocalRef(JavaEnv, s5);
|
||||||
(*JavaEnv)->DeleteLocalRef(JavaEnv, s4);
|
(*JavaEnv)->DeleteLocalRef(JavaEnv, s4);
|
||||||
(*JavaEnv)->DeleteLocalRef(JavaEnv, s3);
|
(*JavaEnv)->DeleteLocalRef(JavaEnv, s3);
|
||||||
|
|||||||
@@ -15,22 +15,27 @@
|
|||||||
-keep public class com.android.vending.licensing.ILicensingService
|
-keep public class com.android.vending.licensing.ILicensingService
|
||||||
|
|
||||||
-keepclasseswithmembernames class * {
|
-keepclasseswithmembernames class * {
|
||||||
native <methods>;
|
native <methods>;
|
||||||
}
|
}
|
||||||
|
|
||||||
-keepclasseswithmembernames class * {
|
-keepclasseswithmembernames class * {
|
||||||
public <init>(android.content.Context, android.util.AttributeSet);
|
public <init>(android.content.Context, android.util.AttributeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
-keepclasseswithmembernames class * {
|
-keepclasseswithmembernames class * {
|
||||||
public <init>(android.content.Context, android.util.AttributeSet, int);
|
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||||
}
|
}
|
||||||
|
|
||||||
-keepclassmembers enum * {
|
-keepclassmembers enum * {
|
||||||
public static **[] values();
|
public static **[] values();
|
||||||
public static ** valueOf(java.lang.String);
|
public static ** valueOf(java.lang.String);
|
||||||
}
|
}
|
||||||
|
|
||||||
-keep class * implements android.os.Parcelable {
|
-keep class * implements android.os.Parcelable {
|
||||||
public static final android.os.Parcelable$Creator *;
|
public static final android.os.Parcelable$Creator *;
|
||||||
|
}
|
||||||
|
|
||||||
|
-keep class com.google.android.gms.games.snapshot.SnapshotMetadataEntity
|
||||||
|
{
|
||||||
|
*;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user