From a6d8a74102420ab8bcaff7857099f3a304797bd4 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 22 May 2014 23:35:51 -0700 Subject: [PATCH] move a few methods, and add utilities, to superclass. --- .../eehouse/android/xw4/BoardDelegate.java | 18 +++++------ .../org/eehouse/android/xw4/DelegateBase.java | 30 +++++++++++++++++++ .../android/xw4/DictImportDelegate.java | 2 +- .../eehouse/android/xw4/DictsDelegate.java | 5 ++-- .../android/xw4/GameConfigDelegate.java | 3 +- .../android/xw4/GamesListDelegate.java | 4 +-- .../eehouse/android/xw4/PrefsDelegate.java | 2 +- .../android/xw4/StudyListDelegate.java | 4 +-- 8 files changed, 48 insertions(+), 20 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java index 6ba976d94..da75df009 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java @@ -510,7 +510,7 @@ public class BoardDelegate extends DelegateBase if ( CommonPrefs.getHideTitleBar( m_activity ) && ABUtils.haveMenuKey( m_activity ) ) { - m_activity.requestWindowFeature( Window.FEATURE_NO_TITLE ); + requestWindowFeature( Window.FEATURE_NO_TITLE ); } if ( BuildConstants.CHAT_SUPPORTED ) { @@ -930,7 +930,7 @@ public class BoardDelegate extends DelegateBase cmd = JNICmd.CMD_COMMIT; break; case SHOW_EXPL_ACTION: - Utils.showToast( m_activity, m_toastStr ); + showToast( m_toastStr ); m_toastStr = null; break; case BUTTON_BROWSEALL_ACTION: @@ -968,7 +968,7 @@ public class BoardDelegate extends DelegateBase startChatActivity(); break; case START_TRADE_ACTION: - Utils.showToast( m_activity, R.string.entering_trade ); + showToast( R.string.entering_trade ); cmd = JNICmd.CMD_TRADE; break; case LOOKUP_ACTION: @@ -1122,7 +1122,7 @@ public class BoardDelegate extends DelegateBase } if ( doToast ) { - Utils.showToast( m_activity, strID ); + showToast( strID ); } else if ( dlgID != DlgID.NONE ) { final int strIDf = strID; final DlgID dlgIDf = dlgID; @@ -1173,7 +1173,7 @@ public class BoardDelegate extends DelegateBase ////////////////////////////////////////////////// public void invalidateParent() { - m_activity.runOnUiThread(new Runnable() { + runOnUiThread(new Runnable() { public void run() { m_view.invalidate(); } @@ -1202,7 +1202,7 @@ public class BoardDelegate extends DelegateBase m_jniThread.setSaveDict( getDict ); String msg = getString( R.string.reload_new_dict_fmt, getDict ); - Utils.showToast( m_activity, msg ); + showToast( msg ); finish(); GameUtils.launchGame( m_activity, m_rowid, false ); } @@ -1400,7 +1400,7 @@ public class BoardDelegate extends DelegateBase final String bonusStr = getString( id ); post( new Runnable() { public void run() { - Utils.showToast( m_activity, bonusStr ); + showToast( bonusStr ); } } ); } @@ -1418,7 +1418,7 @@ public class BoardDelegate extends DelegateBase final String text = String.format( "%s\n%s", name, expl ); post( new Runnable() { public void run() { - Utils.showToast( m_activity, text ); + showToast( text ); } } ); } @@ -1983,7 +1983,7 @@ public class BoardDelegate extends DelegateBase DbgUtils.loge( ie ); if ( DlgID.NONE != m_blockingDlgID ) { try { - m_activity.dismissDialog( m_blockingDlgID.ordinal() ); + dismissDialog( m_blockingDlgID ); } catch ( java.lang.IllegalArgumentException iae ) { DbgUtils.loge( iae ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java index 66d0ab630..3c57fcfbb 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DelegateBase.java @@ -162,6 +162,31 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify, ABUtils.invalidateOptionsMenuIf( m_activity ); } + public void showToast( int msg ) + { + Utils.showToast( m_activity, msg ); + } + + public void showToast( String msg ) + { + Utils.showToast( m_activity, msg ); + } + + public boolean requestWindowFeature( int feature ) + { + return m_activity.requestWindowFeature( feature ); + } + + public Object getSystemService( String name ) + { + return m_activity.getSystemService( name ); + } + + public void runOnUiThread( Runnable runnable ) + { + m_activity.runOnUiThread( runnable ); + } + protected void showDialog( DlgID dlgID ) { m_delegate.showDialog( dlgID ); @@ -172,6 +197,11 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify, removeDialog( dlgID.ordinal() ); } + protected void dismissDialog( DlgID dlgID ) + { + m_activity.dismissDialog( dlgID.ordinal() ); + } + protected void removeDialog( int id ) { m_activity.removeDialog( id ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictImportDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictImportDelegate.java index 89e37510e..482940dc9 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictImportDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictImportDelegate.java @@ -176,7 +176,7 @@ public class DictImportDelegate extends DelegateBase { m_handler = new Handler(); - m_activity.requestWindowFeature( Window.FEATURE_LEFT_ICON ); + requestWindowFeature( Window.FEATURE_LEFT_ICON ); setContentView( R.layout.import_dict ); m_activity.getWindow().setFeatureDrawableResource( Window.FEATURE_LEFT_ICON, R.drawable.icon48x48 ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java index c49bdedc9..24fb6b52d 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java @@ -645,7 +645,7 @@ public class DictsDelegate extends DelegateBase try { startActivity( downloadIntent ); } catch ( android.content.ActivityNotFoundException anfe ) { - Utils.showToast( m_activity, R.string.no_download_warning ); + showToast( R.string.no_download_warning ); } } @@ -790,8 +790,7 @@ public class DictsDelegate extends DelegateBase finish(); } } else { - Utils.showToast( m_activity, - R.string.download_failed ); + showToast( R.string.download_failed ); } } } ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java index b98a46b71..e43b549e7 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java @@ -216,8 +216,7 @@ public class GameConfigDelegate extends DelegateBase public void onDismiss( DialogInterface di ) { if ( m_gi.forceRemoteConsistent() ) { - Utils.showToast( m_activity, - R.string.forced_consistent ); + showToast( R.string.forced_consistent ); loadPlayersList(); } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java index 50cb7ad7b..f5bfc21ac 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -453,7 +453,7 @@ public class GamesListDelegate extends ListDelegateBase // DBUtils.DBChangeListener interface public void gameSaved( final long rowid, final boolean countChanged ) { - m_activity.runOnUiThread( new Runnable() { + runOnUiThread( new Runnable() { public void run() { if ( countChanged || DBUtils.ROWID_NOTFOUND == rowid ) { onContentChanged(); @@ -902,7 +902,7 @@ public class GamesListDelegate extends ListDelegateBase if ( ! madeGame ) { int id = success ? R.string.download_done : R.string.download_failed; - Utils.showToast( m_activity, id ); + showToast( id ); } } } ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsDelegate.java index 352389ed2..fd9c93662 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/PrefsDelegate.java @@ -203,7 +203,7 @@ public class PrefsDelegate extends DelegateBase msg = String.format( "Cannot write to %s", value ); } if ( null != msg ) { - Utils.showToast( m_activity, msg ); + showToast( msg ); } } DictUtils.invalDictList(); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyListDelegate.java index 65f6e7c6f..d9dda4f77 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyListDelegate.java @@ -166,12 +166,12 @@ public class StudyListDelegate extends ListDelegateBase case SL_COPY_ACTION: selWords = getSelWords(); ClipboardManager clipboard = (ClipboardManager) - m_activity.getSystemService( Context.CLIPBOARD_SERVICE ); + getSystemService( Context.CLIPBOARD_SERVICE ); clipboard.setText( TextUtils.join( "\n", selWords ) ); String msg = getString( R.string.paste_done_fmt, selWords.length ); - Utils.showToast( m_activity, msg ); + showToast( msg ); break; default: Assert.fail();