take snapshot after feeding background messages to game, which

required making snapshotting code work with a Context rather than a
full Activity.  Untested with network play as the net's down now.
This commit is contained in:
Eric House 2013-11-27 06:09:49 -08:00
parent f50badc428
commit 83bd5f773c
3 changed files with 54 additions and 34 deletions

View file

@ -20,16 +20,17 @@
package org.eehouse.android.xw4;
import android.content.res.Resources;
import android.app.Activity;
import android.graphics.Canvas;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.Handler;
import android.graphics.RectF;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import org.eehouse.android.xw4.jni.DrawCtx;
import org.eehouse.android.xw4.jni.DrawScoreInfo;
@ -51,6 +52,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
private static final float MIN_FONT_DIPS = 14.0f;
private Activity m_activity;
private Context m_context;
private Bitmap m_bitmap;
private JNIThread m_jniThread;
private Paint m_fillPaint;
@ -120,17 +122,30 @@ public class BoardCanvas extends Canvas implements DrawCtx {
}
protected FontDims m_fontDims;
public BoardCanvas( Context context, Bitmap bitmap )
{
this( context, null, bitmap, null, null );
}
public BoardCanvas( Activity activity, Bitmap bitmap, JNIThread jniThread,
BoardDims dims )
{
this( activity, activity, bitmap, jniThread, dims );
}
private BoardCanvas( Context context, Activity activity, Bitmap bitmap,
JNIThread jniThread, BoardDims dims )
{
super( bitmap );
m_context = context;
m_activity = activity;
m_bitmap = bitmap;
m_jniThread = jniThread;
m_hasSmallScreen = Utils.hasSmallScreen( activity );
m_hasSmallScreen = Utils.hasSmallScreen( m_context );
float scale = activity.getResources().getDisplayMetrics().density;
Resources res = m_context.getResources();
float scale = res.getDisplayMetrics().density;
m_defaultFontHt = (int)(MIN_FONT_DIPS * scale + 0.5f);
m_mediumFontHt = m_defaultFontHt * 3 / 2;
if ( null != dims ) {
@ -142,10 +157,9 @@ public class BoardCanvas extends Canvas implements DrawCtx {
m_strokePaint = new Paint();
m_strokePaint.setStyle( Paint.Style.STROKE );
Resources res = activity.getResources();
m_origin = res.getDrawable( R.drawable.origin );
m_prefs = CommonPrefs.get( activity );
m_prefs = CommonPrefs.get( m_context );
m_playerColors = m_prefs.playerColors;
m_bonusColors = m_prefs.bonusColors;
m_otherColors = m_prefs.otherColors;
@ -510,7 +524,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
drawCentered( text, rect, null );
rect.offset( 0, rect.height() );
drawCentered( m_activity.getResources().getString( R.string.pts ),
drawCentered( m_context.getResources().getString( R.string.pts ),
rect, null );
}
@ -825,7 +839,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
private Drawable loadAndRecolor( int resID, boolean useDark )
{
Resources res = m_activity.getResources();
Resources res = m_context.getResources();
Drawable arrow = res.getDrawable( resID );
if ( !useDark ) {

View file

@ -318,35 +318,41 @@ public class GameUtils {
return thumb;
}
public static Bitmap takeSnapshot( Activity activity, int gamePtr,
public static Bitmap takeSnapshot( Context context, int gamePtr,
CurGameInfo gi )
{
Bitmap thumb = null;
if ( BuildConstants.THUMBNAIL_SUPPORTED ) {
if ( XWPrefs.getThumbEnabled( activity ) ) {
if ( XWPrefs.getThumbEnabled( context ) ) {
int nCols = gi.boardSize;
int pct = XWPrefs.getThumbPct( activity );
int pct = XWPrefs.getThumbPct( context );
Assert.assertTrue( 0 < pct );
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 ) );
if ( context instanceof Activity ) {
Activity activity = (Activity)context;
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 * pct / 100;
int size = dim - (dim % nCols);
if ( null != s_minScreen ) {
int dim = s_minScreen * pct / 100;
int size = dim - (dim % nCols);
thumb = Bitmap.createBitmap( size, size, Bitmap.Config.ARGB_8888 );
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 );
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 );
ThumbCanvas canvas = new ThumbCanvas( context, thumb );
XwJNI.board_setDraw( gamePtr, canvas );
XwJNI.board_invalAll( gamePtr );
XwJNI.board_draw( gamePtr );
}
}
}
return thumb;
@ -744,7 +750,8 @@ public class GameUtils {
summarizeAndClose( context, lock, gamePtr, gi, feedImpl );
if ( draw && XWPrefs.getThumbEnabled( context ) ) {
DBUtils.saveThumbnail( context, lock, null );
Bitmap bitmap = takeSnapshot( context, gamePtr, gi );
DBUtils.saveThumbnail( context, lock, bitmap );
}
int flags = setFromFeedImpl( feedImpl );

View file

@ -20,7 +20,7 @@
package org.eehouse.android.xw4;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Rect;
@ -28,10 +28,9 @@ import org.eehouse.android.xw4.jni.XwJNI;
public class ThumbCanvas extends BoardCanvas {
public ThumbCanvas( Activity activity, Bitmap bitmap )
public ThumbCanvas( Context context, Bitmap bitmap )
{
super( activity, bitmap, null, null );
DbgUtils.logf( "creating new ThumbCanvas" );
super( context, bitmap );
}
// These should not be needed if common code gets fixed! So the