make capture of thumbnail part of save

Problem was that changes to games didn't show up in the thumbnail
until the game was closed. Simply using existing snapshot didn't work
because it changes the board layout in order to "draw" to
ThumbnailCanvas and that change isn't easily reversed. So copy
existing code to open a new JNI object with just-saved game data
and use it to create a thumbnail bitmap.
This commit is contained in:
Eric House 2016-07-25 15:57:48 -07:00
parent 6fcd340e07
commit 9d95630654
3 changed files with 33 additions and 15 deletions

View file

@ -1756,6 +1756,7 @@ public class BoardDelegate extends DelegateBase
}
} );
handleViaThread( JNICmd. CMD_ZOOM, -8 );
handleViaThread( JNICmd.CMD_SAVE );
}
}
@ -2368,14 +2369,6 @@ public class BoardDelegate extends DelegateBase
m_view.stopHandling();
if ( XWPrefs.getThumbEnabled( m_activity ) ) {
// Before we dispose, and after JNIThread has
// relinquished interest, redraw on smaller scale.
Bitmap thumb =
GameUtils.takeSnapshot( m_activity, m_jniGamePtr, m_gi );
DBUtils.saveThumbnail( m_activity, m_gameLock, thumb );
}
m_gameLock = null;
}
}

View file

@ -292,10 +292,17 @@ public class GameUtils {
public static GamePtr loadMakeGame( Context context, CurGameInfo gi,
UtilCtxt util, TransportProcs tp,
GameLock lock )
{
byte[] stream = savedGame( context, lock );
return loadMakeGame( context, gi, util, tp, stream, lock.getRowid() );
}
private static GamePtr loadMakeGame( Context context, CurGameInfo gi,
UtilCtxt util, TransportProcs tp,
byte[] stream, long rowid )
{
GamePtr gamePtr = null;
byte[] stream = savedGame( context, lock );
if ( null == stream ) {
DbgUtils.logf( "loadMakeGame: no saved game!");
} else {
@ -306,7 +313,7 @@ public class GameUtils {
DbgUtils.logf( "loadMakeGame() failing: dicts %s unavailable",
TextUtils.join( ",", dictNames ) );
} else {
gamePtr = XwJNI.initJNI( lock.getRowid() );
gamePtr = XwJNI.initJNI( rowid );
String langName = gi.langName();
boolean madeGame =
@ -327,23 +334,38 @@ public class GameUtils {
return gamePtr;
}
public static Bitmap loadMakeBitmap( Activity activity, long rowid )
public static Bitmap loadMakeBitmap( Context context, long rowid )
{
Bitmap thumb = null;
GameLock lock = new GameLock( rowid, false );
if ( lock.tryLock() ) {
CurGameInfo gi = new CurGameInfo( activity );
GamePtr gamePtr = loadMakeGame( activity, gi, lock );
CurGameInfo gi = new CurGameInfo( context );
GamePtr gamePtr = loadMakeGame( context, gi, lock );
if ( null != gamePtr ) {
thumb = takeSnapshot( activity, gamePtr, gi );
thumb = takeSnapshot( context, gamePtr, gi );
gamePtr.release();
DBUtils.saveThumbnail( activity, lock, thumb );
DBUtils.saveThumbnail( context, lock, thumb );
}
lock.unlock();
}
return thumb;
}
public static Bitmap loadMakeBitmap( Context context, byte[] stream,
GameLock lock )
{
Bitmap thumb = null;
CurGameInfo gi = new CurGameInfo( context );
GamePtr gamePtr = loadMakeGame( context, gi, null, null, stream,
lock.getRowid() );
if ( null != gamePtr ) {
thumb = takeSnapshot( context, gamePtr, gi );
gamePtr.release();
DBUtils.saveThumbnail( context, lock, thumb );
}
return thumb;
}
public static Bitmap takeSnapshot( Context context, GamePtr gamePtr,
CurGameInfo gi )
{

View file

@ -378,9 +378,12 @@ public class JNIThread extends Thread {
XwJNI.game_summarize( m_jniGamePtr, summary );
DBUtils.saveGame( m_context, m_lock, state, false );
DBUtils.saveSummary( m_context, m_lock, summary );
// There'd better be no way for saveGame above to fail!
XwJNI.game_saveSucceeded( m_jniGamePtr );
m_lastSavedState = state;
GameUtils.loadMakeBitmap( m_context, state, m_lock );
}
}
}