From adab1b5cea6f1c9b67b186f4e419483182f79b7e Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 30 Aug 2012 19:18:08 -0700 Subject: [PATCH] replace getString() calls that fetch format strings then apply them with calls to the formatting (varargs) version of getString(). Should be no behavior change. --- .../eehouse/android/xw4/BoardActivity.java | 17 ++++++----------- .../org/eehouse/android/xw4/ChatActivity.java | 4 ++-- .../android/xw4/DictImportActivity.java | 4 ++-- .../eehouse/android/xw4/DictsActivity.java | 16 +++++++--------- .../org/eehouse/android/xw4/GameConfig.java | 19 ++++++++----------- .../eehouse/android/xw4/GameListAdapter.java | 5 ++--- .../org/eehouse/android/xw4/GameUtils.java | 6 ++---- .../org/eehouse/android/xw4/GamesList.java | 17 ++++++++--------- .../eehouse/android/xw4/NetLaunchInfo.java | 5 ++--- .../eehouse/android/xw4/NewGameActivity.java | 3 +-- .../eehouse/android/xw4/RefreshNamesTask.java | 7 +++---- .../android/xw4/RelayGameActivity.java | 3 +-- .../src/org/eehouse/android/xw4/Utils.java | 3 +-- 13 files changed, 45 insertions(+), 64 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 d72dad257..e9d14ce29 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -425,8 +425,7 @@ public class BoardActivity extends XWActivity switch( id ) { case DLG_INVITE: AlertDialog ad = (AlertDialog)dialog; - String format = getString( R.string.invite_msgf ); - String message = String.format( format, m_missing ); + String message = getString( R.string.invite_msgf, m_missing ); if ( m_missing > 1 ) { message += getString( R.string.invite_multiple ); } @@ -1097,8 +1096,7 @@ public class BoardActivity extends XWActivity // All players have now joined the game. The device that // created the room will assign tiles. Then it will be // the first player's turn - String fmt = getString( R.string.msg_relay_all_heref ); - str = String.format( fmt, room ); + str = getString( R.string.msg_relay_all_heref, room ); if ( devOrder > 1 ) { naMsg = R.string.not_again_conndall; naKey = R.string.key_notagain_conndall; @@ -1113,9 +1111,8 @@ public class BoardActivity extends XWActivity m_missing = nMissing; showDialog( DLG_INVITE ); } else { - String fmt = getString( R.string.msg_relay_waiting ); - str = String.format( fmt, devOrder, - room, nMissing ); + str = getString( R.string.msg_relay_waiting, devOrder, + room, nMissing ); if ( devOrder == 1 ) { naMsg = R.string.not_again_conndfirst; naKey = R.string.key_notagain_conndfirst; @@ -1502,8 +1499,7 @@ public class BoardActivity extends XWActivity sb.append( "; " ); } - String format = getString( R.string.ids_badwords ); - String message = String.format( format, sb.toString() ); + String message = getString( R.string.ids_badwords, sb.toString() ); if ( turnLost ) { nonBlockingDialog( DLG_BADWORDS, @@ -1991,8 +1987,7 @@ public class BoardActivity extends XWActivity private void setupPasswdVars() { - String fmt = getString( R.string.msg_ask_password ); - m_dlgTitleStr = String.format( fmt, m_pwdName ); + m_dlgTitleStr = getString( R.string.msg_ask_password, m_pwdName ); m_passwdLyt = (LinearLayout)Utils.inflate( BoardActivity.this, R.layout.passwd_view ); m_passwdEdit = (EditText)m_passwdLyt.findViewById( R.id.edit ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java index 2a4c5543b..a76f94ba3 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java @@ -64,8 +64,8 @@ public class ChatActivity extends XWActivity implements View.OnClickListener { ((Button)findViewById( R.id.send_button )).setOnClickListener( this ); - String fmt = getString( R.string.chat_titlef ); - setTitle( String.format( fmt, GameUtils.getName( this, m_rowid ) ) ); + setTitle( getString( R.string.chat_titlef, + GameUtils.getName( this, m_rowid ) ) ); } @Override diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictImportActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictImportActivity.java index e94b0b50c..73c4f1748 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictImportActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictImportActivity.java @@ -108,8 +108,8 @@ public class DictImportActivity extends XWActivity { DbgUtils.logf( "based on MIME type" ); new DownloadFilesTask().execute( uri ); } else if ( uri.toString().endsWith( XWConstants.DICT_EXTN ) ) { - String fmt = getString( R.string.downloading_dictf ); - String txt = String.format( fmt, basename( uri.getPath()) ); + String txt = getString( R.string.downloading_dictf, + basename( uri.getPath()) ); TextView view = (TextView)findViewById( R.id.dwnld_message ); view.setText( txt ); new DownloadFilesTask().execute( uri ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java index 53811f187..9680b8737 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java @@ -337,8 +337,7 @@ public class DictsActivity extends ExpandableListActivity XWListItem rowView = m_adapter.getSelChildView(); String lang = DictLangCache.getLangName( this, rowView.getText() ); - format = getString( R.string.set_default_messagef ); - message = String.format( format, lang ); + message = getString( R.string.set_default_messagef, lang ); dialog = new AlertDialog.Builder( this ) .setTitle( R.string.query_title ) .setMessage( message ) @@ -507,8 +506,9 @@ public class DictsActivity extends ExpandableListActivity menu.removeItem( R.id.dicts_item_move ); } - String fmt = getString(R.string.game_item_menu_titlef ); - menu.setHeaderTitle( String.format( fmt, row.getText() ) ); + String title = getString( R.string.game_item_menu_titlef, + row.getText() ); + menu.setHeaderTitle( title ); } } @@ -575,8 +575,7 @@ public class DictsActivity extends ExpandableListActivity public void deleteCalled( XWListItem item ) { String dict = item.getText(); - String msg = String.format( getString( R.string.confirm_delete_dictf ), - dict ); + String msg = getString( R.string.confirm_delete_dictf, dict ); m_deleteDict = dict; m_moveFromLoc = (DictUtils.DictLoc)item.getCached(); @@ -605,9 +604,8 @@ public class DictsActivity extends ExpandableListActivity fmtid = R.string.confirm_deletemore_dictf; } if ( 0 != fmtid ) { - String fmt = getString( fmtid ); - msg += String.format( fmt, DictLangCache. - getLangName( this, langcode ) ); + msg += getString( fmtid, DictLangCache. + getLangName( this, langcode ) ); } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java index 63f4680df..d0693db28 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java @@ -261,10 +261,9 @@ public class GameConfig extends XWActivity }); break; case NO_NAME_FOUND: - String format = getString( R.string.no_name_found_f ); - String msg = - String.format( format, m_gi.nPlayers, DictLangCache. - getLangName( this, m_gi.dictLang ) ); + String msg = getString( R.string.no_name_found_f, + m_gi.nPlayers, DictLangCache. + getLangName( this, m_gi.dictLang ) ); dialog = new AlertDialog.Builder( this ) .setPositiveButton( R.string.button_ok, null ) // message added below since varies with language etc. @@ -315,8 +314,7 @@ public class GameConfig extends XWActivity // Dicts spinner with label String langName = DictLangCache.getLangName( this, m_gi.dictLang ); - String label = String.format( getString( R.string.dict_lang_labelf ), - langName ); + String label = getString( R.string.dict_lang_labelf, langName ); TextView text = (TextView)dialog.findViewById( R.id.dict_label ); text.setText( label ); configDictSpinner( dialog, lp ); @@ -724,9 +722,8 @@ public class GameConfig extends XWActivity { Spinner dictsSpinner = (Spinner)dialog.findViewById( R.id.dict_spinner ); - String fmt = getString( R.string.dicts_list_promptf ); String lang = DictLangCache.getLangName( this, m_gi.dictLang ); - dictsSpinner.setPrompt(String.format( fmt, lang ) ); + dictsSpinner.setPrompt( getString( R.string.dicts_list_promptf, lang ) ); OnItemSelectedListener onSel = new OnItemSelectedListener() { @@ -922,10 +919,10 @@ public class GameConfig extends XWActivity if ( localOnlyGame() ) { label = getString( R.string.players_label_standalone ); } else { - String fmt = getString( R.string.players_label_host ); int remoteCount = m_gi.remoteCount(); - label = String.format( fmt, m_gi.nPlayers - remoteCount, - remoteCount ); + label = getString( R.string.players_label_host, + m_gi.nPlayers - remoteCount, + remoteCount ); } ((TextView)findViewById( R.id.players_label )).setText( label ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java index 02c96e584..cfeb6376e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java @@ -172,11 +172,10 @@ public class GameListAdapter extends XWListAdapter { } String name = GameUtils.getName( m_context, m_rowid ); - String format = - m_context.getString( R.string.str_game_namef ); if ( null != value ) { - value = String.format( format, name, value ); + value = m_context.getString( R.string.str_game_namef, + name, value ); } else { value = name; } 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 d912f3a60..4c3f99231 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -329,8 +329,7 @@ public class GameUtils { { String result = DBUtils.getName( context, rowid ); if ( null == result || 0 == result.length() ) { - String fmt = context.getString( R.string.gamef ); - result = String.format( fmt, rowid ); + result = context.getString( R.string.gamef, rowid ); } return result; } @@ -531,8 +530,7 @@ public class GameUtils { if ( null != gameUri ) { int fmtId = choseEmail? R.string.invite_htmf : R.string.invite_txtf; int choiceID; - String format = context.getString( fmtId ); - String message = String.format( format, gameUri.toString() ); + String message = context.getString( fmtId, gameUri.toString() ); Intent intent = new Intent(); if ( choseEmail ) { 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 2d82e380c..2d8f3b2ec 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -116,12 +116,12 @@ public class GamesList extends XWListActivity DictLangCache.getLangName( this, m_missingDictLang ); String gameName = GameUtils.getName( this, m_rowid ); if ( WARN_NODICT == id ) { - message = String.format( getString( R.string.no_dictf ), - gameName, langName ); + message = getString( R.string.no_dictf, + gameName, langName ); } else { - message = String.format( getString(R.string.no_dict_substf), - gameName, m_missingDictNames[0], - langName ); + message = getString( R.string.no_dict_substf, + gameName, m_missingDictNames[0], + langName ); } ab = new AlertDialog.Builder( this ) @@ -510,8 +510,8 @@ public class GamesList extends XWListActivity int position = info.position; long rowid = DBUtils.gamesList( this )[position]; String title = GameUtils.getName( this, rowid ); - String fmt = getString(R.string.game_item_menu_titlef ); - menu.setHeaderTitle( String.format( fmt, title ) ); + menu.setHeaderTitle( getString( R.string.game_item_menu_titlef, + title ) ); } @Override @@ -751,8 +751,7 @@ public class GamesList extends XWListActivity rowid = GameUtils.makeNewNetGame( this, info ); GameUtils.launchGame( this, rowid, true ); } else { - String fmt = getString( R.string.dup_game_queryf ); - String msg = String.format( fmt, info.room ); + String msg = getString( R.string.dup_game_queryf, info.room ); m_netLaunchInfo = info; showConfirmThen( msg, NEW_NET_GAME_ACTION ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java index 01d987341..5e6c08b4b 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java @@ -82,9 +82,8 @@ public class NetLaunchInfo { { Builder ub = new Builder(); ub.scheme( "http" ); - String format = context.getString( R.string.game_url_pathf ); - ub.path( String.format( format, - XWPrefs.getDefaultRedirHost( context ) ) ); + ub.path( context.getString( R.string.game_url_pathf, + XWPrefs.getDefaultRedirHost( context ) ) ); ub.appendQueryParameter( "lang", String.format("%d", lang ) ); ub.appendQueryParameter( "np", String.format( "%d", nPlayers ) ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java index 54e96603e..f1aec34c3 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NewGameActivity.java @@ -78,11 +78,10 @@ public class NewGameActivity extends XWActivity { setContentView( R.layout.new_game ); TextView desc = (TextView)findViewById( R.id.newgame_local_desc ); - String fmt = getString( R.string.newgame_local_descf ); String dict = CommonPrefs.getDefaultHumanDict( this ); String lang = DictLangCache.getLangName( this, dict ); m_lang = DictLangCache.getLangLangCode( this, lang ); - desc.setText( String.format( fmt, lang ) ); + desc.setText( getString( R.string.newgame_local_descf, lang ) ); Button button = (Button)findViewById( R.id.newgame_local ); button.setOnClickListener( new View.OnClickListener() { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RefreshNamesTask.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RefreshNamesTask.java index d2cba999c..3810e1875 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RefreshNamesTask.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RefreshNamesTask.java @@ -55,10 +55,9 @@ public class RefreshNamesTask extends AsyncTask { m_lang = lang; m_nInGame = nInGame; - String fmt = context.getString( R.string.public_names_progress ); - String msg = String.format( fmt, nInGame, - DictLangCache.getLangName(context,lang) ); - + String msg = context.getString( R.string.public_names_progress, + nInGame, + DictLangCache.getLangName(context,lang) ); m_progress = ProgressDialog.show( context, msg, null, true, true ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayGameActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayGameActivity.java index 0b028cf1f..e5571a6a1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayGameActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayGameActivity.java @@ -82,9 +82,8 @@ public class RelayGameActivity extends XWActivity XwJNI.game_dispose( gamePtr ); String lang = DictLangCache.getLangName( this, m_gi.dictLang ); - String fmt = getString( R.string.relay_game_explainf ); TextView text = (TextView)findViewById( R.id.explain ); - text.setText( String.format( fmt, lang ) ); + text.setText( getString( R.string.relay_game_explainf, lang ) ); } @Override diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java index e454c272c..5c08356ae 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java @@ -342,8 +342,7 @@ public class Utils { public static String format( Context context, int id, Object... args ) { - String fmt = context.getString( id ); - return String.format( fmt, args ); + return context.getString( id, args ); } private static void setFirstBootStatics( Context context )