From 9e87a5ee927a5f8a24c9ed0b0762d69a90ba38ed Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 7 Nov 2013 19:55:01 -0800 Subject: [PATCH] implement getting active rect when that pref is set --- .../eehouse/android/xw4/BoardActivity.java | 32 ++++++++++++++++--- .../src/org/eehouse/android/xw4/XWPrefs.java | 5 +++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java index a26c17120..bd4dfebb6 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -20,7 +20,6 @@ package org.eehouse.android.xw4; -import android.view.Display; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; @@ -40,6 +39,7 @@ import android.os.Handler; import android.os.Message; import android.text.TextUtils; +import android.view.Display; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuInflater; @@ -2061,6 +2061,7 @@ public class BoardActivity extends XWActivity 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 ); @@ -2068,7 +2069,22 @@ public class BoardActivity extends XWActivity int width = display.getWidth(); int height = display.getHeight(); int dim = Math.min( width, height ) / scale; - int size = dim - (dim % 15); + 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 ); Rect bounds = new Rect( 0, 0, size, size ); @@ -2077,8 +2093,16 @@ public class BoardActivity extends XWActivity ThumbCanvas canvas = new ThumbCanvas( this, thumb ); XwJNI.board_setDraw( m_jniGamePtr, canvas ); - XwJNI.board_invalAll( m_jniGamePtr ); - XwJNI.board_draw( m_jniGamePtr ); + 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 ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java index f85e71743..bb768e55b 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java @@ -333,6 +333,11 @@ public class XWPrefs { return !getPrefsBoolean( context, R.string.key_thumb_disabled, false ); } + public static boolean getUseActiveRect( Context context ) + { + return getPrefsBoolean( context, R.string.key_thumb_useactive, false ); + } + public static int getThumbScale( Context context ) { String scale = getPrefsString( context, R.string.key_thumbsize );