From 7be3a3bef8f3f7e86d9ea7d4539b5719efb3170f Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 21 Nov 2013 06:27:09 -0800 Subject: [PATCH] express thumb size as percent of screen with options, generated, in 5% increments. --- .../XWords4/res/values/common_rsrc.xml | 17 +------ xwords4/android/XWords4/res/xml/xwprefs.xml | 6 +-- .../org/eehouse/android/xw4/GameUtils.java | 6 +-- .../src/org/eehouse/android/xw4/XWPrefs.java | 23 +++------- .../android/xw4/XWThumbListPreference.java | 46 +++++++++++++++++++ 5 files changed, 59 insertions(+), 39 deletions(-) create mode 100644 xwords4/android/XWords4/src/org/eehouse/android/xw4/XWThumbListPreference.java diff --git a/xwords4/android/XWords4/res/values/common_rsrc.xml b/xwords4/android/XWords4/res/values/common_rsrc.xml index c3772f24a..810705bac 100644 --- a/xwords4/android/XWords4/res/values/common_rsrc.xml +++ b/xwords4/android/XWords4/res/values/common_rsrc.xml @@ -57,7 +57,7 @@ key_notify_vibrate key_enable_sms key_keep_screenon - key_thumbsize2 + key_thumbsize3 key_thumb_disabled key_summary_field @@ -148,13 +148,6 @@ Accept duplicate invites Accept invitations more than once - - 1/2 - 1/3 - 1/4 - 1/5 - 1/6 - @@ -301,12 +294,4 @@ @string/confirm_sms_willpay - - @string/game_thumb_half - @string/game_thumb_third - @string/game_thumb_quarter - @string/game_thumb_fifth - @string/game_thumb_sixth - - diff --git a/xwords4/android/XWords4/res/xml/xwprefs.xml b/xwords4/android/XWords4/res/xml/xwprefs.xml index db162f36f..626cdfae0 100644 --- a/xwords4/android/XWords4/res/xml/xwprefs.xml +++ b/xwords4/android/XWords4/res/xml/xwprefs.xml @@ -119,12 +119,10 @@ android:defaultValue="true" /> - diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java index 94866c63a..248d96e8e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -324,8 +324,8 @@ public class GameUtils { if ( BuildConstants.THUMBNAIL_SUPPORTED ) { if ( XWPrefs.getThumbEnabled( activity ) ) { int nCols = gi.boardSize; - int scale = XWPrefs.getThumbScale( activity ); - Assert.assertTrue( 0 < scale ); + int pct = XWPrefs.getThumbPct( activity ); + Assert.assertTrue( 0 < pct ); if ( null == s_minScreen ) { Display display = @@ -334,7 +334,7 @@ public class GameUtils { int height = display.getHeight(); s_minScreen = new Integer( Math.min( width, height ) ); } - int dim = s_minScreen / scale; + int dim = s_minScreen * pct / 100; int size = dim - (dim % nCols); thumb = Bitmap.createBitmap( size, size, Bitmap.Config.ARGB_8888 ); 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 5292844da..aaee9f88d 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java @@ -347,24 +347,15 @@ public class XWPrefs { return getPrefsBoolean( context, R.string.key_thumb_enabled, false ); } - public static int getThumbScale( Context context ) + public static int getThumbPct( Context context ) { - String scale = getPrefsString( context, R.string.key_thumbsize ); - int result = -1; - final int[][] data = { - { R.string.game_thumb_half, 2 } - ,{ R.string.game_thumb_third, 3 } - ,{ R.string.game_thumb_quarter, 4 } - ,{ R.string.game_thumb_fifth, 5 } - ,{ R.string.game_thumb_sixth, 6 } - }; - - for ( int[] datum : data ) { - if ( context.getString(datum[0]).equals(scale) ) { - result = datum[1]; - break; - } + String pct = getPrefsString( context, R.string.key_thumbsize ); + int result = 30; + if ( null != pct && 2 <= pct.length() ) { + // result = Integer.parseInt( pct.substring( 0, pct.length() - 1 ) ); + result = Integer.parseInt( pct ); } + DbgUtils.logf( "pct: %s => %d", pct, result ); return result; } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWThumbListPreference.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWThumbListPreference.java new file mode 100644 index 000000000..b3e957086 --- /dev/null +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWThumbListPreference.java @@ -0,0 +1,46 @@ +/* -*- compile-command: "cd ../../../../../; ant debug install"; -*- */ +/* + * Copyright 2010 - 2011 by Eric House (xwords@eehouse.org). All + * rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package org.eehouse.android.xw4; + +import android.content.Context; +import android.util.AttributeSet; + +public class XWThumbListPreference extends XWListPreference { + + public XWThumbListPreference( Context context, AttributeSet attrs ) + { + super( context, attrs ); + } + + // Why I exist: insert the rowid and gameid lines if debug is on + protected void onAttachedToActivity() + { + super.onAttachedToActivity(); + + CharSequence[] newEntries = new CharSequence[6]; + int indx = 0; + for ( int pct = 20; pct <= 45; pct += 5 ) { + newEntries[indx++] = String.format( "%d", pct ); + } + setEntries( newEntries ); + setEntryValues( newEntries ); + } +}