Browse files

added invoice data into the payments for pizza and toppings, fixed bu…

…g with BigDecimal overflow issue
  • Loading branch information...
1 parent 3458417 commit d1aa9e8f2040a3a8cf01b962c6d06a4ab2cf26fb @ppalavilli ppalavilli committed Mar 11, 2011
View
157 ...oidDevCamp-March2011/PizzaApp-Complete/src/com/paypal/MobilePayments/Pizza/PizzaMain.java
@@ -1,6 +1,7 @@
package com.paypal.MobilePayments.Pizza;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Currency;
@@ -33,6 +34,7 @@
import com.paypal.android.MEP.PayPal;
import com.paypal.android.MEP.PayPalActivity;
import com.paypal.android.MEP.PayPalInvoiceData;
+import com.paypal.android.MEP.PayPalInvoiceItem;
import com.paypal.android.MEP.PayPalPayment;
public class PizzaMain extends Activity implements OnClickListener,
@@ -55,7 +57,8 @@
private double _theSubtotal;
private double _taxAmount;
private String _pizzaDescription;
-
+ private String _sizeStr;
+ String _price;
// All the booleans we will use for toppings
private boolean _cheese = false;
private boolean _pepperoni = false;
@@ -179,66 +182,66 @@ public void loadReviewPage() {
// Set up our DecimalFormatter for our amounts
_df = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.ENGLISH);
_df.setCurrency(Currency.getInstance("USD"));
- String size = "Small";
+ _sizeStr = "Small";
switch (_size) {
case SIZE_SMALL:
- size = "Small";
+ _sizeStr = "Small";
break;
case SIZE_MEDIUM:
- size = "Medium";
+ _sizeStr = "Medium";
break;
case SIZE_LARGE:
- size = "Large";
+ _sizeStr = "Large";
break;
}
// Set up all the Pizza-related strings
- _pizzaDescription = _number + " " + size + " Pizzas";
+ _pizzaDescription = _number + " " + _sizeStr + " Pizzas";
if (_number == 1) {
- _pizzaDescription = _number + " " + size + " Pizza";
+ _pizzaDescription = _number + " " + _sizeStr + " Pizza";
}
((TextView) findViewById(R.id.NumberOfPizzas))
.setText(_pizzaDescription);
double priceAmount = 7.99;
- String price = "7.99";
+ _price = "7.99";
if (_number == 1) {
if (_size == SIZE_SMALL) {
- price = "7.99";
+ _price = "7.99";
priceAmount = 7.99;
} else if (_size == SIZE_MEDIUM) {
- price = "9.99";
+ _price = "9.99";
priceAmount = 9.99;
} else {
- price = "11.99";
+ _price = "11.99";
priceAmount = 11.99;
}
}
if (_number == 2) {
if (_size == SIZE_SMALL) {
- price = "9.99";
+ _price = "9.99";
priceAmount = 9.99;
} else if (_size == SIZE_MEDIUM) {
- price = "15.99";
+ _price = "15.99";
priceAmount = 15.99;
} else {
- price = "19.99";
+ _price = "19.99";
priceAmount = 19.99;
}
} else if (_number == 3) {
if (_size == SIZE_SMALL) {
- price = "11.99";
+ _price = "11.99";
priceAmount = 11.99;
} else if (_size == SIZE_MEDIUM) {
- price = "20.99";
+ _price = "20.99";
priceAmount = 20.99;
} else {
- price = "25.99";
+ _price = "25.99";
priceAmount = 25.99;
}
}
- ((TextView) findViewById(R.id.Price)).setText("$" + price);
+ ((TextView) findViewById(R.id.Price)).setText("$" + _price);
// hide toppings, if they're not used
if (!_cheese) {
@@ -511,7 +514,7 @@ public void initLibrary() {
// This is the main initialization call that takes in your Context,
// the Application ID, and the server you would like to connect to.
pp = PayPal.initWithAppID(this, "APP-80W284485P519543T",
- PayPal.ENV_NONE);
+ PayPal.ENV_SANDBOX);
// -- These are required settings.
pp.setLanguage("en_US"); // Sets the language for the library.
@@ -534,6 +537,10 @@ public void initLibrary() {
_paypalLibraryInit = true;
}
}
+
+ /** this method generates the PayPal checkout button and adds it to the current view
+ * using the relative layout params
+ */
private void showPayPalButton() {
removePayPalButton();
// Back in the UI thread -- show the "Pay with PayPal" button
@@ -561,6 +568,8 @@ private void showPayPalButton() {
}
}
+ /* this method removes the PayPal button from the view
+ */
private void removePayPalButton() {
// Avoid an exception for setting a parent more than once
if (launchPayPalButton != null) {
@@ -569,7 +578,9 @@ private void removePayPalButton() {
}
}
-
+ /* method to handle PayPal checkout button onClick event
+ * - this must be called from the onClick() method implemented by the application
+ */
public void PayPalButtonClick(View arg0) {
// Create a basic PayPalPayment.
@@ -578,10 +589,12 @@ public void PayPalButtonClick(View arg0) {
payment.setCurrencyType("USD");
// Sets the recipient for the payment. This can also be a phone
// number.
- payment.setRecipient("ppalav_1285013097_biz@yahoo.com");
+ payment.setRecipient("pd_1265515509_biz@yahoo.com");
// Sets the amount of the payment, not including tax and shipping
- // amounts.
- payment.setSubtotal(new BigDecimal(_theSubtotal));
+ // amounts.
+ BigDecimal st = new BigDecimal(_theSubtotal);
+ st = st.setScale(2, RoundingMode.HALF_UP);
+ payment.setSubtotal(st);
// Sets the payment type. This can be PAYMENT_TYPE_GOODS,
// PAYMENT_TYPE_SERVICE, PAYMENT_TYPE_PERSONAL, or
// PAYMENT_TYPE_NONE.
@@ -592,14 +605,103 @@ public void PayPalButtonClick(View arg0) {
// be filled out. These are not required for any transaction.
PayPalInvoiceData invoice = new PayPalInvoiceData();
// Sets the tax amount.
- invoice.setTax(new BigDecimal(_taxAmount));
+ BigDecimal tax = new BigDecimal(_taxAmount);
+ tax = tax.setScale(2, RoundingMode.HALF_UP);
+ invoice.setTax(tax);
// Sets the shipping amount.
if (_method == METHOD_DELIVERY) {
invoice.setShipping(new BigDecimal("2.00"));
// Forces the user to go to the review page
PayPal.getInstance().setShippingEnabled(true);
}
+
+ // PayPalInvoiceItem has several parameters available to it. None of these parameters is required.
+ PayPalInvoiceItem item1 = new PayPalInvoiceItem();
+ // Sets the name of the item.
+ item1.setName("Pizza");
+ // Sets the ID. This is any ID that you would like to have associated with the item.
+ item1.setID("1234");
+ // Sets the total price which should be (quantity * unit price). The total prices of all PayPalInvoiceItem should add up
+ // to less than or equal the subtotal of the payment.
+ item1.setTotalPrice(new BigDecimal(_price));
+ // Sets the unit price.
+ item1.setUnitPrice(new BigDecimal(_price));
+ // Sets the quantity.
+ item1.setQuantity(_number);
+ // Add the PayPalInvoiceItem to the PayPalInvoiceData. Alternatively, you can create an ArrayList<PayPalInvoiceItem>
+ // and pass it to the PayPalInvoiceData function setInvoiceItems().
+ invoice.getInvoiceItems().add(item1);
+ // add toppings as extra items
+ if (_cheese) {
+ PayPalInvoiceItem item2 = new PayPalInvoiceItem();
+ // Sets the name of the item.
+ item2.setName("Cheese");
+ // Sets the ID. This is any ID that you would like to have associated with the item.
+ item2.setID("2345");
+ // Sets the total price which should be (quantity * unit price). The total prices of all PayPalInvoiceItem should add up
+ // to less than or equal the subtotal of the payment.
+ item2.setTotalPrice(new BigDecimal("2.00"));
+ // Sets the unit price.
+ item2.setUnitPrice(new BigDecimal("2.00"));
+ // Sets the quantity.
+ item2.setQuantity(1);
+ // Add the PayPalInvoiceItem to the PayPalInvoiceData. Alternatively, you can create an ArrayList<PayPalInvoiceItem>
+ // and pass it to the PayPalInvoiceData function setInvoiceItems().
+ invoice.getInvoiceItems().add(item2);
+ }
+ if (_pepperoni) {
+ PayPalInvoiceItem item2 = new PayPalInvoiceItem();
+ // Sets the name of the item.
+ item2.setName("Pepperoni");
+ // Sets the ID. This is any ID that you would like to have associated with the item.
+ item2.setID("3456");
+ // Sets the total price which should be (quantity * unit price). The total prices of all PayPalInvoiceItem should add up
+ // to less than or equal the subtotal of the payment.
+ item2.setTotalPrice(new BigDecimal("2.00"));
+ // Sets the unit price.
+ item2.setUnitPrice(new BigDecimal("2.00"));
+ // Sets the quantity.
+ item2.setQuantity(1);
+ // Add the PayPalInvoiceItem to the PayPalInvoiceData. Alternatively, you can create an ArrayList<PayPalInvoiceItem>
+ // and pass it to the PayPalInvoiceData function setInvoiceItems().
+ invoice.getInvoiceItems().add(item2);
+ }
+ if (_mushrooms) {
+ PayPalInvoiceItem item2 = new PayPalInvoiceItem();
+ // Sets the name of the item.
+ item2.setName("Mushrooms");
+ // Sets the ID. This is any ID that you would like to have associated with the item.
+ item2.setID("4567");
+ // Sets the total price which should be (quantity * unit price). The total prices of all PayPalInvoiceItem should add up
+ // to less than or equal the subtotal of the payment.
+ item2.setTotalPrice(new BigDecimal("2.00"));
+ // Sets the unit price.
+ item2.setUnitPrice(new BigDecimal("2.00"));
+ // Sets the quantity.
+ item2.setQuantity(1);
+ // Add the PayPalInvoiceItem to the PayPalInvoiceData. Alternatively, you can create an ArrayList<PayPalInvoiceItem>
+ // and pass it to the PayPalInvoiceData function setInvoiceItems().
+ invoice.getInvoiceItems().add(item2);
+ }
+ if (_onions) {
+ PayPalInvoiceItem item2 = new PayPalInvoiceItem();
+ // Sets the name of the item.
+ item2.setName("Onions");
+ // Sets the ID. This is any ID that you would like to have associated with the item.
+ item2.setID("5678");
+ // Sets the total price which should be (quantity * unit price). The total prices of all PayPalInvoiceItem should add up
+ // to less than or equal the subtotal of the payment.
+ item2.setTotalPrice(new BigDecimal("2.00"));
+ // Sets the unit price.
+ item2.setUnitPrice(new BigDecimal("2.00"));
+ // Sets the quantity.
+ item2.setQuantity(1);
+ // Add the PayPalInvoiceItem to the PayPalInvoiceData. Alternatively, you can create an ArrayList<PayPalInvoiceItem>
+ // and pass it to the PayPalInvoiceData function setInvoiceItems().
+ invoice.getInvoiceItems().add(item2);
+ }
+
// Sets the PayPalPayment invoice data.
payment.setInvoiceData(invoice);
// Sets the merchant name. This is the name of your Application or
@@ -616,8 +718,11 @@ public void PayPalButtonClick(View arg0) {
// This will start the library.
startActivityForResult(checkoutIntent, REQUEST_PAYPAL_CHECKOUT);
}
- // PayPal Activity Results. This handles all the responses from the PayPal
- // Payments Library
+
+ /* This method handles the PayPal Activity Results. This handles all the responses from the PayPal
+ * Payments Library.
+ * This method must be called from the application's onActivityResult() handler
+ */
public void PayPalActivityResult(int requestCode, int resultCode, Intent intent) {
switch (resultCode) {
case Activity.RESULT_OK:
View
533 AndroidDevCamp-March2011/PizzaApp/src/com/paypal/MobilePayments/Pizza/PizzaMain.java
@@ -1,16 +1,19 @@
package com.paypal.MobilePayments.Pizza;
-
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Currency;
import java.util.Locale;
import android.app.Activity;
import android.app.AlertDialog;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
+import android.content.Intent;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
@@ -21,271 +24,322 @@
import android.widget.Spinner;
import android.widget.TextView;
+public class PizzaMain extends Activity implements OnClickListener,
+ OnItemSelectedListener, OnMultiChoiceClickListener, OnDismissListener {
+ /** Called when the activity is first created. */
-public class PizzaMain extends Activity implements OnClickListener, OnItemSelectedListener, OnMultiChoiceClickListener, OnDismissListener {
- /** Called when the activity is first created. */
-
- //So we can easily reference the different sizes and delivery methods
+ // So we can easily reference the different sizes and delivery methods
final static public int SIZE_SMALL = 0;
final static public int SIZE_MEDIUM = 1;
final static public int SIZE_LARGE = 2;
-
+
final static public int METHOD_PICKUP = 0;
final static public int METHOD_DELIVERY = 1;
-
+
private int _size = SIZE_SMALL;
private int _number = 1;
private int _method = METHOD_PICKUP;
-
- //Local references to our amounts and description
+
+ // Local references to our amounts and description
private double _theSubtotal;
private double _taxAmount;
private String _pizzaDescription;
-
- //All the booleans we will use for toppings
+ private String _sizeStr;
+ String _price;
+ // All the booleans we will use for toppings
private boolean _cheese = false;
private boolean _pepperoni = false;
private boolean _mushrooms = false;
private boolean _onions = false;
-
- //Reference to our number formatter (used for to format the amounts)
+
+ // Reference to our number formatter (used for to format the amounts)
private NumberFormat _df;
+
+ // method to check if the device is connected to network
+ public boolean isOnline() {
+ ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo netInfo = cm.getActiveNetworkInfo();
+ if (netInfo != null && netInfo.isConnectedOrConnecting()) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ //<TODO>: Initialize the PayPal library here
+
+ loadMainPage();
+ }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- loadMainPage();
- }
-
- public void loadMainPage() {
- setContentView(R.layout.main);
-
- //do the setup for the Home page -- add the Pay button
- findViewById(R.id.Buy).setOnClickListener(this);
- }
-
- public void loadCustomizePage() {
- setContentView(R.layout.customize);
- //set up the spinner for the Pizza sizes
-
- Spinner sizeSpinner = (Spinner) findViewById(R.id.Spinner01);
- sizeSpinner.setPrompt("Select a size");
- ArrayAdapter <CharSequence> sizeAdapter;
- sizeAdapter = new ArrayAdapter <CharSequence> (this, android.R.layout.simple_spinner_item);
- sizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+
+ public void loadMainPage() {
+ setContentView(R.layout.main);
+
+ // do the setup for the Home page -- add the Pay button
+ findViewById(R.id.Buy).setOnClickListener(this);
+ }
+
+ public void loadCustomizePage() {
+ setContentView(R.layout.customize);
+ // set up the spinner for the Pizza sizes
+
+ Spinner sizeSpinner = (Spinner) findViewById(R.id.Spinner01);
+ sizeSpinner.setPrompt("Select a size");
+ ArrayAdapter<CharSequence> sizeAdapter;
+ sizeAdapter = new ArrayAdapter<CharSequence>(this,
+ android.R.layout.simple_spinner_item);
+ sizeAdapter
+ .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sizeAdapter.add("Small ($7.99)");
sizeAdapter.add("Medium ($9.99)");
sizeAdapter.add("Large ($11.99)");
sizeSpinner.setAdapter(sizeAdapter);
sizeSpinner.setOnItemSelectedListener(this);
sizeSpinner.setSelection(_size);
-
- //Set up the click listeners for the buttons
+
+ // Set up the click listeners for the buttons
findViewById(R.id.Button03).setOnClickListener(this);
findViewById(R.id.Continue).setOnClickListener(this);
-
+
}
-
- public void loadFinalizePage() {
- setContentView(R.layout.finalize);
-
- //Set up the finalize page
- Spinner numberSpinner = (Spinner) findViewById(R.id.Spinner02);
- numberSpinner.setPrompt("Select number of pizzas");
- ArrayAdapter <CharSequence> numberAdapter;
- numberAdapter = new ArrayAdapter <CharSequence> (this, android.R.layout.simple_spinner_item);
- numberAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- numberAdapter.add("One");
- numberAdapter.add("Two");
- numberAdapter.add("Three");
+
+ public void loadFinalizePage() {
+ setContentView(R.layout.finalize);
+
+ // Set up the finalize page
+ Spinner numberSpinner = (Spinner) findViewById(R.id.Spinner02);
+ numberSpinner.setPrompt("Select number of pizzas");
+ ArrayAdapter<CharSequence> numberAdapter;
+ numberAdapter = new ArrayAdapter<CharSequence>(this,
+ android.R.layout.simple_spinner_item);
+ numberAdapter
+ .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ numberAdapter.add("One");
+ numberAdapter.add("Two");
+ numberAdapter.add("Three");
numberSpinner.setAdapter(numberAdapter);
numberSpinner.setOnItemSelectedListener(this);
numberSpinner.setSelection(_number - 1);
+
+ Spinner methodSpinner = (Spinner) findViewById(R.id.Spinner03);
+ methodSpinner.setPrompt("Select method");
+ ArrayAdapter<CharSequence> methodAdapter;
+ methodAdapter = new ArrayAdapter<CharSequence>(this,
+ android.R.layout.simple_spinner_item);
+ methodAdapter
+ .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ methodAdapter.add("Pickup");
+ methodAdapter.add("Delivery");
+ methodSpinner.setAdapter(methodAdapter);
+ methodSpinner.setOnItemSelectedListener(this);
+ methodSpinner.setSelection(_method);
+
+ findViewById(R.id.ReviewOrder).setOnClickListener(this);
+ }
+
+ public void loadReviewPage() {
+ setContentView(R.layout.review);
+
+ // Do all our setup of the Review page
+
+ // Set up our DecimalFormatter for our amounts
+ _df = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.ENGLISH);
+ _df.setCurrency(Currency.getInstance("USD"));
+ _sizeStr = "Small";
+ switch (_size) {
+ case SIZE_SMALL:
+ _sizeStr = "Small";
+ break;
+ case SIZE_MEDIUM:
+ _sizeStr = "Medium";
+ break;
+ case SIZE_LARGE:
+ _sizeStr = "Large";
+ break;
+ }
+
+ // Set up all the Pizza-related strings
+ _pizzaDescription = _number + " " + _sizeStr + " Pizzas";
+ if (_number == 1) {
+ _pizzaDescription = _number + " " + _sizeStr + " Pizza";
+ }
+
+ ((TextView) findViewById(R.id.NumberOfPizzas))
+ .setText(_pizzaDescription);
+ double priceAmount = 7.99;
+ _price = "7.99";
+ if (_number == 1) {
+ if (_size == SIZE_SMALL) {
+ _price = "7.99";
+ priceAmount = 7.99;
+ } else if (_size == SIZE_MEDIUM) {
+ _price = "9.99";
+ priceAmount = 9.99;
+ } else {
+ _price = "11.99";
+ priceAmount = 11.99;
+ }
+ }
+ if (_number == 2) {
+ if (_size == SIZE_SMALL) {
+ _price = "9.99";
+ priceAmount = 9.99;
+ } else if (_size == SIZE_MEDIUM) {
+ _price = "15.99";
+ priceAmount = 15.99;
+ } else {
+ _price = "19.99";
+ priceAmount = 19.99;
+ }
+ } else if (_number == 3) {
+ if (_size == SIZE_SMALL) {
+ _price = "11.99";
+ priceAmount = 11.99;
+ } else if (_size == SIZE_MEDIUM) {
+ _price = "20.99";
+ priceAmount = 20.99;
+ } else {
+ _price = "25.99";
+ priceAmount = 25.99;
+ }
+ }
+
+ ((TextView) findViewById(R.id.Price)).setText("$" + _price);
+
+ // hide toppings, if they're not used
+ if (!_cheese) {
+ ((TextView) findViewById(R.id.ExtraCheesePrice)).setText("$0.00");
+ }
+ if (!_pepperoni) {
+ ((TextView) findViewById(R.id.PepperoniPrice)).setText("$0.00");
+ }
+ if (!_mushrooms) {
+ ((TextView) findViewById(R.id.MushroomsPrice)).setText("$0.00");
+ }
+ if (!_onions) {
+ ((TextView) findViewById(R.id.OnionsPrice)).setText("$0.00");
+ }
+
+ if (_cheese) {
+ priceAmount += 2.00;
+ }
+ if (_pepperoni) {
+ priceAmount += 2.00;
+ }
+ if (_mushrooms) {
+ priceAmount += 2.00;
+ }
+ if (_onions) {
+ priceAmount += 2.00;
+ }
+
+ _theSubtotal = priceAmount;// saving this here so we can access it later
+ ((TextView) findViewById(R.id.SubtotalPrice)).setText(_df
+ .format(priceAmount));
+ if (_method == METHOD_PICKUP) {
+ ((TextView) findViewById(R.id.DeliveryFeePrice)).setText("$0.00");
+ ((TextView) findViewById(R.id.MethodType)).setText("Pick Up");
+ } else {
+ priceAmount += 2.00;
+ }
+ // to account for tax
+ _taxAmount = priceAmount * .08;
+ priceAmount += _taxAmount;
+ ((TextView) findViewById(R.id.TaxPrice))
+ .setText(_df.format(_taxAmount));
+ ((TextView) findViewById(R.id.TotalPrice)).setText(_df
+ .format(priceAmount));
+
+ // <TODO>: Insert the PayPal button here. This requires:
+ // a check to see if the PayPal Library has been initialized yet. If it has, show
+ // the "Pay with PayPal button"
+ // If not, show a progress indicator and start a loop that keeps
+ // checking the init status
- Spinner methodSpinner = (Spinner) findViewById(R.id.Spinner03);
- methodSpinner.setPrompt("Select method");
- ArrayAdapter <CharSequence> methodAdapter;
- methodAdapter = new ArrayAdapter <CharSequence> (this, android.R.layout.simple_spinner_item);
- methodAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- methodAdapter.add("Pickup");
- methodAdapter.add("Delivery");
- methodSpinner.setAdapter(methodAdapter);
- methodSpinner.setOnItemSelectedListener(this);
- methodSpinner.setSelection(_method);
+
+ }
+
+
+
+ // PayPal Activity Results. This handles all the responses from the PayPal
+ // Payments Library
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
+
+ //<TODO>: Add the check to see if the result is from the PayPal checkout activity
+ // and if so handle the results here
- findViewById(R.id.ReviewOrder).setOnClickListener(this);
- }
-
- public void loadReviewPage() {
- setContentView(R.layout.review);
-
- //Do all our setup of the Review page
-
- //Set up our DecimalFormatter for our amounts
- _df = (DecimalFormat)DecimalFormat.getCurrencyInstance(Locale.ENGLISH);
- _df.setCurrency(Currency.getInstance("USD"));
- String size = "Small";
- switch (_size) {
- case SIZE_SMALL: size = "Small"; break;
- case SIZE_MEDIUM: size = "Medium"; break;
- case SIZE_LARGE: size = "Large"; break;
- }
-
- //Set up all the Pizza-related strings
- _pizzaDescription = _number + " " + size + " Pizzas";
- if (_number == 1) {
- _pizzaDescription = _number + " " + size + " Pizza";
- }
-
- ((TextView) findViewById(R.id.NumberOfPizzas)).setText(_pizzaDescription);
- double priceAmount = 7.99;
- String price = "7.99";
- if (_number == 1) {
- if (_size == SIZE_SMALL) {
- price = "7.99";
- priceAmount = 7.99;
- } else if (_size == SIZE_MEDIUM) {
- price = "9.99";
- priceAmount = 9.99;
- } else {
- price = "11.99";
- priceAmount = 11.99;
- }
- }
- if (_number == 2) {
- if (_size == SIZE_SMALL) {
- price = "9.99";
- priceAmount = 9.99;
- } else if (_size == SIZE_MEDIUM) {
- price = "15.99";
- priceAmount = 15.99;
- } else {
- price = "19.99";
- priceAmount = 19.99;
- }
- }
- else if (_number == 3) {
- if (_size == SIZE_SMALL) {
- price = "11.99";
- priceAmount = 11.99;
- } else if (_size == SIZE_MEDIUM) {
- price = "20.99";
- priceAmount = 20.99;
- } else {
- price = "25.99";
- priceAmount = 25.99;
- }
- }
-
- ((TextView) findViewById(R.id.Price)).setText("$" + price);
-
- //hide toppings, if they're not used
- if (!_cheese) {
- ((TextView) findViewById(R.id.ExtraCheesePrice)).setText("$0.00");
- }
- if (!_pepperoni) {
- ((TextView) findViewById(R.id.PepperoniPrice)).setText("$0.00");
- }
- if (!_mushrooms) {
- ((TextView) findViewById(R.id.MushroomsPrice)).setText("$0.00");
- }
- if (!_onions) {
- ((TextView) findViewById(R.id.OnionsPrice)).setText("$0.00");
- }
-
- if (_cheese) {
- priceAmount += 2.00;
- }
- if (_pepperoni) {
- priceAmount += 2.00;
- }
- if (_mushrooms) {
- priceAmount += 2.00;
- }
- if (_onions) {
- priceAmount += 2.00;
- }
-
- _theSubtotal = priceAmount;//saving this here so we can access it later
- ((TextView) findViewById(R.id.SubtotalPrice)).setText(_df.format(priceAmount));
- if (_method == METHOD_PICKUP) {
- ((TextView) findViewById(R.id.DeliveryFeePrice)).setText("$0.00");
- ((TextView) findViewById(R.id.MethodType)).setText("Pick Up");
- }
- else {
- priceAmount += 2.00;
- }
- //to account for tax
- _taxAmount = priceAmount * .08;
- priceAmount += _taxAmount;
- ((TextView) findViewById(R.id.TaxPrice)).setText(_df.format(_taxAmount));
- ((TextView) findViewById(R.id.TotalPrice)).setText(_df.format(priceAmount));
- }
-
- public void loadResultsPage() {
- setContentView(R.layout.results);
-
- //Set up the click listeners for the buttons
+
+
+ super.onActivityResult(requestCode, resultCode, intent);
+
+ }
+
+ public void loadResultsPage() {
+ setContentView(R.layout.results);
+
+ // Set up the click listeners for the buttons
findViewById(R.id.BuyMore).setOnClickListener(this);
findViewById(R.id.Done).setOnClickListener(this);
- }
-
-
-
+ }
+
@Override
public void onClick(View arg0) {
- if (arg0 == (Button)findViewById(R.id.Buy)) {
- //load the Customize page when the Buy button is clicked
+ if (arg0 == (Button) findViewById(R.id.Buy)) {
+ // load the Customize page when the Buy button is clicked
loadCustomizePage();
- }
- else if (arg0 == (Button)findViewById(R.id.Button03)) {
- //Shows the pop-up where the user can select toppings
- ((Button)findViewById(R.id.Continue)).setVisibility(View.GONE);
- final CharSequence[] items = {"Extra Cheese", "Pepperoni", "Mushrooms", "Onions"};
+ } else if (arg0 == (Button) findViewById(R.id.Button03)) {
+ // Shows the pop-up where the user can select toppings
+ ((Button) findViewById(R.id.Continue)).setVisibility(View.GONE);
+ final CharSequence[] items = { "Extra Cheese", "Pepperoni",
+ "Mushrooms", "Onions" };
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose your toppings");
- boolean[] myBools = {_cheese, _pepperoni, _mushrooms, _onions};
+ boolean[] myBools = { _cheese, _pepperoni, _mushrooms, _onions };
builder.setMultiChoiceItems(items, myBools, this);
- builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- });
+ builder.setPositiveButton("OK",
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ }
+ });
AlertDialog alert = builder.create();
alert.setOnDismissListener(this);
alert.show();
- }
- else if (arg0 == (Button)findViewById(R.id.Continue)) {
+ } else if (arg0 == (Button) findViewById(R.id.Continue)) {
loadFinalizePage();
- }
- else if (arg0 == (Button)findViewById(R.id.ReviewOrder)) {
+ } else if (arg0 == (Button) findViewById(R.id.ReviewOrder)) {
loadReviewPage();
- }
- else if (arg0 == (Button)findViewById(R.id.BuyMore)) {
+ } else if (arg0 == (Button) findViewById(R.id.BuyMore)) {
loadMainPage();
- }
- else if (arg0 == (Button)findViewById(R.id.Done)) {
+ } else if (arg0 == (Button) findViewById(R.id.Done)) {
finish();
- }
+ }
+ //<TODO>: Add the check to see if the onClick event is from the PayPal button
+ // and if so create the paypal checkout activity
+
}
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
- //Lets us track the spinner view
+ // Lets us track the spinner view
if (arg0 == findViewById(R.id.Spinner01)) {
- _size = arg2;//0 is small, 1 is medium, 2 is large
+ _size = arg2;// 0 is small, 1 is medium, 2 is large
} else if (arg0 == findViewById(R.id.Spinner02)) {
_number = arg2 + 1;
} else if (arg0 == findViewById(R.id.Spinner03)) {
_method = arg2;
}
-
+
}
@Override
@@ -295,7 +349,7 @@ public void onNothingSelected(AdapterView<?> arg0) {
@Override
public void onClick(DialogInterface arg0, int arg1, boolean arg2) {
- //this is the topping selector
+ // this is the topping selector
if (arg1 == 0) {
_cheese = arg2;
} else if (arg1 == 1) {
@@ -306,43 +360,50 @@ public void onClick(DialogInterface arg0, int arg1, boolean arg2) {
_onions = arg2;
}
}
-
-
- public void paymentSucceeded(String transactionID){
- //We could show the transactionID to the user
+
+ public void paymentSucceeded(String payKey) {
+ // We could show the transactionID to the user
loadResultsPage();
- ((TextView)findViewById(R.id.ResultsTitle)).setText("Success!");
- if(_method == METHOD_PICKUP) {
- ((TextView)findViewById(R.id.ResultsText1)).setText("Your order is being prepared!");
- } else if(_method == METHOD_DELIVERY) {
- ((TextView)findViewById(R.id.ResultsText1)).setText("Your order is on its way!");
+ ((TextView) findViewById(R.id.ResultsTitle)).setText("Success!");
+ if (_method == METHOD_PICKUP) {
+ ((TextView) findViewById(R.id.ResultsText1))
+ .setText("Your order is being prepared!");
+ } else if (_method == METHOD_DELIVERY) {
+ ((TextView) findViewById(R.id.ResultsText1))
+ .setText("Your order is on its way!");
}
- ((TextView)findViewById(R.id.ResultsText2)).setText("Estimated time: 30 minutes.");
- ((TextView)findViewById(R.id.ResultsText3)).setText("Transaction ID: " + transactionID);
- }
-
- public void paymentFailed(String errorID, String errorMessage){
- //We could let the user know the payment failed here
+ ((TextView) findViewById(R.id.ResultsText2))
+ .setText("Estimated time: 30 minutes.");
+ ((TextView) findViewById(R.id.ResultsText3)).setText("Payment Key: "
+ + payKey);
+ }
+
+ public void paymentFailed(String errorID, String errorMessage) {
+ // We could let the user know the payment failed here
loadResultsPage();
- ((TextView)findViewById(R.id.ResultsTitle)).setText("Failure!");
- ((TextView)findViewById(R.id.ResultsText1)).setText("We're sorry, but your payment failed.");
- ((TextView)findViewById(R.id.ResultsText2)).setText("Error: " + errorMessage);
- ((TextView)findViewById(R.id.ResultsText3)).setText("Error ID: " + errorID);
- }
-
- public void paymentCanceled(){
- //We could tell the user that the payment was canceled
+ ((TextView) findViewById(R.id.ResultsTitle)).setText("Failure!");
+ ((TextView) findViewById(R.id.ResultsText1))
+ .setText("We're sorry, but your payment failed.");
+ ((TextView) findViewById(R.id.ResultsText2)).setText("Error: "
+ + errorMessage);
+ ((TextView) findViewById(R.id.ResultsText3)).setText("Error ID: "
+ + errorID);
+ }
+
+ public void paymentCanceled() {
+ // We could tell the user that the payment was canceled
loadResultsPage();
- ((TextView)findViewById(R.id.ResultsTitle)).setText("Canceled.");
- ((TextView)findViewById(R.id.ResultsText1)).setText("Your payment has been canceled.");
- ((TextView)findViewById(R.id.ResultsText2)).setText("Your account was not charged.");
- ((TextView)findViewById(R.id.ResultsText3)).setText("");
- }
-
-
+ ((TextView) findViewById(R.id.ResultsTitle)).setText("Canceled.");
+ ((TextView) findViewById(R.id.ResultsText1))
+ .setText("Your payment has been canceled.");
+ ((TextView) findViewById(R.id.ResultsText2))
+ .setText("Your account was not charged.");
+ ((TextView) findViewById(R.id.ResultsText3)).setText("");
+ }
+
@Override
public void onDismiss(DialogInterface arg0) {
- findViewById(R.id.Continue).setVisibility(View.VISIBLE);
+ findViewById(R.id.Continue).setVisibility(View.VISIBLE);
}
}

0 comments on commit d1aa9e8

Please sign in to comment.