From e9891118f706e5fe084eaebb88acd355411fadc1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 6 Mar 2014 04:28:47 -0500 Subject: [PATCH] [Android] Kill off unnecessary getString calls. --- .../com/reicast/emulator/AboutFragment.java | 17 ++++----- .../src/com/reicast/emulator/FileBrowser.java | 19 ++++------ .../com/reicast/emulator/MainActivity.java | 35 +++++++++---------- .../emulator/config/InputFragment.java | 14 ++++---- .../emulator/config/InputModFragment.java | 2 +- .../reicast/emulator/periph/MOGAInput.java | 4 +-- 6 files changed, 40 insertions(+), 51 deletions(-) diff --git a/shell/android/src/com/reicast/emulator/AboutFragment.java b/shell/android/src/com/reicast/emulator/AboutFragment.java index 2dd9e477a..295caa767 100644 --- a/shell/android/src/com/reicast/emulator/AboutFragment.java +++ b/shell/android/src/com/reicast/emulator/AboutFragment.java @@ -119,7 +119,7 @@ public class AboutFragment extends Fragment { handler = new Handler(); try { - InputStream file = parentActivity.getAssets().open("build"); + InputStream file = getResources().getAssets().open("build"); if (file != null) { BufferedReader reader = new BufferedReader( new InputStreamReader(file)); @@ -137,10 +137,10 @@ public class AboutFragment extends Fragment { .getPackageInfo(parentActivity.getPackageName(), 0).versionCode; TextView version = (TextView) getView().findViewById( R.id.revision_text); - String revision = parentActivity.getString(R.string.revision_text, + String revision = getString(R.string.revision_text, versionName, String.valueOf(versionCode)); if (!buildId.isEmpty()) { - revision = parentActivity.getString(R.string.revision_text, + revision = getString(R.string.revision_text, versionName, buildId.substring(0,7)); } version.setText(revision); @@ -148,17 +148,15 @@ public class AboutFragment extends Fragment { e.printStackTrace(); } - TextView website = (TextView) getView().findViewById( - R.id.site_text); + TextView website = (TextView) getView().findViewById(R.id.site_text); Linkify.addLinks(website, Linkify.ALL); - slidingGithub = (SlidingDrawer) getView().findViewById( - R.id.slidingGithub); + slidingGithub = (SlidingDrawer) getView().findViewById(R.id.slidingGithub); if (MainActivity.debugUser) { slidingGithub.setOnDrawerOpenListener(new OnDrawerOpenListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void onDrawerOpened() { - String git = parentActivity.getString(R.string.git_api); + String git = getString(R.string.git_api); retrieveGitTask queryGithub = new retrieveGitTask(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { queryGithub.executeOnExecutor( @@ -297,8 +295,7 @@ public class AboutFragment extends Fragment { } } - private JSONArray getContent(String urlString) throws IOException, - JSONException { + private JSONArray getContent(String urlString) throws IOException, JSONException { StringBuilder builder = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(urlString); diff --git a/shell/android/src/com/reicast/emulator/FileBrowser.java b/shell/android/src/com/reicast/emulator/FileBrowser.java index d8f5601e3..69120d604 100644 --- a/shell/android/src/com/reicast/emulator/FileBrowser.java +++ b/shell/android/src/com/reicast/emulator/FileBrowser.java @@ -19,7 +19,6 @@ import org.apache.commons.lang3.StringUtils; import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; -import android.content.res.Resources; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.net.Uri; @@ -172,9 +171,9 @@ public class FileBrowser extends Fragment { @Override protected List doInBackground(String... paths) { File storage = new File(paths[0]); - Resources resources = parentActivity.getResources(); + // array of valid image file extensions - String[] mediaTypes = resources.getStringArray(R.array.images); + String[] mediaTypes = getResources().getStringArray(R.array.images); FilenameFilter[] filter = new FilenameFilter[mediaTypes.length]; int i = 0; @@ -206,8 +205,7 @@ public class FileBrowser extends Fragment { .findViewById(R.id.game_list); list.removeAllViews(); - String heading = parentActivity - .getString(R.string.games_listing); + String heading = getString(R.string.games_listing); createListHeader(heading, list, true); if (games != null && !games.isEmpty()) { for (final File game : games) { @@ -240,7 +238,7 @@ public class FileBrowser extends Fragment { R.layout.bios_list_item, null, false); ((TextView) childview.findViewById(R.id.item_name)) - .setText(parentActivity.getString(R.string.boot_bios)); + .setText(R.string.boot_bios); childview.setTag(null); @@ -365,14 +363,11 @@ public class FileBrowser extends Fragment { R.layout.app_list_item, null, false); if (file == null) { - ((TextView) childview.findViewById(R.id.item_name)) - .setText(getString(R.string.folder_select)); + ((TextView) childview.findViewById(R.id.item_name)).setText(R.string.folder_select); } else if (file == parent) - ((TextView) childview.findViewById(R.id.item_name)) - .setText(".."); + ((TextView) childview.findViewById(R.id.item_name)).setText(".."); else - ((TextView) childview.findViewById(R.id.item_name)) - .setText(file.getName()); + ((TextView) childview.findViewById(R.id.item_name)).setText(file.getName()); ((ImageView) childview.findViewById(R.id.item_icon)) .setImageResource(file == null ? R.drawable.config diff --git a/shell/android/src/com/reicast/emulator/MainActivity.java b/shell/android/src/com/reicast/emulator/MainActivity.java index 5115ba2cd..9ac9702b3 100644 --- a/shell/android/src/com/reicast/emulator/MainActivity.java +++ b/shell/android/src/com/reicast/emulator/MainActivity.java @@ -175,7 +175,7 @@ public class MainActivity extends SlidingFragmentActivity implements .replace(R.id.fragment_container, browseFrag, "MAIN_BROWSER").addToBackStack(null) .commit(); - setTitle(getString(R.string.browser)); + setTitle(R.string.browser); sm.toggle(true); } @@ -195,7 +195,7 @@ public class MainActivity extends SlidingFragmentActivity implements .replace(R.id.fragment_container, configFrag, "CONFIG_FRAG").addToBackStack(null) .commit(); - setTitle(getString(R.string.settings)); + setTitle(R.string.settings); sm.toggle(true); } @@ -217,7 +217,7 @@ public class MainActivity extends SlidingFragmentActivity implements .replace(R.id.fragment_container, optionsFrag, "OPTIONS_FRAG") .addToBackStack(null).commit(); - setTitle(getString(R.string.paths)); + setTitle(R.string.paths); sm.toggle(true); } @@ -237,7 +237,7 @@ public class MainActivity extends SlidingFragmentActivity implements .beginTransaction() .replace(R.id.fragment_container, inputFrag, "INPUT_FRAG").addToBackStack(null).commit(); - setTitle(getString(R.string.input)); + setTitle(R.string.input); sm.toggle(true); } @@ -257,7 +257,7 @@ public class MainActivity extends SlidingFragmentActivity implements .beginTransaction() .replace(R.id.fragment_container, aboutFrag, "ABOUT_FRAG").addToBackStack(null).commit(); - setTitle(getString(R.string.about)); + setTitle(R.string.about); sm.toggle(true); } @@ -274,7 +274,7 @@ public class MainActivity extends SlidingFragmentActivity implements startActivity(new Intent(Intent.ACTION_VIEW, Uri .parse("market://details?id=" + getPackageName()))); - //setTitle(getString(R.string.rateme)); + //setTitle(R.string.rateme); sm.toggle(true); return true; } else @@ -314,9 +314,9 @@ public class MainActivity extends SlidingFragmentActivity implements */ private void displayLogOutput(final String error) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); - builder.setTitle(getString(R.string.report_issue)); + builder.setTitle(R.string.report_issue); builder.setMessage(error); - builder.setNegativeButton(getString(R.string.dismiss), + builder.setNegativeButton(R.string.dismiss, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); @@ -353,34 +353,31 @@ public class MainActivity extends SlidingFragmentActivity implements // set title if (!isBiosExisting()) - alertDialogBuilder.setTitle(getString(R.string.missing_bios_title)); + alertDialogBuilder.setTitle(R.string.missing_bios_title); else if (!isFlashExisting()) - alertDialogBuilder.setTitle(getString(R.string.missing_flash_title)); + alertDialogBuilder.setTitle(R.string.missing_flash_title); // set dialog message alertDialogBuilder .setMessage(msg) .setCancelable(false) - .setPositiveButton(getString(R.string.dismiss), + .setPositiveButton(R.string.dismiss, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, - int id) { + public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity // MainActivity.this.finish(); } }) - .setNegativeButton(getString(R.string.options), + .setNegativeButton(R.string.options, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, - int id) { + public void onClick(DialogInterface dialog, int id) { FileBrowser firstFragment = new FileBrowser(); Bundle args = new Bundle(); // args.putBoolean("ImgBrowse", false); // specify ImgBrowse option. true = images, // false = folders only - args.putString("browse_entry", - sdcard.toString()); + args.putString("browse_entry", sdcard.toString()); // specify a path for selecting folder // options args.putBoolean("games_entry", false); @@ -523,7 +520,7 @@ public class MainActivity extends SlidingFragmentActivity implements .beginTransaction() .replace(R.id.fragment_container, fragment, "MAIN_BROWSER").commit(); - setTitle(getString(R.string.browser)); + setTitle(R.string.browser); } @Override diff --git a/shell/android/src/com/reicast/emulator/config/InputFragment.java b/shell/android/src/com/reicast/emulator/config/InputFragment.java index 4226c2ee3..a49faebca 100644 --- a/shell/android/src/com/reicast/emulator/config/InputFragment.java +++ b/shell/android/src/com/reicast/emulator/config/InputFragment.java @@ -286,7 +286,7 @@ public class InputFragment extends Fragment { buttonRemoveControllerPlayer1.setEnabled(true); } else { textViewDeviceDescriptorPlayer1 - .setText(getString(R.string.controller_none_selected)); + .setText(R.string.controller_none_selected); buttonRemoveControllerPlayer1.setEnabled(false); } } @@ -306,7 +306,7 @@ public class InputFragment extends Fragment { buttonRemoveControllerPlayer2.setEnabled(true); } else { textViewDeviceDescriptorPlayer2 - .setText(getString(R.string.controller_none_selected)); + .setText(R.string.controller_none_selected); buttonRemoveControllerPlayer2.setEnabled(false); } } @@ -326,7 +326,7 @@ public class InputFragment extends Fragment { buttonRemoveControllerPlayer3.setEnabled(true); } else { textViewDeviceDescriptorPlayer3 - .setText(getString(R.string.controller_none_selected)); + .setText(R.string.controller_none_selected); buttonRemoveControllerPlayer3.setEnabled(false); } } @@ -346,7 +346,7 @@ public class InputFragment extends Fragment { buttonRemoveControllerPlayer4.setEnabled(true); } else { textViewDeviceDescriptorPlayer4 - .setText(getString(R.string.controller_none_selected)); + .setText(R.string.controller_none_selected); buttonRemoveControllerPlayer4.setEnabled(false); } } @@ -356,17 +356,17 @@ public class InputFragment extends Fragment { listenForButton = playerNum; AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); - builder.setTitle(getString(R.string.select_controller_title)); + builder.setTitle(R.string.select_controller_title); builder.setMessage(getString(R.string.select_controller_message, String.valueOf(listenForButton))); - builder.setPositiveButton(getString(R.string.cancel), + builder.setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { listenForButton = 0; dialog.dismiss(); } }); - builder.setNegativeButton(getString(R.string.manual), + builder.setNegativeButton(R.string.manual, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { InputModFragment inputModFrag = new InputModFragment(); diff --git a/shell/android/src/com/reicast/emulator/config/InputModFragment.java b/shell/android/src/com/reicast/emulator/config/InputModFragment.java index 5e7314f0b..feafb434f 100644 --- a/shell/android/src/com/reicast/emulator/config/InputModFragment.java +++ b/shell/android/src/com/reicast/emulator/config/InputModFragment.java @@ -471,7 +471,7 @@ public class InputModFragment extends Fragment { this.output = output; isMapping = true; AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setTitle(getString(R.string.map_keycode_title)); + builder.setTitle(R.string.map_keycode_title); builder.setMessage(getString(R.string.map_keycode_message, button.replace("_", " "))); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { diff --git a/shell/android/src/com/reicast/emulator/periph/MOGAInput.java b/shell/android/src/com/reicast/emulator/periph/MOGAInput.java index 95f93bb25..0f7c6b731 100644 --- a/shell/android/src/com/reicast/emulator/periph/MOGAInput.java +++ b/shell/android/src/com/reicast/emulator/periph/MOGAInput.java @@ -185,11 +185,11 @@ public class MOGAInput if (mControllerVersion == Controller.ACTION_VERSION_MOGAPRO) { pad.isMogaPro[playerNum] = true; pad.isActiveMoga[playerNum] = true; - Log.d("com.reicast.emulator", act.getApplicationContext().getString(R.string.moga_pro_connect)); + Log.d("com.reicast.emulator", act.getString(R.string.moga_pro_connect)); } else if (mControllerVersion == Controller.ACTION_VERSION_MOGA) { pad.isMogaPro[playerNum] = false; pad.isActiveMoga[playerNum] = true; - Log.d("com.reicast.emulator", act.getApplicationContext().getString(R.string.moga_connect)); + Log.d("com.reicast.emulator", act.getString(R.string.moga_connect)); } if (pad.isActiveMoga[playerNum]) { notifyMogaConnected(notify, playerNum);