diff --git a/AndroidManifest.xml b/AndroidManifest.xml
new file mode 100644
index 0000000..e775d1a
--- /dev/null
+++ b/AndroidManifest.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/drawable/calc.png b/res/drawable/calc.png
new file mode 100644
index 0000000..a4cd97e
Binary files /dev/null and b/res/drawable/calc.png differ
diff --git a/res/drawable/delete.png b/res/drawable/delete.png
new file mode 100644
index 0000000..25e2d4f
Binary files /dev/null and b/res/drawable/delete.png differ
diff --git a/res/drawable/icon.png b/res/drawable/icon.png
new file mode 100644
index 0000000..73575ed
Binary files /dev/null and b/res/drawable/icon.png differ
diff --git a/res/layout/about.xml b/res/layout/about.xml
new file mode 100644
index 0000000..e01a830
--- /dev/null
+++ b/res/layout/about.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/calc.xml b/res/layout/calc.xml
new file mode 100644
index 0000000..b0cda15
--- /dev/null
+++ b/res/layout/calc.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/layout/main.xml b/res/layout/main.xml
new file mode 100644
index 0000000..907c845
--- /dev/null
+++ b/res/layout/main.xml
@@ -0,0 +1,77 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/result.xml b/res/layout/result.xml
new file mode 100644
index 0000000..60a25b6
--- /dev/null
+++ b/res/layout/result.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
new file mode 100644
index 0000000..940859a
--- /dev/null
+++ b/res/values/arrays.xml
@@ -0,0 +1,27 @@
+
+
+
+ - 5
+ - 10
+ - 12
+ - 15
+ - 18
+ - 20
+ - 25
+ - 30
+
+
+ - 1
+ - 2
+ - 3
+ - 4
+ - 5
+ - 6
+ - 7
+ - 8
+ - 9
+ - 10
+ - 11
+ - 12
+
+
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
new file mode 100644
index 0000000..d503695
--- /dev/null
+++ b/res/values/strings.xml
@@ -0,0 +1,21 @@
+
+
+ Tiproid
+ © 2008 Erik C. Thauvin\nAll Rights Reserved\n\nerik@thauvin.net\n\nhttp://mobile.thauvin.net
+ About
+ OK
+ Cancel
+ Bill Total Amount:
+ Calculate
+ Reset
+ Tax Amount:
+ Use the keyboard...
+ Tap button to edit...
+ Tip %:
+ Split:
+ Tip ?%:
+ Split x ?:
+ Total:
+ Please enter the bill amount...
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+
diff --git a/screenshots/1.psd b/screenshots/1.psd
new file mode 100644
index 0000000..2af9527
Binary files /dev/null and b/screenshots/1.psd differ
diff --git a/screenshots/2.psd b/screenshots/2.psd
new file mode 100644
index 0000000..fa7c09b
Binary files /dev/null and b/screenshots/2.psd differ
diff --git a/screenshots/3.psd b/screenshots/3.psd
new file mode 100644
index 0000000..4984544
Binary files /dev/null and b/screenshots/3.psd differ
diff --git a/screenshots/tiproid.gif b/screenshots/tiproid.gif
new file mode 100644
index 0000000..1918509
Binary files /dev/null and b/screenshots/tiproid.gif differ
diff --git a/sign.bat b/sign.bat
new file mode 100644
index 0000000..6809692
--- /dev/null
+++ b/sign.bat
@@ -0,0 +1,10 @@
+@echo off
+"%JAVA_HOME%\bin\jarsigner" -verbose -keystore "%USERPROFILE%\personal\android.keystore" "%1" android
+if errorlevel 1 goto ERROR
+"%JAVA_HOME%\bin\jarsigner" -verify "%1"
+if errorlevel 1 goto ERROR
+goto DONE
+:ERROR
+@pause
+:DONE
+@echo on
\ No newline at end of file
diff --git a/src/net/thauvin/erik/android/tiproid/R.java b/src/net/thauvin/erik/android/tiproid/R.java
new file mode 100644
index 0000000..cbfe4f6
--- /dev/null
+++ b/src/net/thauvin/erik/android/tiproid/R.java
@@ -0,0 +1,86 @@
+/* AUTO-GENERATED FILE. DO NOT MODIFY.
+ *
+ * This class was automatically generated by the
+ * aapt tool from the resource data it found. It
+ * should not be modified by hand.
+ */
+
+package net.thauvin.erik.android.tiproid;
+
+public final class R {
+ public static final class array {
+ public static final int main_split_array=0x7f040001;
+ public static final int main_tip_array=0x7f040000;
+ }
+ public static final class attr {
+ }
+ public static final class drawable {
+ public static final int calc=0x7f020000;
+ public static final int delete=0x7f020001;
+ public static final int icon=0x7f020002;
+ }
+ public static final class id {
+ public static final int Button0=0x7f060011;
+ public static final int Button01=0x7f060004;
+ public static final int Button02=0x7f060005;
+ public static final int Button03=0x7f060006;
+ public static final int Button04=0x7f060008;
+ public static final int Button05=0x7f060009;
+ public static final int Button06=0x7f06000a;
+ public static final int Button07=0x7f06000c;
+ public static final int Button08=0x7f06000d;
+ public static final int Button09=0x7f06000e;
+ public static final int ButtonBS=0x7f060012;
+ public static final int ButtonDot=0x7f060010;
+ public static final int TableLayout01=0x7f060002;
+ public static final int TableRow01=0x7f060003;
+ public static final int TableRow02=0x7f060007;
+ public static final int TableRow03=0x7f06000b;
+ public static final int TableRow04=0x7f06000f;
+ public static final int about_text_fld=0x7f060000;
+ public static final int calc_edit_fld=0x7f060001;
+ public static final int main_bill_edit_btn=0x7f060018;
+ public static final int main_bill_fld=0x7f060017;
+ public static final int main_bill_lbl=0x7f060016;
+ public static final int main_calculate_btn=0x7f06001c;
+ public static final int main_reset_btn=0x7f06001d;
+ public static final int main_split_spin=0x7f06001b;
+ public static final int main_tax_edit_btn=0x7f060015;
+ public static final int main_tax_fld=0x7f060014;
+ public static final int main_tax_lbl=0x7f060013;
+ public static final int main_tip_lbl=0x7f060019;
+ public static final int main_tip_spin=0x7f06001a;
+ public static final int result_split_fld=0x7f060023;
+ public static final int result_split_lbl=0x7f060022;
+ public static final int result_tip_fld=0x7f06001f;
+ public static final int result_tip_lbl=0x7f06001e;
+ public static final int result_total_fld=0x7f060021;
+ public static final int result_total_lbl=0x7f060020;
+ }
+ public static final class layout {
+ public static final int about=0x7f030000;
+ public static final int calc=0x7f030001;
+ public static final int main=0x7f030002;
+ public static final int result=0x7f030003;
+ }
+ public static final class string {
+ public static final int about_menu_txt=0x7f050002;
+ public static final int about_txt=0x7f050001;
+ public static final int alert_dialog_cancel=0x7f050004;
+ public static final int alert_dialog_ok=0x7f050003;
+ public static final int app_name=0x7f050000;
+ public static final int error_bill_txt=0x7f050010;
+ public static final int main_bill_lbl_txt=0x7f050005;
+ public static final int main_calc_btn_txt=0x7f050006;
+ public static final int main_reset_btn_txt=0x7f050007;
+ public static final int main_split_lbl_txt=0x7f05000c;
+ public static final int main_tax_hint_land_txt=0x7f050009;
+ public static final int main_tax_hint_txt=0x7f05000a;
+ public static final int main_tax_lbl_txt=0x7f050008;
+ public static final int main_tip_lbl_txt=0x7f05000b;
+ public static final int result_split_lbl_txt=0x7f05000e;
+ public static final int result_tip_lbl_txt=0x7f05000d;
+ public static final int result_total_lbl_txt=0x7f05000f;
+ public static final int sample_txt=0x7f050011;
+ }
+}
diff --git a/src/net/thauvin/erik/android/tiproid/Tiproid.java b/src/net/thauvin/erik/android/tiproid/Tiproid.java
new file mode 100644
index 0000000..0105c7c
--- /dev/null
+++ b/src/net/thauvin/erik/android/tiproid/Tiproid.java
@@ -0,0 +1,510 @@
+/*
+ * @(#)Tiproid.java
+ *
+ * Copyright (c) 2008, Erik C. Thauvin (http://erik.thauvin.net/)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * Neither the name of the authors nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id$
+ *
+ */
+package net.thauvin.erik.android.tiproid;
+
+/**
+ * Tiproid
is a simple tip calculator for Android.
+ *
+ * @author Erik C. Thauvin
+ * @version $Revision$, $Date$
+ * @created Oct 9, 2008
+ * @since 1.0
+ */
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.SharedPreferences;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ImageButton;
+import android.widget.Spinner;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class Tiproid extends Activity
+{
+ public static final String PREFS_TIP_RATE = "TipRate";
+
+ /**
+ * Displays the calc dialog.
+ *
+ * @param editFld The edit field.
+ */
+ private void calcDialog(final EditText editFld)
+ {
+ final LayoutInflater factory = LayoutInflater.from(this);
+ final View textEntryView = factory.inflate(R.layout.calc, null);
+
+ final Button zero = (Button) textEntryView.findViewById(R.id.Button0);
+ final Button one = (Button) textEntryView.findViewById(R.id.Button01);
+ final Button two = (Button) textEntryView.findViewById(R.id.Button02);
+ final Button three = (Button) textEntryView.findViewById(R.id.Button03);
+ final Button four = (Button) textEntryView.findViewById(R.id.Button04);
+ final Button five = (Button) textEntryView.findViewById(R.id.Button05);
+ final Button six = (Button) textEntryView.findViewById(R.id.Button06);
+ final Button seven = (Button) textEntryView.findViewById(R.id.Button07);
+ final Button eight = (Button) textEntryView.findViewById(R.id.Button08);
+ final Button nine = (Button) textEntryView.findViewById(R.id.Button09);
+ final Button dot = (Button) textEntryView.findViewById(R.id.ButtonDot);
+ final ImageButton bs = (ImageButton) textEntryView.findViewById(R.id.ButtonBS);
+
+ final String curText = editFld.getText().toString();
+
+ final EditText calcEdit = (EditText) textEntryView.findViewById(R.id.calc_edit_fld);
+
+ if (!TextUtils.isEmpty(curText))
+ {
+ calcEdit.setText(curText);
+ }
+
+ zero.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ calcEdit.append("0");
+ }
+ });
+
+ one.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ calcEdit.append("1");
+ }
+ });
+
+ two.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ calcEdit.append("2");
+ }
+ });
+
+ three.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ calcEdit.append("3");
+ }
+ });
+
+ four.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ calcEdit.append("4");
+ }
+ });
+
+ five.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ calcEdit.append("5");
+ }
+ });
+
+ six.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ calcEdit.append("6");
+ }
+ });
+
+ seven.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ calcEdit.append("7");
+ }
+ });
+
+ eight.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ calcEdit.append("8");
+ }
+ });
+
+ nine.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ calcEdit.append("9");
+ }
+ });
+
+ dot.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ calcEdit.append(".");
+ }
+ });
+
+ bs.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ final String txt = calcEdit.getText().toString();
+ if (!TextUtils.isEmpty(txt))
+ {
+ if (txt.length() > 0)
+ {
+ calcEdit.setText(txt.subSequence(0, txt.length() - 1));
+ calcEdit.setSelection(txt.length() - 1);
+ }
+ }
+ }
+ });
+
+ new AlertDialog.Builder(this).setView(textEntryView).setPositiveButton(R.string.alert_dialog_ok,
+ new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int whichButton)
+ {
+
+ editFld.setText(calcEdit.getText().toString());
+
+ editFld.requestFocus();
+ }
+ }).setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int whichButton)
+ {
+ editFld.requestFocus();
+ }
+ }).show();
+ }
+
+ /**
+ * Calculates the tip and displays the result dialog.
+ *
+ * @param billTxt The bill amount.
+ * @param taxTxt The tax amount.
+ * @param tipTxt The tip rate.
+ * @param splitTx The split count.
+ */
+ private void calculate(String billTxt, String taxTxt, String tipTxt, String splitTxt)
+ {
+ if (TextUtils.isEmpty(billTxt))
+ {
+ Toast.makeText(Tiproid.this, R.string.error_bill_txt, Toast.LENGTH_SHORT).show();
+ }
+ else
+ {
+ final int taxTotal;
+ if (TextUtils.isEmpty(taxTxt))
+ {
+ taxTotal = 0;
+ }
+ else
+ {
+ taxTotal = parseInt(taxTxt);
+ }
+
+ final int subTotal = parseInt(billTxt) - taxTotal;
+ final int tipRate = Integer.parseInt(tipTxt);
+ final int splitCount = Integer.parseInt(splitTxt);
+ int tipTotal = (subTotal * tipRate) / 100;
+ int billTotal = subTotal + tipTotal + taxTotal;
+
+ if ((billTotal % 100) < 50)
+ {
+ while ((billTotal % 100) != 0)
+ {
+ tipTotal--;
+ billTotal = subTotal + tipTotal + taxTotal;
+ }
+ }
+ else
+ {
+ while ((billTotal % 100) != 0)
+ {
+ tipTotal++;
+ billTotal = subTotal + tipTotal + taxTotal;
+ }
+ }
+
+ final LayoutInflater factory = LayoutInflater.from(this);
+ final View resultView = factory.inflate(R.layout.result, null);
+
+ final TextView tipFld = (TextView) resultView.findViewById(R.id.result_tip_fld);
+ final TextView totalFld = (TextView) resultView.findViewById(R.id.result_total_fld);
+ final TextView tipLbl = (TextView) resultView.findViewById(R.id.result_tip_lbl);
+ final TextView splitFld = (TextView) resultView.findViewById(R.id.result_split_fld);
+ final TextView splitLbl = (TextView) resultView.findViewById(R.id.result_split_lbl);
+
+ tipLbl.setText(tipLbl.getText().toString().replace("?", tipTxt));
+ tipFld.setText(parseStr(tipTotal));
+ totalFld.setText(parseStr(billTotal));
+
+ if (splitCount == 1)
+ {
+ splitFld.setText("");
+ splitLbl.setText("");
+ }
+ else
+ {
+ splitLbl.setText(splitLbl.getText().toString().replace("?", splitTxt));
+ int split = billTotal / splitCount;
+ if ((split * splitCount) < billTotal)
+ {
+ split += 1;
+ }
+ splitFld.setText(parseStr(split));
+ }
+
+ new AlertDialog.Builder(this).setView(resultView).setPositiveButton(R.string.alert_dialog_ok,
+ new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int whichButton)
+ {
+ // do nothing
+ }
+ }).show();
+ }
+ }
+
+ /**
+ * Returns the current version number.
+ *
+ * @return The current version number or empty.
+ */
+ private String getVersionNumber()
+ {
+ try
+ {
+ return getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
+ }
+ catch (final NameNotFoundException e)
+ {
+ return "";
+ }
+ };
+
+ /**
+ * Initializes the various controls.
+ */
+ private void init()
+ {
+ final EditText billFld = (EditText) findViewById(R.id.main_bill_fld);
+ final EditText taxFld = (EditText) findViewById(R.id.main_tax_fld);
+ final Spinner tipSpin = (Spinner) findViewById(R.id.main_tip_spin);
+ final Spinner splitSpin = (Spinner) findViewById(R.id.main_split_spin);
+
+ final Button calcBtn = (Button) findViewById(R.id.main_calculate_btn);
+ final Button resetBtn = (Button) findViewById(R.id.main_reset_btn);
+
+ final ImageButton billEditBtn = (ImageButton) findViewById(R.id.main_bill_edit_btn);
+ final ImageButton taxEditBtn = (ImageButton) findViewById(R.id.main_tax_edit_btn);
+
+ // Disable edit buttons in landscape mode
+ final boolean enableBtns = getWindow().getWindowManager().getDefaultDisplay().getWidth() < getWindow().getWindowManager()
+ .getDefaultDisplay().getHeight();
+ billEditBtn.setEnabled(enableBtns);
+ taxEditBtn.setEnabled(enableBtns);
+
+ if (!enableBtns)
+ {
+ taxFld.setHint(getString(R.string.main_tax_hint_land_txt));
+ }
+ else
+ {
+ taxFld.setHint(getString(R.string.main_tax_hint_txt));
+
+ }
+
+ final ArrayAdapter tipAdapter = ArrayAdapter.createFromResource(this, R.array.main_tip_array,
+ android.R.layout.simple_spinner_item);
+ final int defaultTipRate = (tipAdapter.getCount() / 2) - 1;
+ tipAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ tipSpin.setAdapter(tipAdapter);
+
+ final ArrayAdapter splitAdapter = ArrayAdapter.createFromResource(this, R.array.main_split_array,
+ android.R.layout.simple_spinner_item);
+ splitAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ splitSpin.setAdapter(splitAdapter);
+
+ final SharedPreferences settings = getSharedPreferences(getString(R.string.app_name), Context.MODE_PRIVATE);
+ tipSpin.setSelection(settings.getInt(PREFS_TIP_RATE, defaultTipRate));
+
+ calcBtn.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ calculate(billFld.getText().toString(), taxFld.getText().toString(), tipSpin.getSelectedItem().toString(), splitSpin
+ .getSelectedItem().toString());
+ }
+ });
+
+ resetBtn.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ billFld.setText("");
+ taxFld.setText("");
+ splitSpin.setSelection(0);
+ tipSpin.setSelection(settings.getInt(PREFS_TIP_RATE, defaultTipRate));
+ }
+ });
+
+ billEditBtn.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ calcDialog(billFld);
+ }
+ });
+
+ taxEditBtn.setOnClickListener(new Button.OnClickListener()
+ {
+ public void onClick(View view)
+ {
+ calcDialog(taxFld);
+ }
+ });
+
+ }
+
+ /**
+ * Called when the activity is first created.
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+ init();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu)
+ {
+ menu.add(0, Menu.FIRST, 0, R.string.about_menu_txt).setIcon(android.R.drawable.ic_menu_info_details);
+ return super.onCreateOptionsMenu(menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item)
+ {
+ if (item.getItemId() == Menu.FIRST)
+ {
+ final LayoutInflater factory = LayoutInflater.from(this);
+ final View aboutView = factory.inflate(R.layout.about, null);
+
+ new AlertDialog.Builder(this).setView(aboutView).setIcon(android.R.drawable.ic_dialog_info).setTitle(
+ getString(R.string.app_name) + ' ' + getVersionNumber()).setPositiveButton(R.string.alert_dialog_ok,
+ new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int whichButton)
+ {
+ // do nothing
+ }
+ }).show();
+
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ protected void onStop()
+ {
+ super.onStop();
+
+ final SharedPreferences settings = getSharedPreferences(getString(R.string.app_name), Context.MODE_PRIVATE);
+ final SharedPreferences.Editor editor = settings.edit();
+ final Spinner tipSpin = (Spinner) findViewById(R.id.main_tip_spin);
+ editor.putInt(PREFS_TIP_RATE, tipSpin.getSelectedItemPosition());
+ editor.commit();
+ }
+
+ /**
+ * Parses a given string to an integer, the decimal point is removed.
+ *
+ * @param str The string to parse.
+ * @return The parsed integer.
+ */
+ private int parseInt(String str)
+ {
+ final int dec = str.lastIndexOf('.');
+ final int len = str.length();
+
+ if (dec == -1)
+ {
+ return Integer.parseInt(str + "00");
+ }
+ else if (dec == (len - 1))
+ {
+ return Integer.parseInt(str.substring(0, dec) + "00");
+ }
+ else if (dec == (len - 2))
+ {
+ return Integer.parseInt(str.substring(0, dec) + str.substring(dec + 1) + '0');
+ }
+
+ return Integer.parseInt(str.substring(0, dec) + str.substring(dec + 1, dec + 3));
+
+ }
+
+ /**
+ * Parses the given integer into to a string, the decimal point is added.
+ *
+ * @param i The integer.
+ * @return The parsed string.
+ */
+ private String parseStr(int i)
+ {
+ final String s = String.valueOf(i);
+
+ return s.substring(0, s.length() - 2) + '.' + s.substring(s.length() - 2);
+ }
+}
\ No newline at end of file