mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-20 22:26:54 +01:00
move snapshoting code into GameUtils, and use it whenever loading a
GameListItem that should have a snapshot but doesn't. This lets games have snapshots immediately rather than only after they've been opened once.
This commit is contained in:
parent
e0dd481393
commit
3e6a7418b1
3 changed files with 93 additions and 53 deletions
|
@ -39,7 +39,6 @@ import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import android.view.Display;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
|
@ -2042,7 +2041,8 @@ public class BoardActivity extends XWActivity
|
||||||
|
|
||||||
// Before we dispose, and after JNIThread has relinquished
|
// Before we dispose, and after JNIThread has relinquished
|
||||||
// interest, redraw on smaller scale.
|
// interest, redraw on smaller scale.
|
||||||
takeSnapshot();
|
Bitmap thumb = GameUtils.takeSnapshot( this, m_jniGamePtr, m_gi );
|
||||||
|
DBUtils.saveThumbnail( this, m_gameLock, thumb );
|
||||||
|
|
||||||
XwJNI.game_dispose( m_jniGamePtr );
|
XwJNI.game_dispose( m_jniGamePtr );
|
||||||
m_jniGamePtr = 0;
|
m_jniGamePtr = 0;
|
||||||
|
@ -2053,57 +2053,6 @@ public class BoardActivity extends XWActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void takeSnapshot()
|
|
||||||
{
|
|
||||||
if ( GitVersion.THUMBNAIL_SUPPORTED ) {
|
|
||||||
Bitmap thumb = null;
|
|
||||||
if ( XWPrefs.getThumbEnabled( this ) ) {
|
|
||||||
int nCols = m_gi.boardSize;
|
|
||||||
int scale = XWPrefs.getThumbScale( this );
|
|
||||||
Assert.assertTrue( 0 < scale );
|
|
||||||
|
|
||||||
Display display = getWindowManager().getDefaultDisplay();
|
|
||||||
int width = display.getWidth();
|
|
||||||
int height = display.getHeight();
|
|
||||||
int dim = Math.min( width, height ) / scale;
|
|
||||||
int size = dim - (dim % nCols);
|
|
||||||
|
|
||||||
// If user wants active rect, we try to make it as
|
|
||||||
// large as possible while still not exceeding the
|
|
||||||
// scale. Since we're only using a fraction of the
|
|
||||||
// board, the board we draw before clipping may be
|
|
||||||
// huge.
|
|
||||||
int[] dims = new int[2];
|
|
||||||
Rect activeRect =
|
|
||||||
XWPrefs.getUseActiveRect( this ) ? new Rect() : null;
|
|
||||||
if ( null != activeRect ) {
|
|
||||||
dims = new int[2];
|
|
||||||
XwJNI.board_getActiveRect( m_jniGamePtr, activeRect, dims );
|
|
||||||
int numCells = Math.max( dims[0], dims[1] );
|
|
||||||
size = size * nCols / numCells;
|
|
||||||
}
|
|
||||||
thumb = Bitmap.createBitmap( size, size, Bitmap.Config.ARGB_8888 );
|
|
||||||
|
|
||||||
XwJNI.board_figureLayout( m_jniGamePtr, m_gi, 0, 0, size, size,
|
|
||||||
0, 0, 0, 20, 20, false, null );
|
|
||||||
|
|
||||||
ThumbCanvas canvas = new ThumbCanvas( this, thumb );
|
|
||||||
XwJNI.board_setDraw( m_jniGamePtr, canvas );
|
|
||||||
XwJNI.board_invalAll( m_jniGamePtr );
|
|
||||||
XwJNI.board_draw( m_jniGamePtr );
|
|
||||||
|
|
||||||
if ( null != activeRect ) {
|
|
||||||
XwJNI.board_getActiveRect( m_jniGamePtr, activeRect, null );
|
|
||||||
thumb = Bitmap.createBitmap( thumb, activeRect.left,
|
|
||||||
activeRect.top,
|
|
||||||
activeRect.width(),
|
|
||||||
activeRect.height() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DBUtils.saveThumbnail( this, m_gameLock, thumb );
|
|
||||||
}
|
|
||||||
} // takeSnapshot
|
|
||||||
|
|
||||||
private void warnIfNoTransport()
|
private void warnIfNoTransport()
|
||||||
{
|
{
|
||||||
switch( m_connType ) {
|
switch( m_connType ) {
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
package org.eehouse.android.xw4;
|
package org.eehouse.android.xw4;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
@ -48,6 +49,7 @@ public class GameListItem extends LinearLayout
|
||||||
|
|
||||||
private static HashSet<Long> s_invalRows = new HashSet<Long>();
|
private static HashSet<Long> s_invalRows = new HashSet<Long>();
|
||||||
|
|
||||||
|
private Activity m_activity;
|
||||||
private Context m_context;
|
private Context m_context;
|
||||||
private boolean m_loaded;
|
private boolean m_loaded;
|
||||||
private long m_rowid;
|
private long m_rowid;
|
||||||
|
@ -70,6 +72,9 @@ public class GameListItem extends LinearLayout
|
||||||
{
|
{
|
||||||
super( cx, as );
|
super( cx, as );
|
||||||
m_context = cx;
|
m_context = cx;
|
||||||
|
if ( cx instanceof Activity ) {
|
||||||
|
m_activity = (Activity)cx;
|
||||||
|
}
|
||||||
m_loaded = false;
|
m_loaded = false;
|
||||||
m_rowid = DBUtils.ROWID_NOTFOUND;
|
m_rowid = DBUtils.ROWID_NOTFOUND;
|
||||||
m_lastMoveTime = 0;
|
m_lastMoveTime = 0;
|
||||||
|
@ -343,6 +348,13 @@ public class GameListItem extends LinearLayout
|
||||||
{
|
{
|
||||||
if ( 0 == --m_loadingCount ) {
|
if ( 0 == --m_loadingCount ) {
|
||||||
m_summary = summary;
|
m_summary = summary;
|
||||||
|
|
||||||
|
if ( null != m_activity && null == summary.getThumbnail()
|
||||||
|
&& XWPrefs.getThumbEnabled( m_context ) ) {
|
||||||
|
summary.setThumbnail( GameUtils.loadMakeBitmap( m_activity,
|
||||||
|
m_rowid ) );
|
||||||
|
}
|
||||||
|
|
||||||
setData( summary );
|
setData( summary );
|
||||||
setLoaded( null != m_summary );
|
setLoaded( null != m_summary );
|
||||||
synchronized( s_invalRows ) {
|
synchronized( s_invalRows ) {
|
||||||
|
|
|
@ -23,9 +23,12 @@ package org.eehouse.android.xw4;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.view.Display;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -47,6 +50,7 @@ public class GameUtils {
|
||||||
public static final String INTENT_FORRESULT_ROWID = "forresult";
|
public static final String INTENT_FORRESULT_ROWID = "forresult";
|
||||||
|
|
||||||
private static final long GROUPID_UNSPEC = -1;
|
private static final long GROUPID_UNSPEC = -1;
|
||||||
|
private static Integer s_minScreen;
|
||||||
|
|
||||||
public static class NoSuchGameException extends RuntimeException {
|
public static class NoSuchGameException extends RuntimeException {
|
||||||
public NoSuchGameException() {
|
public NoSuchGameException() {
|
||||||
|
@ -292,6 +296,81 @@ public class GameUtils {
|
||||||
return gamePtr;
|
return gamePtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Bitmap loadMakeBitmap( Activity activity, long rowid )
|
||||||
|
{
|
||||||
|
DbgUtils.logf( "loadMakeBitmap(): taking snapshot..." );
|
||||||
|
Bitmap thumb = null;
|
||||||
|
GameLock lock = new GameLock( rowid, false );
|
||||||
|
if ( lock.tryLock() ) {
|
||||||
|
CurGameInfo gi = new CurGameInfo( activity );
|
||||||
|
int gamePtr = loadMakeGame( activity, gi, lock );
|
||||||
|
if ( 0 != gamePtr ) {
|
||||||
|
thumb = takeSnapshot( activity, gamePtr, gi );
|
||||||
|
XwJNI.game_dispose( gamePtr );
|
||||||
|
}
|
||||||
|
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
DbgUtils.logf( "loadMakeBitmap(): done with snapshot" );
|
||||||
|
return thumb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Bitmap takeSnapshot( Activity activity, int gamePtr,
|
||||||
|
CurGameInfo gi )
|
||||||
|
{
|
||||||
|
Bitmap thumb = null;
|
||||||
|
if ( GitVersion.THUMBNAIL_SUPPORTED ) {
|
||||||
|
if ( XWPrefs.getThumbEnabled( activity ) ) {
|
||||||
|
int nCols = gi.boardSize;
|
||||||
|
int scale = XWPrefs.getThumbScale( activity );
|
||||||
|
Assert.assertTrue( 0 < scale );
|
||||||
|
|
||||||
|
if ( null == s_minScreen ) {
|
||||||
|
Display display =
|
||||||
|
activity.getWindowManager().getDefaultDisplay();
|
||||||
|
int width = display.getWidth();
|
||||||
|
int height = display.getHeight();
|
||||||
|
s_minScreen = new Integer( Math.min( width, height ) );
|
||||||
|
}
|
||||||
|
int dim = s_minScreen / scale;
|
||||||
|
int size = dim - (dim % nCols);
|
||||||
|
|
||||||
|
// If user wants active rect, we try to make it as
|
||||||
|
// large as possible while still not exceeding the
|
||||||
|
// scale. Since we're only using a fraction of the
|
||||||
|
// board, the board we draw before clipping may be
|
||||||
|
// huge.
|
||||||
|
int[] dims = new int[2];
|
||||||
|
Rect activeRect =
|
||||||
|
XWPrefs.getUseActiveRect( activity ) ? new Rect() : null;
|
||||||
|
if ( null != activeRect ) {
|
||||||
|
dims = new int[2];
|
||||||
|
XwJNI.board_getActiveRect( gamePtr, activeRect, dims );
|
||||||
|
int numCells = Math.max( dims[0], dims[1] );
|
||||||
|
size = size * nCols / numCells;
|
||||||
|
}
|
||||||
|
thumb = Bitmap.createBitmap( size, size, Bitmap.Config.ARGB_8888 );
|
||||||
|
|
||||||
|
XwJNI.board_figureLayout( gamePtr, gi, 0, 0, size, size,
|
||||||
|
0, 0, 0, 20, 20, false, null );
|
||||||
|
|
||||||
|
ThumbCanvas canvas = new ThumbCanvas( activity, thumb );
|
||||||
|
XwJNI.board_setDraw( gamePtr, canvas );
|
||||||
|
XwJNI.board_invalAll( gamePtr );
|
||||||
|
XwJNI.board_draw( gamePtr );
|
||||||
|
|
||||||
|
if ( null != activeRect ) {
|
||||||
|
XwJNI.board_getActiveRect( gamePtr, activeRect, null );
|
||||||
|
thumb = Bitmap.createBitmap( thumb, activeRect.left,
|
||||||
|
activeRect.top,
|
||||||
|
activeRect.width(),
|
||||||
|
activeRect.height() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return thumb;
|
||||||
|
}
|
||||||
|
|
||||||
public static long saveGame( Context context, int gamePtr,
|
public static long saveGame( Context context, int gamePtr,
|
||||||
CurGameInfo gi, GameLock lock,
|
CurGameInfo gi, GameLock lock,
|
||||||
boolean setCreate )
|
boolean setCreate )
|
||||||
|
|
Loading…
Reference in a new issue