move a few methods, and add utilities, to superclass.

This commit is contained in:
Eric House 2014-05-22 23:35:51 -07:00
parent 4b26e04691
commit a6d8a74102
8 changed files with 48 additions and 20 deletions

View file

@ -510,7 +510,7 @@ public class BoardDelegate extends DelegateBase
if ( CommonPrefs.getHideTitleBar( m_activity ) if ( CommonPrefs.getHideTitleBar( m_activity )
&& ABUtils.haveMenuKey( m_activity ) ) { && ABUtils.haveMenuKey( m_activity ) ) {
m_activity.requestWindowFeature( Window.FEATURE_NO_TITLE ); requestWindowFeature( Window.FEATURE_NO_TITLE );
} }
if ( BuildConstants.CHAT_SUPPORTED ) { if ( BuildConstants.CHAT_SUPPORTED ) {
@ -930,7 +930,7 @@ public class BoardDelegate extends DelegateBase
cmd = JNICmd.CMD_COMMIT; cmd = JNICmd.CMD_COMMIT;
break; break;
case SHOW_EXPL_ACTION: case SHOW_EXPL_ACTION:
Utils.showToast( m_activity, m_toastStr ); showToast( m_toastStr );
m_toastStr = null; m_toastStr = null;
break; break;
case BUTTON_BROWSEALL_ACTION: case BUTTON_BROWSEALL_ACTION:
@ -968,7 +968,7 @@ public class BoardDelegate extends DelegateBase
startChatActivity(); startChatActivity();
break; break;
case START_TRADE_ACTION: case START_TRADE_ACTION:
Utils.showToast( m_activity, R.string.entering_trade ); showToast( R.string.entering_trade );
cmd = JNICmd.CMD_TRADE; cmd = JNICmd.CMD_TRADE;
break; break;
case LOOKUP_ACTION: case LOOKUP_ACTION:
@ -1122,7 +1122,7 @@ public class BoardDelegate extends DelegateBase
} }
if ( doToast ) { if ( doToast ) {
Utils.showToast( m_activity, strID ); showToast( strID );
} else if ( dlgID != DlgID.NONE ) { } else if ( dlgID != DlgID.NONE ) {
final int strIDf = strID; final int strIDf = strID;
final DlgID dlgIDf = dlgID; final DlgID dlgIDf = dlgID;
@ -1173,7 +1173,7 @@ public class BoardDelegate extends DelegateBase
////////////////////////////////////////////////// //////////////////////////////////////////////////
public void invalidateParent() public void invalidateParent()
{ {
m_activity.runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
m_view.invalidate(); m_view.invalidate();
} }
@ -1202,7 +1202,7 @@ public class BoardDelegate extends DelegateBase
m_jniThread.setSaveDict( getDict ); m_jniThread.setSaveDict( getDict );
String msg = getString( R.string.reload_new_dict_fmt, getDict ); String msg = getString( R.string.reload_new_dict_fmt, getDict );
Utils.showToast( m_activity, msg ); showToast( msg );
finish(); finish();
GameUtils.launchGame( m_activity, m_rowid, false ); GameUtils.launchGame( m_activity, m_rowid, false );
} }
@ -1400,7 +1400,7 @@ public class BoardDelegate extends DelegateBase
final String bonusStr = getString( id ); final String bonusStr = getString( id );
post( new Runnable() { post( new Runnable() {
public void run() { 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 ); final String text = String.format( "%s\n%s", name, expl );
post( new Runnable() { post( new Runnable() {
public void run() { public void run() {
Utils.showToast( m_activity, text ); showToast( text );
} }
} ); } );
} }
@ -1983,7 +1983,7 @@ public class BoardDelegate extends DelegateBase
DbgUtils.loge( ie ); DbgUtils.loge( ie );
if ( DlgID.NONE != m_blockingDlgID ) { if ( DlgID.NONE != m_blockingDlgID ) {
try { try {
m_activity.dismissDialog( m_blockingDlgID.ordinal() ); dismissDialog( m_blockingDlgID );
} catch ( java.lang.IllegalArgumentException iae ) { } catch ( java.lang.IllegalArgumentException iae ) {
DbgUtils.loge( iae ); DbgUtils.loge( iae );
} }

View file

@ -162,6 +162,31 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify,
ABUtils.invalidateOptionsMenuIf( m_activity ); 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 ) protected void showDialog( DlgID dlgID )
{ {
m_delegate.showDialog( dlgID ); m_delegate.showDialog( dlgID );
@ -172,6 +197,11 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify,
removeDialog( dlgID.ordinal() ); removeDialog( dlgID.ordinal() );
} }
protected void dismissDialog( DlgID dlgID )
{
m_activity.dismissDialog( dlgID.ordinal() );
}
protected void removeDialog( int id ) protected void removeDialog( int id )
{ {
m_activity.removeDialog( id ); m_activity.removeDialog( id );

View file

@ -176,7 +176,7 @@ public class DictImportDelegate extends DelegateBase {
m_handler = new Handler(); m_handler = new Handler();
m_activity.requestWindowFeature( Window.FEATURE_LEFT_ICON ); requestWindowFeature( Window.FEATURE_LEFT_ICON );
setContentView( R.layout.import_dict ); setContentView( R.layout.import_dict );
m_activity.getWindow().setFeatureDrawableResource( Window.FEATURE_LEFT_ICON, m_activity.getWindow().setFeatureDrawableResource( Window.FEATURE_LEFT_ICON,
R.drawable.icon48x48 ); R.drawable.icon48x48 );

View file

@ -645,7 +645,7 @@ public class DictsDelegate extends DelegateBase
try { try {
startActivity( downloadIntent ); startActivity( downloadIntent );
} catch ( android.content.ActivityNotFoundException anfe ) { } 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(); finish();
} }
} else { } else {
Utils.showToast( m_activity, showToast( R.string.download_failed );
R.string.download_failed );
} }
} }
} ); } );

View file

@ -216,8 +216,7 @@ public class GameConfigDelegate extends DelegateBase
public void onDismiss( DialogInterface di ) public void onDismiss( DialogInterface di )
{ {
if ( m_gi.forceRemoteConsistent() ) { if ( m_gi.forceRemoteConsistent() ) {
Utils.showToast( m_activity, showToast( R.string.forced_consistent );
R.string.forced_consistent );
loadPlayersList(); loadPlayersList();
} }
} }

View file

@ -453,7 +453,7 @@ public class GamesListDelegate extends ListDelegateBase
// DBUtils.DBChangeListener interface // DBUtils.DBChangeListener interface
public void gameSaved( final long rowid, final boolean countChanged ) public void gameSaved( final long rowid, final boolean countChanged )
{ {
m_activity.runOnUiThread( new Runnable() { runOnUiThread( new Runnable() {
public void run() { public void run() {
if ( countChanged || DBUtils.ROWID_NOTFOUND == rowid ) { if ( countChanged || DBUtils.ROWID_NOTFOUND == rowid ) {
onContentChanged(); onContentChanged();
@ -902,7 +902,7 @@ public class GamesListDelegate extends ListDelegateBase
if ( ! madeGame ) { if ( ! madeGame ) {
int id = success ? R.string.download_done int id = success ? R.string.download_done
: R.string.download_failed; : R.string.download_failed;
Utils.showToast( m_activity, id ); showToast( id );
} }
} }
} ); } );

View file

@ -203,7 +203,7 @@ public class PrefsDelegate extends DelegateBase
msg = String.format( "Cannot write to %s", value ); msg = String.format( "Cannot write to %s", value );
} }
if ( null != msg ) { if ( null != msg ) {
Utils.showToast( m_activity, msg ); showToast( msg );
} }
} }
DictUtils.invalDictList(); DictUtils.invalDictList();

View file

@ -166,12 +166,12 @@ public class StudyListDelegate extends ListDelegateBase
case SL_COPY_ACTION: case SL_COPY_ACTION:
selWords = getSelWords(); selWords = getSelWords();
ClipboardManager clipboard = (ClipboardManager) ClipboardManager clipboard = (ClipboardManager)
m_activity.getSystemService( Context.CLIPBOARD_SERVICE ); getSystemService( Context.CLIPBOARD_SERVICE );
clipboard.setText( TextUtils.join( "\n", selWords ) ); clipboard.setText( TextUtils.join( "\n", selWords ) );
String msg = getString( R.string.paste_done_fmt, String msg = getString( R.string.paste_done_fmt,
selWords.length ); selWords.length );
Utils.showToast( m_activity, msg ); showToast( msg );
break; break;
default: default:
Assert.fail(); Assert.fail();