From c9fec737e5a03ae5f9fc0480f654e8b2d042f642 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Fri, 14 Jan 2011 18:15:33 -0800 Subject: [PATCH 01/12] changes, protected by a disabled compile-time flag, to use cairo-based API for drawing instead of now-deprecated gdk ones. Unfortunately nothing actually draws and I'm putting the debugging off until I have some time. --- xwords4/linux/Makefile | 5 +- xwords4/linux/gtkdraw.c | 243 +++++++++++++++++++++++++++++----------- xwords4/linux/gtkmain.h | 4 + 3 files changed, 182 insertions(+), 70 deletions(-) diff --git a/xwords4/linux/Makefile b/xwords4/linux/Makefile index c74d8ca54..d44af2488 100644 --- a/xwords4/linux/Makefile +++ b/xwords4/linux/Makefile @@ -37,6 +37,7 @@ ifdef CURSES_SMALL_SCREEN DO_CURSES += -DCURSES_SMALL_SCREEN endif DO_GTK = -DPLATFORM_GTK +# DO_GTK += -DUSE_CAIRO # uncomment for standalone build # STANDALONE = -DXWFEATURE_STANDALONE_ONLY @@ -178,8 +179,8 @@ endif ifneq (,$(findstring DPLATFORM_GTK,$(DEFINES))) LIBS += `pkg-config --libs gtk+-2.0` - CFLAGS += `pkg-config --cflags gtk+-2.0` \ - -DGDK_DISABLE_DEPRECATED + CFLAGS += `pkg-config --cflags gtk+-2.0` +# CFLAGS += -DGDK_DISABLE_DEPRECATED POINTER_SUPPORT = -DPOINTER_SUPPORT endif diff --git a/xwords4/linux/gtkdraw.c b/xwords4/linux/gtkdraw.c index 5876ca725..31d0c0df4 100644 --- a/xwords4/linux/gtkdraw.c +++ b/xwords4/linux/gtkdraw.c @@ -22,8 +22,6 @@ #include #include -#undef GDK_DISABLE_DEPRECATED - #include #include "gtkmain.h" @@ -64,31 +62,75 @@ gtkInsetRect( XP_Rect* r, short i ) #define GTKMIN_W_HT 12 +#ifdef USE_CAIRO +# define XP_UNUSED_CAIRO(var) UNUSED__ ## var __attribute__((unused)) +#else +# define XP_UNUSED_CAIRO(var) var +#endif + +static void +draw_rectangle( const GtkDrawCtx* dctx, + GdkDrawable* XP_UNUSED_CAIRO(drawable), + GdkGC* XP_UNUSED_CAIRO(gc), + gboolean fill, gint left, gint top, gint width, + gint height ) +{ +#ifdef USE_CAIRO + cairo_rectangle( dctx->cr, left, top, width, height ); + cairo_stroke_preserve( dctx->cr ); + cairo_set_source_rgb( dctx->cr, 1, 1, 1 ); + /* if ( fill ) { */ + cairo_fill( dctx->cr ); + /* } else { */ + cairo_stroke( dctx->cr ); + /* } */ + fill = fill; +#else + dctx = dctx; + gdk_draw_rectangle( drawable, gc, fill, left, top, width, height ); +#endif +} + static void gtkFillRect( GtkDrawCtx* dctx, const XP_Rect* rect, const GdkColor* color ) { +#ifdef USE_CAIRO + color = color; + //gdk_cairo_set_source_color( dctx->cr, color ); +#else gdk_gc_set_foreground( dctx->drawGC, color ); - gdk_draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC, - TRUE, - rect->left, rect->top, rect->width, - rect->height ); +#endif + draw_rectangle( dctx, DRAW_WHAT(dctx), dctx->drawGC, TRUE, + rect->left, rect->top, rect->width, + rect->height ); +} + +static void +set_color_cairo( const GtkDrawCtx* dctx, unsigned short red, + unsigned short green, unsigned short blue ) +{ + GdkColor color = { red, green, blue }; + color = color; + dctx = dctx; + //gdk_cairo_set_source_color( dctx->cr, &color ); } static void gtkEraseRect( const GtkDrawCtx* dctx, const XP_Rect* rect ) { - gdk_draw_rectangle( DRAW_WHAT(dctx), - dctx->drawing_area->style->white_gc, - TRUE, rect->left, rect->top, - rect->width, rect->height ); + set_color_cairo( dctx, 0xFFFF, 0xFFFF, 0xFFFF ); + draw_rectangle( dctx, DRAW_WHAT(dctx), + dctx->drawing_area->style->white_gc, + TRUE, rect->left, rect->top, + rect->width, rect->height ); } /* gtkEraseRect */ static void frameRect( GtkDrawCtx* dctx, const XP_Rect* rect ) { - gdk_draw_rectangle( DRAW_WHAT(dctx), - dctx->drawGC, FALSE, rect->left, rect->top, - rect->width, rect->height ); + draw_rectangle( dctx, DRAW_WHAT(dctx), dctx->drawGC, + FALSE, rect->left, rect->top, + rect->width, rect->height ); } /* frameRect */ #ifdef DRAW_WITH_PRIMITIVES @@ -225,9 +267,14 @@ draw_string_at( GtkDrawCtx* dctx, PangoLayout* layout, } } +#ifdef USE_CAIRO + frground = frground; + bkgrnd = bkgrnd; +#else gdk_draw_layout_with_colors( DRAW_WHAT(dctx), dctx->drawGC, xx, yy, layout, frground, bkgrnd ); +#endif } /* draw_string_at */ static void @@ -248,8 +295,8 @@ drawBitmapFromLBS( GtkDrawCtx* dctx, const XP_Bitmap bm, const XP_Rect* rect ) pm = gdk_pixmap_new( DRAW_WHAT(dctx), nCols, nRows, -1 ); - gdk_draw_rectangle( pm, dctx->drawing_area->style->white_gc, TRUE, - 0, 0, nCols, nRows ); + draw_rectangle( dctx, pm, dctx->drawing_area->style->white_gc, TRUE, + 0, 0, nCols, nRows ); x = 0; y = 0; @@ -259,7 +306,10 @@ drawBitmapFromLBS( GtkDrawCtx* dctx, const XP_Bitmap bm, const XP_Rect* rect ) for ( i = 0; i < 8; ++i ) { XP_Bool draw = ((byte & 0x80) != 0); if ( draw ) { +#ifdef USE_CAIRO +#else gdk_draw_point( pm, dctx->drawing_area->style->black_gc, x, y ); +#endif } byte <<= 1; if ( ++x == nCols ) { @@ -273,6 +323,9 @@ drawBitmapFromLBS( GtkDrawCtx* dctx, const XP_Bitmap bm, const XP_Rect* rect ) XP_ASSERT( nBytes == -1 ); /* else we're out of sync */ +#ifdef USE_CAIRO + rect = rect; +#else gdk_draw_drawable( DRAW_WHAT(dctx), dctx->drawGC, (GdkDrawable*)pm, 0, 0, @@ -280,7 +333,7 @@ drawBitmapFromLBS( GtkDrawCtx* dctx, const XP_Bitmap bm, const XP_Rect* rect ) rect->top+2, lbs->nCols, lbs->nRows ); - +#endif g_object_unref( pm ); } /* drawBitmapFromLBS */ @@ -299,10 +352,10 @@ gtk_draw_destroyCtxt( DrawCtx* p_dctx ) GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx; GtkAllocation* alloc = &dctx->drawing_area->allocation; - gdk_draw_rectangle( DRAW_WHAT(dctx), - dctx->drawing_area->style->white_gc, - TRUE, - 0, 0, alloc->width, alloc->height ); + draw_rectangle( dctx, DRAW_WHAT(dctx), + dctx->drawing_area->style->white_gc, + TRUE, + 0, 0, alloc->width, alloc->height ); g_list_foreach( dctx->fontsPerSize, freer, NULL ); g_list_free( dctx->fontsPerSize ); @@ -328,7 +381,11 @@ gtk_draw_boardBegin( DrawCtx* p_dctx, const XP_Rect* rect, dctx->cellWidth = width; dctx->cellHeight = height; +#ifdef USE_CAIRO + //gdk_cairo_set_source_color( dctx->cr, &dctx->black ); +#else gdk_gc_set_foreground( dctx->drawGC, &dctx->black ); +#endif gdkrect = *(GdkRectangle*)rect; ++gdkrect.width; @@ -364,6 +421,9 @@ gtk_draw_vertScrollBoard( DrawCtx* p_dctx, XP_Rect* rect, ysrc = ydest + dist; } +#ifdef USE_CAIRO + dctx = dctx; +#else gdk_draw_drawable( DRAW_WHAT(dctx), dctx->drawGC, DRAW_WHAT(dctx), @@ -373,7 +433,7 @@ gtk_draw_vertScrollBoard( DrawCtx* p_dctx, XP_Rect* rect, ydest, rect->width, rect->height - dist ); - +#endif if ( !down ) { rect->top += rect->height - dist; } @@ -391,33 +451,37 @@ drawHintBorders( GtkDrawCtx* dctx, const XP_Rect* rect, HintAtts hintAtts) XP_Rect lrect = *rect; gtkInsetRect( &lrect, 1 ); +#ifdef USE_CAIRO + //gdk_cairo_set_source_color( dctx->cr, &dctx->black ); +#else gdk_gc_set_foreground( dctx->drawGC, &dctx->black ); +#endif if ( (hintAtts & HINT_BORDER_LEFT) != 0 ) { - gdk_draw_rectangle( DRAW_WHAT(dctx), - dctx->drawGC, - FALSE, lrect.left, lrect.top, - 0, lrect.height); + draw_rectangle( dctx, DRAW_WHAT(dctx), + dctx->drawGC, + FALSE, lrect.left, lrect.top, + 0, lrect.height); } if ( (hintAtts & HINT_BORDER_TOP) != 0 ) { - gdk_draw_rectangle( DRAW_WHAT(dctx), - dctx->drawGC, - FALSE, lrect.left, lrect.top, - lrect.width, 0/*rectInset.height*/); + draw_rectangle( dctx, DRAW_WHAT(dctx), + dctx->drawGC, + FALSE, lrect.left, lrect.top, + lrect.width, 0/*rectInset.height*/); } if ( (hintAtts & HINT_BORDER_RIGHT) != 0 ) { - gdk_draw_rectangle( DRAW_WHAT(dctx), - dctx->drawGC, - FALSE, lrect.left+lrect.width, - lrect.top, - 0, lrect.height); + draw_rectangle( dctx, DRAW_WHAT(dctx), + dctx->drawGC, + FALSE, lrect.left+lrect.width, + lrect.top, + 0, lrect.height); } if ( (hintAtts & HINT_BORDER_BOTTOM) != 0 ) { - gdk_draw_rectangle( DRAW_WHAT(dctx), - dctx->drawGC, - FALSE, lrect.left, - lrect.top+lrect.height, - lrect.width, 0 ); + draw_rectangle( dctx, DRAW_WHAT(dctx), + dctx->drawGC, + FALSE, lrect.left, + lrect.top+lrect.height, + lrect.width, 0 ); } } } @@ -462,12 +526,16 @@ gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter, gtkInsetRect( &rectInset, 1 ); if ( showGrid ) { +#ifdef USE_CAIRO + //gdk_cairo_set_source_color( dctx->cr, &dctx->black ); +#else gdk_gc_set_foreground( dctx->drawGC, &dctx->black ); - gdk_draw_rectangle( DRAW_WHAT(dctx), - dctx->drawGC, - FALSE, - rect->left, rect->top, rect->width, - rect->height ); +#endif + draw_rectangle( dctx, DRAW_WHAT(dctx), + dctx->drawGC, + FALSE, + rect->left, rect->top, rect->width, + rect->height ); } /* We draw just an empty, potentially colored, square IFF there's nothing @@ -483,10 +551,14 @@ gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter, foreground = NULL; } if ( !!foreground ) { +#ifdef USE_CAIRO + //gdk_cairo_set_source_color( dctx->cr, foreground ); +#else gdk_gc_set_foreground( dctx->drawGC, foreground ); - gdk_draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC, TRUE, - rectInset.left, rectInset.top, - rectInset.width+1, rectInset.height+1 ); +#endif + draw_rectangle( dctx, DRAW_WHAT(dctx), dctx->drawGC, TRUE, + rectInset.left, rectInset.top, + rectInset.width+1, rectInset.height+1 ); } } if ( (flags & CELL_ISSTAR) != 0 ) { @@ -499,13 +571,21 @@ gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter, XP_Bool isBlank = (flags & CELL_ISBLANK) != 0; GdkColor* foreground; if ( cursor ) { +#ifdef USE_CAIRO + //gdk_cairo_set_source_color( dctx->cr, cursor ); +#else gdk_gc_set_foreground( dctx->drawGC, cursor ); +#endif } else if ( !highlight ) { +#ifdef USE_CAIRO + //gdk_cairo_set_source_color( dctx->cr, &dctx->tileBack ); +#else gdk_gc_set_foreground( dctx->drawGC, &dctx->tileBack ); +#endif } - gdk_draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC, TRUE, - rectInset.left, rectInset.top, - rectInset.width+1, rectInset.height+1 ); + draw_rectangle( dctx, DRAW_WHAT(dctx), dctx->drawGC, TRUE, + rectInset.left, rectInset.top, + rectInset.width+1, rectInset.height+1 ); if ( isBlank && 0 == strcmp("_",letter ) ) { letter = "?"; @@ -517,6 +597,8 @@ gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter, XP_GTK_JUST_CENTER, foreground, cursor ); if ( isBlank ) { +#ifdef USE_CAIRO +#else gdk_draw_arc( DRAW_WHAT(dctx), dctx->drawGC, 0, /* filled */ rect->left, /* x */ @@ -524,6 +606,7 @@ gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter, rect->width,/*width, */ rect->height,/*width, */ 0, 360*64 ); +#endif } } @@ -547,7 +630,7 @@ gtk_draw_invertCell( DrawCtx* XP_UNUSED(p_dctx), /* gdk_gc_set_function( dctx->drawGC, GDK_INVERT ); */ /* gdk_gc_set_clip_rectangle( dctx->drawGC, (GdkRectangle*)rect ); */ -/* gdk_draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC, */ +/* draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC, */ /* TRUE, rect->left, rect->top, */ /* rect->width, rect->height ); */ @@ -617,19 +700,23 @@ gtkDrawTileImpl( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* textP, } /* frame the tile */ +#ifdef USE_CAIRO + //gdk_cairo_set_source_color( dctx->cr, &dctx->black ); +#else gdk_gc_set_foreground( dctx->drawGC, &dctx->black ); - gdk_draw_rectangle( DRAW_WHAT(dctx), - dctx->drawGC, - FALSE, - insetR.left, insetR.top, insetR.width, - insetR.height ); +#endif + draw_rectangle( dctx, DRAW_WHAT(dctx), + dctx->drawGC, + FALSE, + insetR.left, insetR.top, insetR.width, + insetR.height ); if ( (flags & CELL_HIGHLIGHT) != 0 ) { gtkInsetRect( &insetR, 1 ); - gdk_draw_rectangle( DRAW_WHAT(dctx), - dctx->drawGC, - FALSE, insetR.left, insetR.top, - insetR.width, insetR.height); + draw_rectangle( dctx, DRAW_WHAT(dctx), + dctx->drawGC, + FALSE, insetR.left, insetR.top, + insetR.width, insetR.height); } } } /* gtkDrawTileImpl */ @@ -693,11 +780,15 @@ gtk_draw_drawTrayDivider( DrawCtx* p_dctx, const XP_Rect* rect, --r.height; } +#ifdef USE_CAIRO + //gdk_cairo_set_source_color( dctx->cr, &dctx->black ); +#else gdk_gc_set_foreground( dctx->drawGC, &dctx->black ); - gdk_draw_rectangle( DRAW_WHAT(dctx), - dctx->drawGC, - !selected, - r.left, r.top, r.width, r.height); +#endif + draw_rectangle( dctx, DRAW_WHAT(dctx), + dctx->drawGC, + !selected, + r.left, r.top, r.width, r.height); } /* gtk_draw_drawTrayDivider */ @@ -940,7 +1031,11 @@ gtk_draw_score_drawPlayer( DrawCtx* p_dctx, const XP_Rect* rInner, gtkFillRect( dctx, rOuter, cursor ); } +#ifdef USE_CAIRO + //gdk_cairo_set_source_color( dctx->cr, &dctx->playerColors[playerNum] ); +#else gdk_gc_set_foreground( dctx->drawGC, &dctx->playerColors[playerNum] ); +#endif if ( dsi->selected ) { XP_Rect selRect = *rOuter; @@ -960,9 +1055,9 @@ gtk_draw_score_drawPlayer( DrawCtx* p_dctx, const XP_Rect* rInner, } } - gdk_draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC, - TRUE, selRect.left, selRect.top, - selRect.width, selRect.height ); + draw_rectangle( dctx, DRAW_WHAT(dctx), dctx->drawGC, + TRUE, selRect.left, selRect.top, + selRect.width, selRect.height ); if ( hasCursor ) { gtkFillRect( dctx, rInner, cursor ); } @@ -1099,8 +1194,11 @@ gtk_draw_drawMiniWindow( DrawCtx* p_dctx, const XP_UCHAR* text, GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx; XP_Rect localR = *rect; +#ifdef USE_CAIRO + //gdk_cairo_set_source_color( dctx->cr, &dctx->black ); +#else gdk_gc_set_foreground( dctx->drawGC, &dctx->black ); -/* gdk_gc_set_clip_rectangle( dctx->drawGC, (GdkRectangle*)&localR ); */ +#endif /* play some skanky games to get the shadow drawn under and to the right... */ @@ -1227,7 +1325,16 @@ gtkDrawCtxtMake( GtkWidget* drawing_area, GtkAppGlobals* globals ) } else { window = GTK_WIDGET(drawing_area)->window; } + window = GTK_WIDGET(drawing_area)->window; +#ifdef USE_CAIRO + dctx->cr = gdk_cairo_create( window ); + XP_LOGF( "dctx->cr=%p", dctx->cr ); + cairo_set_line_width( dctx->cr, 1.0 ); + cairo_set_line_cap( dctx->cr, CAIRO_LINE_CAP_SQUARE ); + cairo_set_source_rgb( dctx->cr, 0, 0, 0 ); +#else dctx->drawGC = gdk_gc_new( window ); +#endif } map = gdk_colormap_get_system(); diff --git a/xwords4/linux/gtkmain.h b/xwords4/linux/gtkmain.h index 949894247..cfb02563a 100644 --- a/xwords4/linux/gtkmain.h +++ b/xwords4/linux/gtkmain.h @@ -47,7 +47,11 @@ typedef struct GtkDrawCtx { GtkWidget* drawing_area; struct GtkAppGlobals* globals; +#ifdef USE_CAIRO + cairo_t* cr; +#else GdkGC* drawGC; +#endif GdkColor black; GdkColor white; From 465370bac6c6eb642817454b06090c4961e5d8d7 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Fri, 14 Jan 2011 19:03:08 -0800 Subject: [PATCH 02/12] add ctime and mtime timestamps to DB when creating, and upgrade to new version by adding them. Can't have them default to 'now' because that's not supported for ADDs. Can't remove columns either, so at some point I'll need to migrate to get rid of accumulated cruft. Timestamps are not set nor read yet. --- .../src/org/eehouse/android/xw4/DBHelper.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java index 5e34e8c6a..515e02aa1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java @@ -29,7 +29,7 @@ public class DBHelper extends SQLiteOpenHelper { public static final String TABLE_NAME_SUM = "summaries"; public static final String TABLE_NAME_OBITS = "obits"; private static final String DB_NAME = "xwdb"; - private static final int DB_VERSION = 6; + private static final int DB_VERSION = 7; public static final String FILE_NAME = "FILE_NAME"; public static final String NUM_MOVES = "NUM_MOVES"; @@ -52,9 +52,10 @@ public class DBHelper extends SQLiteOpenHelper { public static final String SEED = "SEED"; public static final String SMSPHONE = "SMSPHONE"; // not used yet - public static final String CREATE_TIME = "CREATE_TIME"; + // public static final String CREATE_TIME = "CREATE_TIME"; + public static final String CTIME = "CTIME"; // not used yet - public static final String LASTPLAY_TIME = "LASTPLAY_TIME"; + public static final String MTIME = "MTIME"; public DBHelper( Context context ) @@ -85,8 +86,11 @@ public class DBHelper extends SQLiteOpenHelper { // HASMSGS: sqlite doesn't have bool; use 0 and 1 + HASMSGS + " INTEGER DEFAULT 0," - + CREATE_TIME + " INTEGER," - + LASTPLAY_TIME + " INTEGER," + + CTIME + " TIMESTAMP," + + MTIME + " TIMESTAMP," + + // + CREATE_TIME + " INTEGER," + // + LASTPLAY_TIME + " INTEGER," + SNAPSHOT + " BLOB" + ");" ); @@ -112,8 +116,24 @@ public class DBHelper extends SQLiteOpenHelper { { Utils.logf( "onUpgrade: old: %d; new: %d", oldVersion, newVersion ); - if ( newVersion == 6 && oldVersion == 5 ) { - onCreateObits(db); + if ( newVersion == 7 ) { + switch( oldVersion ) { + case 5: + onCreateObits( db ); + // FALLTHRU + case 6: + // F*cking sqlite won't let me add a column with a + // non-constant default (i.e. DEFAULT + // (datetime('now','localtime'))," so I'll have to add + // the value manually. Or screw everybody and nuke + // the DB rather than modify it. I want my + // postgres... + db.execSQL( "ALTER TABLE " + TABLE_NAME_SUM + + " ADD " + CTIME + " TIMESTAMP;" ); + db.execSQL( "ALTER TABLE " + TABLE_NAME_SUM + + " ADD " + MTIME + " TIMESTAMP;" ); + break; + } } else { db.execSQL( "DROP TABLE " + TABLE_NAME_SUM + ";" ); if ( oldVersion >= 6 ) { From 33d5246b7a4d3c4b410dbdb482a85a95df40102b Mon Sep 17 00:00:00 2001 From: Andy2 Date: Sat, 15 Jan 2011 21:45:20 -0800 Subject: [PATCH 03/12] add a new-user hint, displayed the first time the arrow's drawn on the board, explaining what the arrow's for and how to move and disable it. Implementation required passing XWActivity into BoardView so the newbie hint method could be called on it. --- .../android/XWords4/res/values/common_rsrc.xml | 1 + xwords4/android/XWords4/res/values/strings.xml | 8 ++++++++ .../org/eehouse/android/xw4/BoardActivity.java | 2 +- .../src/org/eehouse/android/xw4/BoardView.java | 18 +++++++++++++++++- .../eehouse/android/xw4/jni/BoardHandler.java | 6 +++++- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/xwords4/android/XWords4/res/values/common_rsrc.xml b/xwords4/android/XWords4/res/values/common_rsrc.xml index 0d9e4b96a..fd8cd9e03 100644 --- a/xwords4/android/XWords4/res/values/common_rsrc.xml +++ b/xwords4/android/XWords4/res/values/common_rsrc.xml @@ -54,6 +54,7 @@ key_notagain_conndfirst key_notagain_conndmid key_notagain_dicts + key_notagain_arrow org.eehouse.android.xw4.relayids_extra diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 808b87952..90be8b49e 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -488,6 +488,14 @@ here. Email me at eehouse@eehouse.org for information on building and installing your own dictionaries. + Moving tiles to the board:\nYou can + drag tiles between the rack and the board, or you can tap an + empty square to place the board arrow. Rack tiles you tap will + replace the arrow (moving it one square in the direction it + points.) Tap the arrow once to change its orientation; a second + time, to hide it. A checkbox in the Appearance section of + Settings will hide it permanently. + To start a basic networked two-player game in %s: 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 7e4840048..524d639a9 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -830,7 +830,7 @@ public class BoardActivity extends XWActivity implements UtilCtxt { } ); m_jniThread.start(); - m_view.startHandling( m_jniThread, m_jniGamePtr, m_gi ); + m_view.startHandling( this, m_jniThread, m_jniGamePtr, m_gi ); if ( null != m_xport ) { m_xport.setReceiver( m_jniThread ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java index d3cd11639..f25ca08ed 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java @@ -66,6 +66,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler, private Drawable m_origin; private int m_left, m_top; private JNIThread m_jniThread; + private XWActivity m_parent; private String[][] m_scores; private String[] m_dictChars; private Rect m_boundsScratch; @@ -286,8 +287,10 @@ public class BoardView extends View implements DrawCtx, BoardHandler, } // layoutBoardOnce // BoardHandler interface implementation - public void startHandling( JNIThread thread, int gamePtr, CurGameInfo gi ) + public void startHandling( XWActivity parent, JNIThread thread, + int gamePtr, CurGameInfo gi ) { + m_parent = parent; m_jniThread = thread; m_jniGamePtr = gamePtr; m_gi = gi; @@ -506,6 +509,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler, return true; } // drawCell + private boolean m_arrowHintShown = false; public void drawBoardArrow( Rect rect, int bonus, boolean vert, int hintAtts, int flags ) { @@ -513,6 +517,18 @@ public class BoardView extends View implements DrawCtx, BoardHandler, Drawable arrow = vert? m_downArrow : m_rightArrow; arrow.setBounds( rect ); arrow.draw( m_canvas ); + + if ( !m_arrowHintShown ) { + m_arrowHintShown = true; + m_viewHandler.post( new Runnable() { + public void run() { + m_parent. + showNotAgainDlgThen( R.string.not_again_arrow, + R.string.key_notagain_arrow, + null ); + } + } ); + } } public boolean trayBegin ( Rect rect, int owner, int dfs ) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/BoardHandler.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/BoardHandler.java index b803e2ff8..bdadcdecd 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/BoardHandler.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/BoardHandler.java @@ -1,3 +1,4 @@ +/* -*- compile-command: "cd ../../../../../../; ant install"; -*- */ /* * Copyright 2009-2010 by Eric House (xwords@eehouse.org). All * rights reserved. @@ -19,8 +20,11 @@ package org.eehouse.android.xw4.jni; +import org.eehouse.android.xw4.XWActivity; + public interface BoardHandler { - void startHandling( JNIThread thread, int gamePtr, CurGameInfo gi ); + void startHandling( XWActivity parent, JNIThread thread, + int gamePtr, CurGameInfo gi ); } From e9e54ba379d9c380fc222bd388ba4225746b5cb7 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Mon, 17 Jan 2011 18:55:36 -0800 Subject: [PATCH 04/12] toward supporting a light-on-dark theme: add pref for cell border color; add pref for whether highlight is black-on-white or the reverse; and remake the board arrow in white if the background is a dark color. It's now possible to configure various colors so that black empty cells looks good. Next need a single control to do it. --- .../XWords4/res/values/common_rsrc.xml | 2 + .../android/XWords4/res/values/strings.xml | 5 ++ xwords4/android/XWords4/res/xml/xwprefs.xml | 10 +++ .../org/eehouse/android/xw4/BoardView.java | 82 +++++++++++++++---- .../eehouse/android/xw4/jni/CommonPrefs.java | 10 ++- 5 files changed, 91 insertions(+), 18 deletions(-) diff --git a/xwords4/android/XWords4/res/values/common_rsrc.xml b/xwords4/android/XWords4/res/values/common_rsrc.xml index fd8cd9e03..d0271a566 100644 --- a/xwords4/android/XWords4/res/values/common_rsrc.xml +++ b/xwords4/android/XWords4/res/values/common_rsrc.xml @@ -25,6 +25,8 @@ key_clr_tile_back key_clr_empty key_clr_crosshairs + key_clr_frames + key_hilite_whiteonblack key_relay_host key_relay_port2 key_proxy_port diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 90be8b49e..5a86c102c 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -287,6 +287,11 @@ Tile background Empty cell/background Crosshairs color + Border color + Last play white-on-black + Toggle recent move + contrast colors + Advanced You may never need these... Relay address diff --git a/xwords4/android/XWords4/res/xml/xwprefs.xml b/xwords4/android/XWords4/res/xml/xwprefs.xml index fbe8b2f64..260f0713e 100644 --- a/xwords4/android/XWords4/res/xml/xwprefs.xml +++ b/xwords4/android/XWords4/res/xml/xwprefs.xml @@ -72,6 +72,11 @@ + + >= 8; + } + boolean blackArrow = sum > (127 * 3); + + if ( m_blackArrow != blackArrow ) { + m_blackArrow = blackArrow; + m_downArrow = m_rightArrow = null; + } + if ( vert ) { + if ( null == m_downArrow ) { + m_downArrow = loadAndRecolor( R.drawable.downarrow ); + } + arrow = m_downArrow; + } else { + if ( null == m_rightArrow ) { + m_rightArrow = loadAndRecolor( R.drawable.rightarrow ); + } + arrow = m_rightArrow; + } + rect.inset( 2, 2 ); - Drawable arrow = vert? m_downArrow : m_rightArrow; arrow.setBounds( rect ); arrow.draw( m_canvas ); @@ -633,7 +665,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler, public void drawMiniWindow( String text, Rect rect ) { - clearToBack( rect ); + fillRect( rect, WHITE ); m_fillPaint.setTextSize( k_miniTextSize ); m_fillPaint.setTextAlign( Paint.Align.CENTER ); @@ -695,7 +727,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler, m_canvas.clipRect( rect ); if ( clearBack ) { - clearToBack( rect ); + fillRect( rect, WHITE ); } if ( isCursor || notEmpty ) { @@ -818,11 +850,6 @@ public class BoardView extends View implements DrawCtx, BoardHandler, m_canvas.drawRect( rect, m_fillPaint ); } - private void clearToBack( Rect rect ) - { - fillRect( rect, m_otherColors[CommonPrefs.COLOR_BKGND] ); - } - private void figureFontDims() { if ( null == m_fontDims ) { @@ -907,4 +934,25 @@ public class BoardView extends View implements DrawCtx, BoardHandler, m_strokePaint.setColor( curColor ); } } -} \ No newline at end of file + + private Drawable loadAndRecolor( int resID ) + { + Resources res = getResources(); + Drawable arrow = res.getDrawable( resID ); + + if ( ! m_blackArrow ) { + Bitmap src = ((BitmapDrawable)arrow).getBitmap(); + Bitmap bitmap = src.copy( Bitmap.Config.ARGB_8888, true ); + for ( int xx = 0; xx < bitmap.getWidth(); ++xx ) { + for( int yy = 0; yy < bitmap.getHeight(); ++yy ) { + if ( BLACK == bitmap.getPixel( xx, yy ) ) { + bitmap.setPixel( xx, yy, WHITE ); + } + } + } + + arrow = new BitmapDrawable(bitmap); + } + return arrow; + } +} diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java index 1d1d7feb4..a337c045f 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java @@ -35,7 +35,8 @@ public class CommonPrefs { public static final int COLOR_TILE_BACK = 0; public static final int COLOR_BKGND = 1; public static final int COLOR_FOCUS = 2; - public static final int COLOR_LAST = 3; + public static final int COLOR_FRAMES = 3; + public static final int COLOR_LAST = 4; private static CommonPrefs s_cp = null; @@ -103,6 +104,7 @@ public class CommonPrefs { int idsOther[] = { R.string.key_tile_back, R.string.key_empty, R.string.key_clr_crosshairs, + R.string.key_clr_frames, }; for ( int ii = 0; ii < idsOther.length; ++ii ) { otherColors[ii] = prefToColor( context, sp, idsOther[ii] ); @@ -253,6 +255,12 @@ public class CommonPrefs { return getPrefsBoolean( context, R.string.key_show_bonussum, false ); } + public static boolean getHiliteWhiteOnBlack( Context context ) + { + return getPrefsBoolean( context, R.string.key_hilite_whiteonblack, + true ); + } + public static boolean getPrefsBoolean( Context context, int keyID, boolean defaultValue ) { From 8d52149c28d1425086832e5c92081acd30763e2b Mon Sep 17 00:00:00 2001 From: Andy2 Date: Mon, 17 Jan 2011 20:39:35 -0800 Subject: [PATCH 05/12] cache the background color on which arrow is based so don't have to compute its blackness each time. --- .../org/eehouse/android/xw4/BoardView.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java index db2c5a4a3..31c9e2e8e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java @@ -65,6 +65,8 @@ public class BoardView extends View implements DrawCtx, BoardHandler, private Drawable m_rightArrow; private Drawable m_downArrow; private boolean m_blackArrow; + // m_backgroundUsed: alpha not set ensures inequality + private int m_backgroundUsed = 0x00000000; private Drawable m_origin; private int m_left, m_top; private JNIThread m_jniThread; @@ -524,15 +526,18 @@ public class BoardView extends View implements DrawCtx, BoardHandler, // figure out if the background is more dark than light int sum = 0; int background = m_otherColors[ CommonPrefs.COLOR_BKGND ]; - for ( int ii = 0; ii < 3; ++ii ) { - sum += background & 0xFF; - background >>= 8; - } - boolean blackArrow = sum > (127 * 3); + if ( background != m_backgroundUsed ) { + m_backgroundUsed = background; + for ( int ii = 0; ii < 3; ++ii ) { + sum += background & 0xFF; + background >>= 8; + } + boolean blackArrow = sum > (127 * 3); - if ( m_blackArrow != blackArrow ) { - m_blackArrow = blackArrow; - m_downArrow = m_rightArrow = null; + if ( m_blackArrow != blackArrow ) { + m_blackArrow = blackArrow; + m_downArrow = m_rightArrow = null; + } } if ( vert ) { if ( null == m_downArrow ) { From bce4a1159569c300370603389de3da6eb354b7ac Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 18 Jan 2011 18:42:25 -0800 Subject: [PATCH 06/12] more work on color prefs. Add a list pref at the same level as colors for setting "scheme". Implement that as changing potentially several colors but only empty cell color for now. Remove prefs for whether cell letters follow user colors (they always will) and the new one for frame color -- it'll always be dark grey. --- .../XWords4/res/values/common_rsrc.xml | 8 ++- .../android/XWords4/res/values/strings.xml | 9 ++-- xwords4/android/XWords4/res/xml/xwprefs.xml | 34 ++++++------- .../org/eehouse/android/xw4/BoardView.java | 51 +++++++++++-------- .../eehouse/android/xw4/PrefsActivity.java | 30 +++++++++++ .../eehouse/android/xw4/jni/CommonPrefs.java | 10 +--- 6 files changed, 86 insertions(+), 56 deletions(-) diff --git a/xwords4/android/XWords4/res/values/common_rsrc.xml b/xwords4/android/XWords4/res/values/common_rsrc.xml index d0271a566..529248ac1 100644 --- a/xwords4/android/XWords4/res/values/common_rsrc.xml +++ b/xwords4/android/XWords4/res/values/common_rsrc.xml @@ -25,8 +25,7 @@ key_clr_tile_back key_clr_empty key_clr_crosshairs - key_clr_frames - key_hilite_whiteonblack + key_board_theme key_relay_host key_relay_port2 key_proxy_port @@ -83,6 +82,11 @@ @string/robot_smart + + @string/black_on_white + @string/white_on_black + + @string/connect_thirty_seconds @string/connect_five_mins diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 5a86c102c..9b964e1c1 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -268,7 +268,7 @@ Choose - Colors + Individual colors Edit colors used on the board First player Second player @@ -287,10 +287,9 @@ Tile background Empty cell/background Crosshairs color - Border color - Last play white-on-black - Toggle recent move - contrast colors + Board color schemes + Dark background + Light background Advanced You may never need these... diff --git a/xwords4/android/XWords4/res/xml/xwprefs.xml b/xwords4/android/XWords4/res/xml/xwprefs.xml index 260f0713e..d0872209d 100644 --- a/xwords4/android/XWords4/res/xml/xwprefs.xml +++ b/xwords4/android/XWords4/res/xml/xwprefs.xml @@ -49,11 +49,11 @@ - + + + + + + + - - + >= 8; - } - boolean blackArrow = sum > (127 * 3); - - if ( m_blackArrow != blackArrow ) { - m_blackArrow = blackArrow; - m_downArrow = m_rightArrow = null; - } + boolean useDark = darkOnLight(); + if ( m_blackArrow != useDark ) { + m_blackArrow = useDark; + m_downArrow = m_rightArrow = null; } + Drawable arrow; if ( vert ) { if ( null == m_downArrow ) { - m_downArrow = loadAndRecolor( R.drawable.downarrow ); + m_downArrow = loadAndRecolor( R.drawable.downarrow, useDark ); } arrow = m_downArrow; } else { if ( null == m_rightArrow ) { - m_rightArrow = loadAndRecolor( R.drawable.rightarrow ); + m_rightArrow = loadAndRecolor( R.drawable.rightarrow, useDark ); } arrow = m_rightArrow; } @@ -940,12 +931,28 @@ public class BoardView extends View implements DrawCtx, BoardHandler, } } - private Drawable loadAndRecolor( int resID ) + private boolean darkOnLight() + { + int background = m_otherColors[ CommonPrefs.COLOR_BKGND ]; + if ( background != m_backgroundUsed ) { + m_backgroundUsed = background; + + int sum = 0; + for ( int ii = 0; ii < 3; ++ii ) { + sum += background & 0xFF; + background >>= 8; + } + m_darkOnLight = sum > (127*3); + } + return m_darkOnLight; + } + + private Drawable loadAndRecolor( int resID, boolean useDark ) { Resources res = getResources(); Drawable arrow = res.getDrawable( resID ); - if ( ! m_blackArrow ) { + if ( !useDark ) { Bitmap src = ((BitmapDrawable)arrow).getBitmap(); Bitmap bitmap = src.copy( Bitmap.Config.ARGB_8888, true ); for ( int xx = 0; xx < bitmap.getWidth(); ++xx ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java index ab6965b2b..ddfaa1064 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java @@ -39,6 +39,10 @@ public class PrefsActivity extends PreferenceActivity private static final int REVERT_ALL = 2; private String[] m_keys; + private String m_boardThemeKey; + private String m_keyEmpty; + private String m_whiteOnBlack; + private String m_blackOnWhite; @Override protected Dialog onCreateDialog( int id ) @@ -118,6 +122,7 @@ public class PrefsActivity extends PreferenceActivity R.string.key_initial_player_minutes, R.string.key_default_dict, R.string.key_default_phonies, + R.string.key_board_theme, }; SharedPreferences sp @@ -129,6 +134,10 @@ public class PrefsActivity extends PreferenceActivity setSummary( sp, key ); m_keys[ii] = key; } + m_boardThemeKey = getString( R.string.key_board_theme ); + m_keyEmpty = getString( R.string.key_empty ); + m_whiteOnBlack = getString( R.string.white_on_black ); + m_blackOnWhite = getString( R.string.black_on_white ); } @Override @@ -149,12 +158,33 @@ public class PrefsActivity extends PreferenceActivity public void onSharedPreferenceChanged( SharedPreferences sp, String key ) { + // This would search faster if it were a hash set... for ( String akey : m_keys ) { if ( akey.equals( key ) ) { setSummary( sp, key ); break; } } + + // Change those color elements that follow the "themes" -- + // currently only key_empty + while ( m_boardThemeKey.equals( key ) ) { // while allows break + String newValue = sp.getString( key, "" ); + + int color; + if ( m_whiteOnBlack.equals( newValue ) ) { + color = 0xFF000000; + } else if ( m_blackOnWhite.equals( newValue ) ) { + color = 0xFFFFFFFF; + } else { + break; + } + + SharedPreferences.Editor editor = sp.edit(); + editor.putInt( m_keyEmpty, color ); + editor.commit(); + break; + } } @Override diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java index a337c045f..1d1d7feb4 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java @@ -35,8 +35,7 @@ public class CommonPrefs { public static final int COLOR_TILE_BACK = 0; public static final int COLOR_BKGND = 1; public static final int COLOR_FOCUS = 2; - public static final int COLOR_FRAMES = 3; - public static final int COLOR_LAST = 4; + public static final int COLOR_LAST = 3; private static CommonPrefs s_cp = null; @@ -104,7 +103,6 @@ public class CommonPrefs { int idsOther[] = { R.string.key_tile_back, R.string.key_empty, R.string.key_clr_crosshairs, - R.string.key_clr_frames, }; for ( int ii = 0; ii < idsOther.length; ++ii ) { otherColors[ii] = prefToColor( context, sp, idsOther[ii] ); @@ -255,12 +253,6 @@ public class CommonPrefs { return getPrefsBoolean( context, R.string.key_show_bonussum, false ); } - public static boolean getHiliteWhiteOnBlack( Context context ) - { - return getPrefsBoolean( context, R.string.key_hilite_whiteonblack, - true ); - } - public static boolean getPrefsBoolean( Context context, int keyID, boolean defaultValue ) { From f6b95f93a185d7ad278d5029571cdcc0ab12365b Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 18 Jan 2011 18:47:24 -0800 Subject: [PATCH 07/12] use HashSet rather than String[] for faster lookup. --- .../org/eehouse/android/xw4/PrefsActivity.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java index ddfaa1064..f3c1d9b5b 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsActivity.java @@ -31,6 +31,7 @@ import android.preference.PreferenceManager; import android.view.Menu; import android.view.MenuItem; import android.view.MenuInflater; +import java.util.HashSet; public class PrefsActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -38,7 +39,7 @@ public class PrefsActivity extends PreferenceActivity private static final int REVERT_COLORS = 1; private static final int REVERT_ALL = 2; - private String[] m_keys; + private HashSet m_keys; private String m_boardThemeKey; private String m_keyEmpty; private String m_whiteOnBlack; @@ -127,12 +128,12 @@ public class PrefsActivity extends PreferenceActivity SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences( this ); - m_keys = new String[ textKeyIds.length ]; + m_keys = new HashSet( textKeyIds.length ); for ( int ii = 0; ii < textKeyIds.length; ++ii ) { int id = textKeyIds[ii]; String key = getString( id ); setSummary( sp, key ); - m_keys[ii] = key; + m_keys.add( key ); } m_boardThemeKey = getString( R.string.key_board_theme ); m_keyEmpty = getString( R.string.key_empty ); @@ -158,12 +159,8 @@ public class PrefsActivity extends PreferenceActivity public void onSharedPreferenceChanged( SharedPreferences sp, String key ) { - // This would search faster if it were a hash set... - for ( String akey : m_keys ) { - if ( akey.equals( key ) ) { - setSummary( sp, key ); - break; - } + if ( m_keys.contains( key ) ) { + setSummary( sp, key ); } // Change those color elements that follow the "themes" -- From 46f085f479b1a2fee8379949296ebbfea100f58a Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 18 Jan 2011 21:18:21 -0800 Subject: [PATCH 08/12] drop rather than asserting failure when unable to create a dialog. --- .../XWords4/src/org/eehouse/android/xw4/BoardActivity.java | 3 ++- .../android/XWords4/src/org/eehouse/android/xw4/GamesList.java | 2 +- 2 files changed, 3 insertions(+), 2 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 524d639a9..2d846bd00 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -252,7 +252,8 @@ public class BoardActivity extends XWActivity implements UtilCtxt { break; default: - Assert.assertTrue( false ); + // just drop it; super.onCreateDialog likely failed + break; } } return dialog; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java index a12a0caf2..824009508 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -134,7 +134,7 @@ public class GamesList extends XWListActivity }); break; default: - Assert.fail(); + // just drop it; super.onCreateDialog likely failed break; } } From 7f866da8da345e9a127b123e4709244d02c77c1b Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 18 Jan 2011 22:03:17 -0800 Subject: [PATCH 09/12] draw dragged tiles translucent --- .../XWords4/src/org/eehouse/android/xw4/BoardView.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java index 0a5f53291..73b05b879 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java @@ -727,12 +727,12 @@ public class BoardView extends View implements DrawCtx, BoardHandler, } if ( isCursor || notEmpty ) { - - if ( clearBack ) { - int indx = isCursor? CommonPrefs.COLOR_FOCUS - : CommonPrefs.COLOR_TILE_BACK; - fillRect( rect, m_otherColors[indx] ); + int color = m_otherColors[isCursor? CommonPrefs.COLOR_FOCUS + : CommonPrefs.COLOR_TILE_BACK]; + if ( !clearBack ) { + color &= 0x7FFFFFFF; // translucent if being dragged. } + fillRect( rect, color ); m_fillPaint.setColor( m_playerColors[m_trayOwner] ); From a9c65aa950897b144e4063f56ee701ea48e9398f Mon Sep 17 00:00:00 2001 From: "eehouse@eehouse.org" Date: Wed, 19 Jan 2011 06:19:33 -0800 Subject: [PATCH 10/12] Revert "add ctime and mtime timestamps to DB when creating, and upgrade to new" This reverts commit 465370bac6c6eb642817454b06090c4961e5d8d7. Better to work with the existing timestamps as ints than mess with largely unsupported TIMESTAMP type. --- .../src/org/eehouse/android/xw4/DBHelper.java | 34 ++++--------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java index 515e02aa1..5e34e8c6a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java @@ -29,7 +29,7 @@ public class DBHelper extends SQLiteOpenHelper { public static final String TABLE_NAME_SUM = "summaries"; public static final String TABLE_NAME_OBITS = "obits"; private static final String DB_NAME = "xwdb"; - private static final int DB_VERSION = 7; + private static final int DB_VERSION = 6; public static final String FILE_NAME = "FILE_NAME"; public static final String NUM_MOVES = "NUM_MOVES"; @@ -52,10 +52,9 @@ public class DBHelper extends SQLiteOpenHelper { public static final String SEED = "SEED"; public static final String SMSPHONE = "SMSPHONE"; // not used yet - // public static final String CREATE_TIME = "CREATE_TIME"; - public static final String CTIME = "CTIME"; + public static final String CREATE_TIME = "CREATE_TIME"; // not used yet - public static final String MTIME = "MTIME"; + public static final String LASTPLAY_TIME = "LASTPLAY_TIME"; public DBHelper( Context context ) @@ -86,11 +85,8 @@ public class DBHelper extends SQLiteOpenHelper { // HASMSGS: sqlite doesn't have bool; use 0 and 1 + HASMSGS + " INTEGER DEFAULT 0," - + CTIME + " TIMESTAMP," - + MTIME + " TIMESTAMP," - - // + CREATE_TIME + " INTEGER," - // + LASTPLAY_TIME + " INTEGER," + + CREATE_TIME + " INTEGER," + + LASTPLAY_TIME + " INTEGER," + SNAPSHOT + " BLOB" + ");" ); @@ -116,24 +112,8 @@ public class DBHelper extends SQLiteOpenHelper { { Utils.logf( "onUpgrade: old: %d; new: %d", oldVersion, newVersion ); - if ( newVersion == 7 ) { - switch( oldVersion ) { - case 5: - onCreateObits( db ); - // FALLTHRU - case 6: - // F*cking sqlite won't let me add a column with a - // non-constant default (i.e. DEFAULT - // (datetime('now','localtime'))," so I'll have to add - // the value manually. Or screw everybody and nuke - // the DB rather than modify it. I want my - // postgres... - db.execSQL( "ALTER TABLE " + TABLE_NAME_SUM + - " ADD " + CTIME + " TIMESTAMP;" ); - db.execSQL( "ALTER TABLE " + TABLE_NAME_SUM - + " ADD " + MTIME + " TIMESTAMP;" ); - break; - } + if ( newVersion == 6 && oldVersion == 5 ) { + onCreateObits(db); } else { db.execSQL( "DROP TABLE " + TABLE_NAME_SUM + ";" ); if ( oldVersion >= 6 ) { From 7d6e136ca3683b874d47abde8e8141568dfe47fb Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 19 Jan 2011 06:21:31 -0800 Subject: [PATCH 11/12] fix comment --- xwords4/common/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwords4/common/server.c b/xwords4/common/server.c index 8313960ab..517ec69ed 100644 --- a/xwords4/common/server.c +++ b/xwords4/common/server.c @@ -1689,7 +1689,7 @@ server_setGameOverListener( ServerCtxt* server, GameOverListener gol, { server->vol.gameOverListener = gol; server->vol.gameOverData = data; -} /* server_setTurnChangeListener */ +} /* server_setGameOverListener */ static XP_Bool storeBadWords( XP_UCHAR* word, void* closure ) From a8f4d772f8f59b087600d7fa1a861672465f890c Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 19 Jan 2011 06:54:23 -0800 Subject: [PATCH 12/12] set one timestamp when saving game, and another on game creation. --- .../src/org/eehouse/android/xw4/DBUtils.java | 10 +++++++++- .../eehouse/android/xw4/GameConverter.java | 2 +- .../org/eehouse/android/xw4/GameUtils.java | 20 ++++++++++--------- .../eehouse/android/xw4/jni/JNIThread.java | 2 +- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java index a5b2aaaaf..d191b835a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -27,6 +27,7 @@ import android.database.Cursor; import java.util.StringTokenizer; import android.content.ContentValues; import java.util.ArrayList; +import java.util.Date; import junit.framework.Assert; import org.eehouse.android.xw4.jni.*; @@ -356,7 +357,8 @@ public class DBUtils { } } - public static void saveGame( Context context, String path, byte[] bytes ) + public static void saveGame( Context context, String path, byte[] bytes, + boolean setCreate ) { initDB( context ); synchronized( s_dbHelper ) { @@ -366,6 +368,12 @@ public class DBUtils { ContentValues values = new ContentValues(); values.put( DBHelper.SNAPSHOT, bytes ); + long timestamp = new Date().getTime(); + if ( setCreate ) { + values.put( DBHelper.CREATE_TIME, timestamp ); + } + values.put( DBHelper.LASTPLAY_TIME, timestamp ); + int result = db.update( DBHelper.TABLE_NAME_SUM, values, selection, null ); if ( 0 == result ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConverter.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConverter.java index e522de498..09513218c 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConverter.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConverter.java @@ -37,7 +37,7 @@ public class GameConverter { Utils.logf( "GameConverter::convert() converting %s", game ); byte[] bytes = savedGame( context, game ); - DBUtils.saveGame( context, game, bytes ); + DBUtils.saveGame( context, game, bytes, true ); context.deleteFile( game ); } } 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 0216bdda0..90f31f2f5 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -79,7 +79,7 @@ public class GameUtils { if ( null != addr ) { XwJNI.comms_setAddr( gamePtr, addr ); } - saveGame( context, gamePtr, gi, pathOut ); + saveGame( context, gamePtr, gi, pathOut, true ); GameSummary summary = new GameSummary( gi ); XwJNI.game_summarize( gamePtr, summary ); @@ -142,27 +142,29 @@ public class GameUtils { } public static void saveGame( Context context, int gamePtr, - CurGameInfo gi, String path ) + CurGameInfo gi, String path, + boolean setCreate ) { byte[] stream = XwJNI.game_saveToStream( gamePtr, gi ); - saveGame( context, stream, path ); + saveGame( context, stream, path, setCreate ); } public static void saveGame( Context context, int gamePtr, CurGameInfo gi ) { - saveGame( context, gamePtr, gi, newName( context ) ); + saveGame( context, gamePtr, gi, newName( context ), false ); } - public static void saveGame( Context context, byte[] bytes, String path ) + public static void saveGame( Context context, byte[] bytes, + String path, boolean setCreate ) { - DBUtils.saveGame( context, path, bytes ); + DBUtils.saveGame( context, path, bytes, setCreate ); } public static String saveGame( Context context, byte[] bytes ) { String name = newName( context ); - saveGame( context, bytes, name ); + saveGame( context, bytes, name, false ); return name; } @@ -372,7 +374,7 @@ public class GameUtils { CommonPrefs.get( context ) ); gi.dictName = dict; - saveGame( context, gamePtr, gi, path ); + saveGame( context, gamePtr, gi, path, false ); GameSummary summary = new GameSummary( gi ); XwJNI.game_summarize( gamePtr, summary ); @@ -415,7 +417,7 @@ public class GameUtils { XwJNI.comms_setAddr( gamePtr, car ); } - GameUtils.saveGame( context, gamePtr, gi, path ); + saveGame( context, gamePtr, gi, path, false ); GameSummary summary = new GameSummary( gi ); XwJNI.game_summarize( gamePtr, summary ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java index ec2e4d6f6..446081617 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java @@ -262,7 +262,7 @@ public class JNIThread extends Thread { GameSummary summary = new GameSummary( m_gi ); XwJNI.game_summarize( m_jniGamePtr, summary ); byte[] state = XwJNI.game_saveToStream( m_jniGamePtr, null ); - GameUtils.saveGame( m_context, state, m_path ); + GameUtils.saveGame( m_context, state, m_path, false ); DBUtils.saveSummary( m_context, m_path, summary ); break;