mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-04 20:46:28 +01:00
Merge branch 'android_branch' into android_sms_kitkat
This commit is contained in:
commit
85ae5973eb
7 changed files with 78 additions and 38 deletions
|
@ -2095,6 +2095,7 @@ public class BoardActivity extends XWActivity
|
|||
m_jniThread.waitToStop( save );
|
||||
m_jniThread = null;
|
||||
}
|
||||
m_view.stopHandling();
|
||||
|
||||
clearThis();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -165,10 +179,12 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
|
||||
public void setJNIThread( JNIThread jniThread )
|
||||
{
|
||||
if ( ! jniThread.equals( m_jniThread ) ) {
|
||||
DbgUtils.assertOnUIThread();
|
||||
if ( null == jniThread ) {
|
||||
} else if ( ! jniThread.equals( m_jniThread ) ) {
|
||||
DbgUtils.logf( "BoardCanvas changing threads" );
|
||||
m_jniThread = jniThread;
|
||||
}
|
||||
m_jniThread = jniThread;
|
||||
}
|
||||
|
||||
public int getCurPlayer()
|
||||
|
@ -508,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 );
|
||||
}
|
||||
|
||||
|
@ -538,9 +554,9 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
m_dictChars = null;
|
||||
m_activity.runOnUiThread( new Runnable() {
|
||||
public void run() {
|
||||
m_dictChars = XwJNI.dict_getChars( dictPtr );
|
||||
// draw again
|
||||
if ( null != m_jniThread ) {
|
||||
m_dictChars = XwJNI.dict_getChars( dictPtr );
|
||||
// draw again
|
||||
m_jniThread.handle( JNIThread.JNICmd
|
||||
.CMD_INVALALL );
|
||||
}
|
||||
|
@ -823,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 ) {
|
||||
|
|
|
@ -269,6 +269,15 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
invalidate();
|
||||
}
|
||||
|
||||
public void stopHandling()
|
||||
{
|
||||
m_jniThread = null;
|
||||
m_jniGamePtr = 0;
|
||||
if ( null != m_canvas ) {
|
||||
m_canvas.setJNIThread( null );
|
||||
}
|
||||
}
|
||||
|
||||
// SyncedDraw interface implementation
|
||||
public void doJNIDraw()
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@ import android.content.SharedPreferences;
|
|||
import android.database.Cursor;
|
||||
import android.database.DatabaseUtils;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.Time;
|
||||
|
@ -37,6 +38,7 @@ import java.util.ArrayList;
|
|||
import java.util.Formatter;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class DbgUtils {
|
||||
private static final String TAG = "XW4";
|
||||
|
@ -92,6 +94,11 @@ public class DbgUtils {
|
|||
printStack( exception.getStackTrace() );
|
||||
}
|
||||
|
||||
public static void assertOnUIThread()
|
||||
{
|
||||
Assert.assertTrue( Looper.getMainLooper().equals(Looper.myLooper()) );
|
||||
}
|
||||
|
||||
public static void printStack( StackTraceElement[] trace )
|
||||
{
|
||||
if ( s_doLog ) {
|
||||
|
|
|
@ -127,6 +127,7 @@ public class GameUtils {
|
|||
saveGame( context, gamePtr, gi, lockDest, true );
|
||||
}
|
||||
summarizeAndClose( context, lockDest, gamePtr, gi );
|
||||
DBUtils.saveThumbnail( context, lockDest, null );
|
||||
|
||||
return lockDest;
|
||||
} // resetGame
|
||||
|
@ -317,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;
|
||||
|
@ -743,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 );
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue