Moved most Strings to xml

Change-Id: I7c460302d3efd1ffe4b1d7cb66789002bfa1ca33
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-02-06 11:01:50 -05:00
parent 6502542853
commit 1fcf789219
5 changed files with 45 additions and 23 deletions

View File

@@ -3,6 +3,7 @@
xmlns:myapp="com.TwentyCode.android.ExaltedDice" xmlns:myapp="com.TwentyCode.android.ExaltedDice"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="horizontal" > android:orientation="horizontal" >
<RelativeLayout <RelativeLayout
@@ -25,7 +26,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_below="@id/die_selector" android:layout_below="@id/die_selector"
android:layout_marginTop="10dip" android:layout_marginTop="10dip"
android:text="Roll!" /> android:text="@string/roll" />
</RelativeLayout> </RelativeLayout>
<RelativeLayout <RelativeLayout

View File

@@ -31,7 +31,7 @@
android:layout_width="0px" android:layout_width="0px"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:text="Roll!" /> android:text="@string/roll" />
</LinearLayout> </LinearLayout>
<ListView <ListView

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="dice_types">
<item>D2</item>
<item>D3</item>
<item>D4</item>
<item>D6</item>
<item>D8</item>
<item>D10</item>
<item>D12</item>
<item>D20</item>
<item>D100</item>
</string-array>
</resources>

View File

@@ -14,5 +14,13 @@
<string name="email">twentycodes@gmail.com</string> <string name="email">twentycodes@gmail.com</string>
<string name="email_about">Send an email with ideas or problems to help make this application even better! Good or bad we want to know what you think!</string> <string name="email_about">Send an email with ideas or problems to help make this application even better! Good or bad we want to know what you think!</string>
<string name="contact_us">Contact Us</string> <string name="contact_us">Contact Us</string>
<string name="roll">Roll!</string>
<string name="clear_history">Clear Roll History</string>
<string name="settings">Settings</string>
<string name="quit">Quit</string>
<string name="do_you_want_to_quit">Are you sure you want to quit?</string>
<string name="total">Total: </string>
<string name="sucesses">\nSuccesses: </string>
<string name="rolls">\nRolls: </string>
</resources> </resources>

View File

@@ -34,10 +34,10 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
private static final String TAG = "ExaltedDice"; private static final String TAG = "ExaltedDice";
public static final String KEY_GAME_NAME = "game_name"; public static final String KEY_GAME_NAME = "game_name";
public static final String KEY_GAME_ID = "game_id"; public static final String KEY_GAME_ID = "game_id";
private static final String[] DICE_VALUES = { "D2", "D3", "D4", "D6", "D8", "D10", "D12", "D20", "D100" };
private static final int DELETE = 0; private static final int DELETE = 0;
private static final int SETTINGS = Menu.FIRST + 2; private static final int SETTINGS = Menu.FIRST + 2;
private String[] mDiceValues;
private ListView mListView; private ListView mListView;
private NumberPicker mNumberPicker; private NumberPicker mNumberPicker;
private NumberPicker mDPicker; private NumberPicker mDPicker;
@@ -103,20 +103,18 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
mGameName = i.getStringExtra(KEY_GAME_NAME); mGameName = i.getStringExtra(KEY_GAME_NAME);
mGameId = i.getLongExtra(KEY_GAME_ID, -1); mGameId = i.getLongExtra(KEY_GAME_ID, -1);
this.setTitle(mGameName); this.setTitle(mGameName);
Log.v(TAG, "game name ="+mGameName);
Log.v(TAG, "game id ="+mGameId);
} }
mDiceValues = getResources().getStringArray(R.array.dice_types);
mListView = (ListView) findViewById(R.id.list); mListView = (ListView) findViewById(R.id.list);
mListView.setOnItemClickListener(this); mListView.setOnItemClickListener(this);
mListView.setStackFromBottom(true); mListView.setStackFromBottom(true);
mDPicker = (NumberPicker) findViewById(R.id.d_Picker); mDPicker = (NumberPicker) findViewById(R.id.d_Picker);
mDPicker.setMinValue(0); mDPicker.setMinValue(0);
mDPicker.setMaxValue(DICE_VALUES.length -1); mDPicker.setMaxValue(mDiceValues.length -1);
mDPicker.setDisplayedValues(DICE_VALUES); mDPicker.setDisplayedValues(mDiceValues);
mDPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); mDPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
mNumberPicker = (NumberPicker) findViewById(R.id.number_Picker); mNumberPicker = (NumberPicker) findViewById(R.id.number_Picker);
@@ -148,9 +146,9 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
* @author WWPowers 3-27-2010 * @author WWPowers 3-27-2010
*/ */
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
menu.add(1, MENU_CLEAR, 0, "Clear Roll History"); menu.add(1, MENU_CLEAR, 0, R.string.clear_history).setIcon(android.R.drawable.ic_menu_close_clear_cancel);
menu.add(1, SETTINGS, 0, "Settings"); menu.add(1, SETTINGS, 0, R.string.settings).setIcon(android.R.drawable.ic_menu_preferences);;
menu.add(1, MENU_QUIT, 0, "Quit"); menu.add(1, MENU_QUIT, 0, R.string.quit).setIcon(android.R.drawable.ic_menu_revert);
return true; return true;
} }
@@ -253,8 +251,8 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
* @author ricky barrette * @author ricky barrette
*/ */
private int parseD(String d) { private int parseD(String d) {
for(int i = 0; i < DICE_VALUES.length; i++) for(int i = 0; i < mDiceValues.length; i++)
if (DICE_VALUES[i].equalsIgnoreCase(d)) if (mDiceValues[i].equalsIgnoreCase(d))
return i; return i;
return 0; return 0;
} }
@@ -267,13 +265,13 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
*/ */
public void quitDialog() { public void quitDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to quit?").setCancelable( builder.setMessage(R.string.do_you_want_to_quit).setCancelable(
false).setPositiveButton("Yes", false).setPositiveButton(android.R.string.yes,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
ExaltedDice.this.finish(); ExaltedDice.this.finish();
} }
}).setNegativeButton("No", }).setNegativeButton(android.R.string.no,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
dialog.cancel(); dialog.cancel();
@@ -314,9 +312,9 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
total = total + item; total = total + item;
} }
resultsString.append("Total: "+ total); resultsString.append(getString(R.string.total)+ total);
resultsString.append("\nSuccesses: "+ successes(roll)); resultsString.append(getString(R.string.sucesses)+ successes(roll));
resultsString.append("\nRolls: "+ rolls.toString()); resultsString.append(getString(R.string.rolls)+ rolls.toString());
return resultsString.toString(); return resultsString.toString();
} }
@@ -332,7 +330,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
int rollId = mDb.getGameRollCount(mGameId) +1; int rollId = mDb.getGameRollCount(mGameId) +1;
ContentValues roll = new ContentValues(); ContentValues roll = new ContentValues();
roll.put(Database.KEY_D_TYPE, DICE_VALUES[mDPicker.getValue()]); roll.put(Database.KEY_D_TYPE, mDiceValues[mDPicker.getValue()]);
roll.put(Database.KEY_NUMBER, mNumberPicker.getValue()); roll.put(Database.KEY_NUMBER, mNumberPicker.getValue());
roll.put(Database.KEY_LOG, results(mNumberPicker.getValue())); roll.put(Database.KEY_LOG, results(mNumberPicker.getValue()));
@@ -352,7 +350,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
int[] roll = new int[times]; int[] roll = new int[times];
Random random = new Random(); Random random = new Random();
for (int i = 0; i < times; i++) { for (int i = 0; i < times; i++) {
roll[i] = random.nextInt(Integer.parseInt(DICE_VALUES[mDPicker.getValue()].substring(1))) + 1; roll[i] = random.nextInt(Integer.parseInt(mDiceValues[mDPicker.getValue()].substring(1))) + 1;
} }
return roll; return roll;
} }
@@ -385,7 +383,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
* @author WWPowers 3-26-2010 * @author WWPowers 3-26-2010
*/ */
public void toastLong(CharSequence msg) { public void toastLong(CharSequence msg) {
Log.i(TAG, "toastLong()");
Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
} }